Angel Pons | 4b42983 | 2020-04-02 23:48:50 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Bruce Griffith | 006364e | 2014-10-22 03:33:49 -0600 | [diff] [blame] | 2 | |
| 3 | #include <device/device.h> |
| 4 | #include <device/pci.h> |
| 5 | #include <device/pci_ids.h> |
| 6 | #include <device/pci_ops.h> |
| 7 | #include <lib.h> |
| 8 | |
Elyes HAOUAS | c8a649c | 2018-06-10 23:36:44 +0200 | [diff] [blame] | 9 | static void iommu_read_resources(struct device *dev) |
Bruce Griffith | 006364e | 2014-10-22 03:33:49 -0600 | [diff] [blame] | 10 | { |
| 11 | struct resource *res; |
| 12 | |
| 13 | /* Get the normal pci resources of this device */ |
| 14 | pci_dev_read_resources(dev); |
| 15 | |
| 16 | /* Add an extra subtractive resource for both memory and I/O. */ |
| 17 | res = new_resource(dev, 0x44); |
| 18 | res->size = 512 * 1024; |
| 19 | res->align = log2(res->size); |
| 20 | res->gran = log2(res->size); |
| 21 | res->limit = 0xffffffff; /* 4G */ |
| 22 | res->flags = IORESOURCE_MEM; |
| 23 | } |
| 24 | |
Elyes HAOUAS | c8a649c | 2018-06-10 23:36:44 +0200 | [diff] [blame] | 25 | static void iommu_set_resources(struct device *dev) |
Bruce Griffith | 006364e | 2014-10-22 03:33:49 -0600 | [diff] [blame] | 26 | { |
| 27 | struct resource *res; |
| 28 | |
| 29 | pci_dev_set_resources(dev); |
| 30 | |
| 31 | res = find_resource(dev, 0x44); |
| 32 | /* Remember this resource has been stored */ |
| 33 | res->flags |= IORESOURCE_STORED; |
| 34 | /* For now, do only 32-bit space allocation */ |
| 35 | pci_write_config32(dev, 0x48, 0x0); |
| 36 | pci_write_config32(dev, 0x44, res->base | (1 << 0)); |
| 37 | } |
| 38 | |
| 39 | static struct pci_operations lops_pci = { |
| 40 | .set_subsystem = pci_dev_set_subsystem, |
| 41 | }; |
| 42 | |
| 43 | static struct device_operations iommu_ops = { |
| 44 | .read_resources = iommu_read_resources, |
| 45 | .set_resources = iommu_set_resources, |
| 46 | .enable_resources = pci_dev_enable_resources, |
Bruce Griffith | 006364e | 2014-10-22 03:33:49 -0600 | [diff] [blame] | 47 | .ops_pci = &lops_pci, |
| 48 | }; |
| 49 | |
| 50 | static const struct pci_driver iommu_driver __pci_driver = { |
| 51 | .ops = &iommu_ops, |
| 52 | .vendor = PCI_VENDOR_ID_AMD, |
| 53 | .device = PCI_DEVICE_ID_AMD_15H_MODEL_303F_NB_IOMMU, |
| 54 | }; |