1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (c) 2014 The Chromium OS Authors.
5 * Part of this file is adapted from coreboot
6 * src/arch/x86/include/arch/cpu.h and
7 * src/arch/x86/lib/cpu.c
14 X86_VENDOR_INVALID = 0,
25 X86_VENDOR_ANY = 0xfe,
26 X86_VENDOR_UNKNOWN = 0xff
29 /* Global descriptor table (GDT) bits */
32 GDT_32BIT = 1ULL << 54,
33 GDT_LONG = 1ULL << 53,
34 GDT_PRESENT = 1ULL << 47,
35 GDT_NOTSYS = 1ULL << 44,
36 GDT_CODE = 1ULL << 43,
37 GDT_LIMIT_LOW_SHIFT = 0,
38 GDT_LIMIT_LOW_MASK = 0xffff,
39 GDT_LIMIT_HIGH_SHIFT = 48,
40 GDT_LIMIT_HIGH_MASK = 0xf,
41 GDT_BASE_LOW_SHIFT = 16,
42 GDT_BASE_LOW_MASK = 0xffff,
43 GDT_BASE_HIGH_SHIFT = 56,
44 GDT_BASE_HIGH_MASK = 0xf,
48 * System controllers in an x86 system. We mostly need to just find these and
49 * use them on PCI. At some point these might have their own uclass (e.g.
50 * UCLASS_VIDEO for the GMA device).
54 X86_SYSCON_ME, /* Intel Management Engine */
55 X86_SYSCON_PINCONF, /* Intel x86 pin configuration */
56 X86_SYSCON_PMU, /* Power Management Unit */
57 X86_SYSCON_SCU, /* System Controller Unit */
58 X86_SYSCON_PUNIT, /* Power unit */
69 * Generic CPUID function
71 static inline struct cpuid_result cpuid(int op)
73 struct cpuid_result result;
89 * Generic Extended CPUID function
91 static inline struct cpuid_result cpuid_ext(int op, unsigned ecx)
93 struct cpuid_result result;
103 : "0" (op), "2" (ecx)
109 * CPUID functions returning a single datum
111 static inline unsigned int cpuid_eax(unsigned int op)
115 __asm__("mov %%ebx, %%edi;"
120 : "ecx", "edx", "edi");
124 static inline unsigned int cpuid_ebx(unsigned int op)
126 unsigned int eax, ebx;
128 __asm__("mov %%ebx, %%edi;"
132 : "=a" (eax), "=S" (ebx)
134 : "ecx", "edx", "edi");
138 static inline unsigned int cpuid_ecx(unsigned int op)
140 unsigned int eax, ecx;
142 __asm__("mov %%ebx, %%edi;"
145 : "=a" (eax), "=c" (ecx)
151 static inline unsigned int cpuid_edx(unsigned int op)
153 unsigned int eax, edx;
155 __asm__("mov %%ebx, %%edi;"
158 : "=a" (eax), "=d" (edx)
164 #if !CONFIG_IS_ENABLED(X86_64)
166 /* Standard macro to see if a specific flag is changeable */
167 static inline int flag_is_changeable_p(uint32_t flag)
182 : "=&r" (f1), "=&r" (f2)
184 return ((f1^f2) & flag) != 0;
188 static inline void mfence(void)
190 __asm__ __volatile__("mfence" : : : "memory");
194 * cpu_enable_paging_pae() - Enable PAE-paging
196 * @cr3: Value to set in cr3 (PDPT or PML4T)
198 void cpu_enable_paging_pae(ulong cr3);
201 * cpu_disable_paging_pae() - Disable paging and PAE
203 void cpu_disable_paging_pae(void);
206 * cpu_has_64bit() - Check if the CPU has 64-bit support
208 * @return 1 if this CPU supports long mode (64-bit), 0 if not
210 int cpu_has_64bit(void);
213 * cpu_vendor_name() - Get CPU vendor name
215 * @vendor: CPU vendor enumeration number
217 * @return: Address to hold the CPU vendor name string
219 const char *cpu_vendor_name(int vendor);
221 #define CPU_MAX_NAME_LEN 49
224 * cpu_get_name() - Get the name of the current cpu
226 * @name: Place to put name, which must be CPU_MAX_NAME_LEN bytes including
227 * @return pointer to name, which will likely be a few bytes after the start
231 char *cpu_get_name(char *name);
234 * cpu_call64() - Jump to a 64-bit Linux kernel (internal function)
236 * The kernel is uncompressed and the 64-bit entry point is expected to be
239 * This function is used internally - see cpu_jump_to_64bit() for a more
242 * @pgtable: Address of 24KB area containing the page table
243 * @setup_base: Pointer to the setup.bin information for the kernel
244 * @target: Pointer to the start of the kernel image
246 void cpu_call64(ulong pgtable, ulong setup_base, ulong target);
249 * cpu_call32() - Jump to a 32-bit entry point
251 * @code_seg32: 32-bit code segment to use (GDT offset, e.g. 0x20)
252 * @target: Pointer to the start of the 32-bit U-Boot image/entry point
253 * @table: Pointer to start of info table to pass to U-Boot
255 void cpu_call32(ulong code_seg32, ulong target, ulong table);
258 * cpu_jump_to_64bit() - Jump to a 64-bit Linux kernel
260 * The kernel is uncompressed and the 64-bit entry point is expected to be
263 * @setup_base: Pointer to the setup.bin information for the kernel
264 * @target: Pointer to the start of the kernel image
266 int cpu_jump_to_64bit(ulong setup_base, ulong target);
269 * cpu_jump_to_64bit_uboot() - special function to jump from SPL to U-Boot
271 * This handles calling from 32-bit SPL to 64-bit U-Boot.
273 * @target: Address of U-Boot in RAM
275 int cpu_jump_to_64bit_uboot(ulong target);
278 * cpu_get_family_model() - Get the family and model for the CPU
280 * @return the CPU ID masked with 0x0fff0ff0
282 u32 cpu_get_family_model(void);
285 * cpu_get_stepping() - Get the stepping value for the CPU
287 * @return the CPU ID masked with 0xf
289 u32 cpu_get_stepping(void);