diff options
author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-17 16:15:55 -0500 |
---|---|---|
committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-17 16:15:55 -0500 |
commit | 8dea78da5cee153b8af9c07a2745f6c55057fe12 (patch) | |
tree | a8f4d49d63b1ecc92f2fddceba0655b2472c5bd9 /arch/x86/boot/compressed | |
parent | 406089d01562f1e2bf9f089fd7637009ebaad589 (diff) |
Patched in Tegra support.
Diffstat (limited to 'arch/x86/boot/compressed')
-rw-r--r-- | arch/x86/boot/compressed/Makefile | 23 | ||||
-rw-r--r-- | arch/x86/boot/compressed/cmdline.c | 4 | ||||
-rw-r--r-- | arch/x86/boot/compressed/early_serial_console.c | 4 | ||||
-rw-r--r-- | arch/x86/boot/compressed/eboot.c | 1251 | ||||
-rw-r--r-- | arch/x86/boot/compressed/eboot.h | 71 | ||||
-rw-r--r-- | arch/x86/boot/compressed/efi_stub_32.S | 86 | ||||
-rw-r--r-- | arch/x86/boot/compressed/efi_stub_64.S | 1 | ||||
-rw-r--r-- | arch/x86/boot/compressed/head_32.S | 40 | ||||
-rw-r--r-- | arch/x86/boot/compressed/head_64.S | 40 | ||||
-rw-r--r-- | arch/x86/boot/compressed/misc.c | 33 | ||||
-rw-r--r-- | arch/x86/boot/compressed/misc.h | 27 | ||||
-rw-r--r-- | arch/x86/boot/compressed/mkpiggy.c | 11 | ||||
-rw-r--r-- | arch/x86/boot/compressed/string.c | 9 |
13 files changed, 41 insertions, 1559 deletions
diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile index 8a84501acb1..09664efb9ce 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile | |||
@@ -22,20 +22,8 @@ LDFLAGS := -m elf_$(UTS_MACHINE) | |||
22 | LDFLAGS_vmlinux := -T | 22 | LDFLAGS_vmlinux := -T |
23 | 23 | ||
24 | hostprogs-y := mkpiggy | 24 | hostprogs-y := mkpiggy |
25 | HOST_EXTRACFLAGS += -I$(srctree)/tools/include | ||
26 | 25 | ||
27 | VMLINUX_OBJS = $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \ | 26 | $(obj)/vmlinux: $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o $(obj)/string.o $(obj)/cmdline.o $(obj)/early_serial_console.o $(obj)/piggy.o FORCE |
28 | $(obj)/string.o $(obj)/cmdline.o $(obj)/early_serial_console.o \ | ||
29 | $(obj)/piggy.o | ||
30 | |||
31 | $(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone | ||
32 | $(obj)/efi_stub_$(BITS).o: KBUILD_CLFAGS += -fshort-wchar -mno-red-zone | ||
33 | |||
34 | ifeq ($(CONFIG_EFI_STUB), y) | ||
35 | VMLINUX_OBJS += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o | ||
36 | endif | ||
37 | |||
38 | $(obj)/vmlinux: $(VMLINUX_OBJS) FORCE | ||
39 | $(call if_changed,ld) | 27 | $(call if_changed,ld) |
40 | @: | 28 | @: |
41 | 29 | ||
@@ -43,12 +31,13 @@ OBJCOPYFLAGS_vmlinux.bin := -R .comment -S | |||
43 | $(obj)/vmlinux.bin: vmlinux FORCE | 31 | $(obj)/vmlinux.bin: vmlinux FORCE |
44 | $(call if_changed,objcopy) | 32 | $(call if_changed,objcopy) |
45 | 33 | ||
46 | targets += vmlinux.bin.all vmlinux.relocs | ||
47 | 34 | ||
48 | CMD_RELOCS = arch/x86/tools/relocs | 35 | targets += vmlinux.bin.all vmlinux.relocs relocs |
36 | hostprogs-$(CONFIG_X86_NEED_RELOCS) += relocs | ||
37 | |||
49 | quiet_cmd_relocs = RELOCS $@ | 38 | quiet_cmd_relocs = RELOCS $@ |
50 | cmd_relocs = $(CMD_RELOCS) $< > $@;$(CMD_RELOCS) --abs-relocs $< | 39 | cmd_relocs = $(obj)/relocs $< > $@;$(obj)/relocs --abs-relocs $< |
51 | $(obj)/vmlinux.relocs: vmlinux FORCE | 40 | $(obj)/vmlinux.relocs: vmlinux $(obj)/relocs FORCE |
52 | $(call if_changed,relocs) | 41 | $(call if_changed,relocs) |
53 | 42 | ||
54 | vmlinux.bin.all-y := $(obj)/vmlinux.bin | 43 | vmlinux.bin.all-y := $(obj)/vmlinux.bin |
diff --git a/arch/x86/boot/compressed/cmdline.c b/arch/x86/boot/compressed/cmdline.c index 10f6b1178c6..cb62f786990 100644 --- a/arch/x86/boot/compressed/cmdline.c +++ b/arch/x86/boot/compressed/cmdline.c | |||
@@ -1,7 +1,5 @@ | |||
1 | #include "misc.h" | 1 | #include "misc.h" |
2 | 2 | ||
3 | #ifdef CONFIG_EARLY_PRINTK | ||
4 | |||
5 | static unsigned long fs; | 3 | static unsigned long fs; |
6 | static inline void set_fs(unsigned long seg) | 4 | static inline void set_fs(unsigned long seg) |
7 | { | 5 | { |
@@ -21,5 +19,3 @@ int cmdline_find_option_bool(const char *option) | |||
21 | { | 19 | { |
22 | return __cmdline_find_option_bool(real_mode->hdr.cmd_line_ptr, option); | 20 | return __cmdline_find_option_bool(real_mode->hdr.cmd_line_ptr, option); |
23 | } | 21 | } |
24 | |||
25 | #endif | ||
diff --git a/arch/x86/boot/compressed/early_serial_console.c b/arch/x86/boot/compressed/early_serial_console.c index d3d003cb548..261e81fb958 100644 --- a/arch/x86/boot/compressed/early_serial_console.c +++ b/arch/x86/boot/compressed/early_serial_console.c | |||
@@ -1,9 +1,5 @@ | |||
1 | #include "misc.h" | 1 | #include "misc.h" |
2 | 2 | ||
3 | #ifdef CONFIG_EARLY_PRINTK | ||
4 | |||
5 | int early_serial_base; | 3 | int early_serial_base; |
6 | 4 | ||
7 | #include "../early_serial_console.c" | 5 | #include "../early_serial_console.c" |
8 | |||
9 | #endif | ||
diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c deleted file mode 100644 index b1942e22276..00000000000 --- a/arch/x86/boot/compressed/eboot.c +++ /dev/null | |||
@@ -1,1251 +0,0 @@ | |||
1 | /* ----------------------------------------------------------------------- | ||
2 | * | ||
3 | * Copyright 2011 Intel Corporation; author Matt Fleming | ||
4 | * | ||
5 | * This file is part of the Linux kernel, and is made available under | ||
6 | * the terms of the GNU General Public License version 2. | ||
7 | * | ||
8 | * ----------------------------------------------------------------------- */ | ||
9 | |||
10 | #include <linux/efi.h> | ||
11 | #include <linux/pci.h> | ||
12 | #include <asm/efi.h> | ||
13 | #include <asm/setup.h> | ||
14 | #include <asm/desc.h> | ||
15 | |||
16 | #undef memcpy /* Use memcpy from misc.c */ | ||
17 | |||
18 | #include "eboot.h" | ||
19 | |||
20 | static efi_system_table_t *sys_table; | ||
21 | |||
22 | static void efi_printk(char *str) | ||
23 | { | ||
24 | char *s8; | ||
25 | |||
26 | for (s8 = str; *s8; s8++) { | ||
27 | struct efi_simple_text_output_protocol *out; | ||
28 | efi_char16_t ch[2] = { 0 }; | ||
29 | |||
30 | ch[0] = *s8; | ||
31 | out = (struct efi_simple_text_output_protocol *)sys_table->con_out; | ||
32 | |||
33 | if (*s8 == '\n') { | ||
34 | efi_char16_t nl[2] = { '\r', 0 }; | ||
35 | efi_call_phys2(out->output_string, out, nl); | ||
36 | } | ||
37 | |||
38 | efi_call_phys2(out->output_string, out, ch); | ||
39 | } | ||
40 | } | ||
41 | |||
42 | static efi_status_t __get_map(efi_memory_desc_t **map, unsigned long *map_size, | ||
43 | unsigned long *desc_size) | ||
44 | { | ||
45 | efi_memory_desc_t *m = NULL; | ||
46 | efi_status_t status; | ||
47 | unsigned long key; | ||
48 | u32 desc_version; | ||
49 | |||
50 | *map_size = sizeof(*m) * 32; | ||
51 | again: | ||
52 | /* | ||
53 | * Add an additional efi_memory_desc_t because we're doing an | ||
54 | * allocation which may be in a new descriptor region. | ||
55 | */ | ||
56 | *map_size += sizeof(*m); | ||
57 | status = efi_call_phys3(sys_table->boottime->allocate_pool, | ||
58 | EFI_LOADER_DATA, *map_size, (void **)&m); | ||
59 | if (status != EFI_SUCCESS) | ||
60 | goto fail; | ||
61 | |||
62 | status = efi_call_phys5(sys_table->boottime->get_memory_map, map_size, | ||
63 | m, &key, desc_size, &desc_version); | ||
64 | if (status == EFI_BUFFER_TOO_SMALL) { | ||
65 | efi_call_phys1(sys_table->boottime->free_pool, m); | ||
66 | goto again; | ||
67 | } | ||
68 | |||
69 | if (status != EFI_SUCCESS) | ||
70 | efi_call_phys1(sys_table->boottime->free_pool, m); | ||
71 | |||
72 | fail: | ||
73 | *map = m; | ||
74 | return status; | ||
75 | } | ||
76 | |||
77 | /* | ||
78 | * Allocate at the highest possible address that is not above 'max'. | ||
79 | */ | ||
80 | static efi_status_t high_alloc(unsigned long size, unsigned long align, | ||
81 | unsigned long *addr, unsigned long max) | ||
82 | { | ||
83 | unsigned long map_size, desc_size; | ||
84 | efi_memory_desc_t *map; | ||
85 | efi_status_t status; | ||
86 | unsigned long nr_pages; | ||
87 | u64 max_addr = 0; | ||
88 | int i; | ||
89 | |||
90 | status = __get_map(&map, &map_size, &desc_size); | ||
91 | if (status != EFI_SUCCESS) | ||
92 | goto fail; | ||
93 | |||
94 | nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; | ||
95 | again: | ||
96 | for (i = 0; i < map_size / desc_size; i++) { | ||
97 | efi_memory_desc_t *desc; | ||
98 | unsigned long m = (unsigned long)map; | ||
99 | u64 start, end; | ||
100 | |||
101 | desc = (efi_memory_desc_t *)(m + (i * desc_size)); | ||
102 | if (desc->type != EFI_CONVENTIONAL_MEMORY) | ||
103 | continue; | ||
104 | |||
105 | if (desc->num_pages < nr_pages) | ||
106 | continue; | ||
107 | |||
108 | start = desc->phys_addr; | ||
109 | end = start + desc->num_pages * (1UL << EFI_PAGE_SHIFT); | ||
110 | |||
111 | if ((start + size) > end || (start + size) > max) | ||
112 | continue; | ||
113 | |||
114 | if (end - size > max) | ||
115 | end = max; | ||
116 | |||
117 | if (round_down(end - size, align) < start) | ||
118 | continue; | ||
119 | |||
120 | start = round_down(end - size, align); | ||
121 | |||
122 | /* | ||
123 | * Don't allocate at 0x0. It will confuse code that | ||
124 | * checks pointers against NULL. | ||
125 | */ | ||
126 | if (start == 0x0) | ||
127 | continue; | ||
128 | |||
129 | if (start > max_addr) | ||
130 | max_addr = start; | ||
131 | } | ||
132 | |||
133 | if (!max_addr) | ||
134 | status = EFI_NOT_FOUND; | ||
135 | else { | ||
136 | status = efi_call_phys4(sys_table->boottime->allocate_pages, | ||
137 | EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA, | ||
138 | nr_pages, &max_addr); | ||
139 | if (status != EFI_SUCCESS) { | ||
140 | max = max_addr; | ||
141 | max_addr = 0; | ||
142 | goto again; | ||
143 | } | ||
144 | |||
145 | *addr = max_addr; | ||
146 | } | ||
147 | |||
148 | free_pool: | ||
149 | efi_call_phys1(sys_table->boottime->free_pool, map); | ||
150 | |||
151 | fail: | ||
152 | return status; | ||
153 | } | ||
154 | |||
155 | /* | ||
156 | * Allocate at the lowest possible address. | ||
157 | */ | ||
158 | static efi_status_t low_alloc(unsigned long size, unsigned long align, | ||
159 | unsigned long *addr) | ||
160 | { | ||
161 | unsigned long map_size, desc_size; | ||
162 | efi_memory_desc_t *map; | ||
163 | efi_status_t status; | ||
164 | unsigned long nr_pages; | ||
165 | int i; | ||
166 | |||
167 | status = __get_map(&map, &map_size, &desc_size); | ||
168 | if (status != EFI_SUCCESS) | ||
169 | goto fail; | ||
170 | |||
171 | nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; | ||
172 | for (i = 0; i < map_size / desc_size; i++) { | ||
173 | efi_memory_desc_t *desc; | ||
174 | unsigned long m = (unsigned long)map; | ||
175 | u64 start, end; | ||
176 | |||
177 | desc = (efi_memory_desc_t *)(m + (i * desc_size)); | ||
178 | |||
179 | if (desc->type != EFI_CONVENTIONAL_MEMORY) | ||
180 | continue; | ||
181 | |||
182 | if (desc->num_pages < nr_pages) | ||
183 | continue; | ||
184 | |||
185 | start = desc->phys_addr; | ||
186 | end = start + desc->num_pages * (1UL << EFI_PAGE_SHIFT); | ||
187 | |||
188 | /* | ||
189 | * Don't allocate at 0x0. It will confuse code that | ||
190 | * checks pointers against NULL. Skip the first 8 | ||
191 | * bytes so we start at a nice even number. | ||
192 | */ | ||
193 | if (start == 0x0) | ||
194 | start += 8; | ||
195 | |||
196 | start = round_up(start, align); | ||
197 | if ((start + size) > end) | ||
198 | continue; | ||
199 | |||
200 | status = efi_call_phys4(sys_table->boottime->allocate_pages, | ||
201 | EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA, | ||
202 | nr_pages, &start); | ||
203 | if (status == EFI_SUCCESS) { | ||
204 | *addr = start; | ||
205 | break; | ||
206 | } | ||
207 | } | ||
208 | |||
209 | if (i == map_size / desc_size) | ||
210 | status = EFI_NOT_FOUND; | ||
211 | |||
212 | free_pool: | ||
213 | efi_call_phys1(sys_table->boottime->free_pool, map); | ||
214 | fail: | ||
215 | return status; | ||
216 | } | ||
217 | |||
218 | static void low_free(unsigned long size, unsigned long addr) | ||
219 | { | ||
220 | unsigned long nr_pages; | ||
221 | |||
222 | nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; | ||
223 | efi_call_phys2(sys_table->boottime->free_pages, addr, size); | ||
224 | } | ||
225 | |||
226 | static void find_bits(unsigned long mask, u8 *pos, u8 *size) | ||
227 | { | ||
228 | u8 first, len; | ||
229 | |||
230 | first = 0; | ||
231 | len = 0; | ||
232 | |||
233 | if (mask) { | ||
234 | while (!(mask & 0x1)) { | ||
235 | mask = mask >> 1; | ||
236 | first++; | ||
237 | } | ||
238 | |||
239 | while (mask & 0x1) { | ||
240 | mask = mask >> 1; | ||
241 | len++; | ||
242 | } | ||
243 | } | ||
244 | |||
245 | *pos = first; | ||
246 | *size = len; | ||
247 | } | ||
248 | |||
249 | static efi_status_t setup_efi_pci(struct boot_params *params) | ||
250 | { | ||
251 | efi_pci_io_protocol *pci; | ||
252 | efi_status_t status; | ||
253 | void **pci_handle; | ||
254 | efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID; | ||
255 | unsigned long nr_pci, size = 0; | ||
256 | int i; | ||
257 | struct setup_data *data; | ||
258 | |||
259 | data = (struct setup_data *)params->hdr.setup_data; | ||
260 | |||
261 | while (data && data->next) | ||
262 | data = (struct setup_data *)data->next; | ||
263 | |||
264 | status = efi_call_phys5(sys_table->boottime->locate_handle, | ||
265 | EFI_LOCATE_BY_PROTOCOL, &pci_proto, | ||
266 | NULL, &size, pci_handle); | ||
267 | |||
268 | if (status == EFI_BUFFER_TOO_SMALL) { | ||
269 | status = efi_call_phys3(sys_table->boottime->allocate_pool, | ||
270 | EFI_LOADER_DATA, size, &pci_handle); | ||
271 | |||
272 | if (status != EFI_SUCCESS) | ||
273 | return status; | ||
274 | |||
275 | status = efi_call_phys5(sys_table->boottime->locate_handle, | ||
276 | EFI_LOCATE_BY_PROTOCOL, &pci_proto, | ||
277 | NULL, &size, pci_handle); | ||
278 | } | ||
279 | |||
280 | if (status != EFI_SUCCESS) | ||
281 | goto free_handle; | ||
282 | |||
283 | nr_pci = size / sizeof(void *); | ||
284 | for (i = 0; i < nr_pci; i++) { | ||
285 | void *h = pci_handle[i]; | ||
286 | uint64_t attributes; | ||
287 | struct pci_setup_rom *rom; | ||
288 | |||
289 | status = efi_call_phys3(sys_table->boottime->handle_protocol, | ||
290 | h, &pci_proto, &pci); | ||
291 | |||
292 | if (status != EFI_SUCCESS) | ||
293 | continue; | ||
294 | |||
295 | if (!pci) | ||
296 | continue; | ||
297 | |||
298 | status = efi_call_phys4(pci->attributes, pci, | ||
299 | EfiPciIoAttributeOperationGet, 0, | ||
300 | &attributes); | ||
301 | |||
302 | if (status != EFI_SUCCESS) | ||
303 | continue; | ||
304 | |||
305 | if (!attributes & EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM) | ||
306 | continue; | ||
307 | |||
308 | if (!pci->romimage || !pci->romsize) | ||
309 | continue; | ||
310 | |||
311 | size = pci->romsize + sizeof(*rom); | ||
312 | |||
313 | status = efi_call_phys3(sys_table->boottime->allocate_pool, | ||
314 | EFI_LOADER_DATA, size, &rom); | ||
315 | |||
316 | if (status != EFI_SUCCESS) | ||
317 | continue; | ||
318 | |||
319 | rom->data.type = SETUP_PCI; | ||
320 | rom->data.len = size - sizeof(struct setup_data); | ||
321 | rom->data.next = 0; | ||
322 | rom->pcilen = pci->romsize; | ||
323 | |||
324 | status = efi_call_phys5(pci->pci.read, pci, | ||
325 | EfiPciIoWidthUint16, PCI_VENDOR_ID, | ||
326 | 1, &(rom->vendor)); | ||
327 | |||
328 | if (status != EFI_SUCCESS) | ||
329 | goto free_struct; | ||
330 | |||
331 | status = efi_call_phys5(pci->pci.read, pci, | ||
332 | EfiPciIoWidthUint16, PCI_DEVICE_ID, | ||
333 | 1, &(rom->devid)); | ||
334 | |||
335 | if (status != EFI_SUCCESS) | ||
336 | goto free_struct; | ||
337 | |||
338 | status = efi_call_phys5(pci->get_location, pci, | ||
339 | &(rom->segment), &(rom->bus), | ||
340 | &(rom->device), &(rom->function)); | ||
341 | |||
342 | if (status != EFI_SUCCESS) | ||
343 | goto free_struct; | ||
344 | |||
345 | memcpy(rom->romdata, pci->romimage, pci->romsize); | ||
346 | |||
347 | if (data) | ||
348 | data->next = (uint64_t)rom; | ||
349 | else | ||
350 | params->hdr.setup_data = (uint64_t)rom; | ||
351 | |||
352 | data = (struct setup_data *)rom; | ||
353 | |||
354 | continue; | ||
355 | free_struct: | ||
356 | efi_call_phys1(sys_table->boottime->free_pool, rom); | ||
357 | } | ||
358 | |||
359 | free_handle: | ||
360 | efi_call_phys1(sys_table->boottime->free_pool, pci_handle); | ||
361 | return status; | ||
362 | } | ||
363 | |||
364 | /* | ||
365 | * See if we have Graphics Output Protocol | ||
366 | */ | ||
367 | static efi_status_t setup_gop(struct screen_info *si, efi_guid_t *proto, | ||
368 | unsigned long size) | ||
369 | { | ||
370 | struct efi_graphics_output_protocol *gop, *first_gop; | ||
371 | struct efi_pixel_bitmask pixel_info; | ||
372 | unsigned long nr_gops; | ||
373 | efi_status_t status; | ||
374 | void **gop_handle; | ||
375 | u16 width, height; | ||
376 | u32 fb_base, fb_size; | ||
377 | u32 pixels_per_scan_line; | ||
378 | int pixel_format; | ||
379 | int i; | ||
380 | |||
381 | status = efi_call_phys3(sys_table->boottime->allocate_pool, | ||
382 | EFI_LOADER_DATA, size, &gop_handle); | ||
383 | if (status != EFI_SUCCESS) | ||
384 | return status; | ||
385 | |||
386 | status = efi_call_phys5(sys_table->boottime->locate_handle, | ||
387 | EFI_LOCATE_BY_PROTOCOL, proto, | ||
388 | NULL, &size, gop_handle); | ||
389 | if (status != EFI_SUCCESS) | ||
390 | goto free_handle; | ||
391 | |||
392 | first_gop = NULL; | ||
393 | |||
394 | nr_gops = size / sizeof(void *); | ||
395 | for (i = 0; i < nr_gops; i++) { | ||
396 | struct efi_graphics_output_mode_info *info; | ||
397 | efi_guid_t conout_proto = EFI_CONSOLE_OUT_DEVICE_GUID; | ||
398 | bool conout_found = false; | ||
399 | void *dummy; | ||
400 | void *h = gop_handle[i]; | ||
401 | |||
402 | status = efi_call_phys3(sys_table->boottime->handle_protocol, | ||
403 | h, proto, &gop); | ||
404 | if (status != EFI_SUCCESS) | ||
405 | continue; | ||
406 | |||
407 | status = efi_call_phys3(sys_table->boottime->handle_protocol, | ||
408 | h, &conout_proto, &dummy); | ||
409 | |||
410 | if (status == EFI_SUCCESS) | ||
411 | conout_found = true; | ||
412 | |||
413 | status = efi_call_phys4(gop->query_mode, gop, | ||
414 | gop->mode->mode, &size, &info); | ||
415 | if (status == EFI_SUCCESS && (!first_gop || conout_found)) { | ||
416 | /* | ||
417 | * Systems that use the UEFI Console Splitter may | ||
418 | * provide multiple GOP devices, not all of which are | ||
419 | * backed by real hardware. The workaround is to search | ||
420 | * for a GOP implementing the ConOut protocol, and if | ||
421 | * one isn't found, to just fall back to the first GOP. | ||
422 | */ | ||
423 | width = info->horizontal_resolution; | ||
424 | height = info->vertical_resolution; | ||
425 | fb_base = gop->mode->frame_buffer_base; | ||
426 | fb_size = gop->mode->frame_buffer_size; | ||
427 | pixel_format = info->pixel_format; | ||
428 | pixel_info = info->pixel_information; | ||
429 | pixels_per_scan_line = info->pixels_per_scan_line; | ||
430 | |||
431 | /* | ||
432 | * Once we've found a GOP supporting ConOut, | ||
433 | * don't bother looking any further. | ||
434 | */ | ||
435 | if (conout_found) | ||
436 | break; | ||
437 | |||
438 | first_gop = gop; | ||
439 | } | ||
440 | } | ||
441 | |||
442 | /* Did we find any GOPs? */ | ||
443 | if (!first_gop) | ||
444 | goto free_handle; | ||
445 | |||
446 | /* EFI framebuffer */ | ||
447 | si->orig_video_isVGA = VIDEO_TYPE_EFI; | ||
448 | |||
449 | si->lfb_width = width; | ||
450 | si->lfb_height = height; | ||
451 | si->lfb_base = fb_base; | ||
452 | si->pages = 1; | ||
453 | |||
454 | if (pixel_format == PIXEL_RGB_RESERVED_8BIT_PER_COLOR) { | ||
455 | si->lfb_depth = 32; | ||
456 | si->lfb_linelength = pixels_per_scan_line * 4; | ||
457 | si->red_size = 8; | ||
458 | si->red_pos = 0; | ||
459 | si->green_size = 8; | ||
460 | si->green_pos = 8; | ||
461 | si->blue_size = 8; | ||
462 | si->blue_pos = 16; | ||
463 | si->rsvd_size = 8; | ||
464 | si->rsvd_pos = 24; | ||
465 | } else if (pixel_format == PIXEL_BGR_RESERVED_8BIT_PER_COLOR) { | ||
466 | si->lfb_depth = 32; | ||
467 | si->lfb_linelength = pixels_per_scan_line * 4; | ||
468 | si->red_size = 8; | ||
469 | si->red_pos = 16; | ||
470 | si->green_size = 8; | ||
471 | si->green_pos = 8; | ||
472 | si->blue_size = 8; | ||
473 | si->blue_pos = 0; | ||
474 | si->rsvd_size = 8; | ||
475 | si->rsvd_pos = 24; | ||
476 | } else if (pixel_format == PIXEL_BIT_MASK) { | ||
477 | find_bits(pixel_info.red_mask, &si->red_pos, &si->red_size); | ||
478 | find_bits(pixel_info.green_mask, &si->green_pos, | ||
479 | &si->green_size); | ||
480 | find_bits(pixel_info.blue_mask, &si->blue_pos, &si->blue_size); | ||
481 | find_bits(pixel_info.reserved_mask, &si->rsvd_pos, | ||
482 | &si->rsvd_size); | ||
483 | si->lfb_depth = si->red_size + si->green_size + | ||
484 | si->blue_size + si->rsvd_size; | ||
485 | si->lfb_linelength = (pixels_per_scan_line * si->lfb_depth) / 8; | ||
486 | } else { | ||
487 | si->lfb_depth = 4; | ||
488 | si->lfb_linelength = si->lfb_width / 2; | ||
489 | si->red_size = 0; | ||
490 | si->red_pos = 0; | ||
491 | si->green_size = 0; | ||
492 | si->green_pos = 0; | ||
493 | si->blue_size = 0; | ||
494 | si->blue_pos = 0; | ||
495 | si->rsvd_size = 0; | ||
496 | si->rsvd_pos = 0; | ||
497 | } | ||
498 | |||
499 | si->lfb_size = si->lfb_linelength * si->lfb_height; | ||
500 | |||
501 | si->capabilities |= VIDEO_CAPABILITY_SKIP_QUIRKS; | ||
502 | |||
503 | free_handle: | ||
504 | efi_call_phys1(sys_table->boottime->free_pool, gop_handle); | ||
505 | return status; | ||
506 | } | ||
507 | |||
508 | /* | ||
509 | * See if we have Universal Graphics Adapter (UGA) protocol | ||
510 | */ | ||
511 | static efi_status_t setup_uga(struct screen_info *si, efi_guid_t *uga_proto, | ||
512 | unsigned long size) | ||
513 | { | ||
514 | struct efi_uga_draw_protocol *uga, *first_uga; | ||
515 | unsigned long nr_ugas; | ||
516 | efi_status_t status; | ||
517 | u32 width, height; | ||
518 | void **uga_handle = NULL; | ||
519 | int i; | ||
520 | |||
521 | status = efi_call_phys3(sys_table->boottime->allocate_pool, | ||
522 | EFI_LOADER_DATA, size, &uga_handle); | ||
523 | if (status != EFI_SUCCESS) | ||
524 | return status; | ||
525 | |||
526 | status = efi_call_phys5(sys_table->boottime->locate_handle, | ||
527 | EFI_LOCATE_BY_PROTOCOL, uga_proto, | ||
528 | NULL, &size, uga_handle); | ||
529 | if (status != EFI_SUCCESS) | ||
530 | goto free_handle; | ||
531 | |||
532 | first_uga = NULL; | ||
533 | |||
534 | nr_ugas = size / sizeof(void *); | ||
535 | for (i = 0; i < nr_ugas; i++) { | ||
536 | efi_guid_t pciio_proto = EFI_PCI_IO_PROTOCOL_GUID; | ||
537 | void *handle = uga_handle[i]; | ||
538 | u32 w, h, depth, refresh; | ||
539 | void *pciio; | ||
540 | |||
541 | status = efi_call_phys3(sys_table->boottime->handle_protocol, | ||
542 | handle, uga_proto, &uga); | ||
543 | if (status != EFI_SUCCESS) | ||
544 | continue; | ||
545 | |||
546 | efi_call_phys3(sys_table->boottime->handle_protocol, | ||
547 | handle, &pciio_proto, &pciio); | ||
548 | |||
549 | status = efi_call_phys5(uga->get_mode, uga, &w, &h, | ||
550 | &depth, &refresh); | ||
551 | if (status == EFI_SUCCESS && (!first_uga || pciio)) { | ||
552 | width = w; | ||
553 | height = h; | ||
554 | |||
555 | /* | ||
556 | * Once we've found a UGA supporting PCIIO, | ||
557 | * don't bother looking any further. | ||
558 | */ | ||
559 | if (pciio) | ||
560 | break; | ||
561 | |||
562 | first_uga = uga; | ||
563 | } | ||
564 | } | ||
565 | |||
566 | if (!first_uga) | ||
567 | goto free_handle; | ||
568 | |||
569 | /* EFI framebuffer */ | ||
570 | si->orig_video_isVGA = VIDEO_TYPE_EFI; | ||
571 | |||
572 | si->lfb_depth = 32; | ||
573 | si->lfb_width = width; | ||
574 | si->lfb_height = height; | ||
575 | |||
576 | si->red_size = 8; | ||
577 | si->red_pos = 16; | ||
578 | si->green_size = 8; | ||
579 | si->green_pos = 8; | ||
580 | si->blue_size = 8; | ||
581 | si->blue_pos = 0; | ||
582 | si->rsvd_size = 8; | ||
583 | si->rsvd_pos = 24; | ||
584 | |||
585 | |||
586 | free_handle: | ||
587 | efi_call_phys1(sys_table->boottime->free_pool, uga_handle); | ||
588 | return status; | ||
589 | } | ||
590 | |||
591 | void setup_graphics(struct boot_params *boot_params) | ||
592 | { | ||
593 | efi_guid_t graphics_proto = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; | ||
594 | struct screen_info *si; | ||
595 | efi_guid_t uga_proto = EFI_UGA_PROTOCOL_GUID; | ||
596 | efi_status_t status; | ||
597 | unsigned long size; | ||
598 | void **gop_handle = NULL; | ||
599 | void **uga_handle = NULL; | ||
600 | |||
601 | si = &boot_params->screen_info; | ||
602 | memset(si, 0, sizeof(*si)); | ||
603 | |||
604 | size = 0; | ||
605 | status = efi_call_phys5(sys_table->boottime->locate_handle, | ||
606 | EFI_LOCATE_BY_PROTOCOL, &graphics_proto, | ||
607 | NULL, &size, gop_handle); | ||
608 | if (status == EFI_BUFFER_TOO_SMALL) | ||
609 | status = setup_gop(si, &graphics_proto, size); | ||
610 | |||
611 | if (status != EFI_SUCCESS) { | ||
612 | size = 0; | ||
613 | status = efi_call_phys5(sys_table->boottime->locate_handle, | ||
614 | EFI_LOCATE_BY_PROTOCOL, &uga_proto, | ||
615 | NULL, &size, uga_handle); | ||
616 | if (status == EFI_BUFFER_TOO_SMALL) | ||
617 | setup_uga(si, &uga_proto, size); | ||
618 | } | ||
619 | } | ||
620 | |||
621 | struct initrd { | ||
622 | efi_file_handle_t *handle; | ||
623 | u64 size; | ||
624 | }; | ||
625 | |||
626 | /* | ||
627 | * Check the cmdline for a LILO-style initrd= arguments. | ||
628 | * | ||
629 | * We only support loading an initrd from the same filesystem as the | ||
630 | * kernel image. | ||
631 | */ | ||
632 | static efi_status_t handle_ramdisks(efi_loaded_image_t *image, | ||
633 | struct setup_header *hdr) | ||
634 | { | ||
635 | struct initrd *initrds; | ||
636 | unsigned long initrd_addr; | ||
637 | efi_guid_t fs_proto = EFI_FILE_SYSTEM_GUID; | ||
638 | u64 initrd_total; | ||
639 | efi_file_io_interface_t *io; | ||
640 | efi_file_handle_t *fh; | ||
641 | efi_status_t status; | ||
642 | int nr_initrds; | ||
643 | char *str; | ||
644 | int i, j, k; | ||
645 | |||
646 | initrd_addr = 0; | ||
647 | initrd_total = 0; | ||
648 | |||
649 | str = (char *)(unsigned long)hdr->cmd_line_ptr; | ||
650 | |||
651 | j = 0; /* See close_handles */ | ||
652 | |||
653 | if (!str || !*str) | ||
654 | return EFI_SUCCESS; | ||
655 | |||
656 | for (nr_initrds = 0; *str; nr_initrds++) { | ||
657 | str = strstr(str, "initrd="); | ||
658 | if (!str) | ||
659 | break; | ||
660 | |||
661 | str += 7; | ||
662 | |||
663 | /* Skip any leading slashes */ | ||
664 | while (*str == '/' || *str == '\\') | ||
665 | str++; | ||
666 | |||
667 | while (*str && *str != ' ' && *str != '\n') | ||
668 | str++; | ||
669 | } | ||
670 | |||
671 | if (!nr_initrds) | ||
672 | return EFI_SUCCESS; | ||
673 | |||
674 | status = efi_call_phys3(sys_table->boottime->allocate_pool, | ||
675 | EFI_LOADER_DATA, | ||
676 | nr_initrds * sizeof(*initrds), | ||
677 | &initrds); | ||
678 | if (status != EFI_SUCCESS) { | ||
679 | efi_printk("Failed to alloc mem for initrds\n"); | ||
680 | goto fail; | ||
681 | } | ||
682 | |||
683 | str = (char *)(unsigned long)hdr->cmd_line_ptr; | ||
684 | for (i = 0; i < nr_initrds; i++) { | ||
685 | struct initrd *initrd; | ||
686 | efi_file_handle_t *h; | ||
687 | efi_file_info_t *info; | ||
688 | efi_char16_t filename_16[256]; | ||
689 | unsigned long info_sz; | ||
690 | efi_guid_t info_guid = EFI_FILE_INFO_ID; | ||
691 | efi_char16_t *p; | ||
692 | u64 file_sz; | ||
693 | |||
694 | str = strstr(str, "initrd="); | ||
695 | if (!str) | ||
696 | break; | ||
697 | |||
698 | str += 7; | ||
699 | |||
700 | initrd = &initrds[i]; | ||
701 | p = filename_16; | ||
702 | |||
703 | /* Skip any leading slashes */ | ||
704 | while (*str == '/' || *str == '\\') | ||
705 | str++; | ||
706 | |||
707 | while (*str && *str != ' ' && *str != '\n') { | ||
708 | if ((u8 *)p >= (u8 *)filename_16 + sizeof(filename_16)) | ||
709 | break; | ||
710 | |||
711 | *p++ = *str++; | ||
712 | } | ||
713 | |||
714 | *p = '\0'; | ||
715 | |||
716 | /* Only open the volume once. */ | ||
717 | if (!i) { | ||
718 | efi_boot_services_t *boottime; | ||
719 | |||
720 | boottime = sys_table->boottime; | ||
721 | |||
722 | status = efi_call_phys3(boottime->handle_protocol, | ||
723 | image->device_handle, &fs_proto, &io); | ||
724 | if (status != EFI_SUCCESS) { | ||
725 | efi_printk("Failed to handle fs_proto\n"); | ||
726 | goto free_initrds; | ||
727 | } | ||
728 | |||
729 | status = efi_call_phys2(io->open_volume, io, &fh); | ||
730 | if (status != EFI_SUCCESS) { | ||
731 | efi_printk("Failed to open volume\n"); | ||
732 | goto free_initrds; | ||
733 | } | ||
734 | } | ||
735 | |||
736 | status = efi_call_phys5(fh->open, fh, &h, filename_16, | ||
737 | EFI_FILE_MODE_READ, (u64)0); | ||
738 | if (status != EFI_SUCCESS) { | ||
739 | efi_printk("Failed to open initrd file\n"); | ||
740 | goto close_handles; | ||
741 | } | ||
742 | |||
743 | initrd->handle = h; | ||
744 | |||
745 | info_sz = 0; | ||
746 | status = efi_call_phys4(h->get_info, h, &info_guid, | ||
747 | &info_sz, NULL); | ||
748 | if (status != EFI_BUFFER_TOO_SMALL) { | ||
749 | efi_printk("Failed to get initrd info size\n"); | ||
750 | goto close_handles; | ||
751 | } | ||
752 | |||
753 | grow: | ||
754 | status = efi_call_phys3(sys_table->boottime->allocate_pool, | ||
755 | EFI_LOADER_DATA, info_sz, &info); | ||
756 | if (status != EFI_SUCCESS) { | ||
757 | efi_printk("Failed to alloc mem for initrd info\n"); | ||
758 | goto close_handles; | ||
759 | } | ||
760 | |||
761 | status = efi_call_phys4(h->get_info, h, &info_guid, | ||
762 | &info_sz, info); | ||
763 | if (status == EFI_BUFFER_TOO_SMALL) { | ||
764 | efi_call_phys1(sys_table->boottime->free_pool, info); | ||
765 | goto grow; | ||
766 | } | ||
767 | |||
768 | file_sz = info->file_size; | ||
769 | efi_call_phys1(sys_table->boottime->free_pool, info); | ||
770 | |||
771 | if (status != EFI_SUCCESS) { | ||
772 | efi_printk("Failed to get initrd info\n"); | ||
773 | goto close_handles; | ||
774 | } | ||
775 | |||
776 | initrd->size = file_sz; | ||
777 | initrd_total += file_sz; | ||
778 | } | ||
779 | |||
780 | if (initrd_total) { | ||
781 | unsigned long addr; | ||
782 | |||
783 | /* | ||
784 | * Multiple initrd's need to be at consecutive | ||
785 | * addresses in memory, so allocate enough memory for | ||
786 | * all the initrd's. | ||
787 | */ | ||
788 | status = high_alloc(initrd_total, 0x1000, | ||
789 | &initrd_addr, hdr->initrd_addr_max); | ||
790 | if (status != EFI_SUCCESS) { | ||
791 | efi_printk("Failed to alloc highmem for initrds\n"); | ||
792 | goto close_handles; | ||
793 | } | ||
794 | |||
795 | /* We've run out of free low memory. */ | ||
796 | if (initrd_addr > hdr->initrd_addr_max) { | ||
797 | efi_printk("We've run out of free low memory\n"); | ||
798 | status = EFI_INVALID_PARAMETER; | ||
799 | goto free_initrd_total; | ||
800 | } | ||
801 | |||
802 | addr = initrd_addr; | ||
803 | for (j = 0; j < nr_initrds; j++) { | ||
804 | u64 size; | ||
805 | |||
806 | size = initrds[j].size; | ||
807 | while (size) { | ||
808 | u64 chunksize; | ||
809 | if (size > EFI_READ_CHUNK_SIZE) | ||
810 | chunksize = EFI_READ_CHUNK_SIZE; | ||
811 | else | ||
812 | chunksize = size; | ||
813 | status = efi_call_phys3(fh->read, | ||
814 | initrds[j].handle, | ||
815 | &chunksize, addr); | ||
816 | if (status != EFI_SUCCESS) { | ||
817 | efi_printk("Failed to read initrd\n"); | ||
818 | goto free_initrd_total; | ||
819 | } | ||
820 | addr += chunksize; | ||
821 | size -= chunksize; | ||
822 | } | ||
823 | |||
824 | efi_call_phys1(fh->close, initrds[j].handle); | ||
825 | } | ||
826 | |||
827 | } | ||
828 | |||
829 | efi_call_phys1(sys_table->boottime->free_pool, initrds); | ||
830 | |||
831 | hdr->ramdisk_image = initrd_addr; | ||
832 | hdr->ramdisk_size = initrd_total; | ||
833 | |||
834 | return status; | ||
835 | |||
836 | free_initrd_total: | ||
837 | low_free(initrd_total, initrd_addr); | ||
838 | |||
839 | close_handles: | ||
840 | for (k = j; k < i; k++) | ||
841 | efi_call_phys1(fh->close, initrds[k].handle); | ||
842 | free_initrds: | ||
843 | efi_call_phys1(sys_table->boottime->free_pool, initrds); | ||
844 | fail: | ||
845 | hdr->ramdisk_image = 0; | ||
846 | hdr->ramdisk_size = 0; | ||
847 | |||
848 | return status; | ||
849 | } | ||
850 | |||
851 | /* | ||
852 | * Because the x86 boot code expects to be passed a boot_params we | ||
853 | * need to create one ourselves (usually the bootloader would create | ||
854 | * one for us). | ||
855 | */ | ||
856 | struct boot_params *make_boot_params(void *handle, efi_system_table_t *_table) | ||
857 | { | ||
858 | struct boot_params *boot_params; | ||
859 | struct sys_desc_table *sdt; | ||
860 | struct apm_bios_info *bi; | ||
861 | struct setup_header *hdr; | ||
862 | struct efi_info *efi; | ||
863 | efi_loaded_image_t *image; | ||
864 | void *options; | ||
865 | u32 load_options_size; | ||
866 | efi_guid_t proto = LOADED_IMAGE_PROTOCOL_GUID; | ||
867 | int options_size = 0; | ||
868 | efi_status_t status; | ||
869 | unsigned long cmdline; | ||
870 | u16 *s2; | ||
871 | u8 *s1; | ||
872 | int i; | ||
873 | |||
874 | sys_table = _table; | ||
875 | |||
876 | /* Check if we were booted by the EFI firmware */ | ||
877 | if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) | ||
878 | return NULL; | ||
879 | |||
880 | status = efi_call_phys3(sys_table->boottime->handle_protocol, | ||
881 | handle, &proto, (void *)&image); | ||
882 | if (status != EFI_SUCCESS) { | ||
883 | efi_printk("Failed to get handle for LOADED_IMAGE_PROTOCOL\n"); | ||
884 | return NULL; | ||
885 | } | ||
886 | |||
887 | status = low_alloc(0x4000, 1, (unsigned long *)&boot_params); | ||
888 | if (status != EFI_SUCCESS) { | ||
889 | efi_printk("Failed to alloc lowmem for boot params\n"); | ||
890 | return NULL; | ||
891 | } | ||
892 | |||
893 | memset(boot_params, 0x0, 0x4000); | ||
894 | |||
895 | hdr = &boot_params->hdr; | ||
896 | efi = &boot_params->efi_info; | ||
897 | bi = &boot_params->apm_bios_info; | ||
898 | sdt = &boot_params->sys_desc_table; | ||
899 | |||
900 | /* Copy the second sector to boot_params */ | ||
901 | memcpy(&hdr->jump, image->image_base + 512, 512); | ||
902 | |||
903 | /* | ||
904 | * Fill out some of the header fields ourselves because the | ||
905 | * EFI firmware loader doesn't load the first sector. | ||
906 | */ | ||
907 | hdr->root_flags = 1; | ||
908 | hdr->vid_mode = 0xffff; | ||
909 | hdr->boot_flag = 0xAA55; | ||
910 | |||
911 | hdr->code32_start = (__u64)(unsigned long)image->image_base; | ||
912 | |||
913 | hdr->type_of_loader = 0x21; | ||
914 | |||
915 | /* Convert unicode cmdline to ascii */ | ||
916 | options = image->load_options; | ||
917 | load_options_size = image->load_options_size / 2; /* ASCII */ | ||
918 | cmdline = 0; | ||
919 | s2 = (u16 *)options; | ||
920 | |||
921 | if (s2) { | ||
922 | while (*s2 && *s2 != '\n' && options_size < load_options_size) { | ||
923 | s2++; | ||
924 | options_size++; | ||
925 | } | ||
926 | |||
927 | if (options_size) { | ||
928 | if (options_size > hdr->cmdline_size) | ||
929 | options_size = hdr->cmdline_size; | ||
930 | |||
931 | options_size++; /* NUL termination */ | ||
932 | |||
933 | status = low_alloc(options_size, 1, &cmdline); | ||
934 | if (status != EFI_SUCCESS) { | ||
935 | efi_printk("Failed to alloc mem for cmdline\n"); | ||
936 | goto fail; | ||
937 | } | ||
938 | |||
939 | s1 = (u8 *)(unsigned long)cmdline; | ||
940 | s2 = (u16 *)options; | ||
941 | |||
942 | for (i = 0; i < options_size - 1; i++) | ||
943 | *s1++ = *s2++; | ||
944 | |||
945 | *s1 = '\0'; | ||
946 | } | ||
947 | } | ||
948 | |||
949 | hdr->cmd_line_ptr = cmdline; | ||
950 | |||
951 | hdr->ramdisk_image = 0; | ||
952 | hdr->ramdisk_size = 0; | ||
953 | |||
954 | /* Clear APM BIOS info */ | ||
955 | memset(bi, 0, sizeof(*bi)); | ||
956 | |||
957 | memset(sdt, 0, sizeof(*sdt)); | ||
958 | |||
959 | status = handle_ramdisks(image, hdr); | ||
960 | if (status != EFI_SUCCESS) | ||
961 | goto fail2; | ||
962 | |||
963 | return boot_params; | ||
964 | fail2: | ||
965 | if (options_size) | ||
966 | low_free(options_size, hdr->cmd_line_ptr); | ||
967 | fail: | ||
968 | low_free(0x4000, (unsigned long)boot_params); | ||
969 | return NULL; | ||
970 | } | ||
971 | |||
972 | static efi_status_t exit_boot(struct boot_params *boot_params, | ||
973 | void *handle) | ||
974 | { | ||
975 | struct efi_info *efi = &boot_params->efi_info; | ||
976 | struct e820entry *e820_map = &boot_params->e820_map[0]; | ||
977 | struct e820entry *prev = NULL; | ||
978 | unsigned long size, key, desc_size, _size; | ||
979 | efi_memory_desc_t *mem_map; | ||
980 | efi_status_t status; | ||
981 | __u32 desc_version; | ||
982 | u8 nr_entries; | ||
983 | int i; | ||
984 | |||
985 | size = sizeof(*mem_map) * 32; | ||
986 | |||
987 | again: | ||
988 | size += sizeof(*mem_map); | ||
989 | _size = size; | ||
990 | status = low_alloc(size, 1, (unsigned long *)&mem_map); | ||
991 | if (status != EFI_SUCCESS) | ||
992 | return status; | ||
993 | |||
994 | status = efi_call_phys5(sys_table->boottime->get_memory_map, &size, | ||
995 | mem_map, &key, &desc_size, &desc_version); | ||
996 | if (status == EFI_BUFFER_TOO_SMALL) { | ||
997 | low_free(_size, (unsigned long)mem_map); | ||
998 | goto again; | ||
999 | } | ||
1000 | |||
1001 | if (status != EFI_SUCCESS) | ||
1002 | goto free_mem_map; | ||
1003 | |||
1004 | memcpy(&efi->efi_loader_signature, EFI_LOADER_SIGNATURE, sizeof(__u32)); | ||
1005 | efi->efi_systab = (unsigned long)sys_table; | ||
1006 | efi->efi_memdesc_size = desc_size; | ||
1007 | efi->efi_memdesc_version = desc_version; | ||
1008 | efi->efi_memmap = (unsigned long)mem_map; | ||
1009 | efi->efi_memmap_size = size; | ||
1010 | |||
1011 | #ifdef CONFIG_X86_64 | ||
1012 | efi->efi_systab_hi = (unsigned long)sys_table >> 32; | ||
1013 | efi->efi_memmap_hi = (unsigned long)mem_map >> 32; | ||
1014 | #endif | ||
1015 | |||
1016 | /* Might as well exit boot services now */ | ||
1017 | status = efi_call_phys2(sys_table->boottime->exit_boot_services, | ||
1018 | handle, key); | ||
1019 | if (status != EFI_SUCCESS) | ||
1020 | goto free_mem_map; | ||
1021 | |||
1022 | /* Historic? */ | ||
1023 | boot_params->alt_mem_k = 32 * 1024; | ||
1024 | |||
1025 | /* | ||
1026 | * Convert the EFI memory map to E820. | ||
1027 | */ | ||
1028 | nr_entries = 0; | ||
1029 | for (i = 0; i < size / desc_size; i++) { | ||
1030 | efi_memory_desc_t *d; | ||
1031 | unsigned int e820_type = 0; | ||
1032 | unsigned long m = (unsigned long)mem_map; | ||
1033 | |||
1034 | d = (efi_memory_desc_t *)(m + (i * desc_size)); | ||
1035 | switch (d->type) { | ||
1036 | case EFI_RESERVED_TYPE: | ||
1037 | case EFI_RUNTIME_SERVICES_CODE: | ||
1038 | case EFI_RUNTIME_SERVICES_DATA: | ||
1039 | case EFI_MEMORY_MAPPED_IO: | ||
1040 | case EFI_MEMORY_MAPPED_IO_PORT_SPACE: | ||
1041 | case EFI_PAL_CODE: | ||
1042 | e820_type = E820_RESERVED; | ||
1043 | break; | ||
1044 | |||
1045 | case EFI_UNUSABLE_MEMORY: | ||
1046 | e820_type = E820_UNUSABLE; | ||
1047 | break; | ||
1048 | |||
1049 | case EFI_ACPI_RECLAIM_MEMORY: | ||
1050 | e820_type = E820_ACPI; | ||
1051 | break; | ||
1052 | |||
1053 | case EFI_LOADER_CODE: | ||
1054 | case EFI_LOADER_DATA: | ||
1055 | case EFI_BOOT_SERVICES_CODE: | ||
1056 | case EFI_BOOT_SERVICES_DATA: | ||
1057 | case EFI_CONVENTIONAL_MEMORY: | ||
1058 | e820_type = E820_RAM; | ||
1059 | break; | ||
1060 | |||
1061 | case EFI_ACPI_MEMORY_NVS: | ||
1062 | e820_type = E820_NVS; | ||
1063 | break; | ||
1064 | |||
1065 | default: | ||
1066 | continue; | ||
1067 | } | ||
1068 | |||
1069 | /* Merge adjacent mappings */ | ||
1070 | if (prev && prev->type == e820_type && | ||
1071 | (prev->addr + prev->size) == d->phys_addr) | ||
1072 | prev->size += d->num_pages << 12; | ||
1073 | else { | ||
1074 | e820_map->addr = d->phys_addr; | ||
1075 | e820_map->size = d->num_pages << 12; | ||
1076 | e820_map->type = e820_type; | ||
1077 | prev = e820_map++; | ||
1078 | nr_entries++; | ||
1079 | } | ||
1080 | } | ||
1081 | |||
1082 | boot_params->e820_entries = nr_entries; | ||
1083 | |||
1084 | return EFI_SUCCESS; | ||
1085 | |||
1086 | free_mem_map: | ||
1087 | low_free(_size, (unsigned long)mem_map); | ||
1088 | return status; | ||
1089 | } | ||
1090 | |||
1091 | static efi_status_t relocate_kernel(struct setup_header *hdr) | ||
1092 | { | ||
1093 | unsigned long start, nr_pages; | ||
1094 | efi_status_t status; | ||
1095 | |||
1096 | /* | ||
1097 | * The EFI firmware loader could have placed the kernel image | ||
1098 | * anywhere in memory, but the kernel has various restrictions | ||
1099 | * on the max physical address it can run at. Attempt to move | ||
1100 | * the kernel to boot_params.pref_address, or as low as | ||
1101 | * possible. | ||
1102 | */ | ||
1103 | start = hdr->pref_address; | ||
1104 | nr_pages = round_up(hdr->init_size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; | ||
1105 | |||
1106 | status = efi_call_phys4(sys_table->boottime->allocate_pages, | ||
1107 | EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA, | ||
1108 | nr_pages, &start); | ||
1109 | if (status != EFI_SUCCESS) { | ||
1110 | status = low_alloc(hdr->init_size, hdr->kernel_alignment, | ||
1111 | &start); | ||
1112 | if (status != EFI_SUCCESS) | ||
1113 | efi_printk("Failed to alloc mem for kernel\n"); | ||
1114 | } | ||
1115 | |||
1116 | if (status == EFI_SUCCESS) | ||
1117 | memcpy((void *)start, (void *)(unsigned long)hdr->code32_start, | ||
1118 | hdr->init_size); | ||
1119 | |||
1120 | hdr->pref_address = hdr->code32_start; | ||
1121 | hdr->code32_start = (__u32)start; | ||
1122 | |||
1123 | return status; | ||
1124 | } | ||
1125 | |||
1126 | /* | ||
1127 | * On success we return a pointer to a boot_params structure, and NULL | ||
1128 | * on failure. | ||
1129 | */ | ||
1130 | struct boot_params *efi_main(void *handle, efi_system_table_t *_table, | ||
1131 | struct boot_params *boot_params) | ||
1132 | { | ||
1133 | struct desc_ptr *gdt, *idt; | ||
1134 | efi_loaded_image_t *image; | ||
1135 | struct setup_header *hdr = &boot_params->hdr; | ||
1136 | efi_status_t status; | ||
1137 | struct desc_struct *desc; | ||
1138 | |||
1139 | sys_table = _table; | ||
1140 | |||
1141 | /* Check if we were booted by the EFI firmware */ | ||
1142 | if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) | ||
1143 | goto fail; | ||
1144 | |||
1145 | setup_graphics(boot_params); | ||
1146 | |||
1147 | setup_efi_pci(boot_params); | ||
1148 | |||
1149 | status = efi_call_phys3(sys_table->boottime->allocate_pool, | ||
1150 | EFI_LOADER_DATA, sizeof(*gdt), | ||
1151 | (void **)&gdt); | ||
1152 | if (status != EFI_SUCCESS) { | ||
1153 | efi_printk("Failed to alloc mem for gdt structure\n"); | ||
1154 | goto fail; | ||
1155 | } | ||
1156 | |||
1157 | gdt->size = 0x800; | ||
1158 | status = low_alloc(gdt->size, 8, (unsigned long *)&gdt->address); | ||
1159 | if (status != EFI_SUCCESS) { | ||
1160 | efi_printk("Failed to alloc mem for gdt\n"); | ||
1161 | goto fail; | ||
1162 | } | ||
1163 | |||
1164 | status = efi_call_phys3(sys_table->boottime->allocate_pool, | ||
1165 | EFI_LOADER_DATA, sizeof(*idt), | ||
1166 | (void **)&idt); | ||
1167 | if (status != EFI_SUCCESS) { | ||
1168 | efi_printk("Failed to alloc mem for idt structure\n"); | ||
1169 | goto fail; | ||
1170 | } | ||
1171 | |||
1172 | idt->size = 0; | ||
1173 | idt->address = 0; | ||
1174 | |||
1175 | /* | ||
1176 | * If the kernel isn't already loaded at the preferred load | ||
1177 | * address, relocate it. | ||
1178 | */ | ||
1179 | if (hdr->pref_address != hdr->code32_start) { | ||
1180 | status = relocate_kernel(hdr); | ||
1181 | |||
1182 | if (status != EFI_SUCCESS) | ||
1183 | goto fail; | ||
1184 | } | ||
1185 | |||
1186 | status = exit_boot(boot_params, handle); | ||
1187 | if (status != EFI_SUCCESS) | ||
1188 | goto fail; | ||
1189 | |||
1190 | memset((char *)gdt->address, 0x0, gdt->size); | ||
1191 | desc = (struct desc_struct *)gdt->address; | ||
1192 | |||
1193 | /* The first GDT is a dummy and the second is unused. */ | ||
1194 | desc += 2; | ||
1195 | |||
1196 | desc->limit0 = 0xffff; | ||
1197 | desc->base0 = 0x0000; | ||
1198 | desc->base1 = 0x0000; | ||
1199 | desc->type = SEG_TYPE_CODE | SEG_TYPE_EXEC_READ; | ||
1200 | desc->s = DESC_TYPE_CODE_DATA; | ||
1201 | desc->dpl = 0; | ||
1202 | desc->p = 1; | ||
1203 | desc->limit = 0xf; | ||
1204 | desc->avl = 0; | ||
1205 | desc->l = 0; | ||
1206 | desc->d = SEG_OP_SIZE_32BIT; | ||
1207 | desc->g = SEG_GRANULARITY_4KB; | ||
1208 | desc->base2 = 0x00; | ||
1209 | |||
1210 | desc++; | ||
1211 | desc->limit0 = 0xffff; | ||
1212 | desc->base0 = 0x0000; | ||
1213 | desc->base1 = 0x0000; | ||
1214 | desc->type = SEG_TYPE_DATA | SEG_TYPE_READ_WRITE; | ||
1215 | desc->s = DESC_TYPE_CODE_DATA; | ||
1216 | desc->dpl = 0; | ||
1217 | desc->p = 1; | ||
1218 | desc->limit = 0xf; | ||
1219 | desc->avl = 0; | ||
1220 | desc->l = 0; | ||
1221 | desc->d = SEG_OP_SIZE_32BIT; | ||
1222 | desc->g = SEG_GRANULARITY_4KB; | ||
1223 | desc->base2 = 0x00; | ||
1224 | |||
1225 | #ifdef CONFIG_X86_64 | ||
1226 | /* Task segment value */ | ||
1227 | desc++; | ||
1228 | desc->limit0 = 0x0000; | ||
1229 | desc->base0 = 0x0000; | ||
1230 | desc->base1 = 0x0000; | ||
1231 | desc->type = SEG_TYPE_TSS; | ||
1232 | desc->s = 0; | ||
1233 | desc->dpl = 0; | ||
1234 | desc->p = 1; | ||
1235 | desc->limit = 0x0; | ||
1236 | desc->avl = 0; | ||
1237 | desc->l = 0; | ||
1238 | desc->d = 0; | ||
1239 | desc->g = SEG_GRANULARITY_4KB; | ||
1240 | desc->base2 = 0x00; | ||
1241 | #endif /* CONFIG_X86_64 */ | ||
1242 | |||
1243 | asm volatile ("lidt %0" : : "m" (*idt)); | ||
1244 | asm volatile ("lgdt %0" : : "m" (*gdt)); | ||
1245 | |||
1246 | asm volatile("cli"); | ||
1247 | |||
1248 | return boot_params; | ||
1249 | fail: | ||
1250 | return NULL; | ||
1251 | } | ||
diff --git a/arch/x86/boot/compressed/eboot.h b/arch/x86/boot/compressed/eboot.h deleted file mode 100644 index e5b0a8f91c5..00000000000 --- a/arch/x86/boot/compressed/eboot.h +++ /dev/null | |||
@@ -1,71 +0,0 @@ | |||
1 | #ifndef BOOT_COMPRESSED_EBOOT_H | ||
2 | #define BOOT_COMPRESSED_EBOOT_H | ||
3 | |||
4 | #define SEG_TYPE_DATA (0 << 3) | ||
5 | #define SEG_TYPE_READ_WRITE (1 << 1) | ||
6 | #define SEG_TYPE_CODE (1 << 3) | ||
7 | #define SEG_TYPE_EXEC_READ (1 << 1) | ||
8 | #define SEG_TYPE_TSS ((1 << 3) | (1 << 0)) | ||
9 | #define SEG_OP_SIZE_32BIT (1 << 0) | ||
10 | #define SEG_GRANULARITY_4KB (1 << 0) | ||
11 | |||
12 | #define DESC_TYPE_CODE_DATA (1 << 0) | ||
13 | |||
14 | #define EFI_PAGE_SIZE (1UL << EFI_PAGE_SHIFT) | ||
15 | #define EFI_READ_CHUNK_SIZE (1024 * 1024) | ||
16 | |||
17 | #define EFI_CONSOLE_OUT_DEVICE_GUID \ | ||
18 | EFI_GUID(0xd3b36f2c, 0xd551, 0x11d4, 0x9a, 0x46, 0x0, 0x90, 0x27, \ | ||
19 | 0x3f, 0xc1, 0x4d) | ||
20 | |||
21 | #define PIXEL_RGB_RESERVED_8BIT_PER_COLOR 0 | ||
22 | #define PIXEL_BGR_RESERVED_8BIT_PER_COLOR 1 | ||
23 | #define PIXEL_BIT_MASK 2 | ||
24 | #define PIXEL_BLT_ONLY 3 | ||
25 | #define PIXEL_FORMAT_MAX 4 | ||
26 | |||
27 | struct efi_pixel_bitmask { | ||
28 | u32 red_mask; | ||
29 | u32 green_mask; | ||
30 | u32 blue_mask; | ||
31 | u32 reserved_mask; | ||
32 | }; | ||
33 | |||
34 | struct efi_graphics_output_mode_info { | ||
35 | u32 version; | ||
36 | u32 horizontal_resolution; | ||
37 | u32 vertical_resolution; | ||
38 | int pixel_format; | ||
39 | struct efi_pixel_bitmask pixel_information; | ||
40 | u32 pixels_per_scan_line; | ||
41 | } __packed; | ||
42 | |||
43 | struct efi_graphics_output_protocol_mode { | ||
44 | u32 max_mode; | ||
45 | u32 mode; | ||
46 | unsigned long info; | ||
47 | unsigned long size_of_info; | ||
48 | u64 frame_buffer_base; | ||
49 | unsigned long frame_buffer_size; | ||
50 | } __packed; | ||
51 | |||
52 | struct efi_graphics_output_protocol { | ||
53 | void *query_mode; | ||
54 | unsigned long set_mode; | ||
55 | unsigned long blt; | ||
56 | struct efi_graphics_output_protocol_mode *mode; | ||
57 | }; | ||
58 | |||
59 | struct efi_uga_draw_protocol { | ||
60 | void *get_mode; | ||
61 | void *set_mode; | ||
62 | void *blt; | ||
63 | }; | ||
64 | |||
65 | struct efi_simple_text_output_protocol { | ||
66 | void *reset; | ||
67 | void *output_string; | ||
68 | void *test_string; | ||
69 | }; | ||
70 | |||
71 | #endif /* BOOT_COMPRESSED_EBOOT_H */ | ||
diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S deleted file mode 100644 index a53440e81d5..00000000000 --- a/arch/x86/boot/compressed/efi_stub_32.S +++ /dev/null | |||
@@ -1,86 +0,0 @@ | |||
1 | /* | ||
2 | * EFI call stub for IA32. | ||
3 | * | ||
4 | * This stub allows us to make EFI calls in physical mode with interrupts | ||
5 | * turned off. Note that this implementation is different from the one in | ||
6 | * arch/x86/platform/efi/efi_stub_32.S because we're _already_ in physical | ||
7 | * mode at this point. | ||
8 | */ | ||
9 | |||
10 | #include <linux/linkage.h> | ||
11 | #include <asm/page_types.h> | ||
12 | |||
13 | /* | ||
14 | * efi_call_phys(void *, ...) is a function with variable parameters. | ||
15 | * All the callers of this function assure that all the parameters are 4-bytes. | ||
16 | */ | ||
17 | |||
18 | /* | ||
19 | * In gcc calling convention, EBX, ESP, EBP, ESI and EDI are all callee save. | ||
20 | * So we'd better save all of them at the beginning of this function and restore | ||
21 | * at the end no matter how many we use, because we can not assure EFI runtime | ||
22 | * service functions will comply with gcc calling convention, too. | ||
23 | */ | ||
24 | |||
25 | .text | ||
26 | ENTRY(efi_call_phys) | ||
27 | /* | ||
28 | * 0. The function can only be called in Linux kernel. So CS has been | ||
29 | * set to 0x0010, DS and SS have been set to 0x0018. In EFI, I found | ||
30 | * the values of these registers are the same. And, the corresponding | ||
31 | * GDT entries are identical. So I will do nothing about segment reg | ||
32 | * and GDT, but change GDT base register in prelog and epilog. | ||
33 | */ | ||
34 | |||
35 | /* | ||
36 | * 1. Because we haven't been relocated by this point we need to | ||
37 | * use relative addressing. | ||
38 | */ | ||
39 | call 1f | ||
40 | 1: popl %edx | ||
41 | subl $1b, %edx | ||
42 | |||
43 | /* | ||
44 | * 2. Now on the top of stack is the return | ||
45 | * address in the caller of efi_call_phys(), then parameter 1, | ||
46 | * parameter 2, ..., param n. To make things easy, we save the return | ||
47 | * address of efi_call_phys in a global variable. | ||
48 | */ | ||
49 | popl %ecx | ||
50 | movl %ecx, saved_return_addr(%edx) | ||
51 | /* get the function pointer into ECX*/ | ||
52 | popl %ecx | ||
53 | movl %ecx, efi_rt_function_ptr(%edx) | ||
54 | |||
55 | /* | ||
56 | * 3. Call the physical function. | ||
57 | */ | ||
58 | call *%ecx | ||
59 | |||
60 | /* | ||
61 | * 4. Balance the stack. And because EAX contain the return value, | ||
62 | * we'd better not clobber it. We need to calculate our address | ||
63 | * again because %ecx and %edx are not preserved across EFI function | ||
64 | * calls. | ||
65 | */ | ||
66 | call 1f | ||
67 | 1: popl %edx | ||
68 | subl $1b, %edx | ||
69 | |||
70 | movl efi_rt_function_ptr(%edx), %ecx | ||
71 | pushl %ecx | ||
72 | |||
73 | /* | ||
74 | * 10. Push the saved return address onto the stack and return. | ||
75 | */ | ||
76 | movl saved_return_addr(%edx), %ecx | ||
77 | pushl %ecx | ||
78 | ret | ||
79 | ENDPROC(efi_call_phys) | ||
80 | .previous | ||
81 | |||
82 | .data | ||
83 | saved_return_addr: | ||
84 | .long 0 | ||
85 | efi_rt_function_ptr: | ||
86 | .long 0 | ||
diff --git a/arch/x86/boot/compressed/efi_stub_64.S b/arch/x86/boot/compressed/efi_stub_64.S deleted file mode 100644 index cedc60de86e..00000000000 --- a/arch/x86/boot/compressed/efi_stub_64.S +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | #include "../../platform/efi/efi_stub_64.S" | ||
diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S index aa4aaf1b238..67a655a39ce 100644 --- a/arch/x86/boot/compressed/head_32.S +++ b/arch/x86/boot/compressed/head_32.S | |||
@@ -32,46 +32,6 @@ | |||
32 | 32 | ||
33 | __HEAD | 33 | __HEAD |
34 | ENTRY(startup_32) | 34 | ENTRY(startup_32) |
35 | #ifdef CONFIG_EFI_STUB | ||
36 | jmp preferred_addr | ||
37 | |||
38 | .balign 0x10 | ||
39 | /* | ||
40 | * We don't need the return address, so set up the stack so | ||
41 | * efi_main() can find its arugments. | ||
42 | */ | ||
43 | add $0x4, %esp | ||
44 | |||
45 | call make_boot_params | ||
46 | cmpl $0, %eax | ||
47 | je 1f | ||
48 | movl 0x4(%esp), %esi | ||
49 | movl (%esp), %ecx | ||
50 | pushl %eax | ||
51 | pushl %esi | ||
52 | pushl %ecx | ||
53 | |||
54 | .org 0x30,0x90 | ||
55 | call efi_main | ||
56 | cmpl $0, %eax | ||
57 | movl %eax, %esi | ||
58 | jne 2f | ||
59 | 1: | ||
60 | /* EFI init failed, so hang. */ | ||
61 | hlt | ||
62 | jmp 1b | ||
63 | 2: | ||
64 | call 3f | ||
65 | 3: | ||
66 | popl %eax | ||
67 | subl $3b, %eax | ||
68 | subl BP_pref_address(%esi), %eax | ||
69 | add BP_code32_start(%esi), %eax | ||
70 | leal preferred_addr(%eax), %eax | ||
71 | jmp *%eax | ||
72 | |||
73 | preferred_addr: | ||
74 | #endif | ||
75 | cld | 35 | cld |
76 | /* | 36 | /* |
77 | * Test KEEP_SEGMENTS flag to see if the bootloader is asking | 37 | * Test KEEP_SEGMENTS flag to see if the bootloader is asking |
diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index 2c4b171eec3..35af09d13dc 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S | |||
@@ -199,46 +199,6 @@ ENTRY(startup_64) | |||
199 | * an identity mapped page table being provied that maps our | 199 | * an identity mapped page table being provied that maps our |
200 | * entire text+data+bss and hopefully all of memory. | 200 | * entire text+data+bss and hopefully all of memory. |
201 | */ | 201 | */ |
202 | #ifdef CONFIG_EFI_STUB | ||
203 | /* | ||
204 | * The entry point for the PE/COFF executable is 0x210, so only | ||
205 | * legacy boot loaders will execute this jmp. | ||
206 | */ | ||
207 | jmp preferred_addr | ||
208 | |||
209 | .org 0x210 | ||
210 | mov %rcx, %rdi | ||
211 | mov %rdx, %rsi | ||
212 | pushq %rdi | ||
213 | pushq %rsi | ||
214 | call make_boot_params | ||
215 | cmpq $0,%rax | ||
216 | je 1f | ||
217 | mov %rax, %rdx | ||
218 | popq %rsi | ||
219 | popq %rdi | ||
220 | |||
221 | .org 0x230,0x90 | ||
222 | call efi_main | ||
223 | movq %rax,%rsi | ||
224 | cmpq $0,%rax | ||
225 | jne 2f | ||
226 | 1: | ||
227 | /* EFI init failed, so hang. */ | ||
228 | hlt | ||
229 | jmp 1b | ||
230 | 2: | ||
231 | call 3f | ||
232 | 3: | ||
233 | popq %rax | ||
234 | subq $3b, %rax | ||
235 | subq BP_pref_address(%rsi), %rax | ||
236 | add BP_code32_start(%esi), %eax | ||
237 | leaq preferred_addr(%rax), %rax | ||
238 | jmp *%rax | ||
239 | |||
240 | preferred_addr: | ||
241 | #endif | ||
242 | 202 | ||
243 | /* Setup data segments. */ | 203 | /* Setup data segments. */ |
244 | xorl %eax, %eax | 204 | xorl %eax, %eax |
diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c index 88f7ff6da40..3a19d04cebe 100644 --- a/arch/x86/boot/compressed/misc.c +++ b/arch/x86/boot/compressed/misc.c | |||
@@ -108,6 +108,8 @@ static void error(char *m); | |||
108 | * This is set up by the setup-routine at boot-time | 108 | * This is set up by the setup-routine at boot-time |
109 | */ | 109 | */ |
110 | struct boot_params *real_mode; /* Pointer to real-mode data */ | 110 | struct boot_params *real_mode; /* Pointer to real-mode data */ |
111 | static int quiet; | ||
112 | static int debug; | ||
111 | 113 | ||
112 | void *memset(void *s, int c, size_t n); | 114 | void *memset(void *s, int c, size_t n); |
113 | void *memcpy(void *dest, const void *src, size_t n); | 115 | void *memcpy(void *dest, const void *src, size_t n); |
@@ -168,11 +170,15 @@ static void serial_putchar(int ch) | |||
168 | outb(ch, early_serial_base + TXR); | 170 | outb(ch, early_serial_base + TXR); |
169 | } | 171 | } |
170 | 172 | ||
171 | void __putstr(const char *s) | 173 | void __putstr(int error, const char *s) |
172 | { | 174 | { |
173 | int x, y, pos; | 175 | int x, y, pos; |
174 | char c; | 176 | char c; |
175 | 177 | ||
178 | #ifndef CONFIG_X86_VERBOSE_BOOTUP | ||
179 | if (!error) | ||
180 | return; | ||
181 | #endif | ||
176 | if (early_serial_base) { | 182 | if (early_serial_base) { |
177 | const char *str = s; | 183 | const char *str = s; |
178 | while (*str) { | 184 | while (*str) { |
@@ -259,9 +265,9 @@ void *memcpy(void *dest, const void *src, size_t n) | |||
259 | 265 | ||
260 | static void error(char *x) | 266 | static void error(char *x) |
261 | { | 267 | { |
262 | error_putstr("\n\n"); | 268 | __putstr(1, "\n\n"); |
263 | error_putstr(x); | 269 | __putstr(1, x); |
264 | error_putstr("\n\n -- System halted"); | 270 | __putstr(1, "\n\n -- System halted"); |
265 | 271 | ||
266 | while (1) | 272 | while (1) |
267 | asm("hlt"); | 273 | asm("hlt"); |
@@ -288,7 +294,8 @@ static void parse_elf(void *output) | |||
288 | return; | 294 | return; |
289 | } | 295 | } |
290 | 296 | ||
291 | debug_putstr("Parsing ELF... "); | 297 | if (!quiet) |
298 | putstr("Parsing ELF... "); | ||
292 | 299 | ||
293 | phdrs = malloc(sizeof(*phdrs) * ehdr.e_phnum); | 300 | phdrs = malloc(sizeof(*phdrs) * ehdr.e_phnum); |
294 | if (!phdrs) | 301 | if (!phdrs) |
@@ -314,8 +321,6 @@ static void parse_elf(void *output) | |||
314 | default: /* Ignore other PT_* */ break; | 321 | default: /* Ignore other PT_* */ break; |
315 | } | 322 | } |
316 | } | 323 | } |
317 | |||
318 | free(phdrs); | ||
319 | } | 324 | } |
320 | 325 | ||
321 | asmlinkage void decompress_kernel(void *rmode, memptr heap, | 326 | asmlinkage void decompress_kernel(void *rmode, memptr heap, |
@@ -325,6 +330,11 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap, | |||
325 | { | 330 | { |
326 | real_mode = rmode; | 331 | real_mode = rmode; |
327 | 332 | ||
333 | if (cmdline_find_option_bool("quiet")) | ||
334 | quiet = 1; | ||
335 | if (cmdline_find_option_bool("debug")) | ||
336 | debug = 1; | ||
337 | |||
328 | if (real_mode->screen_info.orig_video_mode == 7) { | 338 | if (real_mode->screen_info.orig_video_mode == 7) { |
329 | vidmem = (char *) 0xb0000; | 339 | vidmem = (char *) 0xb0000; |
330 | vidport = 0x3b4; | 340 | vidport = 0x3b4; |
@@ -337,7 +347,8 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap, | |||
337 | cols = real_mode->screen_info.orig_video_cols; | 347 | cols = real_mode->screen_info.orig_video_cols; |
338 | 348 | ||
339 | console_init(); | 349 | console_init(); |
340 | debug_putstr("early console in decompress_kernel\n"); | 350 | if (debug) |
351 | putstr("early console in decompress_kernel\n"); | ||
341 | 352 | ||
342 | free_mem_ptr = heap; /* Heap */ | 353 | free_mem_ptr = heap; /* Heap */ |
343 | free_mem_end_ptr = heap + BOOT_HEAP_SIZE; | 354 | free_mem_end_ptr = heap + BOOT_HEAP_SIZE; |
@@ -356,9 +367,11 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap, | |||
356 | error("Wrong destination address"); | 367 | error("Wrong destination address"); |
357 | #endif | 368 | #endif |
358 | 369 | ||
359 | debug_putstr("\nDecompressing Linux... "); | 370 | if (!quiet) |
371 | putstr("\nDecompressing Linux... "); | ||
360 | decompress(input_data, input_len, NULL, NULL, output, NULL, error); | 372 | decompress(input_data, input_len, NULL, NULL, output, NULL, error); |
361 | parse_elf(output); | 373 | parse_elf(output); |
362 | debug_putstr("done.\nBooting the kernel.\n"); | 374 | if (!quiet) |
375 | putstr("done.\nBooting the kernel.\n"); | ||
363 | return; | 376 | return; |
364 | } | 377 | } |
diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h index 0e6dc0ee0ee..3f19c81a620 100644 --- a/arch/x86/boot/compressed/misc.h +++ b/arch/x86/boot/compressed/misc.h | |||
@@ -24,21 +24,9 @@ | |||
24 | 24 | ||
25 | /* misc.c */ | 25 | /* misc.c */ |
26 | extern struct boot_params *real_mode; /* Pointer to real-mode data */ | 26 | extern struct boot_params *real_mode; /* Pointer to real-mode data */ |
27 | void __putstr(const char *s); | 27 | void __putstr(int error, const char *s); |
28 | #define error_putstr(__x) __putstr(__x) | 28 | #define putstr(__x) __putstr(0, __x) |
29 | 29 | #define puts(__x) __putstr(0, __x) | |
30 | #ifdef CONFIG_X86_VERBOSE_BOOTUP | ||
31 | |||
32 | #define debug_putstr(__x) __putstr(__x) | ||
33 | |||
34 | #else | ||
35 | |||
36 | static inline void debug_putstr(const char *s) | ||
37 | { } | ||
38 | |||
39 | #endif | ||
40 | |||
41 | #ifdef CONFIG_EARLY_PRINTK | ||
42 | 30 | ||
43 | /* cmdline.c */ | 31 | /* cmdline.c */ |
44 | int cmdline_find_option(const char *option, char *buffer, int bufsize); | 32 | int cmdline_find_option(const char *option, char *buffer, int bufsize); |
@@ -48,13 +36,4 @@ int cmdline_find_option_bool(const char *option); | |||
48 | extern int early_serial_base; | 36 | extern int early_serial_base; |
49 | void console_init(void); | 37 | void console_init(void); |
50 | 38 | ||
51 | #else | ||
52 | |||
53 | /* early_serial_console.c */ | ||
54 | static const int early_serial_base; | ||
55 | static inline void console_init(void) | ||
56 | { } | ||
57 | |||
58 | #endif | ||
59 | |||
60 | #endif | 39 | #endif |
diff --git a/arch/x86/boot/compressed/mkpiggy.c b/arch/x86/boot/compressed/mkpiggy.c index 958a641483d..46a82388243 100644 --- a/arch/x86/boot/compressed/mkpiggy.c +++ b/arch/x86/boot/compressed/mkpiggy.c | |||
@@ -29,7 +29,14 @@ | |||
29 | #include <stdio.h> | 29 | #include <stdio.h> |
30 | #include <string.h> | 30 | #include <string.h> |
31 | #include <inttypes.h> | 31 | #include <inttypes.h> |
32 | #include <tools/le_byteshift.h> | 32 | |
33 | static uint32_t getle32(const void *p) | ||
34 | { | ||
35 | const uint8_t *cp = p; | ||
36 | |||
37 | return (uint32_t)cp[0] + ((uint32_t)cp[1] << 8) + | ||
38 | ((uint32_t)cp[2] << 16) + ((uint32_t)cp[3] << 24); | ||
39 | } | ||
33 | 40 | ||
34 | int main(int argc, char *argv[]) | 41 | int main(int argc, char *argv[]) |
35 | { | 42 | { |
@@ -62,7 +69,7 @@ int main(int argc, char *argv[]) | |||
62 | } | 69 | } |
63 | 70 | ||
64 | ilen = ftell(f); | 71 | ilen = ftell(f); |
65 | olen = get_unaligned_le32(&olen); | 72 | olen = getle32(&olen); |
66 | fclose(f); | 73 | fclose(f); |
67 | 74 | ||
68 | /* | 75 | /* |
diff --git a/arch/x86/boot/compressed/string.c b/arch/x86/boot/compressed/string.c index ffb9c5c9d74..19b3e693cd7 100644 --- a/arch/x86/boot/compressed/string.c +++ b/arch/x86/boot/compressed/string.c | |||
@@ -1,11 +1,2 @@ | |||
1 | #include "misc.h" | 1 | #include "misc.h" |
2 | |||
3 | int memcmp(const void *s1, const void *s2, size_t len) | ||
4 | { | ||
5 | u8 diff; | ||
6 | asm("repe; cmpsb; setnz %0" | ||
7 | : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len)); | ||
8 | return diff; | ||
9 | } | ||
10 | |||
11 | #include "../string.c" | 2 | #include "../string.c" |