Jonathan Zhang | 7919d61 | 2020-04-02 17:27:54 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <assert.h> |
Jonathan Zhang | b7cf7d3 | 2020-04-02 20:03:48 -0700 | [diff] [blame] | 4 | #include <device/device.h> |
Jonathan Zhang | bea1980 | 2020-04-13 19:34:53 -0700 | [diff] [blame] | 5 | #include <device/pci.h> |
Jonathan Zhang | b7cf7d3 | 2020-04-02 20:03:48 -0700 | [diff] [blame] | 6 | #include <intelblocks/cpulib.h> |
Jonathan Zhang | bea1980 | 2020-04-13 19:34:53 -0700 | [diff] [blame] | 7 | #include <soc/pci_devs.h> |
Jonathan Zhang | 7919d61 | 2020-04-02 17:27:54 -0700 | [diff] [blame] | 8 | #include <soc/soc_util.h> |
Marc Jones | 18960ce | 2020-11-02 12:41:12 -0700 | [diff] [blame] | 9 | #include <soc/util.h> |
Johnny Lin | 3435f81 | 2023-01-17 10:43:19 +0800 | [diff] [blame] | 10 | #include <pc80/mc146818rtc.h> |
Jonathan Zhang | 7919d61 | 2020-04-02 17:27:54 -0700 | [diff] [blame] | 11 | |
Jonathan Zhang | 3172f98 | 2020-05-28 17:53:48 -0700 | [diff] [blame] | 12 | const 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 Lin | 91c8ccd | 2020-08-16 00:13:29 +0800 | [diff] [blame] | 16 | const struct SystemMemoryMapHob **memmap_addr; |
Jonathan Zhang | 3172f98 | 2020-05-28 17:53:48 -0700 | [diff] [blame] | 17 | |
Johnny Lin | 91c8ccd | 2020-08-16 00:13:29 +0800 | [diff] [blame] | 18 | 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 Haouas | f1ba7d6 | 2022-09-13 10:03:44 +0200 | [diff] [blame] | 21 | assert(memmap_addr && hob_size != 0); |
Johnny Lin | 91c8ccd | 2020-08-16 00:13:29 +0800 | [diff] [blame] | 22 | /* assert the pointer to the hob is not NULL */ |
Elyes Haouas | f1ba7d6 | 2022-09-13 10:03:44 +0200 | [diff] [blame] | 23 | assert(*memmap_addr); |
Jonathan Zhang | 3172f98 | 2020-05-28 17:53:48 -0700 | [diff] [blame] | 24 | |
Johnny Lin | 91c8ccd | 2020-08-16 00:13:29 +0800 | [diff] [blame] | 25 | return *memmap_addr; |
Jonathan Zhang | 3172f98 | 2020-05-28 17:53:48 -0700 | [diff] [blame] | 26 | } |
| 27 | |
Arthur Heymans | 6408ada | 2020-11-12 17:33:00 +0100 | [diff] [blame] | 28 | bool is_iio_stack_res(const STACK_RES *res) |
Jonathan Zhang | 7919d61 | 2020-04-02 17:27:54 -0700 | [diff] [blame] | 29 | { |
Arthur Heymans | 6408ada | 2020-11-12 17:33:00 +0100 | [diff] [blame] | 30 | return res->Personality == TYPE_UBOX_IIO; |
Jonathan Zhang | 7919d61 | 2020-04-02 17:27:54 -0700 | [diff] [blame] | 31 | } |
Jonathan Zhang | bea1980 | 2020-04-13 19:34:53 -0700 | [diff] [blame] | 32 | |
Jonathan Zhang | ca520a7 | 2023-01-23 18:14:53 -0800 | [diff] [blame] | 33 | uint8_t get_stack_busno(const uint8_t stack) |
| 34 | { |
| 35 | if (stack >= MAX_IIO_STACK) { |
| 36 | printk(BIOS_ERR, "%s: Stack %u does not exist!\n", __func__, stack); |
| 37 | return 0; |
| 38 | } |
| 39 | const pci_devfn_t dev = PCI_DEV(UBOX_DECS_BUS, UBOX_DECS_DEV, UBOX_DECS_FUNC); |
| 40 | const uint16_t offset = stack / 4 ? UBOX_DECS_CPUBUSNO1_CSR : UBOX_DECS_CPUBUSNO_CSR; |
| 41 | return pci_io_read_config32(dev, offset) >> (8 * (stack % 4)) & 0xff; |
| 42 | } |
| 43 | |
Marc Jones | 5851f9d | 2020-11-02 15:30:10 -0700 | [diff] [blame] | 44 | uint32_t get_socket_stack_busno(uint32_t socket, uint32_t stack) |
Jonathan Zhang | bea1980 | 2020-04-13 19:34:53 -0700 | [diff] [blame] | 45 | { |
| 46 | const IIO_UDS *hob = get_iio_uds(); |
| 47 | |
Patrick Rudolph | ac02857 | 2023-07-14 17:44:33 +0200 | [diff] [blame] | 48 | assert(socket < CONFIG_MAX_SOCKET && stack < MAX_LOGIC_IIO_STACK); |
Jonathan Zhang | bea1980 | 2020-04-13 19:34:53 -0700 | [diff] [blame] | 49 | |
| 50 | return hob->PlatformData.IIO_resource[socket].StackRes[stack].BusBase; |
| 51 | } |
| 52 | |
Jonathan Zhang | ca520a7 | 2023-01-23 18:14:53 -0800 | [diff] [blame] | 53 | uint32_t get_socket_ubox_busno(uint32_t socket) |
| 54 | { |
| 55 | if (socket == 0) |
| 56 | return get_stack_busno(PCU_IIO_STACK); |
| 57 | |
| 58 | return get_socket_stack_busno(socket, PCU_IIO_STACK); |
| 59 | } |
| 60 | |
Marc Jones | 995a7e2 | 2020-10-28 17:08:54 -0600 | [diff] [blame] | 61 | /* |
| 62 | * EX: CPX-SP |
| 63 | * Ports Stack Stack(HOB) IioConfigIou |
| 64 | * ========================================== |
| 65 | * 0 CSTACK stack 0 IOU0 |
| 66 | * 1A..1D PSTACKZ stack 1 IOU1 |
| 67 | * 2A..2D PSTACK1 stack 2 IOU2 |
| 68 | * 3A..3D PSTACK2 stack 4 IOU3 |
| 69 | */ |
| 70 | int soc_get_stack_for_port(int port) |
| 71 | { |
| 72 | if (port == PORT_0) |
| 73 | return CSTACK; |
| 74 | else if (port >= PORT_1A && port <= PORT_1D) |
| 75 | return PSTACK0; |
| 76 | else if (port >= PORT_2A && port <= PORT_2D) |
| 77 | return PSTACK1; |
| 78 | else if (port >= PORT_3A && port <= PORT_3D) |
| 79 | return PSTACK2; |
| 80 | else |
| 81 | return -1; |
| 82 | } |
Arthur Heymans | a1cc557 | 2020-11-06 12:53:33 +0100 | [diff] [blame] | 83 | |
| 84 | uint8_t soc_get_iio_ioapicid(int socket, int stack) |
| 85 | { |
| 86 | uint8_t ioapic_id = socket ? 0xf : 0x9; |
| 87 | switch (stack) { |
| 88 | case CSTACK: |
| 89 | break; |
| 90 | case PSTACK0: |
| 91 | ioapic_id += 1; |
| 92 | break; |
| 93 | case PSTACK1: |
| 94 | ioapic_id += 2; |
| 95 | break; |
| 96 | case PSTACK2: |
| 97 | ioapic_id += 3; |
| 98 | break; |
| 99 | default: |
| 100 | return 0xff; |
| 101 | } |
| 102 | return ioapic_id; |
| 103 | } |
Johnny Lin | 3435f81 | 2023-01-17 10:43:19 +0800 | [diff] [blame] | 104 | |
| 105 | void soc_set_mrc_cold_boot_flag(bool cold_boot_required) |
| 106 | { |
| 107 | uint8_t mrc_status = cmos_read(CMOS_OFFSET_MRC_STATUS); |
| 108 | uint8_t new_mrc_status = (mrc_status & 0xfe) | cold_boot_required; |
| 109 | printk(BIOS_SPEW, "MRC status: 0x%02x want 0x%02x\n", mrc_status, new_mrc_status); |
| 110 | if (new_mrc_status != mrc_status) { |
| 111 | cmos_write(new_mrc_status, CMOS_OFFSET_MRC_STATUS); |
| 112 | } |
| 113 | } |