coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
mainboard.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 /*
4  * Derived from Cavium's BSD-3 Clause OCTEONTX-SDK-6.2.0.
5  */
6 
7 #include <device/device.h>
8 #include <libbdk-hal/bdk-config.h>
9 #include <libbdk-hal/bdk-twsi.h>
10 #include <soc/gpio.h>
11 #include <soc/uart.h>
12 #include <console/console.h>
13 #include <soc/clock.h>
14 #include <soc/timer.h>
15 #include <soc/cpu.h>
16 #include <soc/sdram.h>
17 #include <soc/spi.h>
18 #include <spi_flash.h>
19 #include <fmap.h>
20 
21 static void mainboard_print_info(void)
22 {
23  struct region region;
24 
25  if (fmap_locate_area("WP_RO", &region) < 0) {
26  printk(BIOS_ERR, "MB: Could not find region '%s'\n", "WP_RO");
27  } else {
28  const struct spi_flash *flash = boot_device_spi_flash();
29  const bool prot = (flash != NULL) &&
30  (spi_flash_is_write_protected(flash, &region) == 1);
31  printk(BIOS_INFO, "MB: WP_RO is %swrite protected\n",
32  prot ? "" : "not ");
33  }
34 
35  printk(BIOS_INFO, "MB: trusted boot : %s\n",
36  gpio_strap_value(10) ? "yes" : "no");
37 
38  const size_t boot_method = gpio_strap_value(0) |
39  (gpio_strap_value(1) << 1) |
40  (gpio_strap_value(2) << 2) |
41  (gpio_strap_value(3) << 3);
42 
43  printk(BIOS_INFO, "MB: boot method : ");
44  switch (boot_method) {
45  case 0x2:
46  case 0x3:
47  printk(BIOS_INFO, "EMMC\n");
48  break;
49  case 0x5:
50  case 0x6:
51  printk(BIOS_INFO, "SPI\n");
52  break;
53  case 0x8:
54  printk(BIOS_INFO, "REMOTE\n");
55  break;
56  case 0xc:
57  case 0xd:
58  printk(BIOS_INFO, "PCIe\n");
59  break;
60  default:
61  printk(BIOS_INFO, "unknown\n");
62  }
63 
64  printk(BIOS_INFO, "MB: REFclk : %llu MHz\n",
65  thunderx_get_ref_clock() / 1000000ULL);
66 
67  printk(BIOS_INFO, "MB: IOclk : %llu MHz\n",
68  thunderx_get_io_clock() / 1000000ULL);
69 
70  printk(BIOS_INFO, "MB: COREclk : %llu MHz\n",
71  thunderx_get_core_clock() / 1000000ULL);
72 
73  printk(BIOS_INFO, "MB: #CPU cores : %zu\n",
75 
76  printk(BIOS_INFO, "MB: RAM : %zu MiB\n",
77  sdram_size_mb());
78 
79  printk(BIOS_INFO, "MB: SPIclk : %llu kHz\n",
80  spi_get_clock(0) >> 10);
81 }
82 
83 extern const struct bdk_devicetree_key_value devtree[];
84 
85 static void mainboard_init(struct device *dev)
86 {
87  size_t i;
88 
89  /* Init timer */
91 
92  /* Init CPUs */
93  for (i = 1; i < CONFIG_MAX_CPUS; i++)
94  start_cpu(i, NULL);
95 }
96 
97 static void mainboard_enable(struct device *dev)
98 {
99  dev->ops->init = &mainboard_init;
100 
101  bdk_config_set_fdt(devtree);
102 
104 }
105 
108 };
struct chip_operations mainboard_ops
Definition: mainboard.c:19
const struct spi_flash * boot_device_spi_flash(void)
const struct bdk_devicetree_key_value devtree[]
Definition: bdk_devicetree.c:8
size_t sdram_size_mb(void)
Definition: sdram.c:24
#define printk(level,...)
Definition: stdlib.h:16
int fmap_locate_area(const char *name, struct region *r)
Definition: fmap.c:164
static int start_cpu(struct device *cpu)
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
static void mainboard_init(struct device *dev)
Definition: mainboard.c:85
static void mainboard_print_info(void)
Definition: mainboard.c:21
static void mainboard_enable(struct device *dev)
Definition: mainboard.c:97
u64 thunderx_get_core_clock(void)
Returns the core clock speed in Hz.
Definition: clock.c:57
u64 thunderx_get_ref_clock(void)
Returns the reference clock speed in Hz.
Definition: clock.c:37
u64 thunderx_get_io_clock(void)
Returns the I/O clock speed in Hz.
Definition: clock.c:45
size_t cpu_get_num_available_cores(void)
Return the number of cores available in the chip.
Definition: cpu.c:17
int gpio_strap_value(gpio_t gpio)
Definition: gpio.c:150
uint64_t spi_get_clock(const size_t bus)
Get current SPI clock frequency in Hz.
Definition: spi.c:211
void soc_timer_init(void)
Definition: timer.c:119
int spi_flash_is_write_protected(const struct spi_flash *flash, const struct region *region)
Definition: spi_flash.c:576
#define NULL
Definition: stddef.h:19
void(* enable_dev)(struct device *dev)
Definition: device.h:24
void(* init)(struct device *dev)
Definition: device.h:42
Definition: device.h:107
struct device_operations * ops
Definition: device.h:143
Definition: region.h:76