Changes in uspace/lib/c/generic/devman.c [8b1e15ac:96b02eb9] in mainline
- File:
-
- 1 edited
-
uspace/lib/c/generic/devman.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/devman.c
r8b1e15ac r96b02eb9 28 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 29 */ 30 31 /** @addtogroup libc30 31 /** @addtogroup libc 32 32 * @{ 33 33 */ … … 37 37 #include <str.h> 38 38 #include <stdio.h> 39 #include <ipc/ipc.h> 39 40 #include <ipc/services.h> 40 41 #include <ipc/devman.h> 41 42 #include <devman.h> 42 43 #include <async.h> 43 #include <fibril_synch.h>44 44 #include <errno.h> 45 45 #include <malloc.h> … … 50 50 static int devman_phone_client = -1; 51 51 52 static FIBRIL_MUTEX_INITIALIZE(devman_phone_mutex);53 54 52 int devman_get_phone(devman_interface_t iface, unsigned int flags) 55 53 { 56 54 switch (iface) { 57 55 case DEVMAN_DRIVER: 58 fibril_mutex_lock(&devman_phone_mutex); 59 if (devman_phone_driver >= 0) { 60 fibril_mutex_unlock(&devman_phone_mutex); 56 if (devman_phone_driver >= 0) 61 57 return devman_phone_driver; 62 }63 58 64 59 if (flags & IPC_FLAG_BLOCKING) 65 devman_phone_driver = async_connect_me_to_blocking(66 PHONE_NS,SERVICE_DEVMAN, DEVMAN_DRIVER, 0);60 devman_phone_driver = ipc_connect_me_to_blocking(PHONE_NS, 61 SERVICE_DEVMAN, DEVMAN_DRIVER, 0); 67 62 else 68 devman_phone_driver = async_connect_me_to(PHONE_NS,63 devman_phone_driver = ipc_connect_me_to(PHONE_NS, 69 64 SERVICE_DEVMAN, DEVMAN_DRIVER, 0); 70 65 71 fibril_mutex_unlock(&devman_phone_mutex);72 66 return devman_phone_driver; 73 67 case DEVMAN_CLIENT: 74 fibril_mutex_lock(&devman_phone_mutex); 75 if (devman_phone_client >= 0) { 76 fibril_mutex_unlock(&devman_phone_mutex); 68 if (devman_phone_client >= 0) 77 69 return devman_phone_client; 78 } 79 80 if (flags & IPC_FLAG_BLOCKING) { 81 devman_phone_client = async_connect_me_to_blocking( 82 PHONE_NS, SERVICE_DEVMAN, DEVMAN_CLIENT, 0); 83 } else { 84 devman_phone_client = async_connect_me_to(PHONE_NS, 70 71 if (flags & IPC_FLAG_BLOCKING) 72 devman_phone_client = ipc_connect_me_to_blocking(PHONE_NS, 85 73 SERVICE_DEVMAN, DEVMAN_CLIENT, 0); 86 } 87 88 fibril_mutex_unlock(&devman_phone_mutex); 74 else 75 devman_phone_client = ipc_connect_me_to(PHONE_NS, 76 SERVICE_DEVMAN, DEVMAN_CLIENT, 0); 77 89 78 return devman_phone_client; 90 79 default: … … 115 104 async_set_client_connection(conn); 116 105 117 async_connect_to_me(phone, 0, 0, 0, NULL); 118 async_wait_for(req, &retval); 119 120 async_serialize_end(); 121 122 return retval; 123 } 124 125 static int devman_send_match_id(int phone, match_id_t *match_id) 126 { 127 ipc_call_t answer; 128 129 aid_t req = async_send_1(phone, DEVMAN_ADD_MATCH_ID, match_id->score, 130 &answer); 131 int retval = async_data_write_start(phone, match_id->id, 132 str_size(match_id->id)); 133 106 sysarg_t callback_phonehash; 107 ipc_connect_to_me(phone, 0, 0, 0, &callback_phonehash); 108 async_wait_for(req, &retval); 109 110 async_serialize_end(); 111 112 return retval; 113 } 114 115 static int devman_send_match_id(int phone, match_id_t *match_id) \ 116 { 117 ipc_call_t answer; 118 aid_t req = async_send_1(phone, DEVMAN_ADD_MATCH_ID, match_id->score, &answer); 119 int retval = async_data_write_start(phone, match_id->id, str_size(match_id->id)); 134 120 async_wait_for(req, NULL); 135 121 return retval; … … 137 123 138 124 139 static int devman_send_match_ids(int phone, match_id_list_t *match_ids) 125 static int devman_send_match_ids(int phone, match_id_list_t *match_ids) 140 126 { 141 127 link_t *link = match_ids->ids.next; 142 128 match_id_t *match_id = NULL; 143 129 int ret = EOK; 144 130 145 131 while (link != &match_ids->ids) { 146 132 match_id = list_get_instance(link, match_id_t, link); 147 ret = devman_send_match_id(phone, match_id); 148 if (ret != EOK) { 149 printf("Driver failed to send match id, error %d\n", 150 ret); 151 return ret; 152 } 153 133 if (EOK != (ret = devman_send_match_id(phone, match_id))) 134 { 135 printf("Driver failed to send match id, error number = %d\n", ret); 136 return ret; 137 } 154 138 link = link->next; 155 139 } 156 157 return ret; 158 } 159 160 /** Add function to a device. 161 * 162 * Request devman to add a new function to the specified device owned by 163 * this driver task. 164 * 165 * @param name Name of the new function 166 * @param ftype Function type, fun_inner or fun_exposed 167 * @param match_ids Match IDs (should be empty for fun_exposed) 168 * @param devh Devman handle of the device 169 * @param funh Place to store handle of the new function 170 * 171 * @return EOK on success or negative error code. 172 */ 173 int devman_add_function(const char *name, fun_type_t ftype, 174 match_id_list_t *match_ids, devman_handle_t devh, devman_handle_t *funh) 175 { 140 return ret; 141 } 142 143 int devman_child_device_register( 144 const char *name, match_id_list_t *match_ids, devman_handle_t parent_handle, devman_handle_t *handle) 145 { 176 146 int phone = devman_get_phone(DEVMAN_DRIVER, IPC_FLAG_BLOCKING); 177 int fun_handle; 178 179 if (phone < 0) 180 return phone; 181 182 async_serialize_start(); 183 184 int match_count = list_count(&match_ids->ids); 185 ipc_call_t answer; 186 187 aid_t req = async_send_3(phone, DEVMAN_ADD_FUNCTION, (sysarg_t) ftype, 188 devh, match_count, &answer); 147 148 if (phone < 0) 149 return phone; 150 151 async_serialize_start(); 152 153 int match_count = list_count(&match_ids->ids); 154 ipc_call_t answer; 155 aid_t req = async_send_2(phone, DEVMAN_ADD_CHILD_DEVICE, parent_handle, match_count, &answer); 189 156 190 157 sysarg_t retval = async_data_write_start(phone, name, str_size(name)); … … 201 168 async_serialize_end(); 202 169 203 if (retval == EOK) 204 fun_handle = (int) IPC_GET_ARG1(answer); 205 else 206 fun_handle = -1; 207 208 *funh = fun_handle; 209 210 return retval; 211 } 212 213 int devman_add_device_to_class(devman_handle_t devman_handle, 214 const char *class_name) 170 if (retval != EOK) { 171 if (handle != NULL) { 172 *handle = -1; 173 } 174 return retval; 175 } 176 177 if (handle != NULL) 178 *handle = (int) IPC_GET_ARG1(answer); 179 180 return retval; 181 } 182 183 int devman_add_device_to_class(devman_handle_t devman_handle, const char *class_name) 215 184 { 216 185 int phone = devman_get_phone(DEVMAN_DRIVER, IPC_FLAG_BLOCKING); … … 221 190 async_serialize_start(); 222 191 ipc_call_t answer; 223 aid_t req = async_send_1(phone, DEVMAN_ADD_DEVICE_TO_CLASS, 224 devman_handle, &answer); 225 226 sysarg_t retval = async_data_write_start(phone, class_name, 227 str_size(class_name)); 228 if (retval != EOK) { 229 async_wait_for(req, NULL); 230 async_serialize_end(); 231 return retval; 232 } 233 234 async_wait_for(req, &retval); 235 async_serialize_end(); 236 237 return retval; 192 aid_t req = async_send_1(phone, DEVMAN_ADD_DEVICE_TO_CLASS, devman_handle, &answer); 193 194 sysarg_t retval = async_data_write_start(phone, class_name, str_size(class_name)); 195 if (retval != EOK) { 196 async_wait_for(req, NULL); 197 async_serialize_end(); 198 return retval; 199 } 200 201 async_wait_for(req, &retval); 202 async_serialize_end(); 203 204 return retval; 238 205 } 239 206 … … 243 210 case DEVMAN_DRIVER: 244 211 if (devman_phone_driver >= 0) { 245 async_hangup(devman_phone_driver);212 ipc_hangup(devman_phone_driver); 246 213 devman_phone_driver = -1; 247 214 } … … 249 216 case DEVMAN_CLIENT: 250 217 if (devman_phone_client >= 0) { 251 async_hangup(devman_phone_client);218 ipc_hangup(devman_phone_client); 252 219 devman_phone_client = -1; 253 220 } … … 263 230 264 231 if (flags & IPC_FLAG_BLOCKING) { 265 phone = async_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAN,232 phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAN, 266 233 DEVMAN_CONNECT_TO_DEVICE, handle); 267 234 } else { 268 phone = async_connect_me_to(PHONE_NS, SERVICE_DEVMAN,235 phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAN, 269 236 DEVMAN_CONNECT_TO_DEVICE, handle); 270 237 } … … 278 245 279 246 if (flags & IPC_FLAG_BLOCKING) { 280 phone = async_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAN,247 phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAN, 281 248 DEVMAN_CONNECT_TO_PARENTS_DEVICE, handle); 282 249 } else { 283 phone = async_connect_me_to(PHONE_NS, SERVICE_DEVMAN,250 phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAN, 284 251 DEVMAN_CONNECT_TO_PARENTS_DEVICE, handle); 285 252 } … … 288 255 } 289 256 290 int devman_device_get_handle(const char *pathname, devman_handle_t *handle, 291 unsigned int flags) 257 int devman_device_get_handle(const char *pathname, devman_handle_t *handle, unsigned int flags) 292 258 { 293 259 int phone = devman_get_phone(DEVMAN_CLIENT, flags); … … 302 268 &answer); 303 269 304 sysarg_t retval = async_data_write_start(phone, pathname, 305 str_size(pathname)); 270 sysarg_t retval = async_data_write_start(phone, pathname, str_size(pathname)); 306 271 if (retval != EOK) { 307 272 async_wait_for(req, NULL);
Note:
See TracChangeset
for help on using the changeset viewer.
