2 * Copyright (c) 2014 The Chromium OS Authors.
4 * Part of this file is adapted from coreboot
5 * src/arch/x86/include/arch/cpu.h and
6 * src/arch/x86/lib/cpu.c
8 * SPDX-License-Identifier: GPL-2.0+
15 X86_VENDOR_INVALID = 0,
26 X86_VENDOR_ANY = 0xfe,
27 X86_VENDOR_UNKNOWN = 0xff
30 /* Global descriptor table (GDT) bits */
33 GDT_32BIT = 1ULL << 54,
34 GDT_LONG = 1ULL << 53,
35 GDT_PRESENT = 1ULL << 47,
36 GDT_NOTSYS = 1ULL << 44,
37 GDT_CODE = 1ULL << 43,
38 GDT_LIMIT_LOW_SHIFT = 0,
39 GDT_LIMIT_LOW_MASK = 0xffff,
40 GDT_LIMIT_HIGH_SHIFT = 48,
41 GDT_LIMIT_HIGH_MASK = 0xf,
42 GDT_BASE_LOW_SHIFT = 16,
43 GDT_BASE_LOW_MASK = 0xffff,
44 GDT_BASE_HIGH_SHIFT = 56,
45 GDT_BASE_HIGH_MASK = 0xf,
49 * System controllers in an x86 system. We mostly need to just find these and
50 * use them on PCI. At some point these might have their own uclass (e.g.
51 * UCLASS_VIDEO for the GMA device).
55 X86_SYSCON_ME, /* Intel Management Engine */
56 X86_SYSCON_PINCONF, /* Intel x86 pin configuration */
67 * Generic CPUID function
69 static inline struct cpuid_result cpuid(int op)
71 struct cpuid_result result;
87 * Generic Extended CPUID function
89 static inline struct cpuid_result cpuid_ext(int op, unsigned ecx)
91 struct cpuid_result result;
101 : "0" (op), "2" (ecx)
107 * CPUID functions returning a single datum
109 static inline unsigned int cpuid_eax(unsigned int op)
113 __asm__("mov %%ebx, %%edi;"
118 : "ecx", "edx", "edi");
122 static inline unsigned int cpuid_ebx(unsigned int op)
124 unsigned int eax, ebx;
126 __asm__("mov %%ebx, %%edi;"
130 : "=a" (eax), "=S" (ebx)
132 : "ecx", "edx", "edi");
136 static inline unsigned int cpuid_ecx(unsigned int op)
138 unsigned int eax, ecx;
140 __asm__("mov %%ebx, %%edi;"
143 : "=a" (eax), "=c" (ecx)
149 static inline unsigned int cpuid_edx(unsigned int op)
151 unsigned int eax, edx;
153 __asm__("mov %%ebx, %%edi;"
156 : "=a" (eax), "=d" (edx)
162 #if !CONFIG_IS_ENABLED(X86_64)
164 /* Standard macro to see if a specific flag is changeable */
165 static inline int flag_is_changeable_p(uint32_t flag)
180 : "=&r" (f1), "=&r" (f2)
182 return ((f1^f2) & flag) != 0;
186 static inline void mfence(void)
188 __asm__ __volatile__("mfence" : : : "memory");
192 * cpu_enable_paging_pae() - Enable PAE-paging
194 * @cr3: Value to set in cr3 (PDPT or PML4T)
196 void cpu_enable_paging_pae(ulong cr3);
199 * cpu_disable_paging_pae() - Disable paging and PAE
201 void cpu_disable_paging_pae(void);
204 * cpu_has_64bit() - Check if the CPU has 64-bit support
206 * @return 1 if this CPU supports long mode (64-bit), 0 if not
208 int cpu_has_64bit(void);
211 * cpu_vendor_name() - Get CPU vendor name
213 * @vendor: CPU vendor enumeration number
215 * @return: Address to hold the CPU vendor name string
217 const char *cpu_vendor_name(int vendor);
219 #define CPU_MAX_NAME_LEN 49
222 * cpu_get_name() - Get the name of the current cpu
224 * @name: Place to put name, which must be CPU_MAX_NAME_LEN bytes including
225 * @return pointer to name, which will likely be a few bytes after the start
229 char *cpu_get_name(char *name);
232 * cpu_call64() - Jump to a 64-bit Linux kernel (internal function)
234 * The kernel is uncompressed and the 64-bit entry point is expected to be
237 * This function is used internally - see cpu_jump_to_64bit() for a more
240 * @pgtable: Address of 24KB area containing the page table
241 * @setup_base: Pointer to the setup.bin information for the kernel
242 * @target: Pointer to the start of the kernel image
244 void cpu_call64(ulong pgtable, ulong setup_base, ulong target);
247 * cpu_call32() - Jump to a 32-bit entry point
249 * @code_seg32: 32-bit code segment to use (GDT offset, e.g. 0x20)
250 * @target: Pointer to the start of the 32-bit U-Boot image/entry point
251 * @table: Pointer to start of info table to pass to U-Boot
253 void cpu_call32(ulong code_seg32, ulong target, ulong table);
256 * cpu_jump_to_64bit() - Jump to a 64-bit Linux kernel
258 * The kernel is uncompressed and the 64-bit entry point is expected to be
261 * @setup_base: Pointer to the setup.bin information for the kernel
262 * @target: Pointer to the start of the kernel image
264 int cpu_jump_to_64bit(ulong setup_base, ulong target);
267 * cpu_jump_to_64bit_uboot() - special function to jump from SPL to U-Boot
269 * This handles calling from 32-bit SPL to 64-bit U-Boot.
271 * @target: Address of U-Boot in RAM
273 int cpu_jump_to_64bit_uboot(ulong target);
276 * cpu_get_family_model() - Get the family and model for the CPU
278 * @return the CPU ID masked with 0x0fff0ff0
280 u32 cpu_get_family_model(void);
283 * cpu_get_stepping() - Get the stepping value for the CPU
285 * @return the CPU ID masked with 0xf
287 u32 cpu_get_stepping(void);
290 * cpu_run_reference_code() - Run the platform reference code
292 * Some platforms require a binary blob to be executed once SDRAM is
293 * available. This is used to set up various platform features, such as the
294 * platform controller hub (PCH). This function should be implemented by the
297 * @return 0 on success, -ve on failure
299 int cpu_run_reference_code(void);