Is this a good way of designing drivers?
Posted: Sun Oct 04, 2020 7:17 pm
So, I'm trying to make the drivers for my kernel abstract and easy to write (e.g.: the driver author shouldn't have to worry about many quirks of the kernel itself, just the hardware it supports). To that end, my drivers follow a convention like this:
1) What should I standardize in (say) a DriverInitializationInfo struct?
2) Do you guys have any suggestions on how I can improve this design?
- The driver has a function called init. I don't have a deinit/shutdown function yet, but once I actually can shutdown the system I'll be adding that in.
- Each driver init function is dependent on the driver; I want to somehow standardize this, but I don't know what I should standardize and leave alone (e.g.: should I require a memory allocation/deallocation routine, a set of port IO routines, etc.). For my NVMe implementation, for example, it accepts an array of 6 u64 elements for the BARs of the NVMe controller, a memory allocation and deallocation routine, the interrupt line of the PCIe device, and an interrupt registration routine that the driver can call to let the kernel know that the driver wants to listen to that interrupt. Interrupt listeners work similar to windows hooks, e.g.: there can be multiple interrupt listeners set for a single interrupt, and each is called in sequence. Interrupt listeners must execute as fast as possible because the interrupt handler does not return an EOI until all listeners have been notified.
- The drivers are directly written in rust and are linked directly into the kernel, though I'm considering decoupling this completely. Making them C-compatible will require me to be able to execute ELF code, which will take me a while to actually figure out, but the drivers will be like DLLs of sorts. I was also thinking about making drivers web assembly modules, but I'm not very knowledgeable on writing WASM in rust (pretty much all the guides assume a web environment).
1) What should I standardize in (say) a DriverInitializationInfo struct?
2) Do you guys have any suggestions on how I can improve this design?