Hardware Access

The minidriver program most likely requires hardware access, meaning it needs to read and write hardware registers. In order to access hardware registers, the startup library provides function calls to map and unmap physical memory.

When the minidriver handler is called with MDRIVER_STARTUP_INIT, you call:

uintptr_t startup_io_map(size, phys_addr);
startup_io_unmap(paddr);
void * startup_memory_map(size, phys_addr);
startup_memory_unmap(paddr);

After the minidriver handler is called with MDRIVER_STARTUP_PREPARE, the above functions are no longer available and your driver must use:

uintptr_t callout_io_map(size, phys_addr);
void * callout_memory_map(size, phys_addr);

At different times in the boot process, some calls may or may not be available. If your driver requires hardware access, it must do the following:

MDRIVER_INIT
MDRIVER_STARTUP
Use the stored pointer, ptr1, to do all hardware access. No memory map calls are needed.
MDRIVER_STARTUP_PREPARE
At this point, it's safe to call callout_io_map() or callout_memory_map(), but don't use the pointer returned.

The minidriver should call one of the above functions and store the pointer in the minidriver data area or in a static variable, separate from the previously stored value (ptr2). Use the stored pointer, ptr1, to do all hardware access.

MDRIVER_STARTUP_FINI
Use the stored pointer, ptr1, to do all hardware access. Any further calls will require the minidriver to use the pointer mapped with callout_io_map() or callout_memory_map() mapped pointer, so your driver must maintain this information in the data area.
MDRIVER_KERNEL
Use the stored pointer, ptr2, to do all hardware access.
MDRIVER_PROCESS
Use the stored pointer, ptr2, to do all hardware access.
MDRIVER_INTR_ATTACH
Use the stored pointer, ptr2, to do all hardware access.