blob: 0154acefbdfc9c03e409ee5139085b50b4b74c98 [file] [log] [blame]
Bruce Griffith006364e2014-10-22 03:33:49 -06001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2013 Rudolf Marek <r.marek@assembler.cz>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Bruce Griffith006364e2014-10-22 03:33:49 -060014 */
15
16#include <device/device.h>
17#include <device/pci.h>
18#include <device/pci_ids.h>
19#include <device/pci_ops.h>
20#include <lib.h>
21
Elyes HAOUASc8a649c2018-06-10 23:36:44 +020022static void iommu_read_resources(struct device *dev)
Bruce Griffith006364e2014-10-22 03:33:49 -060023{
24 struct resource *res;
25
26 /* Get the normal pci resources of this device */
27 pci_dev_read_resources(dev);
28
29 /* Add an extra subtractive resource for both memory and I/O. */
30 res = new_resource(dev, 0x44);
31 res->size = 512 * 1024;
32 res->align = log2(res->size);
33 res->gran = log2(res->size);
34 res->limit = 0xffffffff; /* 4G */
35 res->flags = IORESOURCE_MEM;
36}
37
Elyes HAOUASc8a649c2018-06-10 23:36:44 +020038static void iommu_set_resources(struct device *dev)
Bruce Griffith006364e2014-10-22 03:33:49 -060039{
40 struct resource *res;
41
42 pci_dev_set_resources(dev);
43
44 res = find_resource(dev, 0x44);
45 /* Remember this resource has been stored */
46 res->flags |= IORESOURCE_STORED;
47 /* For now, do only 32-bit space allocation */
48 pci_write_config32(dev, 0x48, 0x0);
49 pci_write_config32(dev, 0x44, res->base | (1 << 0));
50}
51
52static struct pci_operations lops_pci = {
53 .set_subsystem = pci_dev_set_subsystem,
54};
55
56static struct device_operations iommu_ops = {
57 .read_resources = iommu_read_resources,
58 .set_resources = iommu_set_resources,
59 .enable_resources = pci_dev_enable_resources,
60 .init = 0,
61 .scan_bus = 0,
62 .ops_pci = &lops_pci,
63};
64
65static const struct pci_driver iommu_driver __pci_driver = {
66 .ops = &iommu_ops,
67 .vendor = PCI_VENDOR_ID_AMD,
68 .device = PCI_DEVICE_ID_AMD_15H_MODEL_303F_NB_IOMMU,
69};