Kyösti Mälkki | 03eb8a8 | 2016-06-14 14:49:07 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Kyösti Mälkki | 03eb8a8 | 2016-06-14 14:49:07 -0500 | [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> |
Kyösti Mälkki | 03eb8a8 | 2016-06-14 14:49:07 -0500 | [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 void iommu_set_resources(struct device *dev) |
| 37 | { |
| 38 | pci_dev_set_resources(dev); |
| 39 | } |
| 40 | |
| 41 | static struct pci_operations lops_pci = { |
| 42 | .set_subsystem = pci_dev_set_subsystem, |
| 43 | }; |
| 44 | |
| 45 | static struct device_operations iommu_ops = { |
| 46 | .read_resources = iommu_read_resources, |
| 47 | .set_resources = iommu_set_resources, |
| 48 | .enable_resources = pci_dev_enable_resources, |
Kyösti Mälkki | 03eb8a8 | 2016-06-14 14:49:07 -0500 | [diff] [blame] | 49 | .ops_pci = &lops_pci, |
| 50 | }; |
| 51 | |
| 52 | static const struct pci_driver iommu_driver __pci_driver = { |
| 53 | .ops = &iommu_ops, |
| 54 | .vendor = PCI_VENDOR_ID_AMD, |
| 55 | .device = PCI_DEVICE_ID_AMD_16H_MODEL_303F_NB_IOMMU, |
| 56 | }; |