1/* 2 * Copyright 2016, Data61 3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO) 4 * ABN 41 687 119 230. 5 * 6 * This software may be distributed and modified according to the terms of 7 * the BSD 2-Clause license. Note that NO WARRANTY is provided. 8 * See "LICENSE_BSD2.txt" for details. 9 * 10 * @TAG(D61_BSD) 11 */ 12 13#include "dspace.h" 14#include "timer_dspace.h" 15 16 /*! @file 17 @brief Common dataspace interface functions. 18 19 This module implements the actual functions defined in <refos-rpc/data_server.h>, and then 20 analyses the parameters to decide which dataspace to delegate the message to. If the parameters 21 indicate the message should be handed off to the serial / timer dataspace, this module then 22 calls the corresponding dataspace interface function of the correct serial / timer dataspace. 23*/ 24 25seL4_CPtr 26data_open_handler(void *rpc_userptr , char* rpc_name , int rpc_flags , int rpc_mode , int rpc_size , 27 int* rpc_errno) 28{ 29 if (!rpc_name) { 30 SET_ERRNO_PTR(rpc_errno, EFILENOTFOUND); 31 return 0; 32 } 33 34 /* Handle timer dataspace open requests. */ 35 if (strcmp(rpc_name, "timer") == 0 || strcmp(rpc_name, "time") == 0) { 36 return timer_open_handler(rpc_userptr, rpc_name, rpc_flags, rpc_mode, rpc_size, rpc_errno); 37 } 38 39 SET_ERRNO_PTR(rpc_errno, EFILENOTFOUND); 40 return 0; 41} 42 43refos_err_t 44data_close_handler(void *rpc_userptr , seL4_CPtr rpc_dspace_fd) 45{ 46 struct srv_client *c = (struct srv_client *) rpc_userptr; 47 srv_msg_t *m = (srv_msg_t *) c->rpcClient.userptr; 48 assert(c && (c->magic == TIMESERV_DISPATCH_ANON_CLIENT_MAGIC || c->magic == TIMESERV_CLIENT_MAGIC)); 49 50 if (!srv_check_dispatch_caps(m, 0x00000001, 1)) { 51 return EINVALIDPARAM; 52 } 53 54 /* No need to close timer dataspaces. */ 55 if (rpc_dspace_fd == TIMESERV_DSPACE_BADGE_TIMER) { 56 return ESUCCESS; 57 } 58 59 return EFILENOTFOUND; 60} 61 62int 63data_read_handler(void *rpc_userptr , seL4_CPtr rpc_dspace_fd , uint32_t rpc_offset , 64 rpc_buffer_t rpc_buf , uint32_t rpc_count) 65{ 66 struct srv_client *c = (struct srv_client *) rpc_userptr; 67 srv_msg_t *m = (srv_msg_t *) c->rpcClient.userptr; 68 assert(c && (c->magic == TIMESERV_DISPATCH_ANON_CLIENT_MAGIC || c->magic == TIMESERV_CLIENT_MAGIC)); 69 70 if (!srv_check_dispatch_caps(m, 0x00000001, 1)) { 71 return -EINVALIDPARAM; 72 } 73 74 /* Handle read from timer dataspaces. */ 75 if (rpc_dspace_fd == TIMESERV_DSPACE_BADGE_TIMER) { 76 return timer_read_handler(rpc_userptr, rpc_dspace_fd, rpc_offset, rpc_buf, rpc_count); 77 } 78 79 return -EFILENOTFOUND; 80} 81 82int 83data_write_handler(void *rpc_userptr , seL4_CPtr rpc_dspace_fd , uint32_t rpc_offset , 84 rpc_buffer_t rpc_buf , uint32_t rpc_count) 85{ 86 struct srv_client *c = (struct srv_client *) rpc_userptr; 87 srv_msg_t *m = (srv_msg_t *) c->rpcClient.userptr; 88 assert(c && (c->magic == TIMESERV_DISPATCH_ANON_CLIENT_MAGIC || c->magic == TIMESERV_CLIENT_MAGIC)); 89 90 if (!srv_check_dispatch_caps(m, 0x00000001, 1)) { 91 return -EINVALIDPARAM; 92 } 93 94 /* Handle write to timer dataspaces. */ 95 if (rpc_dspace_fd == TIMESERV_DSPACE_BADGE_TIMER) { 96 return timer_write_handler(rpc_userptr, rpc_dspace_fd, rpc_offset, rpc_buf, rpc_count); 97 } 98 99 return -EFILENOTFOUND; 100} 101 102int 103data_getc_handler(void *rpc_userptr , seL4_CPtr rpc_dspace_fd , int rpc_block) 104{ 105 return EUNIMPLEMENTED; 106} 107 108refos_err_t 109data_expand_handler(void *rpc_userptr , seL4_CPtr rpc_dspace_fd , uint32_t rpc_size) 110{ 111 return EUNIMPLEMENTED; 112} 113 114refos_err_t 115data_putc_handler(void *rpc_userptr , seL4_CPtr rpc_dspace_fd , int rpc_c) 116{ 117 return EUNIMPLEMENTED; 118} 119 120off_t 121data_lseek_handler(void *rpc_userptr , seL4_CPtr rpc_dspace_fd , off_t rpc_offset , int rpc_whence) 122{ 123 assert(!"data_lseek_handler unimplemented."); 124 return 0; 125} 126 127uint32_t 128data_get_size_handler(void *rpc_userptr , seL4_CPtr rpc_dspace_fd) 129{ 130 return 0; 131} 132 133refos_err_t 134data_datamap_handler(void *rpc_userptr , seL4_CPtr rpc_dspace_fd , seL4_CPtr rpc_memoryWindow , 135 uint32_t rpc_offset) 136{ 137 assert(!"data_datamap_handler unimplemented."); 138 return EUNIMPLEMENTED; 139} 140 141refos_err_t 142data_dataunmap_handler(void *rpc_userptr , seL4_CPtr rpc_memoryWindow) 143{ 144 assert(!"data_dataunmap_handler unimplemented."); 145 return EUNIMPLEMENTED; 146} 147 148refos_err_t 149data_init_data_handler(void *rpc_userptr , seL4_CPtr rpc_destDataspace , seL4_CPtr rpc_srcDataspace, 150 uint32_t rpc_srcDataspaceOffset) 151{ 152 assert(!"data_init_data_handler unimplemented."); 153 return EUNIMPLEMENTED; 154} 155 156refos_err_t 157data_have_data_handler(void *rpc_userptr , seL4_CPtr rpc_dspace_fd , seL4_CPtr rpc_faultNotifyEP , 158 uint32_t* rpc_dataID) 159{ 160 assert(!"data_have_data_handler unimplemented."); 161 return EUNIMPLEMENTED; 162} 163 164refos_err_t 165data_unhave_data_handler(void *rpc_userptr , seL4_CPtr rpc_dspace_fd) 166{ 167 assert(!"data_unhave_data_handler unimplemented."); 168 return EUNIMPLEMENTED; 169} 170 171refos_err_t 172data_provide_data_from_parambuffer_handler(void *rpc_userptr , seL4_CPtr rpc_dspace_fd , 173 uint32_t rpc_offset , uint32_t rpc_contentSize) 174{ 175 assert(!"data_provide_data_from_parambuffer_handler unimplemented."); 176 return EUNIMPLEMENTED; 177} 178 179int 180check_dispatch_data(srv_msg_t *m, void **userptr) 181{ 182 return check_dispatch_interface(m, userptr, RPC_DATA_LABEL_MIN, RPC_DATA_LABEL_MAX); 183}