blob: 053b3ebecad10fd000a12e12052b7ce148a4cc8c [file] [log] [blame]
Jonathan Zhang15fc4592023-01-25 11:33:16 -08001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <assert.h>
4#include <device/device.h>
5#include <device/pci.h>
6#include <hob_cxlnode.h>
7#include <intelblocks/cpulib.h>
8#include <soc/cpu.h>
9#include <soc/msr.h>
10#include <soc/numa.h>
11#include <soc/pci_devs.h>
12#include <soc/soc_util.h>
13#include <soc/util.h>
14#include <stdlib.h>
15#include <string.h>
16
17const EWL_PRIVATE_DATA *get_ewl_hob(void)
18{
19 size_t hob_size;
20 static const EWL_PRIVATE_DATA *hob;
21 const uint8_t ewl_id_hob_guid[16] = FSP_HOB_EWLID_GUID;
22
23 if (hob != NULL)
24 return hob;
25
26 hob = fsp_find_extension_hob_by_guid(ewl_id_hob_guid, &hob_size);
27 assert(hob != NULL && hob_size != 0);
28 return hob;
29}
30
31const SYSTEM_INFO_VAR *get_system_info_hob(void)
32{
33 size_t hob_size;
34 static const SYSTEM_INFO_VAR *hob;
35 const uint8_t system_info_hob_guid[16] = FSP_HOB_SYSTEMINFO_GUID;
36
37 if (hob != NULL)
38 return hob;
39
40 hob = fsp_find_extension_hob_by_guid(system_info_hob_guid, &hob_size);
41 assert(hob != NULL && hob_size != 0);
42 return hob;
43}
44
45const struct SystemMemoryMapHob *get_system_memory_map(void)
46{
47 size_t hob_size;
48 const uint8_t mem_hob_guid[16] = FSP_SYSTEM_MEMORYMAP_HOB_GUID;
49 const struct SystemMemoryMapHob **memmap_addr;
50
51 memmap_addr = (const struct SystemMemoryMapHob **)fsp_find_extension_hob_by_guid(
52 mem_hob_guid, &hob_size);
53 /* hob_size is the size of the 8-byte address not the hob data */
54 assert(memmap_addr != NULL && hob_size != 0);
55 /* assert the pointer to the hob is not NULL */
56 assert(*memmap_addr != NULL);
57
58 return *memmap_addr;
59}
60
61const struct SystemMemoryMapElement *get_system_memory_map_elment(uint8_t *num)
62{
63 const struct SystemMemoryMapHob *hob = get_system_memory_map();
64 if (!hob)
65 return NULL;
66
67 *num = hob->numberEntries;
68 return hob->Element;
69}
70
71bool is_iio_stack_res(const STACK_RES *res)
72{
73 return res->Personality == TYPE_UBOX_IIO || res->Personality == TYPE_DINO;
74}
75
76/*
77 * Given a stack resource, figure out whether the corresponding stack has
78 * CXL device.
79 * It goes through pds (proximity domains) structure to see if there is any
80 * generic initiator has device with bus # falls between bus base and
81 * bus limit.
82 */
83bool is_iio_cxl_stack_res(const STACK_RES *res)
84{
85 for (uint8_t i = 0; i < pds.num_pds; i++) {
86 if (pds.pds[i].pd_type == PD_TYPE_PROCESSOR)
87 continue;
88
89 uint32_t bus = pds.pds[i].device_handle >> 20;
90 if (bus >= res->BusBase && bus <= res->BusLimit)
91 return true;
92 }
93
94 return false;
95}
96
97const CXL_NODE_SOCKET *get_cxl_node(void)
98{
99 size_t hob_size;
100 static const CXL_NODE_SOCKET *hob;
101 static bool hob_check = 0;
102 const uint8_t fsp_hob_cxl_node_socket_guid[16] = FSP_HOB_CXLNODE_GUID;
103
104 if (hob_check == 1)
105 return hob;
106
107 hob = fsp_find_extension_hob_by_guid(fsp_hob_cxl_node_socket_guid, &hob_size);
108 hob_check = 1;
109 if (hob == NULL || hob_size == 0)
110 printk(BIOS_DEBUG,
111 "FSP_HOB_CXLNODE_GUID not found: CXL may not be installed\n");
112 return hob;
113}
114
115uint8_t get_cxl_node_count(void)
116{
117 const CXL_NODE_SOCKET *hob = get_cxl_node();
118 uint8_t count = 0;
119
120 if (hob != NULL) {
121 for (uint8_t skt_id = 0; skt_id < MAX_SOCKET; skt_id++)
122 count += hob[skt_id].CxlNodeCount;
123 }
124
125 return count;
126}
127
128uint32_t get_socket_stack_busno(uint32_t socket, uint32_t stack)
129{
130 const IIO_UDS *hob = get_iio_uds();
131
132 assert(socket < hob->SystemStatus.numCpus && stack < MAX_LOGIC_IIO_STACK);
133
134 return hob->PlatformData.IIO_resource[socket].StackRes[stack].BusBase;
135}
136
137uint32_t get_ubox_busno(uint32_t socket, uint8_t offset)
138{
139 const IIO_UDS *hob = get_iio_uds();
140
141 assert(socket < hob->SystemStatus.numCpus);
142 for (int stack = 0; stack < MAX_LOGIC_IIO_STACK; ++stack) {
143 if (hob->PlatformData.IIO_resource[socket].StackRes[stack].Personality
144 == TYPE_UBOX)
145 return (hob->PlatformData.IIO_resource[socket].StackRes[stack].BusBase
146 + offset);
147 }
148 die("Unable to locate UBOX BUS NO");
149}
150
151uint32_t get_socket_ubox_busno(uint32_t socket)
152{
153 return get_ubox_busno(socket, UNCORE_BUS_1);
154}
155
156/* mainboard can override this function for their own handling, such as write a BMC SEL. */
157void __weak mainboard_fsp_error_handle(void)
158{
159 die("ERROR: FSP reported an error(s) after running!");
160}
161
162void check_fsp_error(void)
163{
164 bool fsp_found_error = fsp_find_error_info();
165
166 if (fsp_found_error)
167 mainboard_fsp_error_handle();
168}
169
170void bios_done_msr(void *unused)
171{
172 msr_t msr = rdmsr(MSR_BIOS_DONE);
173 if (!(msr.lo & XEON_SP_ENABLE_IA_UNTRUSTED)) { /* if already locked skip update */
174 msr.lo |= XEON_SP_ENABLE_IA_UNTRUSTED;
175 wrmsr(MSR_BIOS_DONE, msr);
176 }
177}