coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
uart.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 /*
4  * The sole purpose of this driver is to avoid BAR to be changed during
5  * resource allocation. Since configuration space is just 32 bytes it
6  * shouldn't cause any fragmentation.
7  */
8 
9 #include <console/uart.h>
10 #include <device/device.h>
11 #include <device/pci.h>
12 #include <device/pci_ops.h>
13 #include <device/pci_ids.h>
14 #include <soc/pci_devs.h>
15 #include <console/console.h>
16 #include <soc/uart.h>
17 #include <fsp/api.h>
18 
19 static void dnv_ns_uart_read_resources(struct device *dev)
20 {
21  /* read resources to be visible in the log*/
23  if (!CONFIG(LEGACY_UART_MODE))
24  return;
25  struct resource *res = probe_resource(dev, PCI_BASE_ADDRESS_0);
26  if (res == NULL)
27  return;
28  res->size = 0x8;
30  /* Do not configure membar */
32  if (res != NULL)
33  res->flags = 0;
34  compact_resources(dev);
35 
36 }
37 
38 static struct device_operations uart_ops = {
40  .set_resources = pci_dev_set_resources,
41  .enable_resources = pci_dev_enable_resources,
42  .init = pci_dev_init,
43 };
44 
45 static const struct pci_driver uart_driver __pci_driver = {
46  .ops = &uart_ops,
47  .vendor = PCI_VID_INTEL,
48  .device = PCI_DID_INTEL_DNV_HSUART
49 };
50 
51 static void hide_hsuarts(void)
52 {
53  int i;
54  printk(BIOS_DEBUG, "HIDING HSUARTs.\n");
55  /* There is a hardware requirement to hide functions starting from the
56  last one. */
57  for (i = DENVERTON_UARTS_TO_INI - 1; i >= 0; i--) {
58  struct device *uart_dev;
59  uart_dev = pcidev_on_root(HSUART_DEV, i);
60  if (uart_dev == NULL)
61  continue;
63  }
64 }
65 
66 /* Hide HSUART PCI device very last when FSP no longer needs it */
68 {
69  if (phase != END_OF_FIRMWARE)
70  return;
71  if (CONFIG(LEGACY_UART_MODE))
72  hide_hsuarts();
73 }
#define printk(level,...)
Definition: stdlib.h:16
DEVTREE_CONST struct device * pcidev_on_root(uint8_t dev, uint8_t fn)
Definition: device_const.c:260
void compact_resources(struct device *dev)
See if we have unused but allocated resource structures.
Definition: device_util.c:302
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
@ CONFIG
Definition: dsi_common.h:201
fsp_notify_phase
Definition: api.h:28
@ END_OF_FIRMWARE
Definition: api.h:31
static __always_inline void pci_or_config32(const struct device *dev, u16 reg, u32 ormask)
Definition: pci_ops.h:191
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define PCI_BASE_ADDRESS_0
Definition: pci_def.h:63
#define PCI_BASE_ADDRESS_1
Definition: pci_def.h:64
void pci_dev_init(struct device *dev)
Default handler: only runs the relevant PCI BIOS.
Definition: pci_device.c:873
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
#define PCI_DID_INTEL_DNV_HSUART
Definition: pci_ids.h:2781
#define PCI_VID_INTEL
Definition: pci_ids.h:2157
#define IORESOURCE_ASSIGNED
Definition: resource.h:34
#define IORESOURCE_IO
Definition: resource.h:9
#define IORESOURCE_FIXED
Definition: resource.h:36
#define HSUART_DEV
Definition: pci_devs.h:167
#define DENVERTON_UARTS_TO_INI
Definition: uart.h:7
#define PCI_FUNC_RDCFG_HIDE
Definition: uart.h:9
static void hide_hsuarts(void)
Definition: uart.c:51
static void dnv_ns_uart_read_resources(struct device *dev)
Definition: uart.c:19
static struct device_operations uart_ops
Definition: uart.c:38
void platform_fsp_notify_status(enum fsp_notify_phase phase)
Definition: uart.c:67
static const struct pci_driver uart_driver __pci_driver
Definition: uart.c:45
#define NULL
Definition: stddef.h:19
void(* read_resources)(struct device *dev)
Definition: device.h:39
Definition: device.h:107
unsigned long flags
Definition: resource.h:49
resource_t size
Definition: resource.h:46