PCI database.

alentours-dev
q3k 2012-10-28 13:30:00 +01:00
parent 5eb8f32864
commit bf27bbb79a
5 changed files with 8651 additions and 1 deletions

View File

@ -52,6 +52,13 @@ version-gen:
@echo "[i] Generating revision file..."
@contrib/rev-gen
include/Alentours/PCIDB.h:
@echo "[i] Downloading pcidatabase.com header file..."
@echo "[w] WARNING: Please check include/Alentours/PCIDB.h for possible rootkits and stuff."
@curl http://www.pcidatabase.com/pci_c_header.php > include/Alentours/PCIDB.h
python2 contrib/fix-pci-db.py
obj/src/%.xo : src/%.cpp
@echo "[i] Compiling $*.cpp ..."
@if [ -e obj/src/$*.xo ] ; then rm obj/src/$*.xo ; fi
@ -78,7 +85,7 @@ ALENTOURSSRC += $(shell find src/Alentours -mindepth 1 -maxdepth 3 -name "*.asm"
ALENTOURSOBJ := $(patsubst %.cpp,%.xo,$(ALENTOURSSRC))
ALENTOURSOBJ := $(patsubst %.asm,%.nao,$(ALENTOURSOBJ))
ALENTOURS := $(foreach i, $(ALENTOURSOBJ), obj/$(i))
Alentours: $(ALENTOURS)
Alentours: $(ALENTOURS) include/Alentours/PCIDB.h
src/Lua/liblua.a:
@echo "[i] Building Lua..."

View File

@ -0,0 +1,34 @@
#!/usr/bin/python2
import re
f = open("include/Alentours/PCIDB.h", "r")
d = f.read()
d = d.replace("char *", "const char *")
d = re.sub(r'http://pcidatabase\.com/update_device\.php[^"]*"', '"', d)
f.close()
lines = d.split("\n")
newlines = []
in_ventable = False
in_devtable = False
for line in lines:
if line.startswith(' { 0x165C, 0x0002'):
in_devtable = True
if in_devtable and line.startswith("}"):
in_devtable = False
if in_devtable:
if not re.match(r' { 0x([a-fA-F0-9]){4}, 0x([a-fA-F0-9]){4}, "[^"\\]*", "[^"\\]*".+', line) or line.find("??") >= 0:
print "[i] Removing invalid line %s from PCIDB.h..." % line
else:
newlines.append(line)
else:
newlines.append(line)
f = open("include/Alentours/PCIDB.h", "w")
f.write("\n".join(newlines))
f.close()

View File

@ -68,6 +68,9 @@ namespace Alentours
static CPCIDevice *GetDeviceByAddress(u16 Bus, u16 Device);
static void GetDeviceByIDPair(cb::CVector<CPCIDevice> &Devices, u16 Vendor, u16 Device);
static void GetAllDevices(cb::CVector<CPCIDevice> &Devices);
static u8 DBGetVendor(u16 VID, const s8 **VendorNameOut);
static u8 DBGetProduct(u16 VID, u16 PID, const s8 **ProductNameOut, const s8 **ProductDescriptionOut);
};
};

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,5 @@
#include "Alentours/PCI.h"
#include "Alentours/PCIDB.h"
extern "C" {
#include "Tier0/kstdio.h"
}
@ -43,6 +44,52 @@ void CPCIManager::Initialize(void)
}
}
u8 CPCIManager::DBGetVendor(u16 VID, const s8 **VendorNameOut)
{
u32 TableLength = PCI_VENTABLE_LEN;
for (u32 i = 0; i < TableLength; i++)
{
PCI_VENTABLE *Vendor = &PciVenTable[i];
if (Vendor->VenId == VID)
{
// try to use the short name, if not null
bool Empty = true;
const s8 *Character = Vendor->VenShort;
while (*Character != 0)
{
if (*Character != 0)
{
Empty = false;
break;
}
Character++;
}
if (!Empty)
*VendorNameOut = Vendor->VenShort;
else
*VendorNameOut = Vendor->VenFull;
return 1;
}
}
return 0;
}
u8 CPCIManager::DBGetProduct(u16 VID, u16 PID, const s8 **ProductNameOut, const s8 **ProductDescriptionOut)
{
u32 TableLength = PCI_DEVTABLE_LEN;
for (u32 i = 0; i < TableLength; i++)
{
PCI_DEVTABLE *Product = &PciDevTable[i];
if (Product->VenId == VID && Product->DevId == PID)
{
*ProductNameOut = Product->Chip;
*ProductDescriptionOut = Product->ChipDesc;
return 1;
}
}
return 0;
}
u32 CPCIDevice::ConfigRead(u16 Function, u16 Offset)
{
TPCIConfigAddress Address;
@ -87,6 +134,13 @@ CPCIDevice::CPCIDevice(u16 Bus, u16 Device)
kprintf("Unknown.\n");
break;
}
kprintf(" Info: ");
const s8 *VendorName, *ProductName, *ProductDescription;
if (CPCIManager::DBGetVendor(m_Header.VendorID, &VendorName))
kprintf("%s", VendorName);
if (CPCIManager::DBGetProduct(m_Header.VendorID, m_Header.ProductID, &ProductName, &ProductDescription))
kprintf(" %s %s", ProductName, ProductDescription);
kprintf("\n");
}
cb::CVector<CPCIDevice> CPCIManager::m_Devices;