Changeset 3ad7b1c in mainline


Ignore:
Timestamp:
2011-04-09T09:28:08Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
26fa82bc
Parents:
033cbf82
Message:

Make devman robust against somebody manually starting a driver. Allow it
if the driver is not running yet. Prevent it if the driver is already
running. Fix phoneid check (zero is valid).

Location:
uspace
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/drv/generic/driver.c

    r033cbf82 r3ad7b1c  
    4747#include <stdlib.h>
    4848#include <str.h>
     49#include <str_error.h>
    4950#include <ctype.h>
    5051#include <errno.h>
     
    675676        rc = devman_driver_register(driver->name, driver_connection);
    676677        if (rc != EOK) {
    677                 printf("Error: Failed to register driver with device manager.\n");
     678                printf("Error: Failed to register driver with device manager "
     679                    "(%s).\n", (rc == EEXISTS) ? "driver already started" :
     680                    str_error(rc));
     681               
    678682                return 1;
    679683        }
  • uspace/srv/devman/devman.c

    r033cbf82 r3ad7b1c  
    555555}
    556556
    557 /** Remember the driver's phone.
    558  *
    559  * @param driver        The driver.
    560  * @param phone         The phone to the driver.
    561  */
    562 void set_driver_phone(driver_t *driver, sysarg_t phone)
    563 {
    564         fibril_mutex_lock(&driver->driver_mutex);
    565         assert(driver->state == DRIVER_STARTING);
    566         driver->phone = phone;
    567         fibril_mutex_unlock(&driver->driver_mutex);
    568 }
    569 
    570557/** Notify driver about the devices to which it was assigned.
    571558 *
     
    685672        list_initialize(&drv->devices);
    686673        fibril_mutex_initialize(&drv->driver_mutex);
     674        drv->phone = -1;
    687675}
    688676
  • uspace/srv/devman/devman.h

    r033cbf82 r3ad7b1c  
    8888       
    8989        /** Phone asociated with this driver. */
    90         sysarg_t phone;
     90        int phone;
    9191        /** Name of the device driver. */
    9292        char *name;
     
    316316
    317317extern driver_t *find_driver(driver_list_t *, const char *);
    318 extern void set_driver_phone(driver_t *, sysarg_t);
    319318extern void initialize_running_driver(driver_t *, dev_tree_t *);
    320319
  • uspace/srv/devman/main.c

    r033cbf82 r3ad7b1c  
    9595        /* Find driver structure. */
    9696        driver = find_driver(&drivers_list, drv_name);
    97        
    9897        if (driver == NULL) {
    9998                log_msg(LVL_ERROR, "No driver named `%s' was found.", drv_name);
     
    107106        drv_name = NULL;
    108107       
     108        fibril_mutex_lock(&driver->driver_mutex);
     109       
     110        if (driver->phone >= 0) {
     111                /* We already have a connection to the driver. */
     112                log_msg(LVL_ERROR, "Driver '%s' already started.\n",
     113                    driver->name);
     114                fibril_mutex_unlock(&driver->driver_mutex);
     115                async_answer_0(iid, EEXISTS);
     116                return NULL;
     117        }
     118       
     119        switch (driver->state) {
     120        case DRIVER_NOT_STARTED:
     121                /* Somebody started the driver manually. */
     122                log_msg(LVL_NOTE, "Driver '%s' started manually.\n",
     123                    driver->name);
     124                driver->state = DRIVER_STARTING;
     125                break;
     126        case DRIVER_STARTING:
     127                /* The expected case */
     128                break;
     129        case DRIVER_RUNNING:
     130                /* Should not happen since we do not have a connected phone */
     131                assert(false);
     132        }
     133       
    109134        /* Create connection to the driver. */
    110135        log_msg(LVL_DEBUG, "Creating connection to the `%s' driver.",
     
    113138        ipc_callid_t callid = async_get_call(&call);
    114139        if (IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) {
     140                fibril_mutex_unlock(&driver->driver_mutex);
    115141                async_answer_0(callid, ENOTSUP);
    116142                async_answer_0(iid, ENOTSUP);
     
    119145       
    120146        /* Remember driver's phone. */
    121         set_driver_phone(driver, IPC_GET_ARG5(call));
     147        driver->phone = IPC_GET_ARG5(call);
     148       
     149        fibril_mutex_unlock(&driver->driver_mutex);
    122150       
    123151        log_msg(LVL_NOTE,
     
    578606                method = DRIVER_CLIENT;
    579607       
    580         if (driver->phone <= 0) {
     608        if (driver->phone < 0) {
    581609                log_msg(LVL_ERROR,
    582610                    "Could not forward to driver `%s' (phone is %d).",
     
    618646        dev = fun->dev;
    619647       
    620         if (dev->state != DEVICE_USABLE || dev->drv->phone <= 0) {
     648        if (dev->state != DEVICE_USABLE || dev->drv->phone < 0) {
    621649                async_answer_0(iid, EINVAL);
    622650                return;
Note: See TracChangeset for help on using the changeset viewer.