Changeset 4006447 in mainline
- Timestamp:
- 2010-12-06T20:03:54Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c0bd08d
- Parents:
- b38dfd8 (diff), 463e734 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Files:
-
- 11 added
- 1 deleted
- 15 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
HelenOS.config
rb38dfd8 r4006447 545 545 % Line debugging information 546 546 ! [CONFIG_STRIP_BINARIES!=y] CONFIG_LINE_DEBUG (n/y) 547 548 % Launch (devman) test drivers 549 ! [CONFIG_DEBUG=y] CONFIG_TEST_DRIVERS (y/n) 550 -
boot/Makefile.common
rb38dfd8 r4006447 109 109 110 110 RD_DRVS = \ 111 root 111 root \ 112 rootvirt \ 113 test1 \ 114 test2 112 115 113 116 RD_DRV_CFG = -
boot/arch/amd64/Makefile.inc
rb38dfd8 r4006447 37 37 38 38 RD_DRVS += \ 39 root ia32\39 rootpc \ 40 40 pciintel \ 41 41 isa \ -
uspace/Makefile
rb38dfd8 r4006447 85 85 srv/net/tl/tcp \ 86 86 srv/net/net \ 87 drv/root 87 drv/root \ 88 drv/rootvirt \ 89 drv/test1 \ 90 drv/test2 88 91 89 92 ## Networking … … 108 111 109 112 ifeq ($(UARCH),amd64) 113 DIRS += drv/rootpc 114 DIRS += drv/pciintel 115 DIRS += drv/isa 116 DIRS += drv/ns8250 110 117 endif 111 118 112 119 ifeq ($(UARCH),ia32) 113 DIRS += drv/root ia32120 DIRS += drv/rootpc 114 121 DIRS += drv/pciintel 115 122 DIRS += drv/isa -
uspace/drv/isa/isa.c
rb38dfd8 r4006447 282 282 283 283 printf(NAME ": added io range (addr=0x%x, size=0x%x) to " 284 "device %s\n", addr, len, dev->name); 284 "device %s\n", (unsigned int) addr, (unsigned int) len, 285 dev->name); 285 286 } 286 287 } … … 489 490 static int isa_add_device(device_t *dev) 490 491 { 491 printf(NAME ": isa_add_device, device handle = %d\n", dev->handle); 492 printf(NAME ": isa_add_device, device handle = %d\n", 493 (int) dev->handle); 492 494 493 495 /* Add child devices. */ -
uspace/drv/ns8250/ns8250.c
rb38dfd8 r4006447 274 274 275 275 /* Gain control over port's registers. */ 276 if (pio_enable((void *) data->io_addr, REG_COUNT,276 if (pio_enable((void *)(uintptr_t) data->io_addr, REG_COUNT, 277 277 (void **) &data->port)) { 278 278 printf(NAME ": error - cannot gain the port %#" PRIx32 " for device " … … 727 727 { 728 728 printf(NAME ": ns8250_add_device %s (handle = %d)\n", 729 dev->name, dev->handle);729 dev->name, (int) dev->handle); 730 730 731 731 int res = ns8250_dev_initialize(dev); -
uspace/drv/pciintel/pci.c
rb38dfd8 r4006447 324 324 printf(NAME ": device %s : ", dev->name); 325 325 printf("address = %" PRIx64, range_addr); 326 printf(", size = %x\n", range_size);326 printf(", size = %x\n", (unsigned int) range_size); 327 327 } 328 328 … … 489 489 (uint32_t) hw_resources.resources[0].res.io_range.address; 490 490 491 if (pio_enable((void *) bus_data->conf_io_addr, 8,491 if (pio_enable((void *)(uintptr_t)bus_data->conf_io_addr, 8, 492 492 &bus_data->conf_addr_port)) { 493 493 printf(NAME ": failed to enable configuration ports.\n"); -
uspace/drv/root/root.c
rb38dfd8 r4006447 1 1 /* 2 2 * Copyright (c) 2010 Lenka Trochtova 3 * Copyright (c) 2010 Vojtech Horky 3 4 * All rights reserved. 4 5 * … … 53 54 #define NAME "root" 54 55 56 #define PLATFORM_DEVICE_NAME "hw" 57 #define PLATFORM_DEVICE_MATCH_ID STRING(UARCH) 58 #define PLATFORM_DEVICE_MATCH_SCORE 100 59 60 #define VIRTUAL_DEVICE_NAME "virt" 61 #define VIRTUAL_DEVICE_MATCH_ID "rootvirt" 62 #define VIRTUAL_DEVICE_MATCH_SCORE 100 63 55 64 static int root_add_device(device_t *dev); 56 65 … … 66 75 }; 67 76 77 /** Create the device which represents the root of virtual device tree. 78 * 79 * @param parent Parent of the newly created device. 80 * @return Error code. 81 */ 82 static int add_virtual_root_child(device_t *parent) 83 { 84 printf(NAME ": adding new child for virtual devices.\n"); 85 printf(NAME ": device node is `%s' (%d %s)\n", VIRTUAL_DEVICE_NAME, 86 VIRTUAL_DEVICE_MATCH_SCORE, VIRTUAL_DEVICE_MATCH_ID); 87 88 int res = child_device_register_wrapper(parent, VIRTUAL_DEVICE_NAME, 89 VIRTUAL_DEVICE_MATCH_ID, VIRTUAL_DEVICE_MATCH_SCORE); 90 91 return res; 92 } 93 68 94 /** Create the device which represents the root of HW device tree. 69 95 * … … 74 100 { 75 101 printf(NAME ": adding new child for platform device.\n"); 102 printf(NAME ": device node is `%s' (%d %s)\n", PLATFORM_DEVICE_NAME, 103 PLATFORM_DEVICE_MATCH_SCORE, PLATFORM_DEVICE_MATCH_ID); 76 104 77 int res = EOK; 78 device_t *platform = NULL; 79 match_id_t *match_id = NULL; 80 81 /* Create new device. */ 82 platform = create_device(); 83 if (NULL == platform) { 84 res = ENOMEM; 85 goto failure; 86 } 87 88 platform->name = "hw"; 89 printf(NAME ": the new device's name is %s.\n", platform->name); 90 91 /* Initialize match id list. */ 92 match_id = create_match_id(); 93 if (NULL == match_id) { 94 res = ENOMEM; 95 goto failure; 96 } 97 98 /* TODO - replace this with some better solution (sysinfo ?) */ 99 match_id->id = STRING(UARCH); 100 match_id->score = 100; 101 add_match_id(&platform->match_ids, match_id); 102 103 /* Register child device. */ 104 res = child_device_register(platform, parent); 105 if (EOK != res) 106 goto failure; 107 108 return res; 109 110 failure: 111 if (NULL != match_id) 112 match_id->id = NULL; 113 114 if (NULL != platform) { 115 platform->name = NULL; 116 delete_device(platform); 117 } 118 105 int res = child_device_register_wrapper(parent, PLATFORM_DEVICE_NAME, 106 PLATFORM_DEVICE_MATCH_ID, PLATFORM_DEVICE_MATCH_SCORE); 107 119 108 return res; 120 109 } … … 130 119 dev->handle); 131 120 121 /* 122 * Register virtual devices root. 123 * We ignore error occurrence because virtual devices shall not be 124 * vital for the system. 125 */ 126 add_virtual_root_child(dev); 127 132 128 /* Register root device's children. */ 133 129 int res = add_platform_child(dev); -
uspace/drv/rootpc/Makefile
rb38dfd8 r4006447 30 30 LIBS = $(LIBDRV_PREFIX)/libdrv.a 31 31 EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include 32 BINARY = root ia3232 BINARY = rootpc 33 33 34 34 SOURCES = \ 35 root ia32.c35 rootpc.c 36 36 37 37 include $(USPACE_PREFIX)/Makefile.common -
uspace/drv/rootpc/rootpc.c
rb38dfd8 r4006447 28 28 29 29 /** 30 * @defgroup root_ ia32 Root HW device driver for ia32platform.31 * @brief HelenOS root HW device driver for ia32 platform.30 * @defgroup root_pc Root HW device driver for ia32 and amd64 platform. 31 * @brief HelenOS root HW device driver for ia32 and amd64 platform. 32 32 * @{ 33 33 */ … … 53 53 #include <device/hw_res.h> 54 54 55 #define NAME "root ia32"56 57 typedef struct root ia32_child_dev_data {55 #define NAME "rootpc" 56 57 typedef struct rootpc_child_dev_data { 58 58 hw_resource_list_t hw_resources; 59 } root ia32_child_dev_data_t;60 61 static int root ia32_add_device(device_t *dev);62 static void root_ ia32_init(void);59 } rootpc_child_dev_data_t; 60 61 static int rootpc_add_device(device_t *dev); 62 static void root_pc_init(void); 63 63 64 64 /** The root device driver's standard operations. */ 65 static driver_ops_t root ia32_ops = {66 .add_device = &root ia32_add_device65 static driver_ops_t rootpc_ops = { 66 .add_device = &rootpc_add_device 67 67 }; 68 68 69 69 /** The root device driver structure. */ 70 static driver_t root ia32_driver = {70 static driver_t rootpc_driver = { 71 71 .name = NAME, 72 .driver_ops = &root ia32_ops72 .driver_ops = &rootpc_ops 73 73 }; 74 74 … … 82 82 }; 83 83 84 static root ia32_child_dev_data_t pci_data = {84 static rootpc_child_dev_data_t pci_data = { 85 85 .hw_resources = { 86 86 1, … … 89 89 }; 90 90 91 static hw_resource_list_t *root ia32_get_child_resources(device_t *dev)92 { 93 root ia32_child_dev_data_t *data;94 95 data = (root ia32_child_dev_data_t *) dev->driver_data;91 static hw_resource_list_t *rootpc_get_child_resources(device_t *dev) 92 { 93 rootpc_child_dev_data_t *data; 94 95 data = (rootpc_child_dev_data_t *) dev->driver_data; 96 96 if (NULL == data) 97 97 return NULL; … … 100 100 } 101 101 102 static bool root ia32_enable_child_interrupt(device_t *dev)102 static bool rootpc_enable_child_interrupt(device_t *dev) 103 103 { 104 104 /* TODO */ … … 108 108 109 109 static resource_iface_t child_res_iface = { 110 &root ia32_get_child_resources,111 &root ia32_enable_child_interrupt112 }; 113 114 /* Initialized in root_ ia32_init() function. */115 static device_ops_t root ia32_child_ops;110 &rootpc_get_child_resources, 111 &rootpc_enable_child_interrupt 112 }; 113 114 /* Initialized in root_pc_init() function. */ 115 static device_ops_t rootpc_child_ops; 116 116 117 117 static bool 118 root ia32_add_child(device_t *parent, const char *name, const char *str_match_id,119 root ia32_child_dev_data_t *drv_data)118 rootpc_add_child(device_t *parent, const char *name, const char *str_match_id, 119 rootpc_child_dev_data_t *drv_data) 120 120 { 121 121 printf(NAME ": adding new child device '%s'.\n", name); … … 142 142 143 143 /* Set provided operations to the device. */ 144 child->ops = &root ia32_child_ops;144 child->ops = &rootpc_child_ops; 145 145 146 146 /* Register child device. */ … … 164 164 } 165 165 166 static bool root ia32_add_children(device_t *dev)167 { 168 return root ia32_add_child(dev, "pci0", "intel_pci", &pci_data);166 static bool rootpc_add_children(device_t *dev) 167 { 168 return rootpc_add_child(dev, "pci0", "intel_pci", &pci_data); 169 169 } 170 170 … … 175 175 * @return Zero on success, negative error number otherwise. 176 176 */ 177 static int rootia32_add_device(device_t *dev) 178 { 179 printf(NAME ": rootia32_add_device, device handle = %d\n", dev->handle); 177 static int rootpc_add_device(device_t *dev) 178 { 179 printf(NAME ": rootpc_add_device, device handle = %d\n", 180 (int)dev->handle); 180 181 181 182 /* Register child devices. */ 182 if (!root ia32_add_children(dev)) {183 if (!rootpc_add_children(dev)) { 183 184 printf(NAME ": failed to add child devices for platform " 184 185 "ia32.\n"); … … 188 189 } 189 190 190 static void root_ ia32_init(void)191 { 192 root ia32_child_ops.interfaces[HW_RES_DEV_IFACE] = &child_res_iface;191 static void root_pc_init(void) 192 { 193 rootpc_child_ops.interfaces[HW_RES_DEV_IFACE] = &child_res_iface; 193 194 } 194 195 195 196 int main(int argc, char *argv[]) 196 197 { 197 printf(NAME ": HelenOS root ia32device driver\n");198 root_ ia32_init();199 return driver_main(&root ia32_driver);198 printf(NAME ": HelenOS rootpc device driver\n"); 199 root_pc_init(); 200 return driver_main(&rootpc_driver); 200 201 } 201 202 -
uspace/lib/c/generic/devman.c
rb38dfd8 r4006447 116 116 { 117 117 ipc_call_t answer; 118 a sync_send_1(phone, DEVMAN_ADD_MATCH_ID, match_id->score, &answer);118 aid_t req = async_send_1(phone, DEVMAN_ADD_MATCH_ID, match_id->score, &answer); 119 119 int retval = async_data_write_start(phone, match_id->id, str_size(match_id->id)); 120 return retval; 120 async_wait_for(req, NULL); 121 return retval; 121 122 } 122 123 -
uspace/lib/drv/generic/driver.c
rb38dfd8 r4006447 165 165 166 166 devman_handle_t dev_handle = IPC_GET_ARG1(*icall); 167 devman_handle_t parent_dev_handle = IPC_GET_ARG2(*icall); 168 167 169 device_t *dev = create_device(); 168 170 dev->handle = dev_handle; … … 172 174 173 175 add_to_devices_list(dev); 176 dev->parent = driver_get_device(&devices, parent_dev_handle); 177 174 178 res = driver->driver_ops->add_device(dev); 175 179 if (0 == res) { … … 377 381 } 378 382 383 /** Wrapper for child_device_register for devices with single match id. 384 * 385 * @param parent Parent device. 386 * @param child_name Child device name. 387 * @param child_match_id Child device match id. 388 * @param child_match_score Child device match score. 389 * @return Error code. 390 */ 391 int child_device_register_wrapper(device_t *parent, const char *child_name, 392 const char *child_match_id, int child_match_score) 393 { 394 device_t *child = NULL; 395 match_id_t *match_id = NULL; 396 int rc; 397 398 child = create_device(); 399 if (child == NULL) { 400 rc = ENOMEM; 401 goto failure; 402 } 403 404 child->name = child_name; 405 406 match_id = create_match_id(); 407 if (match_id == NULL) { 408 rc = ENOMEM; 409 goto failure; 410 } 411 412 match_id->id = child_match_id; 413 match_id->score = child_match_score; 414 add_match_id(&child->match_ids, match_id); 415 416 rc = child_device_register(child, parent); 417 if (EOK != rc) 418 goto failure; 419 420 return EOK; 421 422 failure: 423 if (match_id != NULL) { 424 match_id->id = NULL; 425 delete_match_id(match_id); 426 } 427 428 if (child != NULL) { 429 child->name = NULL; 430 delete_device(child); 431 } 432 433 return rc; 434 } 435 379 436 int driver_main(driver_t *drv) 380 437 { -
uspace/lib/drv/include/driver.h
rb38dfd8 r4006447 199 199 200 200 int child_device_register(device_t *, device_t *); 201 int child_device_register_wrapper(device_t *, const char *, const char *, int); 201 202 202 203 -
uspace/srv/devman/devman.c
rb38dfd8 r4006447 508 508 /** Notify driver about the devices to which it was assigned. 509 509 * 510 * The driver's mutex must be locked.511 *512 510 * @param driver The driver to which the devices are passed. 513 511 */ … … 518 516 int phone; 519 517 520 printf(NAME ": pass_devices_to_driver\n"); 521 522 phone = ipc_connect_me_to(driver->phone, DRIVER_DEVMAN, 0, 0); 523 if (phone > 0) { 524 518 printf(NAME ": pass_devices_to_driver(`%s')\n", driver->name); 519 520 fibril_mutex_lock(&driver->driver_mutex); 521 522 phone = async_connect_me_to(driver->phone, DRIVER_DEVMAN, 0, 0); 523 524 if (phone < 0) { 525 fibril_mutex_unlock(&driver->driver_mutex); 526 return; 527 } 528 529 /* 530 * Go through devices list as long as there is some device 531 * that has not been passed to the driver. 532 */ 533 link = driver->devices.next; 534 while (link != &driver->devices) { 535 dev = list_get_instance(link, node_t, driver_devices); 536 if (dev->passed_to_driver) { 537 link = link->next; 538 continue; 539 } 540 541 /* 542 * We remove the device from the list to allow safe adding 543 * of new devices (no one will touch our item this way). 544 */ 545 list_remove(link); 546 547 /* 548 * Unlock to avoid deadlock when adding device 549 * handled by itself. 550 */ 551 fibril_mutex_unlock(&driver->driver_mutex); 552 553 add_device(phone, driver, dev, tree); 554 555 /* 556 * Lock again as we will work with driver's 557 * structure. 558 */ 559 fibril_mutex_lock(&driver->driver_mutex); 560 561 /* 562 * Insert the device back. 563 * The order is not relevant here so no harm is done 564 * (actually, the order would be preserved in most cases). 565 */ 566 list_append(link, &driver->devices); 567 568 /* 569 * Restart the cycle to go through all devices again. 570 */ 525 571 link = driver->devices.next; 526 while (link != &driver->devices) { 527 dev = list_get_instance(link, node_t, driver_devices); 528 add_device(phone, driver, dev, tree); 529 link = link->next; 530 } 531 532 ipc_hangup(phone); 533 } 572 } 573 574 ipc_hangup(phone); 575 576 /* 577 * Once we passed all devices to the driver, we need to mark the 578 * driver as running. 579 * It is vital to do it here and inside critical section. 580 * 581 * If we would change the state earlier, other devices added to 582 * the driver would be added to the device list and started 583 * immediately and possibly started here as well. 584 */ 585 printf(NAME ": driver %s goes into running state.\n", driver->name); 586 driver->state = DRIVER_RUNNING; 587 588 fibril_mutex_unlock(&driver->driver_mutex); 534 589 } 535 590 … … 545 600 void initialize_running_driver(driver_t *driver, dev_tree_t *tree) 546 601 { 547 printf(NAME ": initialize_running_driver\n"); 548 fibril_mutex_lock(&driver->driver_mutex); 602 printf(NAME ": initialize_running_driver (`%s')\n", driver->name); 549 603 550 604 /* … … 553 607 */ 554 608 pass_devices_to_driver(driver, tree); 555 556 /* Change driver's state to running. */557 driver->state = DRIVER_RUNNING;558 559 fibril_mutex_unlock(&driver->driver_mutex);560 609 } 561 610 … … 629 678 } 630 679 680 static FIBRIL_MUTEX_INITIALIZE(add_device_guard); 631 681 632 682 /** Pass a device to running driver. … … 637 687 void add_device(int phone, driver_t *drv, node_t *node, dev_tree_t *tree) 638 688 { 639 printf(NAME ": add_device\n"); 689 fibril_mutex_lock(&add_device_guard); 690 691 /* 692 * We do not expect to have driver's mutex locked as we do not 693 * access any structures that would affect driver_t. 694 */ 695 printf(NAME ": add_device (driver `%s', device `%s')\n", drv->name, 696 node->name); 640 697 641 698 ipcarg_t rc; … … 643 700 644 701 /* Send the device to the driver. */ 645 aid_t req = async_send_1(phone, DRIVER_ADD_DEVICE, node->handle, 646 &answer); 702 devman_handle_t parent_handle; 703 if (node->parent) { 704 parent_handle = node->parent->handle; 705 } else { 706 parent_handle = 0; 707 } 708 709 aid_t req = async_send_2(phone, DRIVER_ADD_DEVICE, node->handle, 710 parent_handle, &answer); 647 711 648 712 /* Send the device's name to the driver. */ … … 652 716 /* TODO handle error */ 653 717 } 654 718 655 719 /* Wait for answer from the driver. */ 656 720 async_wait_for(req, &rc); 721 722 fibril_mutex_unlock(&add_device_guard); 723 657 724 switch(rc) { 658 725 case EOK: … … 667 734 } 668 735 736 node->passed_to_driver = true; 737 669 738 return; 670 739 } … … 692 761 attach_driver(node, drv); 693 762 763 fibril_mutex_lock(&drv->driver_mutex); 694 764 if (drv->state == DRIVER_NOT_STARTED) { 695 765 /* Start the driver. */ 696 766 start_driver(drv); 697 767 } 698 699 if (drv->state == DRIVER_RUNNING) { 768 bool is_running = drv->state == DRIVER_RUNNING; 769 fibril_mutex_unlock(&drv->driver_mutex); 770 771 if (is_running) { 700 772 /* Notify the driver about the new device. */ 701 int phone = ipc_connect_me_to(drv->phone, DRIVER_DEVMAN, 0, 0);773 int phone = async_connect_me_to(drv->phone, DRIVER_DEVMAN, 0, 0); 702 774 if (phone > 0) { 703 775 add_device(phone, drv, node, tree); … … 861 933 node->name = dev_name; 862 934 if (!set_dev_path(node, parent)) { 863 fibril_rwlock_write_unlock(&tree->rwlock);864 935 return false; 865 936 } … … 1083 1154 while (link != &class_list->classes) { 1084 1155 cl = list_get_instance(link, dev_class_t, link); 1085 if (str_cmp(cl->name, class_name) == 0) 1156 if (str_cmp(cl->name, class_name) == 0) { 1086 1157 return cl; 1158 } 1159 link = link->next; 1087 1160 } 1088 1161 -
uspace/srv/devman/devman.h
rb38dfd8 r4006447 168 168 */ 169 169 link_t devmap_link; 170 171 /** 172 * Whether this device was already passed to the driver. 173 */ 174 bool passed_to_driver; 170 175 }; 171 176 -
uspace/srv/devman/main.c
rb38dfd8 r4006447 197 197 } 198 198 199 static int assign_driver_fibril(void *arg) 200 { 201 node_t *node = (node_t *) arg; 202 assign_driver(node, &drivers_list, &device_tree); 203 return EOK; 204 } 205 199 206 /** Handle child device registration. 200 207 * … … 237 244 238 245 devman_receive_match_ids(match_count, &node->match_ids); 239 246 247 /* 248 * Try to find a suitable driver and assign it to the device. We do 249 * not want to block the current fibril that is used for processing 250 * incoming calls: we will launch a separate fibril to handle the 251 * driver assigning. That is because assign_driver can actually include 252 * task spawning which could take some time. 253 */ 254 fid_t assign_fibril = fibril_create(assign_driver_fibril, node); 255 if (assign_fibril == 0) { 256 /* 257 * Fallback in case we are out of memory. 258 * Probably not needed as we will die soon anyway ;-). 259 */ 260 (void) assign_driver_fibril(node); 261 } else { 262 fibril_add_ready(assign_fibril); 263 } 264 240 265 /* Return device handle to parent's driver. */ 241 266 ipc_answer_1(callid, EOK, node->handle); 242 243 /* Try to find suitable driver and assign it to the device. */244 assign_driver(node, &drivers_list, &device_tree);245 267 } 246 268 … … 297 319 printf(NAME ": device '%s' added to class '%s', class name '%s' was " 298 320 "asigned to it\n", dev->pathname, class_name, class_info->dev_name); 299 321 300 322 ipc_answer_0(callid, EOK); 301 323 } -
uspace/srv/devman/match.c
rb38dfd8 r4006447 35 35 #include "devman.h" 36 36 37 /** Compute compound score of driver and device. 38 * 39 * @param driver Match id of the driver. 40 * @param device Match id of the device. 41 * @return Compound score. 42 * @retval 0 No match at all. 43 */ 44 static int compute_match_score(match_id_t *driver, match_id_t *device) 45 { 46 if (str_cmp(driver->id, device->id) == 0) { 47 /* 48 * The strings match, return the product of their scores. 49 */ 50 return driver->score * device->score; 51 } else { 52 /* 53 * Different strings, return zero. 54 */ 55 return 0; 56 } 57 } 58 37 59 int get_match_score(driver_t *drv, node_t *dev) 38 60 { … … 43 65 return 0; 44 66 67 /* 68 * Go through all pairs, return the highest score obtained. 69 */ 70 int highest_score = 0; 71 45 72 link_t *drv_link = drv->match_ids.ids.next; 46 link_t *dev_link = dev->match_ids.ids.next; 47 48 match_id_t *drv_id = list_get_instance(drv_link, match_id_t, link); 49 match_id_t *dev_id = list_get_instance(dev_link, match_id_t, link); 50 51 int score_next_drv = 0; 52 int score_next_dev = 0; 53 54 do { 55 match_id_t *tmp_ma_id; 56 57 if (str_cmp(drv_id->id, dev_id->id) == 0) { 58 /* 59 * We found a match. 60 * Return the score of the match. 61 */ 62 return drv_id->score * dev_id->score; 73 while (drv_link != drv_head) { 74 link_t *dev_link = dev_head->next; 75 while (dev_link != dev_head) { 76 match_id_t *drv_id = list_get_instance(drv_link, match_id_t, link); 77 match_id_t *dev_id = list_get_instance(dev_link, match_id_t, link); 78 79 int score = compute_match_score(drv_id, dev_id); 80 if (score > highest_score) { 81 highest_score = score; 82 } 83 84 dev_link = dev_link->next; 63 85 } 64 86 65 /* 66 * Compute the next score we get, if we advance in the driver's 67 * list of match ids. 68 */ 69 if (drv_link->next != drv_head) { 70 tmp_ma_id = list_get_instance(drv_link->next, 71 match_id_t, link); 72 score_next_drv = dev_id->score * tmp_ma_id->score; 73 } else { 74 score_next_drv = 0; 75 } 76 77 /* 78 * Compute the next score we get, if we advance in the device's 79 * list of match ids. 80 */ 81 if (dev_link->next != dev_head) { 82 tmp_ma_id = list_get_instance(dev_link->next, 83 match_id_t, link); 84 score_next_dev = drv_id->score * tmp_ma_id->score; 85 } else { 86 score_next_dev = 0; 87 } 88 89 /* 90 * Advance in one of the two lists, so we get the next highest 91 * score. 92 */ 93 if (score_next_drv > score_next_dev) { 94 drv_link = drv_link->next; 95 drv_id = list_get_instance(drv_link, match_id_t, link); 96 } else { 97 dev_link = dev_link->next; 98 dev_id = list_get_instance(dev_link, match_id_t, link); 99 } 100 101 } while (drv_link->next != drv_head && dev_link->next != dev_head); 87 drv_link = drv_link->next; 88 } 102 89 103 return 0;90 return highest_score; 104 91 } 105 92
Note:
See TracChangeset
for help on using the changeset viewer.