blob: ae72133d11c26ac974ff29f1c6adbbbf968356b4 [file] [log] [blame]
Angel Pons3ef916f2020-04-02 23:49:13 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Aaron Durbin06ece7d2014-02-14 00:30:04 -06002
3
4#include <stddef.h>
5#include <stdint.h>
Furquan Shaikhefb546d2014-11-08 17:34:27 -08006#include <boot/coreboot_tables.h>
Aaron Durbin06ece7d2014-02-14 00:30:04 -06007#include <bootstate.h>
8#include <console/console.h>
9#include <cbmem.h>
10#include <device/device.h>
11#include "chromeos.h"
12
Julius Wernercd49cce2019-03-05 16:53:33 -080013#if CONFIG(HAVE_ACPI_TABLES)
Furquan Shaikhaed887f2014-11-08 17:32:38 -080014
Aaron Durbin06ece7d2014-02-14 00:30:04 -060015static void set_ramoops(chromeos_acpi_t *chromeos, void *ram_oops, size_t size)
16{
17 if (chromeos == NULL) {
18 printk(BIOS_DEBUG, "chromeos gnvs is NULL. ramoops not set.\n");
19 return;
20 }
21
Julius Werner540a9802019-12-09 13:03:29 -080022 printk(BIOS_DEBUG, "Ramoops buffer: 0x%zx@%p.\n", size, ram_oops);
Aaron Durbin06ece7d2014-02-14 00:30:04 -060023 chromeos->ramoops_base = (uintptr_t)ram_oops;
24 chromeos->ramoops_len = size;
25}
26
Kyösti Mälkkifce36e42021-02-10 19:31:26 +020027void chromeos_ram_oops_init(chromeos_acpi_t *chromeos)
Aaron Durbin06ece7d2014-02-14 00:30:04 -060028{
29 const size_t size = CONFIG_CHROMEOS_RAMOOPS_RAM_SIZE;
30 void *ram_oops;
31
Aaron Durbin06ece7d2014-02-14 00:30:04 -060032 ram_oops = cbmem_add(CBMEM_ID_RAM_OOPS, size);
33
34 set_ramoops(chromeos, ram_oops, size);
35}
36
Kyösti Mälkkifce36e42021-02-10 19:31:26 +020037#else
Furquan Shaikhefb546d2014-11-08 17:34:27 -080038
39static void ramoops_alloc(void *arg)
40{
41 const size_t size = CONFIG_CHROMEOS_RAMOOPS_RAM_SIZE;
42
43 if (size == 0)
44 return;
45
46 if (cbmem_add(CBMEM_ID_RAM_OOPS, size) == NULL)
47 printk(BIOS_ERR, "Could not allocate RAMOOPS buffer\n");
48}
49
50BOOT_STATE_INIT_ENTRY(BS_WRITE_TABLES, BS_ON_ENTRY, ramoops_alloc, NULL);
51
52#endif
53
54void lb_ramoops(struct lb_header *header)
55{
56 void *buffer = cbmem_find(CBMEM_ID_RAM_OOPS);
57
58 if (buffer == NULL)
59 return;
60
61 struct lb_range *ramoops;
62 ramoops = (struct lb_range *)lb_new_record(header);
63 ramoops->tag = LB_TAG_RAM_OOPS;
64 ramoops->size = sizeof(*ramoops);
65 ramoops->range_start = (uintptr_t)buffer;
66 ramoops->range_size = CONFIG_CHROMEOS_RAMOOPS_RAM_SIZE;
67}