blob: e277752e5cba6c5b7d521d513714d27d5c5a33d6 [file] [log] [blame]
Jonathan Zhang7919d612020-04-02 17:27:54 -07001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <assert.h>
Jonathan Zhangb7cf7d32020-04-02 20:03:48 -07004#include <device/device.h>
Jonathan Zhangbea19802020-04-13 19:34:53 -07005#include <device/pci.h>
Jonathan Zhangb7cf7d32020-04-02 20:03:48 -07006#include <intelblocks/cpulib.h>
Jonathan Zhangbea19802020-04-13 19:34:53 -07007#include <soc/pci_devs.h>
Jonathan Zhang7919d612020-04-02 17:27:54 -07008#include <soc/soc_util.h>
Marc Jones18960ce2020-11-02 12:41:12 -07009#include <soc/util.h>
Johnny Lin3435f812023-01-17 10:43:19 +080010#include <pc80/mc146818rtc.h>
Jonathan Zhang7919d612020-04-02 17:27:54 -070011
Jonathan Zhang3172f982020-05-28 17:53:48 -070012const struct SystemMemoryMapHob *get_system_memory_map(void)
13{
14 size_t hob_size;
15 const uint8_t mem_hob_guid[16] = FSP_SYSTEM_MEMORYMAP_HOB_GUID;
Johnny Lin91c8ccd2020-08-16 00:13:29 +080016 const struct SystemMemoryMapHob **memmap_addr;
Jonathan Zhang3172f982020-05-28 17:53:48 -070017
Johnny Lin91c8ccd2020-08-16 00:13:29 +080018 memmap_addr = (const struct SystemMemoryMapHob **)
19 fsp_find_extension_hob_by_guid(mem_hob_guid, &hob_size);
20 /* hob_size is the size of the 8-byte address not the hob data */
Elyes Haouasf1ba7d62022-09-13 10:03:44 +020021 assert(memmap_addr && hob_size != 0);
Johnny Lin91c8ccd2020-08-16 00:13:29 +080022 /* assert the pointer to the hob is not NULL */
Elyes Haouasf1ba7d62022-09-13 10:03:44 +020023 assert(*memmap_addr);
Jonathan Zhang3172f982020-05-28 17:53:48 -070024
Johnny Lin91c8ccd2020-08-16 00:13:29 +080025 return *memmap_addr;
Jonathan Zhang3172f982020-05-28 17:53:48 -070026}
27
Arthur Heymans550f55e2022-08-24 14:44:26 +020028bool stack_needs_resource_alloc(const STACK_RES *res)
Jonathan Zhang7919d612020-04-02 17:27:54 -070029{
Arthur Heymans6408ada2020-11-12 17:33:00 +010030 return res->Personality == TYPE_UBOX_IIO;
Jonathan Zhang7919d612020-04-02 17:27:54 -070031}
Jonathan Zhangbea19802020-04-13 19:34:53 -070032
Arthur Heymans550f55e2022-08-24 14:44:26 +020033bool is_pcie_iio_stack_res(const STACK_RES *res)
34{
35 return stack_needs_resource_alloc(res);
36}
37
Jonathan Zhangca520a72023-01-23 18:14:53 -080038uint8_t get_stack_busno(const uint8_t stack)
39{
40 if (stack >= MAX_IIO_STACK) {
41 printk(BIOS_ERR, "%s: Stack %u does not exist!\n", __func__, stack);
42 return 0;
43 }
44 const pci_devfn_t dev = PCI_DEV(UBOX_DECS_BUS, UBOX_DECS_DEV, UBOX_DECS_FUNC);
45 const uint16_t offset = stack / 4 ? UBOX_DECS_CPUBUSNO1_CSR : UBOX_DECS_CPUBUSNO_CSR;
46 return pci_io_read_config32(dev, offset) >> (8 * (stack % 4)) & 0xff;
47}
48
Marc Jones5851f9d2020-11-02 15:30:10 -070049uint32_t get_socket_stack_busno(uint32_t socket, uint32_t stack)
Jonathan Zhangbea19802020-04-13 19:34:53 -070050{
51 const IIO_UDS *hob = get_iio_uds();
52
Patrick Rudolphac028572023-07-14 17:44:33 +020053 assert(socket < CONFIG_MAX_SOCKET && stack < MAX_LOGIC_IIO_STACK);
Jonathan Zhangbea19802020-04-13 19:34:53 -070054
55 return hob->PlatformData.IIO_resource[socket].StackRes[stack].BusBase;
56}
57
Jonathan Zhangca520a72023-01-23 18:14:53 -080058uint32_t get_socket_ubox_busno(uint32_t socket)
59{
60 if (socket == 0)
61 return get_stack_busno(PCU_IIO_STACK);
62
63 return get_socket_stack_busno(socket, PCU_IIO_STACK);
64}
65
Marc Jones995a7e22020-10-28 17:08:54 -060066/*
67 * EX: CPX-SP
68 * Ports Stack Stack(HOB) IioConfigIou
69 * ==========================================
70 * 0 CSTACK stack 0 IOU0
71 * 1A..1D PSTACKZ stack 1 IOU1
72 * 2A..2D PSTACK1 stack 2 IOU2
73 * 3A..3D PSTACK2 stack 4 IOU3
74 */
75int soc_get_stack_for_port(int port)
76{
77 if (port == PORT_0)
78 return CSTACK;
79 else if (port >= PORT_1A && port <= PORT_1D)
80 return PSTACK0;
81 else if (port >= PORT_2A && port <= PORT_2D)
82 return PSTACK1;
83 else if (port >= PORT_3A && port <= PORT_3D)
84 return PSTACK2;
85 else
86 return -1;
87}
Arthur Heymansa1cc5572020-11-06 12:53:33 +010088
89uint8_t soc_get_iio_ioapicid(int socket, int stack)
90{
91 uint8_t ioapic_id = socket ? 0xf : 0x9;
92 switch (stack) {
93 case CSTACK:
94 break;
95 case PSTACK0:
96 ioapic_id += 1;
97 break;
98 case PSTACK1:
99 ioapic_id += 2;
100 break;
101 case PSTACK2:
102 ioapic_id += 3;
103 break;
104 default:
105 return 0xff;
106 }
107 return ioapic_id;
108}
Johnny Lin3435f812023-01-17 10:43:19 +0800109
110void soc_set_mrc_cold_boot_flag(bool cold_boot_required)
111{
112 uint8_t mrc_status = cmos_read(CMOS_OFFSET_MRC_STATUS);
113 uint8_t new_mrc_status = (mrc_status & 0xfe) | cold_boot_required;
114 printk(BIOS_SPEW, "MRC status: 0x%02x want 0x%02x\n", mrc_status, new_mrc_status);
115 if (new_mrc_status != mrc_status) {
116 cmos_write(new_mrc_status, CMOS_OFFSET_MRC_STATUS);
117 }
118}