blob: 18d91059595165c07d1877a3a0ee605e32cfca02 [file] [log] [blame]
Marc Jonesbc94aea2018-09-26 09:57:08 -06001/*
2 * This file is part of the coreboot project.
3 *
Marc Jonesbc94aea2018-09-26 09:57:08 -06004 *
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 Jonesbc94aea2018-09-26 09:57:08 -060018#include <lib.h>
19
20static 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
36static struct pci_operations lops_pci = {
37 .set_subsystem = pci_dev_set_subsystem,
38};
39
40static 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 Jonesbc94aea2018-09-26 09:57:08 -060044 .ops_pci = &lops_pci,
45};
46
Marshall Dawsonec63a712019-05-03 12:55:16 -060047static 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 Dawson762621f2019-06-20 14:39:17 -060050 PCI_DEVICE_ID_AMD_17H_MODEL_101F_NB_IOMMU,
Marshall Dawsonec63a712019-05-03 12:55:16 -060051 0
52};
53
Marc Jonesbc94aea2018-09-26 09:57:08 -060054static const struct pci_driver iommu_driver __pci_driver = {
55 .ops = &iommu_ops,
56 .vendor = PCI_VENDOR_ID_AMD,
Marshall Dawsonec63a712019-05-03 12:55:16 -060057 .devices = pci_device_ids,
Marc Jonesbc94aea2018-09-26 09:57:08 -060058};