Changeset d1bafbf in mainline
- Timestamp:
- 2013-09-10T18:24:27Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 38e52c92
- Parents:
- 041b026
- Location:
- uspace/srv/devman
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/Makefile
r041b026 rd1bafbf 33 33 34 34 SOURCES = \ 35 dev.c \ 35 36 devman.c \ 36 37 driver.c \ -
uspace/srv/devman/devman.c
r041b026 rd1bafbf 60 60 #include <stdio.h> 61 61 62 #include "dev.h" 62 63 #include "devman.h" 63 64 #include "driver.h" … … 454 455 } 455 456 456 /* Device nodes */457 458 /** Create a new device node.459 *460 * @return A device node structure.461 */462 dev_node_t *create_dev_node(void)463 {464 dev_node_t *dev;465 466 dev = calloc(1, sizeof(dev_node_t));467 if (dev == NULL)468 return NULL;469 470 atomic_set(&dev->refcnt, 0);471 list_initialize(&dev->functions);472 link_initialize(&dev->driver_devices);473 474 return dev;475 }476 477 /** Delete a device node.478 *479 * @param node The device node structure.480 */481 void delete_dev_node(dev_node_t *dev)482 {483 assert(list_empty(&dev->functions));484 assert(dev->pfun == NULL);485 assert(dev->drv == NULL);486 487 free(dev);488 }489 490 /** Increase device node reference count.491 *492 * @param dev Device node493 */494 void dev_add_ref(dev_node_t *dev)495 {496 atomic_inc(&dev->refcnt);497 }498 499 /** Decrease device node reference count.500 *501 * When the count drops to zero the device node is freed.502 *503 * @param dev Device node504 */505 void dev_del_ref(dev_node_t *dev)506 {507 if (atomic_predec(&dev->refcnt) == 0)508 delete_dev_node(dev);509 }510 511 /** Find the device node structure of the device witch has the specified handle.512 *513 * @param tree The device tree where we look for the device node.514 * @param handle The handle of the device.515 * @return The device node.516 */517 dev_node_t *find_dev_node_no_lock(dev_tree_t *tree, devman_handle_t handle)518 {519 assert(fibril_rwlock_is_locked(&tree->rwlock));520 521 ht_link_t *link = hash_table_find(&tree->devman_devices, &handle);522 if (link == NULL)523 return NULL;524 525 return hash_table_get_inst(link, dev_node_t, devman_dev);526 }527 528 /** Find the device node structure of the device witch has the specified handle.529 *530 * @param tree The device tree where we look for the device node.531 * @param handle The handle of the device.532 * @return The device node.533 */534 dev_node_t *find_dev_node(dev_tree_t *tree, devman_handle_t handle)535 {536 dev_node_t *dev = NULL;537 538 fibril_rwlock_read_lock(&tree->rwlock);539 dev = find_dev_node_no_lock(tree, handle);540 if (dev != NULL)541 dev_add_ref(dev);542 543 fibril_rwlock_read_unlock(&tree->rwlock);544 545 return dev;546 }547 548 /** Get list of device functions. */549 int dev_get_functions(dev_tree_t *tree, dev_node_t *dev,550 devman_handle_t *hdl_buf, size_t buf_size, size_t *act_size)551 {552 size_t act_cnt;553 size_t buf_cnt;554 555 assert(fibril_rwlock_is_locked(&tree->rwlock));556 557 buf_cnt = buf_size / sizeof(devman_handle_t);558 559 act_cnt = list_count(&dev->functions);560 *act_size = act_cnt * sizeof(devman_handle_t);561 562 if (buf_size % sizeof(devman_handle_t) != 0)563 return EINVAL;564 565 size_t pos = 0;566 list_foreach(dev->functions, item) {567 fun_node_t *fun =568 list_get_instance(item, fun_node_t, dev_functions);569 570 if (pos < buf_cnt) {571 hdl_buf[pos] = fun->handle;572 }573 574 pos++;575 }576 577 return EOK;578 }579 580 581 457 /* Function nodes */ 582 458 -
uspace/srv/devman/devman.h
r041b026 rd1bafbf 35 35 #define DEVMAN_H_ 36 36 37 #include <assert.h>38 37 #include <stdbool.h> 39 #include <dirent.h>40 #include <str.h>41 38 #include <adt/list.h> 42 39 #include <adt/hash_table.h> … … 247 244 extern char *read_id(const char **); 248 245 249 /* Device nodes */ 250 251 extern dev_node_t *create_dev_node(void); 252 extern void delete_dev_node(dev_node_t *node); 253 extern void dev_add_ref(dev_node_t *); 254 extern void dev_del_ref(dev_node_t *); 255 256 extern dev_node_t *find_dev_node_no_lock(dev_tree_t *tree, 257 devman_handle_t handle); 258 extern dev_node_t *find_dev_node(dev_tree_t *tree, devman_handle_t handle); 259 extern dev_node_t *find_dev_function(dev_node_t *, const char *); 260 extern int dev_get_functions(dev_tree_t *tree, dev_node_t *, devman_handle_t *, 261 size_t, size_t *); 246 /* Function nodes */ 262 247 263 248 extern fun_node_t *create_fun_node(void); -
uspace/srv/devman/driver.c
r041b026 rd1bafbf 31 31 */ 32 32 33 #include <dirent.h> 33 34 #include <errno.h> 34 35 #include <fcntl.h> … … 41 42 #include <stdio.h> 42 43 44 #include "dev.h" 43 45 #include "devman.h" 44 46 #include "driver.h" -
uspace/srv/devman/driver.h
r041b026 rd1bafbf 35 35 #define DRIVER_H_ 36 36 37 #include <assert.h>38 37 #include <stdbool.h> 39 #include <dirent.h> 40 #include <str.h> 41 #include <adt/list.h> 42 #include <adt/hash_table.h> 43 #include <ipc/devman.h> 44 #include <ipc/loc.h> 45 #include <fibril_synch.h> 46 #include <atomic.h> 47 #include <async.h> 38 #include "devman.h" 48 39 49 40 extern void init_driver_list(driver_list_t *); -
uspace/srv/devman/main.c
r041b026 rd1bafbf 58 58 #include <loc.h> 59 59 60 #include "dev.h" 60 61 #include "devman.h" 61 62 #include "driver.h"
Note:
See TracChangeset
for help on using the changeset viewer.