From nobody Sun Dec 29 03:57:08 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4YLQR90DNjz5jk5X; Sun, 29 Dec 2024 03:57:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YLQR86tqDz4lbv; Sun, 29 Dec 2024 03:57:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735444629; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=2OnoFWT47+oe3bcFpzTDUGdMU7JGfnqt3xOc2GvV5Vo=; b=HUtbmlw+qrvKkLMCbSoMuwwgbGBl6Ls3OvDGOKIbr5I93PaRmAwTX1/skjKZPbZyeNlykf NlKa2eFtKiNl4BBGS/jnbQYMGGZvidbvai6K3RmSwy3JDFoH2RARleGzxLHl4+/6vGlaxD 9PcfyvpwBryHkpeXj1jLBVzSY30+dvmZcYvw3q0jUFKBvpmIAUwETcFYpHxxpjKx75jEB9 eZbjhTdmGbqHG6r/ONfG5G4dV9U55mzob3Qt9x9Nb8OuimDwl7E8aU7PeABERDAj+zC+rz ROZ0Ro6nP5CrEXbDTJ2qeELAedVRlKyULhchmKoYDPUm8qSPVRR1ue3kKLU5nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735444629; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=2OnoFWT47+oe3bcFpzTDUGdMU7JGfnqt3xOc2GvV5Vo=; b=abELR22+w9Ktbr+n58EhShmiku5pxoTONOiFfGzgBYA7+TTVr5yb5kn/oPNLOlIa8kVL88 eTJ6sN2D4+GOkXu6efK6cxlofmbHilGA6JHG4m6RDoMEZjmgF5LfMgbHgd2sf10aDh8RU4 JTzKuyh3wcBKCypKc36gcKyHJJTq7ZiX2x17am0umTpb1rE2+9Mese7RkMTA9a1RdNJQEP DSXWiC2Wo3iFz2hv/jBDcfxYZsFYAp+st1h1yXXhq7deSY3s3OyIKpYMQ5Y+tQFXBVQw2D P6eOSO6eZjPGb6YvKUqfjbMjQZf+jb8houIPuUqaBf0zxUFG1XduhOEpYe9JSQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1735444629; a=rsa-sha256; cv=none; b=dnMYdbtxJQejLUOhVdhhFWVLAmsR35Z/qlaN1LBD8DX9UCZsXU49AIQwLqu5WYH7uoI39d STFQSfhfIZHkPLKgf8oH9lYktSGJXe9qGN95u6nOZzASJyrj6xww5MWz0ikrRdcUqHFaCC 9KPypXh9RJLzBGJd3FQglqJmgkuCMqD07Ien5Rg5mWMSZIVogZLzsm6SoQiN+TQnxIn+s5 a9odlDoXSLyTznsTlfo3gSfTkZqSimUXTKJ6mWne58sqL3+Kh7BPNuyVqtrvM8mrDk8P5L wPXh9Q8LxIxEo/DdWkECm7o+n1N5SQBtVEwdQoagWZkOnuZk0SdkkI2EtWQeNA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4YLQR86VrHzsw6; Sun, 29 Dec 2024 03:57:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4BT3v88i049939; Sun, 29 Dec 2024 03:57:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BT3v8SG049936; Sun, 29 Dec 2024 03:57:08 GMT (envelope-from git) Date: Sun, 29 Dec 2024 03:57:08 GMT Message-Id: <202412290357.4BT3v8SG049936@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: b313229969cc - main - pci: avoid accidental clobbering of regs on some fdt platforms List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b313229969cc56a057dfea28506784fd5468c6f3 Auto-Submitted: auto-generated The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=b313229969cc56a057dfea28506784fd5468c6f3 commit b313229969cc56a057dfea28506784fd5468c6f3 Author: Kyle Evans AuthorDate: 2024-12-29 03:57:03 +0000 Commit: Kyle Evans CommitDate: 2024-12-29 03:57:03 +0000 pci: avoid accidental clobbering of regs on some fdt platforms Most pci controllers will just have a single reg for the config space, but others (e.g., on Apple Silicon) may have more following that to describe, e.g., controller port space. Bump the "ranges" rid space up to avoid overriding these other memory resources. Reviewed by: jhb Differential Revision: https://reviews.freebsd.org/D43921 --- sys/dev/pci/pci_host_generic.c | 22 +++++++++++++++++----- sys/dev/pci/pci_host_generic.h | 1 + sys/dev/pci/pci_host_generic_acpi.c | 1 + sys/dev/pci/pci_host_generic_fdt.c | 1 + 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/sys/dev/pci/pci_host_generic.c b/sys/dev/pci/pci_host_generic.c index 373a54a25a4d..884ab25548ce 100644 --- a/sys/dev/pci/pci_host_generic.c +++ b/sys/dev/pci/pci_host_generic.c @@ -59,6 +59,12 @@ #define PCI_RF_FLAGS 0 #endif +/* + * We allocate "ranges" specified mappings higher up in the rid space to avoid + * conflicts with various definitions in the wild that may have other registers + * attributed to the controller besides just the config space. + */ +#define RANGE_RID(idx) ((idx) + 100) /* Forward prototypes */ @@ -173,7 +179,7 @@ pci_host_generic_core_attach(device_t dev) phys_base = sc->ranges[tuple].phys_base; pci_base = sc->ranges[tuple].pci_base; size = sc->ranges[tuple].size; - rid = tuple + 1; + rid = RANGE_RID(tuple); if (size == 0) continue; /* empty range element */ switch (FLAG_TYPE(sc->ranges[tuple].flags)) { @@ -210,6 +216,7 @@ pci_host_generic_core_attach(device_t dev) error); continue; } + sc->ranges[tuple].rid = rid; sc->ranges[tuple].res = bus_alloc_resource_any(dev, type, &rid, RF_ACTIVE | RF_UNMAPPED | flags); if (sc->ranges[tuple].res == NULL) { @@ -246,7 +253,7 @@ int pci_host_generic_core_detach(device_t dev) { struct generic_pcie_core_softc *sc; - int error, tuple, type; + int error, rid, tuple, type; sc = device_get_softc(dev); @@ -255,8 +262,13 @@ pci_host_generic_core_detach(device_t dev) return (error); for (tuple = 0; tuple < MAX_RANGES_TUPLES; tuple++) { - if (sc->ranges[tuple].size == 0) + rid = sc->ranges[tuple].rid; + if (sc->ranges[tuple].size == 0) { + MPASS(sc->ranges[tuple].res == NULL); continue; /* empty range element */ + } + + MPASS(rid != -1); switch (FLAG_TYPE(sc->ranges[tuple].flags)) { case FLAG_TYPE_PMEM: case FLAG_TYPE_MEM: @@ -269,9 +281,9 @@ pci_host_generic_core_detach(device_t dev) continue; } if (sc->ranges[tuple].res != NULL) - bus_release_resource(dev, type, tuple + 1, + bus_release_resource(dev, type, rid, sc->ranges[tuple].res); - bus_delete_resource(dev, type, tuple + 1); + bus_delete_resource(dev, type, rid); } rman_fini(&sc->io_rman); rman_fini(&sc->mem_rman); diff --git a/sys/dev/pci/pci_host_generic.h b/sys/dev/pci/pci_host_generic.h index 7aa8852fd30a..6579cd0918c4 100644 --- a/sys/dev/pci/pci_host_generic.h +++ b/sys/dev/pci/pci_host_generic.h @@ -64,6 +64,7 @@ struct pcie_range { #define FLAG_TYPE_MEM 0x2 #define FLAG_TYPE_PMEM 0x3 struct resource *res; + int rid; }; struct generic_pcie_core_softc { diff --git a/sys/dev/pci/pci_host_generic_acpi.c b/sys/dev/pci/pci_host_generic_acpi.c index 1ff3a6bda707..f12632e7205b 100644 --- a/sys/dev/pci/pci_host_generic_acpi.c +++ b/sys/dev/pci/pci_host_generic_acpi.c @@ -182,6 +182,7 @@ pci_host_generic_acpi_parse_resource(ACPI_RESOURCE *res, void *arg) /* Save detected ranges */ if (res->Data.Address.ResourceType == ACPI_MEMORY_RANGE || res->Data.Address.ResourceType == ACPI_IO_RANGE) { + sc->base.ranges[r].rid = -1; sc->base.ranges[r].pci_base = min; sc->base.ranges[r].phys_base = min + off; sc->base.ranges[r].size = max - min + 1; diff --git a/sys/dev/pci/pci_host_generic_fdt.c b/sys/dev/pci/pci_host_generic_fdt.c index 4e933dec35db..73c6201dc14b 100644 --- a/sys/dev/pci/pci_host_generic_fdt.c +++ b/sys/dev/pci/pci_host_generic_fdt.c @@ -215,6 +215,7 @@ parse_pci_mem_ranges(device_t dev, struct generic_pcie_core_softc *sc) sc->ranges[i].flags |= FLAG_TYPE_MEM; } + sc->ranges[i].rid = -1; sc->ranges[i].pci_base = 0; for (k = 0; k < (pci_addr_cells - 1); k++) { sc->ranges[i].pci_base <<= 32;