Changeset c16cf62 in mainline for uspace/srv/drivers/root/root.c


Ignore:
Timestamp:
2010-02-26T14:22:33Z (14 years ago)
Author:
Lenka Trochtova <trochtova.lenka@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
67ba309
Parents:
92413de
Message:

backup (unstable)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/drivers/root/root.c

    r92413de rc16cf62  
    2828
    2929/**
    30  * @defgroup root device driver.
     30 * @defgroup root Root device driver.
    3131 * @brief HelenOS root device driver.
    3232 * @{
     
    3737
    3838#include <assert.h>
    39 #include <ipc/services.h>
    40 #include <ipc/ns.h>
    41 #include <async.h>
    4239#include <stdio.h>
    4340#include <errno.h>
     
    4845#include <ctype.h>
    4946
     47#include <driver.h>
    5048#include <devman.h>
    5149#include <ipc/devman.h>
    5250
    53 
    54 ////////////////////////////////////////
    55 // rudiments of generic driver support
    56 // TODO - create library(ies) for this functionality
    57 ////////////////////////////////////////
    58 
    59 typedef enum {
    60         DRIVER_DEVMAN = 1,
    61         DRIVER_CLIENT,
    62         DRIVER_DRIVER
    63 } driver_interface_t;
    64 
    65 typedef struct device {
    66         int parent_handle;
    67         ipcarg_t parent_phone; 
    68         // TODO add more items - parent bus type etc.
    69         int handle;     
    70 } device_t;
    71 
    72 typedef struct driver_ops {     
    73         bool (*add_device)(device_t *dev);
    74         // TODO add other generic driver operations
    75 } driver_ops_t;
    76 
    77 typedef struct driver {
    78         const char *name;
    79         driver_ops_t *driver_ops;
    80 } driver_t;
    81 
    82 
    83 static driver_t *driver;
    84 
    85 
    86 static void driver_connection_devman(ipc_callid_t iid, ipc_call_t *icall)
    87 {
    88         /* Accept connection */
    89         ipc_answer_0(iid, EOK);
    90        
    91         bool cont = true;
    92         while (cont) {
    93                 ipc_call_t call;
    94                 ipc_callid_t callid = async_get_call(&call);
    95                
    96                 switch (IPC_GET_METHOD(call)) {
    97                 case IPC_M_PHONE_HUNGUP:
    98                         cont = false;
    99                         continue;
    100                 case DRIVER_ADD_DEVICE:
    101                         // TODO
    102                         break;
    103                 default:
    104                         if (!(callid & IPC_CALLID_NOTIFICATION))
    105                                 ipc_answer_0(callid, ENOENT);
    106                 }
    107         }
    108        
    109 }
    110 
    111 static void driver_connection_driver(ipc_callid_t iid, ipc_call_t *icall)
    112 {
    113         // TODO later
    114 }
    115 
    116 static void driver_connection_client(ipc_callid_t iid, ipc_call_t *icall)
    117 {
    118         // TODO later
    119 }
    120 
    121 
    122 
    123 
    124 /** Function for handling connections to device driver.
    125  *
    126  */
    127 static void driver_connection(ipc_callid_t iid, ipc_call_t *icall)
    128 {
    129         ipc_callid_t callid;
    130         /* Select interface */
    131         switch ((ipcarg_t) (IPC_GET_ARG1(*icall))) {
    132         case DRIVER_DEVMAN:
    133                 // handle PnP events from device manager
    134                 driver_connection_devman(iid, icall);
    135                 break;
    136         case DRIVER_DRIVER:
    137                 // handle request from drivers of child devices
    138                 driver_connection_driver(iid, icall);
    139                 break;
    140         case DRIVER_CLIENT:
    141                 // handle requests from client applications
    142                 driver_connection_client(iid, icall);
    143                 break;
    144 
    145         default:
    146                 /* No such interface */
    147                 ipc_answer_0(iid, ENOENT);
    148         }
    149 }
    150 
    151 
    152 
    153 int 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 
    17351#define NAME "root"
    17452
    175 
    176 
    177 bool root_add_device(device_t *dev)
    178 {
    179         // TODO add root device and register its children
    180         return true;
    181 }
     53static bool root_add_device(device_t *dev);
     54static bool root_init();
    18255
    18356static driver_ops_t root_ops = {
     
    19063};
    19164
    192 bool root_init()
     65static bool root_add_device(device_t *dev)
     66{
     67        // TODO add root device and register its children
     68        return true;
     69}
     70
     71static bool root_init()
    19372{
    19473        // TODO  driver initialization 
     
    20685        return driver_main(&root_driver);
    20786}
     87
     88/**
     89 * @}
     90 */
Note: See TracChangeset for help on using the changeset viewer.