coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
iommu.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
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 
9 static void iommu_read_resources(struct device *dev)
10 {
11  struct resource *res;
12 
13  /* Get the normal pci resources of this device */
15 
16  /* IOMMU MMIO registers */
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 
25 static void iommu_set_resources(struct device *dev)
26 {
27  struct resource *res;
28 
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 
39 static struct device_operations iommu_ops = {
41  .set_resources = iommu_set_resources,
42  .enable_resources = pci_dev_enable_resources,
43  .ops_pci = &pci_dev_ops_pci,
44 };
45 
46 static const struct pci_driver iommu_driver __pci_driver = {
47  .ops = &iommu_ops,
48  .vendor = PCI_VID_AMD,
50 };
struct resource * new_resource(struct device *dev, unsigned int index)
See if a resource structure already exists for a given index and if not allocate one.
Definition: device_util.c:346
struct resource * find_resource(const struct device *dev, unsigned int index)
Return an existing resource structure for a given index.
Definition: device_util.c:394
static __always_inline void pci_write_config32(const struct device *dev, u16 reg, u32 val)
Definition: pci_ops.h:76
static int log2(u32 x)
Definition: lib.h:53
static void iommu_set_resources(struct device *dev)
Definition: iommu.c:25
static struct device_operations iommu_ops
Definition: iommu.c:39
static void iommu_read_resources(struct device *dev)
Definition: iommu.c:9
static const struct pci_driver iommu_driver __pci_driver
Definition: iommu.c:46
void pci_dev_enable_resources(struct device *dev)
Definition: pci_device.c:721
void pci_dev_read_resources(struct device *dev)
Definition: pci_device.c:534
struct pci_operations pci_dev_ops_pci
Default device operation for PCI devices.
Definition: pci_device.c:911
void pci_dev_set_resources(struct device *dev)
Definition: pci_device.c:691
#define PCI_DID_AMD_15H_MODEL_101F_NB_IOMMU
Definition: pci_ids.h:509
#define PCI_VID_AMD
Definition: pci_ids.h:496
#define IORESOURCE_MEM
Definition: resource.h:10
#define IORESOURCE_STORED
Definition: resource.h:32
void(* read_resources)(struct device *dev)
Definition: device.h:39
Definition: device.h:107
unsigned long flags
Definition: resource.h:49
unsigned char align
Definition: resource.h:51
resource_t limit
Definition: resource.h:47
unsigned char gran
Definition: resource.h:52
resource_t base
Definition: resource.h:45
resource_t size
Definition: resource.h:46