Luna/kernel/src/arch/PCI.h
apio fa29d6e9b9
All checks were successful
continuous-integration/drone/push Build is passing
kernel: Rename PCI::callback_t to PCI::Callback
2023-01-25 20:58:59 +01:00

74 lines
1.5 KiB
C++

#pragma once
#include <luna/Types.h>
namespace PCI
{
enum Field : u32
{
VendorID = 0x00,
DeviceID = 0x02,
Command = 0x04,
Status = 0x06,
RevisionID = 0x08,
ProgIF = 0x09,
Subclass = 0x0a,
Class = 0x0b,
HeaderType = 0x0e,
SecondaryBus = 0x19
};
struct Device
{
struct ID
{
u16 vendor;
u16 device;
};
struct Type
{
u8 klass;
u8 subclass;
u8 prog_if;
};
struct Address
{
u32 bus;
u32 slot;
u32 function;
};
ID id;
Type type;
Address address;
};
typedef void (*Callback)(const Device&);
struct Match
{
i16 klass { -1 };
i16 subclass { -1 };
i16 prog_if { -1 };
};
constexpr u16 INVALID_ID = 0xFFFF;
// Architecture-dependent.
u8 read8(const Device::Address& address, u32 field);
u16 read16(const Device::Address& address, u32 field);
u32 read32(const Device::Address& address, u32 field);
void write8(const Device::Address& address, u32 field, u8 value);
void write16(const Device::Address& address, u32 field, u16 value);
void write32(const Device::Address& address, u32 field, u32 value);
Device::ID read_id(const Device::Address& address);
Device::Type read_type(const Device::Address& address);
void scan(Callback callback, Match match);
}