Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset d1bafbf in mainline


Ignore:
Timestamp:
2013-09-10T18:24:27Z (8 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master
Children:
38e52c92
Parents:
041b026
Message:

Move dev-node related devman functionality to a separate module.

Location:
uspace/srv/devman
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/devman/Makefile

    r041b026 rd1bafbf  
    3333
    3434SOURCES = \
     35        dev.c \
    3536        devman.c \
    3637        driver.c \
  • uspace/srv/devman/devman.c

    r041b026 rd1bafbf  
    6060#include <stdio.h>
    6161
     62#include "dev.h"
    6263#include "devman.h"
    6364#include "driver.h"
     
    454455}
    455456
    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 node
    493  */
    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 node
    504  */
    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 
    581457/* Function nodes */
    582458
  • uspace/srv/devman/devman.h

    r041b026 rd1bafbf  
    3535#define DEVMAN_H_
    3636
    37 #include <assert.h>
    3837#include <stdbool.h>
    39 #include <dirent.h>
    40 #include <str.h>
    4138#include <adt/list.h>
    4239#include <adt/hash_table.h>
     
    247244extern char *read_id(const char **);
    248245
    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 */
    262247
    263248extern fun_node_t *create_fun_node(void);
  • uspace/srv/devman/driver.c

    r041b026 rd1bafbf  
    3131 */
    3232
     33#include <dirent.h>
    3334#include <errno.h>
    3435#include <fcntl.h>
     
    4142#include <stdio.h>
    4243
     44#include "dev.h"
    4345#include "devman.h"
    4446#include "driver.h"
  • uspace/srv/devman/driver.h

    r041b026 rd1bafbf  
    3535#define DRIVER_H_
    3636
    37 #include <assert.h>
    3837#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"
    4839
    4940extern void init_driver_list(driver_list_t *);
  • uspace/srv/devman/main.c

    r041b026 rd1bafbf  
    5858#include <loc.h>
    5959
     60#include "dev.h"
    6061#include "devman.h"
    6162#include "driver.h"
Note: See TracChangeset for help on using the changeset viewer.