blob: cc8db642b8ec0144924e27d26b8de740f737232a [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>
10#include <soc/cpu.h>
11#include <soc/msr.h>
12#include <soc/pci_devs.h>
13#include <soc/pcr_ids.h>
14#include <soc/soc_util.h>
Andrey Petrov662da6c2020-03-16 22:46:57 -070015#include <soc/util.h>
Jonathan Zhang8f895492020-01-16 11:16:45 -080016
Jonathan Zhang8f895492020-01-16 11:16:45 -080017
18/*
19 * +-------------------------+ TOLM
20 * | System Management Mode |
21 * | code and data |
22 * | (TSEG) |
23 * +-------------------------+ SMM base (aligned)
24 * | |
25 * | Chipset Reserved Memory |
26 * | |
27 * +-------------------------+ top_of_ram (aligned)
28 * | |
29 * | CBMEM Root |
30 * | |
31 * +-------------------------+
32 * | |
33 * | FSP Reserved Memory |
34 * | |
35 * +-------------------------+
36 * | |
37 * | Various CBMEM Entries |
38 * | |
39 * +-------------------------+ top_of_stack (8 byte aligned)
40 * | |
41 * | stack (CBMEM Entry) |
42 * | |
43 * +-------------------------+
44 */
45
Marc Jones645bca42020-11-02 14:29:46 -070046const struct SystemMemoryMapHob *get_system_memory_map(void)
Jonathan Zhang8f895492020-01-16 11:16:45 -080047{
48 size_t hob_size;
Marc Jones645bca42020-11-02 14:29:46 -070049 const uint8_t mem_hob_guid[16] = FSP_SYSTEM_MEMORYMAP_HOB_GUID;
50 const struct SystemMemoryMapHob *memmap_addr;
51
52 memmap_addr = fsp_find_extension_hob_by_guid(mem_hob_guid, &hob_size);
53 assert(memmap_addr != NULL && hob_size != 0);
54
55 return memmap_addr;
56}
57
Arthur Heymans6408ada2020-11-12 17:33:00 +010058bool is_iio_stack_res(const STACK_RES *res)
Marc Jones645bca42020-11-02 14:29:46 -070059{
Arthur Heymans6408ada2020-11-12 17:33:00 +010060 // TODO: do we have situation with only bux 0 and one stack?
61 return res->BusBase < res->BusLimit;
Jonathan Zhang8f895492020-01-16 11:16:45 -080062}
63
Marc Jones5851f9d2020-11-02 15:30:10 -070064uint32_t get_socket_stack_busno(uint32_t socket, uint32_t stack)
Jonathan Zhang8f895492020-01-16 11:16:45 -080065{
Arthur Heymans83b26222020-11-06 11:50:55 +010066 const IIO_UDS *hob = get_iio_uds();
Jonathan Zhang8f895492020-01-16 11:16:45 -080067
Marc Jones645bca42020-11-02 14:29:46 -070068 assert(socket < MAX_SOCKET && stack < MAX_IIO_STACK);
Jonathan Zhang8f895492020-01-16 11:16:45 -080069
Marc Jones645bca42020-11-02 14:29:46 -070070 return hob->PlatformData.CpuQpiInfo[socket].StackBus[stack];
71}
Jonathan Zhang8f895492020-01-16 11:16:45 -080072
Marc Jones645bca42020-11-02 14:29:46 -070073void config_reset_cpl3_csrs(void)
Jonathan Zhang8f895492020-01-16 11:16:45 -080074{
Marc Jones645bca42020-11-02 14:29:46 -070075 uint32_t data, plat_info, max_min_turbo_limit_ratio;
Jonathan Zhang8f895492020-01-16 11:16:45 -080076
Marc Jones645bca42020-11-02 14:29:46 -070077 for (uint32_t socket = 0; socket < MAX_SOCKET; ++socket) {
78 uint32_t bus = get_socket_stack_busno(socket, PCU_IIO_STACK);
Jonathan Zhang8f895492020-01-16 11:16:45 -080079
Marc Jones645bca42020-11-02 14:29:46 -070080 /* configure PCU_CR0_FUN csrs */
81 pci_devfn_t cr0_dev = PCI_DEV(bus, PCU_DEV, PCU_CR0_FUN);
Nico Huberf4f365f2021-10-14 18:16:39 +020082 data = pci_s_read_config32(cr0_dev, PCU_CR0_P_STATE_LIMITS);
Marc Jones645bca42020-11-02 14:29:46 -070083 data |= P_STATE_LIMITS_LOCK;
Nico Huberf4f365f2021-10-14 18:16:39 +020084 pci_s_write_config32(cr0_dev, PCU_CR0_P_STATE_LIMITS, data);
Marc Jones645bca42020-11-02 14:29:46 -070085
Nico Huberf4f365f2021-10-14 18:16:39 +020086 plat_info = pci_s_read_config32(cr0_dev, PCU_CR0_PLATFORM_INFO);
Marc Jones645bca42020-11-02 14:29:46 -070087 dump_csr64("", cr0_dev, PCU_CR0_PLATFORM_INFO);
88 max_min_turbo_limit_ratio =
89 (plat_info & MAX_NON_TURBO_LIM_RATIO_MASK) >>
90 MAX_NON_TURBO_LIM_RATIO_SHIFT;
91 printk(BIOS_SPEW, "plat_info: 0x%x, max_min_turbo_limit_ratio: 0x%x\n",
92 plat_info, max_min_turbo_limit_ratio);
93
94 /* configure PCU_CR1_FUN csrs */
95 pci_devfn_t cr1_dev = PCI_DEV(bus, PCU_DEV, PCU_CR1_FUN);
96
Nico Huberf4f365f2021-10-14 18:16:39 +020097 data = pci_s_read_config32(cr1_dev, PCU_CR1_SAPMCTL);
Marc Jones645bca42020-11-02 14:29:46 -070098 /* clear bits 27:31 - FSP sets this with 0x7 which needs to be cleared */
99 data &= 0x0fffffff;
100 data |= SAPMCTL_LOCK_MASK;
Nico Huberf4f365f2021-10-14 18:16:39 +0200101 pci_s_write_config32(cr1_dev, PCU_CR1_SAPMCTL, data);
Marc Jones645bca42020-11-02 14:29:46 -0700102
103 /* configure PCU_CR1_FUN csrs */
104 pci_devfn_t cr2_dev = PCI_DEV(bus, PCU_DEV, PCU_CR2_FUN);
105
106 data = PCIE_IN_PKGCSTATE_L1_MASK;
Nico Huberf4f365f2021-10-14 18:16:39 +0200107 pci_s_write_config32(cr2_dev, PCU_CR2_PKG_CST_ENTRY_CRITERIA_MASK, data);
Marc Jones645bca42020-11-02 14:29:46 -0700108
109 data = KTI_IN_PKGCSTATE_L1_MASK;
Nico Huberf4f365f2021-10-14 18:16:39 +0200110 pci_s_write_config32(cr2_dev, PCU_CR2_PKG_CST_ENTRY_CRITERIA_MASK2, data);
Marc Jones645bca42020-11-02 14:29:46 -0700111
112 data = PROCHOT_RATIO;
113 printk(BIOS_SPEW, "PCU_CR2_PROCHOT_RESPONSE_RATIO_REG data: 0x%x\n", data);
Nico Huberf4f365f2021-10-14 18:16:39 +0200114 pci_s_write_config32(cr2_dev, PCU_CR2_PROCHOT_RESPONSE_RATIO_REG, data);
Marc Jones645bca42020-11-02 14:29:46 -0700115 dump_csr("", cr2_dev, PCU_CR2_PROCHOT_RESPONSE_RATIO_REG);
116
Nico Huberf4f365f2021-10-14 18:16:39 +0200117 data = pci_s_read_config32(cr2_dev, PCU_CR2_DYNAMIC_PERF_POWER_CTL);
Marc Jones645bca42020-11-02 14:29:46 -0700118 data |= UNOCRE_PLIMIT_OVERRIDE_SHIFT;
Nico Huberf4f365f2021-10-14 18:16:39 +0200119 pci_s_write_config32(cr2_dev, PCU_CR2_DYNAMIC_PERF_POWER_CTL, data);
Jonathan Zhang8f895492020-01-16 11:16:45 -0800120 }
Marc Jonese1db55b2020-09-28 16:53:19 -0600121}
Jonathan Zhang8f895492020-01-16 11:16:45 -0800122
Marc Jones995a7e22020-10-28 17:08:54 -0600123/*
124 * EX: SKX-SP
125 * Ports Stack Stack(HOB) IioConfigIou
126 * ==========================================
127 * 0 CSTACK stack 0 IOU0
128 * 1A..1D PSTACKZ stack 1 IOU1
129 * 2A..2D PSTACK1 stack 2 IOU2
130 * 3A..3D PSTACK2 stack 3 IOU3
131 * 5A..4D PSTACK3 stack 4 IOU4
132 * 5A..5D PSTACK4 stack 5 IOU5
133 */
134int soc_get_stack_for_port(int port)
135{
136 if (port == PORT_0)
137 return CSTACK;
138 else if (port >= PORT_1A && port <= PORT_1D)
139 return PSTACK0;
140 else if (port >= PORT_2A && port <= PORT_2D)
141 return PSTACK1;
142 else if (port >= PORT_3A && port <= PORT_3D)
143 return PSTACK2;
144 else if (port >= PORT_4A && port <= PORT_4D)
145 return PSTACK3; // MCP0
146 else if (port >= PORT_5A && port <= PORT_5D)
147 return PSTACK4; // MCP1
148 else
149 return -1;
150}
Arthur Heymansa1cc5572020-11-06 12:53:33 +0100151
152uint8_t soc_get_iio_ioapicid(int socket, int stack)
153{
154 uint8_t ioapic_id = socket ? 0xf : 0x9;
155 switch (stack) {
156 case CSTACK:
157 break;
158 case PSTACK0:
159 ioapic_id += 1;
160 break;
161 case PSTACK1:
162 ioapic_id += 2;
163 break;
164 case PSTACK2:
165 ioapic_id += 3;
166 break;
167 default:
168 return 0xff;
169 }
170 return ioapic_id;
171}