Upgraded GRUB2 to 2.00 release.
[AROS.git] / arch / all-pc / boot / grub2-aros / grub-core / lib / ieee1275 / relocator.c
blob021f0ce71f4c5726784cb7bab4c726503f625684
1 /*
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 unsigned
25 grub_relocator_firmware_get_max_events (void)
27 int counter = 0;
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)))
35 counter++;
36 return 0;
39 if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_CANNOT_INTERPRET))
40 return 0;
41 grub_machine_mmap_iterate (count);
42 return 2 * counter;
45 unsigned
46 grub_relocator_firmware_fill_events (struct grub_relocator_mmap_event *events)
48 int counter = 0;
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)
55 return 0;
57 if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_PRE1_5M_CLAIM))
59 if (addr + len <= 0x180000)
60 return 0;
62 if (addr < 0x180000)
64 len = addr + len - 0x180000;
65 addr = 0x180000;
69 events[counter].type = REG_FIRMWARE_START;
70 events[counter].pos = addr;
71 counter++;
72 events[counter].type = REG_FIRMWARE_END;
73 events[counter].pos = addr + len;
74 counter++;
76 return 0;
79 if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_CANNOT_INTERPRET))
80 return 0;
81 grub_machine_mmap_iterate (fill);
82 return counter;
85 int
86 grub_relocator_firmware_alloc_region (grub_addr_t start, grub_size_t size)
88 grub_err_t err;
89 err = grub_claimmap (start, size);
90 grub_errno = 0;
91 return (err == 0);
94 void
95 grub_relocator_firmware_free_region (grub_addr_t start, grub_size_t size)
97 grub_ieee1275_release (start, size);