2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2007,2008,2013 Free Software Foundation, Inc.
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.
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.
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/>.
19 #include <grub/machine/memory.h>
20 #include <grub/machine/lbio.h>
21 #include <grub/types.h>
23 #include <grub/misc.h>
25 /* Context for grub_machine_mmap_iterate. */
26 struct grub_machine_mmap_iterate_ctx
28 grub_memory_hook_t hook
;
32 #define GRUB_MACHINE_MEMORY_BADRAM 5
34 /* Helper for grub_machine_mmap_iterate. */
36 iterate_linuxbios_table (grub_linuxbios_table_item_t table_item
, void *data
)
38 struct grub_machine_mmap_iterate_ctx
*ctx
= data
;
39 mem_region_t mem_region
;
41 if (table_item
->tag
!= GRUB_LINUXBIOS_MEMBER_MEMORY
)
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
;
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
)
57 && ctx
->hook (start
, 0xa0000 - start
,
58 /* Multiboot mmaps match with the coreboot mmap
59 definition. Therefore, we can just pass type
69 if (ctx
->hook (start
, (end
> 0x100000 ? 0x100000 : end
) - start
,
78 if (ctx
->hook (start
, end
- start
,
79 /* Multiboot mmaps match with the coreboot mmap
80 definition. Therefore, we can just pass type
91 grub_machine_mmap_iterate (grub_memory_hook_t hook
, void *hook_data
)
93 struct grub_machine_mmap_iterate_ctx ctx
= { hook
, hook_data
};
95 grub_linuxbios_table_iterate (iterate_linuxbios_table
, &ctx
);