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>
24 /* Helper for grub_relocator_firmware_get_max_events. */
26 count (grub_uint64_t addr
__attribute__ ((unused
)),
27 grub_uint64_t len
__attribute__ ((unused
)),
28 grub_memory_type_t type
__attribute__ ((unused
)), void *data
)
37 grub_relocator_firmware_get_max_events (void)
41 grub_machine_mmap_iterate (count
, &counter
);
45 /* Context for grub_relocator_firmware_fill_events. */
46 struct grub_relocator_firmware_fill_events_ctx
48 struct grub_relocator_mmap_event
*events
;
52 /* Helper for grub_relocator_firmware_fill_events. */
54 grub_relocator_firmware_fill_events_iter (grub_uint64_t addr
,
56 grub_memory_type_t type
, void *data
)
58 struct grub_relocator_firmware_fill_events_ctx
*ctx
= data
;
60 if (type
!= GRUB_MEMORY_AVAILABLE
)
63 if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_PRE1_5M_CLAIM
))
65 if (addr
+ len
<= 0x180000)
70 len
= addr
+ len
- 0x180000;
75 ctx
->events
[ctx
->counter
].type
= REG_FIRMWARE_START
;
76 ctx
->events
[ctx
->counter
].pos
= addr
;
78 ctx
->events
[ctx
->counter
].type
= REG_FIRMWARE_END
;
79 ctx
->events
[ctx
->counter
].pos
= addr
+ len
;
86 grub_relocator_firmware_fill_events (struct grub_relocator_mmap_event
*events
)
88 struct grub_relocator_firmware_fill_events_ctx ctx
= {
93 grub_machine_mmap_iterate (grub_relocator_firmware_fill_events_iter
, &ctx
);
98 grub_relocator_firmware_alloc_region (grub_addr_t start
, grub_size_t size
)
101 err
= grub_claimmap (start
, size
);
107 grub_relocator_firmware_free_region (grub_addr_t start
, grub_size_t size
)
109 grub_ieee1275_release (start
, size
);