]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
2262cfee | 2 | /* |
dbf7115a GR |
3 | * (C) Copyright 2008-2011 |
4 | * Graeme Russ, <[email protected]> | |
5 | * | |
2262cfee | 6 | * (C) Copyright 2002 |
fa82f871 | 7 | * Daniel Engström, Omicron Ceti AB, <[email protected]> |
8bde7f77 | 8 | * |
2262cfee WD |
9 | * (C) Copyright 2002 |
10 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> | |
11 | * Marius Groeger <[email protected]> | |
12 | * | |
13 | * (C) Copyright 2002 | |
14 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> | |
15 | * Alex Zuepke <[email protected]> | |
16 | * | |
52f952bf BM |
17 | * Part of this file is adapted from coreboot |
18 | * src/arch/x86/lib/cpu.c | |
2262cfee WD |
19 | */ |
20 | ||
2262cfee WD |
21 | #include <common.h> |
22 | #include <command.h> | |
9edefc27 | 23 | #include <cpu_func.h> |
6e6f4ce4 | 24 | #include <dm.h> |
200182a7 | 25 | #include <errno.h> |
35a3f871 | 26 | #include <init.h> |
200182a7 | 27 | #include <malloc.h> |
d8906c1f | 28 | #include <syscon.h> |
3cabcf96 | 29 | #include <acpi/acpi_s3.h> |
a0609a8d | 30 | #include <asm/acpi.h> |
3a34cae0 | 31 | #include <asm/acpi_table.h> |
095593c0 | 32 | #include <asm/control_regs.h> |
d19c9074 | 33 | #include <asm/coreboot_tables.h> |
200182a7 | 34 | #include <asm/cpu.h> |
6e6f4ce4 | 35 | #include <asm/lapic.h> |
e77b62e2 | 36 | #include <asm/microcode.h> |
6e6f4ce4 | 37 | #include <asm/mp.h> |
0c2b7eef | 38 | #include <asm/mrccache.h> |
43dd22f5 BM |
39 | #include <asm/msr.h> |
40 | #include <asm/mtrr.h> | |
a49e3c7f | 41 | #include <asm/post.h> |
c53fd2bb | 42 | #include <asm/processor.h> |
0c24c9cc | 43 | #include <asm/processor-flags.h> |
3f5f18d1 | 44 | #include <asm/interrupt.h> |
5e2400e8 | 45 | #include <asm/tables.h> |
60a9b6bf | 46 | #include <linux/compiler.h> |
2262cfee | 47 | |
52f952bf BM |
48 | DECLARE_GLOBAL_DATA_PTR; |
49 | ||
caca13f6 | 50 | #ifndef CONFIG_TPL_BUILD |
52f952bf BM |
51 | static const char *const x86_vendor_name[] = { |
52 | [X86_VENDOR_INTEL] = "Intel", | |
53 | [X86_VENDOR_CYRIX] = "Cyrix", | |
54 | [X86_VENDOR_AMD] = "AMD", | |
55 | [X86_VENDOR_UMC] = "UMC", | |
56 | [X86_VENDOR_NEXGEN] = "NexGen", | |
57 | [X86_VENDOR_CENTAUR] = "Centaur", | |
58 | [X86_VENDOR_RISE] = "Rise", | |
59 | [X86_VENDOR_TRANSMETA] = "Transmeta", | |
60 | [X86_VENDOR_NSC] = "NSC", | |
61 | [X86_VENDOR_SIS] = "SiS", | |
62 | }; | |
caca13f6 | 63 | #endif |
52f952bf | 64 | |
f30fc4de GB |
65 | int __weak x86_cleanup_before_linux(void) |
66 | { | |
7949703a | 67 | #ifdef CONFIG_BOOTSTAGE_STASH |
ee2b2434 | 68 | bootstage_stash((void *)CONFIG_BOOTSTAGE_STASH_ADDR, |
7949703a SG |
69 | CONFIG_BOOTSTAGE_STASH_SIZE); |
70 | #endif | |
71 | ||
f30fc4de GB |
72 | return 0; |
73 | } | |
74 | ||
d653244b GR |
75 | int x86_init_cache(void) |
76 | { | |
77 | enable_caches(); | |
0ea76e92 | 78 | |
2262cfee WD |
79 | return 0; |
80 | } | |
d653244b | 81 | int init_cache(void) __attribute__((weak, alias("x86_init_cache"))); |
2262cfee | 82 | |
717979fd | 83 | void flush_cache(unsigned long dummy1, unsigned long dummy2) |
2262cfee WD |
84 | { |
85 | asm("wbinvd\n"); | |
2262cfee | 86 | } |
3f5f18d1 | 87 | |
095593c0 SR |
88 | /* Define these functions to allow ehch-hcd to function */ |
89 | void flush_dcache_range(unsigned long start, unsigned long stop) | |
90 | { | |
91 | } | |
92 | ||
93 | void invalidate_dcache_range(unsigned long start, unsigned long stop) | |
94 | { | |
95 | } | |
89371409 SG |
96 | |
97 | void dcache_enable(void) | |
98 | { | |
99 | enable_caches(); | |
100 | } | |
101 | ||
102 | void dcache_disable(void) | |
103 | { | |
104 | disable_caches(); | |
105 | } | |
106 | ||
107 | void icache_enable(void) | |
108 | { | |
109 | } | |
110 | ||
111 | void icache_disable(void) | |
112 | { | |
113 | } | |
114 | ||
115 | int icache_status(void) | |
116 | { | |
117 | return 1; | |
118 | } | |
7bddac94 | 119 | |
caca13f6 | 120 | #ifndef CONFIG_TPL_BUILD |
52f952bf BM |
121 | const char *cpu_vendor_name(int vendor) |
122 | { | |
123 | const char *name; | |
124 | name = "<invalid cpu vendor>"; | |
39670c34 HS |
125 | if (vendor < ARRAY_SIZE(x86_vendor_name) && |
126 | x86_vendor_name[vendor]) | |
52f952bf | 127 | name = x86_vendor_name[vendor]; |
92cc94a1 | 128 | |
52f952bf | 129 | return name; |
92cc94a1 | 130 | } |
caca13f6 | 131 | #endif |
92cc94a1 | 132 | |
727c1a98 | 133 | char *cpu_get_name(char *name) |
92cc94a1 | 134 | { |
727c1a98 | 135 | unsigned int *name_as_ints = (unsigned int *)name; |
52f952bf | 136 | struct cpuid_result regs; |
727c1a98 | 137 | char *ptr; |
52f952bf | 138 | int i; |
92cc94a1 | 139 | |
727c1a98 | 140 | /* This bit adds up to 48 bytes */ |
52f952bf BM |
141 | for (i = 0; i < 3; i++) { |
142 | regs = cpuid(0x80000002 + i); | |
143 | name_as_ints[i * 4 + 0] = regs.eax; | |
144 | name_as_ints[i * 4 + 1] = regs.ebx; | |
145 | name_as_ints[i * 4 + 2] = regs.ecx; | |
146 | name_as_ints[i * 4 + 3] = regs.edx; | |
147 | } | |
727c1a98 | 148 | name[CPU_MAX_NAME_LEN - 1] = '\0'; |
92cc94a1 | 149 | |
52f952bf | 150 | /* Skip leading spaces. */ |
727c1a98 SG |
151 | ptr = name; |
152 | while (*ptr == ' ') | |
153 | ptr++; | |
52f952bf | 154 | |
727c1a98 | 155 | return ptr; |
92cc94a1 SG |
156 | } |
157 | ||
727c1a98 | 158 | int default_print_cpuinfo(void) |
92cc94a1 | 159 | { |
52f952bf BM |
160 | printf("CPU: %s, vendor %s, device %xh\n", |
161 | cpu_has_64bit() ? "x86_64" : "x86", | |
162 | cpu_vendor_name(gd->arch.x86_vendor), gd->arch.x86_device); | |
92cc94a1 | 163 | |
b727961b BM |
164 | #ifdef CONFIG_HAVE_ACPI_RESUME |
165 | debug("ACPI previous sleep state: %s\n", | |
166 | acpi_ss_string(gd->arch.prev_sleep_state)); | |
167 | #endif | |
168 | ||
92cc94a1 SG |
169 | return 0; |
170 | } | |
200182a7 | 171 | |
a49e3c7f SG |
172 | void show_boot_progress(int val) |
173 | { | |
a49e3c7f SG |
174 | outb(val, POST_PORT); |
175 | } | |
5e2400e8 | 176 | |
1ab2c010 | 177 | #if !defined(CONFIG_SYS_COREBOOT) && !defined(CONFIG_EFI_STUB) |
1e2f7b9e BM |
178 | /* |
179 | * Implement a weak default function for boards that optionally | |
180 | * need to clean up the system before jumping to the kernel. | |
181 | */ | |
182 | __weak void board_final_cleanup(void) | |
183 | { | |
184 | } | |
185 | ||
5e2400e8 BM |
186 | int last_stage_init(void) |
187 | { | |
474a62bc BM |
188 | struct acpi_fadt __maybe_unused *fadt; |
189 | ||
bffd7981 BM |
190 | board_final_cleanup(); |
191 | ||
474a62bc BM |
192 | #ifdef CONFIG_HAVE_ACPI_RESUME |
193 | fadt = acpi_find_fadt(); | |
3a34cae0 | 194 | |
474a62bc | 195 | if (fadt && gd->arch.prev_sleep_state == ACPI_S3) |
0f4e2588 | 196 | acpi_resume(fadt); |
3a34cae0 BM |
197 | #endif |
198 | ||
5e2400e8 BM |
199 | write_tables(); |
200 | ||
474a62bc BM |
201 | #ifdef CONFIG_GENERATE_ACPI_TABLE |
202 | fadt = acpi_find_fadt(); | |
203 | ||
204 | /* Don't touch ACPI hardware on HW reduced platforms */ | |
205 | if (fadt && !(fadt->flags & ACPI_FADT_HW_REDUCED_ACPI)) { | |
206 | /* | |
207 | * Other than waiting for OSPM to request us to switch to ACPI | |
208 | * mode, do it by ourselves, since SMI will not be triggered. | |
209 | */ | |
210 | enter_acpi_mode(fadt->pm1a_cnt_blk); | |
211 | } | |
212 | #endif | |
213 | ||
5e2400e8 BM |
214 | return 0; |
215 | } | |
216 | #endif | |
bcb0c61e | 217 | |
afd5d50c | 218 | static int x86_init_cpus(void) |
bcb0c61e | 219 | { |
6e6f4ce4 BM |
220 | #ifdef CONFIG_SMP |
221 | debug("Init additional CPUs\n"); | |
222 | x86_mp_init(); | |
c77b8912 BM |
223 | #else |
224 | struct udevice *dev; | |
225 | ||
226 | /* | |
227 | * This causes the cpu-x86 driver to be probed. | |
228 | * We don't check return value here as we want to allow boards | |
229 | * which have not been converted to use cpu uclass driver to boot. | |
230 | */ | |
231 | uclass_first_device(UCLASS_CPU, &dev); | |
6e6f4ce4 BM |
232 | #endif |
233 | ||
bcb0c61e SG |
234 | return 0; |
235 | } | |
236 | ||
237 | int cpu_init_r(void) | |
238 | { | |
ac643e03 SG |
239 | struct udevice *dev; |
240 | int ret; | |
241 | ||
242 | if (!ll_boot_init()) | |
243 | return 0; | |
244 | ||
245 | ret = x86_init_cpus(); | |
246 | if (ret) | |
247 | return ret; | |
248 | ||
249 | /* | |
250 | * Set up the northbridge, PCH and LPC if available. Note that these | |
251 | * may have had some limited pre-relocation init if they were probed | |
252 | * before relocation, but this is post relocation. | |
253 | */ | |
254 | uclass_first_device(UCLASS_NORTHBRIDGE, &dev); | |
255 | uclass_first_device(UCLASS_PCH, &dev); | |
256 | uclass_first_device(UCLASS_LPC, &dev); | |
e49cceac | 257 | |
d8906c1f BM |
258 | /* Set up pin control if available */ |
259 | ret = syscon_get_by_driver_data(X86_SYSCON_PINCONF, &dev); | |
260 | debug("%s, pinctrl=%p, ret=%d\n", __func__, dev, ret); | |
261 | ||
e49cceac | 262 | return 0; |
bcb0c61e | 263 | } |
0c2b7eef BM |
264 | |
265 | #ifndef CONFIG_EFI_STUB | |
266 | int reserve_arch(void) | |
267 | { | |
268 | #ifdef CONFIG_ENABLE_MRC_CACHE | |
d19c9074 BM |
269 | mrccache_reserve(); |
270 | #endif | |
271 | ||
272 | #ifdef CONFIG_SEABIOS | |
273 | high_table_reserve(); | |
0c2b7eef | 274 | #endif |
d19c9074 | 275 | |
5ae5aa93 BM |
276 | #ifdef CONFIG_HAVE_ACPI_RESUME |
277 | acpi_s3_reserve(); | |
278 | ||
279 | #ifdef CONFIG_HAVE_FSP | |
ba65808e BM |
280 | /* |
281 | * Save stack address to CMOS so that at next S3 boot, | |
282 | * we can use it as the stack address for fsp_contiue() | |
283 | */ | |
284 | fsp_save_s3_stack(); | |
5ae5aa93 BM |
285 | #endif /* CONFIG_HAVE_FSP */ |
286 | #endif /* CONFIG_HAVE_ACPI_RESUME */ | |
ba65808e | 287 | |
d19c9074 | 288 | return 0; |
0c2b7eef BM |
289 | } |
290 | #endif |