2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2010 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/relocator.h>
20 #include <grub/relocator_private.h>
21 #include <grub/memory.h>
22 #include <grub/ieee1275/ieee1275.h>
25 grub_relocator_firmware_get_max_events (void)
28 auto int NESTED_FUNC_ATTR
count (grub_uint64_t addr
__attribute__ ((unused
)),
29 grub_uint64_t len
__attribute__ ((unused
)),
30 grub_memory_type_t type
__attribute__ ((unused
)));
31 int NESTED_FUNC_ATTR
count (grub_uint64_t addr
__attribute__ ((unused
)),
32 grub_uint64_t len
__attribute__ ((unused
)),
33 grub_memory_type_t type
__attribute__ ((unused
)))
39 if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_CANNOT_INTERPRET
))
41 grub_machine_mmap_iterate (count
);
46 grub_relocator_firmware_fill_events (struct grub_relocator_mmap_event
*events
)
49 auto int NESTED_FUNC_ATTR
fill (grub_uint64_t addr
, grub_uint64_t len
,
50 grub_memory_type_t type
);
51 int NESTED_FUNC_ATTR
fill (grub_uint64_t addr
, grub_uint64_t len
,
52 grub_memory_type_t type
)
54 if (type
!= GRUB_MEMORY_AVAILABLE
)
57 if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_PRE1_5M_CLAIM
))
59 if (addr
+ len
<= 0x180000)
64 len
= addr
+ len
- 0x180000;
69 events
[counter
].type
= REG_FIRMWARE_START
;
70 events
[counter
].pos
= addr
;
72 events
[counter
].type
= REG_FIRMWARE_END
;
73 events
[counter
].pos
= addr
+ len
;
79 if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_CANNOT_INTERPRET
))
81 grub_machine_mmap_iterate (fill
);
86 grub_relocator_firmware_alloc_region (grub_addr_t start
, grub_size_t size
)
89 err
= grub_claimmap (start
, size
);
95 grub_relocator_firmware_free_region (grub_addr_t start
, grub_size_t size
)
97 grub_ieee1275_release (start
, size
);