Marc Jones | ccfaf25 | 2020-09-28 12:06:36 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <acpi/acpi_gnvs.h> |
| 4 | #include <acpi/acpigen.h> |
| 5 | #include <arch/smp/mpspec.h> |
| 6 | #include <assert.h> |
| 7 | #include <cbmem.h> |
| 8 | #include <cpu/intel/turbo.h> |
| 9 | #include <device/mmio.h> |
| 10 | #include <device/pci.h> |
Marc Jones | 63e2a84 | 2020-12-02 11:33:02 -0700 | [diff] [blame^] | 11 | #include <intelblocks/acpi.h> |
Marc Jones | ccfaf25 | 2020-09-28 12:06:36 -0600 | [diff] [blame] | 12 | #include <soc/acpi.h> |
| 13 | #include <soc/cpu.h> |
| 14 | #include <soc/iomap.h> |
| 15 | #include <device/mmio.h> |
| 16 | #include <soc/msr.h> |
| 17 | #include <soc/pci_devs.h> |
| 18 | #include <soc/pm.h> |
| 19 | #include <soc/soc_util.h> |
Arthur Heymans | 83b2622 | 2020-11-06 11:50:55 +0100 | [diff] [blame] | 20 | #include <soc/util.h> |
Marc Jones | ccfaf25 | 2020-09-28 12:06:36 -0600 | [diff] [blame] | 21 | |
Marc Jones | ccfaf25 | 2020-09-28 12:06:36 -0600 | [diff] [blame] | 22 | /* TODO: Check if the common/acpi weak function can be used */ |
| 23 | unsigned long acpi_fill_mcfg(unsigned long current) |
| 24 | { |
| 25 | current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)current, |
| 26 | CONFIG_MMCONF_BASE_ADDRESS, 0, 0, 255); |
| 27 | return current; |
| 28 | } |
| 29 | |
| 30 | void acpi_init_gnvs(struct global_nvs *gnvs) |
| 31 | { |
| 32 | /* CPU core count */ |
| 33 | gnvs->pcnt = dev_count_cpu(); |
| 34 | printk(BIOS_DEBUG, "%s gnvs->pcnt: %d\n", __func__, gnvs->pcnt); |
| 35 | |
| 36 | /* Update the mem console pointer. */ |
| 37 | if (CONFIG(CONSOLE_CBMEM)) |
| 38 | gnvs->cbmc = (uint32_t)cbmem_find(CBMEM_ID_CONSOLE); |
| 39 | } |
| 40 | |
| 41 | int soc_madt_sci_irq_polarity(int sci) |
| 42 | { |
| 43 | if (sci >= 20) |
| 44 | return MP_IRQ_POLARITY_LOW; |
| 45 | else |
| 46 | return MP_IRQ_POLARITY_HIGH; |
| 47 | } |
| 48 | |
| 49 | uint32_t soc_read_sci_irq_select(void) |
| 50 | { |
| 51 | struct device *dev = PCH_DEV_PMC; |
| 52 | |
| 53 | if (!dev) |
| 54 | return 0; |
| 55 | |
| 56 | return pci_read_config32(dev, PMC_ACPI_CNT); |
| 57 | } |
| 58 | |
Marc Jones | 3fc0484 | 2020-10-19 16:08:27 -0600 | [diff] [blame] | 59 | void soc_fill_fadt(acpi_fadt_t *fadt) |
| 60 | { |
| 61 | const uint16_t pmbase = ACPI_BASE_ADDRESS; |
| 62 | |
| 63 | /* Fix flags set by common/block/acpi/acpi.c acpi_fill_fadt() */ |
| 64 | fadt->flags &= ~(ACPI_FADT_SEALED_CASE); |
| 65 | fadt->flags |= ACPI_FADT_SLEEP_TYPE; |
| 66 | |
| 67 | fadt->pm2_cnt_blk = pmbase + PM2_CNT; |
| 68 | fadt->pm_tmr_blk = pmbase + PM1_TMR; |
| 69 | |
| 70 | fadt->pm2_cnt_len = 1; |
| 71 | fadt->pm_tmr_len = 4; |
| 72 | |
| 73 | fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED; |
| 74 | fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED; |
| 75 | |
| 76 | fadt->duty_width = 0; |
| 77 | |
| 78 | /* RTC Registers */ |
| 79 | fadt->mon_alrm = 0x00; |
| 80 | fadt->century = 0x00; |
| 81 | fadt->iapc_boot_arch = ACPI_FADT_LEGACY_DEVICES | ACPI_FADT_8042; |
| 82 | |
| 83 | /* PM2 Control Registers */ |
| 84 | fadt->x_pm2_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 85 | fadt->x_pm2_cnt_blk.bit_width = 8; |
| 86 | fadt->x_pm2_cnt_blk.bit_offset = 0; |
| 87 | fadt->x_pm2_cnt_blk.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS; |
| 88 | fadt->x_pm2_cnt_blk.addrl = fadt->pm2_cnt_blk; |
| 89 | fadt->x_pm2_cnt_blk.addrh = 0x00; |
| 90 | |
| 91 | /* PM1 Timer Register */ |
| 92 | fadt->x_pm_tmr_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 93 | fadt->x_pm_tmr_blk.bit_width = 32; |
| 94 | fadt->x_pm_tmr_blk.bit_offset = 0; |
| 95 | fadt->x_pm_tmr_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS; |
| 96 | fadt->x_pm_tmr_blk.addrl = fadt->pm_tmr_blk; |
| 97 | fadt->x_pm_tmr_blk.addrh = 0x00; |
| 98 | |
| 99 | } |
| 100 | |
Marc Jones | 521a03f | 2020-10-19 13:46:59 -0600 | [diff] [blame] | 101 | void uncore_inject_dsdt(const struct device *device) |
Marc Jones | ccfaf25 | 2020-09-28 12:06:36 -0600 | [diff] [blame] | 102 | { |
Arthur Heymans | 83b2622 | 2020-11-06 11:50:55 +0100 | [diff] [blame] | 103 | const IIO_UDS *hob = get_iio_uds(); |
Marc Jones | ccfaf25 | 2020-09-28 12:06:36 -0600 | [diff] [blame] | 104 | |
Marc Jones | 2c70716 | 2020-10-31 15:29:14 -0600 | [diff] [blame] | 105 | /* Only add RTxx entries once. */ |
| 106 | if (device->bus->secondary != 0) |
| 107 | return; |
| 108 | |
Marc Jones | ccfaf25 | 2020-09-28 12:06:36 -0600 | [diff] [blame] | 109 | acpigen_write_scope("\\_SB"); |
| 110 | for (int socket = 0; socket < hob->PlatformData.numofIIO; ++socket) { |
| 111 | IIO_RESOURCE_INSTANCE iio_resource = |
| 112 | hob->PlatformData.IIO_resource[socket]; |
| 113 | for (int stack = 0; stack <= PSTACK2; ++stack) { |
| 114 | const STACK_RES *ri = &iio_resource.StackRes[stack]; |
| 115 | char rtname[16]; |
| 116 | snprintf(rtname, sizeof(rtname), "RT%02x", |
| 117 | (socket*MAX_IIO_STACK)+stack); |
| 118 | |
| 119 | acpigen_write_name(rtname); |
| 120 | printk(BIOS_DEBUG, "\tCreating ResourceTemplate %s for socket: %d, stack: %d\n", |
| 121 | rtname, socket, stack); |
| 122 | |
| 123 | acpigen_write_resourcetemplate_header(); |
| 124 | |
| 125 | /* bus resource */ |
| 126 | acpigen_resource_word(2, 0xc, 0, 0, ri->BusBase, ri->BusLimit, |
| 127 | 0x0, (ri->BusLimit - ri->BusBase + 1)); |
| 128 | |
| 129 | // additional io resources on socket 0 bus 0 |
| 130 | if (socket == 0 && stack == 0) { |
| 131 | /* ACPI 6.4.2.5 I/O Port Descriptor */ |
| 132 | acpigen_write_io16(0xCF8, 0xCFF, 0x1, 0x8, 1); |
| 133 | |
| 134 | /* IO decode CF8-CFF */ |
| 135 | acpigen_resource_word(1, 0xc, 0x3, 0, 0x0000, 0x03AF, |
| 136 | 0, 0x03B0); |
| 137 | acpigen_resource_word(1, 0xc, 0x3, 0, 0x03E0, 0x0CF7, |
| 138 | 0, 0x0918); |
| 139 | acpigen_resource_word(1, 0xc, 0x3, 0, 0x03B0, 0x03BB, |
| 140 | 0, 0x000C); |
| 141 | acpigen_resource_word(1, 0xc, 0x3, 0, 0x03C0, 0x03DF, |
| 142 | 0, 0x0020); |
| 143 | } |
| 144 | |
| 145 | /* IO resource */ |
| 146 | acpigen_resource_word(1, 0xc, 0x3, 0, ri->PciResourceIoBase, |
| 147 | ri->PciResourceIoLimit, 0x0, |
| 148 | (ri->PciResourceIoLimit - ri->PciResourceIoBase + 1)); |
| 149 | |
| 150 | // additional mem32 resources on socket 0 bus 0 |
| 151 | if (socket == 0 && stack == 0) { |
| 152 | acpigen_resource_dword(0, 0xc, 3, 0, VGA_BASE_ADDRESS, |
| 153 | (VGA_BASE_ADDRESS + VGA_BASE_SIZE - 1), 0x0, |
| 154 | VGA_BASE_SIZE); |
| 155 | acpigen_resource_dword(0, 0xc, 1, 0, SPI_BASE_ADDRESS, |
| 156 | (SPI_BASE_ADDRESS + SPI_BASE_SIZE - 1), 0x0, |
| 157 | SPI_BASE_SIZE); |
| 158 | } |
| 159 | |
| 160 | /* Mem32 resource */ |
| 161 | acpigen_resource_dword(0, 0xc, 1, 0, ri->PciResourceMem32Base, |
| 162 | ri->PciResourceMem32Limit, 0x0, |
| 163 | (ri->PciResourceMem32Limit - ri->PciResourceMem32Base + 1)); |
| 164 | |
| 165 | /* Mem64 resource */ |
| 166 | acpigen_resource_qword(0, 0xc, 1, 0, ri->PciResourceMem64Base, |
| 167 | ri->PciResourceMem64Limit, 0x0, |
| 168 | (ri->PciResourceMem64Limit - ri->PciResourceMem64Base + 1)); |
| 169 | |
| 170 | acpigen_write_resourcetemplate_footer(); |
| 171 | } |
| 172 | } |
| 173 | acpigen_pop_len(); |
| 174 | } |
| 175 | |
Marc Jones | 7a25fb8 | 2020-10-19 16:32:05 -0600 | [diff] [blame] | 176 | void soc_power_states_generation(int core, int cores_per_package) |
| 177 | { |
| 178 | } |
| 179 | |
Marc Jones | ccfaf25 | 2020-09-28 12:06:36 -0600 | [diff] [blame] | 180 | unsigned long xeonsp_acpi_create_madt_lapics(unsigned long current) |
| 181 | { |
| 182 | struct device *cpu; |
Marc Jones | 83729bd | 2020-11-05 17:30:26 -0700 | [diff] [blame] | 183 | uint8_t num_cpus = 0; |
Marc Jones | ccfaf25 | 2020-09-28 12:06:36 -0600 | [diff] [blame] | 184 | |
| 185 | for (cpu = all_devices; cpu; cpu = cpu->next) { |
| 186 | if ((cpu->path.type != DEVICE_PATH_APIC) || |
| 187 | (cpu->bus->dev->path.type != DEVICE_PATH_CPU_CLUSTER)) { |
| 188 | continue; |
| 189 | } |
| 190 | if (!cpu->enabled) |
| 191 | continue; |
| 192 | current += acpi_create_madt_lapic((acpi_madt_lapic_t *)current, |
| 193 | num_cpus, cpu->path.apic.apic_id); |
Marc Jones | 83729bd | 2020-11-05 17:30:26 -0700 | [diff] [blame] | 194 | num_cpus++; |
Marc Jones | ccfaf25 | 2020-09-28 12:06:36 -0600 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | return current; |
| 198 | } |