blob: b504e173fc84cc0b7ca1029a8090fd3261ff1038 [file] [log] [blame]
Angel Pons4b429832020-04-02 23:48:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Rudolf Marek88ebbeb2013-05-27 16:06:43 +02002
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
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +03009static void iommu_read_resources(struct device *dev)
Rudolf Marek88ebbeb2013-05-27 16:06:43 +020010{
11 struct resource *res;
12
13 /* Get the normal pci resources of this device */
14 pci_dev_read_resources(dev);
15
Felix Heldddf137f2022-02-04 19:27:48 +010016 /* IOMMU MMIO registers */
Rudolf Marek88ebbeb2013-05-27 16:06:43 +020017 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
Kyösti Mälkkie2c2a4c2018-05-20 20:59:52 +030025static void iommu_set_resources(struct device *dev)
Rudolf Marek88ebbeb2013-05-27 16:06:43 +020026{
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
Rudolf Marek88ebbeb2013-05-27 16:06:43 +020039static 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,
Rudolf Marek88ebbeb2013-05-27 16:06:43 +020044};
45
46static const struct pci_driver iommu_driver __pci_driver = {
47 .ops = &iommu_ops,
Felix Singer43b7f412022-03-07 04:34:52 +010048 .vendor = PCI_VID_AMD,
49 .device = PCI_DID_AMD_15H_MODEL_101F_NB_IOMMU,
Rudolf Marek88ebbeb2013-05-27 16:06:43 +020050};