Changeset 3843ecb in mainline for uspace/lib/libdrv


Ignore:
Timestamp:
2010-04-09T13:54:06Z (15 years ago)
Author:
Lenka Trochtova <trochtova.lenka@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
892e4e1
Parents:
3a5909f
Message:

device classes as interface sets

Location:
uspace/lib/libdrv
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libdrv/generic/dev_iface.c

    r3a5909f r3843ecb  
    4545};
    4646
    47 remote_iface_t* get_remote_iface(dev_inferface_id_t id)
    48 {
    49         assert(is_valid_iface_id(id));
    50        
    51         int idx = get_iface_index(id);
     47remote_iface_t* get_remote_iface(int idx)
     48{       
     49        assert(is_valid_iface_idx(idx));       
    5250        return remote_ifaces.ifaces[idx];       
    5351}
  • uspace/lib/libdrv/generic/driver.c

    r3a5909f r3843ecb  
    177177                callid = async_get_call(&call);
    178178                ipcarg_t method = IPC_GET_METHOD(call);
     179                int iface_idx;
     180               
    179181                switch  (method) {
    180182                case IPC_M_PHONE_HUNGUP:
     
    184186                        ipc_answer_0(callid, EOK);
    185187                        return;
    186                 default:
    187 
    188                         if (!is_valid_iface_id(method)) {
     188                default:               
     189                        // convert ipc interface id to interface index
     190                       
     191                        iface_idx = DEV_IFACE_IDX(method);
     192                       
     193                        if (!is_valid_iface_idx(iface_idx)) {
    189194                                // this is not device's interface
    190195                                printf("%s: driver_connection_gen error - invalid interface id %x.", driver->name, method);
     
    196201                       
    197202                        // get the device interface structure
    198                         void *iface = device_get_iface(dev, method);
     203                        void *iface = device_get_iface(dev, iface_idx);
    199204                        if (NULL == iface) {
    200205                                printf("%s: driver_connection_gen error - ", driver->name);
     
    205210
    206211                        // get the corresponding interface for remote request handling ("remote interface")
    207                         remote_iface_t* rem_iface = get_remote_iface(method);
     212                        remote_iface_t* rem_iface = get_remote_iface(iface_idx);
    208213                        assert(NULL != rem_iface);
    209214
  • uspace/lib/libdrv/include/driver.h

    r3a5909f r3843ecb  
    3939#include <ipc/devman.h>
    4040#include <ipc/dev_iface.h>
     41#include <device/hw_res.h>
    4142#include <assert.h>
    4243
     
    5960} iface_dipatch_table_t;
    6061
    61 static inline int get_iface_index(dev_inferface_id_t id)
     62
     63static inline bool is_valid_iface_idx(int idx)
    6264{
    63         return id - DEV_IFACE_FIRST;
     65        return 0 <= idx && idx < DEV_IFACE_MAX;
    6466}
    6567
    66 static inline bool is_valid_iface_id(dev_inferface_id_t id)
    67 {
    68         return DEV_IFACE_FIRST <= id && id < DEV_IFACE_MAX;
    69 }
     68remote_iface_t* get_remote_iface(int idx);
     69remote_iface_func_ptr_t get_remote_method(remote_iface_t *rem_iface, ipcarg_t iface_method_idx);
    7070
    71 remote_iface_t* get_remote_iface(dev_inferface_id_t id);
    72 remote_iface_func_ptr_t get_remote_method(remote_iface_t *rem_iface, ipcarg_t iface_method_idx);
     71
     72// device class
     73
     74/** Devices belonging to the same class should implement the same set of interfaces.*/
     75typedef struct device_class {
     76        /** Unique identification of the class. */
     77        int id;
     78        /** The table of interfaces implemented by the device. */
     79        void *interfaces[DEV_IFACE_COUNT];     
     80} device_class_t;
    7381
    7482
     
    8997        /** The device driver's data associated with this device.*/
    9098        void *driver_data;
    91         /** The table of interfaces exported by this device. */
    92         void *interfaces[DEV_IFACE_COUNT];
     99        /** Device class consist of class id and table of interfaces supported by the device.*/
     100        device_class_t *class;
    93101        /** Pointer to the previous and next device in the list of devices handled by the driver */
    94102        link_t link;
     
    146154}
    147155
    148 static inline void device_set_iface (device_t *dev, dev_inferface_id_t id, void *iface)
     156static inline void * device_get_iface(device_t *dev, dev_inferface_idx_t idx)
    149157{
    150         assert(is_valid_iface_id(id));
     158        assert(is_valid_iface_idx(idx));       
    151159
    152         int idx = get_iface_index(id);
    153         dev->interfaces[idx] = iface;
    154 }
    155 
    156 static inline void * device_get_iface(device_t *dev, dev_inferface_id_t id)
    157 {
    158         assert(is_valid_iface_id(id));
    159        
    160         int idx = get_iface_index(id);
    161         return dev->interfaces[idx];   
     160        return dev->class->interfaces[idx];     
    162161}
    163162
Note: See TracChangeset for help on using the changeset viewer.