diff options
author | andrew <andrew@FreeBSD.org> | 2016-05-16 09:31:44 +0000 |
---|---|---|
committer | andrew <andrew@FreeBSD.org> | 2016-05-16 09:31:44 +0000 |
commit | cb60d232484543011e4ff8ef6297e9bde00cd4b7 (patch) | |
tree | ea7ade04a96f7a75a4549743125c268538974c99 /sys/arm64 | |
parent | c8b75fc824d9701ee119de24599a43d3212dd4ad (diff) | |
download | FreeBSD-src-cb60d232484543011e4ff8ef6297e9bde00cd4b7.zip FreeBSD-src-cb60d232484543011e4ff8ef6297e9bde00cd4b7.tar.gz |
Add a pcib interface for use by interrupt controllers that need to
translate the pci rid to a controller ID. The translation could be based
on the 'msi-map' OFW property, a similar ACPI option, or hard-coded for
hardware lacking the above options.
Reviewed by: wma
Obtained from: ABT Systems Ltd
Sponsored by: The FreeBSD Foundation
Diffstat (limited to 'sys/arm64')
-rw-r--r-- | sys/arm64/arm64/gic_v3_its.c | 64 | ||||
-rw-r--r-- | sys/arm64/arm64/gic_v3_var.h | 2 | ||||
-rw-r--r-- | sys/arm64/cavium/thunder_pcie_fdt.c | 31 | ||||
-rw-r--r-- | sys/arm64/cavium/thunder_pcie_pem.c | 38 | ||||
-rw-r--r-- | sys/arm64/cavium/thunder_pcie_pem_fdt.c | 23 |
5 files changed, 97 insertions, 61 deletions
diff --git a/sys/arm64/arm64/gic_v3_its.c b/sys/arm64/arm64/gic_v3_its.c index 5dd56cf..a2cfa55 100644 --- a/sys/arm64/arm64/gic_v3_its.c +++ b/sys/arm64/arm64/gic_v3_its.c @@ -62,6 +62,7 @@ __FBSDID("$FreeBSD$"); #define GIC_V3_ITS_QUIRK_THUNDERX_PEM_BUS_OFFSET 88 #include "pic_if.h" +#include "pcib_if.h" /* Device and PIC methods */ static int gic_v3_its_attach(device_t); @@ -150,7 +151,6 @@ const char *its_ptab_type[] = { /* Cavium ThunderX PCI devid acquire function */ static uint32_t its_get_devbits_thunder(device_t); -static uint32_t its_get_devid_thunder(device_t); static const struct its_quirks its_quirks[] = { { @@ -160,7 +160,6 @@ static const struct its_quirks its_quirks[] = { */ .cpuid = CPU_ID_RAW(CPU_IMPL_CAVIUM, CPU_PART_THUNDER, 0, 0), .cpuid_mask = CPU_IMPL_MASK | CPU_PART_MASK, - .devid_func = its_get_devid_thunder, .devbits_func = its_get_devbits_thunder, }, }; @@ -1569,46 +1568,6 @@ its_device_asign_lpi_locked(struct gic_v3_its_softc *sc, * Add vendor specific PCI devid function here. */ static uint32_t -its_get_devid_thunder(device_t pci_dev) -{ - int bsf; - int pem; - uint32_t bus; - - bus = pci_get_bus(pci_dev); - bsf = pci_get_rid(pci_dev); - - /* Check if accessing internal PCIe (low bus numbers) */ - if (bus < GIC_V3_ITS_QUIRK_THUNDERX_PEM_BUS_OFFSET) { - return ((pci_get_domain(pci_dev) << PCI_RID_DOMAIN_SHIFT) | - bsf); - /* PEM otherwise */ - } else { - /* PEM (PCIe MAC/root complex) number is equal to domain */ - pem = pci_get_domain(pci_dev); - - /* - * Set appropriate device ID (passed by the HW along with - * the transaction to memory) for different root complex - * numbers using hard-coded domain portion for each group. - */ - if (pem < 3) - return ((0x1 << PCI_RID_DOMAIN_SHIFT) | bsf); - - if (pem < 6) - return ((0x3 << PCI_RID_DOMAIN_SHIFT) | bsf); - - if (pem < 9) - return ((0x9 << PCI_RID_DOMAIN_SHIFT) | bsf); - - if (pem < 12) - return ((0xB << PCI_RID_DOMAIN_SHIFT) | bsf); - } - - return (0); -} - -static uint32_t its_get_devbits_thunder(device_t dev) { uint32_t devid_bits; @@ -1670,28 +1629,15 @@ its_get_devbits(device_t dev) return (its_get_devbits_default(dev)); } -static __inline uint32_t -its_get_devid_default(device_t pci_dev) -{ - - return (PCI_DEVID_GENERIC(pci_dev)); -} - static uint32_t its_get_devid(device_t pci_dev) { - const struct its_quirks *quirk; - size_t i; + uintptr_t id; - for (i = 0; i < nitems(its_quirks); i++) { - quirk = &its_quirks[i]; - if (CPU_MATCH_RAW(quirk->cpuid_mask, quirk->cpuid)) { - if (quirk->devid_func != NULL) - return ((*quirk->devid_func)(pci_dev)); - } - } + if (pci_get_id(pci_dev, PCI_ID_MSI, &id) != 0) + panic("its_get_devid: Unable to get the MSI DeviceID"); - return (its_get_devid_default(pci_dev)); + return (id); } /* diff --git a/sys/arm64/arm64/gic_v3_var.h b/sys/arm64/arm64/gic_v3_var.h index 2e780c3..d95586c 100644 --- a/sys/arm64/arm64/gic_v3_var.h +++ b/sys/arm64/arm64/gic_v3_var.h @@ -247,12 +247,10 @@ struct gic_v3_its_softc { /* Stuff that is specific to the vendor's implementation */ typedef uint32_t (*its_devbits_func_t)(device_t); -typedef uint32_t (*its_devid_func_t)(device_t); struct its_quirks { uint64_t cpuid; uint64_t cpuid_mask; - its_devid_func_t devid_func; its_devbits_func_t devbits_func; }; diff --git a/sys/arm64/cavium/thunder_pcie_fdt.c b/sys/arm64/cavium/thunder_pcie_fdt.c index b786eef..e25d4a8 100644 --- a/sys/arm64/cavium/thunder_pcie_fdt.c +++ b/sys/arm64/cavium/thunder_pcie_fdt.c @@ -45,16 +45,24 @@ __FBSDID("$FreeBSD$"); #include <dev/ofw/openfirm.h> #include <dev/ofw/ofw_bus.h> #include <dev/ofw/ofw_bus_subr.h> + +#include <dev/pci/pcireg.h> +#include <dev/pci/pcivar.h> #include <dev/pci/pci_host_generic.h> +#include <dev/pci/pcib_private.h> #include "thunder_pcie_common.h" +#include "pcib_if.h" + #ifdef THUNDERX_PASS_1_1_ERRATA static struct resource * thunder_pcie_fdt_alloc_resource(device_t, device_t, int, int *, rman_res_t, rman_res_t, rman_res_t, u_int); #endif static int thunder_pcie_fdt_attach(device_t); static int thunder_pcie_fdt_probe(device_t); +static int thunder_pcie_fdt_get_id(device_t, device_t, enum pci_id_type, + uintptr_t *); static device_method_t thunder_pcie_fdt_methods[] = { /* Device interface */ @@ -64,6 +72,9 @@ static device_method_t thunder_pcie_fdt_methods[] = { DEVMETHOD(bus_alloc_resource, thunder_pcie_fdt_alloc_resource), #endif + /* pcib interface */ + DEVMETHOD(pcib_get_id, thunder_pcie_fdt_get_id), + /* End */ DEVMETHOD_END }; @@ -112,6 +123,26 @@ thunder_pcie_fdt_attach(device_t dev) return (pci_host_generic_attach(dev)); } +static int +thunder_pcie_fdt_get_id(device_t pci, device_t child, enum pci_id_type type, + uintptr_t *id) +{ + phandle_t node; + int bsf; + + if (type != PCI_ID_MSI) + return (pcib_get_id(pci, child, type, id)); + + node = ofw_bus_get_node(pci); + if (OF_hasprop(node, "msi-map")) + return (generic_pcie_get_id(pci, child, type, id)); + + bsf = pci_get_rid(child); + *id = (pci_get_domain(child) << PCI_RID_DOMAIN_SHIFT) | bsf; + + return (0); +} + #ifdef THUNDERX_PASS_1_1_ERRATA static struct resource * thunder_pcie_fdt_alloc_resource(device_t dev, device_t child, int type, int *rid, diff --git a/sys/arm64/cavium/thunder_pcie_pem.c b/sys/arm64/cavium/thunder_pcie_pem.c index 78514b9..7b4394f 100644 --- a/sys/arm64/cavium/thunder_pcie_pem.c +++ b/sys/arm64/cavium/thunder_pcie_pem.c @@ -53,6 +53,7 @@ __FBSDID("$FreeBSD$"); #include <dev/pci/pcivar.h> #include <dev/pci/pcireg.h> #include <dev/pci/pci_host_generic.h> +#include <dev/pci/pcib_private.h> #include <machine/bus.h> #include <machine/resource.h> @@ -131,6 +132,8 @@ static int thunder_pem_release_msi(device_t, device_t, int, int *); static int thunder_pem_alloc_msix(device_t, device_t, int *); static int thunder_pem_release_msix(device_t, device_t, int); static int thunder_pem_map_msi(device_t, device_t, int, uint64_t *, uint32_t *); +static int thunder_pem_get_id(device_t, device_t, enum pci_id_type, + uintptr_t *); static int thunder_pem_attach(device_t); static int thunder_pem_deactivate_resource(device_t, device_t, int, int, struct resource *); @@ -182,6 +185,7 @@ static device_method_t thunder_pem_methods[] = { DEVMETHOD(pcib_alloc_msi, thunder_pem_alloc_msi), DEVMETHOD(pcib_release_msi, thunder_pem_release_msi), DEVMETHOD(pcib_map_msi, thunder_pem_map_msi), + DEVMETHOD(pcib_get_id, thunder_pem_get_id), DEVMETHOD_END }; @@ -372,6 +376,40 @@ thunder_pem_map_msi(device_t pci, device_t child, int irq, uint64_t *addr, } static int +thunder_pem_get_id(device_t pci, device_t child, enum pci_id_type type, + uintptr_t *id) +{ + int bsf; + int pem; + + if (type != PCI_ID_MSI) + return (pcib_get_id(pci, child, type, id)); + + bsf = pci_get_rid(child); + + /* PEM (PCIe MAC/root complex) number is equal to domain */ + pem = pci_get_domain(child); + + /* + * Set appropriate device ID (passed by the HW along with + * the transaction to memory) for different root complex + * numbers using hard-coded domain portion for each group. + */ + if (pem < 3) + *id = (0x1 << PCI_RID_DOMAIN_SHIFT) | bsf; + else if (pem < 6) + *id = (0x3 << PCI_RID_DOMAIN_SHIFT) | bsf; + else if (pem < 9) + *id = (0x9 << PCI_RID_DOMAIN_SHIFT) | bsf; + else if (pem < 12) + *id = (0xB << PCI_RID_DOMAIN_SHIFT) | bsf; + else + return (ENXIO); + + return (0); +} + +static int thunder_pem_identify(device_t dev) { struct thunder_pem_softc *sc; diff --git a/sys/arm64/cavium/thunder_pcie_pem_fdt.c b/sys/arm64/cavium/thunder_pcie_pem_fdt.c index 7c3a436..9e4770b 100644 --- a/sys/arm64/cavium/thunder_pcie_pem_fdt.c +++ b/sys/arm64/cavium/thunder_pcie_pem_fdt.c @@ -65,6 +65,8 @@ static int thunder_pem_fdt_alloc_msi(device_t, device_t, int, int, int *); static int thunder_pem_fdt_release_msi(device_t, device_t, int, int *); static int thunder_pem_fdt_map_msi(device_t, device_t, int, uint64_t *, uint32_t *); +static int thunder_pem_fdt_get_id(device_t, device_t, enum pci_id_type, + uintptr_t *); static device_method_t thunder_pem_fdt_methods[] = { /* Device interface */ @@ -76,6 +78,7 @@ static device_method_t thunder_pem_fdt_methods[] = { DEVMETHOD(pcib_alloc_msi, thunder_pem_fdt_alloc_msi), DEVMETHOD(pcib_release_msi, thunder_pem_fdt_release_msi), DEVMETHOD(pcib_map_msi, thunder_pem_fdt_map_msi), + DEVMETHOD(pcib_get_id, thunder_pem_fdt_get_id), /* End */ DEVMETHOD_END @@ -142,3 +145,23 @@ thunder_pem_fdt_map_msi(device_t pci, device_t child, int irq, uint64_t *addr, return (arm_map_msi(pci, child, irq, addr, data)); } + +static int +thunder_pem_fdt_get_id(device_t dev, device_t child, enum pci_id_type type, + uintptr_t *id) +{ + phandle_t node; + uint32_t rid; + uint16_t pci_rid; + + if (type != PCI_ID_MSI) + return (pcib_get_id(dev, child, type, id)); + + node = ofw_bus_get_node(dev); + pci_rid = pci_get_rid(child); + + ofw_bus_msimap(node, pci_rid, NULL, &rid); + *id = rid; + + return (0); +} |