Lines Matching refs:context

23 static inline uint8_t protocol_get_bmc_event_mask(struct mbox_context *context)  in protocol_get_bmc_event_mask()  argument
25 if (context->version == API_VERSION_1) { in protocol_get_bmc_event_mask()
40 int protocol_events_put(struct mbox_context *context, in protocol_events_put() argument
43 const uint8_t mask = protocol_get_bmc_event_mask(context); in protocol_events_put()
45 return ops->put_events(context, mask); in protocol_events_put()
55 int protocol_events_set(struct mbox_context *context, uint8_t bmc_event) in protocol_events_set() argument
57 const uint8_t mask = protocol_get_bmc_event_mask(context); in protocol_events_set()
64 context->bmc_events |= bmc_event; in protocol_events_set()
66 return context->transport->set_events(context, bmc_event, mask); in protocol_events_set()
77 int protocol_events_clear(struct mbox_context *context, uint8_t bmc_event) in protocol_events_clear() argument
79 const uint8_t mask = protocol_get_bmc_event_mask(context); in protocol_events_clear()
81 context->bmc_events &= ~bmc_event; in protocol_events_clear()
83 return context->transport->clear_events(context, bmc_event, mask); in protocol_events_clear()
86 static int protocol_negotiate_version(struct mbox_context *context,
89 static int protocol_v1_reset(struct mbox_context *context) in protocol_v1_reset() argument
91 return __protocol_reset(context); in protocol_v1_reset()
94 static int protocol_negotiate_version(struct mbox_context *context,
97 static int protocol_v1_get_info(struct mbox_context *context, in protocol_v1_get_info() argument
100 uint8_t old_version = context->version; in protocol_v1_get_info()
104 rc = protocol_negotiate_version(context, io->req.api_version); in protocol_v1_get_info()
111 windows_reset_all(context); in protocol_v1_get_info()
112 return context->protocol->get_info(context, io); in protocol_v1_get_info()
119 context->backend.block_size_shift = BLOCK_SIZE_SHIFT_V1; in protocol_v1_get_info()
121 1 << context->backend.block_size_shift, context->backend.block_size_shift); in protocol_v1_get_info()
124 windows_alloc_dirty_bytemap(context); in protocol_v1_get_info()
127 context->windows.default_size >> context->backend.block_size_shift; in protocol_v1_get_info()
129 context->windows.default_size >> context->backend.block_size_shift; in protocol_v1_get_info()
131 return lpc_map_memory(context); in protocol_v1_get_info()
134 static int protocol_v1_get_flash_info(struct mbox_context *context, in protocol_v1_get_flash_info() argument
137 io->resp.v1.flash_size = context->backend.flash_size; in protocol_v1_get_flash_info()
138 io->resp.v1.erase_size = 1 << context->backend.erase_size_shift; in protocol_v1_get_flash_info()
149 static inline uint16_t get_lpc_addr_shifted(struct mbox_context *context) in get_lpc_addr_shifted() argument
154 mem_offset = context->current->mem - context->mem; in get_lpc_addr_shifted()
156 lpc_addr = context->lpc_base + mem_offset; in get_lpc_addr_shifted()
160 return lpc_addr >> context->backend.block_size_shift; in get_lpc_addr_shifted()
174 static void blktrace_flush_start(struct mbox_context *context) in blktrace_flush_start() argument
176 struct blk_io_trace *trace = &context->trace; in blktrace_flush_start()
179 if (!context->blktracefd) in blktrace_flush_start()
182 if (!context->blktrace_start) { in blktrace_flush_start()
184 context->blktrace_start = blktrace_gettime(); in blktrace_flush_start()
189 trace->time = blktrace_gettime() - context->blktrace_start; in blktrace_flush_start()
190 trace->sector = context->current->flash_offset / 512; in blktrace_flush_start()
191 trace->bytes = context->current->size; in blktrace_flush_start()
192 if (context->current_is_write) in blktrace_flush_start()
201 write(context->blktracefd, trace, sizeof(*trace)); in blktrace_flush_start()
203 trace->time = blktrace_gettime() - context->blktrace_start; in blktrace_flush_start()
206 write(context->blktracefd, trace, sizeof(*trace)); in blktrace_flush_start()
209 static void blktrace_flush_done(struct mbox_context *context) in blktrace_flush_done() argument
211 struct blk_io_trace *trace = &context->trace; in blktrace_flush_done()
213 if (!context->blktracefd) in blktrace_flush_done()
217 trace->time = blktrace_gettime() - context->blktrace_start; in blktrace_flush_done()
220 write(context->blktracefd, trace, sizeof(*trace)); in blktrace_flush_done()
223 static void blktrace_window_start(struct mbox_context *context) in blktrace_window_start() argument
225 struct blk_io_trace *trace = &context->trace; in blktrace_window_start()
227 if (!context->blktracefd) in blktrace_window_start()
230 if (!context->blktrace_start) in blktrace_window_start()
231 context->blktrace_start = blktrace_gettime(); in blktrace_window_start()
235 trace->time = blktrace_gettime() - context->blktrace_start; in blktrace_window_start()
244 static void blktrace_window_done(struct mbox_context *context) in blktrace_window_done() argument
246 struct blk_io_trace *trace = &context->trace; in blktrace_window_done()
248 if (!context->blktracefd) in blktrace_window_done()
251 trace->sector = context->current->flash_offset / 512; in blktrace_window_done()
252 trace->bytes = context->current->size; in blktrace_window_done()
253 write(context->blktracefd, trace, sizeof(*trace)); in blktrace_window_done()
257 write(context->blktracefd, trace, sizeof(*trace)); in blktrace_window_done()
260 trace->time = blktrace_gettime() - context->blktrace_start; in blktrace_window_done()
263 write(context->blktracefd, trace, sizeof(*trace)); in blktrace_window_done()
266 static int protocol_v1_create_window(struct mbox_context *context, in protocol_v1_create_window() argument
269 struct backend *backend = &context->backend; in protocol_v1_create_window()
283 if (context->current) { in protocol_v1_create_window()
290 if (context->current_is_write) { in protocol_v1_create_window()
291 blktrace_flush_start(context); in protocol_v1_create_window()
292 rc = context->protocol->flush(context, NULL); in protocol_v1_create_window()
293 blktrace_flush_done(context); in protocol_v1_create_window()
299 windows_close_current(context, FLAGS_NONE); in protocol_v1_create_window()
305 blktrace_window_start(context); in protocol_v1_create_window()
306 context->current = windows_search(context, offset, in protocol_v1_create_window()
307 context->version == API_VERSION_1); in protocol_v1_create_window()
309 if (!context->current) { /* No existing window */ in protocol_v1_create_window()
311 rc = windows_create_map(context, &context->current, in protocol_v1_create_window()
313 context->version == API_VERSION_1); in protocol_v1_create_window()
320 blktrace_window_done(context); in protocol_v1_create_window()
322 context->current_is_write = !io->req.ro; in protocol_v1_create_window()
325 context->current->mem, context->current->size, in protocol_v1_create_window()
326 context->current->flash_offset); in protocol_v1_create_window()
328 io->resp.lpc_address = get_lpc_addr_shifted(context); in protocol_v1_create_window()
333 static int protocol_v1_mark_dirty(struct mbox_context *context, in protocol_v1_mark_dirty() argument
340 if (!(context->current && context->current_is_write)) { in protocol_v1_mark_dirty()
346 off = offset - ((context->current->flash_offset) >> in protocol_v1_mark_dirty()
347 context->backend.block_size_shift); in protocol_v1_mark_dirty()
351 offset << context->backend.block_size_shift, in protocol_v1_mark_dirty()
352 context->current->flash_offset); in protocol_v1_mark_dirty()
361 size = align_up(size, 1 << context->backend.block_size_shift); in protocol_v1_mark_dirty()
362 size >>= context->backend.block_size_shift; in protocol_v1_mark_dirty()
365 offset << context->backend.block_size_shift, in protocol_v1_mark_dirty()
366 size << context->backend.block_size_shift); in protocol_v1_mark_dirty()
368 return window_set_bytemap(context, context->current, offset, size, in protocol_v1_mark_dirty()
372 static int generic_flush(struct mbox_context *context) in generic_flush() argument
383 context->current->mem, context->current->size, in generic_flush()
384 context->current->flash_offset); in generic_flush()
391 for (i = 0; i < (context->current->size >> context->backend.block_size_shift); in generic_flush()
393 uint8_t cur = context->current->dirty_bmap[i]; in generic_flush()
401 rc = window_flush(context, offset, count, in generic_flush()
411 rc = window_flush(context, offset, count, in generic_flush()
424 rc = window_flush(context, offset, count, prev); in generic_flush()
431 return window_set_bytemap(context, context->current, 0, in generic_flush()
432 context->current->size >> in generic_flush()
433 context->backend.block_size_shift, in generic_flush()
437 static int protocol_v1_flush(struct mbox_context *context, in protocol_v1_flush() argument
442 if (!(context->current && context->current_is_write)) { in protocol_v1_flush()
455 rc = protocol_v1_mark_dirty(context, mdio); in protocol_v1_flush()
461 return generic_flush(context); in protocol_v1_flush()
464 static int protocol_v1_close(struct mbox_context *context, in protocol_v1_close() argument
470 if (!context->current) { in protocol_v1_close()
475 if (context->current_is_write) { in protocol_v1_close()
476 rc = protocol_v1_flush(context, NULL); in protocol_v1_close()
484 windows_close_current(context, io->req.flags); in protocol_v1_close()
489 static int protocol_v1_ack(struct mbox_context *context, in protocol_v1_ack() argument
492 return protocol_events_clear(context, in protocol_v1_ack()
502 static uint16_t get_suggested_timeout(struct mbox_context *context) in get_suggested_timeout() argument
504 struct window_context *window = windows_find_largest(context); in get_suggested_timeout()
515 static int protocol_v2_get_info(struct mbox_context *context, in protocol_v2_get_info() argument
518 uint8_t old_version = context->version; in protocol_v2_get_info()
522 rc = protocol_negotiate_version(context, io->req.api_version); in protocol_v2_get_info()
529 windows_reset_all(context); in protocol_v2_get_info()
530 return context->protocol->get_info(context, io); in protocol_v2_get_info()
539 windows_alloc_dirty_bytemap(context); in protocol_v2_get_info()
541 io->resp.v2.block_size_shift = context->backend.block_size_shift; in protocol_v2_get_info()
543 1 << context->backend.block_size_shift, context->backend.block_size_shift); in protocol_v2_get_info()
545 io->resp.v2.timeout = get_suggested_timeout(context); in protocol_v2_get_info()
547 return lpc_map_memory(context); in protocol_v2_get_info()
550 static int protocol_v2_get_flash_info(struct mbox_context *context, in protocol_v2_get_flash_info() argument
553 struct backend *backend = &context->backend; in protocol_v2_get_flash_info()
563 static int protocol_v2_create_window(struct mbox_context *context, in protocol_v2_create_window() argument
568 rc = protocol_v1_create_window(context, io); in protocol_v2_create_window()
572 io->resp.size = context->current->size >> context->backend.block_size_shift; in protocol_v2_create_window()
573 io->resp.offset = context->current->flash_offset >> in protocol_v2_create_window()
574 context->backend.block_size_shift; in protocol_v2_create_window()
579 static int protocol_v2_mark_dirty(struct mbox_context *context, in protocol_v2_mark_dirty() argument
582 if (!(context->current && context->current_is_write)) { in protocol_v2_mark_dirty()
588 io->req.v2.offset << context->backend.block_size_shift, in protocol_v2_mark_dirty()
589 io->req.v2.size << context->backend.block_size_shift); in protocol_v2_mark_dirty()
591 return window_set_bytemap(context, context->current, io->req.v2.offset, in protocol_v2_mark_dirty()
595 static int protocol_v2_erase(struct mbox_context *context, in protocol_v2_erase() argument
601 if (!(context->current && context->current_is_write)) { in protocol_v2_erase()
607 io->req.offset << context->backend.block_size_shift, in protocol_v2_erase()
608 io->req.size << context->backend.block_size_shift); in protocol_v2_erase()
610 rc = window_set_bytemap(context, context->current, io->req.offset, in protocol_v2_erase()
617 start = io->req.offset << context->backend.block_size_shift; in protocol_v2_erase()
618 len = io->req.size << context->backend.block_size_shift; in protocol_v2_erase()
619 memset(context->current->mem + start, 0xFF, len); in protocol_v2_erase()
624 static int protocol_v2_flush(struct mbox_context *context __attribute__((unused)), in protocol_v2_flush() argument
627 if (!(context->current && context->current_is_write)) { in protocol_v2_flush()
632 return generic_flush(context); in protocol_v2_flush()
635 static int protocol_v2_close(struct mbox_context *context, in protocol_v2_close() argument
641 if (!context->current) { in protocol_v2_close()
646 if (context->current_is_write) { in protocol_v2_close()
647 rc = protocol_v2_flush(context, NULL); in protocol_v2_close()
655 windows_close_current(context, io->req.flags); in protocol_v2_close()
690 static int protocol_negotiate_version(struct mbox_context *context, in protocol_negotiate_version() argument
697 context->version = (requested > API_MAX_VERSION) ? in protocol_negotiate_version()
700 context->protocol = protocol_ops_map[context->version]; in protocol_negotiate_version()
702 return context->version; in protocol_negotiate_version()
705 int protocol_init(struct mbox_context *context) in protocol_init() argument
707 protocol_negotiate_version(context, API_MAX_VERSION); in protocol_init()
712 void protocol_free(struct mbox_context *context __attribute__((unused))) in protocol_free() argument
718 int __protocol_reset(struct mbox_context *context) in __protocol_reset() argument
723 windows_reset_all(context); in __protocol_reset()
725 rc = backend_reset(&context->backend, context->mem, context->mem_size); in __protocol_reset()
734 return lpc_map_flash(context); in __protocol_reset()
737 return lpc_map_memory(context); in __protocol_reset()
741 int protocol_reset(struct mbox_context *context) in protocol_reset() argument
745 rc = protocol_events_clear(context, BMC_EVENT_DAEMON_READY); in protocol_reset()
751 rc = __protocol_reset(context); in protocol_reset()
757 rc = protocol_events_set(context, in protocol_reset()