blob: c87097281325b9377f59c654e70cc6e9195a91e4 [file] [log] [blame]
Angel Ponsae593872020-04-04 18:50:57 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Marc Jonesbc94aea2018-09-26 09:57:08 -06002
3#include <device/device.h>
4#include <device/pci.h>
5#include <device/pci_ids.h>
Marc Jonesbc94aea2018-09-26 09:57:08 -06006#include <lib.h>
7
8static void iommu_read_resources(struct device *dev)
9{
10 struct resource *res;
11
12 /* Get the normal pci resources of this device */
13 pci_dev_read_resources(dev);
14
15 /* Add an extra subtractive resource for both memory and I/O. */
16 res = new_resource(dev, 0x44);
17 res->size = 512 * 1024;
18 res->align = log2(res->size);
19 res->gran = log2(res->size);
20 res->limit = 0xffffffff; /* 4G */
21 res->flags = IORESOURCE_MEM;
22}
23
Marc Jonesbc94aea2018-09-26 09:57:08 -060024static struct device_operations iommu_ops = {
25 .read_resources = iommu_read_resources,
26 .set_resources = pci_dev_set_resources,
27 .enable_resources = pci_dev_enable_resources,
Angel Pons1fc0edd2020-05-31 00:03:28 +020028 .ops_pci = &pci_dev_ops_pci,
Marc Jonesbc94aea2018-09-26 09:57:08 -060029};
30
Marshall Dawsonec63a712019-05-03 12:55:16 -060031static const unsigned short pci_device_ids[] = {
32 PCI_DEVICE_ID_AMD_15H_MODEL_303F_NB_IOMMU,
33 PCI_DEVICE_ID_AMD_15H_MODEL_707F_NB_IOMMU,
Furquan Shaikh590bdc62020-04-15 23:00:44 -070034 PCI_DEVICE_ID_AMD_17H_MODEL_1020_NB_IOMMU,
Marshall Dawsonec63a712019-05-03 12:55:16 -060035 0
36};
37
Marc Jonesbc94aea2018-09-26 09:57:08 -060038static const struct pci_driver iommu_driver __pci_driver = {
39 .ops = &iommu_ops,
40 .vendor = PCI_VENDOR_ID_AMD,
Marshall Dawsonec63a712019-05-03 12:55:16 -060041 .devices = pci_device_ids,
Marc Jonesbc94aea2018-09-26 09:57:08 -060042};