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 <string.h>
4 #include <console/console.h>
5 #include <device/device.h>
6 #include <device/mmio.h>
7 #include <acpi/acpi.h>
10 #include <amdblocks/i2c.h>
11 #include <baseboard/variants.h>
12 #include <boardid.h>
13 #include <smbios.h>
14 #include <soc/gpio.h>
15 #include <soc/pci_devs.h>
16 #include <soc/southbridge.h>
17 #include <amdblocks/acpimmio.h>
18 #include <variant/ec.h>
19 #include <variant/thermal.h>
20 
21 /***********************************************************
22  * These arrays set up the FCH PCI_INTR registers 0xC00/0xC01.
23  * This table is responsible for physically routing the PIC and
24  * IOAPIC IRQs to the different PCI devices on the system. It
25  * is read and written via registers 0xC00/0xC01 as an
26  * Index/Data pair. These values are chipset and mainboard
27  * dependent and should be updated accordingly.
28  *
29  * These values are used by the PCI configuration space,
30  * MP Tables. TODO: Make ACPI use these values too.
31  */
32 
33 static const u8 mainboard_picr_data[] = {
34  [0x00] = 0x03, 0x04, 0x05, 0x07, 0x0B, 0x1F, 0x1F, 0x1F,
35  [0x08] = 0xFA, 0xF1, 0x00, 0x00, 0x1F, 0x1F, 0x1F, 0x1F,
36  [0x10] = 0x09, 0x1F, 0x1F, 0x03, 0x1F, 0x1F, 0x1F, 0x03,
37  [0x18] = 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
38  [0x20] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00, 0x00,
39  [0x28] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
40  [0x30] = 0x05, 0x04, 0x05, 0x04, 0x04, 0x05, 0x04, 0x05,
41  [0x38] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
42  [0x40] = 0x04, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
43  [0x48] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44  [0x50] = 0x03, 0x04, 0x05, 0x07, 0x1F, 0x1F, 0x1F, 0x1F,
45  [0x58] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,
46  [0x60] = 0x1F, 0x1F, 0x07, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,
47  [0x68] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,
48  [0x70] = 0x03, 0x0F, 0x06, 0x0E, 0x0A, 0x0B, 0x1F, 0x1F,
49  [0x78] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,
50 };
51 
52 static const u8 mainboard_intr_data[] = {
53  [0x00] = 0x10, 0x11, 0x12, 0x13, 0x14, 0x1F, 0x16, 0x17,
54  [0x08] = 0x00, 0x00, 0x00, 0x00, 0x1F, 0x1F, 0x1F, 0x1F,
55  [0x10] = 0x09, 0x1F, 0x1F, 0x10, 0x1F, 0x1F, 0x1F, 0x10,
56  [0x18] = 0x1F, 0x1F, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00,
57  [0x20] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00, 0x00,
58  [0x28] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
59  [0x30] = 0x12, 0x11, 0x12, 0x11, 0x12, 0x11, 0x12, 0x00,
60  [0x38] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
61  [0x40] = 0x11, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
62  [0x48] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
63  [0x50] = 0x1F, 0x1F, 0x1F, 0x1F, 0x00, 0x00, 0x00, 0x00,
64  [0x58] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
65  [0x60] = 0x1F, 0x1F, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
66  [0x68] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
67  [0x70] = 0x03, 0x0F, 0x06, 0x0E, 0x0A, 0x0B, 0x1F, 0x1F,
68  [0x78] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
69 };
70 
71 /*
72  * This table defines the index into the picr/intr_data tables for each
73  * device. Any enabled device and slot that uses hardware interrupts should
74  * have an entry in this table to define its index into the FCH PCI_INTR
75  * register 0xC00/0xC01. This index will define the interrupt that it should
76  * use. Putting PIRQ_A into the PIN A index for a device will tell that
77  * device to use PIC IRQ 10 if it uses PIN A for its hardware INT.
78  */
79 static const struct pirq_struct mainboard_pirq_data[] = {
91 };
92 
93 /* PIRQ Setup */
94 static void pirq_setup(void)
95 {
100 }
101 
103 {
104  /* Override dev tree settings per board */
105 }
106 
107 static void mainboard_init(void *chip_info)
108 {
109  int boardid = board_id();
110  size_t num_gpios;
111  const struct soc_amd_gpio *gpios;
112 
113  printk(BIOS_INFO, "Board ID: %d\n", boardid);
114 
116 
117  gpios = variant_gpio_table(&num_gpios);
118  gpio_configure_pads(gpios, num_gpios);
119 
120  /* Initialize i2c buses that were not initialized in bootblock */
121  i2c_soc_init();
122 
123  /* Set GenIntDisable so that GPIO 90 is configured as a GPIO. */
125 
126  /* Set low-power mode for BayHub eMMC bridge's PCIe clock. */
131 
132  /* Same for the WiFi */
137 
139 }
140 
141 /*************************************************
142  * Dedicated mainboard function
143  *************************************************/
144 static void mainboard_enable(struct device *dev)
145 {
146  /* Initialize the PIRQ data structures for consumption */
147  pirq_setup();
148 
149 }
150 
152 {
153  return variant_get_xhci_oc_map(map);
154 }
155 
157 {
158  return variant_get_ehci_oc_map(map);
159 }
160 
162 {
164 }
165 
167  .init = mainboard_init,
168  .enable_dev = mainboard_enable,
169 };
170 
171 /* Variants may override these functions so see definitions in variants/ */
173 {
174  return 0;
175 }
176 
178 {
179 }
180 
181 const char *smbios_system_sku(void)
182 {
183  static char sku_str[7]; /* sku{0..255} */
184 
185  snprintf(sku_str, sizeof(sku_str), "sku%d", variant_board_sku());
186 
187  return sku_str;
188 }
struct chip_operations mainboard_ops
Definition: mainboard.c:19
@ PIRQ_A
Definition: acpi_pirq_gen.h:22
@ PIRQ_C
Definition: acpi_pirq_gen.h:24
@ PIRQ_D
Definition: acpi_pirq_gen.h:25
@ PIRQ_B
Definition: acpi_pirq_gen.h:23
static uint8_t pm_read8(uint8_t reg)
Definition: acpimmio.h:166
uint8_t *MAYBE_CONST acpimmio_misc
static void pm_write8(uint8_t reg, uint8_t value)
Definition: acpimmio.h:181
#define ARRAY_SIZE(a)
Definition: helpers.h:12
#define GPP_CLK_CNTRL
Definition: southbridge.h:89
#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
void mainboard_suspend_resume(void)
Definition: mainboard.c:10
void __weak variant_devtree_update(void)
Definition: mainboard.c:86
const char * smbios_system_sku(void)
Definition: mainboard.c:174
#define SD_DEVFN
Definition: variants.h:11
int mainboard_get_ehci_oc_map(uint16_t *map)
Definition: mainboard.c:156
uint8_t __weak variant_board_sku(void)
Definition: mainboard.c:172
int mainboard_get_xhci_oc_map(uint16_t *map)
Definition: mainboard.c:151
static void mainboard_init(void *chip_info)
Definition: mainboard.c:107
static const struct pirq_struct mainboard_pirq_data[]
Definition: mainboard.c:79
static const u8 mainboard_intr_data[]
Definition: mainboard.c:52
static const u8 mainboard_picr_data[]
Definition: mainboard.c:33
static void mainboard_enable(struct device *dev)
Definition: mainboard.c:144
static void pirq_setup(void)
Definition: mainboard.c:94
void __weak variant_mainboard_suspend_resume(void)
Definition: mainboard.c:177
#define clrsetbits32(addr, clear, set)
Definition: mmio.h:16
#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
int __weak variant_get_ehci_oc_map(uint16_t *map)
Definition: gpio.c:280
int __weak variant_get_xhci_oc_map(uint16_t *map)
Definition: gpio.c:271
const struct smm_save_state_ops *legacy_ops __weak
Definition: save_state.c:8
#define PIRQ_SATA
#define PIRQ_SMBUS
#define PIRQ_SD
#define PIRQ_NC
#define SMBUS_DEVFN
Definition: pci_devs.h:117
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
void i2c_soc_init(void)
Definition: i2c.c:113
u32 pirq_data_size
Definition: amd_pci_util.c:12
const u8 * intr_data_ptr
Definition: amd_pci_util.c:13
const u8 * picr_data_ptr
Definition: amd_pci_util.c:14
const struct pirq_struct * pirq_data_ptr
Definition: amd_pci_util.c:11
#define SATA_DEVFN
Definition: pci_devs.h:83
#define PIRQ_XHCI
#define PIRQ_EHCI
#define PIRQ_HDA
#define EHCI1_DEVFN
Definition: pci_devs.h:170
#define PCIE3_DEVFN
Definition: pci_devs.h:69
#define PCIE4_DEVFN
Definition: pci_devs.h:75
#define PCIE2_DEVFN
Definition: pci_devs.h:63
#define PCIE1_DEVFN
Definition: pci_devs.h:57
#define PCIE0_DEVFN
Definition: pci_devs.h:51
#define XHCI_DEVFN
Definition: pci_devs.h:153
#define HDA0_DEVFN
Definition: pci_devs.h:39
unsigned short uint16_t
Definition: stdint.h:11
uint8_t u8
Definition: stdint.h:45
unsigned char uint8_t
Definition: stdint.h:8
#define GPP_CLK0_REQ_MAP_SHIFT
Definition: southbridge.h:82
#define PM_GENINT_DISABLE
Definition: southbridge.h:69
#define GPP_CLK2_REQ_MAP_MASK
Definition: southbridge.h:80
#define PM_PCIB_CFG
Definition: southbridge.h:68
#define GPP_CLK0_REQ_MAP_CLK_REQ0
Definition: southbridge.h:84
#define GPP_CLK2_REQ_MAP_CLK_REQ2
Definition: southbridge.h:81
#define GPP_CLK2_REQ_MAP_SHIFT
Definition: southbridge.h:79
#define GPP_CLK0_REQ_MAP_MASK
Definition: southbridge.h:83
void(* init)(void *chip_info)
Definition: device.h:25
Definition: device.h:107
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