summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/syslinux/files/0002-memscan-build-a-linked-list-of-memory-scanners.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/syslinux/files/0002-memscan-build-a-linked-list-of-memory-scanners.patch')
-rw-r--r--meta/recipes-devtools/syslinux/files/0002-memscan-build-a-linked-list-of-memory-scanners.patch450
1 files changed, 450 insertions, 0 deletions
diff --git a/meta/recipes-devtools/syslinux/files/0002-memscan-build-a-linked-list-of-memory-scanners.patch b/meta/recipes-devtools/syslinux/files/0002-memscan-build-a-linked-list-of-memory-scanners.patch
new file mode 100644
index 0000000000..48d3955910
--- /dev/null
+++ b/meta/recipes-devtools/syslinux/files/0002-memscan-build-a-linked-list-of-memory-scanners.patch
@@ -0,0 +1,450 @@
1Upstream-Status: Backport [787d7e568fe08d7080d2cd03cd9ee27c327eca67]
2Signed-off-by: Jonathan Liu <net147@gmail.com>
3
4From 2e05f34c0c5bc0144bb203a169009dfb6837b4e3 Mon Sep 17 00:00:00 2001
5From: Matt Fleming <matt.fleming@intel.com>
6Date: Wed, 17 Jul 2013 12:15:16 +0100
7Subject: [PATCH 2/4] memscan: build a linked list of memory scanners
8
9By registering memory scanners at runtime we can support multiple memory
10scanner functions, which helps us to isolate them and keep things
11modular, only registering them for specific platform/derivative
12combinations. This is preparation for adding a memory scanner that is
13specific to PXELINUX on bios and understands when the memory region
14occupied by the PXE stack can be reused.
15
16Signed-off-by: Matt Fleming <matt.fleming@intel.com>
17
18Conflicts:
19 com32/include/syslinux/memscan.h
20 com32/lib/syslinux/memscan.c
21---
22 com32/include/syslinux/firmware.h | 4 +-
23 com32/include/syslinux/memscan.h | 14 +++-
24 com32/lib/syslinux/memscan.c | 143 +++++++-------------------------------
25 core/bios.c | 125 ++++++++++++++++++++++++++++++++-
26 efi/main.c | 14 ++--
27 5 files changed, 173 insertions(+), 127 deletions(-)
28
29diff --git a/com32/include/syslinux/firmware.h b/com32/include/syslinux/firmware.h
30index 4a43c86..6cc06a0 100644
31--- a/com32/include/syslinux/firmware.h
32+++ b/com32/include/syslinux/firmware.h
33@@ -1,7 +1,8 @@
34 #ifndef _SYSLINUX_FIRMWARE_H
35 #define _SYSLINUX_FIRMWARE_H
36
37-#include <syslinux/memscan.h>
38+#include <inttypes.h>
39+#include <stdbool.h>
40
41 struct term_state;
42
43@@ -42,7 +43,6 @@ struct mem_ops {
44 void *(*malloc)(size_t, enum heap, size_t);
45 void *(*realloc)(void *, size_t);
46 void (*free)(void *);
47- int (*scan_memory)(scan_memory_callback_t, void *);
48 };
49
50 struct initramfs;
51diff --git a/com32/include/syslinux/memscan.h b/com32/include/syslinux/memscan.h
52index c3ebf84..ab78e28 100644
53--- a/com32/include/syslinux/memscan.h
54+++ b/com32/include/syslinux/memscan.h
55@@ -29,11 +29,19 @@
56 #ifndef _SYSLINUX_MEMSCAN_H
57 #define _SYSLINUX_MEMSCAN_H
58
59-#include <stdbool.h>
60+#include <linux/list.h>
61 #include <syslinux/movebits.h> /* addr_t */
62
63-typedef int (*scan_memory_callback_t) (void *, addr_t, addr_t, bool);
64+typedef int (*scan_memory_callback_t) (void *, addr_t, addr_t,
65+ enum syslinux_memmap_types type);
66+
67+struct syslinux_memscan {
68+ int (*func)(scan_memory_callback_t callback, void *data);
69+ struct list_head next;
70+};
71+
72+void syslinux_memscan_add(struct syslinux_memscan *entry);
73+int syslinux_memscan_new(int (*func)(scan_memory_callback_t cb, void *data));
74 int syslinux_scan_memory(scan_memory_callback_t callback, void *data);
75-int bios_scan_memory(scan_memory_callback_t callback, void *data);
76
77 #endif /* _SYSLINUX_MEMSCAN_H */
78diff --git a/com32/lib/syslinux/memscan.c b/com32/lib/syslinux/memscan.c
79index 0ff25d7..fdb7274 100644
80--- a/com32/lib/syslinux/memscan.c
81+++ b/com32/lib/syslinux/memscan.c
82@@ -32,133 +32,44 @@
83 * Query the system for free memory
84 */
85
86-#include <assert.h>
87-#include <stdbool.h>
88-#include <stdlib.h>
89-#include <string.h>
90-#include <inttypes.h>
91-#include <com32.h>
92-
93 #include <syslinux/memscan.h>
94-#include <syslinux/firmware.h>
95
96-struct e820_entry {
97- uint64_t start;
98- uint64_t len;
99- uint32_t type;
100-};
101+static LIST_HEAD(syslinux_memscan_head);
102
103-int bios_scan_memory(scan_memory_callback_t callback, void *data)
104+/*
105+ * Add a memscan entry to the list.
106+ */
107+void syslinux_memscan_add(struct syslinux_memscan *entry)
108 {
109- static com32sys_t ireg;
110- com32sys_t oreg;
111- struct e820_entry *e820buf;
112- uint64_t start, len, maxlen;
113- int memfound = 0;
114- int rv;
115- addr_t dosmem;
116- const addr_t bios_data = 0x510; /* Amount to reserve for BIOS data */
117+ list_add(&entry->next, &syslinux_memscan_head);
118+}
119
120- /* Use INT 12h to get DOS memory */
121- __intcall(0x12, &__com32_zero_regs, &oreg);
122- dosmem = oreg.eax.w[0] << 10;
123- if (dosmem < 32 * 1024 || dosmem > 640 * 1024) {
124- /* INT 12h reports nonsense... now what? */
125- uint16_t ebda_seg = *(uint16_t *) 0x40e;
126- if (ebda_seg >= 0x8000 && ebda_seg < 0xa000)
127- dosmem = ebda_seg << 4;
128- else
129- dosmem = 640 * 1024; /* Hope for the best... */
130- }
131- rv = callback(data, bios_data, dosmem - bios_data, true);
132- if (rv)
133- return rv;
134+/*
135+ * Build a new memscan entry and add it to the list.
136+ */
137+int syslinux_memscan_new(int func(scan_memory_callback_t, void *data))
138+{
139+ struct syslinux_memscan *entry;
140
141- /* First try INT 15h AX=E820h */
142- e820buf = lzalloc(sizeof *e820buf);
143- if (!e820buf)
144+ entry = malloc(sizeof *entry);
145+ if (!entry)
146 return -1;
147
148- ireg.eax.l = 0xe820;
149- ireg.edx.l = 0x534d4150;
150- ireg.ebx.l = 0;
151- ireg.ecx.l = sizeof(*e820buf);
152- ireg.es = SEG(e820buf);
153- ireg.edi.w[0] = OFFS(e820buf);
154-
155- do {
156- __intcall(0x15, &ireg, &oreg);
157-
158- if ((oreg.eflags.l & EFLAGS_CF) ||
159- (oreg.eax.l != 0x534d4150) || (oreg.ecx.l < 20))
160- break;
161-
162- start = e820buf->start;
163- len = e820buf->len;
164-
165- if (start < 0x100000000ULL) {
166- /* Don't rely on E820 being valid for low memory. Doing so
167- could mean stuff like overwriting the PXE stack even when
168- using "keeppxe", etc. */
169- if (start < 0x100000ULL) {
170- if (len > 0x100000ULL - start)
171- len -= 0x100000ULL - start;
172- else
173- len = 0;
174- start = 0x100000ULL;
175- }
176-
177- maxlen = 0x100000000ULL - start;
178- if (len > maxlen)
179- len = maxlen;
180-
181- if (len) {
182- rv = callback(data, (addr_t) start, (addr_t) len,
183- e820buf->type == 1);
184- if (rv)
185- return rv;
186- memfound = 1;
187- }
188- }
189-
190- ireg.ebx.l = oreg.ebx.l;
191- } while (oreg.ebx.l);
192-
193- lfree(e820buf);
194-
195- if (memfound)
196- return 0;
197-
198- /* Next try INT 15h AX=E801h */
199- ireg.eax.w[0] = 0xe801;
200- __intcall(0x15, &ireg, &oreg);
201-
202- if (!(oreg.eflags.l & EFLAGS_CF) && oreg.ecx.w[0]) {
203- rv = callback(data, (addr_t) 1 << 20, oreg.ecx.w[0] << 10, true);
204- if (rv)
205- return rv;
206-
207- if (oreg.edx.w[0]) {
208- rv = callback(data, (addr_t) 16 << 20, oreg.edx.w[0] << 16, true);
209- if (rv)
210- return rv;
211- }
212-
213- return 0;
214- }
215-
216- /* Finally try INT 15h AH=88h */
217- ireg.eax.w[0] = 0x8800;
218- if (!(oreg.eflags.l & EFLAGS_CF) && oreg.eax.w[0]) {
219- rv = callback(data, (addr_t) 1 << 20, oreg.ecx.w[0] << 10, true);
220- if (rv)
221- return rv;
222- }
223-
224+ entry->func = func;
225+ syslinux_memscan_add(entry);
226 return 0;
227 }
228
229 int syslinux_scan_memory(scan_memory_callback_t callback, void *data)
230 {
231- return firmware->mem->scan_memory(callback, data);
232+ struct syslinux_memscan *entry;
233+ int rv = 0;
234+
235+ list_for_each_entry(entry, &syslinux_memscan_head, next) {
236+ rv = entry->func(callback, data);
237+ if (rv)
238+ break;
239+ }
240+
241+ return rv;
242 }
243diff --git a/core/bios.c b/core/bios.c
244index 53223e8..5344833 100644
245--- a/core/bios.c
246+++ b/core/bios.c
247@@ -501,6 +501,129 @@ static inline void bios_timer_init(void)
248
249 extern uint16_t *bios_free_mem;
250
251+struct e820_entry {
252+ uint64_t start;
253+ uint64_t len;
254+ uint32_t type;
255+};
256+
257+static int bios_scan_memory(scan_memory_callback_t callback, void *data)
258+{
259+ static com32sys_t ireg;
260+ com32sys_t oreg;
261+ struct e820_entry *e820buf;
262+ uint64_t start, len, maxlen;
263+ int memfound = 0;
264+ int rv;
265+ addr_t dosmem;
266+ const addr_t bios_data = 0x510; /* Amount to reserve for BIOS data */
267+
268+ /* Use INT 12h to get DOS memory */
269+ __intcall(0x12, &__com32_zero_regs, &oreg);
270+ dosmem = oreg.eax.w[0] << 10;
271+ if (dosmem < 32 * 1024 || dosmem > 640 * 1024) {
272+ /* INT 12h reports nonsense... now what? */
273+ uint16_t ebda_seg = *(uint16_t *) 0x40e;
274+ if (ebda_seg >= 0x8000 && ebda_seg < 0xa000)
275+ dosmem = ebda_seg << 4;
276+ else
277+ dosmem = 640 * 1024; /* Hope for the best... */
278+ }
279+ rv = callback(data, bios_data, dosmem - bios_data, SMT_FREE);
280+ if (rv)
281+ return rv;
282+
283+ /* First try INT 15h AX=E820h */
284+ e820buf = lzalloc(sizeof *e820buf);
285+ if (!e820buf)
286+ return -1;
287+
288+ ireg.eax.l = 0xe820;
289+ ireg.edx.l = 0x534d4150;
290+ ireg.ebx.l = 0;
291+ ireg.ecx.l = sizeof(*e820buf);
292+ ireg.es = SEG(e820buf);
293+ ireg.edi.w[0] = OFFS(e820buf);
294+
295+ do {
296+ __intcall(0x15, &ireg, &oreg);
297+
298+ if ((oreg.eflags.l & EFLAGS_CF) ||
299+ (oreg.eax.l != 0x534d4150) || (oreg.ecx.l < 20))
300+ break;
301+
302+ start = e820buf->start;
303+ len = e820buf->len;
304+
305+ if (start < 0x100000000ULL) {
306+ /* Don't rely on E820 being valid for low memory. Doing so
307+ could mean stuff like overwriting the PXE stack even when
308+ using "keeppxe", etc. */
309+ if (start < 0x100000ULL) {
310+ if (len > 0x100000ULL - start)
311+ len -= 0x100000ULL - start;
312+ else
313+ len = 0;
314+ start = 0x100000ULL;
315+ }
316+
317+ maxlen = 0x100000000ULL - start;
318+ if (len > maxlen)
319+ len = maxlen;
320+
321+ if (len) {
322+ enum syslinux_memmap_types type;
323+
324+ type = e820buf->type == 1 ? SMT_FREE : SMT_RESERVED;
325+ rv = callback(data, (addr_t) start, (addr_t) len, type);
326+ if (rv)
327+ return rv;
328+ memfound = 1;
329+ }
330+ }
331+
332+ ireg.ebx.l = oreg.ebx.l;
333+ } while (oreg.ebx.l);
334+
335+ lfree(e820buf);
336+
337+ if (memfound)
338+ return 0;
339+
340+ /* Next try INT 15h AX=E801h */
341+ ireg.eax.w[0] = 0xe801;
342+ __intcall(0x15, &ireg, &oreg);
343+
344+ if (!(oreg.eflags.l & EFLAGS_CF) && oreg.ecx.w[0]) {
345+ rv = callback(data, (addr_t) 1 << 20, oreg.ecx.w[0] << 10, SMT_FREE);
346+ if (rv)
347+ return rv;
348+
349+ if (oreg.edx.w[0]) {
350+ rv = callback(data, (addr_t) 16 << 20,
351+ oreg.edx.w[0] << 16, SMT_FREE);
352+ if (rv)
353+ return rv;
354+ }
355+
356+ return 0;
357+ }
358+
359+ /* Finally try INT 15h AH=88h */
360+ ireg.eax.w[0] = 0x8800;
361+ if (!(oreg.eflags.l & EFLAGS_CF) && oreg.eax.w[0]) {
362+ rv = callback(data, (addr_t) 1 << 20, oreg.ecx.w[0] << 10, SMT_FREE);
363+ if (rv)
364+ return rv;
365+ }
366+
367+ return 0;
368+}
369+
370+static struct syslinux_memscan bios_memscan = {
371+ .func = bios_scan_memory,
372+};
373+
374 void bios_init(void)
375 {
376 int i;
377@@ -515,6 +638,7 @@ void bios_init(void)
378
379 /* Init the memory subsystem */
380 bios_free_mem = (uint16_t *)0x413;
381+ syslinux_memscan_add(&bios_memscan);
382 mem_init();
383
384 /* CPU-dependent initialization and related checks. */
385@@ -534,7 +658,6 @@ struct mem_ops bios_mem_ops = {
386 .malloc = bios_malloc,
387 .realloc = bios_realloc,
388 .free = bios_free,
389- .scan_memory = bios_scan_memory,
390 };
391
392 struct firmware bios_fw = {
393diff --git a/efi/main.c b/efi/main.c
394index 13b9403..fb8cf05 100644
395--- a/efi/main.c
396+++ b/efi/main.c
397@@ -296,21 +296,21 @@ int efi_scan_memory(scan_memory_callback_t callback, void *data)
398 for (i = 0; i < nr_entries; bufpos += desc_sz, i++) {
399 EFI_MEMORY_DESCRIPTOR *m;
400 UINT64 region_sz;
401- int valid;
402+ enum syslinux_memmap_types type;
403
404 m = (EFI_MEMORY_DESCRIPTOR *)bufpos;
405 region_sz = m->NumberOfPages * EFI_PAGE_SIZE;
406
407 switch (m->Type) {
408 case EfiConventionalMemory:
409- valid = 1;
410+ type = SMT_FREE;
411 break;
412 default:
413- valid = 0;
414+ type = SMT_RESERVED;
415 break;
416 }
417
418- rv = callback(data, m->PhysicalStart, region_sz, valid);
419+ rv = callback(data, m->PhysicalStart, region_sz, type);
420 if (rv)
421 break;
422 }
423@@ -319,11 +319,16 @@ int efi_scan_memory(scan_memory_callback_t callback, void *data)
424 return rv;
425 }
426
427+static struct syslinux_memscan efi_memscan = {
428+ .func = efi_scan_memory,
429+};
430+
431 extern uint16_t *bios_free_mem;
432 void efi_init(void)
433 {
434 /* XXX timer */
435 *bios_free_mem = 0;
436+ syslinux_memscan_add(&efi_memscan);
437 mem_init();
438 }
439
440@@ -1103,7 +1108,6 @@ struct mem_ops efi_mem_ops = {
441 .malloc = efi_malloc,
442 .realloc = efi_realloc,
443 .free = efi_free,
444- .scan_memory = efi_scan_memory,
445 };
446
447 struct firmware efi_fw = {
448--
4491.8.5.3
450