Upgraded GRUB2 to 2.00 release.
[AROS.git] / arch / all-pc / boot / grub2-aros / grub-core / kern / ieee1275 / mmap.c
blob2e4e085bb19e79aa63c14c039a551a1f16fed15e
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2003,2004,2005,2007,2008 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/memory.h>
20 #include <grub/ieee1275/ieee1275.h>
21 #include <grub/types.h>
23 grub_err_t
24 grub_machine_mmap_iterate (grub_memory_hook_t hook)
26 grub_ieee1275_phandle_t root;
27 grub_ieee1275_phandle_t memory;
28 grub_uint32_t available[32];
29 grub_ssize_t available_size;
30 grub_uint32_t address_cells = 1;
31 grub_uint32_t size_cells = 1;
32 int i;
34 /* Determine the format of each entry in `available'. */
35 grub_ieee1275_finddevice ("/", &root);
36 grub_ieee1275_get_integer_property (root, "#address-cells", &address_cells,
37 sizeof address_cells, 0);
38 grub_ieee1275_get_integer_property (root, "#size-cells", &size_cells,
39 sizeof size_cells, 0);
41 if (size_cells > address_cells)
42 address_cells = size_cells;
44 /* Load `/memory/available'. */
45 if (grub_ieee1275_finddevice ("/memory", &memory))
46 return grub_error (GRUB_ERR_UNKNOWN_DEVICE,
47 "couldn't find /memory node");
48 if (grub_ieee1275_get_integer_property (memory, "available", available,
49 sizeof available, &available_size))
50 return grub_error (GRUB_ERR_UNKNOWN_DEVICE,
51 "couldn't examine /memory/available property");
53 if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_BROKEN_ADDRESS_CELLS))
55 address_cells = 1;
56 size_cells = 1;
59 /* Decode each entry and call `hook'. */
60 i = 0;
61 available_size /= sizeof (grub_uint32_t);
62 while (i < available_size)
64 grub_uint64_t address;
65 grub_uint64_t size;
67 address = available[i++];
68 if (address_cells == 2)
69 address = (address << 32) | available[i++];
71 size = available[i++];
72 if (size_cells == 2)
73 size = (size << 32) | available[i++];
75 if (hook (address, size, GRUB_MEMORY_AVAILABLE))
76 break;
79 return grub_errno;