Lines Matching refs:context
39 static int write_bmc_event_reg(struct mbox_context *context) in write_bmc_event_reg() argument
44 rc = lseek(context->fds[MBOX_FD].fd, MBOX_BMC_EVENT, SEEK_SET); in write_bmc_event_reg()
52 rc = write(context->fds[MBOX_FD].fd, &context->bmc_events, 1); in write_bmc_event_reg()
60 rc = lseek(context->fds[MBOX_FD].fd, 0, SEEK_SET); in write_bmc_event_reg()
78 int set_bmc_events(struct mbox_context *context, uint8_t bmc_event, in set_bmc_events() argument
83 switch (context->version) { in set_bmc_events()
92 context->bmc_events |= (bmc_event & mask); in set_bmc_events()
93 MSG_DBG("BMC Events set to: 0x%.2x\n", context->bmc_events); in set_bmc_events()
95 return write_back ? write_bmc_event_reg(context) : 0; in set_bmc_events()
106 int clr_bmc_events(struct mbox_context *context, uint8_t bmc_event, in clr_bmc_events() argument
109 context->bmc_events &= ~bmc_event; in clr_bmc_events()
110 MSG_DBG("BMC Events clear to: 0x%.2x\n", context->bmc_events); in clr_bmc_events()
112 return write_back ? write_bmc_event_reg(context) : 0; in clr_bmc_events()
122 int mbox_handle_reset(struct mbox_context *context, in mbox_handle_reset() argument
126 reset_all_windows(context, NO_BMC_EVENT); in mbox_handle_reset()
127 return reset_lpc(context); in mbox_handle_reset()
136 static uint16_t get_suggested_timeout(struct mbox_context *context) in get_suggested_timeout() argument
138 struct window_context *window = find_largest_window(context); in get_suggested_timeout()
171 int mbox_handle_mbox_info(struct mbox_context *context, in mbox_handle_mbox_info() argument
175 uint8_t old_api_version = context->version; in mbox_handle_mbox_info()
185 context->version = mbox_api_version; in mbox_handle_mbox_info()
186 MSG_INFO("Using Protocol Version: %d\n", context->version); in mbox_handle_mbox_info()
194 rc = point_to_memory(context); in mbox_handle_mbox_info()
199 switch (context->version) { in mbox_handle_mbox_info()
201 context->block_size_shift = BLOCK_SIZE_SHIFT_V1; in mbox_handle_mbox_info()
204 context->block_size_shift = log_2(context->mtd_info.erasesize); in mbox_handle_mbox_info()
208 1 << context->block_size_shift, context->block_size_shift); in mbox_handle_mbox_info()
212 alloc_window_dirty_bytemap(context); in mbox_handle_mbox_info()
221 reset_all_windows(context, SET_BMC_EVENT); in mbox_handle_mbox_info()
225 if (context->version == API_VERSION_1) { in mbox_handle_mbox_info()
226 put_u16(&resp->args[1], context->windows.default_size >> in mbox_handle_mbox_info()
227 context->block_size_shift); in mbox_handle_mbox_info()
228 put_u16(&resp->args[3], context->windows.default_size >> in mbox_handle_mbox_info()
229 context->block_size_shift); in mbox_handle_mbox_info()
231 if (context->version >= API_VERSION_2) { in mbox_handle_mbox_info()
232 resp->args[5] = context->block_size_shift; in mbox_handle_mbox_info()
233 put_u16(&resp->args[6], get_suggested_timeout(context)); in mbox_handle_mbox_info()
250 int mbox_handle_flash_info(struct mbox_context *context, in mbox_handle_flash_info() argument
253 switch (context->version) { in mbox_handle_flash_info()
256 put_u32(&resp->args[0], context->flash_size); in mbox_handle_flash_info()
257 put_u32(&resp->args[4], context->mtd_info.erasesize); in mbox_handle_flash_info()
262 context->flash_size >> context->block_size_shift); in mbox_handle_flash_info()
264 context->mtd_info.erasesize >> in mbox_handle_flash_info()
265 context->block_size_shift); in mbox_handle_flash_info()
281 static inline uint16_t get_lpc_addr_shifted(struct mbox_context *context) in get_lpc_addr_shifted() argument
286 mem_offset = context->current->mem - context->mem; in get_lpc_addr_shifted()
288 lpc_addr = context->lpc_base + mem_offset; in get_lpc_addr_shifted()
292 return lpc_addr >> context->block_size_shift; in get_lpc_addr_shifted()
314 int mbox_handle_read_window(struct mbox_context *context, in mbox_handle_read_window() argument
321 if (context->current) { in mbox_handle_read_window()
323 if (context->current_is_write) { in mbox_handle_read_window()
324 rc = mbox_handle_flush_window(context, NULL, NULL); in mbox_handle_read_window()
330 close_current_window(context, NO_BMC_EVENT, FLAGS_NONE); in mbox_handle_read_window()
334 flash_offset = get_u16(&req->msg.args[0]) << context->block_size_shift; in mbox_handle_read_window()
337 context->current = search_windows(context, flash_offset, in mbox_handle_read_window()
338 context->version == API_VERSION_1); in mbox_handle_read_window()
340 if (!context->current) { /* No existing window */ in mbox_handle_read_window()
342 rc = create_map_window(context, &context->current, flash_offset, in mbox_handle_read_window()
343 context->version == API_VERSION_1); in mbox_handle_read_window()
352 context->current->mem, context->current->size, in mbox_handle_read_window()
353 context->current->flash_offset); in mbox_handle_read_window()
355 put_u16(&resp->args[0], get_lpc_addr_shifted(context)); in mbox_handle_read_window()
356 if (context->version >= API_VERSION_2) { in mbox_handle_read_window()
357 put_u16(&resp->args[2], context->current->size >> in mbox_handle_read_window()
358 context->block_size_shift); in mbox_handle_read_window()
359 put_u16(&resp->args[4], context->current->flash_offset >> in mbox_handle_read_window()
360 context->block_size_shift); in mbox_handle_read_window()
363 context->current_is_write = false; in mbox_handle_read_window()
387 int mbox_handle_write_window(struct mbox_context *context, in mbox_handle_write_window() argument
396 rc = mbox_handle_read_window(context, req, resp); in mbox_handle_write_window()
401 context->current_is_write = true; in mbox_handle_write_window()
421 int mbox_handle_dirty_window(struct mbox_context *context, in mbox_handle_dirty_window() argument
426 if (!(context->current && context->current_is_write)) { in mbox_handle_dirty_window()
428 return context->version >= API_VERSION_2 ? -MBOX_R_WINDOW_ERROR in mbox_handle_dirty_window()
434 if (context->version >= API_VERSION_2) { in mbox_handle_dirty_window()
439 off = offset - ((context->current->flash_offset) >> in mbox_handle_dirty_window()
440 context->block_size_shift); in mbox_handle_dirty_window()
444 offset << context->block_size_shift, in mbox_handle_dirty_window()
445 context->current->flash_offset); in mbox_handle_dirty_window()
455 size = align_up(size, 1 << context->block_size_shift); in mbox_handle_dirty_window()
456 size >>= context->block_size_shift; in mbox_handle_dirty_window()
460 offset << context->block_size_shift, in mbox_handle_dirty_window()
461 size << context->block_size_shift); in mbox_handle_dirty_window()
463 return set_window_bytemap(context, context->current, offset, size, in mbox_handle_dirty_window()
480 int mbox_handle_erase_window(struct mbox_context *context, in mbox_handle_erase_window() argument
486 if (context->version < API_VERSION_2) { in mbox_handle_erase_window()
491 if (!(context->current && context->current_is_write)) { in mbox_handle_erase_window()
500 offset << context->block_size_shift, in mbox_handle_erase_window()
501 size << context->block_size_shift); in mbox_handle_erase_window()
503 rc = set_window_bytemap(context, context->current, offset, size, in mbox_handle_erase_window()
510 memset(context->current->mem + (offset << context->block_size_shift), in mbox_handle_erase_window()
511 0xFF, size << context->block_size_shift); in mbox_handle_erase_window()
533 int mbox_handle_flush_window(struct mbox_context *context, in mbox_handle_flush_window() argument
539 if (!(context->current && context->current_is_write)) { in mbox_handle_flush_window()
541 return context->version >= API_VERSION_2 ? -MBOX_R_WINDOW_ERROR in mbox_handle_flush_window()
551 if (context->version == API_VERSION_1 && req && in mbox_handle_flush_window()
553 rc = mbox_handle_dirty_window(context, req, NULL); in mbox_handle_flush_window()
564 context->current->mem, context->current->size, in mbox_handle_flush_window()
565 context->current->flash_offset); in mbox_handle_flush_window()
572 for (i = 0; i < (context->current->size >> context->block_size_shift); in mbox_handle_flush_window()
574 uint8_t cur = context->current->dirty_bmap[i]; in mbox_handle_flush_window()
582 rc = write_from_window(context, offset, count, in mbox_handle_flush_window()
592 rc = write_from_window(context, offset, count, in mbox_handle_flush_window()
605 rc = write_from_window(context, offset, count, prev); in mbox_handle_flush_window()
612 return set_window_bytemap(context, context->current, 0, in mbox_handle_flush_window()
613 context->current->size >> in mbox_handle_flush_window()
614 context->block_size_shift, in mbox_handle_flush_window()
629 int mbox_handle_close_window(struct mbox_context *context, in mbox_handle_close_window() argument
636 if (context->current) { in mbox_handle_close_window()
638 if (context->current_is_write) { in mbox_handle_close_window()
639 rc = mbox_handle_flush_window(context, NULL, NULL); in mbox_handle_close_window()
646 if (context->version >= API_VERSION_2) { in mbox_handle_close_window()
651 close_current_window(context, NO_BMC_EVENT, flags); in mbox_handle_close_window()
663 int mbox_handle_ack(struct mbox_context *context, union mbox_regs *req, in mbox_handle_ack() argument
668 return clr_bmc_events(context, (bmc_events & BMC_EVENT_ACK_MASK), in mbox_handle_ack()
679 static int check_req_valid(struct mbox_context *context, union mbox_regs *req) in check_req_valid() argument
689 if (seq == context->prev_seq && cmd != MBOX_C_GET_MBOX_INFO) { in check_req_valid()
691 context->prev_seq); in check_req_valid()
695 if (context->state & STATE_SUSPENDED) { in check_req_valid()
699 return context->version >= API_VERSION_2 ? -MBOX_R_BUSY in check_req_valid()
704 if (!(context->state & MAPS_MEM)) { in check_req_valid()
735 static int handle_mbox_req(struct mbox_context *context, union mbox_regs *req) in handle_mbox_req() argument
746 rc = check_req_valid(context, req); in handle_mbox_req()
751 mboxd_mbox_handler h = context->handlers[req->msg.command - 1]; in handle_mbox_req()
752 rc = h(context, req, &resp); in handle_mbox_req()
760 context->prev_seq = req->msg.seq; in handle_mbox_req()
769 len = write(context->fds[MBOX_FD].fd, &resp, sizeof(resp)); in handle_mbox_req()
785 static int get_message(struct mbox_context *context, union mbox_regs *msg) in get_message() argument
789 rc = read(context->fds[MBOX_FD].fd, msg, sizeof(msg->raw)); in get_message()
814 int dispatch_mbox(struct mbox_context *context) in dispatch_mbox() argument
819 assert(context); in dispatch_mbox()
821 rc = get_message(context, &req); in dispatch_mbox()
826 return handle_mbox_req(context, &req); in dispatch_mbox()
829 int __init_mbox_dev(struct mbox_context *context, const char *path) in __init_mbox_dev() argument
833 context->handlers = mbox_handlers; in __init_mbox_dev()
844 context->fds[MBOX_FD].fd = fd; in __init_mbox_dev()
849 int init_mbox_dev(struct mbox_context *context) in init_mbox_dev() argument
851 return __init_mbox_dev(context, MBOX_HOST_PATH); in init_mbox_dev()
854 void free_mbox_dev(struct mbox_context *context) in free_mbox_dev() argument
856 close(context->fds[MBOX_FD].fd); in free_mbox_dev()