1 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include <device/device.h>
5 #include <device/pci.h>
6 #include <hob_cxlnode.h>
7 #include <intelblocks/cpulib.h>
10 #include <soc/pci_devs.h>
11 #include <soc/soc_util.h>
13 #include <pc80/mc146818rtc.h>
15 const EWL_PRIVATE_DATA
*get_ewl_hob(void)
18 static const EWL_PRIVATE_DATA
*hob
;
19 const uint8_t ewl_id_hob_guid
[16] = FSP_HOB_EWLID_GUID
;
24 hob
= fsp_find_extension_hob_by_guid(ewl_id_hob_guid
, &hob_size
);
25 assert(hob
!= NULL
&& hob_size
!= 0);
29 const SYSTEM_INFO_VAR
*get_system_info_hob(void)
32 static const SYSTEM_INFO_VAR
*hob
;
33 const uint8_t system_info_hob_guid
[16] = FSP_HOB_SYSTEMINFO_GUID
;
38 hob
= fsp_find_extension_hob_by_guid(system_info_hob_guid
, &hob_size
);
39 assert(hob
!= NULL
&& hob_size
!= 0);
43 const struct SystemMemoryMapHob
*get_system_memory_map(void)
46 const uint8_t mem_hob_guid
[16] = FSP_SYSTEM_MEMORYMAP_HOB_GUID
;
47 const struct SystemMemoryMapHob
**memmap_addr
;
49 memmap_addr
= (const struct SystemMemoryMapHob
**)fsp_find_extension_hob_by_guid(
50 mem_hob_guid
, &hob_size
);
51 /* hob_size is the size of the 8-byte address not the hob data */
52 assert(memmap_addr
!= NULL
&& hob_size
!= 0);
53 /* assert the pointer to the hob is not NULL */
54 assert(*memmap_addr
!= NULL
);
59 const struct SystemMemoryMapElement
*get_system_memory_map_elment(uint8_t *num
)
61 const struct SystemMemoryMapHob
*hob
= get_system_memory_map();
65 *num
= hob
->numberEntries
;
69 bool is_pcie_iio_stack_res(const STACK_RES
*res
)
71 return res
->Personality
== TYPE_UBOX_IIO
;
74 bool is_ubox_stack_res(const STACK_RES
*res
)
76 return res
->Personality
== TYPE_UBOX
;
79 bool is_ioat_iio_stack_res(const STACK_RES
*res
)
81 return res
->Personality
== TYPE_DINO
;
85 * Given a stack resource, figure out whether the corresponding stack has
87 * It goes through pds (proximity domains) structure to see if there is any
88 * generic initiator has device with bus # falls between bus base and
91 bool is_iio_cxl_stack_res(const STACK_RES
*res
)
93 /* pds should be setup ahead of this call */
96 for (uint8_t i
= 0; i
< pds
.num_pds
; i
++) {
97 if (pds
.pds
[i
].pd_type
!= PD_TYPE_GENERIC_INITIATOR
)
100 uint32_t bus
= PCI_BDF(pds
.pds
[i
].dev
) >> 20;
101 if (bus
>= res
->BusBase
&& bus
<= res
->BusLimit
)
108 const CXL_NODE_SOCKET
*get_cxl_node(void)
111 static const CXL_NODE_SOCKET
*hob
;
112 static bool hob_check
= 0;
113 const uint8_t fsp_hob_cxl_node_socket_guid
[16] = FSP_HOB_CXLNODE_GUID
;
118 hob
= fsp_find_extension_hob_by_guid(fsp_hob_cxl_node_socket_guid
, &hob_size
);
120 if (hob
== NULL
|| hob_size
== 0)
122 "FSP_HOB_CXLNODE_GUID not found: CXL may not be installed\n");
126 uint8_t get_cxl_node_count(void)
128 const CXL_NODE_SOCKET
*hob
= get_cxl_node();
132 for (uint8_t skt_id
= 0; skt_id
< MAX_SOCKET
; skt_id
++)
133 count
+= hob
[skt_id
].CxlNodeCount
;
139 void bios_done_msr(void *unused
)
141 msr_t msr
= rdmsr(MSR_BIOS_DONE
);
142 if (!(msr
.lo
& XEON_SP_ENABLE_IA_UNTRUSTED
)) { /* if already locked skip update */
143 msr
.lo
|= XEON_SP_ENABLE_IA_UNTRUSTED
;
144 wrmsr(MSR_BIOS_DONE
, msr
);
148 void soc_set_mrc_cold_boot_flag(bool cold_boot_required
)
150 uint8_t mrc_status
= cmos_read(CMOS_OFFSET_MRC_STATUS
);
151 uint8_t new_mrc_status
= (mrc_status
& 0xfe) | cold_boot_required
;
152 printk(BIOS_SPEW
, "MRC status: 0x%02x want 0x%02x\n", mrc_status
, new_mrc_status
);
153 if (new_mrc_status
!= mrc_status
)
154 cmos_write(new_mrc_status
, CMOS_OFFSET_MRC_STATUS
);
157 bool is_memtype_reserved(uint16_t mem_type
)
159 return !!(mem_type
& MEM_TYPE_RESERVED
);
162 bool is_memtype_non_volatile(uint16_t mem_type
)
164 return !(mem_type
& MEMTYPE_VOLATILE_MASK
);
167 bool is_memtype_processor_attached(uint16_t mem_type
)
170 * Refer to the definition of MEM_TYPE enum type in
171 * vendorcode/intel/fsp/fsp2_0/sapphirerapids_sp/MemoryMapDataHob.h,
172 * values less than MemTypeCxlAccVolatileMem represents
173 * processor attached memory
175 return (mem_type
< MemTypeCxlAccVolatileMem
);
178 unsigned int get_prmrr_count(void)
183 bool get_mmio_high_base_size(resource_t
*base
, resource_t
*size
)
185 const IIO_UDS
*hob
= get_iio_uds();
186 *base
= hob
->PlatformData
.PlatGlobalMmio64Base
;
187 *size
= hob
->PlatformData
.PlatGlobalMmio64Limit
- (*base
) + 1;