Changeset 692c40cb in mainline


Ignore:
Timestamp:
2010-05-28T09:04:37Z (14 years ago)
Author:
Lenka Trochtova <trochtova.lenka@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5159ae9
Parents:
c9f3b45c
Message:

Introduce device classes.Device class specifies functional type of the device. Device classes are identified by their string names (actually device class is just a string value). Device classes can be dynamically added. A device can be added to any number of classes.

Location:
uspace
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/devman.c

    rc9f3b45c r692c40cb  
    180180}
    181181
     182int devman_add_device_to_class(device_handle_t dev_handle, const char *class_name)
     183{
     184        int phone = devman_get_phone(DEVMAN_DRIVER, IPC_FLAG_BLOCKING);
     185       
     186        if (phone < 0)
     187                return phone;
     188       
     189        async_serialize_start();
     190        ipc_call_t answer;
     191        aid_t req = async_send_1(phone, DEVMAN_ADD_DEVICE_TO_CLASS, dev_handle, &answer);
     192       
     193        ipcarg_t retval = async_data_write_start(phone, class_name, str_size(class_name));
     194        if (retval != EOK) {
     195                async_wait_for(req, NULL);
     196                async_serialize_end();
     197                return retval;
     198        }
     199       
     200        async_wait_for(req, &retval);
     201        async_serialize_end();
     202       
     203        return retval; 
     204}
     205
    182206void devman_hangup_phone(devman_interface_t iface)
    183207{
  • uspace/lib/c/include/devman.h

    rc9f3b45c r692c40cb  
    5353int devman_device_get_handle(const char *pathname, device_handle_t *handle, unsigned int flags);
    5454
     55int devman_add_device_to_class(device_handle_t dev_handle, const char *class_name);
    5556
    5657#endif
  • uspace/lib/c/include/ipc/devman.h

    rc9f3b45c r692c40cb  
    129129        DEVMAN_DRIVER_REGISTER = IPC_FIRST_USER_METHOD,
    130130        DEVMAN_ADD_CHILD_DEVICE,
    131         DEVMAN_ADD_MATCH_ID
     131        DEVMAN_ADD_MATCH_ID,
     132        DEVMAN_ADD_DEVICE_TO_CLASS
    132133
    133134} driver_to_devman_t;
  • uspace/lib/drv/generic/driver.c

    rc9f3b45c r692c40cb  
    4949#include <errno.h>
    5050
    51 #include <devman.h>
    52 #include <ipc/devman.h>
    5351#include <ipc/driver.h>
    5452
  • uspace/lib/drv/include/driver.h

    rc9f3b45c r692c40cb  
    3838#include <adt/list.h>
    3939#include <ipc/ipc.h>
     40#include <devman.h>
    4041#include <ipc/devman.h>
    4142#include <ipc/dev_iface.h>
     
    286287}
    287288
     289static inline int add_device_to_class(device_t *dev, const char *class_name)
     290{
     291        return devman_add_device_to_class(dev->handle, class_name);
     292}
     293
    288294#endif
    289295
  • uspace/srv/devman/devman.c

    rc9f3b45c r692c40cb  
    807807 */
    808808dev_class_info_t * add_device_to_class(node_t *dev, dev_class_t *cl, const char *base_dev_name)
    809 {
     809{       
    810810        dev_class_info_t *info = create_dev_class_info();
    811         info->dev_class = cl;
    812         info->dev = dev;
    813        
    814         // add the device to the class
    815         fibril_mutex_lock(&cl->mutex);
    816         list_append(&info->link, &cl->devices);
    817         fibril_mutex_unlock(&cl->mutex);
    818        
    819         // add the class to the device
    820         list_append(&info->dev_classes, &dev->classes);
    821        
    822         // create unique name for the device within the class
    823         info->dev_name = create_dev_name_for_class(cl, base_dev_name); 
     811        if (NULL != info) {
     812                info->dev_class = cl;
     813                info->dev = dev;
     814               
     815                // add the device to the class
     816                fibril_mutex_lock(&cl->mutex);
     817                list_append(&info->link, &cl->devices);
     818                fibril_mutex_unlock(&cl->mutex);
     819               
     820                // add the class to the device
     821                list_append(&info->dev_classes, &dev->classes);
     822               
     823                // create unique name for the device within the class
     824                info->dev_name = create_dev_name_for_class(cl, base_dev_name); 
     825        }
    824826       
    825827        return info;
    826828}
    827829
     830dev_class_t * get_dev_class(class_list_t *class_list, char *class_name)
     831{
     832        dev_class_t *cl;
     833        fibril_mutex_lock(&class_list->classes_mutex); 
     834        cl = find_dev_class_no_lock(class_list, class_name);
     835        if (NULL == cl) {
     836                cl = create_dev_class();
     837                if (NULL != cl) {
     838                        cl->name = class_name; 
     839                        cl->base_dev_name = "";
     840                        add_dev_class_no_lock(class_list, cl);
     841                }               
     842        }       
     843        fibril_mutex_unlock(&class_list->classes_mutex);
     844        return cl;
     845}
     846
     847dev_class_t * find_dev_class_no_lock(class_list_t *class_list, const char *class_name)
     848{
     849        dev_class_t *cl;
     850        link_t *link = class_list->classes.next;
     851        while (link != &class_list->classes) {
     852                cl = list_get_instance(link, dev_class_t, link);
     853                if (0 == str_cmp(cl->name, class_name)) {
     854                        return cl;
     855                }
     856        }
     857       
     858        return NULL;   
     859}
     860
    828861/** @}
    829862 */
  • uspace/srv/devman/devman.h

    rc9f3b45c r692c40cb  
    158158        link_t link;   
    159159        /** List of dev_class_info structures - one for each device registered by this class.*/
    160         link_t devices; 
    161         /** Default base name for the device within the class, might be overrided by the driver.*/
     160        link_t devices;
     161        /** Default base name for the device within the class, might be overrided by the driver.*/     
    162162        const char *base_dev_name;
    163         /** Unique numerical identifier appened to the base name of the newly added device.*/
     163        /** Unique numerical identifier of the newly added device.*/
    164164        size_t curr_dev_idx;
    165165        /** Synchronize access to the list of devices in this class. */
     
    185185} dev_class_info_t;
    186186
     187/** The list of device classes. */
     188typedef struct class_list {
     189        /** List of classes */
     190        link_t classes;
     191        /** Fibril mutex for list of classes. */
     192        fibril_mutex_t classes_mutex;   
     193} class_list_t;
     194
    187195// Match ids and scores
    188196
     
    282290{
    283291        node_t *res = malloc(sizeof(node_t));
     292       
    284293        if (res != NULL) {
    285294                memset(res, 0, sizeof(node_t));
     295                list_initialize(&res->children);
     296                list_initialize(&res->match_ids.ids);
     297                list_initialize(&res->classes);
    286298        }
    287        
    288         list_initialize(&res->children);
    289         list_initialize(&res->match_ids.ids);
    290299       
    291300        return res;
     
    364373        if (NULL != cl) {
    365374                memset(cl, 0, sizeof(dev_class_t));
     375                list_initialize(&cl->devices);
    366376                fibril_mutex_initialize(&cl->mutex);
    367377        }
     
    394404dev_class_info_t * add_device_to_class(node_t *dev, dev_class_t *cl, const char *base_dev_name);
    395405
     406static inline void init_class_list(class_list_t *class_list)
     407{
     408        list_initialize(&class_list->classes);
     409        fibril_mutex_initialize(&class_list->classes_mutex);
     410}
     411
     412dev_class_t * get_dev_class(class_list_t *class_list, char *class_name);
     413dev_class_t * find_dev_class_no_lock(class_list_t *class_list, const char *class_name);
     414
     415static inline void add_dev_class_no_lock(class_list_t *class_list, dev_class_t *cl)
     416{
     417        list_append(&cl->link, &class_list->classes);
     418}
     419
    396420#endif
    397421
  • uspace/srv/devman/main.c

    rc9f3b45c r692c40cb  
    6060static driver_list_t drivers_list;
    6161static dev_tree_t device_tree;
     62static class_list_t class_list;
    6263
    6364
     
    240241        // try to find suitable driver and assign it to the device     
    241242        assign_driver(node, &drivers_list);     
     243}
     244
     245static void devman_add_device_to_class(ipc_callid_t callid, ipc_call_t *call)
     246{               
     247        device_handle_t handle = IPC_GET_ARG1(*call);
     248       
     249        // Get class name
     250        char *class_name;
     251        int rc = async_data_write_accept((void **)&class_name, true, 0, 0, 0, 0);
     252        if (rc != EOK) {
     253                ipc_answer_0(callid, rc);
     254                return;
     255        }       
     256       
     257        node_t *dev = find_dev_node(&device_tree, handle);
     258        if (NULL == dev) {
     259                ipc_answer_0(callid, ENOENT);
     260                return;
     261        }
     262       
     263        dev_class_t *cl = get_dev_class(&class_list, class_name);
     264       
     265        dev_class_info_t *class_info = add_device_to_class(dev, cl, NULL);
     266       
     267        // TODO register the device's class alias by devmapper
     268       
     269        printf(NAME ": device '%s' added to class '%s', class name '%s' was asigned to it\n", dev->pathname, class_name, class_info->dev_name);
     270       
     271        ipc_answer_0(callid, EOK);     
    242272}
    243273
     
    294324                case DEVMAN_ADD_CHILD_DEVICE:
    295325                        devman_add_child(callid, &call);
     326                        break;
     327                case DEVMAN_ADD_DEVICE_TO_CLASS:
     328                        devman_add_device_to_class(callid, &call);
    296329                        break;
    297330                default:
     
    444477        }
    445478
     479        init_class_list(&class_list);
     480       
    446481        return true;
    447482}
  • uspace/srv/drivers/ns8250/ns8250.c

    rc9f3b45c r692c40cb  
    760760        dev->class = &ns8250_dev_class;
    761761       
     762        add_device_to_class(dev, "serial");
     763       
    762764        printf(NAME ": the %s device has been successfully initialized.\n", dev->name);
    763765       
Note: See TracChangeset for help on using the changeset viewer.