These will serve as functions I use with the Extensible Driver Interface (EDI) to help support other hobbyist OS'.
Code: Select all
#ifndef DRAGON_OS_PCI_H
#define DRAGON_OS_PCI_H
/* Includes */
#include <kernel/preprocessor.h> /* Contains several macros, such as API, which is __attribute__((stdcall)) */
#include <kernel/types.h> /* Specifies u8, u16, u32, u64, s8, s16, s32, s64, ptr_t, result_t, and bitfield_t */
/* PCI Types */
typedef u8 pci_bus_t; /* 0..255 (8 bits) */
typedef u8 pci_device_t; /* 0..32 (5 bits) */
typedef u8 pci_function_t; /* 0..7 (3 bits) */
typedef u16 pci_pack_t; /* 0..2 = pci_function_t, 3..7 = pci_device_t, 8..15 = pci_bus_t */
/* NOTE: Maybe rename pci_pack_t to pci_path_t (in essence, it is a "path" of sorts) */
typedef u8 pci_register_t;
typedef u8 pci_result_t;
/* PCI Results (pci_result_t) */
#define PCI_SUCCESS 0x00
#define PCI_BIOS_PRESENT 0x00
#define PCI_BIOS_NOT_PRESENT 0x80
#define PCI_DEVICE_NOT_FOUND 0x86
#define PCI_BAD_VENDOR_ID 0x83
#define PCI_FUNCTION_NOT_SUPPORTED 0x81
#define PCI_BAD_REGISTER_NUMBER 0x87
/* Functions */
EXTERN pci_result_t API pciBiosPresent(PCI_BIOS_DESC *pPciBios); /* TODO: Create PCI_BIOS_DESC structure */
EXTERN pci_result_t API pciFindDevice(u16 deviceId, u16 vendorId, u16 index, pci_pack_t *pPack /* out */);
EXTERN pci_result_t API pciFindClassCode(u32 classCode, u16 index, pci_pack_t *pPack /* out */);
EXTERN pci_result_t API pciGenerateSpecialCycle(pci_bus_t bus, u32 data);
EXTERN pci_result_t API pciReadByte(pci_pack_t pack, pci_register_t reg, u8 *pData /* out */);
EXTERN pci_result_t API pciReadWord(pci_pack_t pack, pci_register_t reg, u16 *pData /* out */);
EXTERN pci_result_t API pciReadDword(pci_pack_t pack, pci_register_t reg, u32 *pData /* out */);
EXTERN pci_result_t API pciWriteByte(pci_pack_t pack, pci_register_t reg, u8 data);
EXTERN pci_result_t API pciWriteWord(pci_pack_t pack, pci_register_t reg, u16 data);
EXTERN pci_result_t API pciWriteDword(pci_pack_t pack, pci_register_t reg, u32 data);
#endif