xref: /rk3399_rockchip-uboot/arch/sandbox/cpu/state.c (revision 5c2859cdc30287b3593d9df88f48c31eecb0bbed)
1 /*
2  * Copyright (c) 2011-2012 The Chromium OS Authors.
3  * SPDX-License-Identifier:	GPL-2.0+
4  */
5 
6 #include <common.h>
7 #include <os.h>
8 #include <asm/state.h>
9 
10 /* Main state record for the sandbox */
11 static struct sandbox_state main_state;
12 static struct sandbox_state *state;	/* Pointer to current state record */
13 
14 void state_record_exit(enum exit_type_id exit_type)
15 {
16 	state->exit_type = exit_type;
17 }
18 
19 struct sandbox_state *state_get_current(void)
20 {
21 	assert(state);
22 	return state;
23 }
24 
25 int state_init(void)
26 {
27 	state = &main_state;
28 
29 	state->ram_size = CONFIG_SYS_SDRAM_SIZE;
30 	state->ram_buf = os_malloc(state->ram_size);
31 	assert(state->ram_buf);
32 
33 	/*
34 	 * Example of how to use GPIOs:
35 	 *
36 	 * sandbox_gpio_set_direction(170, 0);
37 	 * sandbox_gpio_set_value(170, 0);
38 	 */
39 	return 0;
40 }
41 
42 int state_uninit(void)
43 {
44 	int err;
45 
46 	state = &main_state;
47 
48 	if (state->write_ram_buf) {
49 		err = os_write_ram_buf(state->ram_buf_fname);
50 		if (err) {
51 			printf("Failed to write RAM buffer\n");
52 			return err;
53 		}
54 	}
55 
56 	return 0;
57 }
58