Changeset 1a5b252 in mainline for uspace/lib
- Timestamp:
- 2011-08-21T11:54:15Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8cc4ddb
- Parents:
- e64df9a
- Location:
- uspace/lib
- Files:
-
- 5 edited
-
c/generic/devman.c (modified) (2 diffs)
-
c/include/devman.h (modified) (2 diffs)
-
c/include/ipc/devman.h (modified) (2 diffs)
-
drv/generic/driver.c (modified) (8 diffs)
-
drv/include/ddf/driver.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/devman.c
re64df9a r1a5b252 327 327 } 328 328 329 int devman_drv_fun_online(devman_handle_t funh) 330 { 331 async_exch_t *exch = devman_exchange_begin(DEVMAN_DRIVER); 332 if (exch == NULL) 333 return ENOMEM; 334 335 sysarg_t retval = async_req_1_0(exch, DEVMAN_DRV_FUN_ONLINE, funh); 336 337 devman_exchange_end(exch); 338 return (int) retval; 339 } 340 341 int devman_drv_fun_offline(devman_handle_t funh) 342 { 343 async_exch_t *exch = devman_exchange_begin(DEVMAN_DRIVER); 344 if (exch == NULL) 345 return ENOMEM; 346 347 sysarg_t retval = async_req_1_0(exch, DEVMAN_DRV_FUN_OFFLINE, funh); 348 349 devman_exchange_end(exch); 350 return (int) retval; 351 } 352 329 353 async_sess_t *devman_parent_device_connect(exch_mgmt_t mgmt, 330 354 devman_handle_t handle, unsigned int flags) … … 430 454 } 431 455 456 int devman_fun_online(devman_handle_t funh) 457 { 458 async_exch_t *exch = devman_exchange_begin(DEVMAN_CLIENT); 459 if (exch == NULL) 460 return ENOMEM; 461 462 sysarg_t retval = async_req_1_0(exch, DEVMAN_FUN_ONLINE, funh); 463 464 devman_exchange_end(exch); 465 return (int) retval; 466 } 467 468 int devman_fun_offline(devman_handle_t funh) 469 { 470 async_exch_t *exch = devman_exchange_begin(DEVMAN_CLIENT); 471 if (exch == NULL) 472 return ENOMEM; 473 474 sysarg_t retval = async_req_1_0(exch, DEVMAN_FUN_OFFLINE, funh); 475 476 devman_exchange_end(exch); 477 return (int) retval; 478 } 479 432 480 static int devman_get_handles_once(sysarg_t method, sysarg_t arg1, 433 481 devman_handle_t *handle_buf, size_t buf_size, size_t *act_size) -
uspace/lib/c/include/devman.h
re64df9a r1a5b252 50 50 devman_handle_t, devman_handle_t *); 51 51 extern int devman_remove_function(devman_handle_t); 52 extern int devman_drv_fun_online(devman_handle_t); 53 extern int devman_drv_fun_offline(devman_handle_t); 52 54 53 55 extern async_sess_t *devman_device_connect(exch_mgmt_t, devman_handle_t, … … 63 65 extern int devman_fun_get_name(devman_handle_t, char *, size_t); 64 66 extern int devman_fun_get_path(devman_handle_t, char *, size_t); 67 extern int devman_fun_online(devman_handle_t); 68 extern int devman_fun_offline(devman_handle_t); 65 69 66 70 extern int devman_add_device_to_category(devman_handle_t, const char *); -
uspace/lib/c/include/ipc/devman.h
re64df9a r1a5b252 139 139 DEVMAN_ADD_MATCH_ID, 140 140 DEVMAN_ADD_DEVICE_TO_CATEGORY, 141 DEVMAN_DRV_FUN_ONLINE, 142 DEVMAN_DRV_FUN_OFFLINE, 141 143 DEVMAN_REMOVE_FUNCTION 142 144 } driver_to_devman_t; 143 145 144 146 typedef enum { 145 DRIVER_ADD_DEVICE = IPC_FIRST_USER_METHOD 147 DRIVER_DEV_ADD = IPC_FIRST_USER_METHOD, 148 DRIVER_DEV_REMOVE, 149 DRIVER_FUN_ONLINE, 150 DRIVER_FUN_OFFLINE, 146 151 147 152 } devman_to_driver_t; … … 152 157 DEVMAN_FUN_GET_CHILD, 153 158 DEVMAN_FUN_GET_NAME, 159 DEVMAN_FUN_ONLINE, 160 DEVMAN_FUN_OFFLINE, 154 161 DEVMAN_FUN_GET_PATH, 155 162 DEVMAN_FUN_SID_TO_HANDLE -
uspace/lib/drv/generic/driver.c
re64df9a r1a5b252 63 63 64 64 /** Devices */ 65 LIST_INITIALIZE(devices); 66 FIBRIL_MUTEX_INITIALIZE(devices_mutex); 67 68 /** Functions */ 65 69 LIST_INITIALIZE(functions); 66 70 FIBRIL_MUTEX_INITIALIZE(functions_mutex); … … 227 231 } 228 232 229 static ddf_fun_t *driver_get_function(list_t *functions, devman_handle_t handle) 233 static ddf_dev_t *driver_get_device(devman_handle_t handle) 234 { 235 ddf_dev_t *dev = NULL; 236 237 assert(fibril_mutex_is_locked(&devices_mutex)); 238 239 list_foreach(devices, link) { 240 dev = list_get_instance(link, ddf_dev_t, link); 241 if (dev->handle == handle) 242 return dev; 243 } 244 245 return NULL; 246 } 247 248 static ddf_fun_t *driver_get_function(devman_handle_t handle) 230 249 { 231 250 ddf_fun_t *fun = NULL; 232 251 233 fibril_mutex_lock(&functions_mutex);234 235 list_foreach( *functions, link) {252 assert(fibril_mutex_is_locked(&functions_mutex)); 253 254 list_foreach(functions, link) { 236 255 fun = list_get_instance(link, ddf_fun_t, link); 237 if (fun->handle == handle) { 238 fibril_mutex_unlock(&functions_mutex); 256 if (fun->handle == handle) 239 257 return fun; 240 } 241 } 242 243 fibril_mutex_unlock(&functions_mutex); 258 } 244 259 245 260 return NULL; … … 270 285 delete_device(dev); 271 286 287 fibril_mutex_lock(&devices_mutex); 288 list_append(&dev->link, &devices); 289 fibril_mutex_unlock(&devices_mutex); 290 272 291 async_answer_0(iid, res); 292 } 293 294 static void driver_dev_remove(ipc_callid_t iid, ipc_call_t *icall) 295 { 296 devman_handle_t devh; 297 ddf_dev_t *dev; 298 int rc; 299 300 printf("libdrv: driver_dev_offline()\n"); 301 devh = IPC_GET_ARG1(*icall); 302 303 fibril_mutex_lock(&devices_mutex); 304 dev = driver_get_device(devh); 305 fibril_mutex_unlock(&devices_mutex); 306 /* XXX need lock on dev */ 307 308 if (dev == NULL) { 309 async_answer_0(iid, ENOENT); 310 return; 311 } 312 313 if (driver->driver_ops->dev_remove != NULL) 314 rc = driver->driver_ops->dev_remove(dev); 315 else 316 rc = ENOTSUP; 317 318 async_answer_0(iid, (sysarg_t) rc); 319 } 320 321 static void driver_fun_online(ipc_callid_t iid, ipc_call_t *icall) 322 { 323 devman_handle_t funh; 324 ddf_fun_t *fun; 325 int rc; 326 327 funh = IPC_GET_ARG1(*icall); 328 fibril_mutex_lock(&functions_mutex); 329 fun = driver_get_function(funh); 330 fibril_mutex_unlock(&functions_mutex); 331 /* XXX Need lock on fun */ 332 333 if (fun == NULL) { 334 async_answer_0(iid, ENOENT); 335 return; 336 } 337 338 if (driver->driver_ops->fun_online != NULL) 339 rc = driver->driver_ops->fun_online(fun); 340 else 341 rc = ENOTSUP; 342 343 async_answer_0(iid, (sysarg_t) rc); 344 } 345 346 static void driver_fun_offline(ipc_callid_t iid, ipc_call_t *icall) 347 { 348 devman_handle_t funh; 349 ddf_fun_t *fun; 350 int rc; 351 352 funh = IPC_GET_ARG1(*icall); 353 fibril_mutex_lock(&functions_mutex); 354 fun = driver_get_function(funh); 355 fibril_mutex_unlock(&functions_mutex); 356 /* XXX Need lock on fun */ 357 358 if (fun == NULL) { 359 async_answer_0(iid, ENOENT); 360 return; 361 } 362 363 if (driver->driver_ops->fun_offline != NULL) 364 rc = driver->driver_ops->fun_offline(fun); 365 else 366 rc = ENOTSUP; 367 368 async_answer_0(iid, (sysarg_t) rc); 273 369 } 274 370 … … 286 382 287 383 switch (IPC_GET_IMETHOD(call)) { 288 case DRIVER_ ADD_DEVICE:384 case DRIVER_DEV_ADD: 289 385 driver_add_device(callid, &call); 290 386 break; 387 case DRIVER_DEV_REMOVE: 388 driver_dev_remove(callid, &call); 389 break; 390 case DRIVER_FUN_ONLINE: 391 driver_fun_online(callid, &call); 392 break; 393 case DRIVER_FUN_OFFLINE: 394 driver_fun_offline(callid, &call); 395 break; 291 396 default: 292 async_answer_0(callid, ENO ENT);397 async_answer_0(callid, ENOTSUP); 293 398 } 294 399 } … … 308 413 */ 309 414 devman_handle_t handle = IPC_GET_ARG2(*icall); 310 ddf_fun_t *fun = driver_get_function(&functions, handle); 415 416 fibril_mutex_lock(&functions_mutex); 417 ddf_fun_t *fun = driver_get_function(handle); 418 fibril_mutex_unlock(&functions_mutex); 419 /* XXX Need a lock on fun */ 311 420 312 421 if (fun == NULL) { … … 614 723 * the function invisible to the system. 615 724 * 616 * @param fun Function to bind725 * @param fun Function to unbind 617 726 * @return EOK on success or negative error code 618 727 */ … … 623 732 assert(fun->bound == true); 624 733 625 add_to_functions_list(fun);626 734 res = devman_remove_function(fun->handle); 627 735 if (res != EOK) … … 631 739 632 740 fun->bound = false; 741 return EOK; 742 } 743 744 /** Online function. 745 * 746 * @param fun Function to online 747 * @return EOK on success or negative error code 748 */ 749 int ddf_fun_online(ddf_fun_t *fun) 750 { 751 int res; 752 753 assert(fun->bound == true); 754 755 res = devman_drv_fun_online(fun->handle); 756 if (res != EOK) 757 return res; 758 759 return EOK; 760 } 761 762 /** Offline function. 763 * 764 * @param fun Function to offline 765 * @return EOK on success or negative error code 766 */ 767 int ddf_fun_offline(ddf_fun_t *fun) 768 { 769 int res; 770 771 assert(fun->bound == true); 772 773 res = devman_drv_fun_offline(fun->handle); 774 if (res != EOK) 775 return res; 776 633 777 return EOK; 634 778 } -
uspace/lib/drv/include/ddf/driver.h
re64df9a r1a5b252 132 132 typedef struct driver_ops { 133 133 /** Callback method for passing a new device to the device driver */ 134 int (*add_device)(ddf_dev_t *dev); 135 /* TODO: add other generic driver operations */ 134 int (*add_device)(ddf_dev_t *); 135 /** Ask driver to remove a device */ 136 int (*dev_remove)(ddf_dev_t *); 137 /** Ask driver to online a specific function */ 138 int (*fun_online)(ddf_fun_t *); 139 /** Ask driver to offline a specific function */ 140 int (*fun_offline)(ddf_fun_t *); 136 141 } driver_ops_t; 137 142 … … 150 155 extern int ddf_fun_bind(ddf_fun_t *); 151 156 extern int ddf_fun_unbind(ddf_fun_t *); 157 extern int ddf_fun_online(ddf_fun_t *); 158 extern int ddf_fun_offline(ddf_fun_t *); 152 159 extern int ddf_fun_add_match_id(ddf_fun_t *, const char *, int); 153 160
Note:
See TracChangeset
for help on using the changeset viewer.
