Changeset 25453
- Timestamp:
- 05/11/08 12:00:07 (5 days ago)
- Files:
-
- haiku/trunk/src/tests/system/kernel/device_manager/playground/bus.cpp (modified) (1 diff)
- haiku/trunk/src/tests/system/kernel/device_manager/playground/device_manager.cpp (modified) (25 diffs)
- haiku/trunk/src/tests/system/kernel/device_manager/playground/device_manager.h (modified) (1 diff)
- haiku/trunk/src/tests/system/kernel/device_manager/playground/driver.cpp (modified) (1 diff)
- haiku/trunk/src/tests/system/kernel/device_manager/playground/generic_video_driver.cpp (added)
- haiku/trunk/src/tests/system/kernel/device_manager/playground/Jamfile (modified) (1 diff)
- haiku/trunk/src/tests/system/kernel/device_manager/playground/specific_video_driver.cpp (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
haiku/trunk/src/tests/system/kernel/device_manager/playground/bus.cpp
r25394 r25453 72 72 {0x1000, 0x0001, PCI_mass_storage, PCI_sata, PCI_sata_ahci}, 73 73 {0x1001, 0x0001, PCI_network, PCI_ethernet, 0}, 74 {0x1001, 0x0002, PCI_display, 0, 0}, 74 75 {0x1002, 0x0001, PCI_multimedia, PCI_audio, 0}, 75 76 {0x1002, 0x0002, PCI_serial_bus, PCI_usb, PCI_usb_ehci}, haiku/trunk/src/tests/system/kernel/device_manager/playground/device_manager.cpp
r25406 r25453 30 30 extern struct device_module_info gDeviceModuleInfo; 31 31 extern struct driver_module_info gDriverModuleInfo; 32 extern struct device_module_info gGenericVideoDeviceModuleInfo; 33 extern struct driver_module_info gGenericVideoDriverModuleInfo; 34 extern struct device_module_info gSpecificVideoDeviceModuleInfo; 35 extern struct driver_module_info gSpecificVideoDriverModuleInfo; 32 36 extern struct driver_module_info gBusModuleInfo; 33 37 extern struct driver_module_info gBusDriverModuleInfo; … … 113 117 bool IsRegistered() const { return fRegistered; } 114 118 bool IsInitialized() const { return fInitialized > 0; } 119 120 void Acquire(); 121 bool Release(); 122 123 int CompareTo(const device_attr* attributes) const; 124 device_node* FindChild(const device_attr* attributes) const; 125 126 void Dump(int32 level = 0); 115 127 116 128 private: … … 362 374 363 375 364 void365 dm_dump_node(device_node* node, int32 level)366 {367 if (node == NULL)368 return;369 370 put_level(level);371 dprintf("(%ld) @%p \"%s\"\n", level, node, node->ModuleName());372 373 AttributeList::Iterator attribute = node->Attributes().GetIterator();374 while (attribute.HasNext()) {375 dump_attribute(attribute.Next(), level);376 }377 378 NodeList::ConstIterator iterator = node->Children().GetIterator();379 while (iterator.HasNext()) {380 dm_dump_node(iterator.Next(), level + 1);381 }382 }383 384 385 376 static void 386 377 uninit_unused() … … 435 426 device_node::~device_node() 436 427 { 428 TRACE(("delete node %p\n", this)); 429 437 430 // Delete children 438 431 NodeList::Iterator nodeIterator = fChildren.GetIterator(); … … 465 458 device_node::InitDriver() 466 459 { 467 if (fInitialized++ > 0) 460 if (fInitialized++ > 0) { 461 if (Parent() != NULL) { 462 Parent()->InitDriver(); 463 // acquire another reference to our parent as well 464 } 465 Acquire(); 468 466 return B_OK; 467 } 469 468 470 469 status_t status = get_module(ModuleName(), (module_info**)&fDriver); 470 if (status == B_OK && Parent() != NULL) { 471 // our parent always have to be initialized 472 status = Parent()->InitDriver(); 473 } 471 474 if (status < B_OK) { 472 475 fInitialized--; … … 476 479 if (fDriver->init_driver != NULL) 477 480 status = fDriver->init_driver(this, &fDriverData); 481 478 482 if (status < B_OK) { 479 483 fInitialized--; 484 480 485 put_module(ModuleName()); 486 fDriver = NULL; 487 fDriverData = NULL; 481 488 return status; 482 489 } 483 490 491 Acquire(); 484 492 return B_OK; 485 493 } … … 489 497 device_node::UninitDriver() 490 498 { 491 if (fInitialized-- > 1) 499 if (fInitialized-- > 1) { 500 Release(); 492 501 return false; 502 } 503 TRACE(("uninit driver for node %p\n", this)); 493 504 494 505 if (fDriver->uninit_driver != NULL) … … 500 511 put_module(ModuleName()); 501 512 513 Release(); 514 if (Parent() != NULL) 515 Parent()->UninitDriver(); 516 502 517 if ((fFlags & NODE_FLAG_REMOVE_ON_UNINIT) != 0) 503 delete this;518 Release(); 504 519 505 520 return true; … … 511 526 { 512 527 // we must not be destroyed as long as we have children 513 fRefCount++;528 Acquire(); 514 529 node->fParent = this; 515 530 fChildren.Add(node); … … 520 535 device_node::RemoveChild(device_node* node) 521 536 { 522 fRefCount--;523 // TODO: we may need to destruct ourselves here!524 537 node->fParent = NULL; 525 538 fChildren.Remove(node); 539 Release(); 526 540 } 527 541 … … 785 799 float support = driver->supports_device(this); 786 800 if (support > 0.0) { 787 printf(" register module \"%s\", support %f\n", driver->info.name, support); 801 TRACE((" register module \"%s\", support %f\n", driver->info.name, 802 support)); 788 803 if (driver->register_device(this) == B_OK) 789 804 count++; … … 836 851 837 852 if (bestDriver != NULL) { 838 printf(" register best module \"%s\", support %f\n", bestDriver->info.name, bestSupport); 853 TRACE((" register best module \"%s\", support %f\n", 854 bestDriver->info.name, bestSupport)); 839 855 bestDriver->register_device(this); 840 856 put_module(bestDriver->info.name); … … 862 878 // this child is not used currently, and can be removed safely 863 879 iterator.Remove(); 864 fRefCount--;865 880 child->fParent = NULL; 866 881 delete child; 882 if (Release()) 883 panic("died early"); 867 884 } else 868 885 child->fFlags |= NODE_FLAG_REMOVE_ON_UNINIT; … … 876 893 device_node::Probe(const char* devicePath) 877 894 { 895 status_t status = InitDriver(); 896 if (status < B_OK) 897 return status; 898 899 MethodDeleter<device_node, bool> uninit(this, &device_node::UninitDriver); 900 878 901 uint16 type = 0; 879 902 uint16 subType = 0; … … 918 941 device_node* child = iterator.Next(); 919 942 920 status _t status= child->Probe(devicePath);943 status = child->Probe(devicePath); 921 944 if (status != B_OK) 922 945 return status; … … 963 986 { 964 987 _UninitUnusedChildren(); 988 } 989 990 991 void 992 device_node::Acquire() 993 { 994 atomic_add(&fRefCount, 1); 995 } 996 997 998 bool 999 device_node::Release() 1000 { 1001 if (atomic_add(&fRefCount, -1) > 1) 1002 return false; 1003 1004 if (Parent() != NULL) 1005 Parent()->RemoveChild(this); 1006 delete this; 1007 return true; 1008 } 1009 1010 1011 int 1012 device_node::CompareTo(const device_attr* attributes) const 1013 { 1014 if (attributes == NULL) 1015 return -1; 1016 1017 for (; attributes->name != NULL; attributes++) { 1018 // find corresponding attribute 1019 AttributeList::ConstIterator iterator = Attributes().GetIterator(); 1020 device_attr_private* attr = NULL; 1021 while (iterator.HasNext()) { 1022 attr = iterator.Next(); 1023 1024 if (!strcmp(attr->name, attributes->name)) 1025 break; 1026 } 1027 if (!iterator.HasNext()) 1028 return -1; 1029 1030 int compare = device_attr_private::Compare(attr, attributes); 1031 if (compare != 0) 1032 return compare; 1033 } 1034 1035 return 0; 1036 } 1037 1038 1039 device_node* 1040 device_node::FindChild(const device_attr* attributes) const 1041 { 1042 if (attributes == NULL) 1043 return NULL; 1044 1045 NodeList::ConstIterator iterator = Children().GetIterator(); 1046 while (iterator.HasNext()) { 1047 device_node* child = iterator.Next(); 1048 1049 if (!child->CompareTo(attributes)) 1050 return child; 1051 } 1052 1053 return NULL; 1054 } 1055 1056 1057 void 1058 device_node::Dump(int32 level = 0) 1059 { 1060 put_level(level); 1061 dprintf("(%ld) @%p \"%s\" (ref %ld, init %ld)\n", level, this, ModuleName(), 1062 fRefCount, fInitialized); 1063 1064 AttributeList::Iterator attribute = Attributes().GetIterator(); 1065 while (attribute.HasNext()) { 1066 dump_attribute(attribute.Next(), level); 1067 } 1068 1069 NodeList::ConstIterator iterator = Children().GetIterator(); 1070 while (iterator.HasNext()) { 1071 iterator.Next()->Dump(level + 1); 1072 } 965 1073 } 966 1074 … … 984 1092 return B_BAD_VALUE; 985 1093 1094 if (parent != NULL && parent->FindChild(attrs) != NULL) { 1095 // A node like this one already exists for this parent 1096 return B_NAME_IN_USE; 1097 } 1098 986 1099 // TODO: handle I/O resources! 987 1100 … … 997 1110 998 1111 status_t status = newNode->InitCheck(); 999 if (status != B_OK)1000 goto err1;1001 1002 status = newNode->InitDriver();1003 1112 if (status != B_OK) 1004 1113 goto err1; … … 1009 1118 else 1010 1119 sRootNode = newNode; 1120 1121 status = newNode->InitDriver(); 1122 if (status != B_OK) 1123 goto err1; 1011 1124 1012 1125 #if 0 … … 1064 1177 1065 1178 static device_node* 1066 device_root(void) 1067 { 1179 get_device_root(void) 1180 { 1181 if (sRootNode != NULL) 1182 sRootNode->Acquire(); 1183 1068 1184 return sRootNode; 1069 1185 } … … 1081 1197 get_parent(device_node* node) 1082 1198 { 1083 return NULL; 1199 if (node == NULL) 1200 return NULL; 1201 1202 RecursiveLocker _(sLock); 1203 1204 device_node* parent = node->Parent(); 1205 parent->Acquire(); 1206 1207 return parent; 1084 1208 } 1085 1209 … … 1088 1212 put_device_node(device_node* node) 1089 1213 { 1214 RecursiveLocker _(sLock); 1215 node->Release(); 1090 1216 } 1091 1217 … … 1230 1356 unregister_device, 1231 1357 get_driver, 1232 device_root,1358 get_device_root, 1233 1359 get_next_child_device, 1234 1360 get_parent, … … 1285 1411 _add_builtin_module((module_info*)&sDeviceManagerModule); 1286 1412 _add_builtin_module((module_info*)&sDeviceRootModule); 1287 _add_builtin_module((module_info*)&gDeviceModuleInfo); 1288 _add_builtin_module((module_info*)&gDriverModuleInfo);1413 1414 // bus 1289 1415 _add_builtin_module((module_info*)&gBusModuleInfo); 1290 1416 _add_builtin_module((module_info*)&gBusDriverModuleInfo); 1417 1418 // sample driver 1419 _add_builtin_module((module_info*)&gDriverModuleInfo); 1420 _add_builtin_module((module_info*)&gDeviceModuleInfo); 1421 1422 // generic video driver 1423 _add_builtin_module((module_info*)&gGenericVideoDriverModuleInfo); 1424 _add_builtin_module((module_info*)&gGenericVideoDeviceModuleInfo); 1291 1425 1292 1426 gDeviceManager = &sDeviceManagerModule; … … 1302 1436 1303 1437 dm_init_root_node(); 1304 dm_dump_node(sRootNode, 0);1438 sRootNode->Dump(); 1305 1439 1306 1440 probe_path("net"); 1441 probe_path("graphics"); 1442 // TODO: opened devices need to keep a "initialized" reference of the 1443 // device_node 1444 1445 sRootNode->Dump(); 1446 uninit_unused(); 1447 1448 // add specific video driver - ie. simulate installing it 1449 _add_builtin_module((module_info*)&gSpecificVideoDriverModuleInfo); 1450 _add_builtin_module((module_info*)&gSpecificVideoDeviceModuleInfo); 1451 probe_path("graphics"); 1452 1307 1453 uninit_unused(); 1308 1454 haiku/trunk/src/tests/system/kernel/device_manager/playground/device_manager.h
r25406 r25453 73 73 void **_cookie); 74 74 75 device_node *(* root_device)();75 device_node *(*get_root_device)(); 76 76 status_t (*get_next_child_device)(device_node *parent, device_node *node, 77 77 const device_attr *attrs); haiku/trunk/src/tests/system/kernel/device_manager/playground/driver.cpp
r25394 r25453 160 160 NULL, 161 161 }, 162 162 163 163 supports_device, 164 164 register_device, haiku/trunk/src/tests/system/kernel/device_manager/playground/Jamfile
r25383 r25453 13 13 bus.cpp 14 14 driver.cpp 15 generic_video_driver.cpp 16 specific_video_driver.cpp 15 17 16 18 : be libkernelland_emu.so
