Changeset df747b9c in mainline


Ignore:
Timestamp:
2010-04-23T11:30:25Z (14 years ago)
Author:
Lenka Trochtova <trochtova.lenka@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5af21c5
Parents:
a78fa2a
Message:

added device states (usable, invalid, not present, not initialized); add_device driver callback method returns integer (errno) instead of bool

Location:
uspace
Files:
10 edited

Legend:

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

    ra78fa2a rdf747b9c  
    103103static void driver_add_device(ipc_callid_t iid, ipc_call_t *icall)
    104104{
    105         // TODO device state - the driver may detect the device is not actually present
    106         // (old non PnP devices) or is not working properly.
    107         // We should send such information to device manager.
    108        
    109         ipcarg_t ret;
     105        char *dev_name = NULL;
     106        int res = EOK;
     107       
    110108        device_handle_t dev_handle =  IPC_GET_ARG1(*icall);
    111109        device_t *dev = driver_create_device();
    112110        dev->handle = dev_handle;
    113         async_string_receive(&dev->name, 0, NULL);
    114         add_to_devices_list(dev);
    115         if (driver->driver_ops->add_device(dev)) {             
     111       
     112        async_string_receive(&dev_name, 0, NULL);
     113        dev->name = dev_name;
     114       
     115        add_to_devices_list(dev);               
     116        res = driver->driver_ops->add_device(dev);
     117        if (0 == res) {
    116118                printf("%s: new device with handle = %x was added.\n", driver->name, dev_handle);
    117                 ret = 1;
    118119        } else {
    119                 printf("%s: failed to add a new device with handle = %x.\n", driver->name, dev_handle);
     120                printf("%s: failed to add a new device with handle = %d.\n", driver->name, dev_handle);
    120121                remove_from_devices_list(dev);
    121                 // TODO delete device           
    122                 ret = 0;
    123         }
    124         ipc_answer_0(iid, EOK);
     122                delete_device(dev);             
     123        }
     124       
     125        ipc_answer_0(iid, res);
    125126}
    126127
     
    270271}
    271272
    272 bool child_device_register(device_t *child, device_t *parent)
     273int child_device_register(device_t *child, device_t *parent)
    273274{
    274275        // printf("%s: child_device_register\n", driver->name);
     
    276277        assert(NULL != child->name);
    277278
     279        int res;
     280       
    278281        add_to_devices_list(child);
    279         if (EOK == devman_child_device_register(child->name, &child->match_ids, parent->handle, &child->handle)) {
    280                 return true;
     282        if (EOK == (res = devman_child_device_register(child->name, &child->match_ids, parent->handle, &child->handle))) {
     283                return res;
    281284        }
    282285        remove_from_devices_list(child);       
    283         return false;
     286        return res;
    284287}
    285288
  • uspace/lib/libdrv/include/driver.h

    ra78fa2a rdf747b9c  
    109109typedef struct driver_ops {
    110110        /** Callback method for passing a new device to the device driver.*/
    111         bool (*add_device)(device_t *dev);
     111        int (*add_device)(device_t *dev);
    112112        // TODO add other generic driver operations
    113113} driver_ops_t;
     
    161161}
    162162
    163 bool child_device_register(device_t *child, device_t *parent);
     163int child_device_register(device_t *child, device_t *parent);
    164164
    165165
  • uspace/srv/devman/devman.c

    ra78fa2a rdf747b9c  
    519519        async_wait_for(req, &rc);
    520520        switch(rc) {
    521                 // TODO inspect return value to find out whether the device was successfully probed and added
    522521        case EOK:
     522                node->state = DEVICE_USABLE;
     523                break;
    523524        case ENOENT:
    524                
     525                node->state = DEVICE_NOT_PRESENT;
    525526                break;
    526                
     527        default:
     528                node->state = DEVICE_INVALID;           
    527529        }
    528530       
  • uspace/srv/devman/devman.h

    ra78fa2a rdf747b9c  
    9393} driver_list_t;
    9494
     95/** The state of the device. */
     96typedef enum {
     97        DEVICE_NOT_INITIALIZED = 0,
     98        DEVICE_USABLE,
     99        DEVICE_NOT_PRESENT,
     100        DEVICE_INVALID
     101} device_state_t;
     102
    95103/** Representation of a node in the device tree.*/
    96104struct node {
     
    113121        /** Driver of this device.*/
    114122        driver_t *drv;
     123        /** The state of the device. */
     124        device_state_t state;
    115125        /** Pointer to the previous and next device in the list of devices
    116126            owned by one driver */
  • uspace/srv/devman/main.c

    ra78fa2a rdf747b9c  
    309309                        driver = dev->parent->drv;             
    310310                }
    311         } else {
     311        } else if (DEVICE_USABLE == dev->state) {
    312312                driver = dev->drv;             
     313                assert(NULL != driver);
    313314        }
    314315       
    315316        if (NULL == driver) {   
    316                 printf(NAME ": devman_forward error - no driver to connect to.\n", handle);
     317                printf(NAME ": devman_forward error - the device is not in usable state.\n", handle);
    317318                ipc_answer_0(iid, ENOENT);
    318319                return;
     
    331332                return;
    332333        }
    333         printf(NAME ": devman_forward: forward connection to device %s to driver %s with phone %d.\n",
    334                 dev->pathname, driver->name, driver->phone);
     334        printf(NAME ": devman_forward: forward connection to device %s to driver %s.\n", dev->pathname, driver->name);
    335335        ipc_forward_fast(iid, driver->phone, method, dev->handle, 0, IPC_FF_NONE);     
    336336}
  • uspace/srv/drivers/isa/isa.c

    ra78fa2a rdf747b9c  
    8989static device_class_t isa_child_class;
    9090
    91 static bool isa_add_device(device_t *dev);
     91static int isa_add_device(device_t *dev);
    9292
    9393/** The isa device driver's standard operations.
     
    474474}
    475475
    476 static bool isa_add_device(device_t *dev)
     476static int isa_add_device(device_t *dev)
    477477{
    478478        printf(NAME ": isa_add_device, device handle = %d\n", dev->handle);
     
    482482        printf(NAME ": finished the enumeration of legacy devices\n", dev->handle);
    483483       
    484         return true;
     484        return EOK;
    485485}
    486486
  • uspace/srv/drivers/pciintel/pci.c

    ra78fa2a rdf747b9c  
    8585
    8686
    87 static bool pci_add_device(device_t *dev);
     87static int pci_add_device(device_t *dev);
    8888
    8989/** The pci bus driver's standard operations.
     
    402402                        create_pci_match_ids(dev);
    403403                       
    404                         if (!child_device_register(dev, parent)) {                             
     404                        if (EOK != child_device_register(dev, parent)) {                               
    405405                                pci_clean_resource_list(dev);                           
    406406                                clean_match_ids(&dev->match_ids);
     
    433433}
    434434
    435 static bool pci_add_device(device_t *dev)
     435static int pci_add_device(device_t *dev)
    436436{
    437437        printf(NAME ": pci_add_device\n");
     
    440440        if (NULL == bus_data) {
    441441                printf(NAME ": pci_add_device allocation failed.\n");
    442                 return false;
     442                return ENOMEM;
    443443        }       
    444444       
     
    447447                printf(NAME ": pci_add_device failed to connect to the parent's driver.\n");
    448448                delete_pci_bus_data(bus_data);
    449                 return false;
     449                return EPARTY;
    450450        }
    451451       
     
    456456                delete_pci_bus_data(bus_data);
    457457                ipc_hangup(dev->parent_phone);
    458                 return false;           
     458                return EPARTY;         
    459459        }       
    460460       
     
    472472                ipc_hangup(dev->parent_phone);
    473473                clean_hw_resource_list(&hw_resources);
    474                 return false;                                   
     474                return EADDRNOTAVAIL;                                   
    475475        }
    476476        bus_data->conf_data_port = (char *)bus_data->conf_addr_port + 4;
     
    484484        clean_hw_resource_list(&hw_resources);
    485485       
    486         return true;
     486        return EOK;
    487487}
    488488
  • uspace/srv/drivers/root/root.c

    ra78fa2a rdf747b9c  
    5252#define NAME "root"
    5353
    54 static bool root_add_device(device_t *dev);
     54static int root_add_device(device_t *dev);
    5555
    5656/** The root device driver's standard operations.
     
    6767};
    6868
    69 /** Create the device which represents the root of HW device tree.
     69/** Create the device which represents the root of HW device tree.
     70 *
    7071 * @param parent parent of the newly created device.
     72 * @return 0 on success, negative error number otherwise.
    7173 */
    72 static bool add_platform_child(device_t *parent) {
     74static int add_platform_child(device_t *parent) {
    7375        printf(NAME ": adding new child for platform device.\n");
    7476       
     77        int res = EOK;
    7578        device_t *platform = NULL;
    7679        match_id_t *match_id = NULL;   
     
    7881        // create new device
    7982        if (NULL == (platform = create_device())) {
     83                res = ENOMEM;
    8084                goto failure;
    8185        }       
     
    8690        // initialize match id list
    8791        if (NULL == (match_id = create_match_id())) {
     92                res = ENOMEM;
    8893                goto failure;
    8994        }
     
    95100       
    96101        // register child  device
    97         if (!child_device_register(platform, parent)) {
     102        res = child_device_register(platform, parent);
     103        if (EOK != res) {
    98104                goto failure;
    99105        }
    100106       
    101         return true;
     107        return res;
    102108       
    103109failure:
     
    111117        }
    112118       
    113         return false;   
     119        return res;     
    114120}
    115121
     
    117123 * @param dev the device which is root of the whole device tree (both of HW and pseudo devices).
    118124 */
    119 static bool root_add_device(device_t *dev)
     125static int root_add_device(device_t *dev)
    120126{
    121127        printf(NAME ": root_add_device, device handle = %d\n", dev->handle);
    122128       
    123129        // register root device's children     
    124         if (!add_platform_child(dev)) {
     130        int res = add_platform_child(dev);     
     131        if (EOK != res) {
    125132                printf(NAME ": failed to add child device for platform.\n");
    126                 return false;
    127133        }
    128134       
    129         return true;
     135        return res;
    130136}
    131137
  • uspace/srv/drivers/rootia32/rootia32.c

    ra78fa2a rdf747b9c  
    5959} rootia32_child_dev_data_t;
    6060
    61 static bool rootia32_add_device(device_t *dev);
     61static int rootia32_add_device(device_t *dev);
    6262static bool rootia32_init();
    6363
     
    144144       
    145145        // register child  device
    146         if (!child_device_register(child, parent)) {
     146        if (EOK != child_device_register(child, parent)) {
    147147                goto failure;
    148148        }
     
    171171
    172172/** Get the root device.
     173 *
    173174 * @param dev the device which is root of the whole device tree (both of HW and pseudo devices).
    174  */
    175 static bool rootia32_add_device(device_t *dev)
     175 * @return 0 on success, negative error number otherwise.
     176 */
     177static int rootia32_add_device(device_t *dev)
    176178{
    177179        printf(NAME ": rootia32_add_device, device handle = %d\n", dev->handle);
     
    182184        }
    183185       
    184         return true;
     186        return EOK;
    185187}
    186188
  • uspace/srv/drivers/serial/serial.c

    ra78fa2a rdf747b9c  
    9393static device_class_t serial_dev_class;
    9494
    95 static bool serial_add_device(device_t *dev);
     95static int serial_add_device(device_t *dev);
    9696
    9797/** The serial port device driver's standard operations.
     
    123123static bool serial_pio_enable(device_t *dev)
    124124{
    125         printf(NAME ": serial_pio_enable = %s\n", dev->name);
     125        printf(NAME ": serial_pio_enable %s\n", dev->name);
    126126       
    127127        serial_dev_data_t *data = (serial_dev_data_t *)dev->driver_data;
     
    138138static bool serial_dev_probe(device_t *dev)
    139139{
    140         printf(NAME ": serial_dev_probe dev = %s\n", dev->name);
     140        printf(NAME ": serial_dev_probe %s\n", dev->name);
    141141       
    142142        serial_dev_data_t *data = (serial_dev_data_t *)dev->driver_data;
     
    166166}
    167167
    168 static bool serial_dev_initialize(device_t *dev)
    169 {
    170         printf(NAME ": serial_dev_initialize dev = %s\n", dev->name);
    171        
     168static int serial_dev_initialize(device_t *dev)
     169{
     170        printf(NAME ": serial_dev_initialize %s\n", dev->name);
     171       
     172        int ret = EOK;
    172173        hw_resource_list_t hw_resources;
    173174        memset(&hw_resources, 0, sizeof(hw_resource_list_t));
     
    176177        serial_dev_data_t *data = create_serial_dev_data();     
    177178        if (NULL == data) {
    178                 return false;
     179                return ENOMEM;
    179180        }
    180181        dev->driver_data = data;
     
    184185        if (dev->parent_phone <= 0) {
    185186                printf(NAME ": failed to connect to the parent driver of the device %s.\n", dev->name);
     187                ret = EPARTY;
    186188                goto failed;
    187189        }
     
    191193        if (!get_hw_resources(dev->parent_phone, &hw_resources)) {
    192194                printf(NAME ": failed to get hw resources for the device %s.\n", dev->name);
     195                ret = EPARTY;
    193196                goto failed;
    194197        }       
     
    211214                        if (res->res.io_range.size < REG_COUNT) {
    212215                                printf(NAME ": i/o range assigned to the device %s is too small.\n", dev->name);
     216                                ret = EPARTY;
    213217                                goto failed;
    214218                        }
     
    221225        if (!irq || !ioport) {
    222226                printf(NAME ": missing hw resource(s) for the device %s.\n", dev->name);
     227                ret = EPARTY;
    223228                goto failed;
    224229        }               
    225230       
    226231        clean_hw_resource_list(&hw_resources);
    227         return true;
     232        return ret;
    228233       
    229234failed:
    230235        serial_dev_cleanup(dev);       
    231236        clean_hw_resource_list(&hw_resources); 
    232         return false;   
    233 }
    234 
    235 static bool serial_add_device(device_t *dev)
    236 {
    237         printf(NAME ": serial_add_device, device handle = %d\n", dev->handle);
    238        
    239         if (!serial_dev_initialize(dev)) {
    240                 return false;
     237        return ret;     
     238}
     239
     240static int serial_add_device(device_t *dev)
     241{
     242        printf(NAME ": serial_add_device %s (handle = %d)\n", dev->name, dev->handle);
     243       
     244        int res = serial_dev_initialize(dev);
     245        if (EOK != res) {
     246                return res;
    241247        }
    242248       
    243249        if (!serial_pio_enable(dev)) {
    244250                serial_dev_cleanup(dev);
    245                 return false;
    246         }
     251                return EADDRNOTAVAIL;
     252        }
     253       
    247254       
    248255        if (!serial_dev_probe(dev)) {
    249256                serial_dev_cleanup(dev);
    250                 return false;
     257                return ENOENT;
    251258        }       
    252259       
    253260        // TODO interrupt and serial port initialization (baud rate etc.)
    254261       
    255         return true;
     262        return EOK;
    256263}
    257264
Note: See TracChangeset for help on using the changeset viewer.