Bruce Griffith | 006364e | 2014-10-22 03:33:49 -0600 | [diff] [blame^] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2013 Rudolf Marek <r.marek@assembler.cz> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include <device/device.h> |
| 21 | #include <device/pci.h> |
| 22 | #include <device/pci_ids.h> |
| 23 | #include <device/pci_ops.h> |
| 24 | #include <lib.h> |
| 25 | |
| 26 | static void iommu_read_resources(device_t dev) |
| 27 | { |
| 28 | struct resource *res; |
| 29 | |
| 30 | /* Get the normal pci resources of this device */ |
| 31 | pci_dev_read_resources(dev); |
| 32 | |
| 33 | /* Add an extra subtractive resource for both memory and I/O. */ |
| 34 | res = new_resource(dev, 0x44); |
| 35 | res->size = 512 * 1024; |
| 36 | res->align = log2(res->size); |
| 37 | res->gran = log2(res->size); |
| 38 | res->limit = 0xffffffff; /* 4G */ |
| 39 | res->flags = IORESOURCE_MEM; |
| 40 | } |
| 41 | |
| 42 | static void iommu_set_resources(device_t dev) |
| 43 | { |
| 44 | struct resource *res; |
| 45 | |
| 46 | pci_dev_set_resources(dev); |
| 47 | |
| 48 | res = find_resource(dev, 0x44); |
| 49 | /* Remember this resource has been stored */ |
| 50 | res->flags |= IORESOURCE_STORED; |
| 51 | /* For now, do only 32-bit space allocation */ |
| 52 | pci_write_config32(dev, 0x48, 0x0); |
| 53 | pci_write_config32(dev, 0x44, res->base | (1 << 0)); |
| 54 | } |
| 55 | |
| 56 | static struct pci_operations lops_pci = { |
| 57 | .set_subsystem = pci_dev_set_subsystem, |
| 58 | }; |
| 59 | |
| 60 | static struct device_operations iommu_ops = { |
| 61 | .read_resources = iommu_read_resources, |
| 62 | .set_resources = iommu_set_resources, |
| 63 | .enable_resources = pci_dev_enable_resources, |
| 64 | .init = 0, |
| 65 | .scan_bus = 0, |
| 66 | .ops_pci = &lops_pci, |
| 67 | }; |
| 68 | |
| 69 | static const struct pci_driver iommu_driver __pci_driver = { |
| 70 | .ops = &iommu_ops, |
| 71 | .vendor = PCI_VENDOR_ID_AMD, |
| 72 | .device = PCI_DEVICE_ID_AMD_15H_MODEL_303F_NB_IOMMU, |
| 73 | }; |