Changeset 9a66bc2 in mainline


Ignore:
Timestamp:
2010-04-04T21:52:26Z (14 years ago)
Author:
Lenka Trochtova <trochtova.lenka@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8c06905
Parents:
5cd136ab
Message:

several bugs fixed

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • boot/arch/amd64/Makefile.inc

    r5cd136ab r9a66bc2  
    3838RD_DRVS = \
    3939        root \
    40         rootia32
     40        rootia32 \
     41        pciintel
    4142
    4243MODULES := $(notdir $(COMPONENTS))
  • uspace/Makefile

    r5cd136ab r9a66bc2  
    7878        DIRS += srv/dd
    7979        DIRS += srv/drivers/rootia32
     80        DIRS += srv/drivers/pciintel
    8081#       DIRS += srv/hw/bus/pci
    8182endif
  • uspace/lib/libc/generic/device/hw_res.c

    r5cd136ab r9a66bc2  
    5252        hw_resources->resources = (hw_resource_t *)malloc(size);
    5353        if (NULL == hw_resources->resources) {
    54                 size = 0;
    55                 ret = false;
     54                return false;
    5655        }
    5756       
     
    6059                free(hw_resources->resources);
    6160                hw_resources->resources = NULL;
    62                 ret = false;
     61                return false;
    6362        }
    6463                 
    65         return ret;     
     64        return true;     
    6665}
    6766
  • uspace/lib/libdrv/generic/driver.c

    r5cd136ab r9a66bc2  
    5757static driver_t *driver;
    5858LIST_INITIALIZE(devices);
     59FIBRIL_MUTEX_INITIALIZE(devices_mutex);
    5960
    6061static device_t * driver_create_device()
     
    6768}
    6869
     70static void add_to_devices_list(device_t *dev)
     71{
     72        fibril_mutex_lock(&devices_mutex);
     73        list_append(&dev->link, &devices);
     74        fibril_mutex_unlock(&devices_mutex);
     75}
     76
     77static void remove_from_devices_list(device_t *dev)
     78{
     79        fibril_mutex_lock(&devices_mutex);
     80        list_append(&dev->link, &devices);
     81        fibril_mutex_unlock(&devices_mutex);
     82}
     83
    6984static device_t * driver_get_device(link_t *devices, device_handle_t handle)
    7085{
    7186        device_t *dev = NULL;
     87       
     88        fibril_mutex_lock(&devices_mutex);     
    7289        link_t *link = devices->next;
    73 
    7490        while (link != devices) {
    7591                dev = list_get_instance(link, device_t, link);
    7692                if (handle == dev->handle) {
     93                        fibril_mutex_unlock(&devices_mutex);
    7794                        return dev;
    7895                }
    79         }
     96                link = link->next;
     97        }
     98        fibril_mutex_unlock(&devices_mutex);
    8099
    81100        return NULL;
     
    86105        printf("%s: driver_add_device\n", driver->name);
    87106
    88         // result of the operation - device was added, device is not present etc.
    89         ipcarg_t ret = 0;
     107        // TODO device state - the driver may detect the device is not actually present
     108        // (old non PnP devices) or is not working properly.
     109        // We should send such information to device manager.
     110       
     111        ipcarg_t ret;
    90112        device_handle_t dev_handle =  IPC_GET_ARG1(*icall);
    91113        device_t *dev = driver_create_device();
    92114        dev->handle = dev_handle;
    93         if (driver->driver_ops->add_device(dev)) {
    94                 list_append(&dev->link, &devices);
    95                 // TODO set return value
    96         }
    97         printf("%s: new device with handle = %x was added.\n", driver->name, dev_handle);
    98 
     115        add_to_devices_list(dev);
     116        if (driver->driver_ops->add_device(dev)) {             
     117                printf("%s: new device with handle = %x was added.\n", driver->name, dev_handle);
     118                ret = 1;
     119        } else {
     120                printf("%s: failed to add a new device with handle = %x.\n", driver->name, dev_handle);
     121                remove_from_devices_list(dev);
     122                // TODO delete device           
     123                ret = 0;
     124        }
    99125        ipc_answer_1(iid, EOK, ret);
    100126}
     
    129155 * Generic client connection handler both for applications and drivers.
    130156 *
    131  * @param driver true for driver client, false for other clients (applications, services etc.).
    132  */
    133 static void driver_connection_gen(ipc_callid_t iid, ipc_call_t *icall, bool driver)
     157 * @param drv true for driver client, false for other clients (applications, services etc.).
     158 */
     159static void driver_connection_gen(ipc_callid_t iid, ipc_call_t *icall, bool drv)
    134160{
    135161        // Answer the first IPC_M_CONNECT_ME_TO call and remember the handle of the device to which the client connected.
    136         device_handle_t handle = IPC_GET_ARG1(*icall);
     162        device_handle_t handle = IPC_GET_ARG2(*icall);
    137163        device_t *dev = driver_get_device(&devices, handle);
    138164
    139165        if (dev == NULL) {
     166                printf("%s: driver_connection_gen error - no device with handle %x was found.\n", driver->name, handle);
    140167                ipc_answer_0(iid, ENOENT);
    141168                return;
     
    147174        // TODO open the device (introduce some callbacks for opening and closing devices registered by the driver)
    148175       
    149         ipc_answer_0(iid, EOK);
     176        printf("%s: driver_connection_gen: accepting connection.\n", driver->name);
     177        ipc_answer_0(iid, EOK);
    150178
    151179        while (1) {
     
    153181                ipc_call_t call;
    154182
     183                printf("%s: driver_connection_gen: waiting for call.\n", driver->name);
    155184                callid = async_get_call(&call);
    156185                ipcarg_t method = IPC_GET_METHOD(call);
     
    166195                        if (!is_valid_iface_id(method)) {
    167196                                // this is not device's interface
     197                                printf("%s: driver_connection_gen error - invalid interface id %x.", driver->name, method);
    168198                                ipc_answer_0(callid, ENOTSUP);
    169199                                break;
     
    175205                        void *iface = device_get_iface(dev, method);
    176206                        if (NULL == iface) {
     207                                printf("%s: driver_connection_gen error - ", driver->name);
     208                                printf("device with handle %x has no interface with id %x.\n", handle, method);
    177209                                ipc_answer_0(callid, ENOTSUP);
    178210                                break;
     
    188220                        if (NULL == iface_method_ptr) {
    189221                                // the interface has not such method
     222                                printf("%s: driver_connection_gen error - invalid interface method.", driver->name);
    190223                                ipc_answer_0(callid, ENOTSUP);
    191224                                break;
     
    203236static void driver_connection_driver(ipc_callid_t iid, ipc_call_t *icall)
    204237{
     238        printf("%s: driver_connection_driver\n", driver->name);
    205239        driver_connection_gen(iid, icall, true);
    206240}
     
    208242static void driver_connection_client(ipc_callid_t iid, ipc_call_t *icall)
    209243{
     244        printf("%s: driver_connection_client\n", driver->name);
    210245        driver_connection_gen(iid, icall, false);
    211246}
     
    244279        assert(NULL != child->name);
    245280
     281        add_to_devices_list(child);
    246282        if (EOK == devman_child_device_register(child->name, &child->match_ids, parent->handle, &child->handle)) {
    247283                return true;
    248284        }
     285        remove_from_devices_list(child);       
    249286        return false;
    250287}
  • uspace/lib/libdrv/include/driver.h

    r5cd136ab r9a66bc2  
    8080        device_handle_t handle;
    8181        /** The phone to the parent device driver.*/
    82         ipcarg_t parent_phone;
     82        int parent_phone;
    8383        /** The device's name.*/
    8484        const char *name;
  • uspace/srv/devman/main.c

    r5cd136ab r9a66bc2  
    258258}
    259259
    260 static void devman_forward(ipc_callid_t iid, ipc_call_t *icall, bool drv_to_parent) {
    261         device_handle_t handle;
     260static void devman_forward(ipc_callid_t iid, ipc_call_t *icall, bool drv_to_parent) {   
     261       
     262        device_handle_t handle = IPC_GET_ARG2(*icall);
     263        printf(NAME ": devman_forward - trying to forward connection to device with handle %x.\n", handle);
     264       
    262265        node_t *dev = find_dev_node(&device_tree, handle);
    263266        if (NULL == dev) {
     267                printf(NAME ": devman_forward error - no device with handle %x was found.\n", handle);
    264268                ipc_answer_0(iid, ENOENT);
    265269                return;
     
    269273       
    270274        if (drv_to_parent) {
    271                 driver = dev->parent->drv;
     275                if (NULL != dev->parent) {
     276                        driver = dev->parent->drv;             
     277                }
    272278        } else {
    273279                driver = dev->drv;             
    274280        }
    275281       
    276         if (NULL == driver) {           
     282        if (NULL == driver) {   
     283                printf(NAME ": devman_forward error - no driver to connect to.\n", handle);
    277284                ipc_answer_0(iid, ENOENT);
    278285                return;
     
    286293        }
    287294       
     295        if (driver->phone <= 0) {
     296                printf(NAME ": devman_forward: cound not forward to driver %s (the driver's phone is %x).\n", driver->name, driver->phone);
     297                return;
     298        }
     299        printf(NAME ": devman_forward: forward to driver %s with phone %d.\n", driver->name, driver->phone);
    288300        ipc_forward_fast(iid, driver->phone, method, dev->handle, 0, IPC_FF_NONE);     
    289301}
  • uspace/srv/drivers/rootia32/rootia32.c

    r5cd136ab r9a66bc2  
    5050#include <ipc/devman.h>
    5151#include <ipc/dev_iface.h>
     52#include <resource.h>
    5253
    5354#define NAME "rootia32"
    5455
    55 typedef struct rootia32_dev_data {
     56typedef struct rootia32_child_dev_data {
    5657        hw_resource_list_t hw_resources;       
    57 } rootia32_dev_data_t;
     58} rootia32_child_dev_data_t;
    5859
    5960static bool rootia32_add_device(device_t *dev);
     
    8283};
    8384
    84 static rootia32_dev_data_t pci_data = {
     85static rootia32_child_dev_data_t pci_data = {
    8586        .hw_resources = {
    8687                1,
     
    8990};
    9091
     92static hw_resource_list_t * rootia32_get_child_resources(device_t *dev)
     93{
     94        rootia32_child_dev_data_t *data = (rootia32_child_dev_data_t *)dev->driver_data;
     95        if (NULL == data) {
     96                return NULL;
     97        }
     98        return &data->hw_resources;
     99}
     100
     101static bool rootia32_enable_child_interrupt(device_t *dev)
     102{
     103        // TODO
     104       
     105        return false;
     106}
     107
     108static resource_iface_t child_res_iface = {
     109        &rootia32_get_child_resources,
     110        &rootia32_enable_child_interrupt       
     111};
     112
    91113static bool rootia32_add_child(
    92114        device_t *parent, const char *name, const char *str_match_id,
    93         rootia32_dev_data_t *drv_data)
     115        rootia32_child_dev_data_t *drv_data)
    94116{
    95117        printf(NAME ": adding new child device '%s'.\n", name);
     
    113135        match_id->score = 100;
    114136        add_match_id(&child->match_ids, match_id);     
     137       
     138        // add an interface to the device
     139        device_set_iface(child, HW_RES_DEV_IFACE, &child_res_iface);
    115140       
    116141        // register child  device
     
    151176        if (!rootia32_add_children(dev)) {
    152177                printf(NAME ": failed to add child devices for platform ia32.\n");
    153                 return false;
    154178        }
    155179       
Note: See TracChangeset for help on using the changeset viewer.