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,
56 * Generic CPUID function
58 static inline struct cpuid_result cpuid(int op)
60 struct cpuid_result result;
76 * Generic Extended CPUID function
78 static inline struct cpuid_result cpuid_ext(int op, unsigned ecx)
80 struct cpuid_result result;
96 * CPUID functions returning a single datum
98 static inline unsigned int cpuid_eax(unsigned int op)
102 __asm__("mov %%ebx, %%edi;"
107 : "ecx", "edx", "edi");
111 static inline unsigned int cpuid_ebx(unsigned int op)
113 unsigned int eax, ebx;
115 __asm__("mov %%ebx, %%edi;"
119 : "=a" (eax), "=S" (ebx)
121 : "ecx", "edx", "edi");
125 static inline unsigned int cpuid_ecx(unsigned int op)
127 unsigned int eax, ecx;
129 __asm__("mov %%ebx, %%edi;"
132 : "=a" (eax), "=c" (ecx)
138 static inline unsigned int cpuid_edx(unsigned int op)
140 unsigned int eax, edx;
142 __asm__("mov %%ebx, %%edi;"
145 : "=a" (eax), "=d" (edx)
151 /* Standard macro to see if a specific flag is changeable */
152 static inline int flag_is_changeable_p(uint32_t flag)
167 : "=&r" (f1), "=&r" (f2)
169 return ((f1^f2) & flag) != 0;
172 static inline void mfence(void)
174 __asm__ __volatile__("mfence" : : : "memory");
178 * cpu_enable_paging_pae() - Enable PAE-paging
180 * @cr3: Value to set in cr3 (PDPT or PML4T)
182 void cpu_enable_paging_pae(ulong cr3);
185 * cpu_disable_paging_pae() - Disable paging and PAE
187 void cpu_disable_paging_pae(void);
190 * cpu_has_64bit() - Check if the CPU has 64-bit support
192 * @return 1 if this CPU supports long mode (64-bit), 0 if not
194 int cpu_has_64bit(void);
197 * cpu_vendor_name() - Get CPU vendor name
199 * @vendor: CPU vendor enumeration number
201 * @return: Address to hold the CPU vendor name string
203 const char *cpu_vendor_name(int vendor);
205 #define CPU_MAX_NAME_LEN 49
208 * cpu_get_name() - Get the name of the current cpu
210 * @name: Place to put name, which must be CPU_MAX_NAME_LEN bytes including
211 * @return pointer to name, which will likely be a few bytes after the start
215 char *cpu_get_name(char *name);
218 * cpu_call64() - Jump to a 64-bit Linux kernel (internal function)
220 * The kernel is uncompressed and the 64-bit entry point is expected to be
223 * This function is used internally - see cpu_jump_to_64bit() for a more
226 * @pgtable: Address of 24KB area containing the page table
227 * @setup_base: Pointer to the setup.bin information for the kernel
228 * @target: Pointer to the start of the kernel image
230 void cpu_call64(ulong pgtable, ulong setup_base, ulong target);
233 * cpu_jump_to_64bit() - Jump to a 64-bit Linux kernel
235 * The kernel is uncompressed and the 64-bit entry point is expected to be
238 * @setup_base: Pointer to the setup.bin information for the kernel
239 * @target: Pointer to the start of the kernel image
241 int cpu_jump_to_64bit(ulong setup_base, ulong target);