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 #include <acpi/acpi.h>
4 #include <baseboard/variants.h>
5 #include <boardid.h>
6 #include <console/console.h>
7 #include <device/device.h>
8 #include <ec/ec.h>
9 #include <gpio.h>
10 #include <nhlt.h>
11 #include <smbios.h>
12 #include <soc/gpio.h>
13 #include <soc/nhlt.h>
14 #include <string.h>
15 #include <variant/ec.h>
16 #include <variant/gpio.h>
17 
18 /* override specific gpio by sku id */
19 const struct pad_config __weak
21 {
22  *num = 0;
23  return NULL;
24 }
25 
26 static void mainboard_init(void *chip_info)
27 {
28  int boardid;
29  const struct pad_config *pads;
30  size_t num;
31 
32  boardid = board_id();
33  printk(BIOS_INFO, "Board ID: %d\n", boardid);
34 
35  pads = variant_gpio_table(&num);
36  gpio_configure_pads(pads, num);
37 
38  pads = variant_sku_gpio_table(&num);
39  gpio_configure_pads(pads, num);
40 
42 
44 }
45 
46 /*
47  * There are 2 pins on reef-like boards that can be used for SKU'ing
48  * board differences. They each have optional stuffing for a pullup and
49  * a pulldown. This way we can generate 9 different values with the
50  * 2 pins.
51  */
53 {
54  gpio_t board_sku_gpios[] = {
55  [1] = GPIO_17, [0] = GPIO_16,
56  };
57  const size_t num = ARRAY_SIZE(board_sku_gpios);
58 
59  return gpio_base3_value(board_sku_gpios, num);
60 }
61 
63 {
64  static int board_sku_num = -1;
65 
66  if (board_sku_num < 0)
67  board_sku_num = sku_strapping_value();
68 
69  return board_sku_num;
70 }
71 
72 /* Set variant board sku to ec by sku id */
74 {
75 }
76 
77 const char *smbios_system_sku(void)
78 {
79  static char sku_str[7]; /* sku{0..255} */
80 
81  snprintf(sku_str, sizeof(sku_str), "sku%d", variant_board_sku());
82 
83  return sku_str;
84 }
85 
86 void __weak variant_nhlt_oem_overrides(const char **oem_id,
87  const char **oem_table_id,
88  uint32_t *oem_revision)
89 {
90  *oem_id = "reef";
91  *oem_table_id = CONFIG_VARIANT_DIR;
92  *oem_revision = variant_board_sku();
93 }
94 
95 static unsigned long mainboard_write_acpi_tables(
96  const struct device *device, unsigned long current, acpi_rsdp_t *rsdp)
97 {
98  uintptr_t start_addr;
99  uintptr_t end_addr;
100  struct nhlt *nhlt;
101  const char *oem_id = NULL;
102  const char *oem_table_id = NULL;
103  uint32_t oem_revision = 0;
104 
105  start_addr = current;
106 
107  nhlt = nhlt_init();
108 
109  if (nhlt == NULL)
110  return start_addr;
111 
113  variant_nhlt_oem_overrides(&oem_id, &oem_table_id, &oem_revision);
114 
115  end_addr = nhlt_soc_serialize_oem_overrides(nhlt, start_addr,
116  oem_id, oem_table_id, oem_revision);
117 
118  if (end_addr != start_addr)
119  acpi_add_table(rsdp, (void *)start_addr);
120 
121  return end_addr;
122 }
123 
124 static void mainboard_enable(struct device *dev)
125 {
126  dev->ops->write_acpi_tables = mainboard_write_acpi_tables;
127 }
128 
130  .init = mainboard_init,
131  .enable_dev = mainboard_enable,
132 };
struct chip_operations mainboard_ops
Definition: mainboard.c:19
void acpi_add_table(acpi_rsdp_t *rsdp, void *table)
Add an ACPI table to the RSDT (and XSDT) structure, recalculate length and checksum.
Definition: acpi.c:49
#define GPIO_17
Definition: gpio_ftns.h:16
#define GPIO_16
Definition: gpio_ftns.h:15
#define ARRAY_SIZE(a)
Definition: helpers.h:12
#define printk(level,...)
Definition: stdlib.h:16
void mainboard_ec_init(void)
Definition: ec.c:8
uint32_t board_id(void)
board_id() - Get the board version
Definition: ec_boardid.c:6
const char * smbios_system_sku(void)
Definition: mainboard.c:174
void variant_nhlt_init(struct nhlt *nhlt)
Definition: nhlt.c:7
uint8_t __weak variant_board_sku(void)
Definition: mainboard.c:172
static unsigned long mainboard_write_acpi_tables(const struct device *device, unsigned long current, acpi_rsdp_t *rsdp)
Definition: mainboard.c:95
uint8_t sku_strapping_value(void)
Definition: mainboard.c:52
static void mainboard_init(void *chip_info)
Definition: mainboard.c:26
void __weak variant_board_ec_set_skuid(void)
Definition: mainboard.c:73
void __weak variant_nhlt_oem_overrides(const char **oem_id, const char **oem_table_id, uint32_t *oem_revision)
Definition: mainboard.c:86
static void mainboard_enable(struct device *dev)
Definition: mainboard.c:124
const struct pad_config __weak * variant_sku_gpio_table(size_t *num)
Definition: mainboard.c:20
static uint32_t gpio_base3_value(const gpio_t gpio[], int num_gpio)
Definition: gpio.h:63
struct nhlt * nhlt_init(void)
Definition: nhlt.c:23
uintptr_t nhlt_soc_serialize_oem_overrides(struct nhlt *nhlt, uintptr_t acpi_addr, const char *oem_id, const char *oem_table_id, uint32_t oem_revision)
Definition: nhlt.c:12
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
const struct pad_config *__weak variant_gpio_table(size_t *num)
Definition: gpio.c:406
const struct smm_save_state_ops *legacy_ops __weak
Definition: save_state.c:8
void gpio_configure_pads(const struct soc_amd_gpio *gpio_list_ptr, size_t size)
program a particular set of GPIO
Definition: gpio.c:307
#define NULL
Definition: stddef.h:19
unsigned int uint32_t
Definition: stdint.h:14
unsigned long uintptr_t
Definition: stdint.h:21
unsigned char uint8_t
Definition: stdint.h:8
Definition: acpi.h:82
void(* init)(void *chip_info)
Definition: device.h:25
Definition: device.h:107
struct device_operations * ops
Definition: device.h:143
Definition: nhlt.h:287
int snprintf(char *buf, size_t size, const char *fmt,...)
Note: This file is only for POSIX compatibility, and is meant to be chain-included via string....
Definition: vsprintf.c:35