blob: 08486cc0ee22c12c43410bdeed49246ce3a1ffdd [file] [log] [blame]
Angel Pons4b429832020-04-02 23:48:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Bruce Griffith006364e2014-10-22 03:33:49 -06002
3#include <device/device.h>
4#include <device/pci.h>
5#include <device/pci_ids.h>
6#include <device/pci_ops.h>
7#include <lib.h>
8
Elyes HAOUASc8a649c2018-06-10 23:36:44 +02009static void iommu_read_resources(struct device *dev)
Bruce Griffith006364e2014-10-22 03:33:49 -060010{
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
Elyes HAOUASc8a649c2018-06-10 23:36:44 +020025static void iommu_set_resources(struct device *dev)
Bruce Griffith006364e2014-10-22 03:33:49 -060026{
27 struct resource *res;
28
29 pci_dev_set_resources(dev);
30
31 res = find_resource(dev, 0x44);
32 /* Remember this resource has been stored */
33 res->flags |= IORESOURCE_STORED;
34 /* For now, do only 32-bit space allocation */
35 pci_write_config32(dev, 0x48, 0x0);
36 pci_write_config32(dev, 0x44, res->base | (1 << 0));
37}
38
39static struct pci_operations lops_pci = {
40 .set_subsystem = pci_dev_set_subsystem,
41};
42
43static struct device_operations iommu_ops = {
44 .read_resources = iommu_read_resources,
45 .set_resources = iommu_set_resources,
46 .enable_resources = pci_dev_enable_resources,
Bruce Griffith006364e2014-10-22 03:33:49 -060047 .ops_pci = &lops_pci,
48};
49
50static const struct pci_driver iommu_driver __pci_driver = {
51 .ops = &iommu_ops,
52 .vendor = PCI_VENDOR_ID_AMD,
53 .device = PCI_DEVICE_ID_AMD_15H_MODEL_303F_NB_IOMMU,
54};