coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
oxpcie.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_def.h>
5 #include <device/pci.h>
6 #include <console/console.h>
7 #include <console/uart.h>
8 #include <device/mmio.h>
9 #include <device/pci_ops.h>
10 
11 static void oxford_oxpcie_enable(struct device *dev)
12 {
13  printk(BIOS_DEBUG, "Initializing Oxford OXPCIe952\n");
14 
15  struct resource *res = probe_resource(dev, PCI_BASE_ADDRESS_0);
16  if (!res) {
17  printk(BIOS_WARNING, "OXPCIe952: No UART resource found.\n");
18  return;
19  }
20  void *bar0 = res2mmio(res, 0, 0);
21 
22  printk(BIOS_DEBUG, "OXPCIe952: Class=%x Revision ID=%x\n",
23  (read32(bar0) >> 8), (read32(bar0) & 0xff));
24  printk(BIOS_DEBUG, "OXPCIe952: %d UARTs detected.\n",
25  (read32(bar0 + 4) & 3));
26  printk(BIOS_DEBUG, "OXPCIe952: UART BAR: 0x%x\n", (u32)res->base);
27 }
28 
29 static void oxford_oxpcie_set_resources(struct device *dev)
30 {
32 
33  /* Re-initialize OXPCIe base address after set_resources */
34  u32 mmio_base = pci_read_config32(dev, PCI_BASE_ADDRESS_0);
35  oxford_remap(mmio_base & ~0xf);
36 }
37 
38 static struct device_operations oxford_oxpcie_ops = {
40  .set_resources = oxford_oxpcie_set_resources,
41  .enable_resources = pci_dev_enable_resources,
42  .init = oxford_oxpcie_enable,
43 };
44 
45 static const struct pci_driver oxford_oxpcie_driver __pci_driver = {
46  .ops = &oxford_oxpcie_ops,
47  .vendor = 0x1415,
48  .device = 0xc158,
49 };
50 
51 static const struct pci_driver oxford_oxpcie_driver_2 __pci_driver = {
52  .ops = &oxford_oxpcie_ops,
53  .vendor = 0x1415,
54  .device = 0xc11b,
55 };
static uint32_t read32(const void *addr)
Definition: mmio.h:22
#define printk(level,...)
Definition: stdlib.h:16
struct resource * probe_resource(const struct device *dev, unsigned int index)
See if a resource structure already exists for a given index.
Definition: device_util.c:323
static __always_inline u32 pci_read_config32(const struct device *dev, u16 reg)
Definition: pci_ops.h:58
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define BIOS_WARNING
BIOS_WARNING - Bad configuration.
Definition: loglevel.h:86
static void oxford_oxpcie_set_resources(struct device *dev)
Definition: oxpcie.c:29
static struct device_operations oxford_oxpcie_ops
Definition: oxpcie.c:38
static void oxford_oxpcie_enable(struct device *dev)
Definition: oxpcie.c:11
static const struct pci_driver oxford_oxpcie_driver __pci_driver
Definition: oxpcie.c:45
void oxford_remap(u32 new_base)
Definition: oxpcie_early.c:65
#define PCI_BASE_ADDRESS_0
Definition: pci_def.h:63
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
void pci_dev_set_resources(struct device *dev)
Definition: pci_device.c:691
static void * res2mmio(const struct resource *res, unsigned long offset, unsigned long mask)
Definition: resource.h:87
uint32_t u32
Definition: stdint.h:51
void(* read_resources)(struct device *dev)
Definition: device.h:39
Definition: device.h:107
resource_t base
Definition: resource.h:45