blob: c1b294526e91eb1f06f13b35cc2c296619113201 [file] [log] [blame]
Angel Pons4b429832020-04-02 23:48:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Bruce Griffith006364e2014-10-22 03:33:49 -06003
4#include <device/device.h>
5#include <device/pci.h>
6#include <device/pci_ids.h>
7#include <device/pci_ops.h>
8#include <lib.h>
9
Elyes HAOUASc8a649c2018-06-10 23:36:44 +020010static void iommu_read_resources(struct device *dev)
Bruce Griffith006364e2014-10-22 03:33:49 -060011{
12 struct resource *res;
13
14 /* Get the normal pci resources of this device */
15 pci_dev_read_resources(dev);
16
17 /* Add an extra subtractive resource for both memory and I/O. */
18 res = new_resource(dev, 0x44);
19 res->size = 512 * 1024;
20 res->align = log2(res->size);
21 res->gran = log2(res->size);
22 res->limit = 0xffffffff; /* 4G */
23 res->flags = IORESOURCE_MEM;
24}
25
Elyes HAOUASc8a649c2018-06-10 23:36:44 +020026static void iommu_set_resources(struct device *dev)
Bruce Griffith006364e2014-10-22 03:33:49 -060027{
28 struct resource *res;
29
30 pci_dev_set_resources(dev);
31
32 res = find_resource(dev, 0x44);
33 /* Remember this resource has been stored */
34 res->flags |= IORESOURCE_STORED;
35 /* For now, do only 32-bit space allocation */
36 pci_write_config32(dev, 0x48, 0x0);
37 pci_write_config32(dev, 0x44, res->base | (1 << 0));
38}
39
40static struct pci_operations lops_pci = {
41 .set_subsystem = pci_dev_set_subsystem,
42};
43
44static struct device_operations iommu_ops = {
45 .read_resources = iommu_read_resources,
46 .set_resources = iommu_set_resources,
47 .enable_resources = pci_dev_enable_resources,
Bruce Griffith006364e2014-10-22 03:33:49 -060048 .ops_pci = &lops_pci,
49};
50
51static const struct pci_driver iommu_driver __pci_driver = {
52 .ops = &iommu_ops,
53 .vendor = PCI_VENDOR_ID_AMD,
54 .device = PCI_DEVICE_ID_AMD_15H_MODEL_303F_NB_IOMMU,
55};