Lines Matching refs:context
59 static int init_window_mem(struct mbox_context *context) in init_window_mem() argument
61 void *mem_location = context->mem; in init_window_mem()
71 for (i = 0; i < context->windows.num; i++) { in init_window_mem()
72 uint32_t size = context->windows.window[i].size; in init_window_mem()
75 context->windows.window[i].mem = mem_location; in init_window_mem()
77 if (mem_location > (context->mem + context->mem_size)) { in init_window_mem()
81 MSG_ERR("Mem size: 0x%.8x\n", context->mem_size); in init_window_mem()
94 int windows_init(struct mbox_context *context) in windows_init() argument
99 if (!context->windows.default_size) { in windows_init()
101 context->windows.default_size = 1 << 20; in windows_init()
103 MSG_INFO("Window size: 0x%.8x\n", context->windows.default_size); in windows_init()
104 if (!context->windows.num) { in windows_init()
106 context->windows.num = context->mem_size / in windows_init()
107 context->windows.default_size; in windows_init()
109 MSG_INFO("Number of windows: %d\n", context->windows.num); in windows_init()
111 context->windows.window = calloc(context->windows.num, in windows_init()
112 sizeof(*context->windows.window)); in windows_init()
113 if (!context->windows.window) { in windows_init()
118 for (i = 0; i < context->windows.num; i++) { in windows_init()
119 init_window_state(&context->windows.window[i], in windows_init()
120 context->windows.default_size); in windows_init()
123 return init_window_mem(context); in windows_init()
130 void windows_free(struct mbox_context *context) in windows_free() argument
135 if (context->windows.window) { in windows_free()
136 for (i = 0; i < context->windows.num; i++) { in windows_free()
137 free(context->windows.window[i].dirty_bmap); in windows_free()
139 free(context->windows.window); in windows_free()
160 int window_flush_v1(struct mbox_context *context, in window_flush_v1() argument
168 flash_offset = context->current->flash_offset + offset_bytes; in window_flush_v1()
179 1 << context->backend.erase_size_shift); in window_flush_v1()
183 1 << context->backend.erase_size_shift) - in window_flush_v1()
190 if (low_mem.flash_offset < context->current->flash_offset) { in window_flush_v1()
197 rc = backend_copy(&context->backend, low_mem.flash_offset, in window_flush_v1()
204 (context->current->flash_offset + context->current->size)) { in window_flush_v1()
212 rc = backend_copy(&context->backend, high_mem.flash_offset, in window_flush_v1()
223 rc = backend_erase(&context->backend, low_mem.flash_offset, in window_flush_v1()
234 rc = backend_write(&context->backend, low_mem.flash_offset, in window_flush_v1()
240 rc = backend_write(&context->backend, flash_offset, in window_flush_v1()
241 context->current->mem + offset_bytes, count_bytes); in window_flush_v1()
251 rc = backend_write(&context->backend, high_mem.flash_offset, in window_flush_v1()
258 rc = backend_write(&context->backend, high_mem.flash_offset, in window_flush_v1()
259 context->current->mem + offset_bytes + in window_flush_v1()
281 int window_flush(struct mbox_context *context, uint32_t offset, in window_flush() argument
285 uint32_t flash_offset, count_bytes = count << context->backend.block_size_shift; in window_flush()
286 uint32_t offset_bytes = offset << context->backend.block_size_shift; in window_flush()
290 flash_offset = context->current->flash_offset + offset_bytes; in window_flush()
291 rc = backend_erase(&context->backend, flash_offset, in window_flush()
304 if (context->backend.erase_size_shift != in window_flush()
305 context->backend.block_size_shift) { in window_flush()
306 return window_flush_v1(context, offset_bytes, in window_flush()
309 flash_offset = context->current->flash_offset + offset_bytes; in window_flush()
312 rc = backend_erase(&context->backend, flash_offset, in window_flush()
319 rc = backend_write(&context->backend, flash_offset, in window_flush()
320 context->current->mem + offset_bytes, in window_flush()
342 void windows_alloc_dirty_bytemap(struct mbox_context *context) in windows_alloc_dirty_bytemap() argument
347 for (i = 0; i < context->windows.num; i++) { in windows_alloc_dirty_bytemap()
348 cur = &context->windows.window[i]; in windows_alloc_dirty_bytemap()
352 cur->dirty_bmap = calloc((context->windows.default_size >> in windows_alloc_dirty_bytemap()
353 context->backend.block_size_shift), in windows_alloc_dirty_bytemap()
368 int window_set_bytemap(struct mbox_context *context, struct window_context *cur, in window_set_bytemap() argument
371 if (offset + size > (cur->size >> context->backend.block_size_shift)) { in window_set_bytemap()
374 offset << context->backend.block_size_shift, in window_set_bytemap()
375 size << context->backend.block_size_shift, in window_set_bytemap()
376 cur->size << context->backend.block_size_shift); in window_set_bytemap()
395 void windows_close_current(struct mbox_context *context, uint8_t flags) in windows_close_current() argument
400 context->current->age = 0; in windows_close_current()
403 context->current = NULL; in windows_close_current()
404 context->current_is_write = false; in windows_close_current()
412 void window_reset(struct mbox_context *context, struct window_context *window) in window_reset() argument
415 window->size = context->windows.default_size; in window_reset()
417 window_set_bytemap(context, window, 0, in window_reset()
418 window->size >> context->backend.block_size_shift, in window_reset()
430 bool windows_reset_all(struct mbox_context *context) in windows_reset_all() argument
432 bool closed = context->current; in windows_reset_all()
437 context->windows.max_age = 0; in windows_reset_all()
441 if (context->current) { in windows_reset_all()
442 windows_close_current(context, FLAGS_NONE); in windows_reset_all()
445 for (i = 0; i < context->windows.num; i++) { in windows_reset_all()
446 window_reset(context, &context->windows.window[i]); in windows_reset_all()
458 struct window_context *windows_find_oldest(struct mbox_context *context) in windows_find_oldest() argument
461 uint32_t min_age = context->windows.max_age + 1; in windows_find_oldest()
464 for (i = 0; i < context->windows.num; i++) { in windows_find_oldest()
465 cur = &context->windows.window[i]; in windows_find_oldest()
482 struct window_context *windows_find_largest(struct mbox_context *context) in windows_find_largest() argument
488 for (i = 0; i < context->windows.num; i++) { in windows_find_largest()
489 cur = &context->windows.window[i]; in windows_find_largest()
514 struct window_context *windows_search(struct mbox_context *context, in windows_search() argument
522 for (i = 0; i < context->windows.num; i++) { in windows_search()
523 cur = &context->windows.window[i]; in windows_search()
537 cur->age = ++(context->windows.max_age); in windows_search()
560 int windows_create_map(struct mbox_context *context, in windows_create_map() argument
571 cur = windows_search(context, FLASH_OFFSET_UNINIT, true); in windows_create_map()
576 cur = windows_find_oldest(context); in windows_create_map()
577 window_reset(context, cur); in windows_create_map()
584 if (backend_align_offset(&(context->backend), &offset, cur->size)) { in windows_create_map()
589 if (offset > context->backend.flash_size) { in windows_create_map()
592 } else if ((offset + cur->size) > context->backend.flash_size) { in windows_create_map()
603 if (context->version == API_VERSION_1) { in windows_create_map()
604 cur->size = align_down(context->backend.flash_size - offset, in windows_create_map()
605 1 << context->backend.block_size_shift); in windows_create_map()
611 cur->size = context->backend.flash_size - offset; in windows_create_map()
616 rc = backend_copy(&context->backend, offset, cur->mem, cur->size); in windows_create_map()
619 window_reset(context, cur); in windows_create_map()
628 cur->size = align_up(rc, (1ULL << context->backend.block_size_shift)); in windows_create_map()
640 if (context->version == API_VERSION_1) { in windows_create_map()
648 tmp = windows_search(context, i, false); in windows_create_map()
650 window_reset(context, tmp); in windows_create_map()
657 window_set_bytemap(context, cur, 0, in windows_create_map()
658 cur->size >> context->backend.block_size_shift, in windows_create_map()
663 cur->age = ++(context->windows.max_age); in windows_create_map()