With the current setup of that file that's going to be pretty hard to do. I have a small Python script that does the generation of that file for me (though its primitive and has some errors). Not really sure how to correlate vendor ID and device ID together. The script, as I wrote it, is below:Octocontrabass wrote:Yes.Ethin wrote:How would I determine this at runtime? Would I just mask all the bits anyway?
But get_device_string() tries to identify the device using only the device ID, which means it will be wrong if more than one vendor assigns the same device ID. It needs to work like get_subclass_string(), taking both the vendor ID and the device ID as input.Ethin wrote:I get this information by calling get_vendor_string(), get_device_string(), and get_class_string(), all of which are defined in src/pcidb.rs. Its a rust implementation of the entire PCI ID database.
Code: Select all
import requests
import sys
db=requests.get("https://pci-ids.ucw.cz/v2.2/pci.ids").content.decode()
lines = db.split("\n")
vendors = {}
devices = {}
# extract vendors
# syntax: vendor vendor_name (no tab)
for line in lines:
if line.startswith("#"): # comment
continue
if line.startswith("\t"): # device
continue
if line.startswith("\t\t"): # subsystem
continue
if line.startswith('C'): # PCI class
continue
if len(line) > 0:
vendor = line.split(" ")[0]
vendor_name = line.split(" ")[1]
vendors[vendor] = vendor_name
# Extract devices
# syntax: device device_name <-- single tab
for line in lines:
if line.startswith("#"): # comment
continue
if not line.startswith("\t"): # device
continue
if line.startswith("\t\t"): # subsystem
continue
if line.startswith('C'):
continue
if len(line) > 0:
device = line.split(" ")
devices[device[0]] = device[1]
# print match statements
print("""pub fn get_vendor_string(vendor: u16)->&str {
match vendor {""")
for vendor, name in vendors.items():
print (f"0x{vendor} => \"{name}\",")
print("_ => \"Unknown vendor\",")
print("}")
print("}")
print("""pub fn get_device_string(device: u16)->&str {
match device {""")
for device, name in devices.items():
try:
print (f"0x{device[1:]} => \"{name}\",")
except UnicodeEncodeError:
continue
print("_ => \"Unknown device\",")
print("}")
print("}")
Code: Select all
0014 Loongson Technology LLC
7a00 Hyper Transport Bridge Controller
7a02 APB (Advanced Peripheral Bus) Controller
7a03 Gigabit Ethernet Controller
7a04 OTG USB Controller
7a05 Vivante GPU (Graphics Processing Unit)
7a06 DC (Display Controller)
7a07 HDA (High Definition Audio) Controller
7a08 SATA AHCI Controller
7a09 PCI-to-PCI Bridge
7a0b SPI Controller
7a0c LPC Controller
7a0f DMA (Direct Memory Access) Controller
7a14 EHCI USB Controller
7a15 Vivante GPU (Graphics Processing Unit)
7a19 PCI-to-PCI Bridge
7a24 OHCI USB Controller
7a29 PCI-to-PCI Bridge
Code: Select all
# Syntax:
# vendor vendor_name
# device device_name <-- single tab
# subvendor subdevice subsystem_name <-- two tabs