Specifications
Understanding the Kernel Environmen
t
9-15
ready to manage its own allocation and deallocation requests. This is done by indexing the
memory units in the map structure and calling rmalloc() and rmfree(), respectively.
(Note that rmfree() calls have different meanings depending on the context in which
they are made; the first call to rmfree() is used to add space to the map. After the first
call to rmalloc() occurs, rmfree() is used to return memory space to the map.)
Once the driver has finished using its own private memory pool, it can free the map by
calling rmfreemap(). The memory pool must still be deallocated via a call to
kmem_free(). For an example showing the use of these routines, refer to the
rmalloc(D3) entry in the on-line Device Driver Reference.
Memory Access Routines 9
On the Series 6000, Power Hawk, and PowerMAXION platforms, all I/O hardware is
memory mapped. To communicate with this hardware, the device driver, which is execut-
ing within the kernel address space, must first map a portion of kernel virtual memory onto
the physical address range of the controller’s registers or memory.
The kernel provides the following routines for this purpose:
physmap(D3) Allocate a virtual address mapping for a specified range of
physical addresses
physmap_free(D3) Free a virtual address mapping allocated by physmap()
Once this is done, the driver communicates with the controller by addressing memory
within the mapped range. The physmap() routine is generally used from a driver’s
init() or start() routine to obtain a pointer to the device memory. It returns a virtual
address or NULL if the mapping cannot be allocated. Generally, the physmap_free()
routine is never called because device drivers keep the mapping forever. It is provided in
case a driver dynamically allocates mappings. The number of bytes specified on the call to
physmap_free() must be identical to the number of bytes specified on the call to
physmap().
During the system initialization, the system calls the init(D2) entry point of the device
driver. This entry point must probe for the hardware device at its configured address to
determine whether it is present. The kernel provides a special routine for probing and
detecting devices called badaddr(), which must be used for that purpose.
badaddr() probes a virtual address by reading or writing a byte/word/longword to this
location. The length of the access can be a byte, a word, or a longword. The badaddr
routine returns TRUE if accessing the specified address causes a bus error; otherwise, it
must return FALSE. Note that on a Series 6000 platform, accessing an invalid I/O address
causes a machine check exception and a sysfault interrupt.
Address Management Routines 9
The kernel provides the following address management routines:
btop(D3) Convert size in bytes to size in pages (round down)