Changeset 0c3666d in mainline
- Timestamp:
- 2010-02-19T14:51:15Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 924c75e1
- Parents:
- e85920d
- Location:
- uspace/srv/devman
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/devman.c
re85920d r0c3666d 38 38 #include "util.h" 39 39 40 40 /** Allocate and initialize a new driver structure. 41 * 42 * @return driver structure. 43 */ 41 44 driver_t * create_driver() 42 45 { … … 50 53 } 51 54 52 char * read_id(const char **buf) 55 /** Add a driver to the list of drivers. 56 * 57 * @param drivers_list the list of drivers. 58 * @param drv the driver's structure. 59 */ 60 void add_driver(driver_list_t *drivers_list, driver_t *drv) 61 { 62 fibril_mutex_lock(&drivers_list->drivers_mutex); 63 list_prepend(&drv->drivers, &drivers_list->drivers); 64 fibril_mutex_unlock(&drivers_list->drivers_mutex); 65 66 printf(NAME": the '%s' driver was added to the list of available drivers.\n", drv->name); 67 } 68 69 /** Read match id at the specified position of a string and set 70 * the position in the string to the first character following the id. 71 * 72 * @param buf the position in the input string. 73 * 74 * @return the match id. 75 */ 76 char * read_match_id(const char **buf) 53 77 { 54 78 char *res = NULL; … … 64 88 } 65 89 90 /** 91 * Read match ids and associated match scores from a string. 92 * 93 * Each match score in the string is followed by its match id. 94 * The match ids and match scores are separated by whitespaces. 95 * Neither match ids nor match scores can contain whitespaces. 96 * 97 * @param buf the string from which the match ids are read. 98 * @param ids the list of match ids into which the match ids and scores are added. 99 * 100 * @return true if at least one match id and associated match score was successfully read, false otherwise. 101 */ 66 102 bool parse_match_ids(const char *buf, match_id_list_t *ids) 67 103 { … … 84 120 85 121 // read id 86 if (NULL == (id = read_ id(&buf))) {122 if (NULL == (id = read_match_id(&buf))) { 87 123 break; 88 124 } … … 102 138 } 103 139 140 /** 141 * Read match ids and associated match scores from a file. 142 * 143 * Each match score in the file is followed by its match id. 144 * The match ids and match scores are separated by whitespaces. 145 * Neither match ids nor match scores can contain whitespaces. 146 * 147 * @param buf the path to the file from which the match ids are read. 148 * @param ids the list of match ids into which the match ids and scores are added. 149 * 150 * @return true if at least one match id and associated match score was successfully read, false otherwise. 151 */ 104 152 bool read_match_ids(const char *conf_path, match_id_list_t *ids) 105 153 { … … 151 199 } 152 200 153 201 /** 202 * Get information about a driver. 203 * 204 * Each driver has its own directory in the base directory. 205 * The name of the driver's directory is the same as the name of the driver. 206 * The driver's directory contains driver's binary (named as the driver without extension) 207 * and the configuration file with match ids for device-to-driver matching 208 * (named as the driver with a special extension). 209 * 210 * This function searches for the driver's directory and containing configuration files. 211 * If all the files needed are found, they are parsed and 212 * the information about the driver is stored to the driver's structure. 213 * 214 * @param base_path the base directory, in which we look for driver's subdirectory. 215 * @param name the name of the driver. 216 * @param drv the driver structure to fill information in. 217 * 218 * @return true on success, false otherwise. 219 */ 154 220 bool get_driver_info(const char *base_path, const char *name, driver_t *drv) 155 221 { … … 213 279 * @param drivers_list the list of available drivers. 214 280 * @param dir_path the path to the directory where we search for drivers. 281 * 282 * @return number of drivers which were found. 215 283 */ 216 int lookup_available_drivers( link_t *drivers_list, const char *dir_path)284 int lookup_available_drivers(driver_list_t *drivers_list, const char *dir_path) 217 285 { 218 286 printf(NAME ": lookup_available_drivers \n"); … … 242 310 } 243 311 312 /** Create root device node of the device tree. 313 * 314 * @return root device node. 315 */ 244 316 node_t * create_root_node() 245 317 { … … 256 328 } 257 329 258 driver_t * find_best_match_driver(link_t *drivers_list, node_t *node) 330 /** Lookup the best matching driver for the specified device in the list of drivers. 331 * 332 * A match between a device and a driver is found 333 * if one of the driver's match ids match one of the device's match ids. 334 * The score of the match is the product of the driver's and device's score associated with the matching id. 335 * The best matching driver for a device is the driver 336 * with the highest score of the match between the device and the driver. 337 * 338 * @param drivers_list the list of drivers, where we look for the driver suitable for handling the device. 339 * @param node the device node structure of the device. 340 * 341 * @return the best matching driver or NULL if no matching driver is found. 342 */ 343 driver_t * find_best_match_driver(driver_list_t *drivers_list, node_t *node) 259 344 { 260 345 printf(NAME ": find_best_match_driver\n"); 261 346 driver_t *best_drv = NULL, *drv = NULL; 262 347 int best_score = 0, score = 0; 263 link_t *link = drivers_list->next; 264 265 while (link != drivers_list) { 348 349 fibril_mutex_lock(&drivers_list->drivers_mutex); 350 link_t *link = drivers_list->drivers.next; 351 while (link != &drivers_list->drivers) { 266 352 drv = list_get_instance(link, driver_t, drivers); 267 353 score = get_match_score(drv, node); … … 271 357 } 272 358 link = link->next; 273 } 359 } 360 fibril_mutex_unlock(&drivers_list->drivers_mutex); 274 361 275 362 return best_drv; 276 363 } 277 364 365 /** 366 * Assign a driver to a device. 367 * 368 * @param node the device's node in the device tree. 369 * @param drv the driver. 370 */ 278 371 void attach_driver(node_t *node, driver_t *drv) 279 372 { 373 fibril_mutex_lock(&drv->driver_mutex); 374 280 375 node->drv = drv; 281 376 list_append(&node->driver_devices, &drv->devices); 282 } 283 377 378 fibril_mutex_unlock(&drv->driver_mutex); 379 } 380 381 /** Start a driver. 382 * 383 * The driver's mutex is assumed to be locked. 384 * 385 * @param drv the driver's structure. 386 * @return true if the driver's task is successfully spawned, false otherwise. 387 */ 284 388 bool start_driver(driver_t *drv) 285 389 { … … 302 406 } 303 407 408 /** Pass a device to running driver. 409 * 410 * @param drv the driver's structure. 411 * @param node the device's node in the device tree. 412 * 413 * @return true on success, false otherwise. 414 */ 304 415 bool add_device(driver_t *drv, node_t *node) 305 416 { … … 316 427 } 317 428 318 bool assign_driver(node_t *node, link_t *drivers_list) 429 /** 430 * Find suitable driver for a device and assign the driver to it. 431 * 432 * @param node the device node of the device in the device tree. 433 * @param drivers_list the list of available drivers. 434 * 435 * @return true if the suitable driver is found and successfully assigned to the device, false otherwise. 436 */ 437 bool assign_driver(node_t *node, driver_list_t *drivers_list) 319 438 { 320 439 printf(NAME ": assign_driver\n"); … … 343 462 } 344 463 345 bool init_device_tree(dev_tree_t *tree, link_t *drivers_list) 464 /** 465 * Initialize the device tree. 466 * 467 * Create root device node of the tree and assign driver to it. 468 * 469 * @param tree the device tree. 470 * @param the list of available drivers. 471 * @return true on success, false otherwise. 472 */ 473 bool init_device_tree(dev_tree_t *tree, driver_list_t *drivers_list) 346 474 { 347 475 printf(NAME ": init_device_tree.\n"); 476 348 477 // create root node and add it to the device tree 349 478 if (NULL == (tree->root_node = create_root_node())) { -
uspace/srv/devman/devman.h
re85920d r0c3666d 168 168 } 169 169 170 // Driver list 171 172 static inline void init_driver_list(driver_list_t *drv_list) 173 { 174 assert(NULL != drv_list); 175 176 list_initialize(&drv_list->drivers); 177 fibril_mutex_initialize(&drv_list->drivers_mutex); 178 } 179 170 180 // Drivers 171 181 172 182 driver_t * create_driver(); 173 183 bool get_driver_info(const char *base_path, const char *name, driver_t *drv); 174 int lookup_available_drivers(link_t *drivers_list, const char *dir_path); 175 176 driver_t * find_best_match_driver(link_t *drivers_list, node_t *node); 177 bool assign_driver(node_t *node, link_t *drivers_list); 178 184 int lookup_available_drivers(driver_list_t *drivers_list, const char *dir_path); 185 186 driver_t * find_best_match_driver(driver_list_t *drivers_list, node_t *node); 187 bool assign_driver(node_t *node, driver_list_t *drivers_list); 188 189 void add_driver(driver_list_t *drivers_list, driver_t *drv); 179 190 void attach_driver(node_t *node, driver_t *drv); 180 191 bool add_device(driver_t *drv, node_t *node); … … 214 225 } 215 226 216 static inline void add_driver(link_t *drivers_list, driver_t *drv)217 {218 list_prepend(&drv->drivers, drivers_list);219 printf(NAME": the '%s' driver was added to the list of available drivers.\n", drv->name);220 }221 222 223 227 // Device nodes 224 228 node_t * create_root_node(); … … 250 254 // Device tree 251 255 252 bool init_device_tree(dev_tree_t *tree, link_t *drivers_list);256 bool init_device_tree(dev_tree_t *tree, driver_list_t *drivers_list); 253 257 254 258 -
uspace/srv/devman/main.c
re85920d r0c3666d 56 56 #define DRIVER_DEFAULT_STORE "/srv/drivers" 57 57 58 LIST_INITIALIZE(drivers_list);58 static driver_list_t drivers_list; 59 59 static dev_tree_t device_tree; 60 60 … … 92 92 static bool devman_init() 93 93 { 94 printf(NAME ": devman_init - looking for available drivers. \n"); 94 printf(NAME ": devman_init - looking for available drivers. \n"); 95 95 96 96 // initialize list of available drivers 97 init_driver_list(&drivers_list); 97 98 if (0 == lookup_available_drivers(&drivers_list, DRIVER_DEFAULT_STORE)) { 98 99 printf(NAME " no drivers found."); … … 110 111 } 111 112 112 /**113 *114 */115 113 int main(int argc, char *argv[]) 116 114 {
Note:
See TracChangeset
for help on using the changeset viewer.