coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
soc_util.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include <assert.h>
4 #include <console/console.h>
5 #include <device/pci.h>
6 #include <hob_iiouds.h>
7 #include <intelblocks/cpulib.h>
8 #include <intelblocks/pcr.h>
9 #include <soc/iomap.h>
10 #include <soc/cpu.h>
11 #include <soc/msr.h>
12 #include <soc/pci_devs.h>
13 #include <soc/pcr_ids.h>
14 #include <soc/soc_util.h>
15 #include <soc/util.h>
16 
17 
18 /*
19  * +-------------------------+ TOLM
20  * | System Management Mode |
21  * | code and data |
22  * | (TSEG) |
23  * +-------------------------+ SMM base (aligned)
24  * | |
25  * | Chipset Reserved Memory |
26  * | |
27  * +-------------------------+ top_of_ram (aligned)
28  * | |
29  * | CBMEM Root |
30  * | |
31  * +-------------------------+
32  * | |
33  * | FSP Reserved Memory |
34  * | |
35  * +-------------------------+
36  * | |
37  * | Various CBMEM Entries |
38  * | |
39  * +-------------------------+ top_of_stack (8 byte aligned)
40  * | |
41  * | stack (CBMEM Entry) |
42  * | |
43  * +-------------------------+
44  */
45 
46 const struct SystemMemoryMapHob *get_system_memory_map(void)
47 {
48  size_t hob_size;
49  const uint8_t mem_hob_guid[16] = FSP_SYSTEM_MEMORYMAP_HOB_GUID;
50  const struct SystemMemoryMapHob *memmap_addr;
51 
52  memmap_addr = fsp_find_extension_hob_by_guid(mem_hob_guid, &hob_size);
53  assert(memmap_addr != NULL && hob_size != 0);
54 
55  return memmap_addr;
56 }
57 
58 bool is_iio_stack_res(const STACK_RES *res)
59 {
60  // TODO: do we have situation with only bux 0 and one stack?
61  return res->BusBase < res->BusLimit;
62 }
63 
65 {
66  const IIO_UDS *hob = get_iio_uds();
67 
68  assert(socket < MAX_SOCKET && stack < MAX_IIO_STACK);
69 
70  return hob->PlatformData.CpuQpiInfo[socket].StackBus[stack];
71 }
72 
74 {
75  uint32_t data, plat_info, max_min_turbo_limit_ratio;
76 
77  for (uint32_t socket = 0; socket < MAX_SOCKET; ++socket) {
79 
80  /* configure PCU_CR0_FUN csrs */
83  data |= P_STATE_LIMITS_LOCK;
85 
86  plat_info = pci_s_read_config32(cr0_dev, PCU_CR0_PLATFORM_INFO);
87  dump_csr64("", cr0_dev, PCU_CR0_PLATFORM_INFO);
88  max_min_turbo_limit_ratio =
89  (plat_info & MAX_NON_TURBO_LIM_RATIO_MASK) >>
91  printk(BIOS_SPEW, "plat_info: 0x%x, max_min_turbo_limit_ratio: 0x%x\n",
92  plat_info, max_min_turbo_limit_ratio);
93 
94  /* configure PCU_CR1_FUN csrs */
96 
97  data = pci_s_read_config32(cr1_dev, PCU_CR1_SAPMCTL);
98  /* clear bits 27:31 - FSP sets this with 0x7 which needs to be cleared */
99  data &= 0x0fffffff;
100  data |= SAPMCTL_LOCK_MASK;
101  pci_s_write_config32(cr1_dev, PCU_CR1_SAPMCTL, data);
102 
103  /* configure PCU_CR1_FUN csrs */
105 
108 
111 
112  data = PROCHOT_RATIO;
113  printk(BIOS_SPEW, "PCU_CR2_PROCHOT_RESPONSE_RATIO_REG data: 0x%x\n", data);
116 
120  }
121 }
122 
123 /*
124  * EX: SKX-SP
125  * Ports Stack Stack(HOB) IioConfigIou
126  * ==========================================
127  * 0 CSTACK stack 0 IOU0
128  * 1A..1D PSTACKZ stack 1 IOU1
129  * 2A..2D PSTACK1 stack 2 IOU2
130  * 3A..3D PSTACK2 stack 3 IOU3
131  * 5A..4D PSTACK3 stack 4 IOU4
132  * 5A..5D PSTACK4 stack 5 IOU5
133  */
135 {
136  if (port == PORT_0)
137  return CSTACK;
138  else if (port >= PORT_1A && port <= PORT_1D)
139  return PSTACK0;
140  else if (port >= PORT_2A && port <= PORT_2D)
141  return PSTACK1;
142  else if (port >= PORT_3A && port <= PORT_3D)
143  return PSTACK2;
144  else if (port >= PORT_4A && port <= PORT_4D)
145  return PSTACK3; // MCP0
146  else if (port >= PORT_5A && port <= PORT_5D)
147  return PSTACK4; // MCP1
148  else
149  return -1;
150 }
151 
152 uint8_t soc_get_iio_ioapicid(int socket, int stack)
153 {
154  uint8_t ioapic_id = socket ? 0xf : 0x9;
155  switch (stack) {
156  case CSTACK:
157  break;
158  case PSTACK0:
159  ioapic_id += 1;
160  break;
161  case PSTACK1:
162  ioapic_id += 2;
163  break;
164  case PSTACK2:
165  ioapic_id += 3;
166  break;
167  default:
168  return 0xff;
169  }
170  return ioapic_id;
171 }
#define assert(statement)
Definition: assert.h:74
#define printk(level,...)
Definition: stdlib.h:16
const void * fsp_find_extension_hob_by_guid(const uint8_t *guid, size_t *size)
port
Definition: i915.h:29
bool is_iio_stack_res(const STACK_RES *res)
Definition: soc_util.c:28
uint8_t soc_get_iio_ioapicid(int socket, int stack)
Definition: soc_util.c:65
const struct SystemMemoryMapHob * get_system_memory_map(void)
Definition: soc_util.c:12
int soc_get_stack_for_port(int port)
Definition: soc_util.c:51
uint32_t get_socket_stack_busno(uint32_t socket, uint32_t stack)
Definition: soc_util.c:33
void config_reset_cpl3_csrs(void)
Definition: soc_util.c:73
#define BIOS_SPEW
BIOS_SPEW - Excessively verbose output.
Definition: loglevel.h:142
static __always_inline uint32_t pci_s_read_config32(pci_devfn_t dev, uint16_t reg)
Definition: pci_io_cfg.h:92
static __always_inline void pci_s_write_config32(pci_devfn_t dev, uint16_t reg, uint32_t value)
Definition: pci_io_cfg.h:110
#define PCI_DEV(SEGBUS, DEV, FN)
Definition: pci_type.h:14
u32 pci_devfn_t
Definition: pci_type.h:8
#define PCU_DEV
Definition: pci_devs.h:121
#define P_STATE_LIMITS_LOCK
Definition: pci_devs.h:32
#define PCU_CR0_P_STATE_LIMITS
Definition: pci_devs.h:31
#define SAPMCTL_LOCK_MASK
Definition: pci_devs.h:64
#define PCU_CR0_PLATFORM_INFO
Definition: pci_devs.h:28
#define PCU_CR0_FUN
Definition: pci_devs.h:26
#define PCU_CR1_SAPMCTL
Definition: pci_devs.h:63
#define PCU_CR1_FUN
Definition: pci_devs.h:39
#define PCU_CR2_FUN
Definition: pci_devs.h:66
#define PCU_IIO_STACK
Definition: pci_devs.h:23
const IIO_UDS * get_iio_uds(void)
Definition: util.c:89
#define MAX_NON_TURBO_LIM_RATIO_SHIFT
Definition: pci_devs.h:49
#define PCU_CR2_PROCHOT_RESPONSE_RATIO_REG
Definition: pci_devs.h:130
#define UNOCRE_PLIMIT_OVERRIDE_SHIFT
Definition: pci_devs.h:129
#define dump_csr(fmt, dev, reg)
Definition: pci_devs.h:12
#define PROCHOT_RATIO
Definition: pci_devs.h:131
#define KTI_IN_PKGCSTATE_L1_MASK
Definition: pci_devs.h:126
#define dump_csr64(fmt, dev, reg)
Definition: pci_devs.h:18
#define PCU_CR2_PKG_CST_ENTRY_CRITERIA_MASK
Definition: pci_devs.h:123
#define PCIE_IN_PKGCSTATE_L1_MASK
Definition: pci_devs.h:124
#define PCU_CR2_DYNAMIC_PERF_POWER_CTL
Definition: pci_devs.h:127
#define PCU_CR2_PKG_CST_ENTRY_CRITERIA_MASK2
Definition: pci_devs.h:125
#define MAX_NON_TURBO_LIM_RATIO_MASK
Definition: pci_devs.h:50
#define NULL
Definition: stddef.h:19
unsigned int uint32_t
Definition: stdint.h:14
unsigned char uint8_t
Definition: stdint.h:8
Definition: device.h:76