Jonathan Zhang | 15fc459 | 2023-01-25 11:33:16 -0800 | [diff] [blame] | 1 | /* 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> |
Jonathan Zhang | 15fc459 | 2023-01-25 11:33:16 -0800 | [diff] [blame] | 8 | #include <soc/msr.h> |
| 9 | #include <soc/numa.h> |
| 10 | #include <soc/pci_devs.h> |
| 11 | #include <soc/soc_util.h> |
| 12 | #include <soc/util.h> |
| 13 | #include <stdlib.h> |
| 14 | #include <string.h> |
Johnny Lin | a0b199c | 2023-01-30 20:44:05 +0800 | [diff] [blame] | 15 | #include <pc80/mc146818rtc.h> |
Jonathan Zhang | 15fc459 | 2023-01-25 11:33:16 -0800 | [diff] [blame] | 16 | |
| 17 | const 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 | |
| 31 | const 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 | |
| 45 | const 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 | |
| 61 | const 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 | |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 71 | bool is_pcie_iio_stack_res(const STACK_RES *res) |
| 72 | { |
| 73 | return res->Personality == TYPE_UBOX_IIO; |
| 74 | } |
| 75 | |
Patrick Rudolph | 1567259 | 2024-01-18 07:57:07 +0100 | [diff] [blame] | 76 | bool is_ubox_stack_res(const STACK_RES *res) |
| 77 | { |
| 78 | return res->Personality == TYPE_UBOX; |
| 79 | } |
| 80 | |
Shuo Liu | 08f1f05 | 2024-01-20 02:52:17 +0800 | [diff] [blame] | 81 | bool is_ioat_iio_stack_res(const STACK_RES *res) |
| 82 | { |
| 83 | return res->Personality == TYPE_DINO; |
| 84 | } |
| 85 | |
Jonathan Zhang | 15fc459 | 2023-01-25 11:33:16 -0800 | [diff] [blame] | 86 | /* |
| 87 | * Given a stack resource, figure out whether the corresponding stack has |
| 88 | * CXL device. |
| 89 | * It goes through pds (proximity domains) structure to see if there is any |
| 90 | * generic initiator has device with bus # falls between bus base and |
| 91 | * bus limit. |
| 92 | */ |
| 93 | bool is_iio_cxl_stack_res(const STACK_RES *res) |
| 94 | { |
| 95 | for (uint8_t i = 0; i < pds.num_pds; i++) { |
| 96 | if (pds.pds[i].pd_type == PD_TYPE_PROCESSOR) |
| 97 | continue; |
| 98 | |
Patrick Rudolph | f25d58c | 2024-01-31 11:31:55 +0100 | [diff] [blame] | 99 | uint32_t bus = PCI_BDF(pds.pds[i].dev) >> 20; |
Jonathan Zhang | 15fc459 | 2023-01-25 11:33:16 -0800 | [diff] [blame] | 100 | if (bus >= res->BusBase && bus <= res->BusLimit) |
| 101 | return true; |
| 102 | } |
| 103 | |
| 104 | return false; |
| 105 | } |
| 106 | |
| 107 | const CXL_NODE_SOCKET *get_cxl_node(void) |
| 108 | { |
| 109 | size_t hob_size; |
| 110 | static const CXL_NODE_SOCKET *hob; |
| 111 | static bool hob_check = 0; |
| 112 | const uint8_t fsp_hob_cxl_node_socket_guid[16] = FSP_HOB_CXLNODE_GUID; |
| 113 | |
| 114 | if (hob_check == 1) |
| 115 | return hob; |
| 116 | |
| 117 | hob = fsp_find_extension_hob_by_guid(fsp_hob_cxl_node_socket_guid, &hob_size); |
| 118 | hob_check = 1; |
| 119 | if (hob == NULL || hob_size == 0) |
| 120 | printk(BIOS_DEBUG, |
| 121 | "FSP_HOB_CXLNODE_GUID not found: CXL may not be installed\n"); |
| 122 | return hob; |
| 123 | } |
| 124 | |
| 125 | uint8_t get_cxl_node_count(void) |
| 126 | { |
| 127 | const CXL_NODE_SOCKET *hob = get_cxl_node(); |
| 128 | uint8_t count = 0; |
| 129 | |
| 130 | if (hob != NULL) { |
| 131 | for (uint8_t skt_id = 0; skt_id < MAX_SOCKET; skt_id++) |
| 132 | count += hob[skt_id].CxlNodeCount; |
| 133 | } |
| 134 | |
| 135 | return count; |
| 136 | } |
| 137 | |
Patrick Rudolph | 47e6882 | 2024-01-19 16:05:56 +0100 | [diff] [blame] | 138 | /* Returns the UBOX(offset) bus number for socket0 */ |
| 139 | uint8_t socket0_get_ubox_busno(uint8_t offset) |
Jonathan Zhang | 15fc459 | 2023-01-25 11:33:16 -0800 | [diff] [blame] | 140 | { |
| 141 | const IIO_UDS *hob = get_iio_uds(); |
| 142 | |
Jonathan Zhang | 15fc459 | 2023-01-25 11:33:16 -0800 | [diff] [blame] | 143 | for (int stack = 0; stack < MAX_LOGIC_IIO_STACK; ++stack) { |
Patrick Rudolph | 47e6882 | 2024-01-19 16:05:56 +0100 | [diff] [blame] | 144 | if (hob->PlatformData.IIO_resource[0].StackRes[stack].Personality |
Jonathan Zhang | 15fc459 | 2023-01-25 11:33:16 -0800 | [diff] [blame] | 145 | == TYPE_UBOX) |
Patrick Rudolph | 47e6882 | 2024-01-19 16:05:56 +0100 | [diff] [blame] | 146 | return (hob->PlatformData.IIO_resource[0].StackRes[stack].BusBase |
Jonathan Zhang | 15fc459 | 2023-01-25 11:33:16 -0800 | [diff] [blame] | 147 | + offset); |
| 148 | } |
| 149 | die("Unable to locate UBOX BUS NO"); |
| 150 | } |
| 151 | |
Jonathan Zhang | 15fc459 | 2023-01-25 11:33:16 -0800 | [diff] [blame] | 152 | void bios_done_msr(void *unused) |
| 153 | { |
| 154 | msr_t msr = rdmsr(MSR_BIOS_DONE); |
| 155 | if (!(msr.lo & XEON_SP_ENABLE_IA_UNTRUSTED)) { /* if already locked skip update */ |
| 156 | msr.lo |= XEON_SP_ENABLE_IA_UNTRUSTED; |
| 157 | wrmsr(MSR_BIOS_DONE, msr); |
| 158 | } |
| 159 | } |
Johnny Lin | a0b199c | 2023-01-30 20:44:05 +0800 | [diff] [blame] | 160 | |
Johnny Lin | 3435f81 | 2023-01-17 10:43:19 +0800 | [diff] [blame] | 161 | void soc_set_mrc_cold_boot_flag(bool cold_boot_required) |
Johnny Lin | a0b199c | 2023-01-30 20:44:05 +0800 | [diff] [blame] | 162 | { |
| 163 | uint8_t mrc_status = cmos_read(CMOS_OFFSET_MRC_STATUS); |
| 164 | uint8_t new_mrc_status = (mrc_status & 0xfe) | cold_boot_required; |
| 165 | printk(BIOS_SPEW, "MRC status: 0x%02x want 0x%02x\n", mrc_status, new_mrc_status); |
| 166 | if (new_mrc_status != mrc_status) |
| 167 | cmos_write(new_mrc_status, CMOS_OFFSET_MRC_STATUS); |
Johnny Lin | a0b199c | 2023-01-30 20:44:05 +0800 | [diff] [blame] | 168 | } |
Shuo Liu | a5bdf8e | 2024-02-20 01:06:10 +0800 | [diff] [blame] | 169 | |
| 170 | bool is_memtype_reserved(uint16_t mem_type) |
| 171 | { |
| 172 | return !!(mem_type & MEM_TYPE_RESERVED); |
| 173 | } |
| 174 | |
| 175 | bool is_memtype_non_volatile(uint16_t mem_type) |
| 176 | { |
| 177 | return !(mem_type & MEMTYPE_VOLATILE_MASK); |
| 178 | } |
| 179 | |
| 180 | bool is_memtype_processor_attached(uint16_t mem_type) |
| 181 | { |
| 182 | /* |
| 183 | * Refer to the definition of MEM_TYPE enum type in |
| 184 | * vendorcode/intel/fsp/fsp2_0/sapphirerapids_sp/MemoryMapDataHob.h, |
| 185 | * values less than MemTypeCxlAccVolatileMem represents |
| 186 | * processor attached memory |
| 187 | */ |
| 188 | return (mem_type < MemTypeCxlAccVolatileMem); |
| 189 | } |