Changeset 729fa2d6 in mainline


Ignore:
Timestamp:
2010-02-25T14:29:23Z (15 years ago)
Author:
Lenka Trochtova <trochtova.lenka@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
92413de
Parents:
924c75e1
Message:

parts of root device driver

Location:
uspace
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libc/Makefile

    r924c75e1 r729fa2d6  
    5353        generic/clipboard.c \
    5454        generic/devmap.c \
     55        generic/devman.c \
    5556        generic/event.c \
    5657        generic/errno.c \
  • uspace/lib/libc/include/ipc/devman.h

    r924c75e1 r729fa2d6  
    3636#include <ipc/ipc.h>
    3737
     38#define DEVMAN_NAME_MAXLEN 256
     39
    3840typedef enum {
    3941        DEVMAN_DRIVER = 1,
  • uspace/srv/devman/devman.c

    r924c75e1 r729fa2d6  
    348348       
    349349        fibril_mutex_lock(&drivers_list->drivers_mutex);
     350       
    350351        link_t *link = drivers_list->drivers.next;             
    351352        while (link != &drivers_list->drivers) {
     
    358359                link = link->next;
    359360        }
     361       
    360362        fibril_mutex_unlock(&drivers_list->drivers_mutex);
    361363       
     
    404406        drv->state = DRIVER_STARTING;
    405407        return true;
     408}
     409
     410driver_t * find_driver(driver_list_t *drv_list, const char *drv_name)
     411{       
     412        driver_t *res = NULL;
     413       
     414        fibril_mutex_lock(&drv_list->drivers_mutex);   
     415       
     416        driver_t *drv = NULL;
     417        link_t *link = drv_list->drivers.next; 
     418        while (link !=  &drv_list->drivers) {
     419                drv = list_get_instance(link, driver_t, drivers);
     420                if (0 == str_cmp(drv->name, drv_name)) {
     421                        res = drv;
     422                        break;
     423                }               
     424                link = link->next;
     425        }       
     426       
     427        fibril_mutex_unlock(&drv_list->drivers_mutex);
     428       
     429        return res;
    406430}
    407431
  • uspace/srv/devman/devman.h

    r924c75e1 r729fa2d6  
    168168}
    169169
    170 // Driver list
     170
     171
     172
     173
     174// Drivers
    171175
    172176static inline void init_driver_list(driver_list_t *drv_list)
     
    178182}
    179183
    180 // Drivers
    181 
    182184driver_t * create_driver();
    183185bool get_driver_info(const char *base_path, const char *name, driver_t *drv);
     
    191193bool add_device(driver_t *drv, node_t *node);
    192194bool start_driver(driver_t *drv);
     195
     196driver_t * find_driver(driver_list_t *drv_list, const char *drv_name);
    193197
    194198
  • uspace/srv/devman/main.c

    r924c75e1 r729fa2d6  
    5959static dev_tree_t device_tree;
    6060
     61/**
     62 *
     63 *
     64 * Driver's mutex must be locked.
     65 */
     66static void pass_devices_to_driver(driver_t *driver)
     67{
     68       
     69
     70       
     71       
     72}
     73
     74static void init_running_driver(driver_t *driver)
     75{
     76        fibril_mutex_lock(&driver->driver_mutex);
     77       
     78        // pass devices which have been already assigned to the driver to the driver
     79        pass_devices_to_driver(driver);
     80       
     81        // change driver's state to running
     82        driver->state = DRIVER_RUNNING;
     83       
     84        fibril_mutex_unlock(&driver->driver_mutex);
     85}
     86
     87/**
     88 * Register running driver.
     89 */
     90static driver_t * devman_driver_register(void)
     91{       
     92        printf(NAME ": devman_driver_register \n");
     93       
     94        ipc_call_t icall;
     95        ipc_callid_t iid = async_get_call(&icall);
     96        driver_t *driver = NULL;
     97       
     98        if (IPC_GET_METHOD(icall) != DEVMAN_DRIVER_REGISTER) {
     99                ipc_answer_0(iid, EREFUSED);
     100                return NULL;
     101        }
     102       
     103        char drv_name[DEVMAN_NAME_MAXLEN];
     104       
     105        // Get driver name
     106        int rc = async_string_receive(drv_name, DEVMAN_NAME_MAXLEN, NULL);     
     107        if (rc != EOK) {
     108                ipc_answer_0(iid, rc);
     109                return NULL;
     110        }
     111        printf(NAME ": the %s driver is trying to register by the service.\n", drv_name);
     112       
     113        // Find driver structure
     114        driver = find_driver(&drivers_list, drv_name);
     115        if (NULL == driver) {
     116                printf(NAME ": no driver named %s was found.\n", drv_name);
     117                ipc_answer_0(iid, ENOENT);
     118                return NULL;
     119        }
     120        printf(NAME ": registering the running instance of the %s driver.\n", driver->name);
     121       
     122        // Create connection to the driver
     123        printf(NAME ":  creating connection to the %s driver.\n", driver->name);       
     124        ipc_call_t call;
     125        ipc_callid_t callid = async_get_call(&call);           
     126        if (IPC_GET_METHOD(call) != IPC_M_CONNECT_TO_ME) {
     127                ipc_answer_0(callid, ENOTSUP);
     128                ipc_answer_0(iid, ENOTSUP);
     129                return NULL;
     130        }
     131       
     132        fibril_mutex_lock(&driver->driver_mutex);
     133        assert(DRIVER_STARTING == driver->state);
     134        driver->phone = IPC_GET_ARG5(call);     
     135        fibril_mutex_unlock(&driver->driver_mutex);     
     136       
     137        printf(NAME ":  the %s driver was successfully registered as running.\n", driver->name);
     138       
     139        ipc_answer_0(callid, EOK);     
     140       
     141        ipc_answer_0(iid, EOK);
     142       
     143        return driver;
     144}
    61145
    62146/** Function for handling connections to device manager.
     
    64148 */
    65149static void devman_connection_driver(ipc_callid_t iid, ipc_call_t *icall)
    66 {
     150{       
     151        /* Accept the connection */
     152        ipc_answer_0(iid, EOK);
     153       
     154        driver_t *driver = devman_driver_register();
     155        if (driver == NULL)
     156                return;
     157               
     158        init_running_driver(driver);
     159       
    67160        ipc_callid_t callid;
    68161        ipc_call_t call;
    69        
    70         /* Accept the connection */
    71         ipc_answer_0(iid, EOK);
    72        
    73         while (1) {
     162        bool cont = true;
     163        while (cont) {
    74164                callid = async_get_call(&call);
    75165               
    76166                switch (IPC_GET_METHOD(call)) {
    77                 case DEVMAN_DRIVER_REGISTER:
    78                         // TODO register running driver instance - remember driver's phone and lookup devices to which it has been assigned
    79                         break;
     167                case IPC_M_PHONE_HUNGUP:
     168                        cont = false;
     169                        continue;
    80170                case DEVMAN_ADD_CHILD_DEVICE:
    81171                        // TODO add new device node to the device tree
  • uspace/srv/devman/util.h

    r924c75e1 r729fa2d6  
    5757}
    5858
    59 static inline void free_not_null(void *ptr)
     59static inline void free_not_null(const void *ptr)
    6060{
    6161        if (NULL != ptr) {
  • uspace/srv/drivers/root/Makefile

    r924c75e1 r729fa2d6  
    2828USPACE_PREFIX = ../../..
    2929LIBS = $(LIBC_PREFIX)/libc.a
    30 EXTRA_CFLAGS = -Iinclude
    3130
    32 OUTPUT = root 
     31OUTPUT = root
    3332
    3433SOURCES = \
    35         root.c \
     34        root.c
    3635
    3736include ../../Makefile.common
    38 
  • uspace/srv/drivers/root/root.c

    r924c75e1 r729fa2d6  
    4848#include <ctype.h>
    4949
     50#include <devman.h>
    5051#include <ipc/devman.h>
    5152
     
    149150
    150151
    151 // TODO put this to library (like in device mapper)
    152 static int devman_phone_driver = -1;
    153 static int devman_phone_client = -1;
    154 
    155 int devman_get_phone(devman_interface_t iface, unsigned int flags)
    156 {
    157         switch (iface) {
    158         case DEVMAN_DRIVER:
    159                 if (devman_phone_driver >= 0)
    160                         return devman_phone_driver;
    161                
    162                 if (flags & IPC_FLAG_BLOCKING)
    163                         devman_phone_driver = ipc_connect_me_to_blocking(PHONE_NS,
    164                             SERVICE_DEVMAN, DEVMAN_DRIVER, 0);
    165                 else
    166                         devman_phone_driver = ipc_connect_me_to(PHONE_NS,
    167                             SERVICE_DEVMAN, DEVMAN_DRIVER, 0);
    168                
    169                 return devman_phone_driver;
    170         case DEVMAN_CLIENT:
    171                 if (devman_phone_client >= 0)
    172                         return devman_phone_client;
    173                
    174                 if (flags & IPC_FLAG_BLOCKING)
    175                         devman_phone_client = ipc_connect_me_to_blocking(PHONE_NS,
    176                             SERVICE_DEVMAN, DEVMAN_CLIENT, 0);
    177                 else
    178                         devman_phone_client = ipc_connect_me_to(PHONE_NS,
    179                             SERVICE_DEVMAN, DEVMAN_CLIENT, 0);
    180                
    181                 return devman_phone_client;
    182         default:
     152
     153int driver_main(driver_t *drv)
     154{
     155        // remember driver structure - driver_ops will be called by generic handler for incoming connections
     156        driver = drv;
     157       
     158        // register driver by device manager with generic handler for incoming connections
     159        printf("%s: sending registration request to devman.\n", driver->name);
     160        devman_driver_register(driver->name, driver_connection);               
     161
     162        async_manager();
     163
     164        // Never reached
     165        return 0;
     166       
     167}
     168
     169////////////////////////////////////////
     170// ROOT driver
     171////////////////////////////////////////
     172
     173#define NAME "root"
     174
     175
     176
     177bool root_add_device(device_t *dev)
     178{
     179        // TODO add root device and register its children
     180        return true;
     181}
     182
     183static driver_ops_t root_ops = {
     184        .add_device = &root_add_device
     185};
     186
     187static driver_t root_driver = {
     188        .name = NAME,
     189        .driver_ops = &root_ops
     190};
     191
     192bool root_init()
     193{
     194        // TODO  driver initialization 
     195        return true;
     196}
     197
     198int main(int argc, char *argv[])
     199{
     200        printf(NAME ": HelenOS root device driver\n");
     201        if (!root_init()) {
     202                printf(NAME ": Error while initializing driver.\n");
    183203                return -1;
    184204        }
    185 }
    186 
    187 /** Register new driver with device manager. */
    188 int devman_driver_register(const char *name, async_client_conn_t conn)
    189 {
    190         int phone = devman_get_phone(DEVMAN_DRIVER, IPC_FLAG_BLOCKING);
    191        
    192         if (phone < 0)
    193                 return phone;
    194        
    195         async_serialize_start();
    196        
    197         ipc_call_t answer;
    198         aid_t req = async_send_2(phone, DEVMAN_DRIVER_REGISTER, 0, 0, &answer);
    199        
    200         ipcarg_t retval = async_data_write_start(phone, name, str_size(name));
    201         if (retval != EOK) {
    202                 async_wait_for(req, NULL);
    203                 async_serialize_end();
    204                 return -1;
    205         }
    206        
    207         async_set_client_connection(conn);
    208        
    209         ipcarg_t callback_phonehash;
    210         ipc_connect_to_me(phone, 0, 0, 0, &callback_phonehash);
    211         async_wait_for(req, &retval);
    212        
    213         async_serialize_end();
    214        
    215         return retval;
    216 }
    217 
    218 int driver_main(driver_t *drv)
    219 {
    220         // remember driver structure - driver_ops will be called by generic handler for incoming connections
    221         driver = drv;
    222        
    223         // register driver by device manager with generic handler for incoming connections
    224         devman_driver_register(driver->name, driver_connection);               
    225 
    226         async_manager();
    227 
    228         // Never reached
    229         return 0;
    230        
    231 }
    232 
    233 ////////////////////////////////////////
    234 // ROOT driver
    235 ////////////////////////////////////////
    236 
    237 #define NAME "root"
    238 
    239 static driver_t root_driver;
    240 
    241 bool root_add_device(device_t *dev)
    242 {
    243         // TODO
    244         return true;
    245 }
    246 
    247 bool root_init(driver_t *drv, const char *name)
    248 {
    249         // TODO  initialize driver structure
    250        
    251         return true;
    252 }
    253 
    254 int main(int argc, char *argv[])
    255 {
    256         printf(NAME ": HelenOS root device driver\n");
    257         if (!root_init(&root_driver, argv[0])) {
    258                 printf(NAME ": Error while initializing driver\n");
    259                 return -1;
    260         }
    261205       
    262206        return driver_main(&root_driver);
    263 
    264 }
     207}
Note: See TracChangeset for help on using the changeset viewer.