summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorKyösti Mälkki <kyosti.malkki@gmail.com>2014-11-28 11:24:19 +0200
committerKyösti Mälkki <kyosti.malkki@gmail.com>2015-01-27 22:54:32 +0100
commitae98e83eb256c17a4a8d535bba4107611126db3d (patch)
treede963b2d1cd3652e51ec17da112ff7642ddb0e72 /src/lib
parent2fb6b40ed0d4c4d169d4b909ad784e1841b50242 (diff)
downloadcoreboot-ae98e83eb256c17a4a8d535bba4107611126db3d.tar.xz
CBMEM: Always use DYNAMIC_CBMEM
Drop the implementation of statically allocated high memory region for CBMEM. There is no longer the need to explicitly select DYNAMIC_CBMEM, it is the only remaining choice. Change-Id: Iadf6f27a134e05daa1038646d0b4e0b8f9f0587a Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com> Reviewed-on: http://review.coreboot.org/7851 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org> Reviewed-by: Aaron Durbin <adurbin@google.com>
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/Makefile.inc13
-rw-r--r--src/lib/cbmem.c288
-rw-r--r--src/lib/rmodule.c8
3 files changed, 4 insertions, 305 deletions
diff --git a/src/lib/Makefile.inc b/src/lib/Makefile.inc
index b5eb81971d..9650fd5fd9 100644
--- a/src/lib/Makefile.inc
+++ b/src/lib/Makefile.inc
@@ -82,17 +82,8 @@ ramstage-y += memrange.c
ramstage-$(CONFIG_COOP_MULTITASKING) += thread.c
ramstage-$(CONFIG_TIMER_QUEUE) += timer_queue.c
-# The CBMEM implementations are chosen based on CONFIG_DYNAMIC_CBMEM.
-ifeq ($(CONFIG_DYNAMIC_CBMEM),y)
-ramstage-y += dynamic_cbmem.c
-romstage-y += dynamic_cbmem.c
-else
-ramstage-y += cbmem.c
-romstage-y += cbmem.c
-endif # CONFIG_DYNAMIC_CBMEM
-
-romstage-y += cbmem_common.c
-ramstage-y += cbmem_common.c
+romstage-y += cbmem_common.c dynamic_cbmem.c
+ramstage-y += cbmem_common.c dynamic_cbmem.c
ramstage-y += hexdump.c
romstage-y += hexdump.c
diff --git a/src/lib/cbmem.c b/src/lib/cbmem.c
deleted file mode 100644
index d5f89a188d..0000000000
--- a/src/lib/cbmem.c
+++ /dev/null
@@ -1,288 +0,0 @@
-/*
- * This file is part of the coreboot project.
- *
- * Copyright (C) 2009 coresystems GmbH
- *
- * 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.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
- */
-
-#include <types.h>
-#include <string.h>
-#include <bootmem.h>
-#include <bootstate.h>
-#include <cbmem.h>
-#include <console/console.h>
-#include <arch/early_variables.h>
-#if CONFIG_HAVE_ACPI_RESUME && !defined(__PRE_RAM__)
-#include <arch/acpi.h>
-#endif
-
-// The CBMEM TOC reserves 512 bytes to keep
-// the other entries somewhat aligned.
-// Increase if MAX_CBMEM_ENTRIES exceeds 21
-#define CBMEM_TOC_RESERVED 512
-#define MAX_CBMEM_ENTRIES 16
-#define CBMEM_MAGIC 0x434f5245
-
-struct cbmem_entry {
- u32 magic;
- u32 id;
- u64 base;
- u64 size;
-} __attribute__((packed));
-
-#ifndef __PRE_RAM__
-static uint64_t cbmem_base = 0;
-static uint64_t cbmem_size = 0;
-#endif
-
-static void cbmem_trace_location(uint64_t base, uint64_t size, const char *s)
-{
- if (base && size && s) {
- printk(BIOS_DEBUG, "CBMEM region %llx-%llx (%s)\n",
- base, base + size - 1, s);
- }
-}
-
-static void cbmem_locate_table(uint64_t *base, uint64_t *size)
-{
-#ifdef __PRE_RAM__
- get_cbmem_table(base, size);
-#else
- if (!(cbmem_base && cbmem_size)) {
- get_cbmem_table(&cbmem_base, &cbmem_size);
- cbmem_trace_location(cbmem_base, cbmem_size, __FUNCTION__);
- }
- *base = cbmem_base;
- *size = cbmem_size;
-#endif
-}
-
-struct cbmem_entry *get_cbmem_toc(void)
-{
- uint64_t base, size;
- cbmem_locate_table(&base, &size);
- return (struct cbmem_entry *)(unsigned long)base;
-}
-
-#if !defined(__PRE_RAM__)
-void cbmem_late_set_table(uint64_t base, uint64_t size)
-{
- cbmem_trace_location(base, size, __FUNCTION__);
- cbmem_base = base;
- cbmem_size = size;
-}
-#endif
-
-/**
- * cbmem is a simple mechanism to do some kind of book keeping of the coreboot
- * high tables memory. This is a small amount of memory which is "stolen" from
- * the system memory for coreboot purposes. Usually this memory is used for
- * - the coreboot table
- * - legacy tables (PIRQ, MP table)
- * - ACPI tables
- * - suspend/resume backup memory
- */
-
-static void cbmem_initialize_empty(void)
-{
- uint64_t baseaddr, size;
- struct cbmem_entry *cbmem_toc;
-
- cbmem_locate_table(&baseaddr, &size);
- cbmem_trace_location(baseaddr, size, __FUNCTION__);
-
- if (!(baseaddr && size)) {
- printk(BIOS_CRIT, "Unable to set location for CBMEM.\n");
- return;
- }
-
- cbmem_toc = (struct cbmem_entry *)(unsigned long)baseaddr;
- memset(cbmem_toc, 0, CBMEM_TOC_RESERVED);
-
- cbmem_toc[0] = (struct cbmem_entry) {
- .magic = CBMEM_MAGIC,
- .id = CBMEM_ID_FREESPACE,
- .base = baseaddr + CBMEM_TOC_RESERVED,
- .size = size - CBMEM_TOC_RESERVED
- };
-}
-
-static int cbmem_check_toc(void)
-{
- uint64_t baseaddr, size;
- struct cbmem_entry *cbmem_toc;
-
- cbmem_locate_table(&baseaddr, &size);
- cbmem_trace_location(baseaddr, size, __FUNCTION__);
-
- cbmem_toc = (struct cbmem_entry *)(unsigned long)baseaddr;
-
- return (cbmem_toc[0].magic == CBMEM_MAGIC);
-}
-
-void *cbmem_add(u32 id, u64 size)
-{
- struct cbmem_entry *cbmem_toc;
- int i;
- void *p;
-
- /*
- * This could be a restart, check if the section is there already. It
- * is remotely possible that the dram contents persisted over the
- * bootloader upgrade AND the same section now needs more room, but
- * this is quite a remote possibility and it is ignored here.
- */
- p = cbmem_find(id);
- if (p) {
- printk(BIOS_NOTICE,
- "CBMEM section %x: using existing location at %p.\n",
- id, p);
- return p;
- }
-
- cbmem_toc = get_cbmem_toc();
-
- if (cbmem_toc == NULL) {
- return NULL;
- }
-
- if (cbmem_toc[0].magic != CBMEM_MAGIC) {
- printk(BIOS_ERR, "ERROR: CBMEM was not initialized yet.\n");
- return NULL;
- }
-
- /* Will the entry fit at all? */
- if (size > cbmem_toc[0].size) {
- printk(BIOS_ERR, "ERROR: Not enough memory for table %x\n", id);
- return NULL;
- }
-
- /* Align size to 512 byte blocks */
-
- size = ALIGN(size, 512) < cbmem_toc[0].size ?
- ALIGN(size, 512) : cbmem_toc[0].size;
-
- /* Now look for the first free/usable TOC entry */
- for (i = 0; i < MAX_CBMEM_ENTRIES; i++) {
- if (cbmem_toc[i].id == CBMEM_ID_NONE)
- break;
- }
-
- if (i >= MAX_CBMEM_ENTRIES) {
- printk(BIOS_ERR, "ERROR: No more CBMEM entries available.\n");
- return NULL;
- }
-
- printk(BIOS_DEBUG, "Adding CBMEM entry as no. %d\n", i);
-
- cbmem_toc[i] = (struct cbmem_entry) {
- .magic = CBMEM_MAGIC,
- .id = id,
- .base = cbmem_toc[0].base,
- .size = size
- };
-
- cbmem_toc[0].base += size;
- cbmem_toc[0].size -= size;
-
- return (void *)(uintptr_t)cbmem_toc[i].base;
-}
-
-void *cbmem_find(u32 id)
-{
- struct cbmem_entry *cbmem_toc;
- int i;
- cbmem_toc = get_cbmem_toc();
-
- if (cbmem_toc == NULL)
- return NULL;
-
- for (i = 0; i < MAX_CBMEM_ENTRIES; i++) {
- if (cbmem_toc[i].id == id)
- return (void *)(unsigned long)cbmem_toc[i].base;
- }
-
- return (void *)NULL;
-}
-
-/* Returns True if it was not initialized before. */
-int cbmem_recovery(int is_wakeup)
-{
- int found = cbmem_check_toc();
- int wipe = 0;
-
- /* CBMEM TOC is wiped clean when we are not waking up from S3
- * suspend. Boards with EARLY_CBMEM_INIT do this in romstage,
- * boards without EARLY_CBMEM_INIT do this in ramstage.
- */
-#if defined(__PRE_RAM__) && CONFIG_EARLY_CBMEM_INIT
- wipe = 1;
-#endif
-#if !defined(__PRE_RAM__) && !CONFIG_EARLY_CBMEM_INIT
- wipe = 1;
-#endif
-
- if (!is_wakeup && wipe)
- cbmem_initialize_empty();
-
- if (is_wakeup && !found) {
- cbmem_initialize_empty();
- cbmem_fail_resume();
- }
-
- /* Complete migration to CBMEM. */
- cbmem_run_init_hooks();
-
- return !found;
-}
-
-#ifndef __PRE_RAM__
-static void init_cbmem_post_device(void *unused)
-{
-#if CONFIG_HAVE_ACPI_RESUME
- cbmem_recovery(acpi_is_wakeup());
-#else
- cbmem_recovery(0);
-#endif
-}
-
-BOOT_STATE_INIT_ENTRIES(cbmem_bscb) = {
- BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_ENTRY,
- init_cbmem_post_device, NULL),
-};
-
-void cbmem_add_bootmem(void)
-{
- bootmem_add_range(cbmem_base, cbmem_size, LB_MEM_TABLE);
-}
-
-void cbmem_list(void)
-{
- struct cbmem_entry *cbmem_toc;
- int i;
- cbmem_toc = get_cbmem_toc();
-
- if (cbmem_toc == NULL)
- return;
-
- for (i = 0; i < MAX_CBMEM_ENTRIES; i++) {
-
- if (cbmem_toc[i].magic != CBMEM_MAGIC)
- continue;
- cbmem_print_entry(i, cbmem_toc[i].id, cbmem_toc[i].base,
- cbmem_toc[i].size);
- }
-}
-#endif
diff --git a/src/lib/rmodule.c b/src/lib/rmodule.c
index d7c2326f12..8d96e8d86f 100644
--- a/src/lib/rmodule.c
+++ b/src/lib/rmodule.c
@@ -17,6 +17,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <assert.h>
+#include <cbmem.h>
+#include <cbfs_core.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
@@ -249,10 +251,6 @@ int rmodule_calc_region(unsigned int region_alignment, size_t rmodule_size,
return region_alignment - sizeof(struct rmodule_header);
}
-#if CONFIG_DYNAMIC_CBMEM
-#include <cbmem.h>
-#include <cbfs_core.h>
-
int rmodule_stage_load(struct rmod_stage_load *rsl, struct cbfs_stage *stage)
{
struct rmodule rmod_stage;
@@ -307,5 +305,3 @@ int rmodule_stage_load_from_cbfs(struct rmod_stage_load *rsl)
return rmodule_stage_load(rsl, stage);
}
-
-#endif /* DYNAMIC_CBMEM */