111 lines
2.9 KiB
C
111 lines
2.9 KiB
C
/*
|
|
* VAS_EBOOT -- GRand Unified Bootloader
|
|
* Copyright (C) 2010 Free Software Foundation, Inc.
|
|
*
|
|
* VAS_EBOOT 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.
|
|
*
|
|
* VAS_EBOOT 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 VAS_EBOOT. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include <VasEBoot/relocator.h>
|
|
#include <VasEBoot/relocator_private.h>
|
|
#include <VasEBoot/memory.h>
|
|
#include <VasEBoot/ieee1275/ieee1275.h>
|
|
|
|
/* Helper for VasEBoot_relocator_firmware_get_max_events. */
|
|
static int
|
|
count (VasEBoot_uint64_t addr __attribute__ ((unused)),
|
|
VasEBoot_uint64_t len __attribute__ ((unused)),
|
|
VasEBoot_memory_type_t type __attribute__ ((unused)), void *data)
|
|
{
|
|
int *counter = data;
|
|
|
|
(*counter)++;
|
|
return 0;
|
|
}
|
|
|
|
unsigned
|
|
VasEBoot_relocator_firmware_get_max_events (void)
|
|
{
|
|
int counter = 0;
|
|
|
|
VasEBoot_machine_mmap_iterate (count, &counter);
|
|
return 2 * counter;
|
|
}
|
|
|
|
/* Context for VasEBoot_relocator_firmware_fill_events. */
|
|
struct VasEBoot_relocator_firmware_fill_events_ctx
|
|
{
|
|
struct VasEBoot_relocator_mmap_event *events;
|
|
int counter;
|
|
};
|
|
|
|
/* Helper for VasEBoot_relocator_firmware_fill_events. */
|
|
static int
|
|
VasEBoot_relocator_firmware_fill_events_iter (VasEBoot_uint64_t addr,
|
|
VasEBoot_uint64_t len,
|
|
VasEBoot_memory_type_t type, void *data)
|
|
{
|
|
struct VasEBoot_relocator_firmware_fill_events_ctx *ctx = data;
|
|
|
|
if (type != VAS_EBOOT_MEMORY_AVAILABLE)
|
|
return 0;
|
|
|
|
if (VasEBoot_ieee1275_test_flag (VAS_EBOOT_IEEE1275_FLAG_NO_PRE1_5M_CLAIM))
|
|
{
|
|
if (addr + len <= 0x180000)
|
|
return 0;
|
|
|
|
if (addr < 0x180000)
|
|
{
|
|
len = addr + len - 0x180000;
|
|
addr = 0x180000;
|
|
}
|
|
}
|
|
|
|
ctx->events[ctx->counter].type = REG_FIRMWARE_START;
|
|
ctx->events[ctx->counter].pos = addr;
|
|
ctx->counter++;
|
|
ctx->events[ctx->counter].type = REG_FIRMWARE_END;
|
|
ctx->events[ctx->counter].pos = addr + len;
|
|
ctx->counter++;
|
|
|
|
return 0;
|
|
}
|
|
|
|
unsigned
|
|
VasEBoot_relocator_firmware_fill_events (struct VasEBoot_relocator_mmap_event *events)
|
|
{
|
|
struct VasEBoot_relocator_firmware_fill_events_ctx ctx = {
|
|
.events = events,
|
|
.counter = 0
|
|
};
|
|
|
|
VasEBoot_machine_mmap_iterate (VasEBoot_relocator_firmware_fill_events_iter, &ctx);
|
|
return ctx.counter;
|
|
}
|
|
|
|
int
|
|
VasEBoot_relocator_firmware_alloc_region (VasEBoot_addr_t start, VasEBoot_size_t size)
|
|
{
|
|
VasEBoot_err_t err;
|
|
err = VasEBoot_claimmap (start, size);
|
|
VasEBoot_errno = 0;
|
|
return (err == 0);
|
|
}
|
|
|
|
void
|
|
VasEBoot_relocator_firmware_free_region (VasEBoot_addr_t start, VasEBoot_size_t size)
|
|
{
|
|
VasEBoot_ieee1275_release (start, size);
|
|
}
|