Lines Matching full:state
10 #include <asm/state.h>
12 /* Main state record for the sandbox */
14 static struct sandbox_state *state; /* Pointer to current state record */ variable
18 void *blob = state->state_fdt; in state_ensure_space()
41 state->state_fdt = buf; in state_ensure_space()
45 static int state_read_file(struct sandbox_state *state, const char *fname) in state_read_file() argument
53 printf("Cannot find sandbox state file '%s'\n", fname); in state_read_file()
56 state->state_fdt = os_malloc(size); in state_read_file()
57 if (!state->state_fdt) { in state_read_file()
58 puts("No memory to read sandbox state\n"); in state_read_file()
63 printf("Cannot open sandbox state file '%s'\n", fname); in state_read_file()
67 if (os_read(fd, state->state_fdt, size) != size) { in state_read_file()
68 printf("Cannot read sandbox state file '%s'\n", fname); in state_read_file()
78 os_free(state->state_fdt); in state_read_file()
79 state->state_fdt = NULL; in state_read_file()
85 * sandbox_read_state_nodes() - Read state associated with a driver
88 * each one, to read in the state.
91 * single global state for that driver.
93 * @state: Sandbox state
94 * @io: Method to use for reading state
95 * @blob: FDT containing state
98 int sandbox_read_state_nodes(struct sandbox_state *state, in sandbox_read_state_nodes() argument
118 printf("Unable to read state for '%s'\n", io->compat); in sandbox_read_state_nodes()
125 * If we got no saved state, call the read function once without a in sandbox_read_state_nodes()
126 * node, to set up the global state. in sandbox_read_state_nodes()
132 printf("Unable to read global state for '%s'\n", in sandbox_read_state_nodes()
141 int sandbox_read_state(struct sandbox_state *state, const char *fname) in sandbox_read_state() argument
148 if (state->read_state && fname) { in sandbox_read_state()
149 ret = state_read_file(state, fname); in sandbox_read_state()
150 if (ret == -ENOENT && state->ignore_missing_state_on_read) in sandbox_read_state()
156 /* Call all the state read functions */ in sandbox_read_state()
158 blob = state->state_fdt; in sandbox_read_state()
161 ret = sandbox_read_state_nodes(state, io, blob); in sandbox_read_state()
166 if (state->read_state && fname) { in sandbox_read_state()
167 debug("Read sandbox state from '%s'%s\n", fname, in sandbox_read_state()
175 * sandbox_write_state_node() - Write state associated with a driver
177 * This calls the write function to write out global state for that driver.
179 * TODO(sjg@chromium.org): Support writing out state from multiple drivers
183 * @state: Sandbox state
184 * @io: Method to use for writing state
188 int sandbox_write_state_node(struct sandbox_state *state, in sandbox_write_state_node() argument
200 printf("Failed to add more space for state\n"); in sandbox_write_state_node()
205 blob = state->state_fdt; in sandbox_write_state_node()
224 debug("Write state for '%s' to node %d\n", io->compat, node); in sandbox_write_state_node()
227 printf("Unable to write state for '%s'\n", io->compat); in sandbox_write_state_node()
234 int sandbox_write_state(struct sandbox_state *state, const char *fname) in sandbox_write_state() argument
242 /* Create a state FDT if we don't have one */ in sandbox_write_state()
243 if (!state->state_fdt) { in sandbox_write_state()
245 state->state_fdt = os_malloc(size); in sandbox_write_state()
246 if (!state->state_fdt) { in sandbox_write_state()
250 ret = fdt_create_empty_tree(state->state_fdt, size); in sandbox_write_state()
252 printf("Cannot create empty state FDT: %s\n", in sandbox_write_state()
259 /* Call all the state write funtcions */ in sandbox_write_state()
264 ret = sandbox_write_state_node(state, io); in sandbox_write_state()
272 printf("Could not write sandbox state\n"); in sandbox_write_state()
276 ret = fdt_pack(state->state_fdt); in sandbox_write_state()
278 printf("Cannot pack state FDT: %s\n", fdt_strerror(ret)); in sandbox_write_state()
282 size = fdt_totalsize(state->state_fdt); in sandbox_write_state()
285 printf("Cannot open sandbox state file '%s'\n", fname); in sandbox_write_state()
289 if (os_write(fd, state->state_fdt, size) != size) { in sandbox_write_state()
290 printf("Cannot write sandbox state file '%s'\n", fname); in sandbox_write_state()
296 debug("Wrote sandbox state to '%s'%s\n", fname, in sandbox_write_state()
303 os_free(state->state_fdt); in sandbox_write_state()
314 fdt_getprop(state->state_fdt, node, prop_name, &len); in state_setprop()
322 blob = state->state_fdt; in state_setprop()
336 assert(state); in state_get_current()
337 return state; in state_get_current()
342 struct sandbox_state *state = state_get_current(); in state_set_skip_delays() local
344 state->skip_delays = skip_delays; in state_set_skip_delays()
349 struct sandbox_state *state = state_get_current(); in state_get_skip_delays() local
351 return state->skip_delays; in state_get_skip_delays()
354 void state_reset_for_test(struct sandbox_state *state) in state_reset_for_test() argument
357 state->last_sysreset = SYSRESET_COUNT; in state_reset_for_test()
358 state->sysreset_allowed[SYSRESET_POWER] = true; in state_reset_for_test()
360 memset(&state->wdt, '\0', sizeof(state->wdt)); in state_reset_for_test()
361 memset(state->spi, '\0', sizeof(state->spi)); in state_reset_for_test()
368 INIT_LIST_HEAD(&state->mapmem_head); in state_reset_for_test()
369 state->next_tag = state->ram_size; in state_reset_for_test()
374 state = &main_state; in state_init()
376 state->ram_size = CONFIG_SYS_SDRAM_SIZE; in state_init()
377 state->ram_buf = os_malloc(state->ram_size); in state_init()
378 assert(state->ram_buf); in state_init()
380 state_reset_for_test(state); in state_init()
394 state = &main_state; in state_uninit()
396 if (state->write_ram_buf) { in state_uninit()
397 err = os_write_ram_buf(state->ram_buf_fname); in state_uninit()
404 if (state->write_state) { in state_uninit()
405 if (sandbox_write_state(state, state->state_fname)) { in state_uninit()
406 printf("Failed to write sandbox state\n"); in state_uninit()
412 if (state->ram_buf_rm && state->ram_buf_fname) in state_uninit()
413 os_unlink(state->ram_buf_fname); in state_uninit()
416 if (state->jumped_fname) in state_uninit()
417 os_unlink(state->jumped_fname); in state_uninit()
419 if (state->state_fdt) in state_uninit()
420 os_free(state->state_fdt); in state_uninit()
421 memset(state, '\0', sizeof(*state)); in state_uninit()