Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 084ff99 in mainline


Ignore:
Timestamp:
2010-03-14T09:14:50Z (12 years ago)
Author:
Lenka Trochtova <trochtova.lenka@…>
Branches:
lfn, master
Children:
7707954
Parents:
67ba309
Message:

passing device to driver (parts of code)

Location:
uspace
Files:
1 added
5 edited

Legend:

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

    r67ba309 r084ff99  
    5050#include <devman.h>
    5151#include <ipc/devman.h>
     52#include <ipc/driver.h>
    5253
    5354#include "driver.h"
    5455
    5556static driver_t *driver;
     57LIST_INITIALIZE(devices);
     58
     59static device_t* driver_create_device()
     60{
     61        device_t *dev = (device_t *)malloc(sizeof(device_t));
     62        if (NULL != dev) {
     63                memset(dev, 0, sizeof(device_t));               
     64        }       
     65        return dev;     
     66}
     67
     68static void driver_add_device(ipc_callid_t iid, ipc_call_t *icall)
     69{
     70        printf("%s: driver_add_device\n", driver->name);
     71       
     72        // result of the operation - device was added, device is not present etc.
     73        ipcarg_t ret = 0;       
     74        ipcarg_t dev_handle =  IPC_GET_ARG1(*icall);
     75       
     76        printf("%s: adding device with handle = %x \n", driver->name, dev_handle);
     77       
     78        device_t *dev = driver_create_device();
     79        dev->handle = dev_handle;
     80        if (driver->driver_ops->add_device(dev)) {
     81                list_append(&dev->link, &devices);
     82                // TODO set return value
     83        }
     84       
     85        ipc_answer_1(iid, EOK, ret);
     86}
    5687
    5788static void driver_connection_devman(ipc_callid_t iid, ipc_call_t *icall)
    5889{
     90        printf("%s: driver_connection_devman \n", driver->name);
     91       
    5992        /* Accept connection */
    6093        ipc_answer_0(iid, EOK);
     
    70103                        continue;
    71104                case DRIVER_ADD_DEVICE:
    72                         // TODO
     105                        driver_add_device(callid, &call);
    73106                        break;
    74107                default:
  • uspace/lib/libdrv/include/driver.h

    r67ba309 r084ff99  
    3232/** @file
    3333 */
    34 
    3534#ifndef LIBDRV_DRIVER_H_
    3635#define LIBDRV_DRIVER_H_
    3736
    38 typedef enum {
    39         DRIVER_DEVMAN = 1,
    40         DRIVER_CLIENT,
    41         DRIVER_DRIVER
    42 } driver_interface_t;
     37
     38#include <adt/list.h>
     39
     40
    4341
    4442typedef struct device {
    45         int parent_handle;
     43        long handle;
    4644        ipcarg_t parent_phone; 
     45       
    4746        // TODO add more items - parent bus type etc.
    48         int handle;     
     47       
     48        link_t link;
    4949} device_t;
    5050
  • uspace/srv/devman/devman.c

    r67ba309 r084ff99  
    3434#include <fcntl.h>
    3535#include <sys/stat.h>
     36#include <ipc/driver.h>
     37#include <ipc/devman.h>
    3638
    3739#include "devman.h"
     
    308310}
    309311
    310 /** Create root device node of the device tree.
    311  *
    312  * @return root device node.
    313  */
    314 node_t * create_root_node()
     312/** Create root device node in the device tree.
     313 *
     314 * @param tree the device tree.
     315 * @return true on success, false otherwise.
     316 */
     317bool create_root_node(dev_tree_t *tree)
    315318{
    316319        printf(NAME ": create_root_node\n");
    317320        node_t *node = create_dev_node();
    318321        if (node) {
    319                 init_dev_node(node, NULL);
     322                insert_dev_node(tree, node, NULL);
    320323                match_id_t *id = create_match_id();
    321324                id->id = "root";
    322325                id->score = 100;
    323326                add_match_id(&node->match_ids, id);
    324         }
    325         return node;   
     327                tree->root_node = node;
     328        }
     329        return node != NULL;   
    326330}
    327331
     
    448452        link_t *link;
    449453       
    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         }       
     454        int phone = ipc_connect_me_to(driver->phone, DRIVER_DEVMAN, 0, 0);
     455       
     456        if (0 < phone) {
     457               
     458                link = driver->devices.next;
     459                while (link != &driver->devices) {
     460                        dev = list_get_instance(link, node_t, driver_devices);
     461                        add_device(phone, driver, dev);
     462                        link = link->next;
     463                }
     464               
     465                ipc_hangup(phone);
     466        }
    456467}
    457468
     
    463474 */
    464475void initialize_running_driver(driver_t *driver)
    465 {
     476{       
    466477        fibril_mutex_lock(&driver->driver_mutex);
    467478       
     
    480491 * @param node the device's node in the device tree.
    481492 */
    482 void add_device(driver_t *drv, node_t *node)
     493void add_device(int phone, driver_t *drv, node_t *node)
    483494{
    484495        printf(NAME ": add_device\n");
    485        
    486         // TODO
    487        
    488         // pass a new device to the running driver, which was previously assigned to it
    489                 // send the phone of the parent's driver and device's handle within the parent's driver to the driver
    490                 // let the driver to probe the device and specify whether the device is actually present
    491                 // if the device is present, remember its handle within the driver
     496
     497        ipcarg_t ret;
     498        ipcarg_t rc = async_req_1_1(phone, DRIVER_ADD_DEVICE, node->handle, &ret);
     499        if (rc != EOK) {
     500                // TODO handle error
     501                return false;
     502        }
     503       
     504        // TODO inspect return value (ret) to find out whether the device was successfully probed and added
    492505       
    493506        return true;
    494507}
    495508
    496 /**
     509/** 
    497510 * Find suitable driver for a device and assign the driver to it.
    498511 *
     
    523536        if (DRIVER_RUNNING == drv->state) {
    524537                // notify driver about new device
    525                 add_device(drv, node);         
     538                int phone = ipc_connect_me_to(drv->phone, DRIVER_DEVMAN, 0, 0);
     539                if (phone > 0) {
     540                        add_device(phone, drv, node);           
     541                        ipc_hangup(phone);
     542                }
    526543        }
    527544       
     
    542559        printf(NAME ": init_device_tree.\n");
    543560       
     561        atomic_set(&tree->current_handle, 0);
     562       
    544563        // create root node and add it to the device tree
    545         if (NULL == (tree->root_node = create_root_node())) {
     564        if (!create_root_node(tree)) {
    546565                return false;
    547566        }
  • uspace/srv/devman/devman.h

    r67ba309 r084ff99  
    4141#include <ipc/ipc.h>
    4242#include <fibril_synch.h>
     43#include <atomic.h>
    4344
    4445#include "util.h"
     
    115116/** Representation of a node in the device tree.*/
    116117struct node {
     118        /** The global unique identifier of the device.*/
     119        long handle;
    117120        /** The node of the parent device. */
    118121        node_t *parent;
     
    137140        /** Root device node. */
    138141        node_t *root_node;
     142        atomic_t current_handle;
    139143} dev_tree_t;
    140144
     
    191195void add_driver(driver_list_t *drivers_list, driver_t *drv);
    192196void attach_driver(node_t *node, driver_t *drv);
    193 void add_device(driver_t *drv, node_t *node);
     197void add_device(int phone, driver_t *drv, node_t *node);
    194198bool start_driver(driver_t *drv);
    195199
     
    230234
    231235// Device nodes
    232 node_t * create_root_node();
    233236
    234237static inline node_t * create_dev_node()
     
    238241                memset(res, 0, sizeof(node_t));
    239242        }
     243       
     244        list_initialize(&res->children);
     245        list_initialize(&res->match_ids.ids);
     246       
    240247        return res;
    241248}
    242249
    243 static inline void init_dev_node(node_t *node, node_t *parent)
    244 {
    245         assert(NULL != node);
     250static inline void insert_dev_node(dev_tree_t *tree, node_t *node, node_t *parent)
     251{
     252        assert(NULL != node && NULL != tree);
     253       
     254        node->handle = atomic_postinc(&tree->current_handle);
    246255
    247256        node->parent = parent;
    248257        if (NULL != parent) {
     258                fibril_mutex_lock(&parent->children_mutex);
    249259                list_append(&node->sibling, &parent->children);
     260                fibril_mutex_unlock(&parent->children_mutex);
    250261        }
    251 
    252         list_initialize(&node->children);
    253 
    254         list_initialize(&node->match_ids.ids);
    255262}
    256263
     
    259266
    260267bool init_device_tree(dev_tree_t *tree, driver_list_t *drivers_list);
     268bool create_root_node(dev_tree_t *tree);
    261269
    262270
  • uspace/srv/drivers/root/root.c

    r67ba309 r084ff99  
    6565static bool root_add_device(device_t *dev)
    6666{
     67        printf(NAME ": root_add_device, device handle = %s", dev->handle);
    6768        // TODO add root device and register its children
    6869        return true;
Note: See TracChangeset for help on using the changeset viewer.