1 /* 2 * Copyright 2008-2009 Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Pieter Panman 7 */ 8 9 10 #include <sstream> 11 #include <stdlib.h> 12 13 #include "DevicePCI.h" 14 15 extern "C" { 16 #include "dm_wrapper.h" 17 #include "pcihdr.h" 18 #include "pci-utils.h" 19 } 20 21 22 DevicePCI::DevicePCI(Device* parent) 23 : 24 Device(parent), 25 fClassBaseId(0), 26 fClassSubId(0), 27 fClassApiId(0), 28 fVendorId(0), 29 fDeviceId(0), 30 fSubsystemVendorId(0), 31 fSubSystemId(0) 32 { 33 } 34 35 36 DevicePCI::~DevicePCI() 37 { 38 } 39 40 41 BString ToHex(uint16 num) 42 { 43 std::stringstream ss; 44 ss.flags(std::ios::hex | std::ios::showbase); 45 ss << num; 46 return BString(ss.str().c_str()); 47 } 48 49 50 void 51 DevicePCI::InitFromAttributes() 52 { 53 // Process the attributes 54 fClassBaseId = atoi(fAttributeMap[B_DEVICE_TYPE].String()); 55 fClassSubId = atoi(fAttributeMap[B_DEVICE_SUB_TYPE].String()); 56 fClassApiId = atoi(fAttributeMap[B_DEVICE_INTERFACE].String()); 57 fVendorId = atoi(fAttributeMap[B_DEVICE_VENDOR_ID].String()); 58 fDeviceId = atoi(fAttributeMap[B_DEVICE_ID].String()); 59 60 // Looks better in Hex, so rewrite 61 fAttributeMap[B_DEVICE_TYPE] = ToHex(fClassBaseId); 62 fAttributeMap[B_DEVICE_SUB_TYPE] = ToHex(fClassSubId); 63 fAttributeMap[B_DEVICE_INTERFACE] = ToHex(fClassApiId); 64 fAttributeMap[B_DEVICE_VENDOR_ID] = ToHex(fVendorId); 65 fAttributeMap[B_DEVICE_ID] = ToHex(fDeviceId); 66 67 // Fetch ClassInfo 68 char classInfo[64]; 69 get_class_info(fClassBaseId, fClassSubId, fClassApiId, classInfo, sizeof(classInfo)); 70 71 // Fetch ManufacturerName 72 BString ManufacturerName; 73 const char *venShort; 74 const char *venFull; 75 get_vendor_info(fVendorId, &venShort, &venFull); 76 if (!venShort && !venFull) { 77 ManufacturerName << "Unkown"; 78 } else if (venShort && venFull) { 79 ManufacturerName << venFull << "(" << venShort << ")"; 80 } else { 81 ManufacturerName << (venShort ? venShort : venFull); 82 } 83 84 // Fetch DeviceName 85 BString DeviceName; 86 const char *devShort; 87 const char *devFull; 88 get_device_info(fVendorId, fDeviceId, fSubsystemVendorId, fSubSystemId, &devShort, &devFull); 89 if (!devShort && !devFull) { 90 DeviceName << "Unknown"; 91 } else if (devShort && devFull) { 92 DeviceName << devFull << "(" << devShort << ")"; 93 } else { 94 DeviceName << (devShort ? devShort : devFull); 95 } 96 97 SetAttribute("Device name", DeviceName); 98 SetAttribute("Manufacturer", ManufacturerName); 99 SetAttribute("Driver used", "Not implemented"); 100 SetAttribute("Device paths", "Not implemented"); 101 SetAttribute("Class Info", classInfo); 102 fCategory = (Category)fClassBaseId; 103 BString outlineName; 104 outlineName << ManufacturerName << " " << DeviceName; 105 SetText(outlineName.String()); 106 } 107 108 109 Attributes 110 DevicePCI::GetBusAttributes() 111 { 112 Attributes attributes; 113 attributes.push_back(GetAttribute(B_DEVICE_TYPE)); 114 attributes.push_back(GetAttribute(B_DEVICE_SUB_TYPE)); 115 attributes.push_back(GetAttribute(B_DEVICE_INTERFACE)); 116 attributes.push_back(GetAttribute(B_DEVICE_VENDOR_ID)); 117 attributes.push_back(GetAttribute(B_DEVICE_ID)); 118 return attributes; 119 } 120 121 122 BString 123 DevicePCI::GetBusStrings() 124 { 125 BString str; 126 str << "Class Info:\t\t\t\t: " << fAttributeMap["Class Info"]; 127 return str; 128 } 129