XenevaOS
Loading...
Searching...
No Matches
audrv.h
Go to the documentation of this file.
1
30#ifndef __AU_DRV_H__
31#define __AU_DRV_H__
32
33#include <stdint.h>
34#if defined(__GNUC__) || defined(__clang__)
35#ifndef __cplusplus
36#include <stdbool.h>
37#endif
38#endif
39#ifdef ARCH_X64
40#include <Hal/x86_64_hal.h>
41#include <Hal/hal.h>
42#endif
43#include <Fs/vfs.h>
44
45#define DRIVER_CLASS_AUDIO 1
46#define DRIVER_CLASS_VIDEO 2
47#define DRIVER_CLASS_NETWORK 3
48#define DRIVER_CLASS_CONNECTIVITY_BLUETOOTH 4
49#define DRIVER_CLASS_CONNECTIVITY_WIFI 5
50#define DRIVER_CLASS_STORAGE 6
51#define DRIVER_CLASS_USB 7
52#define DRIVER_CLASS_HID 8
53#define DRIVER_CLASS_UNKNOWN 9
54
55#define DEVICE_CLASS_ETHERNET 1
56#define DEVICE_CLASS_HD_AUDIO 2
57#define DEVICE_CLASS_USB3 3
58
59#define AURORA_MAX_DRIVERS 256
60
61typedef int(*au_drv_entry)(void* drv);
62typedef int(*au_drv_unload)(void* drv);
63
64/* A driver opts in to runtime unloading by exporting `uint32_t AuDriverFlags`
65 * with AU_DRV_FLAG_UNLOADABLE set AND an AuDriverUnload() that undoes every
66 * kernel-visible registration it made (devices, VFS nodes, callbacks, hooks).
67 * Drivers without the flag are never unloaded. */
68#define AU_DRV_FLAG_UNLOADABLE 0x1
69
70/* In a driver: AU_DRIVER_FLAGS(AU_DRV_FLAG_UNLOADABLE); exports AuDriverFlags */
71#ifdef __GNUC__
72#define AU_DRIVER_FLAGS(f) AU_EXTERN AU_EXPORT uint32_t AuDriverFlags = (f)
73#else
74#define AU_DRIVER_FLAGS(f) AU_EXTERN __declspec(dllexport) uint32_t AuDriverFlags = (f)
75#endif
76
77
78#pragma pack(push,1)
79typedef struct _aurora_driver_ {
82 char name[32];
83 bool present;
90 int bus;
91 int func;
92 int dev;
98 size_t image_sz;
99 /* component model: set by the driver manager, never by drivers */
100 uint32_t flags; /* AU_DRV_FLAG_* , read from the driver's AuDriverFlags export */
101 int32_t refcount; /* >0 blocks unload */
102 size_t region_pages; /* pages reserved in the driver region */
103 void* resources; /* AuResource list, see aucomponent.h */
105#pragma pack(pop)
106
107
108
109#pragma pack(push,1)
110
119
120#pragma pack(pop)
121
122
123/*
124* AuDrvMngrInitialize -- Initialize the driver manager
125* @param info -- kernel boot info
126*/
127extern void AuDrvMngrInitialize(KERNEL_BOOT_INFO *info);
128
129/*
130* AuRegisterDevice -- register a new device to
131* aurora system
132* @param dev -- Pointer to device to add
133*/
135
136/*
137* AuCheckDevice -- checks an aurora device if it's
138* already present
139* @param classC -- class code of the device to check
140* @param subclassC -- sub class code of the device to check
141* @param progIF -- programming interface of the device
142*/
143AU_EXTERN AU_EXPORT bool AuCheckDevice(uint16_t classC, uint16_t subclassC, uint8_t progIF);
144
145/*
146 * AuBootDriverInitialise -- Initialise and load all boot time drivers
147 * @param info -- Kernel boot information passed by XNLDR
148 * [TODO] : Everything is hard coded for now
149 */
151
152/*
153 * AuDrvMgrGetBaseAddress -- returns the current
154 * driver load base address
155 */
157
158/*
159 * AuDrvMgrSetBaseAddress -- sets a new base
160 * address for driver to load
161 * it's highly risky because, if we set it to
162 * kernel stack location, kernel will crash
163 */
164extern void AuDrvMgrSetBaseAddress(uint64_t base_address);
165
166/*
167* AuGetConfEntry -- Get an entry offset in the file for required device
168* @param vendor_id -- vendor id of the product
169* @param device_id -- device id of the product
170* @param buffer -- configuration file buffer
171* @param entryoff -- entry offset from where search begins
172*/
173extern char* AuGetConfEntry(uint32_t vendor_id, uint32_t device_id, uint8_t* buffer, int entryoff);
174
175/*
176* AuGetDriverName -- Extract the driver path from its entry offset
177* @param vendor_id -- vendor id of the product
178* @param device_id -- device id of the product
179* @param buffer -- configuration file buffer
180* @param entryoff -- entry offset from where search begins
181*/
182extern AuDriver* AuGetDriverName(uint32_t vendor_id, uint32_t device_id, uint8_t* buffer, int entryoff);
183
189extern AuDriver* AuDrvManagerCheckFault(uint64_t fault_addr);
190
197extern void AuDrvCatchFault(AuDriver* drv, uint64_t fault_addr);
198
202extern void AuDrvUnloadAll();
203
204
205#endif
#define AU_EXTERN
Definition aurora.h:54
#define AU_EXPORT
Definition aurora.h:40
int int32_t
Definition acefiex.h:160
unsigned int uint32_t
Definition acefiex.h:163
unsigned char uint8_t
Definition acefiex.h:161
COMPILER_DEPENDENT_UINT64 uint64_t
Definition acefiex.h:165
unsigned short int uint16_t
Definition acefiex.h:162
int(* au_drv_unload)(void *drv)
Definition audrv.h:62
uint64_t AuDrvMgrGetBaseAddress()
AuDrvMgrGetBaseAddress – returns the current driver load base address.
Definition audrv.cpp:428
AU_EXTERN AU_EXPORT void AuBootDriverInitialise(KERNEL_BOOT_INFO *info)
AuBootDriverInitialise – Initialise and load all boot time drivers.
Definition audrv.cpp:395
char * AuGetConfEntry(uint32_t vendor_id, uint32_t device_id, uint8_t *buffer, int entryoff)
AuGetConfEntry – Get an entry offset in the file for required device.
Definition audrv.cpp:91
AuDriver * AuGetDriverName(uint32_t vendor_id, uint32_t device_id, uint8_t *buffer, int entryoff)
AuGetDriverName – Extract the driver path from its entry offset.
Definition audrv.cpp:199
void AuDrvMngrInitialize(KERNEL_BOOT_INFO *info)
AuDrvMngrInitialize – Initialize the driver manager.
Definition audrv.cpp:283
AU_EXTERN AU_EXPORT bool AuCheckDevice(uint16_t classC, uint16_t subclassC, uint8_t progIF)
AuCheckDevice – checks an aurora device if it's already present.
Definition audrv.cpp:357
AuDriver * AuDrvManagerCheckFault(uint64_t fault_addr)
AuDrvManagerCheckFault – check if this driver contain the fault address, helpful for debugging.
Definition audrv.c:785
void AuDrvCatchFault(AuDriver *drv, uint64_t fault_addr)
AuDrvCatchFault – resolves original virtual address of the driver and relocate its symbol name.
Definition audrv.c:803
struct _aurora_device_ AuDevice
void AuDrvMgrSetBaseAddress(uint64_t base_address)
AuDrvMgrSetBaseAddress – sets a new base address for driver to load it's highly risky because,...
Definition audrv.cpp:438
struct _aurora_driver_ AuDriver
int(* au_drv_entry)(void *drv)
Definition audrv.h:61
AU_EXTERN AU_EXPORT void AuRegisterDevice(AuDevice *dev)
AuRegisterDevice – register a new device to aurora system.
Definition audrv.cpp:345
void AuDrvUnloadAll()
AuDrvUnloadAll – call unload handler of all registered drivers.
Definition audrv.c:816
const struct device * dev
Definition drm_print.h:519
Definition aurora.h:166
Definition audrv.h:111
uint8_t progIf
Definition audrv.h:114
uint16_t subClassCode
Definition audrv.h:113
uint8_t aurora_dev_class
Definition audrv.h:116
uint8_t aurora_driver_class
Definition audrv.h:117
uint16_t classCode
Definition audrv.h:112
bool initialized
Definition audrv.h:115
Definition audrv.h:79
uint64_t base
Definition audrv.h:84
int dev
Definition audrv.h:92
uint16_t vendorID
Definition audrv.h:86
uint8_t drv_type
Definition audrv.h:81
uint8_t classCode
Definition audrv.h:88
size_t image_sz
Definition audrv.h:98
bool present
Definition audrv.h:83
uint64_t new_load_base
Definition audrv.h:97
int bus
Definition audrv.h:90
au_drv_unload unload
Definition audrv.h:95
uint64_t device
Definition audrv.h:93
uint64_t end
Definition audrv.h:85
void * resources
Definition audrv.h:103
uint32_t flags
Definition audrv.h:100
au_drv_entry entry
Definition audrv.h:94
size_t region_pages
Definition audrv.h:102
int func
Definition audrv.h:91
char name[32]
Definition audrv.h:82
uint16_t deviceID
Definition audrv.h:87
uint8_t subClassCode
Definition audrv.h:89
int32_t refcount
Definition audrv.h:101
uint8_t id
Definition audrv.h:80
uint64_t original_load_base
Definition audrv.h:96