/* SPDX-License-Identifier: GPL-2.0-only */ #include #include #include #include #include #include #include #include #include #include #include #include const struct SystemMemoryMapHob *get_system_memory_map(void) { size_t hob_size; const uint8_t mem_hob_guid[16] = FSP_SYSTEM_MEMORYMAP_HOB_GUID; const struct SystemMemoryMapHob **memmap_addr; memmap_addr = (const struct SystemMemoryMapHob **) fsp_find_extension_hob_by_guid(mem_hob_guid, &hob_size); /* hob_size is the size of the 8-byte address not the hob data */ assert(memmap_addr != NULL && hob_size != 0); /* assert the pointer to the hob is not NULL */ assert(*memmap_addr != NULL); return *memmap_addr; } uint8_t get_iiostack_info(struct iiostack_resource *info) { size_t hob_size; const uint8_t fsp_hob_iio_universal_data_guid[16] = FSP_HOB_IIO_UNIVERSAL_DATA_GUID; const IIO_UDS *hob; hob = fsp_find_extension_hob_by_guid( fsp_hob_iio_universal_data_guid, &hob_size); assert(hob != NULL && hob_size != 0); // copy IIO Stack info from FSP HOB info->no_of_stacks = 0; for (int s = 0; s < hob->PlatformData.numofIIO; ++s) { for (int x = 0; x < MAX_IIO_STACK; ++x) { const STACK_RES *ri = &hob->PlatformData.IIO_resource[s].StackRes[x]; if (ri->Personality == TYPE_UBOX_IIO) { assert(info->no_of_stacks < ARRAY_SIZE(info->res)); memcpy(&info->res[info->no_of_stacks++], ri, sizeof(STACK_RES)); } } } return hob->PlatformData.Pci64BitResourceAllocation; } /* return true if command timed out else false */ static bool wait_for_bios_cmd_cpl(pci_devfn_t dev, uint32_t reg, uint32_t mask, uint32_t target) { const uint32_t max_delay = 5000; /* 5 seconds max */ const uint32_t step_delay = 50; /* 50 us */ struct stopwatch sw; stopwatch_init_msecs_expire(&sw, max_delay); while ((pci_s_read_config32(dev, reg) & mask) != target) { udelay(step_delay); if (stopwatch_expired(&sw)) { printk(BIOS_ERR, "%s timed out for dev: %x, reg: 0x%x, " "mask: 0x%x, target: 0x%x\n", __func__, dev, reg, mask, target); return true; /* timedout */ } } return false; /* successful */ } /* return true if command timed out else false */ static bool write_bios_mailbox_cmd(pci_devfn_t dev, uint32_t command, uint32_t data) { /* verify bios is not in busy state */ if (wait_for_bios_cmd_cpl(dev, PCU_CR1_BIOS_MB_INTERFACE_REG, BIOS_MB_RUN_BUSY_MASK, 0)) return true; /* timed out */ /* write data to data register */ printk(BIOS_SPEW, "%s - pci_s_write_config32 reg: 0x%x, data: 0x%x\n", __func__, PCU_CR1_BIOS_MB_DATA_REG, data); pci_s_write_config32(dev, PCU_CR1_BIOS_MB_DATA_REG, data); /* write the command */ printk(BIOS_SPEW, "%s - pci_s_write_config32 reg: 0x%x, data: 0x%lx\n", __func__, PCU_CR1_BIOS_MB_INTERFACE_REG, command | BIOS_MB_RUN_BUSY_MASK); pci_s_write_config32(dev, PCU_CR1_BIOS_MB_INTERFACE_REG, command | BIOS_MB_RUN_BUSY_MASK); /* wait for completion or time out*/ return wait_for_bios_cmd_cpl(dev, PCU_CR1_BIOS_MB_INTERFACE_REG, BIOS_MB_RUN_BUSY_MASK, 0); } static uint32_t get_socket_stack_busno(uint32_t socket, uint32_t stack) { const IIO_UDS *hob = get_iio_uds(); assert(socket < hob->SystemStatus.numCpus && stack < MAX_LOGIC_IIO_STACK); return hob->PlatformData.IIO_resource[socket].StackRes[stack].BusBase; } /* return true if command timed out else false */ static bool set_bios_reset_cpl_for_package(uint32_t socket, uint32_t rst_cpl_mask, uint32_t pcode_init_mask, uint32_t val) { const uint32_t bus = get_socket_stack_busno(socket, PCU_IIO_STACK); const pci_devfn_t dev = PCI_DEV(bus, PCU_DEV, PCU_CR1_FUN); uint32_t reg = pci_s_read_config32(dev, PCU_CR1_BIOS_RESET_CPL_REG); reg &= (uint32_t) ~rst_cpl_mask; reg |= val; /* update BIOS RESET completion bit */ pci_s_write_config32(dev, PCU_CR1_BIOS_RESET_CPL_REG, reg); /* wait for PCU ack */ return wait_for_bios_cmd_cpl(dev, PCU_CR1_BIOS_RESET_CPL_REG, pcode_init_mask, pcode_init_mask); } static void set_bios_init_completion_for_package(uint32_t socket) { uint32_t data; bool timedout; const uint32_t bus = get_socket_stack_busno(socket, PCU_IIO_STACK); const pci_devfn_t dev = PCI_DEV(bus, PCU_DEV, PCU_CR1_FUN); /* read PCU config */ timedout = write_bios_mailbox_cmd(dev, BIOS_CMD_READ_PCU_MISC_CFG, 0); if (timedout) { /* 2nd try */ timedout = write_bios_mailbox_cmd(dev, BIOS_CMD_READ_PCU_MISC_CFG, 0); if (timedout) die("BIOS PCU Misc Config Read timed out.\n"); /* Since the 1st try failed, we need to make sure PCU is in stable state */ data = pci_s_read_config32(dev, PCU_CR1_BIOS_MB_DATA_REG); printk(BIOS_SPEW, "%s - pci_s_read_config32 reg: 0x%x, data: 0x%x\n", __func__, PCU_CR1_BIOS_MB_DATA_REG, data); timedout = write_bios_mailbox_cmd(dev, BIOS_CMD_WRITE_PCU_MISC_CFG, data); if (timedout) die("BIOS PCU Misc Config Write timed out.\n"); } /* update RST_CPL3, PCODE_INIT_DONE3 */ timedout = set_bios_reset_cpl_for_package(socket, RST_CPL3_MASK, PCODE_INIT_DONE3_MASK, RST_CPL3_MASK); if (timedout) die("BIOS RESET CPL3 timed out.\n"); /* update RST_CPL4, PCODE_INIT_DONE4 */ timedout = set_bios_reset_cpl_for_package(socket, RST_CPL4_MASK, PCODE_INIT_DONE4_MASK, RST_CPL4_MASK); if (timedout) die("BIOS RESET CPL4 timed out.\n"); /* set CSR_DESIRED_CORES_CFG2 lock bit */ data = pci_s_read_config32(dev, PCU_CR1_DESIRED_CORES_CFG2_REG); data |= PCU_CR1_DESIRED_CORES_CFG2_REG_LOCK_MASK; printk(BIOS_SPEW, "%s - pci_s_write_config32 PCU_CR1_DESIRED_CORES_CFG2_REG 0x%x, data: 0x%x\n", __func__, PCU_CR1_DESIRED_CORES_CFG2_REG, data); pci_s_write_config32(dev, PCU_CR1_DESIRED_CORES_CFG2_REG, data); } void set_bios_init_completion(void) { /* FIXME: This may need to be changed for multi-socket platforms */ uint32_t sbsp_socket_id = 0; /* * According to the BIOS Writer's Guide, the SBSP must be the last socket * to receive the BIOS init completion message. So, we send it to all non-SBSP * sockets first. */ for (uint32_t socket = 0; socket < soc_get_num_cpus(); ++socket) { if (socket == sbsp_socket_id) continue; set_bios_init_completion_for_package(socket); } /* And finally, take care of the SBSP */ set_bios_init_completion_for_package(sbsp_socket_id); } /* * EX: CPX-SP * Ports Stack Stack(HOB) IioConfigIou * ========================================== * 0 CSTACK stack 0 IOU0 * 1A..1D PSTACKZ stack 1 IOU1 * 2A..2D PSTACK1 stack 2 IOU2 * 3A..3D PSTACK2 stack 4 IOU3 */ int soc_get_stack_for_port(int port) { if (port == PORT_0) return CSTACK; else if (port >= PORT_1A && port <= PORT_1D) return PSTACK0; else if (port >= PORT_2A && port <= PORT_2D) return PSTACK1; else if (port >= PORT_3A && port <= PORT_3D) return PSTACK2; else return -1; }