2014-02-19 04:55:02 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the coreboot project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* This program 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; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BOOTMEM_H
|
|
|
|
#define BOOTMEM_H
|
|
|
|
|
|
|
|
#include <memrange.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <boot/coreboot_tables.h>
|
|
|
|
|
2018-04-05 09:14:51 +02:00
|
|
|
/**
|
2018-04-12 10:36:57 +02:00
|
|
|
* Bootmem types match to LB_MEM tags, except for the following:
|
|
|
|
* BM_MEM_RAMSTAGE : Memory where any kind of boot firmware resides and that
|
|
|
|
* should not be touched by bootmem (by example: stack,
|
|
|
|
* TTB, program, ...).
|
|
|
|
* BM_MEM_PAYLOAD : Memory where any kind of payload resides and that should
|
|
|
|
* not be touched by bootmem.
|
2018-04-05 09:14:51 +02:00
|
|
|
* Start at 0x10000 to make sure that the caller doesn't provide LB_MEM tags.
|
|
|
|
*/
|
|
|
|
enum bootmem_type {
|
|
|
|
BM_MEM_FIRST = 0x10000, /* First entry in this list */
|
|
|
|
BM_MEM_RAM, /* Memory anyone can use */
|
|
|
|
BM_MEM_RESERVED, /* Don't use this memory region */
|
|
|
|
BM_MEM_ACPI, /* ACPI Tables */
|
|
|
|
BM_MEM_NVS, /* ACPI NVS Memory */
|
|
|
|
BM_MEM_UNUSABLE, /* Unusable address space */
|
|
|
|
BM_MEM_VENDOR_RSVD, /* Vendor Reserved */
|
|
|
|
BM_MEM_TABLE, /* Ram configuration tables are kept in */
|
2018-04-12 10:36:57 +02:00
|
|
|
BM_MEM_RAMSTAGE,
|
|
|
|
BM_MEM_PAYLOAD,
|
2018-04-05 09:14:51 +02:00
|
|
|
BM_MEM_LAST, /* Last entry in this list */
|
|
|
|
};
|
|
|
|
|
2018-04-12 10:36:57 +02:00
|
|
|
/**
|
|
|
|
* Write memory coreboot table. Current resource map is serialized into
|
2018-04-03 08:08:12 +02:00
|
|
|
* memtable (LB_MEM_* types). bootmem library is unusable until this function
|
2018-04-12 10:36:57 +02:00
|
|
|
* is called first in the write tables path before payload is loaded.
|
|
|
|
*
|
|
|
|
* Bootmem types match to LB_MEM tags, except for the following:
|
|
|
|
* BM_MEM_RAMSTAGE : Translates to LB_MEM_RAM.
|
|
|
|
* BM_MEM_PAYLOAD : Translates to LB_MEM_RAM.
|
|
|
|
*/
|
2018-04-03 08:08:12 +02:00
|
|
|
void bootmem_write_memory_table(struct lb_memory *mem);
|
2014-02-19 04:55:02 +01:00
|
|
|
|
2018-04-03 08:08:12 +02:00
|
|
|
/* Architecture hook to add bootmem areas the architecture controls when
|
|
|
|
* bootmem_write_memory_table() is called. */
|
2016-04-20 00:25:59 +02:00
|
|
|
void bootmem_arch_add_ranges(void);
|
|
|
|
|
2018-04-12 10:36:57 +02:00
|
|
|
/* Platform hook to add bootmem areas the platform / board controls. */
|
|
|
|
void bootmem_platform_add_ranges(void);
|
|
|
|
|
2014-02-19 04:55:02 +01:00
|
|
|
/* Add a range of a given type to the bootmem address space. */
|
2018-04-05 09:14:51 +02:00
|
|
|
void bootmem_add_range(uint64_t start, uint64_t size,
|
|
|
|
const enum bootmem_type tag);
|
2014-02-19 04:55:02 +01:00
|
|
|
|
|
|
|
/* Print current range map of boot memory. */
|
|
|
|
void bootmem_dump_ranges(void);
|
|
|
|
|
2018-04-10 09:34:29 +02:00
|
|
|
typedef bool (*range_action_t)(const struct range_entry *r, void *arg);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Walk memory tables and call the provided function, for every region.
|
|
|
|
* The caller has to return false to break out of the loop any time, or
|
|
|
|
* return true to continue.
|
|
|
|
*
|
|
|
|
* @param action The function to call for each memory range.
|
|
|
|
* @param arg Pointer passed to function @action. Set to NULL if unused.
|
|
|
|
* @return true if the function 'action' returned false.
|
|
|
|
*/
|
|
|
|
bool bootmem_walk(range_action_t action, void *arg);
|
|
|
|
|
2014-02-19 04:55:02 +01:00
|
|
|
/* Return 1 if region targets usable RAM, 0 otherwise. */
|
|
|
|
int bootmem_region_targets_usable_ram(uint64_t start, uint64_t size);
|
|
|
|
|
|
|
|
/* Allocate a temporary buffer from the unused RAM areas. */
|
|
|
|
void *bootmem_allocate_buffer(size_t size);
|
|
|
|
|
|
|
|
#endif /* BOOTMEM_H */
|