Angel Pons | ae59387 | 2020-04-04 18:50:57 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Marc Jones | bc94aea | 2018-09-26 09:57:08 -0600 | [diff] [blame] | 2 | |
| 3 | #include <device/device.h> |
| 4 | #include <device/pci.h> |
| 5 | #include <device/pci_ids.h> |
Marc Jones | bc94aea | 2018-09-26 09:57:08 -0600 | [diff] [blame] | 6 | #include <lib.h> |
| 7 | |
| 8 | static 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 | |
| 15 | /* Add an extra subtractive resource for both memory and I/O. */ |
| 16 | res = new_resource(dev, 0x44); |
| 17 | res->size = 512 * 1024; |
| 18 | res->align = log2(res->size); |
| 19 | res->gran = log2(res->size); |
| 20 | res->limit = 0xffffffff; /* 4G */ |
| 21 | res->flags = IORESOURCE_MEM; |
| 22 | } |
| 23 | |
Felix Held | 8aa9edf | 2021-02-17 00:15:12 +0100 | [diff] [blame] | 24 | #if CONFIG(HAVE_ACPI_TABLES) |
| 25 | static const char *iommu_acpi_name(const struct device *dev) |
| 26 | { |
| 27 | return "IOMM"; |
| 28 | } |
| 29 | #endif |
| 30 | |
Marc Jones | bc94aea | 2018-09-26 09:57:08 -0600 | [diff] [blame] | 31 | static 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 Pons | 1fc0edd | 2020-05-31 00:03:28 +0200 | [diff] [blame] | 35 | .ops_pci = &pci_dev_ops_pci, |
Felix Held | 8aa9edf | 2021-02-17 00:15:12 +0100 | [diff] [blame] | 36 | #if CONFIG(HAVE_ACPI_TABLES) |
| 37 | .acpi_name = iommu_acpi_name, |
| 38 | #endif |
Marc Jones | bc94aea | 2018-09-26 09:57:08 -0600 | [diff] [blame] | 39 | }; |
| 40 | |
Marshall Dawson | ec63a71 | 2019-05-03 12:55:16 -0600 | [diff] [blame] | 41 | static const unsigned short pci_device_ids[] = { |
| 42 | PCI_DEVICE_ID_AMD_15H_MODEL_303F_NB_IOMMU, |
| 43 | PCI_DEVICE_ID_AMD_15H_MODEL_707F_NB_IOMMU, |
Furquan Shaikh | 590bdc6 | 2020-04-15 23:00:44 -0700 | [diff] [blame] | 44 | PCI_DEVICE_ID_AMD_17H_MODEL_1020_NB_IOMMU, |
Raul E Rangel | 3acc515 | 2021-06-09 13:36:10 -0600 | [diff] [blame] | 45 | PCI_DEVICE_ID_AMD_17H_MODEL_606F_NB_IOMMU, |
Marshall Dawson | ec63a71 | 2019-05-03 12:55:16 -0600 | [diff] [blame] | 46 | 0 |
| 47 | }; |
| 48 | |
Marc Jones | bc94aea | 2018-09-26 09:57:08 -0600 | [diff] [blame] | 49 | static const struct pci_driver iommu_driver __pci_driver = { |
| 50 | .ops = &iommu_ops, |
| 51 | .vendor = PCI_VENDOR_ID_AMD, |
Marshall Dawson | ec63a71 | 2019-05-03 12:55:16 -0600 | [diff] [blame] | 52 | .devices = pci_device_ids, |
Marc Jones | bc94aea | 2018-09-26 09:57:08 -0600 | [diff] [blame] | 53 | }; |