Marc Jones | bc94aea | 2018-09-26 09:57:08 -0600 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Marc Jones | bc94aea | 2018-09-26 09:57:08 -0600 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; version 2 of the License. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | */ |
| 14 | |
| 15 | #include <device/device.h> |
| 16 | #include <device/pci.h> |
| 17 | #include <device/pci_ids.h> |
Marc Jones | bc94aea | 2018-09-26 09:57:08 -0600 | [diff] [blame] | 18 | #include <lib.h> |
| 19 | |
| 20 | static void iommu_read_resources(struct device *dev) |
| 21 | { |
| 22 | struct resource *res; |
| 23 | |
| 24 | /* Get the normal pci resources of this device */ |
| 25 | pci_dev_read_resources(dev); |
| 26 | |
| 27 | /* Add an extra subtractive resource for both memory and I/O. */ |
| 28 | res = new_resource(dev, 0x44); |
| 29 | res->size = 512 * 1024; |
| 30 | res->align = log2(res->size); |
| 31 | res->gran = log2(res->size); |
| 32 | res->limit = 0xffffffff; /* 4G */ |
| 33 | res->flags = IORESOURCE_MEM; |
| 34 | } |
| 35 | |
| 36 | static struct pci_operations lops_pci = { |
| 37 | .set_subsystem = pci_dev_set_subsystem, |
| 38 | }; |
| 39 | |
| 40 | static struct device_operations iommu_ops = { |
| 41 | .read_resources = iommu_read_resources, |
| 42 | .set_resources = pci_dev_set_resources, |
| 43 | .enable_resources = pci_dev_enable_resources, |
Marc Jones | bc94aea | 2018-09-26 09:57:08 -0600 | [diff] [blame] | 44 | .ops_pci = &lops_pci, |
| 45 | }; |
| 46 | |
Marshall Dawson | ec63a71 | 2019-05-03 12:55:16 -0600 | [diff] [blame] | 47 | static const unsigned short pci_device_ids[] = { |
| 48 | PCI_DEVICE_ID_AMD_15H_MODEL_303F_NB_IOMMU, |
| 49 | PCI_DEVICE_ID_AMD_15H_MODEL_707F_NB_IOMMU, |
Marshall Dawson | 762621f | 2019-06-20 14:39:17 -0600 | [diff] [blame] | 50 | PCI_DEVICE_ID_AMD_17H_MODEL_101F_NB_IOMMU, |
Marshall Dawson | ec63a71 | 2019-05-03 12:55:16 -0600 | [diff] [blame] | 51 | 0 |
| 52 | }; |
| 53 | |
Marc Jones | bc94aea | 2018-09-26 09:57:08 -0600 | [diff] [blame] | 54 | static const struct pci_driver iommu_driver __pci_driver = { |
| 55 | .ops = &iommu_ops, |
| 56 | .vendor = PCI_VENDOR_ID_AMD, |
Marshall Dawson | ec63a71 | 2019-05-03 12:55:16 -0600 | [diff] [blame] | 57 | .devices = pci_device_ids, |
Marc Jones | bc94aea | 2018-09-26 09:57:08 -0600 | [diff] [blame] | 58 | }; |