blob: d9517c814c738b49bc5f70513f77c6d0f00acb11 [file] [log] [blame]
Angel Ponsae593872020-04-04 18:50:57 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Marc Jonesbc94aea2018-09-26 09:57:08 -06003
4#include <device/device.h>
5#include <device/pci.h>
6#include <device/pci_ids.h>
Marc Jonesbc94aea2018-09-26 09:57:08 -06007#include <lib.h>
8
9static void iommu_read_resources(struct device *dev)
10{
11 struct resource *res;
12
13 /* Get the normal pci resources of this device */
14 pci_dev_read_resources(dev);
15
16 /* Add an extra subtractive resource for both memory and I/O. */
17 res = new_resource(dev, 0x44);
18 res->size = 512 * 1024;
19 res->align = log2(res->size);
20 res->gran = log2(res->size);
21 res->limit = 0xffffffff; /* 4G */
22 res->flags = IORESOURCE_MEM;
23}
24
25static struct pci_operations lops_pci = {
26 .set_subsystem = pci_dev_set_subsystem,
27};
28
29static struct device_operations iommu_ops = {
30 .read_resources = iommu_read_resources,
31 .set_resources = pci_dev_set_resources,
32 .enable_resources = pci_dev_enable_resources,
Marc Jonesbc94aea2018-09-26 09:57:08 -060033 .ops_pci = &lops_pci,
34};
35
Marshall Dawsonec63a712019-05-03 12:55:16 -060036static const unsigned short pci_device_ids[] = {
37 PCI_DEVICE_ID_AMD_15H_MODEL_303F_NB_IOMMU,
38 PCI_DEVICE_ID_AMD_15H_MODEL_707F_NB_IOMMU,
Furquan Shaikh590bdc62020-04-15 23:00:44 -070039 PCI_DEVICE_ID_AMD_17H_MODEL_1020_NB_IOMMU,
Marshall Dawsonec63a712019-05-03 12:55:16 -060040 0
41};
42
Marc Jonesbc94aea2018-09-26 09:57:08 -060043static const struct pci_driver iommu_driver __pci_driver = {
44 .ops = &iommu_ops,
45 .vendor = PCI_VENDOR_ID_AMD,
Marshall Dawsonec63a712019-05-03 12:55:16 -060046 .devices = pci_device_ids,
Marc Jonesbc94aea2018-09-26 09:57:08 -060047};