From 79d29fd7b805842ff83063d9dd1406b33a75f0d9 Mon Sep 17 00:00:00 2001 From: robertmh Date: Thu, 20 Nov 2008 20:30:24 +0000 Subject: [PATCH] Harmonize ieee1275's grub_available_iterate() with the generic grub_machine_mmap_iterate() interface (fixes a recently-introduced build problem on i386-ieee1275): * kern/ieee1275/openfw.c (grub_available_iterate): Moved from here ... * kern/ieee1275/mmap.c (grub_machine_mmap_iterate): ... here. Add third parameter `type'. Update all users of this function. * conf/i386-ieee1275.rmk (kernel_elf_SOURCES): Add `kern/ieee1275/mmap.c'. * kern/ieee1275/init.c * include/grub/ieee1275/ieee1275.h (grub_available_iterate): Replace with ... (grub_machine_mmap_iterate): ... this. * include/grub/i386/pc/memory.h (grub_machine_mmap_iterate): Change return type to `grub_err_t'. Update all implementations of this function prototype. * include/grub/i386/coreboot/memory.h (grub_machine_mmap_iterate): Likewise. --- ChangeLog | 18 ++++++++ DISTLIST | 1 + conf/i386-ieee1275.mk | 13 ++++-- conf/i386-ieee1275.rmk | 1 + include/grub/i386/coreboot/memory.h | 3 +- include/grub/i386/pc/memory.h | 3 +- include/grub/ieee1275/ieee1275.h | 4 +- kern/i386/multiboot_mmap.c | 4 +- kern/i386/pc/mmap.c | 5 +- kern/ieee1275/init.c | 19 ++++---- kern/ieee1275/mmap.c | 71 +++++++++++++++++++++++++++++ kern/ieee1275/openfw.c | 49 -------------------- 12 files changed, 124 insertions(+), 67 deletions(-) create mode 100644 kern/ieee1275/mmap.c diff --git a/ChangeLog b/ChangeLog index c78361cdf..74a91ed22 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,24 @@ * loader/i386/linux.c (allocate_pages): Fix a warning. Move comment text to `#error' stanza. + Harmonize ieee1275's grub_available_iterate() with the generic + grub_machine_mmap_iterate() interface (fixes a recently-introduced + build problem on i386-ieee1275): + * kern/ieee1275/openfw.c (grub_available_iterate): Moved from here ... + * kern/ieee1275/mmap.c (grub_machine_mmap_iterate): ... here. Add third + parameter `type'. Update all users of this function. + * conf/i386-ieee1275.rmk (kernel_elf_SOURCES): Add + `kern/ieee1275/mmap.c'. + * kern/ieee1275/init.c + * include/grub/ieee1275/ieee1275.h (grub_available_iterate): Replace + with ... + (grub_machine_mmap_iterate): ... this. + * include/grub/i386/pc/memory.h (grub_machine_mmap_iterate): Change + return type to `grub_err_t'. Update all implementations of this + function prototype. + * include/grub/i386/coreboot/memory.h (grub_machine_mmap_iterate): + Likewise. + 2008-11-19 Robert Millan * loader/i386/pc/linux.c (grub_rescue_cmd_initrd): Fix a typo. diff --git a/DISTLIST b/DISTLIST index a283043bb..b93b0a81c 100644 --- a/DISTLIST +++ b/DISTLIST @@ -334,6 +334,7 @@ kern/i386/pc/startup.S kern/ieee1275/cmain.c kern/ieee1275/ieee1275.c kern/ieee1275/init.c +kern/ieee1275/mmap.c kern/ieee1275/openfw.c kern/powerpc/cache.S kern/powerpc/dl.c diff --git a/conf/i386-ieee1275.mk b/conf/i386-ieee1275.mk index 2d981d045..bad302fbf 100644 --- a/conf/i386-ieee1275.mk +++ b/conf/i386-ieee1275.mk @@ -14,6 +14,7 @@ pkglib_PROGRAMS = kernel.elf # For kernel.elf. kernel_elf_SOURCES = kern/i386/ieee1275/startup.S kern/i386/ieee1275/init.c \ kern/ieee1275/init.c \ + kern/ieee1275/mmap.c \ kern/ieee1275/cmain.c kern/ieee1275/openfw.c \ kern/main.c kern/device.c \ kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \ @@ -26,11 +27,11 @@ kernel_elf_SOURCES = kern/i386/ieee1275/startup.S kern/i386/ieee1275/init.c \ term/ieee1275/ofconsole.c \ disk/ieee1275/ofdisk.c \ symlist.c -CLEANFILES += kernel.elf kernel_elf-kern_i386_ieee1275_startup.o kernel_elf-kern_i386_ieee1275_init.o kernel_elf-kern_ieee1275_init.o kernel_elf-kern_ieee1275_cmain.o kernel_elf-kern_ieee1275_openfw.o kernel_elf-kern_main.o kernel_elf-kern_device.o kernel_elf-kern_disk.o kernel_elf-kern_dl.o kernel_elf-kern_file.o kernel_elf-kern_fs.o kernel_elf-kern_err.o kernel_elf-kern_misc.o kernel_elf-kern_mm.o kernel_elf-kern_loader.o kernel_elf-kern_rescue.o kernel_elf-kern_term.o kernel_elf-kern_i386_dl.o kernel_elf-kern_parser.o kernel_elf-kern_partition.o kernel_elf-kern_env.o kernel_elf-kern_time.o kernel_elf-kern_generic_millisleep.o kernel_elf-kern_ieee1275_ieee1275.o kernel_elf-term_ieee1275_ofconsole.o kernel_elf-disk_ieee1275_ofdisk.o kernel_elf-symlist.o -MOSTLYCLEANFILES += kernel_elf-kern_i386_ieee1275_startup.d kernel_elf-kern_i386_ieee1275_init.d kernel_elf-kern_ieee1275_init.d kernel_elf-kern_ieee1275_cmain.d kernel_elf-kern_ieee1275_openfw.d kernel_elf-kern_main.d kernel_elf-kern_device.d kernel_elf-kern_disk.d kernel_elf-kern_dl.d kernel_elf-kern_file.d kernel_elf-kern_fs.d kernel_elf-kern_err.d kernel_elf-kern_misc.d kernel_elf-kern_mm.d kernel_elf-kern_loader.d kernel_elf-kern_rescue.d kernel_elf-kern_term.d kernel_elf-kern_i386_dl.d kernel_elf-kern_parser.d kernel_elf-kern_partition.d kernel_elf-kern_env.d kernel_elf-kern_time.d kernel_elf-kern_generic_millisleep.d kernel_elf-kern_ieee1275_ieee1275.d kernel_elf-term_ieee1275_ofconsole.d kernel_elf-disk_ieee1275_ofdisk.d kernel_elf-symlist.d +CLEANFILES += kernel.elf kernel_elf-kern_i386_ieee1275_startup.o kernel_elf-kern_i386_ieee1275_init.o kernel_elf-kern_ieee1275_init.o kernel_elf-kern_ieee1275_mmap.o kernel_elf-kern_ieee1275_cmain.o kernel_elf-kern_ieee1275_openfw.o kernel_elf-kern_main.o kernel_elf-kern_device.o kernel_elf-kern_disk.o kernel_elf-kern_dl.o kernel_elf-kern_file.o kernel_elf-kern_fs.o kernel_elf-kern_err.o kernel_elf-kern_misc.o kernel_elf-kern_mm.o kernel_elf-kern_loader.o kernel_elf-kern_rescue.o kernel_elf-kern_term.o kernel_elf-kern_i386_dl.o kernel_elf-kern_parser.o kernel_elf-kern_partition.o kernel_elf-kern_env.o kernel_elf-kern_time.o kernel_elf-kern_generic_millisleep.o kernel_elf-kern_ieee1275_ieee1275.o kernel_elf-term_ieee1275_ofconsole.o kernel_elf-disk_ieee1275_ofdisk.o kernel_elf-symlist.o +MOSTLYCLEANFILES += kernel_elf-kern_i386_ieee1275_startup.d kernel_elf-kern_i386_ieee1275_init.d kernel_elf-kern_ieee1275_init.d kernel_elf-kern_ieee1275_mmap.d kernel_elf-kern_ieee1275_cmain.d kernel_elf-kern_ieee1275_openfw.d kernel_elf-kern_main.d kernel_elf-kern_device.d kernel_elf-kern_disk.d kernel_elf-kern_dl.d kernel_elf-kern_file.d kernel_elf-kern_fs.d kernel_elf-kern_err.d kernel_elf-kern_misc.d kernel_elf-kern_mm.d kernel_elf-kern_loader.d kernel_elf-kern_rescue.d kernel_elf-kern_term.d kernel_elf-kern_i386_dl.d kernel_elf-kern_parser.d kernel_elf-kern_partition.d kernel_elf-kern_env.d kernel_elf-kern_time.d kernel_elf-kern_generic_millisleep.d kernel_elf-kern_ieee1275_ieee1275.d kernel_elf-term_ieee1275_ofconsole.d kernel_elf-disk_ieee1275_ofdisk.d kernel_elf-symlist.d -kernel.elf: $(kernel_elf_DEPENDENCIES) kernel_elf-kern_i386_ieee1275_startup.o kernel_elf-kern_i386_ieee1275_init.o kernel_elf-kern_ieee1275_init.o kernel_elf-kern_ieee1275_cmain.o kernel_elf-kern_ieee1275_openfw.o kernel_elf-kern_main.o kernel_elf-kern_device.o kernel_elf-kern_disk.o kernel_elf-kern_dl.o kernel_elf-kern_file.o kernel_elf-kern_fs.o kernel_elf-kern_err.o kernel_elf-kern_misc.o kernel_elf-kern_mm.o kernel_elf-kern_loader.o kernel_elf-kern_rescue.o kernel_elf-kern_term.o kernel_elf-kern_i386_dl.o kernel_elf-kern_parser.o kernel_elf-kern_partition.o kernel_elf-kern_env.o kernel_elf-kern_time.o kernel_elf-kern_generic_millisleep.o kernel_elf-kern_ieee1275_ieee1275.o kernel_elf-term_ieee1275_ofconsole.o kernel_elf-disk_ieee1275_ofdisk.o kernel_elf-symlist.o - $(TARGET_CC) -o $@ kernel_elf-kern_i386_ieee1275_startup.o kernel_elf-kern_i386_ieee1275_init.o kernel_elf-kern_ieee1275_init.o kernel_elf-kern_ieee1275_cmain.o kernel_elf-kern_ieee1275_openfw.o kernel_elf-kern_main.o kernel_elf-kern_device.o kernel_elf-kern_disk.o kernel_elf-kern_dl.o kernel_elf-kern_file.o kernel_elf-kern_fs.o kernel_elf-kern_err.o kernel_elf-kern_misc.o kernel_elf-kern_mm.o kernel_elf-kern_loader.o kernel_elf-kern_rescue.o kernel_elf-kern_term.o kernel_elf-kern_i386_dl.o kernel_elf-kern_parser.o kernel_elf-kern_partition.o kernel_elf-kern_env.o kernel_elf-kern_time.o kernel_elf-kern_generic_millisleep.o kernel_elf-kern_ieee1275_ieee1275.o kernel_elf-term_ieee1275_ofconsole.o kernel_elf-disk_ieee1275_ofdisk.o kernel_elf-symlist.o $(TARGET_LDFLAGS) $(kernel_elf_LDFLAGS) +kernel.elf: $(kernel_elf_DEPENDENCIES) kernel_elf-kern_i386_ieee1275_startup.o kernel_elf-kern_i386_ieee1275_init.o kernel_elf-kern_ieee1275_init.o kernel_elf-kern_ieee1275_mmap.o kernel_elf-kern_ieee1275_cmain.o kernel_elf-kern_ieee1275_openfw.o kernel_elf-kern_main.o kernel_elf-kern_device.o kernel_elf-kern_disk.o kernel_elf-kern_dl.o kernel_elf-kern_file.o kernel_elf-kern_fs.o kernel_elf-kern_err.o kernel_elf-kern_misc.o kernel_elf-kern_mm.o kernel_elf-kern_loader.o kernel_elf-kern_rescue.o kernel_elf-kern_term.o kernel_elf-kern_i386_dl.o kernel_elf-kern_parser.o kernel_elf-kern_partition.o kernel_elf-kern_env.o kernel_elf-kern_time.o kernel_elf-kern_generic_millisleep.o kernel_elf-kern_ieee1275_ieee1275.o kernel_elf-term_ieee1275_ofconsole.o kernel_elf-disk_ieee1275_ofdisk.o kernel_elf-symlist.o + $(TARGET_CC) -o $@ kernel_elf-kern_i386_ieee1275_startup.o kernel_elf-kern_i386_ieee1275_init.o kernel_elf-kern_ieee1275_init.o kernel_elf-kern_ieee1275_mmap.o kernel_elf-kern_ieee1275_cmain.o kernel_elf-kern_ieee1275_openfw.o kernel_elf-kern_main.o kernel_elf-kern_device.o kernel_elf-kern_disk.o kernel_elf-kern_dl.o kernel_elf-kern_file.o kernel_elf-kern_fs.o kernel_elf-kern_err.o kernel_elf-kern_misc.o kernel_elf-kern_mm.o kernel_elf-kern_loader.o kernel_elf-kern_rescue.o kernel_elf-kern_term.o kernel_elf-kern_i386_dl.o kernel_elf-kern_parser.o kernel_elf-kern_partition.o kernel_elf-kern_env.o kernel_elf-kern_time.o kernel_elf-kern_generic_millisleep.o kernel_elf-kern_ieee1275_ieee1275.o kernel_elf-term_ieee1275_ofconsole.o kernel_elf-disk_ieee1275_ofdisk.o kernel_elf-symlist.o $(TARGET_LDFLAGS) $(kernel_elf_LDFLAGS) kernel_elf-kern_i386_ieee1275_startup.o: kern/i386/ieee1275/startup.S $(kern/i386/ieee1275/startup.S_DEPENDENCIES) $(TARGET_CC) -Ikern/i386/ieee1275 -I$(srcdir)/kern/i386/ieee1275 $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(kernel_elf_CFLAGS) -MD -c -o $@ $< @@ -44,6 +45,10 @@ kernel_elf-kern_ieee1275_init.o: kern/ieee1275/init.c $(kern/ieee1275/init.c_DEP $(TARGET_CC) -Ikern/ieee1275 -I$(srcdir)/kern/ieee1275 $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(kernel_elf_CFLAGS) -MD -c -o $@ $< -include kernel_elf-kern_ieee1275_init.d +kernel_elf-kern_ieee1275_mmap.o: kern/ieee1275/mmap.c $(kern/ieee1275/mmap.c_DEPENDENCIES) + $(TARGET_CC) -Ikern/ieee1275 -I$(srcdir)/kern/ieee1275 $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(kernel_elf_CFLAGS) -MD -c -o $@ $< +-include kernel_elf-kern_ieee1275_mmap.d + kernel_elf-kern_ieee1275_cmain.o: kern/ieee1275/cmain.c $(kern/ieee1275/cmain.c_DEPENDENCIES) $(TARGET_CC) -Ikern/ieee1275 -I$(srcdir)/kern/ieee1275 $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(kernel_elf_CFLAGS) -MD -c -o $@ $< -include kernel_elf-kern_ieee1275_cmain.d diff --git a/conf/i386-ieee1275.rmk b/conf/i386-ieee1275.rmk index bbd856640..1b96ca1d7 100644 --- a/conf/i386-ieee1275.rmk +++ b/conf/i386-ieee1275.rmk @@ -13,6 +13,7 @@ pkglib_PROGRAMS = kernel.elf # For kernel.elf. kernel_elf_SOURCES = kern/i386/ieee1275/startup.S kern/i386/ieee1275/init.c \ kern/ieee1275/init.c \ + kern/ieee1275/mmap.c \ kern/ieee1275/cmain.c kern/ieee1275/openfw.c \ kern/main.c kern/device.c \ kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \ diff --git a/include/grub/i386/coreboot/memory.h b/include/grub/i386/coreboot/memory.h index faac757bd..434ae622e 100644 --- a/include/grub/i386/coreboot/memory.h +++ b/include/grub/i386/coreboot/memory.h @@ -24,6 +24,7 @@ #include #ifndef ASM_FILE +#include #include #endif @@ -61,7 +62,7 @@ typedef struct grub_linuxbios_mem_region *mem_region_t; void grub_machine_mmap_init (void); -void EXPORT_FUNC(grub_machine_mmap_iterate) +grub_err_t EXPORT_FUNC(grub_machine_mmap_iterate) (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t)); #endif diff --git a/include/grub/i386/pc/memory.h b/include/grub/i386/pc/memory.h index 6a4830788..08e92a9f2 100644 --- a/include/grub/i386/pc/memory.h +++ b/include/grub/i386/pc/memory.h @@ -24,6 +24,7 @@ #include #ifndef ASM_FILE #include +#include #endif /* The scratch buffer used in real mode code. */ @@ -94,7 +95,7 @@ struct grub_machine_mmap_entry grub_uint32_t type; } __attribute__((packed)); -void EXPORT_FUNC(grub_machine_mmap_iterate) +grub_err_t EXPORT_FUNC(grub_machine_mmap_iterate) (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t)); #endif diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h index 6f8f1ccb8..628d888cd 100644 --- a/include/grub/ieee1275/ieee1275.h +++ b/include/grub/ieee1275/ieee1275.h @@ -167,8 +167,8 @@ grub_err_t EXPORT_FUNC(grub_devalias_iterate) (int (*hook) (struct grub_ieee1275_devalias *alias)); grub_err_t EXPORT_FUNC(grub_children_iterate) (char *devpath, int (*hook) (struct grub_ieee1275_devalias *alias)); -grub_err_t EXPORT_FUNC(grub_available_iterate) - (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t)); +grub_err_t EXPORT_FUNC(grub_machine_mmap_iterate) + (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t)); int EXPORT_FUNC(grub_claimmap) (grub_addr_t addr, grub_size_t size); char *EXPORT_FUNC(grub_ieee1275_encode_devname) (const char *path); diff --git a/kern/i386/multiboot_mmap.c b/kern/i386/multiboot_mmap.c index 16f155bac..8331bd5df 100644 --- a/kern/i386/multiboot_mmap.c +++ b/kern/i386/multiboot_mmap.c @@ -69,7 +69,7 @@ grub_machine_mmap_init () } } -void +grub_err_t grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t)) { struct grub_multiboot_mmap_entry *entry = (void *) kern_multiboot_info.mmap_addr; @@ -81,4 +81,6 @@ grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uin entry = (void *) ((grub_addr_t) entry + entry->size + sizeof (entry->size)); } + + return 0; } diff --git a/kern/i386/pc/mmap.c b/kern/i386/pc/mmap.c index 47aa53cff..d289c731d 100644 --- a/kern/i386/pc/mmap.c +++ b/kern/i386/pc/mmap.c @@ -18,9 +18,10 @@ #include #include +#include #include -void +grub_err_t grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t)) { grub_uint32_t cont; @@ -57,4 +58,6 @@ grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uin else hook (0x100000, grub_get_memsize (1) << 10, GRUB_MACHINE_MEMORY_AVAILABLE); } + + return 0; } diff --git a/kern/ieee1275/init.c b/kern/ieee1275/init.c index 71b7ba9c6..d345ba2dd 100644 --- a/kern/ieee1275/init.c +++ b/kern/ieee1275/init.c @@ -130,9 +130,12 @@ static void grub_claim_heap (void) { unsigned long total = 0; - auto int NESTED_FUNC_ATTR heap_init (grub_uint64_t addr, grub_uint64_t len); - int NESTED_FUNC_ATTR heap_init (grub_uint64_t addr, grub_uint64_t len) + auto int NESTED_FUNC_ATTR heap_init (grub_uint64_t addr, grub_uint64_t len, grub_uint32_t type); + int NESTED_FUNC_ATTR heap_init (grub_uint64_t addr, grub_uint64_t len, grub_uint32_t type) { + if (type != 1) + return 0; + len -= 1; /* Required for some firmware. */ /* Never exceed HEAP_MAX_SIZE */ @@ -174,9 +177,9 @@ static void grub_claim_heap (void) } if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_CANNOT_INTERPRET)) - heap_init (HEAP_MAX_ADDR - HEAP_MIN_SIZE, HEAP_MIN_SIZE); + heap_init (HEAP_MAX_ADDR - HEAP_MIN_SIZE, HEAP_MIN_SIZE, 1); else - grub_available_iterate (heap_init); + grub_machine_mmap_iterate (heap_init); } #ifdef __i386__ @@ -187,10 +190,10 @@ grub_uint32_t grub_upper_mem; static void grub_get_extended_memory (void) { - auto int NESTED_FUNC_ATTR find_ext_mem (grub_uint64_t addr, grub_uint64_t len); - int NESTED_FUNC_ATTR find_ext_mem (grub_uint64_t addr, grub_uint64_t len) + auto int NESTED_FUNC_ATTR find_ext_mem (grub_uint64_t addr, grub_uint64_t len, grub_uint32_t type); + int NESTED_FUNC_ATTR find_ext_mem (grub_uint64_t addr, grub_uint64_t len, grub_uint32_t type) { - if (addr == 0x100000) + if (type == 1 && addr == 0x100000) { grub_upper_mem = len; return 1; @@ -199,7 +202,7 @@ grub_get_extended_memory (void) return 0; } - grub_available_iterate (find_ext_mem); + grub_machine_mmap_iterate (find_ext_mem); } #endif diff --git a/kern/ieee1275/mmap.c b/kern/ieee1275/mmap.c new file mode 100644 index 000000000..5b30dbb9e --- /dev/null +++ b/kern/ieee1275/mmap.c @@ -0,0 +1,71 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2003,2004,2005,2007,2008 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include + +grub_err_t +grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t)) +{ + grub_ieee1275_phandle_t root; + grub_ieee1275_phandle_t memory; + grub_uint32_t available[32]; + grub_ssize_t available_size; + grub_uint32_t address_cells = 1; + grub_uint32_t size_cells = 1; + int i; + + /* Determine the format of each entry in `available'. */ + grub_ieee1275_finddevice ("/", &root); + grub_ieee1275_get_integer_property (root, "#address-cells", &address_cells, + sizeof address_cells, 0); + grub_ieee1275_get_integer_property (root, "#size-cells", &size_cells, + sizeof size_cells, 0); + + /* Load `/memory/available'. */ + if (grub_ieee1275_finddevice ("/memory", &memory)) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, + "Couldn't find /memory node"); + if (grub_ieee1275_get_integer_property (memory, "available", available, + sizeof available, &available_size)) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, + "Couldn't examine /memory/available property"); + + /* Decode each entry and call `hook'. */ + i = 0; + available_size /= sizeof (grub_uint32_t); + while (i < available_size) + { + grub_uint64_t address; + grub_uint64_t size; + + address = available[i++]; + if (address_cells == 2) + address = (address << 32) | available[i++]; + + size = available[i++]; + if (size_cells == 2) + size = (size << 32) | available[i++]; + + if (hook (address, size, GRUB_MACHINE_MEMORY_AVAILABLE)) + break; + } + + return grub_errno; +} diff --git a/kern/ieee1275/openfw.c b/kern/ieee1275/openfw.c index ac97a5920..e88f3b338 100644 --- a/kern/ieee1275/openfw.c +++ b/kern/ieee1275/openfw.c @@ -147,55 +147,6 @@ nextprop: return 0; } -grub_err_t grub_available_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t)) -{ - grub_ieee1275_phandle_t root; - grub_ieee1275_phandle_t memory; - grub_uint32_t available[32]; - grub_ssize_t available_size; - grub_uint32_t address_cells = 1; - grub_uint32_t size_cells = 1; - int i; - - /* Determine the format of each entry in `available'. */ - grub_ieee1275_finddevice ("/", &root); - grub_ieee1275_get_integer_property (root, "#address-cells", &address_cells, - sizeof address_cells, 0); - grub_ieee1275_get_integer_property (root, "#size-cells", &size_cells, - sizeof size_cells, 0); - - /* Load `/memory/available'. */ - if (grub_ieee1275_finddevice ("/memory", &memory)) - return grub_error (GRUB_ERR_UNKNOWN_DEVICE, - "Couldn't find /memory node"); - if (grub_ieee1275_get_integer_property (memory, "available", available, - sizeof available, &available_size)) - return grub_error (GRUB_ERR_UNKNOWN_DEVICE, - "Couldn't examine /memory/available property"); - - /* Decode each entry and call `hook'. */ - i = 0; - available_size /= sizeof (grub_uint32_t); - while (i < available_size) - { - grub_uint64_t address; - grub_uint64_t size; - - address = available[i++]; - if (address_cells == 2) - address = (address << 32) | available[i++]; - - size = available[i++]; - if (size_cells == 2) - size = (size << 32) | available[i++]; - - if (hook (address, size)) - break; - } - - return grub_errno; -} - /* Call the "map" method of /chosen/mmu. */ static int grub_map (grub_addr_t phys, grub_addr_t virt, grub_uint32_t size,