Add Pci.Type struct

This commit is contained in:
Josh Holtrop 2023-10-22 21:30:36 -04:00
parent 7632445d43
commit 1c6c922b45

View File

@ -1,3 +1,6 @@
/**
* PCI (Peripheral Component Interconnect) functionality.
*/
module hulk.pci; module hulk.pci;
import hulk.cpu; import hulk.cpu;
@ -20,6 +23,9 @@ struct Pci
enum MAX_FUNCTIONS_PER_DEVICE = 8; enum MAX_FUNCTIONS_PER_DEVICE = 8;
/**
* PCI device address (bus number, device number, function number).
*/
struct Address struct Address
{ {
/** Bus number (0-255). */ /** Bus number (0-255). */
@ -32,10 +38,29 @@ struct Pci
ubyte function_nr; ubyte function_nr;
} }
/**
* PCI device type (class ID, subclass ID, interface ID).
*/
struct Type
{
/** Class ID. */
ubyte class_id;
/** Subclass ID. */
ubyte subclass_id;
/** Interface ID. */
ubyte interface_id;
}
/**
* PCI device object.
*/
static struct Device static struct Device
{ {
Configuration * config; Configuration * config;
Address address; Address address;
Type type;
bool multifunction; bool multifunction;
Range[6] memory_ranges; Range[6] memory_ranges;
@ -43,9 +68,12 @@ struct Pci
{ {
this.config = config; this.config = config;
this.address = address; this.address = address;
type.class_id = config.class_id;
type.subclass_id = config.subclass_id;
type.interface_id = config.interface_id;
Klog.writefln("Found PCI device %04x:%04x (%02x:%02x:%02x) at %02u:%02u.%u", Klog.writefln("Found PCI device %04x:%04x (%02x:%02x:%02x) at %02u:%02u.%u",
config.vendor_id, config.device_id, config.vendor_id, config.device_id,
config.class_id, config.subclass_id, config.interface_id, type.class_id, type.subclass_id, type.interface_id,
address.bus_nr, address.device_nr, address.function_nr); address.bus_nr, address.device_nr, address.function_nr);
multifunction = (address.function_nr == 0u) && ((config.header_type & 0x80u) != 0u); multifunction = (address.function_nr == 0u) && ((config.header_type & 0x80u) != 0u);
ubyte header_type = config.header_type & 0x7Fu; ubyte header_type = config.header_type & 0x7Fu;