]> git.ipfire.org Git - thirdparty/u-boot.git/blame - arch/x86/cpu/cpu.c
Revert "Merge patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet""
[thirdparty/u-boot.git] / arch / x86 / cpu / cpu.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
2262cfee 2/*
dbf7115a
GR
3 * (C) Copyright 2008-2011
4 * Graeme Russ, <graeme.russ@gmail.com>
5 *
2262cfee 6 * (C) Copyright 2002
fa82f871 7 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
8bde7f77 8 *
2262cfee
WD
9 * (C) Copyright 2002
10 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
11 * Marius Groeger <mgroeger@sysgo.de>
12 *
13 * (C) Copyright 2002
14 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
15 * Alex Zuepke <azu@sysgo.de>
16 *
52f952bf
BM
17 * Part of this file is adapted from coreboot
18 * src/arch/x86/lib/cpu.c
2262cfee
WD
19 */
20
38e498c3
SG
21#define LOG_CATEGORY UCLASS_CPU
22
d678a59d 23#include <common.h>
52f24238 24#include <bootstage.h>
2262cfee 25#include <command.h>
9edefc27 26#include <cpu_func.h>
6e6f4ce4 27#include <dm.h>
200182a7 28#include <errno.h>
91caa3bb 29#include <event.h>
35a3f871 30#include <init.h>
b95611f6 31#include <irq.h>
f7ae49fc 32#include <log.h>
200182a7 33#include <malloc.h>
d8906c1f 34#include <syscon.h>
3cabcf96 35#include <acpi/acpi_s3.h>
776cc201 36#include <acpi/acpi_table.h>
a0609a8d 37#include <asm/acpi.h>
095593c0 38#include <asm/control_regs.h>
d19c9074 39#include <asm/coreboot_tables.h>
200182a7 40#include <asm/cpu.h>
401d1c4f 41#include <asm/global_data.h>
6e6f4ce4 42#include <asm/lapic.h>
e77b62e2 43#include <asm/microcode.h>
6e6f4ce4 44#include <asm/mp.h>
0c2b7eef 45#include <asm/mrccache.h>
43dd22f5
BM
46#include <asm/msr.h>
47#include <asm/mtrr.h>
a49e3c7f 48#include <asm/post.h>
c53fd2bb 49#include <asm/processor.h>
0c24c9cc 50#include <asm/processor-flags.h>
3f5f18d1 51#include <asm/interrupt.h>
5e2400e8 52#include <asm/tables.h>
60a9b6bf 53#include <linux/compiler.h>
2262cfee 54
52f952bf
BM
55DECLARE_GLOBAL_DATA_PTR;
56
caca13f6 57#ifndef CONFIG_TPL_BUILD
52f952bf
BM
58static const char *const x86_vendor_name[] = {
59 [X86_VENDOR_INTEL] = "Intel",
60 [X86_VENDOR_CYRIX] = "Cyrix",
61 [X86_VENDOR_AMD] = "AMD",
62 [X86_VENDOR_UMC] = "UMC",
63 [X86_VENDOR_NEXGEN] = "NexGen",
64 [X86_VENDOR_CENTAUR] = "Centaur",
65 [X86_VENDOR_RISE] = "Rise",
66 [X86_VENDOR_TRANSMETA] = "Transmeta",
67 [X86_VENDOR_NSC] = "NSC",
68 [X86_VENDOR_SIS] = "SiS",
69};
caca13f6 70#endif
52f952bf 71
f30fc4de
GB
72int __weak x86_cleanup_before_linux(void)
73{
99a573fb
SG
74 int ret;
75
76 ret = mp_park_aps();
77 if (ret)
78 return log_msg_ret("park", ret);
ee2b2434 79 bootstage_stash((void *)CONFIG_BOOTSTAGE_STASH_ADDR,
7949703a 80 CONFIG_BOOTSTAGE_STASH_SIZE);
7949703a 81
f30fc4de
GB
82 return 0;
83}
84
d653244b
GR
85int x86_init_cache(void)
86{
87 enable_caches();
0ea76e92 88
2262cfee
WD
89 return 0;
90}
d653244b 91int init_cache(void) __attribute__((weak, alias("x86_init_cache")));
2262cfee 92
717979fd 93void flush_cache(unsigned long dummy1, unsigned long dummy2)
2262cfee
WD
94{
95 asm("wbinvd\n");
2262cfee 96}
3f5f18d1 97
095593c0
SR
98/* Define these functions to allow ehch-hcd to function */
99void flush_dcache_range(unsigned long start, unsigned long stop)
100{
101}
102
103void invalidate_dcache_range(unsigned long start, unsigned long stop)
104{
105}
89371409
SG
106
107void dcache_enable(void)
108{
109 enable_caches();
110}
111
112void dcache_disable(void)
113{
114 disable_caches();
115}
116
117void icache_enable(void)
118{
119}
120
121void icache_disable(void)
122{
123}
124
125int icache_status(void)
126{
127 return 1;
128}
7bddac94 129
caca13f6 130#ifndef CONFIG_TPL_BUILD
52f952bf
BM
131const char *cpu_vendor_name(int vendor)
132{
133 const char *name;
134 name = "<invalid cpu vendor>";
39670c34
HS
135 if (vendor < ARRAY_SIZE(x86_vendor_name) &&
136 x86_vendor_name[vendor])
52f952bf 137 name = x86_vendor_name[vendor];
92cc94a1 138
52f952bf 139 return name;
92cc94a1 140}
caca13f6 141#endif
92cc94a1 142
727c1a98 143char *cpu_get_name(char *name)
92cc94a1 144{
727c1a98 145 unsigned int *name_as_ints = (unsigned int *)name;
52f952bf 146 struct cpuid_result regs;
727c1a98 147 char *ptr;
52f952bf 148 int i;
92cc94a1 149
727c1a98 150 /* This bit adds up to 48 bytes */
52f952bf
BM
151 for (i = 0; i < 3; i++) {
152 regs = cpuid(0x80000002 + i);
153 name_as_ints[i * 4 + 0] = regs.eax;
154 name_as_ints[i * 4 + 1] = regs.ebx;
155 name_as_ints[i * 4 + 2] = regs.ecx;
156 name_as_ints[i * 4 + 3] = regs.edx;
157 }
727c1a98 158 name[CPU_MAX_NAME_LEN - 1] = '\0';
92cc94a1 159
52f952bf 160 /* Skip leading spaces. */
727c1a98
SG
161 ptr = name;
162 while (*ptr == ' ')
163 ptr++;
52f952bf 164
727c1a98 165 return ptr;
92cc94a1
SG
166}
167
727c1a98 168int default_print_cpuinfo(void)
92cc94a1 169{
52f952bf
BM
170 printf("CPU: %s, vendor %s, device %xh\n",
171 cpu_has_64bit() ? "x86_64" : "x86",
172 cpu_vendor_name(gd->arch.x86_vendor), gd->arch.x86_device);
92cc94a1 173
ef5f5f6c
SG
174 if (IS_ENABLED(CONFIG_HAVE_ACPI_RESUME)) {
175 debug("ACPI previous sleep state: %s\n",
176 acpi_ss_string(gd->arch.prev_sleep_state));
177 }
b727961b 178
92cc94a1
SG
179 return 0;
180}
200182a7 181
b55881dd 182#if CONFIG_IS_ENABLED(SHOW_BOOT_PROGRESS)
a49e3c7f
SG
183void show_boot_progress(int val)
184{
a49e3c7f
SG
185 outb(val, POST_PORT);
186}
cb80ff20 187#endif
5e2400e8 188
91caa3bb
SG
189#if !defined(CONFIG_SYS_COREBOOT) && !defined(CONFIG_EFI_STUB) && \
190 !defined(CONFIG_SPL_BUILD)
1e2f7b9e 191/*
4021ee63
SG
192 * Implement a weak default function for boards that need to do some final init
193 * before the system is ready.
1e2f7b9e 194 */
4021ee63 195__weak void board_final_init(void)
1e2f7b9e
BM
196{
197}
198
7c73cea4
SG
199/*
200 * Implement a weak default function for boards that need to do some final
201 * processing before booting the OS.
202 */
203__weak void board_final_cleanup(void)
204{
205}
206
91caa3bb 207static int last_stage_init(void)
5e2400e8 208{
474a62bc 209 struct acpi_fadt __maybe_unused *fadt;
38e498c3 210 int ret;
474a62bc 211
4021ee63 212 board_final_init();
bffd7981 213
ef5f5f6c
SG
214 if (IS_ENABLED(CONFIG_HAVE_ACPI_RESUME)) {
215 fadt = acpi_find_fadt();
3a34cae0 216
ef5f5f6c
SG
217 if (fadt && gd->arch.prev_sleep_state == ACPI_S3)
218 acpi_resume(fadt);
219 }
3a34cae0 220
38e498c3
SG
221 ret = write_tables();
222 if (ret) {
223 log_err("Failed to write tables\n");
224 return log_msg_ret("table", ret);
225 }
5e2400e8 226
8bccbc5a
SG
227 if (IS_ENABLED(CONFIG_GENERATE_ACPI_TABLE)) {
228 fadt = acpi_find_fadt();
474a62bc 229
8bccbc5a
SG
230 /* Don't touch ACPI hardware on HW reduced platforms */
231 if (fadt && !(fadt->flags & ACPI_FADT_HW_REDUCED_ACPI)) {
232 /*
233 * Other than waiting for OSPM to request us to switch
234 * to ACPI * mode, do it by ourselves, since SMI will
235 * not be triggered.
236 */
237 enter_acpi_mode(fadt->pm1a_cnt_blk);
238 }
474a62bc 239 }
474a62bc 240
7c73cea4
SG
241 /*
242 * TODO(sjg@chromium.org): Move this to bootm_announce_and_cleanup()
243 * once APL FSP-S at 0x200000 does not overlap with the bzimage at
244 * 0x100000.
245 */
246 board_final_cleanup();
247
5e2400e8
BM
248 return 0;
249}
91caa3bb
SG
250EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, last_stage_init);
251
252#endif /* !SYS_COREBOOT && !EFI_STUB && !SPL_BUILD */
bcb0c61e 253
afd5d50c 254static int x86_init_cpus(void)
bcb0c61e 255{
8bccbc5a
SG
256 if (IS_ENABLED(CONFIG_SMP)) {
257 debug("Init additional CPUs\n");
258 x86_mp_init();
259 } else {
260 struct udevice *dev;
c77b8912 261
8bccbc5a
SG
262 /*
263 * This causes the cpu-x86 driver to be probed.
264 * We don't check return value here as we want to allow boards
265 * which have not been converted to use cpu uclass driver to
266 * boot.
267 */
268 uclass_first_device(UCLASS_CPU, &dev);
269 }
6e6f4ce4 270
bcb0c61e
SG
271 return 0;
272}
273
274int cpu_init_r(void)
275{
ac643e03
SG
276 struct udevice *dev;
277 int ret;
278
526aabec
SG
279 if (!ll_boot_init()) {
280 uclass_first_device(UCLASS_PCI, &dev);
ac643e03 281 return 0;
526aabec 282 }
ac643e03
SG
283
284 ret = x86_init_cpus();
285 if (ret)
286 return ret;
287
288 /*
289 * Set up the northbridge, PCH and LPC if available. Note that these
290 * may have had some limited pre-relocation init if they were probed
291 * before relocation, but this is post relocation.
292 */
293 uclass_first_device(UCLASS_NORTHBRIDGE, &dev);
294 uclass_first_device(UCLASS_PCH, &dev);
295 uclass_first_device(UCLASS_LPC, &dev);
e49cceac 296
d8906c1f
BM
297 /* Set up pin control if available */
298 ret = syscon_get_by_driver_data(X86_SYSCON_PINCONF, &dev);
299 debug("%s, pinctrl=%p, ret=%d\n", __func__, dev, ret);
300
e49cceac 301 return 0;
bcb0c61e 302}
0c2b7eef
BM
303
304#ifndef CONFIG_EFI_STUB
305int reserve_arch(void)
306{
b95611f6
SG
307 struct udevice *itss;
308 int ret;
309
310 if (IS_ENABLED(CONFIG_ENABLE_MRC_CACHE))
311 mrccache_reserve();
d19c9074 312
8bccbc5a
SG
313 if (IS_ENABLED(CONFIG_SEABIOS))
314 high_table_reserve();
d19c9074 315
ef5f5f6c
SG
316 if (IS_ENABLED(CONFIG_HAVE_ACPI_RESUME)) {
317 acpi_s3_reserve();
5ae5aa93 318
ef5f5f6c
SG
319 if (IS_ENABLED(CONFIG_HAVE_FSP)) {
320 /*
321 * Save stack address to CMOS so that at next S3 boot,
58e2a35f 322 * we can use it as the stack address for fsp_continue()
ef5f5f6c
SG
323 */
324 fsp_save_s3_stack();
325 }
326 }
b95611f6
SG
327 ret = irq_first_device_type(X86_IRQT_ITSS, &itss);
328 if (!ret) {
329 /*
330 * Snapshot the current GPIO IRQ polarities. FSP-S is about to
331 * run and will set a default policy that doesn't honour boards'
332 * requirements
333 */
334 irq_snapshot_polarities(itss);
335 }
ba65808e 336
d19c9074 337 return 0;
0c2b7eef
BM
338}
339#endif
7ec0e7b6
SG
340
341long detect_coreboot_table_at(ulong start, ulong size)
342{
343 u32 *ptr, *end;
344
345 size /= 4;
346 for (ptr = (void *)start, end = ptr + size; ptr < end; ptr += 4) {
347 if (*ptr == 0x4f49424c) /* "LBIO" */
348 return (long)ptr;
349 }
350
351 return -ENOENT;
352}
353
354long locate_coreboot_table(void)
355{
356 long addr;
357
7a187a89
SG
358 /* We look for LBIO from addresses 1K-4K and again at 960KB */
359 addr = detect_coreboot_table_at(0x400, 0xc00);
7ec0e7b6
SG
360 if (addr < 0)
361 addr = detect_coreboot_table_at(0xf0000, 0x1000);
362
363 return addr;
364}