blob: d61d07489f04f8b606b785ad7f6015c81fdba764 [file] [log] [blame]
Patrick Georgiac959032020-05-05 22:49:26 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Jonathan Zhang8f895492020-01-16 11:16:45 -08002
3#include <assert.h>
Jonathan Zhang8f895492020-01-16 11:16:45 -08004#include <console/console.h>
Jonathan Zhang8f895492020-01-16 11:16:45 -08005#include <device/pci.h>
6#include <hob_iiouds.h>
7#include <intelblocks/cpulib.h>
8#include <intelblocks/pcr.h>
9#include <soc/iomap.h>
Jonathan Zhang8f895492020-01-16 11:16:45 -080010#include <soc/msr.h>
11#include <soc/pci_devs.h>
12#include <soc/pcr_ids.h>
13#include <soc/soc_util.h>
Andrey Petrov662da6c2020-03-16 22:46:57 -070014#include <soc/util.h>
Jonathan Zhang8f895492020-01-16 11:16:45 -080015
Jonathan Zhang8f895492020-01-16 11:16:45 -080016
17/*
18 * +-------------------------+ TOLM
19 * | System Management Mode |
20 * | code and data |
21 * | (TSEG) |
22 * +-------------------------+ SMM base (aligned)
23 * | |
24 * | Chipset Reserved Memory |
25 * | |
26 * +-------------------------+ top_of_ram (aligned)
27 * | |
28 * | CBMEM Root |
29 * | |
30 * +-------------------------+
31 * | |
32 * | FSP Reserved Memory |
33 * | |
34 * +-------------------------+
35 * | |
36 * | Various CBMEM Entries |
37 * | |
38 * +-------------------------+ top_of_stack (8 byte aligned)
39 * | |
40 * | stack (CBMEM Entry) |
41 * | |
42 * +-------------------------+
43 */
44
Marc Jones645bca42020-11-02 14:29:46 -070045const struct SystemMemoryMapHob *get_system_memory_map(void)
Jonathan Zhang8f895492020-01-16 11:16:45 -080046{
47 size_t hob_size;
Marc Jones645bca42020-11-02 14:29:46 -070048 const uint8_t mem_hob_guid[16] = FSP_SYSTEM_MEMORYMAP_HOB_GUID;
49 const struct SystemMemoryMapHob *memmap_addr;
50
51 memmap_addr = fsp_find_extension_hob_by_guid(mem_hob_guid, &hob_size);
Elyes Haouasf1ba7d62022-09-13 10:03:44 +020052 assert(memmap_addr && hob_size != 0);
Marc Jones645bca42020-11-02 14:29:46 -070053
54 return memmap_addr;
55}
56
Arthur Heymans550f55e2022-08-24 14:44:26 +020057bool stack_needs_resource_alloc(const STACK_RES *res)
Marc Jones645bca42020-11-02 14:29:46 -070058{
Arthur Heymans6408ada2020-11-12 17:33:00 +010059 // TODO: do we have situation with only bux 0 and one stack?
60 return res->BusBase < res->BusLimit;
Jonathan Zhang8f895492020-01-16 11:16:45 -080061}
62
Arthur Heymans550f55e2022-08-24 14:44:26 +020063bool is_pcie_iio_stack_res(const STACK_RES *res)
64{
65 return stack_needs_resource_alloc(res);
66}
67
Jonathan Zhangca520a72023-01-23 18:14:53 -080068uint8_t get_stack_busno(const uint8_t stack)
69{
70 if (stack >= MAX_IIO_STACK) {
71 printk(BIOS_ERR, "%s: Stack %u does not exist!\n", __func__, stack);
72 return 0;
73 }
74 const pci_devfn_t dev = PCI_DEV(UBOX_DECS_BUS, UBOX_DECS_DEV, UBOX_DECS_FUNC);
75 const uint16_t offset = stack / 4 ? UBOX_DECS_CPUBUSNO1_CSR : UBOX_DECS_CPUBUSNO_CSR;
76 return pci_io_read_config32(dev, offset) >> (8 * (stack % 4)) & 0xff;
77}
78
Marc Jones5851f9d2020-11-02 15:30:10 -070079uint32_t get_socket_stack_busno(uint32_t socket, uint32_t stack)
Jonathan Zhang8f895492020-01-16 11:16:45 -080080{
Arthur Heymans83b26222020-11-06 11:50:55 +010081 const IIO_UDS *hob = get_iio_uds();
Jonathan Zhang8f895492020-01-16 11:16:45 -080082
Marc Jones645bca42020-11-02 14:29:46 -070083 assert(socket < MAX_SOCKET && stack < MAX_IIO_STACK);
Jonathan Zhang8f895492020-01-16 11:16:45 -080084
Marc Jones645bca42020-11-02 14:29:46 -070085 return hob->PlatformData.CpuQpiInfo[socket].StackBus[stack];
86}
Jonathan Zhang8f895492020-01-16 11:16:45 -080087
Jonathan Zhangca520a72023-01-23 18:14:53 -080088uint32_t get_socket_ubox_busno(uint32_t socket)
89{
90 if (socket == 0)
91 return get_stack_busno(PCU_IIO_STACK);
92
93 return get_socket_stack_busno(socket, PCU_IIO_STACK);
94}
95
Marc Jones645bca42020-11-02 14:29:46 -070096void config_reset_cpl3_csrs(void)
Jonathan Zhang8f895492020-01-16 11:16:45 -080097{
Marc Jones645bca42020-11-02 14:29:46 -070098 uint32_t data, plat_info, max_min_turbo_limit_ratio;
Jonathan Zhang8f895492020-01-16 11:16:45 -080099
Marc Jones645bca42020-11-02 14:29:46 -0700100 for (uint32_t socket = 0; socket < MAX_SOCKET; ++socket) {
101 uint32_t bus = get_socket_stack_busno(socket, PCU_IIO_STACK);
Jonathan Zhang8f895492020-01-16 11:16:45 -0800102
Marc Jones645bca42020-11-02 14:29:46 -0700103 /* configure PCU_CR0_FUN csrs */
104 pci_devfn_t cr0_dev = PCI_DEV(bus, PCU_DEV, PCU_CR0_FUN);
Nico Huberf4f365f2021-10-14 18:16:39 +0200105 data = pci_s_read_config32(cr0_dev, PCU_CR0_P_STATE_LIMITS);
Marc Jones645bca42020-11-02 14:29:46 -0700106 data |= P_STATE_LIMITS_LOCK;
Nico Huberf4f365f2021-10-14 18:16:39 +0200107 pci_s_write_config32(cr0_dev, PCU_CR0_P_STATE_LIMITS, data);
Marc Jones645bca42020-11-02 14:29:46 -0700108
Nico Huberf4f365f2021-10-14 18:16:39 +0200109 plat_info = pci_s_read_config32(cr0_dev, PCU_CR0_PLATFORM_INFO);
Marc Jones645bca42020-11-02 14:29:46 -0700110 dump_csr64("", cr0_dev, PCU_CR0_PLATFORM_INFO);
111 max_min_turbo_limit_ratio =
112 (plat_info & MAX_NON_TURBO_LIM_RATIO_MASK) >>
113 MAX_NON_TURBO_LIM_RATIO_SHIFT;
114 printk(BIOS_SPEW, "plat_info: 0x%x, max_min_turbo_limit_ratio: 0x%x\n",
115 plat_info, max_min_turbo_limit_ratio);
116
117 /* configure PCU_CR1_FUN csrs */
118 pci_devfn_t cr1_dev = PCI_DEV(bus, PCU_DEV, PCU_CR1_FUN);
119
Nico Huberf4f365f2021-10-14 18:16:39 +0200120 data = pci_s_read_config32(cr1_dev, PCU_CR1_SAPMCTL);
Marc Jones645bca42020-11-02 14:29:46 -0700121 /* clear bits 27:31 - FSP sets this with 0x7 which needs to be cleared */
122 data &= 0x0fffffff;
123 data |= SAPMCTL_LOCK_MASK;
Nico Huberf4f365f2021-10-14 18:16:39 +0200124 pci_s_write_config32(cr1_dev, PCU_CR1_SAPMCTL, data);
Marc Jones645bca42020-11-02 14:29:46 -0700125
126 /* configure PCU_CR1_FUN csrs */
127 pci_devfn_t cr2_dev = PCI_DEV(bus, PCU_DEV, PCU_CR2_FUN);
128
129 data = PCIE_IN_PKGCSTATE_L1_MASK;
Nico Huberf4f365f2021-10-14 18:16:39 +0200130 pci_s_write_config32(cr2_dev, PCU_CR2_PKG_CST_ENTRY_CRITERIA_MASK, data);
Marc Jones645bca42020-11-02 14:29:46 -0700131
132 data = KTI_IN_PKGCSTATE_L1_MASK;
Nico Huberf4f365f2021-10-14 18:16:39 +0200133 pci_s_write_config32(cr2_dev, PCU_CR2_PKG_CST_ENTRY_CRITERIA_MASK2, data);
Marc Jones645bca42020-11-02 14:29:46 -0700134
135 data = PROCHOT_RATIO;
136 printk(BIOS_SPEW, "PCU_CR2_PROCHOT_RESPONSE_RATIO_REG data: 0x%x\n", data);
Nico Huberf4f365f2021-10-14 18:16:39 +0200137 pci_s_write_config32(cr2_dev, PCU_CR2_PROCHOT_RESPONSE_RATIO_REG, data);
Marc Jones645bca42020-11-02 14:29:46 -0700138 dump_csr("", cr2_dev, PCU_CR2_PROCHOT_RESPONSE_RATIO_REG);
139
Nico Huberf4f365f2021-10-14 18:16:39 +0200140 data = pci_s_read_config32(cr2_dev, PCU_CR2_DYNAMIC_PERF_POWER_CTL);
Marc Jones645bca42020-11-02 14:29:46 -0700141 data |= UNOCRE_PLIMIT_OVERRIDE_SHIFT;
Nico Huberf4f365f2021-10-14 18:16:39 +0200142 pci_s_write_config32(cr2_dev, PCU_CR2_DYNAMIC_PERF_POWER_CTL, data);
Jonathan Zhang8f895492020-01-16 11:16:45 -0800143 }
Marc Jonese1db55b2020-09-28 16:53:19 -0600144}
Jonathan Zhang8f895492020-01-16 11:16:45 -0800145
Marc Jones995a7e22020-10-28 17:08:54 -0600146/*
147 * EX: SKX-SP
148 * Ports Stack Stack(HOB) IioConfigIou
149 * ==========================================
150 * 0 CSTACK stack 0 IOU0
151 * 1A..1D PSTACKZ stack 1 IOU1
152 * 2A..2D PSTACK1 stack 2 IOU2
153 * 3A..3D PSTACK2 stack 3 IOU3
154 * 5A..4D PSTACK3 stack 4 IOU4
155 * 5A..5D PSTACK4 stack 5 IOU5
156 */
157int soc_get_stack_for_port(int port)
158{
159 if (port == PORT_0)
160 return CSTACK;
161 else if (port >= PORT_1A && port <= PORT_1D)
162 return PSTACK0;
163 else if (port >= PORT_2A && port <= PORT_2D)
164 return PSTACK1;
165 else if (port >= PORT_3A && port <= PORT_3D)
166 return PSTACK2;
167 else if (port >= PORT_4A && port <= PORT_4D)
168 return PSTACK3; // MCP0
169 else if (port >= PORT_5A && port <= PORT_5D)
170 return PSTACK4; // MCP1
171 else
172 return -1;
173}
Arthur Heymansa1cc5572020-11-06 12:53:33 +0100174
175uint8_t soc_get_iio_ioapicid(int socket, int stack)
176{
177 uint8_t ioapic_id = socket ? 0xf : 0x9;
178 switch (stack) {
179 case CSTACK:
180 break;
181 case PSTACK0:
182 ioapic_id += 1;
183 break;
184 case PSTACK1:
185 ioapic_id += 2;
186 break;
187 case PSTACK2:
188 ioapic_id += 3;
189 break;
190 default:
191 return 0xff;
192 }
193 return ioapic_id;
194}