blob: 0902243ab74cffcbee331f12367acf0d726fc29a [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
Bruce Griffith006364e2014-10-22 03:33:49 -060039static struct device_operations iommu_ops = {
40 .read_resources = iommu_read_resources,
41 .set_resources = iommu_set_resources,
42 .enable_resources = pci_dev_enable_resources,
Angel Pons1fc0edd2020-05-31 00:03:28 +020043 .ops_pci = &pci_dev_ops_pci,
Bruce Griffith006364e2014-10-22 03:33:49 -060044};
45
46static const struct pci_driver iommu_driver __pci_driver = {
47 .ops = &iommu_ops,
48 .vendor = PCI_VENDOR_ID_AMD,
49 .device = PCI_DEVICE_ID_AMD_15H_MODEL_303F_NB_IOMMU,
50};