York Yang | d7cba28 | 2016-03-09 10:54:26 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2013 Google Inc. |
| 5 | * Copyright (C) 2015-2016 Intel Corp. |
| 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 | |
| 17 | #include <stdlib.h> |
| 18 | #include <arch/cpu.h> |
| 19 | #include <arch/acpi.h> |
| 20 | #include <console/console.h> |
| 21 | #include <cpu/intel/microcode.h> |
| 22 | #include <cpu/x86/cr.h> |
| 23 | #include <cpu/x86/msr.h> |
| 24 | #include <device/device.h> |
| 25 | #include <device/pci_def.h> |
| 26 | #include <device/pci_ops.h> |
| 27 | #include <romstage_handoff.h> |
| 28 | #include <soc/lpc.h> |
| 29 | #include <soc/msr.h> |
| 30 | #include <soc/pattrs.h> |
| 31 | #include <soc/pci_devs.h> |
| 32 | #include <soc/ramstage.h> |
| 33 | |
| 34 | /* Global PATTRS */ |
| 35 | DEFINE_PATTRS; |
| 36 | |
| 37 | #define SHOW_PATTRS 1 |
| 38 | |
| 39 | static void detect_num_cpus(struct pattrs *attrs) |
| 40 | { |
| 41 | msr_t core_thread_count = rdmsr(MSR_CORE_THREAD_COUNT); |
| 42 | attrs->num_cpus = core_thread_count.lo & 0xffff; |
| 43 | } |
| 44 | |
| 45 | static inline void fill_in_msr(msr_t *msr, int idx) |
| 46 | { |
| 47 | *msr = rdmsr(idx); |
| 48 | if (SHOW_PATTRS) { |
| 49 | printk(BIOS_DEBUG, "msr(%x) = %08x%08x\n", |
| 50 | idx, msr->hi, msr->lo); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | static const char *stepping_str[] = { |
| 55 | "U0", "V1", "V2", "Y0" |
| 56 | }; |
| 57 | |
| 58 | static void fill_in_pattrs(void) |
| 59 | { |
| 60 | device_t dev; |
| 61 | struct pattrs *attrs = (struct pattrs *)pattrs_get(); |
| 62 | |
| 63 | attrs->cpuid = cpuid_eax(1); |
| 64 | attrs->stepping = (attrs->cpuid & 0x0F) - 1; |
| 65 | dev = dev_find_slot(0, PCI_DEVFN(LPC_DEV, LPC_FUNC)); |
| 66 | attrs->revid = pci_read_config8(dev, REVID); |
| 67 | attrs->microcode_patch = intel_microcode_find(); |
| 68 | attrs->address_bits = cpuid_eax(0x80000008) & 0xff; |
| 69 | detect_num_cpus(attrs); |
| 70 | |
| 71 | if (SHOW_PATTRS) { |
| 72 | printk(BIOS_DEBUG, "CPUID: %08x\n", attrs->cpuid); |
| 73 | printk(BIOS_DEBUG, "Cores: %d\n", attrs->num_cpus); |
| 74 | printk(BIOS_DEBUG, "Stepping: %s\n", (attrs->stepping >= ARRAY_SIZE(stepping_str)) |
| 75 | ? "??" : stepping_str[attrs->stepping]); |
| 76 | printk(BIOS_DEBUG, "Revision ID: %02x\n", attrs->revid); |
| 77 | } |
| 78 | |
| 79 | fill_in_msr(&attrs->platform_id, MSR_IA32_PLATFORM_ID); |
| 80 | fill_in_msr(&attrs->platform_info, MSR_PLATFORM_INFO); |
| 81 | } |
| 82 | |
| 83 | void broadwell_de_init_pre_device(void) |
| 84 | { |
| 85 | fill_in_pattrs(); |
| 86 | } |