Changeset 25394
- Timestamp:
- 05/09/08 08:56:29 (7 months ago)
- Location:
- haiku/trunk/src/tests/system/kernel/device_manager/playground
- Files:
-
- 4 modified
-
bus.cpp (modified) (7 diffs)
-
device_manager.cpp (modified) (17 diffs)
-
device_manager.h (modified) (3 diffs)
-
driver.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
haiku/trunk/src/tests/system/kernel/device_manager/playground/bus.cpp
r25112 r25394 8 8 9 9 #include <KernelExport.h> 10 #include <PCI.h> 10 11 11 12 … … 20 21 { 21 22 const char* bus; 22 if (gDeviceManager->get_attr_string(parent, B_D RIVER_BUS, &bus, false)23 if (gDeviceManager->get_attr_string(parent, B_DEVICE_BUS, &bus, false) 23 24 != B_OK) 24 25 return -1; … … 35 36 { 36 37 device_attr attrs[] = { 37 {B_DRIVER_PRETTY_NAME, B_STRING_TYPE, {string: "My Bus"}}, 38 {B_DRIVER_BUS, B_STRING_TYPE, {string: BUS_NAME}}, 39 {B_DRIVER_IS_BUS, B_UINT8_TYPE, {ui8: true}}, 38 {B_DEVICE_PRETTY_NAME, B_STRING_TYPE, {string: "My Bus"}}, 39 {B_DEVICE_BUS, B_STRING_TYPE, {string: BUS_NAME}}, 40 40 {NULL} 41 41 }; … … 66 66 uint16 vendor; 67 67 uint16 device; 68 const char *type; 68 uint16 type; 69 uint16 sub_type; 70 uint16 interface; 69 71 } kDevices[] = { 70 {0x1000, 0x0001, B_DISK_DRIVER_TYPE},71 {0x1001, 0x0001, B_NETWORK_DRIVER_TYPE},72 {0x1002, 0x0001, B_AUDIO_DRIVER_TYPE},73 {0x1002, 0x0002, B_BUS_DRIVER_TYPE},72 {0x1000, 0x0001, PCI_mass_storage, PCI_sata, PCI_sata_ahci}, 73 {0x1001, 0x0001, PCI_network, PCI_ethernet, 0}, 74 {0x1002, 0x0001, PCI_multimedia, PCI_audio, 0}, 75 {0x1002, 0x0002, PCI_serial_bus, PCI_usb, PCI_usb_ehci}, 74 76 }; 75 77 const size_t kNumDevices = sizeof(kDevices) / sizeof(kDevices[0]); … … 78 80 device_attr attrs[] = { 79 81 // info about the device 80 { "bus/vendor", B_UINT16_TYPE, {ui16: kDevices[i].vendor}},81 { "bus/device", B_UINT16_TYPE, {ui16: kDevices[i].device}},82 {B_DEVICE_VENDOR_ID, B_UINT16_TYPE, {ui16: kDevices[i].vendor}}, 83 {B_DEVICE_ID, B_UINT16_TYPE, {ui16: kDevices[i].device}}, 82 84 83 {B_DRIVER_BUS, B_STRING_TYPE, {string: BUS_NAME}}, 84 {B_DRIVER_DEVICE_TYPE, B_STRING_TYPE, {string: kDevices[i].type}}, 85 {B_DEVICE_BUS, B_STRING_TYPE, {string: BUS_NAME}}, 86 {B_DEVICE_TYPE, B_UINT16_TYPE, {ui16: kDevices[i].type}}, 87 {B_DEVICE_SUB_TYPE, B_UINT16_TYPE, 88 {ui16: kDevices[i].sub_type}}, 89 {B_DEVICE_INTERFACE, B_UINT16_TYPE, 90 {ui16: kDevices[i].interface}}, 91 92 {B_DEVICE_FIND_CHILD_FLAGS, B_UINT32_TYPE, 93 {ui32: B_FIND_CHILD_ON_DEMAND}}, 85 94 {NULL} 86 95 }; … … 91 100 92 101 device_attr attrs[] = { 93 {B_DRIVER_FIXED_CHILD, B_STRING_TYPE, {string: "non_existing/driver_v1"}}, 102 {B_DEVICE_FIXED_CHILD, B_STRING_TYPE, 103 {string: "non_existing/driver_v1"}}, 94 104 {NULL} 95 105 }; … … 123 133 get_bus_info(void* cookie, bus_info* info) 124 134 { 125 gDeviceManager->get_attr_uint16((device_node*)cookie, "bus/vendor",135 gDeviceManager->get_attr_uint16((device_node*)cookie, B_DEVICE_VENDOR_ID, 126 136 &info->vendor_id, false); 127 gDeviceManager->get_attr_uint16((device_node*)cookie, "bus/device",137 gDeviceManager->get_attr_uint16((device_node*)cookie, B_DEVICE_ID, 128 138 &info->device_id, false); 129 139 return B_OK; -
haiku/trunk/src/tests/system/kernel/device_manager/playground/device_manager.cpp
r25383 r25394 14 14 15 15 #include <KernelExport.h> 16 #include <Locker.h> 16 17 #include <module.h> 17 #include < Locker.h>18 #include <PCI.h> 18 19 19 20 #include <fs/KPath.h> … … 37 38 // from libkernelland_emu.so 38 39 39 status_t dm_get_attr_uint8(const device_node* node, const char* name, uint8* _value, 40 bool recursive); 41 status_t dm_get_attr_uint32(device_node* node, const char* name, uint32* _value, 42 bool recursive); 43 status_t dm_get_attr_string(device_node* node, const char* name, 40 status_t dm_get_attr_uint8(const device_node* node, const char* name, 41 uint8* _value, bool recursive); 42 status_t dm_get_attr_uint16(const device_node* node, const char* name, 43 uint16* _value, bool recursive); 44 status_t dm_get_attr_uint32(const device_node* node, const char* name, 45 uint32* _value, bool recursive); 46 status_t dm_get_attr_string(const device_node* node, const char* name, 44 47 const char** _value, bool recursive); 45 48 … … 110 113 private: 111 114 status_t _RegisterFixed(uint32& registered); 115 bool _AlwaysRegisterDynamic(); 116 status_t _AddPath(Stack<KPath*>& stack, const char* path, 117 const char* subPath = NULL); 112 118 status_t _GetNextDriverPath(void*& cookie, KPath& _path); 113 119 status_t _GetNextDriver(void* list, … … 118 124 status_t _RegisterPath(const char* path); 119 125 status_t _RegisterDynamic(); 120 bool _IsBus() const;121 126 122 127 device_node* fParent; … … 497 502 return status; 498 503 499 if (!fChildren.IsEmpty()) 504 if (!fChildren.IsEmpty()) { 505 fRegistered = true; 500 506 return B_OK; 507 } 501 508 } 502 509 503 510 // Register all possible child device nodes 504 511 505 uint32 findFlags = 0; 506 dm_get_attr_uint32(this, B_DRIVER_FIND_CHILD_FLAGS, &findFlags, false); 507 508 if ((findFlags & B_FIND_CHILD_ON_DEMAND) != 0) 509 return B_OK; 510 511 return _RegisterDynamic(); 512 } 513 514 515 bool 516 device_node::_IsBus() const 517 { 518 uint8 isBus; 519 if (dm_get_attr_uint8(this, B_DRIVER_IS_BUS, &isBus, false) != B_OK) 520 return false; 521 522 return isBus; 512 status = _RegisterDynamic(); 513 if (status == B_OK) 514 fRegistered = true; 515 516 return status; 523 517 } 524 518 … … 537 531 while (iterator.HasNext()) { 538 532 device_attr_private* attr = iterator.Next(); 539 if (strcmp(attr->name, B_D RIVER_FIXED_CHILD))533 if (strcmp(attr->name, B_DEVICE_FIXED_CHILD)) 540 534 continue; 541 535 … … 563 557 564 558 status_t 559 device_node::_AddPath(Stack<KPath*>& stack, const char* basePath, 560 const char* subPath) 561 { 562 KPath* path = new(std::nothrow) KPath; 563 if (path == NULL) 564 return B_NO_MEMORY; 565 566 status_t status = path->SetTo(basePath); 567 if (status == B_OK && subPath != NULL && subPath[0]) 568 status = path->Append(subPath); 569 if (status == B_OK) 570 status = stack.Push(path); 571 572 if (status != B_OK) 573 delete path; 574 575 return status; 576 } 577 578 579 status_t 565 580 device_node::_GetNextDriverPath(void*& cookie, KPath& _path) 566 581 { … … 574 589 575 590 StackDeleter<KPath*> stackDeleter(stack); 576 577 if (!_IsBus()) { 578 // add driver paths 579 KPath* path = new(std::nothrow) KPath; 580 if (path == NULL) 581 return B_NO_MEMORY; 582 583 status_t status = path->SetTo("drivers"); 584 if (status != B_OK) { 585 delete path; 586 return status; 587 } 588 589 // TODO: this might be more than one path! 590 const char *type; 591 if (dm_get_attr_string(this, B_DRIVER_DEVICE_TYPE, &type, false) 592 == B_OK) 593 path->Append(type); 594 595 stack->Push(path); 591 uint16 type = 0; 592 uint16 subType = 0; 593 uint16 interface = 0; 594 dm_get_attr_uint16(this, B_DEVICE_TYPE, &type, false); 595 dm_get_attr_uint16(this, B_DEVICE_SUB_TYPE, &subType, false); 596 dm_get_attr_uint16(this, B_DEVICE_INTERFACE, &interface, false); 597 598 // TODO: maybe make this extendible via settings file? 599 switch (type) { 600 case PCI_mass_storage: 601 switch (subType) { 602 case PCI_scsi: 603 _AddPath(*stack, "busses", "scsi"); 604 break; 605 case PCI_ide: 606 _AddPath(*stack, "busses", "ide"); 607 break; 608 case PCI_sata: 609 _AddPath(*stack, "busses", "sata"); 610 break; 611 default: 612 _AddPath(*stack, "busses", "disk"); 613 break; 614 } 615 break; 616 case PCI_serial_bus: 617 switch (subType) { 618 case PCI_firewire: 619 _AddPath(*stack, "busses", "firewire"); 620 break; 621 case PCI_usb: 622 _AddPath(*stack, "busses", "usb"); 623 break; 624 default: 625 _AddPath(*stack, "busses"); 626 break; 627 } 628 break; 629 case PCI_network: 630 _AddPath(*stack, "drivers", "net"); 631 break; 632 case PCI_display: 633 _AddPath(*stack, "drivers", "graphics"); 634 break; 635 case PCI_multimedia: 636 switch (subType) { 637 case PCI_audio: 638 case PCI_hd_audio: 639 _AddPath(*stack, "drivers", "audio"); 640 break; 641 case PCI_video: 642 _AddPath(*stack, "drivers", "video"); 643 break; 644 default: 645 _AddPath(*stack, "drivers"); 646 break; 647 } 648 break; 649 default: 650 if (sRootNode == this) { 651 _AddPath(*stack, "busses/pci"); 652 _AddPath(*stack, "bus_managers"); 653 } else 654 _AddPath(*stack, "drivers"); 655 break; 596 656 } 597 657 598 // add bus paths599 KPath* path = new(std::nothrow) KPath;600 if (path == NULL)601 return B_NO_MEMORY;602 603 status_t status = path->SetTo("bus");604 if (status != B_OK) {605 delete path;606 return status;607 }608 609 stack->Push(path);610 658 stackDeleter.Detach(); 611 659 … … 706 754 707 755 756 bool 757 device_node::_AlwaysRegisterDynamic() 758 { 759 uint16 type = 0; 760 uint16 subType = 0; 761 dm_get_attr_uint16(this, B_DEVICE_TYPE, &type, false); 762 dm_get_attr_uint16(this, B_DEVICE_SUB_TYPE, &subType, false); 763 764 return type == PCI_serial_bus || type == PCI_bridge; 765 // TODO: we may want to be a bit more specific in the future 766 } 767 768 708 769 status_t 709 770 device_node::_RegisterDynamic() 710 771 { 711 uint32 findFlags; 712 if (dm_get_attr_uint32(this, B_DRIVER_FIND_CHILD_FLAGS, &findFlags, false) 713 != B_OK) 714 findFlags = 0; 772 uint32 findFlags = 0; 773 dm_get_attr_uint32(this, B_DEVICE_FIND_CHILD_FLAGS, &findFlags, false); 774 775 // If this is our initial registration, we honour the B_FIND_CHILD_ON_DEMAND 776 // requirements 777 if (!fRegistered && (findFlags & B_FIND_CHILD_ON_DEMAND) != 0 778 && !_AlwaysRegisterDynamic()) 779 return B_OK; 715 780 716 781 KPath path; … … 826 891 827 892 828 static driver_module_info* 829 driver_module(device_node* node) 830 { 831 return node->DriverModule(); 832 } 833 834 835 static void* 836 driver_data(device_node* node) 837 { 838 return node->DriverData(); 893 static void 894 get_driver(device_node* node, driver_module_info** _module, void** _data) 895 { 896 if (_module != NULL) 897 *_module = node->DriverModule(); 898 if (_data != NULL) 899 *_data = node->DriverData(); 839 900 } 840 901 … … 886 947 887 948 status_t 888 dm_get_attr_uint16( device_node* node, const char* name, uint16* _value,949 dm_get_attr_uint16(const device_node* node, const char* name, uint16* _value, 889 950 bool recursive) 890 951 { … … 903 964 904 965 status_t 905 dm_get_attr_uint32( device_node* node, const char* name, uint32* _value,966 dm_get_attr_uint32(const device_node* node, const char* name, uint32* _value, 906 967 bool recursive) 907 968 { … … 920 981 921 982 status_t 922 dm_get_attr_uint64( device_node* node, const char* name,983 dm_get_attr_uint64(const device_node* node, const char* name, 923 984 uint64* _value, bool recursive) 924 985 { … … 937 998 938 999 status_t 939 dm_get_attr_string( device_node* node, const char* name, const char** _value,940 bool recursive)1000 dm_get_attr_string(const device_node* node, const char* name, 1001 const char** _value, bool recursive) 941 1002 { 942 1003 if (node == NULL || name == NULL || _value == NULL) … … 954 1015 955 1016 status_t 956 dm_get_attr_raw( device_node* node, const char* name, const void** _data,1017 dm_get_attr_raw(const device_node* node, const char* name, const void** _data, 957 1018 size_t* _length, bool recursive) 958 1019 { … … 1006 1067 register_device, 1007 1068 unregister_device, 1008 driver_module, 1009 driver_data, 1069 get_driver, 1010 1070 device_root, 1011 1071 get_next_child_device, … … 1031 1091 { 1032 1092 device_attr attrs[] = { 1033 {B_DRIVER_PRETTY_NAME, B_STRING_TYPE, {string: "Devices Root"}}, 1034 {B_DRIVER_IS_BUS, B_UINT8_TYPE, {ui8: true}}, 1035 {B_DRIVER_BUS, B_STRING_TYPE, {string: "root"}}, 1036 {B_DRIVER_FIND_CHILD_FLAGS, B_UINT32_TYPE, 1093 {B_DEVICE_PRETTY_NAME, B_STRING_TYPE, {string: "Devices Root"}}, 1094 {B_DEVICE_BUS, B_STRING_TYPE, {string: "root"}}, 1095 {B_DEVICE_FIND_CHILD_FLAGS, B_UINT32_TYPE, 1037 1096 {ui32: B_FIND_MULTIPLE_CHILDREN}}, 1038 1097 {NULL} -
haiku/trunk/src/tests/system/kernel/device_manager/playground/device_manager.h
r24973 r25394 70 70 status_t (*unregister_device)(device_node *node); 71 71 72 driver_module_info *(*driver_module)(device_node *node);73 void *(*driver_data)(device_node *node);72 void (*get_driver)(device_node *node, driver_module_info **_module, 73 void **_cookie); 74 74 75 75 device_node *(*root_device)(); … … 87 87 #endif 88 88 89 status_t (*get_attr_uint8)( device_node *node, const char *name,89 status_t (*get_attr_uint8)(const device_node *node, const char *name, 90 90 uint8 *value, bool recursive); 91 status_t (*get_attr_uint16)( device_node *node, const char *name,91 status_t (*get_attr_uint16)(const device_node *node, const char *name, 92 92 uint16 *value, bool recursive); 93 status_t (*get_attr_uint32)( device_node *node, const char *name,93 status_t (*get_attr_uint32)(const device_node *node, const char *name, 94 94 uint32 *value, bool recursive); 95 status_t (*get_attr_uint64)( device_node *node, const char *name,95 status_t (*get_attr_uint64)(const device_node *node, const char *name, 96 96 uint64 *value, bool recursive); 97 status_t (*get_attr_string)( device_node *node, const char *name,97 status_t (*get_attr_string)(const device_node *node, const char *name, 98 98 const char **_value, bool recursive); 99 status_t (*get_attr_raw)( device_node *node, const char *name,99 status_t (*get_attr_raw)(const device_node *node, const char *name, 100 100 const void **_data, size_t *_size, bool recursive); 101 101 … … 123 123 124 124 125 / / standard device node attributes125 /* standard device node attributes */ 126 126 127 #define B_DRIVER_PRETTY_NAME "driver/pretty name" // string 128 #define B_DRIVER_MAPPING "driver/mapping" // string 129 #define B_DRIVER_IS_BUS "driver/is_bus" // uint8 130 #define B_DRIVER_BUS "driver/bus" // string 131 #define B_DRIVER_FIXED_CHILD "fixed child" // string 132 #define B_DRIVER_FIND_CHILD_FLAGS "find child flags" // uint32 133 #define B_DRIVER_UNIQUE_DEVICE_ID "unique id" // string 134 #define B_DRIVER_DEVICE_TYPE "device type" // string 127 #define B_DEVICE_PRETTY_NAME "device/pretty name" /* string */ 128 #define B_DEVICE_MAPPING "device/mapping" /* string */ 129 #define B_DEVICE_BUS "device/bus" /* string */ 130 #define B_DEVICE_FIXED_CHILD "device/fixed child" /* string */ 131 #define B_DEVICE_FIND_CHILD_FLAGS "device/find child flags" /* uint32 */ 132 133 #define B_DEVICE_VENDOR_ID "device/vendor" /* uint16 */ 134 #define B_DEVICE_ID "device/id" /* uint16 */ 135 #define B_DEVICE_TYPE "device/type" 136 /* uint16, PCI base class */ 137 #define B_DEVICE_SUB_TYPE "device/subtype" 138 /* uint16, PCI sub type */ 139 #define B_DEVICE_INTERFACE "device/interface" 140 /* uint16, PCI class API */ 141 142 #define B_DEVICE_UNIQUE_ID "device/unique id" /* string */ 135 143 136 144 // find child flags 137 145 #define B_FIND_CHILD_ON_DEMAND 0x01 138 146 #define B_FIND_MULTIPLE_CHILDREN 0x02 139 140 // driver types141 #define B_AUDIO_DRIVER_TYPE "audio"142 #define B_BUS_DRIVER_TYPE "bus"143 #define B_DISK_DRIVER_TYPE "disk"144 #define B_GRAPHICS_DRIVER_TYPE "graphics"145 #define B_INPUT_DRIVER_TYPE "input"146 #define B_MISC_DRIVER_TYPE "misc"147 #define B_NETWORK_DRIVER_TYPE "net"148 #define B_VIDEO_DRIVER_TYPE "video"149 #define B_INTERRUPT_CONTROLLER_DRIVER_TYPE "interrupt controller"150 147 151 148 -
haiku/trunk/src/tests/system/kernel/device_manager/playground/driver.cpp
r25112 r25394 29 29 #endif 30 30 31 bus_for_driver_module_info* module 32 = (bus_for_driver_module_info*)gDeviceManager->driver_module(parent); 31 bus_for_driver_module_info* module; 32 void* data; 33 gDeviceManager->get_driver(parent, (driver_module_info**)&module, &data); 34 33 35 if (strcmp(module->info.info.name, BUS_FOR_DRIVER_NAME)) 34 36 return -1; 35 36 void* data = gDeviceManager->driver_data(parent);37 37 38 38 bus_info info;
