Merge into main the new state of the operating system/kernel #1
@ -95,17 +95,30 @@ const char* GetClassCodeName (uint64_t ClassCode ) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* getVendor( uint64_t VendorID){
|
const char* getVendor( uint32_t VendorID){
|
||||||
switch (VendorID)
|
switch (VendorID)
|
||||||
{
|
{
|
||||||
case 0x8086:
|
case 0x8086:
|
||||||
return "Intel Corporation";
|
return "Intel Corporation";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
case 0x10DE:
|
||||||
return "Vendor Unkown";
|
return "NVIDIA Corporation";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 0x1022:
|
||||||
|
return "Advanced Micro Devices, Inc.[AMD]";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0x1002:
|
||||||
|
return "Advanced Micor Devices, Inc.[AMD/ATI]";
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return "Vendor Unkown";
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -136,8 +149,9 @@ uint32_t ConfigReadWord (uint8_t bus, uint8_t device, uint8_t func, uint8_t offs
|
|||||||
uint8_t GetHeaderType( PCIBusAddress& PCIDeviceAddress ){
|
uint8_t GetHeaderType( PCIBusAddress& PCIDeviceAddress ){
|
||||||
uint32_t header_information = ConfigReadWord(PCIDeviceAddress , 0xC);
|
uint32_t header_information = ConfigReadWord(PCIDeviceAddress , 0xC);
|
||||||
return (uint8_t) (
|
return (uint8_t) (
|
||||||
(header_information >> 16) //Get higher half
|
((header_information >> 16) //Get higher half
|
||||||
& 0x00FF ); // Select the last two bytes
|
& 0x00FF) // Select the last two bytes
|
||||||
|
& 0x7F ); // Mask bit 7 as it indicates if the device is a mulit function device!
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t GetClassCodes( PCIBusAddress& PCIDeviceAddress ){
|
uint16_t GetClassCodes( PCIBusAddress& PCIDeviceAddress ){
|
||||||
@ -146,6 +160,39 @@ uint16_t GetClassCodes( PCIBusAddress& PCIDeviceAddress ){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsMultiFunctionDevice(PCIBusAddress& PCIDeviceAddress){
|
||||||
|
uint32_t header_information = ConfigReadWord(PCIDeviceAddress, 0xC);
|
||||||
|
return (((header_information>>16)
|
||||||
|
& 0x80)
|
||||||
|
>> 7 );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void PrintPCIDeviceInfo (PCIBusAddress& PCIDeviceAddress)
|
||||||
|
{
|
||||||
|
uint32_t DeviceID = (GetDevice(PCIDeviceAddress.bus, PCIDeviceAddress.device, PCIDeviceAddress.function) >> 16);
|
||||||
|
uint32_t VendorID = GetDevice(PCIDeviceAddress.bus, PCIDeviceAddress.device, PCIDeviceAddress.function) & 0xFFFF;
|
||||||
|
printf("Device found!\n");
|
||||||
|
printf("Bus: %d, Device: %d, function: %d \n", PCIDeviceAddress.bus, PCIDeviceAddress.device, PCIDeviceAddress.function);
|
||||||
|
printf("DeviceID: 0x%x, Vendor: %s\n",
|
||||||
|
DeviceID
|
||||||
|
, getVendor(VendorID) );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t header_type = GetHeaderType(PCIDeviceAddress);
|
||||||
|
printf( "Header type: 0x%x\n", header_type);
|
||||||
|
|
||||||
|
uint16_t deviceClasses = GetClassCodes(PCIDeviceAddress);
|
||||||
|
printf("class: %s, subClass: %d\n\n", GetClassCodeName((deviceClasses >>8)), deviceClasses & 0xFF);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void PCI_Enumerate(){
|
void PCI_Enumerate(){
|
||||||
int devicesFound = 0;
|
int devicesFound = 0;
|
||||||
// loop through all possible busses, devices and their functions;
|
// loop through all possible busses, devices and their functions;
|
||||||
@ -159,33 +206,35 @@ void PCI_Enumerate(){
|
|||||||
int function = 0;
|
int function = 0;
|
||||||
|
|
||||||
//uint64_t DeviceIdentify = ConfigReadWord(bus, device, function,0x0);
|
//uint64_t DeviceIdentify = ConfigReadWord(bus, device, function,0x0);
|
||||||
uint32_t VendorID = GetDevice(bus, device, function) & 0xFFFF;
|
|
||||||
uint32_t DeviceID = GetDevice(bus, device, function) >> 16;
|
uint32_t DeviceID = GetDevice(bus, device, function) >> 16;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if( DeviceID != 0xFFFF){
|
if( DeviceID != 0xFFFF){
|
||||||
printf("Device found!\n");
|
|
||||||
printf("Bus: %d, Device: %d, function: %d \n", bus, device, function);
|
|
||||||
printf("DeviceID: 0x%x, VendorID: %s\n", DeviceID, getVendor(VendorID) );
|
|
||||||
|
|
||||||
// iterate over the functions if it is a multi function device!
|
|
||||||
if( false ){
|
|
||||||
for ( function ++ ; function < 8; function++)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PCIBusAddress busAddress =
|
PCIBusAddress busAddress =
|
||||||
PCIBusAddress{bus, device, function };
|
PCIBusAddress{bus, device, function };
|
||||||
|
|
||||||
uint8_t header_type = GetHeaderType(busAddress);
|
PrintPCIDeviceInfo(busAddress);
|
||||||
printf( "Header type: 0x%x\n", header_type);
|
|
||||||
|
// iterate over the functions if it is a multi function device!
|
||||||
|
if( IsMultiFunctionDevice(busAddress) ){
|
||||||
|
printf("Multi function device! \n");
|
||||||
|
printf("Check remaining Functions\n");
|
||||||
|
for ( function = 1 ; function < 8; function++)
|
||||||
|
{
|
||||||
|
uint32_t DeviceID = GetDevice(bus, device, function) >> 16;
|
||||||
|
|
||||||
|
if( DeviceID != 0xFFFF){
|
||||||
|
PCIBusAddress busAddress2 = PCIBusAddress{bus, device, function};
|
||||||
|
PrintPCIDeviceInfo(busAddress2);
|
||||||
|
devicesFound++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint16_t deviceClasses = GetClassCodes(busAddress);
|
|
||||||
printf(" class: %s, subClass: %d\n\n",
|
|
||||||
(deviceClasses >>8) > 0x13 ? "Unknown": GetClassCodeName((deviceClasses >>8)), deviceClasses & 0xFF);
|
|
||||||
|
|
||||||
devicesFound++;
|
devicesFound++;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* PCI devices API
|
* PCI devices API
|
||||||
*/
|
*/
|
||||||
@ -8,14 +7,14 @@ struct PCIBusAddress{
|
|||||||
|
|
||||||
int bus ;
|
int bus ;
|
||||||
int device ;
|
int device ;
|
||||||
int function[8];
|
int function;
|
||||||
|
|
||||||
|
|
||||||
uint32_t getAddress( int deviceFunction = 0 ){
|
uint32_t getAddress( ){
|
||||||
return ((uint32_t) 1 << 31) |
|
return ((uint32_t) 1 << 31) |
|
||||||
((uint32_t) bus << 16) |
|
((uint32_t) bus << 16) |
|
||||||
((uint32_t) device << 11)|
|
((uint32_t) device << 11)|
|
||||||
((uint32_t) function[deviceFunction] << 8) |
|
((uint32_t) function << 8) |
|
||||||
0x0000;
|
0x0000;
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -27,10 +26,29 @@ class PCIDevice {
|
|||||||
~PCIDevice();
|
~PCIDevice();
|
||||||
PCIBusAddress const PCIAddress();
|
PCIBusAddress const PCIAddress();
|
||||||
|
|
||||||
|
|
||||||
|
inline const char* getDeviceString(){
|
||||||
|
return "Not implemented"; //GetClassCodeName(deviceclass);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const char* getVendorString(){
|
||||||
|
return "Not implemented"; // getVendor(VendorID);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void setVendorID (uint16_t id) {
|
||||||
|
this->VendorID = id;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int bus;
|
int bus;
|
||||||
int device;
|
int device;
|
||||||
int function;
|
int function;
|
||||||
|
|
||||||
|
uint16_t VendorID;
|
||||||
|
uint16_t DeviceID;
|
||||||
|
uint8_t deviceclass;
|
||||||
|
uint8_t devicesubclass;
|
||||||
|
|
||||||
int headerType;
|
int headerType;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user