Changes in uspace/lib/c/generic/devman.c [4db43721:e72fb34] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/devman.c
r4db43721 re72fb34 28 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 29 */ 30 31 30 31 /** @addtogroup libc 32 32 * @{ 33 33 */ … … 37 37 #include <str.h> 38 38 #include <stdio.h> 39 #include <ipc/ipc.h>40 39 #include <ipc/services.h> 41 40 #include <ipc/devman.h> … … 116 115 async_set_client_connection(conn); 117 116 118 sysarg_t callback_phonehash; 119 ipc_connect_to_me(phone, 0, 0, 0, &callback_phonehash); 120 async_wait_for(req, &retval); 121 122 async_serialize_end(); 123 124 return retval; 125 } 126 127 static int devman_send_match_id(int phone, match_id_t *match_id) \ 128 { 129 ipc_call_t answer; 130 aid_t req = async_send_1(phone, DEVMAN_ADD_MATCH_ID, match_id->score, &answer); 131 int retval = async_data_write_start(phone, match_id->id, str_size(match_id->id)); 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 132 134 async_wait_for(req, NULL); 133 135 return retval; … … 135 137 136 138 137 static int devman_send_match_ids(int phone, match_id_list_t *match_ids) 139 static int devman_send_match_ids(int phone, match_id_list_t *match_ids) 138 140 { 139 141 link_t *link = match_ids->ids.next; 140 142 match_id_t *match_id = NULL; 141 143 int ret = EOK; 142 144 143 145 while (link != &match_ids->ids) { 144 146 match_id = list_get_instance(link, match_id_t, link); 145 if (EOK != (ret = devman_send_match_id(phone, match_id)))146 {147 printf("Driver failed to send match id, error number = %d\n", ret);148 return ret;149 } 147 ret = devman_send_match_id(phone, match_id); 148 if (ret != EOK) { 149 return ret; 150 } 151 150 152 link = link->next; 151 153 } 152 return ret; 153 } 154 155 int devman_child_device_register( 156 const char *name, match_id_list_t *match_ids, devman_handle_t parent_handle, devman_handle_t *handle) 157 { 154 155 return ret; 156 } 157 158 /** Add function to a device. 159 * 160 * Request devman to add a new function to the specified device owned by 161 * this driver task. 162 * 163 * @param name Name of the new function 164 * @param ftype Function type, fun_inner or fun_exposed 165 * @param match_ids Match IDs (should be empty for fun_exposed) 166 * @param devh Devman handle of the device 167 * @param funh Place to store handle of the new function 168 * 169 * @return EOK on success or negative error code. 170 */ 171 int devman_add_function(const char *name, fun_type_t ftype, 172 match_id_list_t *match_ids, devman_handle_t devh, devman_handle_t *funh) 173 { 158 174 int phone = devman_get_phone(DEVMAN_DRIVER, IPC_FLAG_BLOCKING); 159 160 if (phone < 0) 161 return phone; 162 163 async_serialize_start(); 164 165 int match_count = list_count(&match_ids->ids); 166 ipc_call_t answer; 167 aid_t req = async_send_2(phone, DEVMAN_ADD_CHILD_DEVICE, parent_handle, match_count, &answer); 175 int fun_handle; 176 177 if (phone < 0) 178 return phone; 179 180 async_serialize_start(); 181 182 int match_count = list_count(&match_ids->ids); 183 ipc_call_t answer; 184 185 aid_t req = async_send_3(phone, DEVMAN_ADD_FUNCTION, (sysarg_t) ftype, 186 devh, match_count, &answer); 168 187 169 188 sysarg_t retval = async_data_write_start(phone, name, str_size(name)); … … 174 193 } 175 194 176 devman_send_match_ids(phone, match_ids); 177 178 async_wait_for(req, &retval); 179 180 async_serialize_end(); 181 182 if (retval != EOK) { 183 if (handle != NULL) { 184 *handle = -1; 185 } 186 return retval; 187 } 188 189 if (handle != NULL) 190 *handle = (int) IPC_GET_ARG1(answer); 191 192 return retval; 193 } 194 195 int devman_add_device_to_class(devman_handle_t devman_handle, const char *class_name) 195 int match_ids_rc = devman_send_match_ids(phone, match_ids); 196 197 async_wait_for(req, &retval); 198 199 async_serialize_end(); 200 201 /* Prefer the answer to DEVMAN_ADD_FUNCTION in case of errors. */ 202 if ((match_ids_rc != EOK) && (retval == EOK)) { 203 retval = match_ids_rc; 204 } 205 206 if (retval == EOK) 207 fun_handle = (int) IPC_GET_ARG1(answer); 208 else 209 fun_handle = -1; 210 211 *funh = fun_handle; 212 213 return retval; 214 } 215 216 int devman_add_device_to_class(devman_handle_t devman_handle, 217 const char *class_name) 196 218 { 197 219 int phone = devman_get_phone(DEVMAN_DRIVER, IPC_FLAG_BLOCKING); … … 202 224 async_serialize_start(); 203 225 ipc_call_t answer; 204 aid_t req = async_send_1(phone, DEVMAN_ADD_DEVICE_TO_CLASS, devman_handle, &answer); 205 206 sysarg_t retval = async_data_write_start(phone, class_name, str_size(class_name)); 207 if (retval != EOK) { 208 async_wait_for(req, NULL); 209 async_serialize_end(); 210 return retval; 211 } 212 213 async_wait_for(req, &retval); 214 async_serialize_end(); 215 216 return retval; 226 aid_t req = async_send_1(phone, DEVMAN_ADD_DEVICE_TO_CLASS, 227 devman_handle, &answer); 228 229 sysarg_t retval = async_data_write_start(phone, class_name, 230 str_size(class_name)); 231 if (retval != EOK) { 232 async_wait_for(req, NULL); 233 async_serialize_end(); 234 return retval; 235 } 236 237 async_wait_for(req, &retval); 238 async_serialize_end(); 239 240 return retval; 217 241 } 218 242 … … 222 246 case DEVMAN_DRIVER: 223 247 if (devman_phone_driver >= 0) { 224 ipc_hangup(devman_phone_driver);248 async_hangup(devman_phone_driver); 225 249 devman_phone_driver = -1; 226 250 } … … 228 252 case DEVMAN_CLIENT: 229 253 if (devman_phone_client >= 0) { 230 ipc_hangup(devman_phone_client);254 async_hangup(devman_phone_client); 231 255 devman_phone_client = -1; 232 256 } … … 267 291 } 268 292 269 int devman_device_get_handle(const char *pathname, devman_handle_t *handle, unsigned int flags) 293 int devman_device_get_handle(const char *pathname, devman_handle_t *handle, 294 unsigned int flags) 270 295 { 271 296 int phone = devman_get_phone(DEVMAN_CLIENT, flags); … … 280 305 &answer); 281 306 282 sysarg_t retval = async_data_write_start(phone, pathname, str_size(pathname)); 307 sysarg_t retval = async_data_write_start(phone, pathname, 308 str_size(pathname)); 283 309 if (retval != EOK) { 284 310 async_wait_for(req, NULL); … … 303 329 } 304 330 331 int devman_device_get_handle_by_class(const char *classname, 332 const char *devname, devman_handle_t *handle, unsigned int flags) 333 { 334 int phone = devman_get_phone(DEVMAN_CLIENT, flags); 335 336 if (phone < 0) 337 return phone; 338 339 async_serialize_start(); 340 341 ipc_call_t answer; 342 aid_t req = async_send_1(phone, DEVMAN_DEVICE_GET_HANDLE_BY_CLASS, 343 flags, &answer); 344 345 sysarg_t retval = async_data_write_start(phone, classname, 346 str_size(classname)); 347 if (retval != EOK) { 348 async_wait_for(req, NULL); 349 async_serialize_end(); 350 return retval; 351 } 352 retval = async_data_write_start(phone, devname, 353 str_size(devname)); 354 if (retval != EOK) { 355 async_wait_for(req, NULL); 356 async_serialize_end(); 357 return retval; 358 } 359 360 async_wait_for(req, &retval); 361 362 async_serialize_end(); 363 364 if (retval != EOK) { 365 if (handle != NULL) 366 *handle = (devman_handle_t) -1; 367 return retval; 368 } 369 370 if (handle != NULL) 371 *handle = (devman_handle_t) IPC_GET_ARG1(answer); 372 373 return retval; 374 } 375 305 376 306 377 /** @}
Note:
See TracChangeset
for help on using the changeset viewer.