]> git.proxmox.com Git - grub2.git/blob - grub-core/kern/i386/coreboot/mmap.c
* grub-core/kern/i386/coreboot/mmap.c: Filter out 0xa0000-0x100000
[grub2.git] / grub-core / kern / i386 / coreboot / mmap.c
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2007,2008,2013 Free Software Foundation, Inc.
4 *
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include <grub/machine/memory.h>
20 #include <grub/machine/lbio.h>
21 #include <grub/types.h>
22 #include <grub/err.h>
23 #include <grub/misc.h>
24
25 /* Context for grub_machine_mmap_iterate. */
26 struct grub_machine_mmap_iterate_ctx
27 {
28 grub_memory_hook_t hook;
29 void *hook_data;
30 };
31
32 #define GRUB_MACHINE_MEMORY_BADRAM 5
33
34 /* Helper for grub_machine_mmap_iterate. */
35 static int
36 iterate_linuxbios_table (grub_linuxbios_table_item_t table_item, void *data)
37 {
38 struct grub_machine_mmap_iterate_ctx *ctx = data;
39 mem_region_t mem_region;
40
41 if (table_item->tag != GRUB_LINUXBIOS_MEMBER_MEMORY)
42 return 0;
43
44 mem_region =
45 (mem_region_t) ((long) table_item +
46 sizeof (struct grub_linuxbios_table_item));
47 for (; (long) mem_region < (long) table_item + (long) table_item->size;
48 mem_region++)
49 {
50 grub_uint64_t start = mem_region->addr;
51 grub_uint64_t end = mem_region->addr + mem_region->size;
52 /* Mark region 0xa0000 - 0x100000 as reserved. */
53 if (start < 0x100000 && end >= 0xa0000
54 && mem_region->type == GRUB_MACHINE_MEMORY_AVAILABLE)
55 {
56 if (start < 0xa0000
57 && ctx->hook (start, 0xa0000 - start,
58 /* Multiboot mmaps match with the coreboot mmap
59 definition. Therefore, we can just pass type
60 through. */
61 mem_region->type,
62 ctx->hook_data))
63 return 1;
64 if (start < 0xa0000)
65 start = 0xa0000;
66 if (start >= end)
67 continue;
68
69 if (ctx->hook (start, (end > 0x100000 ? 0x100000 : end) - start,
70 GRUB_MEMORY_RESERVED,
71 ctx->hook_data))
72 return 1;
73 start = 0x100000;
74
75 if (end <= start)
76 continue;
77 }
78 if (ctx->hook (start, end - start,
79 /* Multiboot mmaps match with the coreboot mmap
80 definition. Therefore, we can just pass type
81 through. */
82 mem_region->type,
83 ctx->hook_data))
84 return 1;
85 }
86
87 return 0;
88 }
89
90 grub_err_t
91 grub_machine_mmap_iterate (grub_memory_hook_t hook, void *hook_data)
92 {
93 struct grub_machine_mmap_iterate_ctx ctx = { hook, hook_data };
94
95 grub_linuxbios_table_iterate (iterate_linuxbios_table, &ctx);
96
97 return 0;
98 }