Changeset 25394

Show
Ignore:
Timestamp:
05/09/08 08:56:29 (7 months ago)
Author:
axeld
Message:

* Changed how the driver paths are found: now, the bus can add type/sub-type/

interface information (in the PCI notion) to a node, and the possible paths
of a device driver are generated from that information by the device manager.

* Removed the "is bus" attribute - the device manager now decides wether or not

a device always loads its children (as opposed to on demand loading only),
even if the B_FIND_CHILD_ON_DEMAND flag is specified.

* device_node::Register() now correctly maintains the fRegistered member field.
* Replaced the driver_module() and driver_data() methods with a get_driver()

method that retrieves all information at once.

* Cleaned attribute names.
* Some other cleanup, adding const where it makes sense.

Location:
haiku/trunk/src/tests/system/kernel/device_manager/playground
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • haiku/trunk/src/tests/system/kernel/device_manager/playground/bus.cpp

    r25112 r25394  
    88 
    99#include <KernelExport.h> 
     10#include <PCI.h> 
    1011 
    1112 
     
    2021{ 
    2122        const char* bus; 
    22         if (gDeviceManager->get_attr_string(parent, B_DRIVER_BUS, &bus, false) 
     23        if (gDeviceManager->get_attr_string(parent, B_DEVICE_BUS, &bus, false) 
    2324                        != B_OK) 
    2425                return -1; 
     
    3536{ 
    3637        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}}, 
    4040                {NULL} 
    4141        }; 
     
    6666                uint16          vendor; 
    6767                uint16          device; 
    68                 const char      *type; 
     68                uint16          type; 
     69                uint16          sub_type; 
     70                uint16          interface; 
    6971        } 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}, 
    7476        }; 
    7577        const size_t kNumDevices = sizeof(kDevices) / sizeof(kDevices[0]); 
     
    7880                device_attr attrs[] = { 
    7981                        // 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}}, 
    8284 
    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}}, 
    8594                        {NULL} 
    8695                }; 
     
    91100 
    92101        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"}}, 
    94104                {NULL} 
    95105        }; 
     
    123133get_bus_info(void* cookie, bus_info* info) 
    124134{ 
    125         gDeviceManager->get_attr_uint16((device_node*)cookie, "bus/vendor", 
     135        gDeviceManager->get_attr_uint16((device_node*)cookie, B_DEVICE_VENDOR_ID, 
    126136                &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, 
    128138                &info->device_id, false); 
    129139        return B_OK; 
  • haiku/trunk/src/tests/system/kernel/device_manager/playground/device_manager.cpp

    r25383 r25394  
    1414 
    1515#include <KernelExport.h> 
     16#include <Locker.h> 
    1617#include <module.h> 
    17 #include <Locker.h> 
     18#include <PCI.h> 
    1819 
    1920#include <fs/KPath.h> 
     
    3738        // from libkernelland_emu.so 
    3839 
    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, 
     40status_t dm_get_attr_uint8(const device_node* node, const char* name, 
     41        uint8* _value, bool recursive); 
     42status_t dm_get_attr_uint16(const device_node* node, const char* name, 
     43        uint16* _value, bool recursive); 
     44status_t dm_get_attr_uint32(const device_node* node, const char* name, 
     45        uint32* _value, bool recursive); 
     46status_t dm_get_attr_string(const device_node* node, const char* name, 
    4447        const char** _value, bool recursive); 
    4548 
     
    110113private: 
    111114                        status_t                _RegisterFixed(uint32& registered); 
     115                        bool                    _AlwaysRegisterDynamic(); 
     116                        status_t                _AddPath(Stack<KPath*>& stack, const char* path, 
     117                                                                const char* subPath = NULL); 
    112118                        status_t                _GetNextDriverPath(void*& cookie, KPath& _path); 
    113119                        status_t                _GetNextDriver(void* list, 
     
    118124                        status_t                _RegisterPath(const char* path); 
    119125                        status_t                _RegisterDynamic(); 
    120                         bool                    _IsBus() const; 
    121126 
    122127        device_node*                    fParent; 
     
    497502                        return status; 
    498503 
    499                 if (!fChildren.IsEmpty()) 
     504                if (!fChildren.IsEmpty()) { 
     505                        fRegistered = true; 
    500506                        return B_OK; 
     507                } 
    501508        } 
    502509 
    503510        // Register all possible child device nodes 
    504511 
    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; 
    523517} 
    524518 
     
    537531        while (iterator.HasNext()) { 
    538532                device_attr_private* attr = iterator.Next(); 
    539                 if (strcmp(attr->name, B_DRIVER_FIXED_CHILD)) 
     533                if (strcmp(attr->name, B_DEVICE_FIXED_CHILD)) 
    540534                        continue; 
    541535 
     
    563557 
    564558status_t 
     559device_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 
     579status_t 
    565580device_node::_GetNextDriverPath(void*& cookie, KPath& _path) 
    566581{ 
     
    574589 
    575590                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; 
    596656                } 
    597657 
    598                 // add bus paths 
    599                 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); 
    610658                stackDeleter.Detach(); 
    611659 
     
    706754 
    707755 
     756bool 
     757device_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 
    708769status_t 
    709770device_node::_RegisterDynamic() 
    710771{ 
    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; 
    715780 
    716781        KPath path; 
     
    826891 
    827892 
    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(); 
     893static void 
     894get_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(); 
    839900} 
    840901 
     
    886947 
    887948status_t 
    888 dm_get_attr_uint16(device_node* node, const char* name, uint16* _value, 
     949dm_get_attr_uint16(const device_node* node, const char* name, uint16* _value, 
    889950        bool recursive) 
    890951{ 
     
    903964 
    904965status_t 
    905 dm_get_attr_uint32(device_node* node, const char* name, uint32* _value, 
     966dm_get_attr_uint32(const device_node* node, const char* name, uint32* _value, 
    906967        bool recursive) 
    907968{ 
     
    920981 
    921982status_t 
    922 dm_get_attr_uint64(device_node* node, const char* name, 
     983dm_get_attr_uint64(const device_node* node, const char* name, 
    923984        uint64* _value, bool recursive) 
    924985{ 
     
    937998 
    938999status_t 
    939 dm_get_attr_string(device_node* node, const char* name, const char** _value, 
    940         bool recursive) 
     1000dm_get_attr_string(const device_node* node, const char* name, 
     1001        const char** _value, bool recursive) 
    9411002{ 
    9421003        if (node == NULL || name == NULL || _value == NULL) 
     
    9541015 
    9551016status_t 
    956 dm_get_attr_raw(device_node* node, const char* name, const void** _data, 
     1017dm_get_attr_raw(const device_node* node, const char* name, const void** _data, 
    9571018        size_t* _length, bool recursive) 
    9581019{ 
     
    10061067        register_device, 
    10071068        unregister_device, 
    1008         driver_module, 
    1009         driver_data, 
     1069        get_driver, 
    10101070        device_root, 
    10111071        get_next_child_device, 
     
    10311091{ 
    10321092        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, 
    10371096                        {ui32: B_FIND_MULTIPLE_CHILDREN}}, 
    10381097                {NULL} 
  • haiku/trunk/src/tests/system/kernel/device_manager/playground/device_manager.h

    r24973 r25394  
    7070        status_t (*unregister_device)(device_node *node); 
    7171 
    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); 
    7474 
    7575        device_node *(*root_device)(); 
     
    8787#endif 
    8888 
    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, 
    9090                                        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, 
    9292                                        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, 
    9494                                        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, 
    9696                                        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, 
    9898                                        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, 
    100100                                        const void **_data, size_t *_size, bool recursive); 
    101101 
     
    123123 
    124124 
    125 // standard device node attributes 
     125/* standard device node attributes */ 
    126126 
    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 */ 
    135143 
    136144// find child flags 
    137145#define B_FIND_CHILD_ON_DEMAND          0x01 
    138146#define B_FIND_MULTIPLE_CHILDREN        0x02 
    139  
    140 // driver types 
    141 #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" 
    150147 
    151148 
  • haiku/trunk/src/tests/system/kernel/device_manager/playground/driver.cpp

    r25112 r25394  
    2929#endif 
    3030 
    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 
    3335        if (strcmp(module->info.info.name, BUS_FOR_DRIVER_NAME)) 
    3436                return -1; 
    35  
    36         void* data = gDeviceManager->driver_data(parent); 
    3737 
    3838        bus_info info;