From 06ece7de93a6e0820fa21a86d2312c6fd9209aea Mon Sep 17 00:00:00 2001 From: Aaron Durbin Date: Fri, 14 Feb 2014 00:30:04 -0600 Subject: chromeos: provide option to dynamically allocate ram oops buffer Fixing the location of the ram oops buffer can lead to certain kernel and boot loaders being confused when there is a ram reservation low in the address space. Alternatively provide a mechanism to allocate the ram oops buffer in cbmem. As cbmem is usually high in the address space it avoids low reservation confusion. The patch uncondtionally provides a GOOG9999 ACPI device with a single memory resource describing the memory region used for the ramoops region. BUG=None BRANCH=baytrail,haswell TEST=Built and booted with and w/o dynamic ram oops. With the corresponding kernel change things behave correctly. Change-Id: Ide2bb4434768c9f9b90e125adae4324cb1d2d073 Signed-off-by: Aaron Durbin Reviewed-on: http://review.coreboot.org/5257 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer --- src/vendorcode/google/chromeos/ramoops.c | 99 ++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 src/vendorcode/google/chromeos/ramoops.c (limited to 'src/vendorcode/google/chromeos/ramoops.c') diff --git a/src/vendorcode/google/chromeos/ramoops.c b/src/vendorcode/google/chromeos/ramoops.c new file mode 100644 index 0000000000..500bc907bc --- /dev/null +++ b/src/vendorcode/google/chromeos/ramoops.c @@ -0,0 +1,99 @@ +/* + * 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. + * + * 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 +#include +#include +#include +#include +#include +#include "chromeos.h" + +static void set_ramoops(chromeos_acpi_t *chromeos, void *ram_oops, size_t size) +{ + if (chromeos == NULL) { + printk(BIOS_DEBUG, "chromeos gnvs is NULL. ramoops not set.\n"); + return; + } + + printk(BIOS_DEBUG, "Ramoops buffer: 0x%zx@0x%p.\n", size, ram_oops); + chromeos->ramoops_base = (uintptr_t)ram_oops; + chromeos->ramoops_len = size; +} + +static void reserve_ram_oops_dynamic(chromeos_acpi_t *chromeos) +{ + const size_t size = CONFIG_CHROMEOS_RAMOOPS_RAM_SIZE; + void *ram_oops; + + if (!IS_ENABLED(CONFIG_CHROMEOS_RAMOOPS_DYNAMIC)) + return; + + ram_oops = cbmem_add(CBMEM_ID_RAM_OOPS, size); + + set_ramoops(chromeos, ram_oops, size); +} + +#if CONFIG_CHROMEOS_RAMOOPS_DYNAMIC +static inline void set_global_chromeos_pointer(chromeos_acpi_t *chromeos) {} +#else /* !CONFIG_CHROMEOS_RAMOOPS_DYNAMIC */ + +static const unsigned long ramoops_base = CONFIG_CHROMEOS_RAMOOPS_RAM_START; +static const unsigned long ramoops_size = CONFIG_CHROMEOS_RAMOOPS_RAM_SIZE; + +/* + * Save pointer to chromeos structure in memory. This is needed because the + * memory reservation is not done when chromeos_init() is called. However, + * the pointer to the chromeos_acpi_t structure is needed to update the + * fields with the rserved base and size. + */ +static chromeos_acpi_t *g_chromeos; + +static void set_global_chromeos_pointer(chromeos_acpi_t *chromeos) +{ + g_chromeos = chromeos; +} + +static void update_gnvs(void *arg) +{ + chromeos_acpi_t **chromeos = arg; + + set_ramoops(*chromeos, (void *)ramoops_base, ramoops_size); +} + +static BOOT_STATE_CALLBACK(bscb_ramoops, update_gnvs, &g_chromeos); + +void chromeos_reserve_ram_oops(struct device *dev, int idx) +{ + const unsigned long base = ramoops_base >> 10; + const unsigned long size = ramoops_size >> 10; + + reserved_ram_resource(dev, idx, base, size); + + boot_state_sched_on_exit(&bscb_ramoops, BS_WRITE_TABLES); +} +#endif /* CONFIG_CHROMEOS_RAMOOPS_DYNAMIC */ + +void chromeos_ram_oops_init(chromeos_acpi_t *chromeos) +{ + set_global_chromeos_pointer(chromeos); + reserve_ram_oops_dynamic(chromeos); +} + -- cgit v1.2.3