summaryrefslogtreecommitdiff
path: root/chip/ish/ish_persistent_data.c
blob: 149acaeadef98f53b643cb81c96c294954a82949 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* Copyright 2019 The ChromiumOS Authors
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "common.h"
#include "ec_commands.h"
#include "config.h"
#include "hooks.h"
#include "system.h"
#include "ish_persistent_data.h"

#define PERSISTENT_DATA_MAGIC 0x49534864 /* "ISHd" */

struct ish_persistent_data ish_persistent_data = {
	.magic = PERSISTENT_DATA_MAGIC,
	.reset_flags = EC_RESET_FLAG_POWER_ON,
	.watchdog_counter = 0,
	.panic_data = { 0 },
};

/*
 * When AON task firmware is not available (perhaps in the early
 * stages of bringing up a new board), we have no way to persist data
 * across reset. Allocate a memory region for "persistent data" which
 * will never persist, this way we can use ish_persistent_data in a
 * consistent manner without having to worry if the AON task firmware
 * is available.
 *
 * Otherwise (AON task firmware is available), the
 * ish_persistent_data_aon symbol is exported by the linker script.
 */
#ifdef CONFIG_ISH_PM_AONTASK
extern struct ish_persistent_data ish_persistent_data_aon;
#else
static struct ish_persistent_data ish_persistent_data_aon;
#endif

void ish_persistent_data_init(void)
{
	if (ish_persistent_data_aon.magic == PERSISTENT_DATA_MAGIC) {
		/* Stored data is valid, load a copy */
		memcpy(&ish_persistent_data, &ish_persistent_data_aon,
		       sizeof(struct ish_persistent_data));

		/* Invalidate stored data, in case commit fails to happen */
		ish_persistent_data_aon.magic = 0;
	}

	/* Update the system module's copy of the reset flags */
	system_set_reset_flags(chip_read_reset_flags());
}

void ish_persistent_data_commit(void)
{
	memcpy(&ish_persistent_data_aon, &ish_persistent_data,
	       sizeof(struct ish_persistent_data));
}