Changeset 084ff99 in mainline
- Timestamp:
- 2010-03-14T09:14:50Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7707954
- Parents:
- 67ba309
- Location:
- uspace
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libdrv/generic/driver.c
r67ba309 r084ff99 50 50 #include <devman.h> 51 51 #include <ipc/devman.h> 52 #include <ipc/driver.h> 52 53 53 54 #include "driver.h" 54 55 55 56 static driver_t *driver; 57 LIST_INITIALIZE(devices); 58 59 static 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 68 static 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 } 56 87 57 88 static void driver_connection_devman(ipc_callid_t iid, ipc_call_t *icall) 58 89 { 90 printf("%s: driver_connection_devman \n", driver->name); 91 59 92 /* Accept connection */ 60 93 ipc_answer_0(iid, EOK); … … 70 103 continue; 71 104 case DRIVER_ADD_DEVICE: 72 // TODO105 driver_add_device(callid, &call); 73 106 break; 74 107 default: -
uspace/lib/libdrv/include/driver.h
r67ba309 r084ff99 32 32 /** @file 33 33 */ 34 35 34 #ifndef LIBDRV_DRIVER_H_ 36 35 #define LIBDRV_DRIVER_H_ 37 36 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 43 41 44 42 typedef struct device { 45 int parent_handle;43 long handle; 46 44 ipcarg_t parent_phone; 45 47 46 // TODO add more items - parent bus type etc. 48 int handle; 47 48 link_t link; 49 49 } device_t; 50 50 -
uspace/srv/devman/devman.c
r67ba309 r084ff99 34 34 #include <fcntl.h> 35 35 #include <sys/stat.h> 36 #include <ipc/driver.h> 37 #include <ipc/devman.h> 36 38 37 39 #include "devman.h" … … 308 310 } 309 311 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 */ 317 bool create_root_node(dev_tree_t *tree) 315 318 { 316 319 printf(NAME ": create_root_node\n"); 317 320 node_t *node = create_dev_node(); 318 321 if (node) { 319 in it_dev_node(node, NULL);322 insert_dev_node(tree, node, NULL); 320 323 match_id_t *id = create_match_id(); 321 324 id->id = "root"; 322 325 id->score = 100; 323 326 add_match_id(&node->match_ids, id); 324 } 325 return node; 327 tree->root_node = node; 328 } 329 return node != NULL; 326 330 } 327 331 … … 448 452 link_t *link; 449 453 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 } 456 467 } 457 468 … … 463 474 */ 464 475 void initialize_running_driver(driver_t *driver) 465 { 476 { 466 477 fibril_mutex_lock(&driver->driver_mutex); 467 478 … … 480 491 * @param node the device's node in the device tree. 481 492 */ 482 void add_device( driver_t *drv, node_t *node)493 void add_device(int phone, driver_t *drv, node_t *node) 483 494 { 484 495 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 492 505 493 506 return true; 494 507 } 495 508 496 /** 509 /** 497 510 * Find suitable driver for a device and assign the driver to it. 498 511 * … … 523 536 if (DRIVER_RUNNING == drv->state) { 524 537 // 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 } 526 543 } 527 544 … … 542 559 printf(NAME ": init_device_tree.\n"); 543 560 561 atomic_set(&tree->current_handle, 0); 562 544 563 // 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)) { 546 565 return false; 547 566 } -
uspace/srv/devman/devman.h
r67ba309 r084ff99 41 41 #include <ipc/ipc.h> 42 42 #include <fibril_synch.h> 43 #include <atomic.h> 43 44 44 45 #include "util.h" … … 115 116 /** Representation of a node in the device tree.*/ 116 117 struct node { 118 /** The global unique identifier of the device.*/ 119 long handle; 117 120 /** The node of the parent device. */ 118 121 node_t *parent; … … 137 140 /** Root device node. */ 138 141 node_t *root_node; 142 atomic_t current_handle; 139 143 } dev_tree_t; 140 144 … … 191 195 void add_driver(driver_list_t *drivers_list, driver_t *drv); 192 196 void attach_driver(node_t *node, driver_t *drv); 193 void add_device( driver_t *drv, node_t *node);197 void add_device(int phone, driver_t *drv, node_t *node); 194 198 bool start_driver(driver_t *drv); 195 199 … … 230 234 231 235 // Device nodes 232 node_t * create_root_node();233 236 234 237 static inline node_t * create_dev_node() … … 238 241 memset(res, 0, sizeof(node_t)); 239 242 } 243 244 list_initialize(&res->children); 245 list_initialize(&res->match_ids.ids); 246 240 247 return res; 241 248 } 242 249 243 static inline void init_dev_node(node_t *node, node_t *parent) 244 { 245 assert(NULL != node); 250 static 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); 246 255 247 256 node->parent = parent; 248 257 if (NULL != parent) { 258 fibril_mutex_lock(&parent->children_mutex); 249 259 list_append(&node->sibling, &parent->children); 260 fibril_mutex_unlock(&parent->children_mutex); 250 261 } 251 252 list_initialize(&node->children);253 254 list_initialize(&node->match_ids.ids);255 262 } 256 263 … … 259 266 260 267 bool init_device_tree(dev_tree_t *tree, driver_list_t *drivers_list); 268 bool create_root_node(dev_tree_t *tree); 261 269 262 270 -
uspace/srv/drivers/root/root.c
r67ba309 r084ff99 65 65 static bool root_add_device(device_t *dev) 66 66 { 67 printf(NAME ": root_add_device, device handle = %s", dev->handle); 67 68 // TODO add root device and register its children 68 69 return true;
Note:
See TracChangeset
for help on using the changeset viewer.