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/io.h>
4 #include <bootblock_common.h>
5 #include <build.h>
6 #include <console/console.h>
7 #include <device/pci_ops.h>
8 #include <fsp/util.h>
9 #include <pc80/mc146818rtc.h>
10 #include <soc/gpio.h>
11 #include <soc/iomap.h>
12 #include <soc/iosf.h>
13 #include <soc/lpc.h>
14 #include <soc/msr.h>
15 #include <soc/pm.h>
16 #include <soc/spi.h>
17 
19 {
20  /* Call lib/bootblock.c main */
21  bootblock_main_with_basetime(base_timestamp);
22 }
23 
24 static void program_base_addresses(void)
25 {
26  uint32_t reg;
27  const uint32_t lpc_dev = PCI_DEV(0, LPC_DEV, LPC_FUNC);
28 
29  /* Memory Mapped IO registers. */
30  reg = PMC_BASE_ADDRESS | 2;
31  pci_write_config32(lpc_dev, PBASE, reg);
32  reg = IO_BASE_ADDRESS | 2;
33  pci_write_config32(lpc_dev, IOBASE, reg);
34  reg = ILB_BASE_ADDRESS | 2;
35  pci_write_config32(lpc_dev, IBASE, reg);
36  reg = SPI_BASE_ADDRESS | 2;
37  pci_write_config32(lpc_dev, SBASE, reg);
38  reg = MPHY_BASE_ADDRESS | 2;
39  pci_write_config32(lpc_dev, MPBASE, reg);
40  reg = PUNIT_BASE_ADDRESS | 2;
41  pci_write_config32(lpc_dev, PUBASE, reg);
42  reg = RCBA_BASE_ADDRESS | 1;
43  pci_write_config32(lpc_dev, RCBA, reg);
44 
45  /* IO Port Registers. */
46  reg = ACPI_BASE_ADDRESS | 2;
47  pci_write_config32(lpc_dev, ABASE, reg);
48  reg = GPIO_BASE_ADDRESS | 2;
49  pci_write_config32(lpc_dev, GBASE, reg);
50 }
51 
52 static void tco_disable(void)
53 {
54  uint32_t reg;
55 
57  reg |= TCO_TMR_HALT;
59 }
60 
61 static void spi_init(void)
62 {
63  void *scs = (void *)(SPI_BASE_ADDRESS + SCS);
64  void *bcr = (void *)(SPI_BASE_ADDRESS + BCR);
65  uint32_t reg;
66 
67  /* Disable generating SMI when setting WPD bit. */
68  write32(scs, read32(scs) & ~SMIWPEN);
69  /*
70  * Enable caching and prefetching in the SPI controller. Disable
71  * the SMM-only BIOS write and set WPD bit.
72  */
73  reg = (read32(bcr) & ~SRC_MASK) | SRC_CACHE_PREFETCH | BCR_WPD;
74  reg &= ~EISS;
75  write32(bcr, reg);
76 }
77 
78 static void soc_rtc_init(void)
79 {
80  int rtc_failed = rtc_failure();
81 
82  if (rtc_failed) {
83  printk(BIOS_ERR, "RTC Failure detected. Resetting date to %x/%x/%x%x\n",
84  COREBOOT_BUILD_MONTH_BCD, COREBOOT_BUILD_DAY_BCD, 0x20,
85  COREBOOT_BUILD_YEAR_BCD);
86  }
87 
89 }
90 
91 static void setup_mmconfig(void)
92 {
93  uint32_t reg;
94 
95  /*
96  * Set up the MMCONF range. The register lives in the BUNIT. The IO variant of the
97  * config access needs to be used initially to properly configure as the IOSF access
98  * registers live in PCI config space.
99  */
100  reg = 0;
101  /* Clear the extended register. */
103  reg = CONFIG_ECAM_MMCONF_BASE_ADDRESS | 1;
108 }
109 
111 {
112  /* Allow memory-mapped PCI config access */
113  setup_mmconfig();
114 
115  /* Early chipset initialization */
117  tco_disable();
118 }
120 {
122 
123  /* Continue chipset initialization */
124  soc_rtc_init();
125  set_max_freq();
126  spi_init();
127 
128  lpc_init();
129 }
#define SPI_BASE_ADDRESS
Definition: iomap.h:8
#define asmlinkage
Definition: cpu.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
int rtc_failure(void)
Definition: pmutil.c:330
#define printk(level,...)
Definition: stdlib.h:16
void bootblock_soc_early_init(void)
Definition: bootblock.c:20
void bootblock_soc_init(void)
Definition: bootblock.c:27
void set_max_freq(void)
Definition: romstage.c:7
u32 inl(u16 port)
void outl(u32 val, u16 port)
asmlinkage void bootblock_c_entry(uint64_t base_timestamp)
Definition: bootblock.c:26
void report_fsp_output(void)
Definition: fsp_report.c:11
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
void bootblock_main_with_basetime(uint64_t base_timestamp)
Definition: bootblock.c:71
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
void cmos_init(bool invalid)
Definition: mc146818rtc.c:156
#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
static void lpc_init(struct device *dev)
Definition: lpc.c:45
static int rtc_failed(uint32_t gen_pmcon_b)
Definition: pmutil.c:169
#define TCO1_CNT
Definition: smbus.h:12
#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 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
static void setup_mmconfig(void)
Definition: bootblock.c:91
static void tco_disable(void)
Definition: bootblock.c:52
static void soc_rtc_init(void)
Definition: bootblock.c:78
static void program_base_addresses(void)
Definition: bootblock.c:24
static void spi_init(void)
Definition: bootblock.c:61
unsigned int uint32_t
Definition: stdint.h:14
unsigned long long uint64_t
Definition: stdint.h:17