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 "DevicePCI.h" 11 12#include <sstream> 13#include <stdlib.h> 14 15#include <Catalog.h> 16 17#undef B_TRANSLATION_CONTEXT 18#define B_TRANSLATION_CONTEXT "DevicePCI" 19 20extern "C" { 21#include "dm_wrapper.h" 22#include "pcihdr.h" 23#include "pci-utils.h" 24} 25 26 27DevicePCI::DevicePCI(Device* parent) 28 : 29 Device(parent), 30 fClassBaseId(0), 31 fClassSubId(0), 32 fClassApiId(0), 33 fVendorId(0), 34 fDeviceId(0), 35 fSubsystemVendorId(0), 36 fSubSystemId(0) 37{ 38} 39 40 41DevicePCI::~DevicePCI() 42{ 43} 44 45 46BString ToHex(uint16 num) 47{ 48 std::stringstream ss; 49 ss.flags(std::ios::hex | std::ios::showbase); 50 ss << num; 51 return BString(ss.str().c_str()); 52} 53 54 55void 56DevicePCI::InitFromAttributes() 57{ 58 // Process the attributes 59 fClassBaseId = atoi(fAttributeMap[B_DEVICE_TYPE].String()); 60 fClassSubId = atoi(fAttributeMap[B_DEVICE_SUB_TYPE].String()); 61 fClassApiId = atoi(fAttributeMap[B_DEVICE_INTERFACE].String()); 62 fVendorId = atoi(fAttributeMap[B_DEVICE_VENDOR_ID].String()); 63 fDeviceId = atoi(fAttributeMap[B_DEVICE_ID].String()); 64 65 // Looks better in Hex, so rewrite 66 fAttributeMap[B_DEVICE_TYPE] = ToHex(fClassBaseId); 67 fAttributeMap[B_DEVICE_SUB_TYPE] = ToHex(fClassSubId); 68 fAttributeMap[B_DEVICE_INTERFACE] = ToHex(fClassApiId); 69 fAttributeMap[B_DEVICE_VENDOR_ID] = ToHex(fVendorId); 70 fAttributeMap[B_DEVICE_ID] = ToHex(fDeviceId); 71 72 // Fetch ClassInfo 73 char classInfo[128]; 74 get_class_info(fClassBaseId, fClassSubId, fClassApiId, classInfo, 75 sizeof(classInfo)); 76 77 // Fetch ManufacturerName 78 BString ManufacturerName; 79 const char *venShort; 80 const char *venFull; 81 get_vendor_info(fVendorId, &venShort, &venFull); 82 if (!venShort && !venFull) { 83 ManufacturerName << B_TRANSLATE("Unknown"); 84 } else if (venShort && venFull) { 85 ManufacturerName << venFull << "(" << venShort << ")"; 86 } else { 87 ManufacturerName << (venShort ? venShort : venFull); 88 } 89 90 // Fetch DeviceName 91 BString DeviceName; 92 const char *devShort; 93 const char *devFull; 94 get_device_info(fVendorId, fDeviceId, fSubsystemVendorId, fSubSystemId, 95 &devShort, &devFull); 96 if (!devShort && !devFull) { 97 DeviceName << B_TRANSLATE("Unknown"); 98 } else if (devShort && devFull) { 99 DeviceName << devFull << "(" << devShort << ")"; 100 } else { 101 DeviceName << (devShort ? devShort : devFull); 102 } 103 104 SetAttribute(B_TRANSLATE("Device name"), DeviceName); 105 SetAttribute(B_TRANSLATE("Manufacturer"), ManufacturerName); 106#if 0 107 // These are a source of confusion for users, leading them to think there 108 // is no driver for their device. Until we can display something useful, 109 // let's not show the lines at all. 110 SetAttribute(B_TRANSLATE("Driver used"), B_TRANSLATE("Not implemented")); 111 SetAttribute(B_TRANSLATE("Device paths"), B_TRANSLATE("Not implemented")); 112#endif 113 SetAttribute(B_TRANSLATE("Class info"), classInfo); 114 fCategory = (Category)fClassBaseId; 115 BString outlineName; 116 outlineName << ManufacturerName << " " << DeviceName; 117 SetText(outlineName.String()); 118} 119