Rudolf Marek | 88ebbeb | 2013-05-27 16:06:43 +0200 | [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. |
Rudolf Marek | 88ebbeb | 2013-05-27 16:06:43 +0200 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <device/device.h> |
| 17 | #include <device/pci.h> |
| 18 | #include <device/pci_ids.h> |
| 19 | #include <device/pci_ops.h> |
| 20 | #include <lib.h> |
| 21 | |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 22 | static void iommu_read_resources(struct device *dev) |
Rudolf Marek | 88ebbeb | 2013-05-27 16:06:43 +0200 | [diff] [blame] | 23 | { |
| 24 | struct resource *res; |
| 25 | |
| 26 | /* Get the normal pci resources of this device */ |
| 27 | pci_dev_read_resources(dev); |
| 28 | |
| 29 | /* Add an extra subtractive resource for both memory and I/O. */ |
| 30 | res = new_resource(dev, 0x44); |
| 31 | res->size = 512 * 1024; |
| 32 | res->align = log2(res->size); |
| 33 | res->gran = log2(res->size); |
| 34 | res->limit = 0xffffffff; /* 4G */ |
| 35 | res->flags = IORESOURCE_MEM; |
| 36 | } |
| 37 | |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 38 | static void iommu_set_resources(struct device *dev) |
Rudolf Marek | 88ebbeb | 2013-05-27 16:06:43 +0200 | [diff] [blame] | 39 | { |
| 40 | struct resource *res; |
| 41 | |
| 42 | pci_dev_set_resources(dev); |
| 43 | |
| 44 | res = find_resource(dev, 0x44); |
| 45 | /* Remember this resource has been stored */ |
| 46 | res->flags |= IORESOURCE_STORED; |
| 47 | /* For now, do only 32-bit space allocation */ |
| 48 | pci_write_config32(dev, 0x48, 0x0); |
| 49 | pci_write_config32(dev, 0x44, res->base | (1 << 0)); |
| 50 | } |
| 51 | |
| 52 | static struct pci_operations lops_pci = { |
| 53 | .set_subsystem = pci_dev_set_subsystem, |
| 54 | }; |
| 55 | |
| 56 | static struct device_operations iommu_ops = { |
| 57 | .read_resources = iommu_read_resources, |
| 58 | .set_resources = iommu_set_resources, |
| 59 | .enable_resources = pci_dev_enable_resources, |
| 60 | .init = 0, |
| 61 | .scan_bus = 0, |
| 62 | .ops_pci = &lops_pci, |
| 63 | }; |
| 64 | |
| 65 | static const struct pci_driver iommu_driver __pci_driver = { |
| 66 | .ops = &iommu_ops, |
| 67 | .vendor = PCI_VENDOR_ID_AMD, |
Marshall Dawson | 8b199ce | 2019-07-18 07:34:20 -0600 | [diff] [blame^] | 68 | .device = PCI_DEVICE_ID_AMD_15H_MODEL_101F_NB_IOMMU, |
Rudolf Marek | 88ebbeb | 2013-05-27 16:06:43 +0200 | [diff] [blame] | 69 | }; |