1 /* Compute amount of lower and upper memory till the first hole. */
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2009 Free Software Foundation, Inc.
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20 #include <grub/memory.h>
21 #include <grub/i386/memory.h>
23 #include <grub/misc.h>
25 /* Helper for grub_mmap_get_lower. */
27 lower_hook (grub_uint64_t addr
, grub_uint64_t size
, grub_memory_type_t type
,
30 grub_uint64_t
*lower
= data
;
32 if (type
!= GRUB_MEMORY_AVAILABLE
)
34 #ifdef GRUB_MACHINE_COREBOOT
44 grub_mmap_get_lower (void)
46 grub_uint64_t lower
= 0;
48 grub_mmap_iterate (lower_hook
, &lower
);
54 /* Helper for grub_mmap_get_upper. */
56 upper_hook (grub_uint64_t addr
, grub_uint64_t size
, grub_memory_type_t type
,
59 grub_uint64_t
*upper
= data
;
61 if (type
!= GRUB_MEMORY_AVAILABLE
)
63 if (addr
<= 0x100000 && addr
+ size
> 0x100000)
64 *upper
= addr
+ size
- 0x100000;
69 grub_mmap_get_upper (void)
71 grub_uint64_t upper
= 0;
73 grub_mmap_iterate (upper_hook
, &upper
);
77 /* Helper for grub_mmap_get_post64. */
79 post64_hook (grub_uint64_t addr
, grub_uint64_t size
, grub_memory_type_t type
,
82 grub_uint64_t
*post64
= data
;
83 if (type
!= GRUB_MEMORY_AVAILABLE
)
85 if (addr
<= 0x4000000 && addr
+ size
> 0x4000000)
86 *post64
= addr
+ size
- 0x4000000;
90 /* Count the continuous bytes after 64 MiB. */
92 grub_mmap_get_post64 (void)
94 grub_uint64_t post64
= 0;
96 grub_mmap_iterate (post64_hook
, &post64
);