Add OFW_IOMMU id type for pci_get_id() so we can ask parent IOMMU

controller to map PCI RID to an IOMMU specifier.

Sponsored by:	UKRI
Discussed with:	jhb
Differential Revision: https://reviews.freebsd.org/D35129
This commit is contained in:
Ruslan Bukin 2022-05-07 10:17:43 +01:00
parent 904c148f1c
commit b7672a7025
4 changed files with 36 additions and 0 deletions

View file

@ -373,6 +373,30 @@ generic_pcie_fdt_release_msix(device_t pci, device_t child, int irq)
#endif
}
static int
generic_pcie_get_iommu(device_t pci, device_t child, uintptr_t *id)
{
struct pci_id_ofw_iommu *iommu;
uint32_t iommu_rid;
uint32_t iommu_xref;
uint16_t pci_rid;
phandle_t node;
int err;
node = ofw_bus_get_node(pci);
pci_rid = pci_get_rid(child);
iommu = (struct pci_id_ofw_iommu *)id;
err = ofw_bus_iommu_map(node, pci_rid, &iommu_xref, &iommu_rid);
if (err == 0) {
iommu->id = iommu_rid;
iommu->xref = iommu_xref;
}
return (err);
}
int
generic_pcie_get_id(device_t pci, device_t child, enum pci_id_type type,
uintptr_t *id)
@ -382,6 +406,9 @@ generic_pcie_get_id(device_t pci, device_t child, enum pci_id_type type,
uint32_t rid;
uint16_t pci_rid;
if (type == PCI_ID_OFW_IOMMU)
return (generic_pcie_get_iommu(pci, child, id));
if (type != PCI_ID_MSI)
return (pcib_get_id(pci, child, type, id));

View file

@ -59,6 +59,7 @@ HEADER {
enum pci_id_type {
PCI_ID_RID,
PCI_ID_MSI,
PCI_ID_OFW_IOMMU,
};
enum pci_feature {

View file

@ -59,6 +59,9 @@ pcib_get_id(device_t pcib, device_t dev, enum pci_id_type type, uintptr_t *id)
{
uint8_t bus, slot, func;
if (type == PCI_ID_OFW_IOMMU)
return (PCI_GET_ID(device_get_parent(pcib), dev, type, id));
if (type != PCI_ID_RID)
return (ENXIO);

View file

@ -127,6 +127,11 @@ struct pcicfg_msix {
struct resource *msix_pba_res; /* Resource containing PBA. */
};
struct pci_id_ofw_iommu {
uint32_t id;
uint32_t xref;
};
/* Interesting values for HyperTransport */
struct pcicfg_ht {
uint8_t ht_slave; /* Non-zero if device is an HT slave. */