1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <amdblocks/iommu.h>
4 #include <console/console.h>
5 #include <device/device.h>
6 #include <device/pci.h>
9 static void iommu_read_resources(struct device
*dev
)
13 /* Get the normal pci resources of this device */
14 pci_dev_read_resources(dev
);
16 /* IOMMU MMIO registers */
17 res
= new_resource(dev
, IOMMU_CAP_BASE_LO
);
18 res
->size
= 512 * KiB
;
19 res
->align
= log2(res
->size
);
20 res
->gran
= log2(res
->size
);
21 res
->limit
= 0xffffffff; /* 4G */
22 res
->flags
= IORESOURCE_MEM
;
26 static void iommu_enable_resources(struct device
*dev
)
28 uint32_t base
= pci_read_config32(dev
, IOMMU_CAP_BASE_LO
);
30 pci_write_config32(dev
, IOMMU_CAP_BASE_LO
, base
);
31 printk(BIOS_DEBUG
, "%s -> mmio enable: %08X", __func__
,
32 pci_read_config32(dev
, IOMMU_CAP_BASE_LO
));
33 pci_dev_enable_resources(dev
);
36 #if CONFIG(HAVE_ACPI_TABLES)
37 static const char *iommu_acpi_name(const struct device
*dev
)
43 struct device_operations amd_iommu_ops
= {
44 .read_resources
= iommu_read_resources
,
45 .set_resources
= pci_dev_set_resources
,
46 .enable_resources
= iommu_enable_resources
,
47 .ops_pci
= &pci_dev_ops_pci
,
48 #if CONFIG(HAVE_ACPI_TABLES)
49 .acpi_name
= iommu_acpi_name
,