1 #include <malloc.h> 2 #include <stdio.h> 3 #include <string.h> 4 #include <unistd.h> 5 6 #include <drivers/device_manager.h> 7 #include <drivers/module.h> 8 #include <drivers/PCI.h> 9 10 #include "config_driver.h" 11 #include "dm_wrapper.h" 12 13 static void 14 put_level(int32 level) 15 { 16 while (level-- > 0) 17 printf(" "); 18 } 19 20 21 static void 22 dump_attribute(struct dev_attr *attr, int32 level) 23 { 24 if (attr == NULL) 25 return; 26 27 put_level(level); 28 printf("\"%s\" : ", attr->name); 29 switch (attr->type) { 30 case B_STRING_TYPE: 31 printf("string : \"%s\"", attr->value.string); 32 break; 33 case B_UINT8_TYPE: 34 printf("uint8 : %u (%#x)", attr->value.ui8, attr->value.ui8); 35 break; 36 case B_UINT16_TYPE: 37 printf("uint16 : %u (%#x)", attr->value.ui16, attr->value.ui16); 38 break; 39 case B_UINT32_TYPE: 40 printf("uint32 : %lu (%#lx)", attr->value.ui32, attr->value.ui32); 41 break; 42 case B_UINT64_TYPE: 43 printf("uint64 : %Lu (%#Lx)", attr->value.ui64, attr->value.ui64); 44 break; 45 default: 46 printf("raw data"); 47 } 48 printf("\n"); 49 } 50 51 static void 52 dump_device(uint8 level) 53 { 54 char data[256]; 55 56 while (dm_get_next_attr() == B_OK) { 57 struct dev_attr attr; 58 attr.value.raw.data = data; 59 attr.value.raw.length = sizeof(data); 60 dm_retrieve_attr(&attr); 61 dump_attribute(&attr, level); 62 } 63 } 64 65 66 static void 67 dump_nodes(uint8 level) 68 { 69 status_t err; 70 dump_device(level); 71 72 if (get_child() != B_OK) 73 return; 74 75 do { 76 dump_nodes(level+1); 77 } while ((err = get_next_child()) == B_OK); 78 79 get_parent(); 80 } 81 82 int main() 83 { 84 status_t error; 85 86 if ((error = init_dm_wrapper()) < 0) { 87 printf("Error initializing device manager (%s)\n", strerror(error)); 88 return error; 89 } 90 91 dump_nodes(0); 92 93 uninit_dm_wrapper(); 94 95 return 0; 96 } 97