1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2008-2011
4 * Graeme Russ, <graeme.russ@gmail.com>
7 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
10 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
11 * Marius Groeger <mgroeger@sysgo.de>
14 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
15 * Alex Zuepke <azu@sysgo.de>
17 * Part of this file is adapted from coreboot
18 * src/arch/x86/lib/cpu.c
22 #include <bootstage.h>
32 #include <acpi/acpi_s3.h>
33 #include <acpi/acpi_table.h>
35 #include <asm/control_regs.h>
36 #include <asm/coreboot_tables.h>
38 #include <asm/lapic.h>
39 #include <asm/microcode.h>
41 #include <asm/mrccache.h>
45 #include <asm/processor.h>
46 #include <asm/processor-flags.h>
47 #include <asm/interrupt.h>
48 #include <asm/tables.h>
49 #include <linux/compiler.h>
51 DECLARE_GLOBAL_DATA_PTR;
53 #ifndef CONFIG_TPL_BUILD
54 static const char *const x86_vendor_name[] = {
55 [X86_VENDOR_INTEL] = "Intel",
56 [X86_VENDOR_CYRIX] = "Cyrix",
57 [X86_VENDOR_AMD] = "AMD",
58 [X86_VENDOR_UMC] = "UMC",
59 [X86_VENDOR_NEXGEN] = "NexGen",
60 [X86_VENDOR_CENTAUR] = "Centaur",
61 [X86_VENDOR_RISE] = "Rise",
62 [X86_VENDOR_TRANSMETA] = "Transmeta",
63 [X86_VENDOR_NSC] = "NSC",
64 [X86_VENDOR_SIS] = "SiS",
68 int __weak x86_cleanup_before_linux(void)
70 #ifdef CONFIG_BOOTSTAGE_STASH
71 bootstage_stash((void *)CONFIG_BOOTSTAGE_STASH_ADDR,
72 CONFIG_BOOTSTAGE_STASH_SIZE);
78 int x86_init_cache(void)
84 int init_cache(void) __attribute__((weak, alias("x86_init_cache")));
86 void flush_cache(unsigned long dummy1, unsigned long dummy2)
91 /* Define these functions to allow ehch-hcd to function */
92 void flush_dcache_range(unsigned long start, unsigned long stop)
96 void invalidate_dcache_range(unsigned long start, unsigned long stop)
100 void dcache_enable(void)
105 void dcache_disable(void)
110 void icache_enable(void)
114 void icache_disable(void)
118 int icache_status(void)
123 #ifndef CONFIG_TPL_BUILD
124 const char *cpu_vendor_name(int vendor)
127 name = "<invalid cpu vendor>";
128 if (vendor < ARRAY_SIZE(x86_vendor_name) &&
129 x86_vendor_name[vendor])
130 name = x86_vendor_name[vendor];
136 char *cpu_get_name(char *name)
138 unsigned int *name_as_ints = (unsigned int *)name;
139 struct cpuid_result regs;
143 /* This bit adds up to 48 bytes */
144 for (i = 0; i < 3; i++) {
145 regs = cpuid(0x80000002 + i);
146 name_as_ints[i * 4 + 0] = regs.eax;
147 name_as_ints[i * 4 + 1] = regs.ebx;
148 name_as_ints[i * 4 + 2] = regs.ecx;
149 name_as_ints[i * 4 + 3] = regs.edx;
151 name[CPU_MAX_NAME_LEN - 1] = '\0';
153 /* Skip leading spaces. */
161 int default_print_cpuinfo(void)
163 printf("CPU: %s, vendor %s, device %xh\n",
164 cpu_has_64bit() ? "x86_64" : "x86",
165 cpu_vendor_name(gd->arch.x86_vendor), gd->arch.x86_device);
167 if (IS_ENABLED(CONFIG_HAVE_ACPI_RESUME)) {
168 debug("ACPI previous sleep state: %s\n",
169 acpi_ss_string(gd->arch.prev_sleep_state));
175 void show_boot_progress(int val)
177 outb(val, POST_PORT);
180 #if !defined(CONFIG_SYS_COREBOOT) && !defined(CONFIG_EFI_STUB)
182 * Implement a weak default function for boards that need to do some final init
183 * before the system is ready.
185 __weak void board_final_init(void)
189 int last_stage_init(void)
191 struct acpi_fadt __maybe_unused *fadt;
195 if (IS_ENABLED(CONFIG_HAVE_ACPI_RESUME)) {
196 fadt = acpi_find_fadt();
198 if (fadt && gd->arch.prev_sleep_state == ACPI_S3)
204 #ifdef CONFIG_GENERATE_ACPI_TABLE
205 fadt = acpi_find_fadt();
207 /* Don't touch ACPI hardware on HW reduced platforms */
208 if (fadt && !(fadt->flags & ACPI_FADT_HW_REDUCED_ACPI)) {
210 * Other than waiting for OSPM to request us to switch to ACPI
211 * mode, do it by ourselves, since SMI will not be triggered.
213 enter_acpi_mode(fadt->pm1a_cnt_blk);
221 static int x86_init_cpus(void)
224 debug("Init additional CPUs\n");
230 * This causes the cpu-x86 driver to be probed.
231 * We don't check return value here as we want to allow boards
232 * which have not been converted to use cpu uclass driver to boot.
234 uclass_first_device(UCLASS_CPU, &dev);
245 if (!ll_boot_init()) {
246 uclass_first_device(UCLASS_PCI, &dev);
250 ret = x86_init_cpus();
255 * Set up the northbridge, PCH and LPC if available. Note that these
256 * may have had some limited pre-relocation init if they were probed
257 * before relocation, but this is post relocation.
259 uclass_first_device(UCLASS_NORTHBRIDGE, &dev);
260 uclass_first_device(UCLASS_PCH, &dev);
261 uclass_first_device(UCLASS_LPC, &dev);
263 /* Set up pin control if available */
264 ret = syscon_get_by_driver_data(X86_SYSCON_PINCONF, &dev);
265 debug("%s, pinctrl=%p, ret=%d\n", __func__, dev, ret);
270 #ifndef CONFIG_EFI_STUB
271 int reserve_arch(void)
273 struct udevice *itss;
276 if (IS_ENABLED(CONFIG_ENABLE_MRC_CACHE))
279 #ifdef CONFIG_SEABIOS
280 high_table_reserve();
283 if (IS_ENABLED(CONFIG_HAVE_ACPI_RESUME)) {
286 if (IS_ENABLED(CONFIG_HAVE_FSP)) {
288 * Save stack address to CMOS so that at next S3 boot,
289 * we can use it as the stack address for fsp_contiue()
294 ret = irq_first_device_type(X86_IRQT_ITSS, &itss);
297 * Snapshot the current GPIO IRQ polarities. FSP-S is about to
298 * run and will set a default policy that doesn't honour boards'
301 irq_snapshot_polarities(itss);
308 long detect_coreboot_table_at(ulong start, ulong size)
313 for (ptr = (void *)start, end = ptr + size; ptr < end; ptr += 4) {
314 if (*ptr == 0x4f49424c) /* "LBIO" */
321 long locate_coreboot_table(void)
325 /* We look for LBIO in the first 4K of RAM and again at 960KB */
326 addr = detect_coreboot_table_at(0x0, 0x1000);
328 addr = detect_coreboot_table_at(0xf0000, 0x1000);