blob: 4f20dd4117b1792fa83ab47338493c093a33e025 [file] [log] [blame]
Angel Ponsae593872020-04-04 18:50:57 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Marc Jonesbc94aea2018-09-26 09:57:08 -06002
3#include <device/device.h>
4#include <device/pci.h>
5#include <device/pci_ids.h>
Marc Jonesbc94aea2018-09-26 09:57:08 -06006#include <lib.h>
7
8static void iommu_read_resources(struct device *dev)
9{
10 struct resource *res;
11
12 /* Get the normal pci resources of this device */
13 pci_dev_read_resources(dev);
14
Felix Heldddf137f2022-02-04 19:27:48 +010015 /* IOMMU MMIO registers */
Marc Jonesbc94aea2018-09-26 09:57:08 -060016 res = new_resource(dev, 0x44);
Felix Held6ebcdf32021-10-12 21:39:27 +020017 res->size = 512 * KiB;
Marc Jonesbc94aea2018-09-26 09:57:08 -060018 res->align = log2(res->size);
19 res->gran = log2(res->size);
20 res->limit = 0xffffffff; /* 4G */
21 res->flags = IORESOURCE_MEM;
22}
23
Felix Held8aa9edf2021-02-17 00:15:12 +010024#if CONFIG(HAVE_ACPI_TABLES)
25static const char *iommu_acpi_name(const struct device *dev)
26{
27 return "IOMM";
28}
29#endif
30
Marc Jonesbc94aea2018-09-26 09:57:08 -060031static struct device_operations iommu_ops = {
32 .read_resources = iommu_read_resources,
33 .set_resources = pci_dev_set_resources,
34 .enable_resources = pci_dev_enable_resources,
Angel Pons1fc0edd2020-05-31 00:03:28 +020035 .ops_pci = &pci_dev_ops_pci,
Felix Held8aa9edf2021-02-17 00:15:12 +010036#if CONFIG(HAVE_ACPI_TABLES)
37 .acpi_name = iommu_acpi_name,
38#endif
Marc Jonesbc94aea2018-09-26 09:57:08 -060039};
40
Marshall Dawsonec63a712019-05-03 12:55:16 -060041static const unsigned short pci_device_ids[] = {
Felix Singer43b7f412022-03-07 04:34:52 +010042 PCI_DID_AMD_15H_MODEL_303F_NB_IOMMU,
43 PCI_DID_AMD_15H_MODEL_707F_NB_IOMMU,
44 PCI_DID_AMD_17H_MODEL_1020_NB_IOMMU,
45 PCI_DID_AMD_17H_MODEL_606F_NB_IOMMU,
46 PCI_DID_AMD_17H_MODEL_A0AF_NB_IOMMU,
Marshall Dawsonec63a712019-05-03 12:55:16 -060047 0
48};
49
Marc Jonesbc94aea2018-09-26 09:57:08 -060050static const struct pci_driver iommu_driver __pci_driver = {
51 .ops = &iommu_ops,
Felix Singer43b7f412022-03-07 04:34:52 +010052 .vendor = PCI_VID_AMD,
Marshall Dawsonec63a712019-05-03 12:55:16 -060053 .devices = pci_device_ids,
Marc Jonesbc94aea2018-09-26 09:57:08 -060054};