kernel/inc/drivers/driver.h

116 lines
3.8 KiB
C
Raw Permalink Normal View History

// This file is part of noxos and licensed under the MIT open source license
#ifndef NOXOS_DRIVER_H
#define NOXOS_DRIVER_H
#include <utils/stdtypes.h>
#include <utils/bitmap.h>
#include <utils/hashmap.h>
#include <drivers/builtin/elf/elf.h>
#define DRIVER_MANAGER_CHUNK_SIZE 64
#define DRIVER_MANAGER_HASHMAP_SIZE 128
#define DRIVER_MEMORY_REGION_SIZE 0x100000000 // 4 GB
typedef enum {
DRIVER_TRANSPORT_PCI,
DRIVER_TRANSPORT_USB,
DRIVER_TRANSPORT_FS
} __attribute__((packed)) driver_transport_protocol_E;
typedef enum {
DRIVER_UNKNOWN = 0x0000,
DRIVER_RESERVED = 0x0001,
// Specific Driver
DRIVER_MASS_STORAGE = 0x0101,
DRIVER_FILESYSTEM = 0x0102,
DRIVER_GRAPHICS = 0x0103,
DRIVER_AUDIO = 0x0104,
// Drivers which define the transmission of data but have multiple
// intended usages, such as USB for mass storage, input, etc..
DRIVER_TRANSMISSION = 0x0201,
DRIVER_USB_DEVICE = 0x0202,
DRIVER_PCI_DEVICE = 0x0203,
DRIVER_PCIE_DEVICE = 0x0204,
DRIVER_BLUETOOTH = 0x0205,
DRIVER_ETHERNET = 0x0206,
// MISCELLANEOUS
DRIVER_EMULATION = 0x7fff
} driver_category_E;
typedef struct {
uint16_t vendor_id;
uint16_t device_id;
} __attribute__((packed)) driver_config_device_id_T;
typedef struct {
bool enable_progif;
uint8_t class;
uint8_t subclass;
uint8_t progif;
uint16_t num_device_ids;
driver_config_device_id_T device_ids[];
} __attribute__((packed)) driver_config_pci_T;
typedef struct {
uint8_t min_version;
uint16_t num_device_ids;
driver_config_device_id_T device_ids[];
} __attribute__((packed)) driver_config_usb_T;
typedef struct {
uint8_t gpt_guid[16];
uint8_t mbr_type;
} __attribute__((packed)) driver_config_fs_T;
typedef union {
driver_config_pci_T* pci;
driver_config_usb_T* usb;
driver_config_fs_T* fs;
} conf_U;
typedef struct {
uint64_t id;
void* base;
elf_executable_T* executable;
} driver_T;
typedef struct driver_manager_chunk_T driver_manager_chunk_T;
struct driver_manager_chunk_T {
driver_T drivers [DRIVER_MANAGER_CHUNK_SIZE];
bitmap_T drivers_bitmap;
uint32_t free_slots;
driver_manager_chunk_T* prev;
driver_manager_chunk_T* next;
};
typedef struct {
driver_manager_chunk_T* driver_pool;
hashmap_T lookup_table_pci;
hashmap_T lookup_table_usb;
hashmap_T lookup_table_fs_gpt;
hashmap_T lookup_table_fs_mbr;
} driver_manager_T;
void driver_manager_init ();
driver_manager_chunk_T* driver_manager_chunk_alloc(driver_manager_chunk_T* prev);
driver_T* driver_register (elf_executable_T* executable, uint8_t* buffer);
void driver_init (driver_T* driver, driver_transport_protocol_E protocol, conf_U conf);
driver_T* driver_lookup_pci_device (uint16_t vendor_id, uint16_t device_id);
driver_T* driver_lookup_usb_device (uint16_t vendor_id, uint16_t device_id);
driver_T* driver_lookup_fs_gpt (uint8_t guid[16]);
driver_T* driver_lookup_fs_mbr (uint8_t type);
driver_T* driver_lookup_by_address (void* address);
#endif //NOXOS_DRIVER_H