coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
bootblock.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <arch/bootblock.h>
4 #include <arch/io.h>
5 #include <device/pci_ops.h>
6 #include <soc/iosf.h>
7 #include <soc/iomap.h>
8 #include <soc/gpio.h>
9 #include <soc/lpc.h>
10 #include <soc/spi.h>
11 #include <soc/pm.h>
12 
13 static void program_base_addresses(void)
14 {
15  uint32_t reg;
16  const uint32_t lpc_dev = PCI_DEV(0, LPC_DEV, LPC_FUNC);
17 
18  /* Memory Mapped IO registers. */
19  reg = PMC_BASE_ADDRESS | 2;
20  pci_write_config32(lpc_dev, PBASE, reg);
21  reg = IO_BASE_ADDRESS | 2;
22  pci_write_config32(lpc_dev, IOBASE, reg);
23  reg = ILB_BASE_ADDRESS | 2;
24  pci_write_config32(lpc_dev, IBASE, reg);
25  reg = SPI_BASE_ADDRESS | 2;
26  pci_write_config32(lpc_dev, SBASE, reg);
27  reg = MPHY_BASE_ADDRESS | 2;
28  pci_write_config32(lpc_dev, MPBASE, reg);
29  reg = PUNIT_BASE_ADDRESS | 2;
30  pci_write_config32(lpc_dev, PUBASE, reg);
31  reg = RCBA_BASE_ADDRESS | 1;
32  pci_write_config32(lpc_dev, RCBA, reg);
33 
34  /* IO Port Registers. */
35  reg = ACPI_BASE_ADDRESS | 2;
36  pci_write_config32(lpc_dev, ABASE, reg);
37  reg = GPIO_BASE_ADDRESS | 2;
38  pci_write_config32(lpc_dev, GBASE, reg);
39 }
40 
41 static void tco_disable(void)
42 {
43  uint32_t reg;
44 
46  reg |= TCO_TMR_HALT;
48 }
49 
50 static void spi_init(void)
51 {
52  void *scs = (void *)(SPI_BASE_ADDRESS + SCS);
53  void *bcr = (void *)(SPI_BASE_ADDRESS + BCR);
54  uint32_t reg;
55 
56  /* Disable generating SMI when setting WPD bit. */
57  write32(scs, read32(scs) & ~SMIWPEN);
58  /*
59  * Enable caching and prefetching in the SPI controller. Disable
60  * the SMM-only BIOS write and set WPD bit.
61  */
62  reg = (read32(bcr) & ~SRC_MASK) | SRC_CACHE_PREFETCH | BCR_WPD;
63  reg &= ~EISS;
64  write32(bcr, reg);
65 }
66 
67 static void byt_config_com1_and_enable(void)
68 {
69  uint32_t reg;
70 
71  /* Enable the UART hardware for COM1. */
72  reg = 1;
74 
75  /* Set up the pads to select the UART function */
78 }
79 
80 static void setup_mmconfig(void)
81 {
82  uint32_t reg;
83 
84  /*
85  * Set up the MMCONF range. The register lives in the BUNIT. The IO variant of the
86  * config access needs to be used initially to properly configure as the IOSF access
87  * registers live in PCI config space.
88  */
89  reg = 0;
90  /* Clear the extended register. */
92  reg = CONFIG_ECAM_MMCONF_BASE_ADDRESS | 1;
97 }
98 
99 /* The distinction between nb/sb/cpu is not applicable here so
100  just pick the one that is called first. */
102 {
103  /* Allow memory-mapped PCI config access */
104  setup_mmconfig();
105 
106  /* Early chipset initialization */
108  tco_disable();
109 
110  if (CONFIG(ENABLE_BUILTIN_COM1))
112 
113  spi_init();
114 }
#define SPI_BASE_ADDRESS
Definition: iomap.h:8
static void write32(void *addr, uint32_t val)
Definition: mmio.h:40
static uint32_t read32(const void *addr)
Definition: mmio.h:22
#define IOSF_BYTE_EN
Definition: iosf.h:30
#define IOSF_REG(x)
Definition: iosf.h:23
#define IOSF_OP_WRITE_BUNIT
Definition: iosf.h:126
#define IOSF_PORT(x)
Definition: iosf.h:22
#define IOSF_PORT_BUNIT
Definition: iosf.h:92
#define IOSF_OPCODE(x)
Definition: iosf.h:21
#define IOSF_PCI_DEV
Definition: iosf.h:19
#define MDR_REG
Definition: iosf.h:34
#define BUNIT_MMCONF_REG
Definition: iosf.h:185
#define MCR_REG
Definition: iosf.h:33
#define MCRX_REG
Definition: iosf.h:35
#define TCO_TMR_HALT
Definition: pm.h:231
void __weak bootblock_early_northbridge_init(void)
Definition: bootblock.c:16
u32 inl(u16 port)
void outl(u32 val, u16 port)
@ CONFIG
Definition: dsi_common.h:201
static __always_inline void pci_write_config32(const struct device *dev, u16 reg, u32 val)
Definition: pci_ops.h:76
#define ACPI_BASE_ADDRESS
Definition: iomap.h:99
#define ABASE
Definition: pmc.h:11
#define PUNIT_BASE_ADDRESS
Definition: iomap.h:38
#define IO_BASE_ADDRESS
Definition: iomap.h:19
#define RCBA_BASE_ADDRESS
Definition: iomap.h:42
#define GPIO_BASE_ADDRESS
Definition: iomap.h:54
#define ILB_BASE_ADDRESS
Definition: iomap.h:26
#define PMC_BASE_ADDRESS
Definition: iomap.h:15
#define MPHY_BASE_ADDRESS
Definition: iomap.h:34
#define LPC_DEV
Definition: romstage.c:15
static __always_inline void pci_io_write_config32(pci_devfn_t dev, uint16_t reg, uint32_t value)
Definition: pci_io_cfg.h:65
#define PCI_DEV(SEGBUS, DEV, FN)
Definition: pci_type.h:14
#define LPC_FUNC
Definition: pci_devs.h:122
#define TCO1_CNT
Definition: smbus.h:12
static void byt_config_com1_and_enable(void)
Definition: bootblock.c:67
static void setup_mmconfig(void)
Definition: bootblock.c:80
static void tco_disable(void)
Definition: bootblock.c:41
static void program_base_addresses(void)
Definition: bootblock.c:13
static void spi_init(void)
Definition: bootblock.c:50
#define UART_RXD_PAD
Definition: gpio.h:369
#define UART_TXD_PAD
Definition: gpio.h:370
static void score_select_func(int pad, int func)
Definition: gpio.h:401
#define IBASE
Definition: lpc.h:12
#define PUBASE
Definition: lpc.h:15
#define IOBASE
Definition: lpc.h:11
#define PBASE
Definition: lpc.h:9
#define RCBA
Definition: lpc.h:17
#define GBASE
Definition: lpc.h:10
#define SBASE
Definition: lpc.h:13
#define UART_CONT
Definition: lpc.h:16
#define MPBASE
Definition: lpc.h:14
#define BCR_WPD
Definition: spi.h:34
#define SCS
Definition: spi.h:25
#define SRC_CACHE_PREFETCH
Definition: spi.h:32
#define EISS
Definition: spi.h:28
#define SRC_MASK
Definition: spi.h:29
#define SMIWPEN
Definition: spi.h:26
#define BCR
Definition: spi.h:27
unsigned int uint32_t
Definition: stdint.h:14