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
30 #include <asm/acpi_table.h>
31 #include <asm/control_regs.h>
32 #include <asm/coreboot_tables.h>
34 #include <asm/lapic.h>
35 #include <asm/microcode.h>
37 #include <asm/mrccache.h>
41 #include <asm/processor.h>
42 #include <asm/processor-flags.h>
43 #include <asm/interrupt.h>
44 #include <asm/tables.h>
45 #include <linux/compiler.h>
47 DECLARE_GLOBAL_DATA_PTR;
49 static const char *const x86_vendor_name[] = {
50 [X86_VENDOR_INTEL] = "Intel",
51 [X86_VENDOR_CYRIX] = "Cyrix",
52 [X86_VENDOR_AMD] = "AMD",
53 [X86_VENDOR_UMC] = "UMC",
54 [X86_VENDOR_NEXGEN] = "NexGen",
55 [X86_VENDOR_CENTAUR] = "Centaur",
56 [X86_VENDOR_RISE] = "Rise",
57 [X86_VENDOR_TRANSMETA] = "Transmeta",
58 [X86_VENDOR_NSC] = "NSC",
59 [X86_VENDOR_SIS] = "SiS",
62 int __weak x86_cleanup_before_linux(void)
64 #ifdef CONFIG_BOOTSTAGE_STASH
65 bootstage_stash((void *)CONFIG_BOOTSTAGE_STASH_ADDR,
66 CONFIG_BOOTSTAGE_STASH_SIZE);
72 int x86_init_cache(void)
78 int init_cache(void) __attribute__((weak, alias("x86_init_cache")));
80 void flush_cache(unsigned long dummy1, unsigned long dummy2)
85 /* Define these functions to allow ehch-hcd to function */
86 void flush_dcache_range(unsigned long start, unsigned long stop)
90 void invalidate_dcache_range(unsigned long start, unsigned long stop)
94 void dcache_enable(void)
99 void dcache_disable(void)
104 void icache_enable(void)
108 void icache_disable(void)
112 int icache_status(void)
117 const char *cpu_vendor_name(int vendor)
120 name = "<invalid cpu vendor>";
121 if (vendor < ARRAY_SIZE(x86_vendor_name) &&
122 x86_vendor_name[vendor])
123 name = x86_vendor_name[vendor];
128 char *cpu_get_name(char *name)
130 unsigned int *name_as_ints = (unsigned int *)name;
131 struct cpuid_result regs;
135 /* This bit adds up to 48 bytes */
136 for (i = 0; i < 3; i++) {
137 regs = cpuid(0x80000002 + i);
138 name_as_ints[i * 4 + 0] = regs.eax;
139 name_as_ints[i * 4 + 1] = regs.ebx;
140 name_as_ints[i * 4 + 2] = regs.ecx;
141 name_as_ints[i * 4 + 3] = regs.edx;
143 name[CPU_MAX_NAME_LEN - 1] = '\0';
145 /* Skip leading spaces. */
153 int default_print_cpuinfo(void)
155 printf("CPU: %s, vendor %s, device %xh\n",
156 cpu_has_64bit() ? "x86_64" : "x86",
157 cpu_vendor_name(gd->arch.x86_vendor), gd->arch.x86_device);
159 #ifdef CONFIG_HAVE_ACPI_RESUME
160 debug("ACPI previous sleep state: %s\n",
161 acpi_ss_string(gd->arch.prev_sleep_state));
167 void show_boot_progress(int val)
169 outb(val, POST_PORT);
172 #if !defined(CONFIG_SYS_COREBOOT) && !defined(CONFIG_EFI_STUB)
174 * Implement a weak default function for boards that optionally
175 * need to clean up the system before jumping to the kernel.
177 __weak void board_final_cleanup(void)
181 int last_stage_init(void)
183 struct acpi_fadt __maybe_unused *fadt;
185 board_final_cleanup();
187 #ifdef CONFIG_HAVE_ACPI_RESUME
188 fadt = acpi_find_fadt();
190 if (fadt && gd->arch.prev_sleep_state == ACPI_S3)
196 #ifdef CONFIG_GENERATE_ACPI_TABLE
197 fadt = acpi_find_fadt();
199 /* Don't touch ACPI hardware on HW reduced platforms */
200 if (fadt && !(fadt->flags & ACPI_FADT_HW_REDUCED_ACPI)) {
202 * Other than waiting for OSPM to request us to switch to ACPI
203 * mode, do it by ourselves, since SMI will not be triggered.
205 enter_acpi_mode(fadt->pm1a_cnt_blk);
213 static int x86_init_cpus(void)
216 debug("Init additional CPUs\n");
222 * This causes the cpu-x86 driver to be probed.
223 * We don't check return value here as we want to allow boards
224 * which have not been converted to use cpu uclass driver to boot.
226 uclass_first_device(UCLASS_CPU, &dev);
240 ret = x86_init_cpus();
245 * Set up the northbridge, PCH and LPC if available. Note that these
246 * may have had some limited pre-relocation init if they were probed
247 * before relocation, but this is post relocation.
249 uclass_first_device(UCLASS_NORTHBRIDGE, &dev);
250 uclass_first_device(UCLASS_PCH, &dev);
251 uclass_first_device(UCLASS_LPC, &dev);
253 /* Set up pin control if available */
254 ret = syscon_get_by_driver_data(X86_SYSCON_PINCONF, &dev);
255 debug("%s, pinctrl=%p, ret=%d\n", __func__, dev, ret);
260 #ifndef CONFIG_EFI_STUB
261 int reserve_arch(void)
263 #ifdef CONFIG_ENABLE_MRC_CACHE
267 #ifdef CONFIG_SEABIOS
268 high_table_reserve();
271 #ifdef CONFIG_HAVE_ACPI_RESUME
274 #ifdef CONFIG_HAVE_FSP
276 * Save stack address to CMOS so that at next S3 boot,
277 * we can use it as the stack address for fsp_contiue()
280 #endif /* CONFIG_HAVE_FSP */
281 #endif /* CONFIG_HAVE_ACPI_RESUME */