blob: 1592b2c9d3b3a503251af4317b6541db89721e29 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass16a624b2017-01-16 07:03:57 -07002/*
3 * (C) Copyright 2008-2011
4 * Graeme Russ, <graeme.russ@gmail.com>
5 *
6 * (C) Copyright 2002
7 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
8 *
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 *
17 * Part of this file is adapted from coreboot
18 * src/arch/x86/lib/cpu.c
Simon Glass16a624b2017-01-16 07:03:57 -070019 */
20
21#include <common.h>
Simon Glass1d91ba72019-11-14 12:57:37 -070022#include <cpu_func.h>
Simon Glassda25eff2019-12-28 10:44:56 -070023#include <init.h>
Simon Glass16a624b2017-01-16 07:03:57 -070024#include <malloc.h>
Simon Glassdd45a7a2019-12-06 21:41:51 -070025#include <spl.h>
Simon Glass16a624b2017-01-16 07:03:57 -070026#include <asm/control_regs.h>
27#include <asm/cpu.h>
28#include <asm/mp.h>
29#include <asm/msr.h>
30#include <asm/mtrr.h>
31#include <asm/processor-flags.h>
32
33DECLARE_GLOBAL_DATA_PTR;
34
35/*
36 * Constructor for a conventional segment GDT (or LDT) entry
37 * This is a macro so it can be used in initialisers
38 */
39#define GDT_ENTRY(flags, base, limit) \
40 ((((base) & 0xff000000ULL) << (56-24)) | \
41 (((flags) & 0x0000f0ffULL) << 40) | \
42 (((limit) & 0x000f0000ULL) << (48-16)) | \
43 (((base) & 0x00ffffffULL) << 16) | \
44 (((limit) & 0x0000ffffULL)))
45
46struct gdt_ptr {
47 u16 len;
48 u32 ptr;
49} __packed;
50
51struct cpu_device_id {
52 unsigned vendor;
53 unsigned device;
54};
55
56struct cpuinfo_x86 {
57 uint8_t x86; /* CPU family */
58 uint8_t x86_vendor; /* CPU vendor */
59 uint8_t x86_model;
60 uint8_t x86_mask;
61};
62
Simon Glassdd45a7a2019-12-06 21:41:51 -070063/* gcc 7.3 does not wwant to drop x86_vendors, so use #ifdef */
64#ifndef CONFIG_TPL_BUILD
Simon Glass16a624b2017-01-16 07:03:57 -070065/*
66 * List of cpu vendor strings along with their normalized
67 * id values.
68 */
69static const struct {
70 int vendor;
71 const char *name;
72} x86_vendors[] = {
73 { X86_VENDOR_INTEL, "GenuineIntel", },
74 { X86_VENDOR_CYRIX, "CyrixInstead", },
75 { X86_VENDOR_AMD, "AuthenticAMD", },
76 { X86_VENDOR_UMC, "UMC UMC UMC ", },
77 { X86_VENDOR_NEXGEN, "NexGenDriven", },
78 { X86_VENDOR_CENTAUR, "CentaurHauls", },
79 { X86_VENDOR_RISE, "RiseRiseRise", },
80 { X86_VENDOR_TRANSMETA, "GenuineTMx86", },
81 { X86_VENDOR_TRANSMETA, "TransmetaCPU", },
82 { X86_VENDOR_NSC, "Geode by NSC", },
83 { X86_VENDOR_SIS, "SiS SiS SiS ", },
84};
Simon Glassdd45a7a2019-12-06 21:41:51 -070085#endif
Simon Glass16a624b2017-01-16 07:03:57 -070086
87static void load_ds(u32 segment)
88{
89 asm volatile("movl %0, %%ds" : : "r" (segment * X86_GDT_ENTRY_SIZE));
90}
91
92static void load_es(u32 segment)
93{
94 asm volatile("movl %0, %%es" : : "r" (segment * X86_GDT_ENTRY_SIZE));
95}
96
97static void load_fs(u32 segment)
98{
99 asm volatile("movl %0, %%fs" : : "r" (segment * X86_GDT_ENTRY_SIZE));
100}
101
102static void load_gs(u32 segment)
103{
104 asm volatile("movl %0, %%gs" : : "r" (segment * X86_GDT_ENTRY_SIZE));
105}
106
107static void load_ss(u32 segment)
108{
109 asm volatile("movl %0, %%ss" : : "r" (segment * X86_GDT_ENTRY_SIZE));
110}
111
112static void load_gdt(const u64 *boot_gdt, u16 num_entries)
113{
114 struct gdt_ptr gdt;
115
116 gdt.len = (num_entries * X86_GDT_ENTRY_SIZE) - 1;
117 gdt.ptr = (ulong)boot_gdt;
118
119 asm volatile("lgdtl %0\n" : : "m" (gdt));
120}
121
122void arch_setup_gd(gd_t *new_gd)
123{
124 u64 *gdt_addr;
125
126 gdt_addr = new_gd->arch.gdt;
127
128 /*
129 * CS: code, read/execute, 4 GB, base 0
130 *
131 * Some OS (like VxWorks) requires GDT entry 1 to be the 32-bit CS
132 */
133 gdt_addr[X86_GDT_ENTRY_UNUSED] = GDT_ENTRY(0xc09b, 0, 0xfffff);
134 gdt_addr[X86_GDT_ENTRY_32BIT_CS] = GDT_ENTRY(0xc09b, 0, 0xfffff);
135
136 /* DS: data, read/write, 4 GB, base 0 */
137 gdt_addr[X86_GDT_ENTRY_32BIT_DS] = GDT_ENTRY(0xc093, 0, 0xfffff);
138
139 /* FS: data, read/write, 4 GB, base (Global Data Pointer) */
140 new_gd->arch.gd_addr = new_gd;
141 gdt_addr[X86_GDT_ENTRY_32BIT_FS] = GDT_ENTRY(0xc093,
142 (ulong)&new_gd->arch.gd_addr, 0xfffff);
143
144 /* 16-bit CS: code, read/execute, 64 kB, base 0 */
145 gdt_addr[X86_GDT_ENTRY_16BIT_CS] = GDT_ENTRY(0x009b, 0, 0x0ffff);
146
147 /* 16-bit DS: data, read/write, 64 kB, base 0 */
148 gdt_addr[X86_GDT_ENTRY_16BIT_DS] = GDT_ENTRY(0x0093, 0, 0x0ffff);
149
150 gdt_addr[X86_GDT_ENTRY_16BIT_FLAT_CS] = GDT_ENTRY(0x809b, 0, 0xfffff);
151 gdt_addr[X86_GDT_ENTRY_16BIT_FLAT_DS] = GDT_ENTRY(0x8093, 0, 0xfffff);
152
153 load_gdt(gdt_addr, X86_GDT_NUM_ENTRIES);
154 load_ds(X86_GDT_ENTRY_32BIT_DS);
155 load_es(X86_GDT_ENTRY_32BIT_DS);
156 load_gs(X86_GDT_ENTRY_32BIT_DS);
157 load_ss(X86_GDT_ENTRY_32BIT_DS);
158 load_fs(X86_GDT_ENTRY_32BIT_FS);
159}
160
161#ifdef CONFIG_HAVE_FSP
162/*
163 * Setup FSP execution environment GDT
164 *
165 * Per Intel FSP external architecture specification, before calling any FSP
166 * APIs, we need make sure the system is in flat 32-bit mode and both the code
167 * and data selectors should have full 4GB access range. Here we reuse the one
168 * we used in arch/x86/cpu/start16.S, and reload the segement registers.
169 */
170void setup_fsp_gdt(void)
171{
172 load_gdt((const u64 *)(gdt_rom + CONFIG_RESET_SEG_START), 4);
173 load_ds(X86_GDT_ENTRY_32BIT_DS);
174 load_ss(X86_GDT_ENTRY_32BIT_DS);
175 load_es(X86_GDT_ENTRY_32BIT_DS);
176 load_fs(X86_GDT_ENTRY_32BIT_DS);
177 load_gs(X86_GDT_ENTRY_32BIT_DS);
178}
179#endif
180
181/*
182 * Cyrix CPUs without cpuid or with cpuid not yet enabled can be detected
183 * by the fact that they preserve the flags across the division of 5/2.
184 * PII and PPro exhibit this behavior too, but they have cpuid available.
185 */
186
187/*
188 * Perform the Cyrix 5/2 test. A Cyrix won't change
189 * the flags, while other 486 chips will.
190 */
191static inline int test_cyrix_52div(void)
192{
193 unsigned int test;
194
195 __asm__ __volatile__(
196 "sahf\n\t" /* clear flags (%eax = 0x0005) */
197 "div %b2\n\t" /* divide 5 by 2 */
198 "lahf" /* store flags into %ah */
199 : "=a" (test)
200 : "0" (5), "q" (2)
201 : "cc");
202
203 /* AH is 0x02 on Cyrix after the divide.. */
204 return (unsigned char) (test >> 8) == 0x02;
205}
206
Simon Glassdd45a7a2019-12-06 21:41:51 -0700207#ifndef CONFIG_TPL_BUILD
Simon Glass16a624b2017-01-16 07:03:57 -0700208/*
209 * Detect a NexGen CPU running without BIOS hypercode new enough
210 * to have CPUID. (Thanks to Herbert Oppmann)
211 */
212static int deep_magic_nexgen_probe(void)
213{
214 int ret;
215
216 __asm__ __volatile__ (
217 " movw $0x5555, %%ax\n"
218 " xorw %%dx,%%dx\n"
219 " movw $2, %%cx\n"
220 " divw %%cx\n"
221 " movl $0, %%eax\n"
222 " jnz 1f\n"
223 " movl $1, %%eax\n"
224 "1:\n"
225 : "=a" (ret) : : "cx", "dx");
226 return ret;
227}
Simon Glassdd45a7a2019-12-06 21:41:51 -0700228#endif
Simon Glass16a624b2017-01-16 07:03:57 -0700229
230static bool has_cpuid(void)
231{
232 return flag_is_changeable_p(X86_EFLAGS_ID);
233}
234
235static bool has_mtrr(void)
236{
237 return cpuid_edx(0x00000001) & (1 << 12) ? true : false;
238}
239
Simon Glassdd45a7a2019-12-06 21:41:51 -0700240#ifndef CONFIG_TPL_BUILD
Simon Glass16a624b2017-01-16 07:03:57 -0700241static int build_vendor_name(char *vendor_name)
242{
243 struct cpuid_result result;
244 result = cpuid(0x00000000);
245 unsigned int *name_as_ints = (unsigned int *)vendor_name;
246
247 name_as_ints[0] = result.ebx;
248 name_as_ints[1] = result.edx;
249 name_as_ints[2] = result.ecx;
250
251 return result.eax;
252}
Simon Glassdd45a7a2019-12-06 21:41:51 -0700253#endif
Simon Glass16a624b2017-01-16 07:03:57 -0700254
255static void identify_cpu(struct cpu_device_id *cpu)
256{
Simon Glassdd45a7a2019-12-06 21:41:51 -0700257 cpu->device = 0; /* fix gcc 4.4.4 warning */
258
259 /*
260 * Do a quick and dirty check to save space - Intel and AMD only and
261 * just the vendor. This is enough for most TPL code.
262 */
263 if (spl_phase() == PHASE_TPL) {
264 struct cpuid_result result;
265
266 result = cpuid(0x00000000);
267 switch (result.ecx >> 24) {
268 case 'l': /* GenuineIntel */
269 cpu->vendor = X86_VENDOR_INTEL;
270 break;
271 case 'D': /* AuthenticAMD */
272 cpu->vendor = X86_VENDOR_AMD;
273 break;
274 default:
275 cpu->vendor = X86_VENDOR_ANY;
276 break;
277 }
278 return;
279 }
280
281/* gcc 7.3 does not want to drop x86_vendors, so use #ifdef */
282#ifndef CONFIG_TPL_BUILD
Simon Glass16a624b2017-01-16 07:03:57 -0700283 char vendor_name[16];
284 int i;
285
286 vendor_name[0] = '\0'; /* Unset */
Simon Glass16a624b2017-01-16 07:03:57 -0700287
288 /* Find the id and vendor_name */
289 if (!has_cpuid()) {
290 /* Its a 486 if we can modify the AC flag */
291 if (flag_is_changeable_p(X86_EFLAGS_AC))
292 cpu->device = 0x00000400; /* 486 */
293 else
294 cpu->device = 0x00000300; /* 386 */
295 if ((cpu->device == 0x00000400) && test_cyrix_52div()) {
296 memcpy(vendor_name, "CyrixInstead", 13);
297 /* If we ever care we can enable cpuid here */
298 }
299 /* Detect NexGen with old hypercode */
300 else if (deep_magic_nexgen_probe())
301 memcpy(vendor_name, "NexGenDriven", 13);
Simon Glassdd45a7a2019-12-06 21:41:51 -0700302 } else {
303 int cpuid_level;
Simon Glass16a624b2017-01-16 07:03:57 -0700304
305 cpuid_level = build_vendor_name(vendor_name);
306 vendor_name[12] = '\0';
307
308 /* Intel-defined flags: level 0x00000001 */
309 if (cpuid_level >= 0x00000001) {
310 cpu->device = cpuid_eax(0x00000001);
311 } else {
312 /* Have CPUID level 0 only unheard of */
313 cpu->device = 0x00000400;
314 }
315 }
316 cpu->vendor = X86_VENDOR_UNKNOWN;
317 for (i = 0; i < ARRAY_SIZE(x86_vendors); i++) {
318 if (memcmp(vendor_name, x86_vendors[i].name, 12) == 0) {
319 cpu->vendor = x86_vendors[i].vendor;
320 break;
321 }
322 }
Simon Glassdd45a7a2019-12-06 21:41:51 -0700323#endif
Simon Glass16a624b2017-01-16 07:03:57 -0700324}
325
326static inline void get_fms(struct cpuinfo_x86 *c, uint32_t tfms)
327{
328 c->x86 = (tfms >> 8) & 0xf;
329 c->x86_model = (tfms >> 4) & 0xf;
330 c->x86_mask = tfms & 0xf;
331 if (c->x86 == 0xf)
332 c->x86 += (tfms >> 20) & 0xff;
333 if (c->x86 >= 0x6)
334 c->x86_model += ((tfms >> 16) & 0xF) << 4;
335}
336
337u32 cpu_get_family_model(void)
338{
339 return gd->arch.x86_device & 0x0fff0ff0;
340}
341
342u32 cpu_get_stepping(void)
343{
344 return gd->arch.x86_mask;
345}
346
Simon Glass05e12f72019-04-25 21:58:42 -0600347/* initialise FPU, reset EM, set MP and NE */
348static void setup_cpu_features(void)
Simon Glass16a624b2017-01-16 07:03:57 -0700349{
350 const u32 em_rst = ~X86_CR0_EM;
351 const u32 mp_ne_set = X86_CR0_MP | X86_CR0_NE;
352
Simon Glass05e12f72019-04-25 21:58:42 -0600353 asm ("fninit\n" \
354 "movl %%cr0, %%eax\n" \
355 "andl %0, %%eax\n" \
356 "orl %1, %%eax\n" \
357 "movl %%eax, %%cr0\n" \
358 : : "i" (em_rst), "i" (mp_ne_set) : "eax");
359}
Simon Glass16a624b2017-01-16 07:03:57 -0700360
Simon Glass05e12f72019-04-25 21:58:42 -0600361static void setup_identity(void)
362{
Simon Glass16a624b2017-01-16 07:03:57 -0700363 /* identify CPU via cpuid and store the decoded info into gd->arch */
364 if (has_cpuid()) {
365 struct cpu_device_id cpu;
366 struct cpuinfo_x86 c;
367
368 identify_cpu(&cpu);
369 get_fms(&c, cpu.device);
370 gd->arch.x86 = c.x86;
371 gd->arch.x86_vendor = cpu.vendor;
372 gd->arch.x86_model = c.x86_model;
373 gd->arch.x86_mask = c.x86_mask;
374 gd->arch.x86_device = cpu.device;
375
376 gd->arch.has_mtrr = has_mtrr();
377 }
Simon Glass05e12f72019-04-25 21:58:42 -0600378}
379
380/* Don't allow PCI region 3 to use memory in the 2-4GB memory hole */
381static void setup_pci_ram_top(void)
382{
Simon Glass16a624b2017-01-16 07:03:57 -0700383 gd->pci_ram_top = 0x80000000U;
Simon Glass05e12f72019-04-25 21:58:42 -0600384}
385
386static void setup_mtrr(void)
387{
388 u64 mtrr_cap;
Simon Glass16a624b2017-01-16 07:03:57 -0700389
390 /* Configure fixed range MTRRs for some legacy regions */
Simon Glass05e12f72019-04-25 21:58:42 -0600391 if (!gd->arch.has_mtrr)
392 return;
Simon Glass16a624b2017-01-16 07:03:57 -0700393
Simon Glass05e12f72019-04-25 21:58:42 -0600394 mtrr_cap = native_read_msr(MTRR_CAP_MSR);
395 if (mtrr_cap & MTRR_CAP_FIX) {
396 /* Mark the VGA RAM area as uncacheable */
397 native_write_msr(MTRR_FIX_16K_A0000_MSR,
398 MTRR_FIX_TYPE(MTRR_TYPE_UNCACHEABLE),
399 MTRR_FIX_TYPE(MTRR_TYPE_UNCACHEABLE));
Simon Glass16a624b2017-01-16 07:03:57 -0700400
Simon Glass05e12f72019-04-25 21:58:42 -0600401 /*
402 * Mark the PCI ROM area as cacheable to improve ROM
403 * execution performance.
404 */
405 native_write_msr(MTRR_FIX_4K_C0000_MSR,
406 MTRR_FIX_TYPE(MTRR_TYPE_WRBACK),
407 MTRR_FIX_TYPE(MTRR_TYPE_WRBACK));
408 native_write_msr(MTRR_FIX_4K_C8000_MSR,
409 MTRR_FIX_TYPE(MTRR_TYPE_WRBACK),
410 MTRR_FIX_TYPE(MTRR_TYPE_WRBACK));
411 native_write_msr(MTRR_FIX_4K_D0000_MSR,
412 MTRR_FIX_TYPE(MTRR_TYPE_WRBACK),
413 MTRR_FIX_TYPE(MTRR_TYPE_WRBACK));
414 native_write_msr(MTRR_FIX_4K_D8000_MSR,
415 MTRR_FIX_TYPE(MTRR_TYPE_WRBACK),
416 MTRR_FIX_TYPE(MTRR_TYPE_WRBACK));
Simon Glass16a624b2017-01-16 07:03:57 -0700417
Simon Glass05e12f72019-04-25 21:58:42 -0600418 /* Enable the fixed range MTRRs */
419 msr_setbits_64(MTRR_DEF_TYPE_MSR, MTRR_DEF_TYPE_FIX_EN);
Simon Glass16a624b2017-01-16 07:03:57 -0700420 }
Simon Glass05e12f72019-04-25 21:58:42 -0600421}
Simon Glass16a624b2017-01-16 07:03:57 -0700422
Simon Glassdc444672019-10-20 21:37:54 -0600423int x86_cpu_init_tpl(void)
424{
425 setup_cpu_features();
426 setup_identity();
427
428 return 0;
429}
430
Simon Glass05e12f72019-04-25 21:58:42 -0600431int x86_cpu_init_f(void)
432{
433 if (ll_boot_init())
434 setup_cpu_features();
435 setup_identity();
436 setup_mtrr();
437 setup_pci_ram_top();
438
Simon Glass16a624b2017-01-16 07:03:57 -0700439 /* Set up the i8254 timer if required */
Simon Glass05e12f72019-04-25 21:58:42 -0600440 if (IS_ENABLED(CONFIG_I8254_TIMER))
441 i8254_init();
442
443 return 0;
444}
445
446int x86_cpu_reinit_f(void)
447{
448 setup_identity();
449 setup_pci_ram_top();
Simon Glass16a624b2017-01-16 07:03:57 -0700450
451 return 0;
452}
453
454void x86_enable_caches(void)
455{
456 unsigned long cr0;
457
458 cr0 = read_cr0();
459 cr0 &= ~(X86_CR0_NW | X86_CR0_CD);
460 write_cr0(cr0);
461 wbinvd();
462}
463void enable_caches(void) __attribute__((weak, alias("x86_enable_caches")));
464
465void x86_disable_caches(void)
466{
467 unsigned long cr0;
468
469 cr0 = read_cr0();
470 cr0 |= X86_CR0_NW | X86_CR0_CD;
471 wbinvd();
472 write_cr0(cr0);
473 wbinvd();
474}
475void disable_caches(void) __attribute__((weak, alias("x86_disable_caches")));
476
477int dcache_status(void)
478{
479 return !(read_cr0() & X86_CR0_CD);
480}
481
482void cpu_enable_paging_pae(ulong cr3)
483{
484 __asm__ __volatile__(
485 /* Load the page table address */
486 "movl %0, %%cr3\n"
487 /* Enable pae */
488 "movl %%cr4, %%eax\n"
489 "orl $0x00000020, %%eax\n"
490 "movl %%eax, %%cr4\n"
491 /* Enable paging */
492 "movl %%cr0, %%eax\n"
493 "orl $0x80000000, %%eax\n"
494 "movl %%eax, %%cr0\n"
495 :
496 : "r" (cr3)
497 : "eax");
498}
499
500void cpu_disable_paging_pae(void)
501{
502 /* Turn off paging */
503 __asm__ __volatile__ (
504 /* Disable paging */
505 "movl %%cr0, %%eax\n"
506 "andl $0x7fffffff, %%eax\n"
507 "movl %%eax, %%cr0\n"
508 /* Disable pae */
509 "movl %%cr4, %%eax\n"
510 "andl $0xffffffdf, %%eax\n"
511 "movl %%eax, %%cr4\n"
512 :
513 :
514 : "eax");
515}
516
517static bool can_detect_long_mode(void)
518{
519 return cpuid_eax(0x80000000) > 0x80000000UL;
520}
521
522static bool has_long_mode(void)
523{
524 return cpuid_edx(0x80000001) & (1 << 29) ? true : false;
525}
526
527int cpu_has_64bit(void)
528{
529 return has_cpuid() && can_detect_long_mode() &&
530 has_long_mode();
531}
532
Bin Meng6aac2ca2019-01-31 08:22:12 -0800533#define PAGETABLE_BASE 0x80000
Simon Glass16a624b2017-01-16 07:03:57 -0700534#define PAGETABLE_SIZE (6 * 4096)
535
536/**
537 * build_pagetable() - build a flat 4GiB page table structure for 64-bti mode
538 *
539 * @pgtable: Pointer to a 24iKB block of memory
540 */
541static void build_pagetable(uint32_t *pgtable)
542{
543 uint i;
544
545 memset(pgtable, '\0', PAGETABLE_SIZE);
546
547 /* Level 4 needs a single entry */
548 pgtable[0] = (ulong)&pgtable[1024] + 7;
549
550 /* Level 3 has one 64-bit entry for each GiB of memory */
551 for (i = 0; i < 4; i++)
552 pgtable[1024 + i * 2] = (ulong)&pgtable[2048] + 0x1000 * i + 7;
553
554 /* Level 2 has 2048 64-bit entries, each repesenting 2MiB */
555 for (i = 0; i < 2048; i++)
556 pgtable[2048 + i * 2] = 0x183 + (i << 21UL);
557}
558
559int cpu_jump_to_64bit(ulong setup_base, ulong target)
560{
561 uint32_t *pgtable;
562
563 pgtable = memalign(4096, PAGETABLE_SIZE);
564 if (!pgtable)
565 return -ENOMEM;
566
567 build_pagetable(pgtable);
568 cpu_call64((ulong)pgtable, setup_base, target);
569 free(pgtable);
570
571 return -EFAULT;
572}
573
Simon Glass1e32ede2017-01-16 07:04:15 -0700574/*
575 * Jump from SPL to U-Boot
576 *
577 * This function is work-in-progress with many issues to resolve.
578 *
579 * It works by setting up several regions:
580 * ptr - a place to put the code that jumps into 64-bit mode
581 * gdt - a place to put the global descriptor table
582 * pgtable - a place to put the page tables
583 *
584 * The cpu_call64() code is copied from ROM and then manually patched so that
585 * it has the correct GDT address in RAM. U-Boot is copied from ROM into
586 * its pre-relocation address. Then we jump to the cpu_call64() code in RAM,
587 * which changes to 64-bit mode and starts U-Boot.
588 */
589int cpu_jump_to_64bit_uboot(ulong target)
590{
591 typedef void (*func_t)(ulong pgtable, ulong setup_base, ulong target);
592 uint32_t *pgtable;
593 func_t func;
Bin Meng17b7b602019-01-31 08:22:13 -0800594 char *ptr;
Simon Glass1e32ede2017-01-16 07:04:15 -0700595
Bin Meng6aac2ca2019-01-31 08:22:12 -0800596 pgtable = (uint32_t *)PAGETABLE_BASE;
Simon Glass1e32ede2017-01-16 07:04:15 -0700597
598 build_pagetable(pgtable);
599
Bin Meng17b7b602019-01-31 08:22:13 -0800600 extern long call64_stub_size;
601 ptr = malloc(call64_stub_size);
602 if (!ptr) {
603 printf("Failed to allocate the cpu_call64 stub\n");
604 return -ENOMEM;
605 }
Bin Meng17b7b602019-01-31 08:22:13 -0800606 memcpy(ptr, cpu_call64, call64_stub_size);
Simon Glass1e32ede2017-01-16 07:04:15 -0700607
Simon Glass1e32ede2017-01-16 07:04:15 -0700608 func = (func_t)ptr;
Simon Glass1e32ede2017-01-16 07:04:15 -0700609
610 /*
611 * Copy U-Boot from ROM
612 * TODO(sjg@chromium.org): Figure out a way to get the text base
613 * correctly here, and in the device-tree binman definition.
614 *
615 * Also consider using FIT so we get the correct image length and
616 * parameters.
617 */
618 memcpy((char *)target, (char *)0xfff00000, 0x100000);
619
620 /* Jump to U-Boot */
621 func((ulong)pgtable, 0, (ulong)target);
622
623 return -EFAULT;
624}
625
Simon Glass16a624b2017-01-16 07:03:57 -0700626#ifdef CONFIG_SMP
627static int enable_smis(struct udevice *cpu, void *unused)
628{
629 return 0;
630}
631
632static struct mp_flight_record mp_steps[] = {
633 MP_FR_BLOCK_APS(mp_init_cpu, NULL, mp_init_cpu, NULL),
634 /* Wait for APs to finish initialization before proceeding */
635 MP_FR_BLOCK_APS(NULL, NULL, enable_smis, NULL),
636};
637
638int x86_mp_init(void)
639{
640 struct mp_params mp_params;
641
642 mp_params.parallel_microcode_load = 0,
643 mp_params.flight_plan = &mp_steps[0];
644 mp_params.num_records = ARRAY_SIZE(mp_steps);
645 mp_params.microcode_pointer = 0;
646
647 if (mp_init(&mp_params)) {
648 printf("Warning: MP init failure\n");
649 return -EIO;
650 }
651
652 return 0;
653}
654#endif