Draft Version
Goals

The
picture illustrates how the communication between application/driver/kernel
will happen during an IO request. The following picture is drawn for system
synchronous READ call from an application.

For
performance reasons, there will be little control over IO space. The IO flag in
control registers should set to ring 1. This means only ring 0 and ring1
processes can access IO space. Since only kernel will be in ring 0 and drivers
in ring 1, applications can’t access the IO space.
The
kernel should not worry about managing/sharing IO space between drivers. It
will be overhead. Kernel will manage a sparse tree for managing IO Space. A
driver can allocate IO Space from kernel. If a driver allocated a memory then
that range can’t be allocated by other drivers. If other drivers try to
allocate that range then that system call will fail. However there wont any
checking to control drivers to access only allocated space.

The
above picture explains all the drivers has full access to IO Space, however it
should access only the allocated IO Space.
Provision
should be added to share IO space between to drivers.
Kernel setups PIC/APIC to receive
interrupts; the default interrupt hander is a kernel stub function. These stub
function will call the real driver’s interrupt handler if one registered.
Drivers should register an entry
point for every interrupt request it is expecting and it should give priority
for the interrupt also. The driver is only responsible for completing IRQ for
the device. It should not send EOI to PIC. Kernel will send EOI to the PIC
before calling the registered handler. In this way, interrupts can be
distributed.

The
above picture explains, only kernel entry points can registered in IDT and
PIC/APIC are programmed only by kernel. Drivers even don’t send EOI to PIC.
When an interrupt occurs, the
currently running thread enters into kernel mode (kernel interrupt handlers)
and then checks whether any driver registered any handler for the raised IRQ,
if no handler is register, the interrupt is ignored. If a handler is registered
then the handler is waked up and a priority boost will be given to the driver
thread.
Here there should be a provision
should to switch to the driver and run the handler without full context switch.
Because full context switch might take longer time. To
achieve partially this, interrupt handlers code should not made pageable.
Boot
loader should capable of loading certain drivers during the boot of kernel. For
example- boot loader should load Storage and FS drivers during boot.