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