Aaron Durbin | 61cd57b | 2013-10-30 14:36:11 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2007-2009 coresystems GmbH |
| 5 | * Copyright (C) 2013 Google Inc. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
| 20 | |
| 21 | #include <arch/acpi.h> |
| 22 | #include <arch/acpigen.h> |
Aaron Durbin | 1af3663 | 2013-11-07 10:42:16 -0600 | [diff] [blame] | 23 | #include <arch/io.h> |
| 24 | #include <arch/smp/mpspec.h> |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 25 | #include <cbmem.h> |
Aaron Durbin | 1af3663 | 2013-11-07 10:42:16 -0600 | [diff] [blame] | 26 | #include <console/console.h> |
Aaron Durbin | 303525b | 2013-11-05 11:42:32 -0600 | [diff] [blame] | 27 | #include <cpu/x86/smm.h> |
Duncan Laurie | 8923be5 | 2013-11-05 13:02:30 -0800 | [diff] [blame] | 28 | #include <console/console.h> |
Aaron Durbin | 61cd57b | 2013-10-30 14:36:11 -0500 | [diff] [blame] | 29 | #include <types.h> |
| 30 | #include <string.h> |
Duncan Laurie | 8923be5 | 2013-11-05 13:02:30 -0800 | [diff] [blame] | 31 | #include <arch/cpu.h> |
| 32 | #include <cpu/x86/msr.h> |
| 33 | #include <cpu/x86/tsc.h> |
| 34 | #include <cpu/intel/turbo.h> |
Aaron Durbin | 61cd57b | 2013-10-30 14:36:11 -0500 | [diff] [blame] | 35 | |
Julius Werner | 18ea2d3 | 2014-10-07 16:42:17 -0700 | [diff] [blame^] | 36 | #include <soc/acpi.h> |
| 37 | #include <soc/iomap.h> |
| 38 | #include <soc/irq.h> |
| 39 | #include <soc/msr.h> |
| 40 | #include <soc/pattrs.h> |
| 41 | #include <soc/pmc.h> |
Aaron Durbin | 61cd57b | 2013-10-30 14:36:11 -0500 | [diff] [blame] | 42 | |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 43 | #include <ec/google/chromeec/ec.h> |
| 44 | #include <vendorcode/google/chromeos/gnvs.h> |
| 45 | |
Duncan Laurie | 8923be5 | 2013-11-05 13:02:30 -0800 | [diff] [blame] | 46 | #define MWAIT_RES(state, sub_state) \ |
| 47 | { \ |
| 48 | .addrl = (((state) << 4) | (sub_state)), \ |
| 49 | .space_id = ACPI_ADDRESS_SPACE_FIXED, \ |
| 50 | .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL, \ |
| 51 | .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT, \ |
| 52 | .access_size = ACPI_FFIXEDHW_FLAG_HW_COORD, \ |
| 53 | } |
| 54 | |
| 55 | /* C-state map without S0ix */ |
| 56 | static acpi_cstate_t cstate_map[] = { |
| 57 | { |
| 58 | /* C1 */ |
| 59 | .ctype = 1, /* ACPI C1 */ |
| 60 | .latency = 1, |
| 61 | .power = 1000, |
| 62 | .resource = MWAIT_RES(0, 0), |
| 63 | }, |
| 64 | { |
| 65 | /* C6NS with no L2 shrink */ |
| 66 | /* NOTE: this substate is above CPUID limit */ |
| 67 | .ctype = 2, /* ACPI C2 */ |
| 68 | .latency = 500, |
| 69 | .power = 10, |
Duncan Laurie | 22f1dcd | 2013-12-02 10:14:47 -0800 | [diff] [blame] | 70 | .resource = MWAIT_RES(5, 1), |
Duncan Laurie | 8923be5 | 2013-11-05 13:02:30 -0800 | [diff] [blame] | 71 | }, |
| 72 | { |
| 73 | /* C6FS with full L2 shrink */ |
| 74 | .ctype = 3, /* ACPI C3 */ |
| 75 | .latency = 1500, /* 1.5ms worst case */ |
Aaron Durbin | 4177db5 | 2014-02-05 14:55:26 -0600 | [diff] [blame] | 76 | .power = 1, |
Duncan Laurie | 8923be5 | 2013-11-05 13:02:30 -0800 | [diff] [blame] | 77 | .resource = MWAIT_RES(5, 2), |
| 78 | } |
| 79 | }; |
| 80 | |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 81 | void acpi_init_gnvs(global_nvs_t *gnvs) |
| 82 | { |
| 83 | /* Set unknown wake source */ |
| 84 | gnvs->pm1i = -1; |
| 85 | |
| 86 | /* CPU core count */ |
| 87 | gnvs->pcnt = dev_count_cpu(); |
| 88 | |
| 89 | /* Top of Low Memory (start of resource allocation) */ |
| 90 | gnvs->tolm = nc_read_top_of_low_memory(); |
| 91 | |
| 92 | #if CONFIG_CONSOLE_CBMEM |
| 93 | /* Update the mem console pointer. */ |
| 94 | gnvs->cbmc = (u32)cbmem_find(CBMEM_ID_CONSOLE); |
| 95 | #endif |
| 96 | |
| 97 | #if CONFIG_CHROMEOS |
| 98 | /* Initialize Verified Boot data */ |
| 99 | chromeos_init_vboot(&(gnvs->chromeos)); |
| 100 | #if CONFIG_EC_GOOGLE_CHROMEEC |
| 101 | gnvs->chromeos.vbt2 = google_ec_running_ro() ? |
| 102 | ACTIVE_ECFW_RO : ACTIVE_ECFW_RW; |
| 103 | #endif |
| 104 | #endif |
| 105 | } |
| 106 | |
Aaron Durbin | 1af3663 | 2013-11-07 10:42:16 -0600 | [diff] [blame] | 107 | static int acpi_sci_irq(void) |
| 108 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 109 | u32 *actl = (u32 *)(ILB_BASE_ADDRESS + ACTL); |
Aaron Durbin | 1af3663 | 2013-11-07 10:42:16 -0600 | [diff] [blame] | 110 | int scis; |
| 111 | static int sci_irq; |
| 112 | |
| 113 | if (sci_irq) |
| 114 | return sci_irq; |
| 115 | |
| 116 | /* Determine how SCI is routed. */ |
| 117 | scis = read32(actl) & SCIS_MASK; |
| 118 | switch (scis) { |
| 119 | case SCIS_IRQ9: |
| 120 | case SCIS_IRQ10: |
| 121 | case SCIS_IRQ11: |
| 122 | sci_irq = scis - SCIS_IRQ9 + 9; |
| 123 | break; |
| 124 | case SCIS_IRQ20: |
| 125 | case SCIS_IRQ21: |
| 126 | case SCIS_IRQ22: |
| 127 | case SCIS_IRQ23: |
| 128 | sci_irq = scis - SCIS_IRQ20 + 20; |
| 129 | break; |
| 130 | default: |
| 131 | printk(BIOS_DEBUG, "Invalid SCI route! Defaulting to IRQ9.\n"); |
| 132 | sci_irq = 9; |
| 133 | break; |
| 134 | } |
| 135 | |
| 136 | printk(BIOS_DEBUG, "SCI is IRQ%d\n", sci_irq); |
| 137 | return sci_irq; |
| 138 | } |
| 139 | |
Aaron Durbin | 61cd57b | 2013-10-30 14:36:11 -0500 | [diff] [blame] | 140 | void acpi_create_intel_hpet(acpi_hpet_t * hpet) |
| 141 | { |
| 142 | acpi_header_t *header = &(hpet->header); |
| 143 | acpi_addr_t *addr = &(hpet->addr); |
| 144 | |
| 145 | memset((void *) hpet, 0, sizeof(acpi_hpet_t)); |
| 146 | |
| 147 | /* fill out header fields */ |
| 148 | memcpy(header->signature, "HPET", 4); |
| 149 | memcpy(header->oem_id, OEM_ID, 6); |
| 150 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 151 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 152 | |
| 153 | header->length = sizeof(acpi_hpet_t); |
| 154 | header->revision = 1; |
| 155 | |
| 156 | /* fill out HPET address */ |
| 157 | addr->space_id = 0; /* Memory */ |
| 158 | addr->bit_width = 64; |
| 159 | addr->bit_offset = 0; |
| 160 | addr->addrl = (unsigned long long)HPET_BASE_ADDRESS & 0xffffffff; |
| 161 | addr->addrh = (unsigned long long)HPET_BASE_ADDRESS >> 32; |
| 162 | |
| 163 | hpet->id = 0x8086a201; /* Intel */ |
| 164 | hpet->number = 0x00; |
| 165 | hpet->min_tick = 0x0080; |
| 166 | |
| 167 | header->checksum = |
| 168 | acpi_checksum((void *) hpet, sizeof(acpi_hpet_t)); |
| 169 | } |
Duncan Laurie | 03ff2a2 | 2013-11-04 17:15:20 -0800 | [diff] [blame] | 170 | |
| 171 | unsigned long acpi_fill_mcfg(unsigned long current) |
| 172 | { |
| 173 | current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)current, |
| 174 | MCFG_BASE_ADDRESS, 0, 0, 255); |
| 175 | return current; |
| 176 | } |
Aaron Durbin | 303525b | 2013-11-05 11:42:32 -0600 | [diff] [blame] | 177 | |
| 178 | void acpi_fill_in_fadt(acpi_fadt_t *fadt) |
| 179 | { |
| 180 | const uint16_t pmbase = ACPI_BASE_ADDRESS; |
| 181 | |
Aaron Durbin | 1af3663 | 2013-11-07 10:42:16 -0600 | [diff] [blame] | 182 | fadt->sci_int = acpi_sci_irq(); |
Aaron Durbin | 303525b | 2013-11-05 11:42:32 -0600 | [diff] [blame] | 183 | fadt->smi_cmd = APM_CNT; |
| 184 | fadt->acpi_enable = APM_CNT_ACPI_ENABLE; |
| 185 | fadt->acpi_disable = APM_CNT_ACPI_DISABLE; |
| 186 | fadt->s4bios_req = 0x0; |
| 187 | fadt->pstate_cnt = 0; |
| 188 | |
| 189 | fadt->pm1a_evt_blk = pmbase + PM1_STS; |
| 190 | fadt->pm1b_evt_blk = 0x0; |
| 191 | fadt->pm1a_cnt_blk = pmbase + PM1_CNT; |
| 192 | fadt->pm1b_cnt_blk = 0x0; |
| 193 | fadt->pm2_cnt_blk = pmbase + PM2A_CNT_BLK; |
| 194 | fadt->pm_tmr_blk = pmbase + PM1_TMR; |
| 195 | fadt->gpe0_blk = pmbase + GPE0_STS; |
| 196 | fadt->gpe1_blk = 0; |
| 197 | |
| 198 | fadt->pm1_evt_len = 4; |
| 199 | fadt->pm1_cnt_len = 2; |
| 200 | fadt->pm2_cnt_len = 1; |
| 201 | fadt->pm_tmr_len = 4; |
Aaron Durbin | 997d252 | 2013-11-08 17:37:48 -0600 | [diff] [blame] | 202 | fadt->gpe0_blk_len = 2 * (GPE0_EN - GPE0_STS); |
Aaron Durbin | 303525b | 2013-11-05 11:42:32 -0600 | [diff] [blame] | 203 | fadt->gpe1_blk_len = 0; |
| 204 | fadt->gpe1_base = 0; |
| 205 | fadt->cst_cnt = 0; |
| 206 | fadt->p_lvl2_lat = 1; |
| 207 | fadt->p_lvl3_lat = 87; |
| 208 | fadt->flush_size = 1024; |
| 209 | fadt->flush_stride = 16; |
| 210 | fadt->duty_offset = 1; |
| 211 | fadt->duty_width = 0; |
| 212 | fadt->day_alrm = 0xd; |
| 213 | fadt->mon_alrm = 0x00; |
| 214 | fadt->century = 0x00; |
| 215 | fadt->iapc_boot_arch = ACPI_FADT_LEGACY_DEVICES | ACPI_FADT_8042; |
| 216 | |
| 217 | fadt->flags = ACPI_FADT_WBINVD | ACPI_FADT_C1_SUPPORTED | |
| 218 | ACPI_FADT_C2_MP_SUPPORTED | ACPI_FADT_SLEEP_BUTTON | |
| 219 | ACPI_FADT_RESET_REGISTER | ACPI_FADT_SEALED_CASE | |
| 220 | ACPI_FADT_S4_RTC_WAKE | ACPI_FADT_PLATFORM_CLOCK; |
| 221 | |
| 222 | fadt->reset_reg.space_id = 1; |
| 223 | fadt->reset_reg.bit_width = 8; |
| 224 | fadt->reset_reg.bit_offset = 0; |
| 225 | fadt->reset_reg.resv = 0; |
| 226 | fadt->reset_reg.addrl = 0xcf9; |
| 227 | fadt->reset_reg.addrh = 0; |
| 228 | fadt->reset_value = 6; |
| 229 | |
| 230 | fadt->x_pm1a_evt_blk.space_id = 1; |
Aaron Durbin | 997d252 | 2013-11-08 17:37:48 -0600 | [diff] [blame] | 231 | fadt->x_pm1a_evt_blk.bit_width = fadt->pm1_evt_len * 8; |
Aaron Durbin | 303525b | 2013-11-05 11:42:32 -0600 | [diff] [blame] | 232 | fadt->x_pm1a_evt_blk.bit_offset = 0; |
| 233 | fadt->x_pm1a_evt_blk.resv = 0; |
| 234 | fadt->x_pm1a_evt_blk.addrl = pmbase + PM1_STS; |
| 235 | fadt->x_pm1a_evt_blk.addrh = 0x0; |
| 236 | |
| 237 | fadt->x_pm1b_evt_blk.space_id = 1; |
| 238 | fadt->x_pm1b_evt_blk.bit_width = 0; |
| 239 | fadt->x_pm1b_evt_blk.bit_offset = 0; |
| 240 | fadt->x_pm1b_evt_blk.resv = 0; |
| 241 | fadt->x_pm1b_evt_blk.addrl = 0x0; |
| 242 | fadt->x_pm1b_evt_blk.addrh = 0x0; |
| 243 | |
| 244 | fadt->x_pm1a_cnt_blk.space_id = 1; |
Aaron Durbin | 997d252 | 2013-11-08 17:37:48 -0600 | [diff] [blame] | 245 | fadt->x_pm1a_cnt_blk.bit_width = fadt->pm1_cnt_len * 8; |
Aaron Durbin | 303525b | 2013-11-05 11:42:32 -0600 | [diff] [blame] | 246 | fadt->x_pm1a_cnt_blk.bit_offset = 0; |
| 247 | fadt->x_pm1a_cnt_blk.resv = 0; |
| 248 | fadt->x_pm1a_cnt_blk.addrl = pmbase + PM1_CNT; |
| 249 | fadt->x_pm1a_cnt_blk.addrh = 0x0; |
| 250 | |
| 251 | fadt->x_pm1b_cnt_blk.space_id = 1; |
| 252 | fadt->x_pm1b_cnt_blk.bit_width = 0; |
| 253 | fadt->x_pm1b_cnt_blk.bit_offset = 0; |
| 254 | fadt->x_pm1b_cnt_blk.resv = 0; |
| 255 | fadt->x_pm1b_cnt_blk.addrl = 0x0; |
| 256 | fadt->x_pm1b_cnt_blk.addrh = 0x0; |
| 257 | |
| 258 | fadt->x_pm2_cnt_blk.space_id = 1; |
Aaron Durbin | 997d252 | 2013-11-08 17:37:48 -0600 | [diff] [blame] | 259 | fadt->x_pm2_cnt_blk.bit_width = fadt->pm2_cnt_len * 8; |
Aaron Durbin | 303525b | 2013-11-05 11:42:32 -0600 | [diff] [blame] | 260 | fadt->x_pm2_cnt_blk.bit_offset = 0; |
| 261 | fadt->x_pm2_cnt_blk.resv = 0; |
| 262 | fadt->x_pm2_cnt_blk.addrl = pmbase + PM2A_CNT_BLK; |
| 263 | fadt->x_pm2_cnt_blk.addrh = 0x0; |
| 264 | |
| 265 | fadt->x_pm_tmr_blk.space_id = 1; |
Aaron Durbin | 997d252 | 2013-11-08 17:37:48 -0600 | [diff] [blame] | 266 | fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8; |
Aaron Durbin | 303525b | 2013-11-05 11:42:32 -0600 | [diff] [blame] | 267 | fadt->x_pm_tmr_blk.bit_offset = 0; |
| 268 | fadt->x_pm_tmr_blk.resv = 0; |
| 269 | fadt->x_pm_tmr_blk.addrl = pmbase + PM1_TMR; |
| 270 | fadt->x_pm_tmr_blk.addrh = 0x0; |
| 271 | |
| 272 | fadt->x_gpe0_blk.space_id = 1; |
Aaron Durbin | 997d252 | 2013-11-08 17:37:48 -0600 | [diff] [blame] | 273 | fadt->x_gpe0_blk.bit_width = fadt->gpe0_blk_len * 8; |
Aaron Durbin | 303525b | 2013-11-05 11:42:32 -0600 | [diff] [blame] | 274 | fadt->x_gpe0_blk.bit_offset = 0; |
| 275 | fadt->x_gpe0_blk.resv = 0; |
| 276 | fadt->x_gpe0_blk.addrl = pmbase + GPE0_STS; |
| 277 | fadt->x_gpe0_blk.addrh = 0x0; |
| 278 | |
| 279 | fadt->x_gpe1_blk.space_id = 1; |
| 280 | fadt->x_gpe1_blk.bit_width = 0; |
| 281 | fadt->x_gpe1_blk.bit_offset = 0; |
| 282 | fadt->x_gpe1_blk.resv = 0; |
| 283 | fadt->x_gpe1_blk.addrl = 0x0; |
| 284 | fadt->x_gpe1_blk.addrh = 0x0; |
Duncan Laurie | 8923be5 | 2013-11-05 13:02:30 -0800 | [diff] [blame] | 285 | } |
Aaron Durbin | 303525b | 2013-11-05 11:42:32 -0600 | [diff] [blame] | 286 | |
Duncan Laurie | 8923be5 | 2013-11-05 13:02:30 -0800 | [diff] [blame] | 287 | static acpi_tstate_t baytrail_tss_table[] = { |
| 288 | { 100, 1000, 0, 0x00, 0 }, |
| 289 | { 88, 875, 0, 0x1e, 0 }, |
| 290 | { 75, 750, 0, 0x1c, 0 }, |
| 291 | { 63, 625, 0, 0x1a, 0 }, |
| 292 | { 50, 500, 0, 0x18, 0 }, |
| 293 | { 38, 375, 0, 0x16, 0 }, |
| 294 | { 25, 250, 0, 0x14, 0 }, |
| 295 | { 13, 125, 0, 0x12, 0 }, |
| 296 | }; |
| 297 | |
| 298 | static int generate_T_state_entries(int core, int cores_per_package) |
| 299 | { |
| 300 | int len; |
| 301 | |
| 302 | /* Indicate SW_ALL coordination for T-states */ |
| 303 | len = acpigen_write_TSD_package(core, cores_per_package, SW_ALL); |
| 304 | |
| 305 | /* Indicate FFixedHW so OS will use MSR */ |
| 306 | len += acpigen_write_empty_PTC(); |
| 307 | |
| 308 | /* Set NVS controlled T-state limit */ |
| 309 | len += acpigen_write_TPC("\\TLVL"); |
| 310 | |
| 311 | /* Write TSS table for MSR access */ |
| 312 | len += acpigen_write_TSS_package( |
| 313 | ARRAY_SIZE(baytrail_tss_table), baytrail_tss_table); |
| 314 | |
| 315 | return len; |
| 316 | } |
| 317 | |
| 318 | static int calculate_power(int tdp, int p1_ratio, int ratio) |
| 319 | { |
| 320 | u32 m; |
| 321 | u32 power; |
| 322 | |
| 323 | /* |
| 324 | * M = ((1.1 - ((p1_ratio - ratio) * 0.00625)) / 1.1) ^ 2 |
| 325 | * |
| 326 | * Power = (ratio / p1_ratio) * m * tdp |
| 327 | */ |
| 328 | |
| 329 | m = (110000 - ((p1_ratio - ratio) * 625)) / 11; |
| 330 | m = (m * m) / 1000; |
| 331 | |
| 332 | power = ((ratio * 100000 / p1_ratio) / 100); |
| 333 | power *= (m / 100) * (tdp / 1000); |
| 334 | power /= 1000; |
| 335 | |
| 336 | return (int)power; |
| 337 | } |
| 338 | |
| 339 | static int generate_P_state_entries(int core, int cores_per_package) |
| 340 | { |
| 341 | int len, len_pss; |
| 342 | int ratio_min, ratio_max, ratio_turbo, ratio_step, ratio_range_2; |
| 343 | int coord_type, power_max, power_unit, num_entries; |
| 344 | int ratio, power, clock, clock_max; |
| 345 | int vid, vid_turbo, vid_min, vid_max, vid_range_2; |
| 346 | u32 control_status; |
| 347 | const struct pattrs *pattrs = pattrs_get(); |
| 348 | msr_t msr; |
| 349 | |
| 350 | /* Inputs from CPU attributes */ |
| 351 | ratio_max = pattrs->iacore_ratios[IACORE_MAX]; |
| 352 | ratio_min = pattrs->iacore_ratios[IACORE_LFM]; |
| 353 | vid_max = pattrs->iacore_vids[IACORE_MAX]; |
| 354 | vid_min = pattrs->iacore_vids[IACORE_LFM]; |
| 355 | |
Aaron Durbin | 4177db5 | 2014-02-05 14:55:26 -0600 | [diff] [blame] | 356 | /* Set P-states coordination type based on MSR disable bit */ |
Duncan Laurie | 31ac9e3 | 2014-03-28 10:52:13 -0700 | [diff] [blame] | 357 | coord_type = (pattrs->num_cpus > 2) ? SW_ALL : HW_ALL; |
Duncan Laurie | 8923be5 | 2013-11-05 13:02:30 -0800 | [diff] [blame] | 358 | |
| 359 | /* Max Non-Turbo Frequency */ |
| 360 | clock_max = (ratio_max * pattrs->bclk_khz) / 1000; |
| 361 | |
| 362 | /* Calculate CPU TDP in mW */ |
| 363 | msr = rdmsr(MSR_PKG_POWER_SKU_UNIT); |
| 364 | power_unit = 1 << (msr.lo & 0xf); |
| 365 | msr = rdmsr(MSR_PKG_POWER_LIMIT); |
| 366 | power_max = ((msr.lo & 0x7fff) / power_unit) * 1000; |
| 367 | |
| 368 | /* Write _PCT indicating use of FFixedHW */ |
| 369 | len = acpigen_write_empty_PCT(); |
| 370 | |
Duncan Laurie | ad8d913 | 2013-12-10 07:41:33 -0800 | [diff] [blame] | 371 | /* Write _PPC with NVS specified limit on supported P-state */ |
| 372 | len += acpigen_write_PPC_NVS(); |
Duncan Laurie | 8923be5 | 2013-11-05 13:02:30 -0800 | [diff] [blame] | 373 | |
| 374 | /* Write PSD indicating configured coordination type */ |
| 375 | len += acpigen_write_PSD_package(core, 1, coord_type); |
| 376 | |
| 377 | /* Add P-state entries in _PSS table */ |
| 378 | len += acpigen_write_name("_PSS"); |
| 379 | |
| 380 | /* Determine ratio points */ |
| 381 | ratio_step = 1; |
| 382 | num_entries = (ratio_max - ratio_min) / ratio_step; |
| 383 | while (num_entries > 15) { /* ACPI max is 15 ratios */ |
| 384 | ratio_step <<= 1; |
| 385 | num_entries >>= 1; |
| 386 | } |
| 387 | |
| 388 | /* P[T] is Turbo state if enabled */ |
| 389 | if (get_turbo_state() == TURBO_ENABLED) { |
| 390 | /* _PSS package count including Turbo */ |
| 391 | len_pss = acpigen_write_package(num_entries + 2); |
| 392 | |
| 393 | ratio_turbo = pattrs->iacore_ratios[IACORE_TURBO]; |
| 394 | vid_turbo = pattrs->iacore_vids[IACORE_TURBO]; |
| 395 | control_status = (ratio_turbo << 8) | vid_turbo; |
| 396 | |
| 397 | /* Add entry for Turbo ratio */ |
| 398 | len_pss += acpigen_write_PSS_package( |
| 399 | clock_max + 1, /*MHz*/ |
| 400 | power_max, /*mW*/ |
| 401 | 10, /*lat1*/ |
| 402 | 10, /*lat2*/ |
| 403 | control_status, /*control*/ |
| 404 | control_status); /*status*/ |
| 405 | } else { |
| 406 | /* _PSS package count without Turbo */ |
| 407 | len_pss = acpigen_write_package(num_entries + 1); |
| 408 | ratio_turbo = ratio_max; |
| 409 | vid_turbo = vid_max; |
| 410 | } |
| 411 | |
| 412 | /* First regular entry is max non-turbo ratio */ |
| 413 | control_status = (ratio_max << 8) | vid_max; |
| 414 | len_pss += acpigen_write_PSS_package( |
| 415 | clock_max, /*MHz*/ |
| 416 | power_max, /*mW*/ |
| 417 | 10, /*lat1*/ |
| 418 | 10, /*lat2*/ |
| 419 | control_status, /*control */ |
| 420 | control_status); /*status*/ |
| 421 | |
| 422 | /* Set up ratio and vid ranges for VID calculation */ |
| 423 | ratio_range_2 = (ratio_turbo - ratio_min) * 2; |
| 424 | vid_range_2 = (vid_turbo - vid_min) * 2; |
| 425 | |
| 426 | /* Generate the remaining entries */ |
| 427 | for (ratio = ratio_min + ((num_entries - 1) * ratio_step); |
| 428 | ratio >= ratio_min; ratio -= ratio_step) { |
| 429 | |
| 430 | /* Calculate VID for this ratio */ |
| 431 | vid = ((ratio - ratio_min) * vid_range_2) / |
| 432 | ratio_range_2 + vid_min; |
| 433 | /* Round up if remainder */ |
| 434 | if (((ratio - ratio_min) * vid_range_2) % ratio_range_2) |
| 435 | vid++; |
| 436 | |
| 437 | /* Calculate power at this ratio */ |
| 438 | power = calculate_power(power_max, ratio_max, ratio); |
| 439 | clock = (ratio * pattrs->bclk_khz) / 1000; |
| 440 | control_status = (ratio << 8) | (vid & 0xff); |
| 441 | |
| 442 | len_pss += acpigen_write_PSS_package( |
| 443 | clock, /*MHz*/ |
| 444 | power, /*mW*/ |
| 445 | 10, /*lat1*/ |
| 446 | 10, /*lat2*/ |
| 447 | control_status, /*control*/ |
| 448 | control_status); /*status*/ |
| 449 | } |
| 450 | |
| 451 | /* Fix package length */ |
| 452 | len_pss--; |
| 453 | acpigen_patch_len(len_pss); |
| 454 | |
| 455 | return len + len_pss; |
| 456 | } |
| 457 | |
| 458 | void generate_cpu_entries(void) |
| 459 | { |
| 460 | int len_pr, core; |
| 461 | int pcontrol_blk = get_pmbase(), plen = 6; |
| 462 | const struct pattrs *pattrs = pattrs_get(); |
| 463 | |
| 464 | for (core=0; core<pattrs->num_cpus; core++) { |
| 465 | if (core > 0) { |
| 466 | pcontrol_blk = 0; |
| 467 | plen = 0; |
| 468 | } |
| 469 | |
| 470 | /* Generate processor \_PR.CPUx */ |
| 471 | len_pr = acpigen_write_processor( |
| 472 | core, pcontrol_blk, plen); |
| 473 | |
| 474 | /* Generate P-state tables */ |
| 475 | len_pr += generate_P_state_entries( |
| 476 | core, pattrs->num_cpus); |
| 477 | |
| 478 | /* Generate C-state tables */ |
| 479 | len_pr += acpigen_write_CST_package( |
| 480 | cstate_map, ARRAY_SIZE(cstate_map)); |
| 481 | |
| 482 | /* Generate T-state tables */ |
| 483 | len_pr += generate_T_state_entries( |
| 484 | core, pattrs->num_cpus); |
| 485 | |
| 486 | len_pr--; |
| 487 | acpigen_patch_len(len_pr); |
| 488 | } |
Aaron Durbin | 303525b | 2013-11-05 11:42:32 -0600 | [diff] [blame] | 489 | } |
Aaron Durbin | 1af3663 | 2013-11-07 10:42:16 -0600 | [diff] [blame] | 490 | |
| 491 | unsigned long acpi_madt_irq_overrides(unsigned long current) |
| 492 | { |
| 493 | int sci_irq = acpi_sci_irq(); |
| 494 | acpi_madt_irqoverride_t *irqovr; |
| 495 | uint16_t sci_flags = MP_IRQ_TRIGGER_LEVEL; |
| 496 | |
| 497 | /* INT_SRC_OVR */ |
| 498 | irqovr = (void *)current; |
| 499 | current += acpi_create_madt_irqoverride(irqovr, 0, 0, 2, 0); |
| 500 | |
| 501 | if (sci_irq >= 20) |
| 502 | sci_flags |= MP_IRQ_POLARITY_LOW; |
| 503 | else |
| 504 | sci_flags |= MP_IRQ_POLARITY_HIGH; |
| 505 | |
| 506 | irqovr = (void *)current; |
| 507 | current += acpi_create_madt_irqoverride(irqovr, 0, sci_irq, sci_irq, |
| 508 | sci_flags); |
| 509 | |
| 510 | return current; |
| 511 | } |