Patrick Georgi | ac95903 | 2020-05-05 22:49:26 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 2 | |
| 3 | #include <assert.h> |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 4 | #include <console/console.h> |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 5 | #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 Petrov | 662da6c | 2020-03-16 22:46:57 -0700 | [diff] [blame] | 15 | #include <soc/util.h> |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 16 | |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 17 | |
| 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 Jones | 645bca4 | 2020-11-02 14:29:46 -0700 | [diff] [blame] | 46 | const struct SystemMemoryMapHob *get_system_memory_map(void) |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 47 | { |
| 48 | size_t hob_size; |
Marc Jones | 645bca4 | 2020-11-02 14:29:46 -0700 | [diff] [blame] | 49 | 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 Heymans | 6408ada | 2020-11-12 17:33:00 +0100 | [diff] [blame] | 58 | bool is_iio_stack_res(const STACK_RES *res) |
Marc Jones | 645bca4 | 2020-11-02 14:29:46 -0700 | [diff] [blame] | 59 | { |
Arthur Heymans | 6408ada | 2020-11-12 17:33:00 +0100 | [diff] [blame] | 60 | // TODO: do we have situation with only bux 0 and one stack? |
| 61 | return res->BusBase < res->BusLimit; |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 62 | } |
| 63 | |
Marc Jones | 5851f9d | 2020-11-02 15:30:10 -0700 | [diff] [blame] | 64 | uint32_t get_socket_stack_busno(uint32_t socket, uint32_t stack) |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 65 | { |
Arthur Heymans | 83b2622 | 2020-11-06 11:50:55 +0100 | [diff] [blame] | 66 | const IIO_UDS *hob = get_iio_uds(); |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 67 | |
Marc Jones | 645bca4 | 2020-11-02 14:29:46 -0700 | [diff] [blame] | 68 | assert(socket < MAX_SOCKET && stack < MAX_IIO_STACK); |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 69 | |
Marc Jones | 645bca4 | 2020-11-02 14:29:46 -0700 | [diff] [blame] | 70 | return hob->PlatformData.CpuQpiInfo[socket].StackBus[stack]; |
| 71 | } |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 72 | |
Marc Jones | 645bca4 | 2020-11-02 14:29:46 -0700 | [diff] [blame] | 73 | void config_reset_cpl3_csrs(void) |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 74 | { |
Marc Jones | 645bca4 | 2020-11-02 14:29:46 -0700 | [diff] [blame] | 75 | uint32_t data, plat_info, max_min_turbo_limit_ratio; |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 76 | |
Marc Jones | 645bca4 | 2020-11-02 14:29:46 -0700 | [diff] [blame] | 77 | for (uint32_t socket = 0; socket < MAX_SOCKET; ++socket) { |
| 78 | uint32_t bus = get_socket_stack_busno(socket, PCU_IIO_STACK); |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 79 | |
Marc Jones | 645bca4 | 2020-11-02 14:29:46 -0700 | [diff] [blame] | 80 | /* configure PCU_CR0_FUN csrs */ |
| 81 | pci_devfn_t cr0_dev = PCI_DEV(bus, PCU_DEV, PCU_CR0_FUN); |
Nico Huber | f4f365f | 2021-10-14 18:16:39 +0200 | [diff] [blame^] | 82 | data = pci_s_read_config32(cr0_dev, PCU_CR0_P_STATE_LIMITS); |
Marc Jones | 645bca4 | 2020-11-02 14:29:46 -0700 | [diff] [blame] | 83 | data |= P_STATE_LIMITS_LOCK; |
Nico Huber | f4f365f | 2021-10-14 18:16:39 +0200 | [diff] [blame^] | 84 | pci_s_write_config32(cr0_dev, PCU_CR0_P_STATE_LIMITS, data); |
Marc Jones | 645bca4 | 2020-11-02 14:29:46 -0700 | [diff] [blame] | 85 | |
Nico Huber | f4f365f | 2021-10-14 18:16:39 +0200 | [diff] [blame^] | 86 | plat_info = pci_s_read_config32(cr0_dev, PCU_CR0_PLATFORM_INFO); |
Marc Jones | 645bca4 | 2020-11-02 14:29:46 -0700 | [diff] [blame] | 87 | 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 Huber | f4f365f | 2021-10-14 18:16:39 +0200 | [diff] [blame^] | 97 | data = pci_s_read_config32(cr1_dev, PCU_CR1_SAPMCTL); |
Marc Jones | 645bca4 | 2020-11-02 14:29:46 -0700 | [diff] [blame] | 98 | /* clear bits 27:31 - FSP sets this with 0x7 which needs to be cleared */ |
| 99 | data &= 0x0fffffff; |
| 100 | data |= SAPMCTL_LOCK_MASK; |
Nico Huber | f4f365f | 2021-10-14 18:16:39 +0200 | [diff] [blame^] | 101 | pci_s_write_config32(cr1_dev, PCU_CR1_SAPMCTL, data); |
Marc Jones | 645bca4 | 2020-11-02 14:29:46 -0700 | [diff] [blame] | 102 | |
| 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 Huber | f4f365f | 2021-10-14 18:16:39 +0200 | [diff] [blame^] | 107 | pci_s_write_config32(cr2_dev, PCU_CR2_PKG_CST_ENTRY_CRITERIA_MASK, data); |
Marc Jones | 645bca4 | 2020-11-02 14:29:46 -0700 | [diff] [blame] | 108 | |
| 109 | data = KTI_IN_PKGCSTATE_L1_MASK; |
Nico Huber | f4f365f | 2021-10-14 18:16:39 +0200 | [diff] [blame^] | 110 | pci_s_write_config32(cr2_dev, PCU_CR2_PKG_CST_ENTRY_CRITERIA_MASK2, data); |
Marc Jones | 645bca4 | 2020-11-02 14:29:46 -0700 | [diff] [blame] | 111 | |
| 112 | data = PROCHOT_RATIO; |
| 113 | printk(BIOS_SPEW, "PCU_CR2_PROCHOT_RESPONSE_RATIO_REG data: 0x%x\n", data); |
Nico Huber | f4f365f | 2021-10-14 18:16:39 +0200 | [diff] [blame^] | 114 | pci_s_write_config32(cr2_dev, PCU_CR2_PROCHOT_RESPONSE_RATIO_REG, data); |
Marc Jones | 645bca4 | 2020-11-02 14:29:46 -0700 | [diff] [blame] | 115 | dump_csr("", cr2_dev, PCU_CR2_PROCHOT_RESPONSE_RATIO_REG); |
| 116 | |
Nico Huber | f4f365f | 2021-10-14 18:16:39 +0200 | [diff] [blame^] | 117 | data = pci_s_read_config32(cr2_dev, PCU_CR2_DYNAMIC_PERF_POWER_CTL); |
Marc Jones | 645bca4 | 2020-11-02 14:29:46 -0700 | [diff] [blame] | 118 | data |= UNOCRE_PLIMIT_OVERRIDE_SHIFT; |
Nico Huber | f4f365f | 2021-10-14 18:16:39 +0200 | [diff] [blame^] | 119 | pci_s_write_config32(cr2_dev, PCU_CR2_DYNAMIC_PERF_POWER_CTL, data); |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 120 | } |
Marc Jones | e1db55b | 2020-09-28 16:53:19 -0600 | [diff] [blame] | 121 | } |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 122 | |
Marc Jones | 995a7e2 | 2020-10-28 17:08:54 -0600 | [diff] [blame] | 123 | /* |
| 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 | */ |
| 134 | int 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 Heymans | a1cc557 | 2020-11-06 12:53:33 +0100 | [diff] [blame] | 151 | |
| 152 | uint8_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 | } |