Add Pci.Address struct
This commit is contained in:
parent
9ac69c9003
commit
40ff805f7d
@ -11,6 +11,18 @@ struct Pci
|
|||||||
/* IO address for PCI configuration data. */
|
/* IO address for PCI configuration data. */
|
||||||
enum IO_ADDR_CONFIG_DATA = 0xCFCu;
|
enum IO_ADDR_CONFIG_DATA = 0xCFCu;
|
||||||
|
|
||||||
|
struct Address
|
||||||
|
{
|
||||||
|
/** Bus number (0-255). */
|
||||||
|
ubyte bus_nr;
|
||||||
|
|
||||||
|
/** Device number (0-31). */
|
||||||
|
ubyte device_nr;
|
||||||
|
|
||||||
|
/** Function number (0-7). */
|
||||||
|
ubyte function_nr;
|
||||||
|
}
|
||||||
|
|
||||||
struct SerialBusController
|
struct SerialBusController
|
||||||
{
|
{
|
||||||
enum ID = 0x0Cu;
|
enum ID = 0x0Cu;
|
||||||
@ -26,17 +38,25 @@ struct Pci
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static uint read_config_register(uint bus_id, uint device_idx, uint function_idx, uint register_id)
|
private static uint read_config_register(Address address, uint register_id)
|
||||||
{
|
{
|
||||||
uint addr = 0x8000_0000u | (bus_id << 16u) | (device_idx << 11u) | (function_idx << 8u) | (register_id << 2u);
|
uint cfg_addr = 0x8000_0000u |
|
||||||
out32(IO_ADDR_CONFIG_ADDRESS, addr);
|
(address.bus_nr << 16u) |
|
||||||
|
(address.device_nr << 11u) |
|
||||||
|
(address.function_nr << 8u) |
|
||||||
|
(register_id << 2u);
|
||||||
|
out32(IO_ADDR_CONFIG_ADDRESS, cfg_addr);
|
||||||
return in32(IO_ADDR_CONFIG_DATA);
|
return in32(IO_ADDR_CONFIG_DATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void write_config_register(uint bus_id, uint device_idx, uint function_idx, uint register_id, uint value)
|
private static void write_config_register(Address address, uint register_id, uint value)
|
||||||
{
|
{
|
||||||
uint addr = 0x8000_0000u | (bus_id << 16u) | (device_idx << 11u) | (function_idx << 8u) | (register_id << 2u);
|
uint cfg_addr = 0x8000_0000u |
|
||||||
out32(IO_ADDR_CONFIG_ADDRESS, addr);
|
(address.bus_nr << 16u) |
|
||||||
|
(address.device_nr << 11u) |
|
||||||
|
(address.function_nr << 8u) |
|
||||||
|
(register_id << 2u);
|
||||||
|
out32(IO_ADDR_CONFIG_ADDRESS, cfg_addr);
|
||||||
out32(IO_ADDR_CONFIG_DATA, value);
|
out32(IO_ADDR_CONFIG_DATA, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,12 +86,12 @@ struct Pci
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void scan(uint bus_id, uint device_idx, uint function_idx)
|
private static void scan(Address address)
|
||||||
{
|
{
|
||||||
ulong reg0 = read_config_register(bus_id, device_idx, function_idx, 0u);
|
ulong reg0 = read_config_register(address, 0u);
|
||||||
if (reg0 != 0xFFFFFFFFu)
|
if (reg0 != 0xFFFFFFFFu)
|
||||||
{
|
{
|
||||||
uint reg2 = read_config_register(bus_id, device_idx, function_idx, 2u);
|
uint reg2 = read_config_register(address, 2u);
|
||||||
ushort vendor_id = reg0 & 0xFFFFu;
|
ushort vendor_id = reg0 & 0xFFFFu;
|
||||||
ushort device_id = (reg0 >> 16u) & 0xFFFFu;
|
ushort device_id = (reg0 >> 16u) & 0xFFFFu;
|
||||||
ubyte class_id = (reg2 >> 24u) & 0xFFu;
|
ubyte class_id = (reg2 >> 24u) & 0xFFu;
|
||||||
@ -80,17 +100,17 @@ struct Pci
|
|||||||
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",
|
||||||
vendor_id, device_id,
|
vendor_id, device_id,
|
||||||
class_id, subclass_id, if_id,
|
class_id, subclass_id, if_id,
|
||||||
bus_id, device_idx, function_idx);
|
address.bus_nr, address.device_nr, address.function_nr);
|
||||||
init_device(class_id, subclass_id, if_id);
|
init_device(class_id, subclass_id, if_id);
|
||||||
if (function_idx == 0u)
|
if (address.function_nr == 0u)
|
||||||
{
|
{
|
||||||
uint reg3 = read_config_register(bus_id, device_idx, function_idx, 3u);
|
uint reg3 = read_config_register(address, 3u);
|
||||||
if ((reg3 & (1u << 23u)) != 0u)
|
if ((reg3 & (1u << 23u)) != 0u)
|
||||||
{
|
{
|
||||||
/* Multi-function device found. */
|
/* Multi-function device found. */
|
||||||
for (function_idx = 1u; function_idx < 8u; function_idx++)
|
for (address.function_nr = 1u; address.function_nr < 8u; address.function_nr++)
|
||||||
{
|
{
|
||||||
scan(bus_id, device_idx, function_idx);
|
scan(address);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -100,11 +120,11 @@ struct Pci
|
|||||||
public static void initialize()
|
public static void initialize()
|
||||||
{
|
{
|
||||||
Klog.writefln("Scanning PCI devices...");
|
Klog.writefln("Scanning PCI devices...");
|
||||||
for (uint bus_id = 0u; bus_id < 256u; bus_id++)
|
for (uint bus_nr = 0u; bus_nr < 256u; bus_nr++)
|
||||||
{
|
{
|
||||||
for (uint device_idx = 0u; device_idx < 32u; device_idx++)
|
for (ubyte device_nr = 0u; device_nr < 32u; device_nr++)
|
||||||
{
|
{
|
||||||
scan(bus_id, device_idx, 0u);
|
scan(Address(cast(ubyte)bus_nr, device_nr, 0u));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Klog.writefln("PCI scan complete.");
|
Klog.writefln("PCI scan complete.");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user