1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include <common.h>
22#include <acpi_s3.h>
23#include <command.h>
24#include <cpu_func.h>
25#include <dm.h>
26#include <errno.h>
27#include <malloc.h>
28#include <syscon.h>
29#include <asm/acpi.h>
30#include <asm/acpi_table.h>
31#include <asm/control_regs.h>
32#include <asm/coreboot_tables.h>
33#include <asm/cpu.h>
34#include <asm/lapic.h>
35#include <asm/microcode.h>
36#include <asm/mp.h>
37#include <asm/mrccache.h>
38#include <asm/msr.h>
39#include <asm/mtrr.h>
40#include <asm/post.h>
41#include <asm/processor.h>
42#include <asm/processor-flags.h>
43#include <asm/interrupt.h>
44#include <asm/tables.h>
45#include <linux/compiler.h>
46
47DECLARE_GLOBAL_DATA_PTR;
48
49static const char *const x86_vendor_name[] = {
50 [X86_VENDOR_INTEL] = "Intel",
51 [X86_VENDOR_CYRIX] = "Cyrix",
52 [X86_VENDOR_AMD] = "AMD",
53 [X86_VENDOR_UMC] = "UMC",
54 [X86_VENDOR_NEXGEN] = "NexGen",
55 [X86_VENDOR_CENTAUR] = "Centaur",
56 [X86_VENDOR_RISE] = "Rise",
57 [X86_VENDOR_TRANSMETA] = "Transmeta",
58 [X86_VENDOR_NSC] = "NSC",
59 [X86_VENDOR_SIS] = "SiS",
60};
61
62int __weak x86_cleanup_before_linux(void)
63{
64#ifdef CONFIG_BOOTSTAGE_STASH
65 bootstage_stash((void *)CONFIG_BOOTSTAGE_STASH_ADDR,
66 CONFIG_BOOTSTAGE_STASH_SIZE);
67#endif
68
69 return 0;
70}
71
72int x86_init_cache(void)
73{
74 enable_caches();
75
76 return 0;
77}
78int init_cache(void) __attribute__((weak, alias("x86_init_cache")));
79
80void flush_cache(unsigned long dummy1, unsigned long dummy2)
81{
82 asm("wbinvd\n");
83}
84
85
86void flush_dcache_range(unsigned long start, unsigned long stop)
87{
88}
89
90void invalidate_dcache_range(unsigned long start, unsigned long stop)
91{
92}
93
94void dcache_enable(void)
95{
96 enable_caches();
97}
98
99void dcache_disable(void)
100{
101 disable_caches();
102}
103
104void icache_enable(void)
105{
106}
107
108void icache_disable(void)
109{
110}
111
112int icache_status(void)
113{
114 return 1;
115}
116
117const char *cpu_vendor_name(int vendor)
118{
119 const char *name;
120 name = "<invalid cpu vendor>";
121 if (vendor < ARRAY_SIZE(x86_vendor_name) &&
122 x86_vendor_name[vendor])
123 name = x86_vendor_name[vendor];
124
125 return name;
126}
127
128char *cpu_get_name(char *name)
129{
130 unsigned int *name_as_ints = (unsigned int *)name;
131 struct cpuid_result regs;
132 char *ptr;
133 int i;
134
135
136 for (i = 0; i < 3; i++) {
137 regs = cpuid(0x80000002 + i);
138 name_as_ints[i * 4 + 0] = regs.eax;
139 name_as_ints[i * 4 + 1] = regs.ebx;
140 name_as_ints[i * 4 + 2] = regs.ecx;
141 name_as_ints[i * 4 + 3] = regs.edx;
142 }
143 name[CPU_MAX_NAME_LEN - 1] = '\0';
144
145
146 ptr = name;
147 while (*ptr == ' ')
148 ptr++;
149
150 return ptr;
151}
152
153int default_print_cpuinfo(void)
154{
155 printf("CPU: %s, vendor %s, device %xh\n",
156 cpu_has_64bit() ? "x86_64" : "x86",
157 cpu_vendor_name(gd->arch.x86_vendor), gd->arch.x86_device);
158
159#ifdef CONFIG_HAVE_ACPI_RESUME
160 debug("ACPI previous sleep state: %s\n",
161 acpi_ss_string(gd->arch.prev_sleep_state));
162#endif
163
164 return 0;
165}
166
167void show_boot_progress(int val)
168{
169 outb(val, POST_PORT);
170}
171
172#if !defined(CONFIG_SYS_COREBOOT) && !defined(CONFIG_EFI_STUB)
173
174
175
176
177__weak void board_final_cleanup(void)
178{
179}
180
181int last_stage_init(void)
182{
183 struct acpi_fadt __maybe_unused *fadt;
184
185 board_final_cleanup();
186
187#ifdef CONFIG_HAVE_ACPI_RESUME
188 fadt = acpi_find_fadt();
189
190 if (fadt && gd->arch.prev_sleep_state == ACPI_S3)
191 acpi_resume(fadt);
192#endif
193
194 write_tables();
195
196#ifdef CONFIG_GENERATE_ACPI_TABLE
197 fadt = acpi_find_fadt();
198
199
200 if (fadt && !(fadt->flags & ACPI_FADT_HW_REDUCED_ACPI)) {
201
202
203
204
205 enter_acpi_mode(fadt->pm1a_cnt_blk);
206 }
207#endif
208
209 return 0;
210}
211#endif
212
213static int x86_init_cpus(void)
214{
215#ifdef CONFIG_SMP
216 debug("Init additional CPUs\n");
217 x86_mp_init();
218#else
219 struct udevice *dev;
220
221
222
223
224
225
226 uclass_first_device(UCLASS_CPU, &dev);
227#endif
228
229 return 0;
230}
231
232int cpu_init_r(void)
233{
234 struct udevice *dev;
235 int ret;
236
237 if (!ll_boot_init())
238 return 0;
239
240 ret = x86_init_cpus();
241 if (ret)
242 return ret;
243
244
245
246
247
248
249 uclass_first_device(UCLASS_NORTHBRIDGE, &dev);
250 uclass_first_device(UCLASS_PCH, &dev);
251 uclass_first_device(UCLASS_LPC, &dev);
252
253
254 ret = syscon_get_by_driver_data(X86_SYSCON_PINCONF, &dev);
255 debug("%s, pinctrl=%p, ret=%d\n", __func__, dev, ret);
256
257 return 0;
258}
259
260#ifndef CONFIG_EFI_STUB
261int reserve_arch(void)
262{
263#ifdef CONFIG_ENABLE_MRC_CACHE
264 mrccache_reserve();
265#endif
266
267#ifdef CONFIG_SEABIOS
268 high_table_reserve();
269#endif
270
271#ifdef CONFIG_HAVE_ACPI_RESUME
272 acpi_s3_reserve();
273
274#ifdef CONFIG_HAVE_FSP
275
276
277
278
279 fsp_save_s3_stack();
280#endif
281#endif
282
283 return 0;
284}
285#endif
286