Changeset c16cf62 in mainline


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)

Location:
uspace
Files:
3 added
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/Makefile

    r92413de rc16cf62  
    9797        lib/softint \
    9898        lib/softfloat \
     99        lib/libdrv
    99100
    100101ifeq ($(UARCH),amd64)
  • uspace/lib/libc/include/devman.h

    r92413de rc16cf62  
    11/*
    22 * Copyright (c) 2009 Jiri Svoboda
    3  * Copyright (c) 2010 Lenka Trochtova *
     3 * Copyright (c) 2010 Lenka Trochtova
    44 * All rights reserved.
    55 *
  • uspace/lib/libc/include/ipc/devman.h

    r92413de rc16cf62  
    5555} devman_to_driver_t;
    5656
     57#endif
    5758
    58 
    59 
    60 
    61 
    62 
    63 
    64 
    65 #endif
     59/** @}
     60 */
  • uspace/srv/Makefile.common

    r92413de rc16cf62  
    4949LIBPCI_PREFIX = $(USPACE_PREFIX)/lib/libpci
    5050SOFTINT_PREFIX = $(USPACE_PREFIX)/lib/softint
     51LIBDRV_PREFIX = $(USPACE_PREFIX)/lib/libdrv
    5152
    5253LINK_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld
  • uspace/srv/devman/devman.c

    r92413de rc16cf62  
    428428}
    429429
     430void set_driver_phone(driver_t *driver, ipcarg_t phone)
     431{               
     432        fibril_mutex_lock(&driver->driver_mutex);       
     433        assert(DRIVER_STARTING == driver->state);
     434        driver->phone = phone; 
     435        fibril_mutex_unlock(&driver->driver_mutex);     
     436}
     437
     438/**
     439 * Notify driver about the devices to which it was assigned.
     440 *
     441 * The driver's mutex must be locked.
     442 *
     443 * @param driver the driver to which the devices are passed.
     444 */
     445static void pass_devices_to_driver(driver_t *driver)
     446{       
     447        node_t *dev;
     448        link_t *link;
     449       
     450        link = driver->devices.next;
     451        while (link != &driver->devices) {
     452                dev = list_get_instance(link, node_t, driver_devices);
     453                add_device(driver, dev);
     454                link = link->next;
     455        }       
     456}
     457
     458/** Finish the initialization of a driver after it has succesfully started and registered itself by the device manager.
     459 *
     460 * Pass devices formerly matched to the driver to the driver and remember the driver is running and fully functional now.
     461 *
     462 * @param driver the driver which registered itself as running by the device manager.
     463 */
     464void initialize_running_driver(driver_t *driver)
     465{
     466        fibril_mutex_lock(&driver->driver_mutex);
     467       
     468        // pass devices which have been already assigned to the driver to the driver
     469        pass_devices_to_driver(driver);
     470       
     471        // change driver's state to running
     472        driver->state = DRIVER_RUNNING;
     473       
     474        fibril_mutex_unlock(&driver->driver_mutex);
     475}
     476
    430477/** Pass a device to running driver.
    431478 *
    432479 * @param drv the driver's structure.
    433480 * @param node the device's node in the device tree.
    434  *
    435  * @return true on success, false otherwise.
    436  */
    437 bool add_device(driver_t *drv, node_t *node)
     481 */
     482void add_device(driver_t *drv, node_t *node)
    438483{
    439484        printf(NAME ": add_device\n");
     
    506551}
    507552
     553/** @}
     554 */
  • uspace/srv/devman/devman.h

    r92413de rc16cf62  
    191191void add_driver(driver_list_t *drivers_list, driver_t *drv);
    192192void attach_driver(node_t *node, driver_t *drv);
    193 bool add_device(driver_t *drv, node_t *node);
     193void add_device(driver_t *drv, node_t *node);
    194194bool start_driver(driver_t *drv);
    195195
    196196driver_t * find_driver(driver_list_t *drv_list, const char *drv_name);
     197void set_driver_phone(driver_t *driver, ipcarg_t phone);
     198void initialize_running_driver(driver_t *driver);
    197199
    198200
     
    260262
    261263#endif
     264
     265/** @}
     266 */
  • uspace/srv/devman/main.c

    r92413de rc16cf62  
    6060
    6161/**
    62  *
    63  *
    64  * Driver's mutex must be locked.
    65  */
    66 static void pass_devices_to_driver(driver_t *driver)
    67 {
    68        
    69 
    70        
    71        
    72 }
    73 
    74 static 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 /**
    8862 * Register running driver.
    8963 */
     
    134108        }
    135109       
    136         fibril_mutex_lock(&driver->driver_mutex);
    137         assert(DRIVER_STARTING == driver->state);
    138         driver->phone = IPC_GET_ARG5(call);     
    139         fibril_mutex_unlock(&driver->driver_mutex);     
     110        // remember driver's phone
     111        set_driver_phone(driver, IPC_GET_ARG5(call));
    140112       
    141113        printf(NAME ":  the %s driver was successfully registered as running.\n", driver->name);
     
    160132                return;
    161133               
    162         init_running_driver(driver);
     134        initialize_running_driver(driver);
    163135       
    164136        ipc_callid_t callid;
     
    251223        return 0;
    252224}
     225
     226/** @}
     227 */
  • uspace/srv/drivers/root/Makefile

    r92413de rc16cf62  
    2727
    2828USPACE_PREFIX = ../../..
    29 LIBS = $(LIBC_PREFIX)/libc.a
     29LIBS = $(LIBC_PREFIX)/libc.a $(LIBDRV_PREFIX)/libdrv.a
    3030
    3131OUTPUT = root
     
    3535
    3636include ../../Makefile.common
     37
     38EXTRA_CFLAGS = -I$(LIBDRV_PREFIX)/include
  • 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.