2 * This file is part of the coreboot project.
4 * Copyright (C) 2013 Rudolf Marek <r.marek@assembler.cz>
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.
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.
16 #include <device/device.h>
17 #include <device/pci.h>
18 #include <device/pci_ids.h>
19 #include <device/pci_ops.h>
22 static void iommu_read_resources(device_t dev
)
26 /* Get the normal pci resources of this device */
27 pci_dev_read_resources(dev
);
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
;
38 static void iommu_set_resources(device_t dev
)
42 pci_dev_set_resources(dev
);
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));
52 static struct pci_operations lops_pci
= {
53 .set_subsystem
= pci_dev_set_subsystem
,
56 static struct device_operations iommu_ops
= {
57 .read_resources
= iommu_read_resources
,
58 .set_resources
= iommu_set_resources
,
59 .enable_resources
= pci_dev_enable_resources
,
65 static const struct pci_driver iommu_driver __pci_driver
= {
67 .vendor
= PCI_VENDOR_ID_AMD
,
68 .device
= PCI_DEVICE_ID_AMD_15H_NB_IOMMU
,