## Physical Device Driver Reference

[prev][next][parent][TOC]

### Memory Management

The physical device driver must manage addressability to data across task- time and interrupt-time operations. DevHlp services are provided to allow the physical device driver to be independent of the CPU mode, whether at task time or interrupt time. Addressability is particularly critical at interrupt time because the context of the current process might not cover the address space containing the data buffer that the hardware interrupt handler needs to access in order to move data.

To prevent an application from passing an unauthorized address, the physical device driver can use the DevHlp_VerifyAccess to validate the application's authority to access the memory. Because physical device drivers execute at the operating system privilege level (Ring 0), they have access rights to segments at all privilege levels. However, a well- balanced device driver must not allow an application to force it into accessing segments the application does not own. This check applies to addresses an application passes within a generic IOCtl request; the OS/2 kernel validates addresses for READ and WRITE requests. If an application passes a bad address to the physical device driver, the physical device driver could cause a system halt if it does not verify the caller's access authority. Once an address has been verified, the physical device driver can proceed with the I/O request.

The DevHlp services Lock and Unlock are used to fix a segment in place, which prevents the segment from being removed or swapped while the physical device driver needs access to it. The physical device driver does not need to lock segments for the READ or WRITE request packets. However, segments referenced in the generic IOCtl request packet need to be locked by the physical device driver, if it intends to access those segments at interrupt time.

Once a segment has been locked, the physical device driver can convert the virtual address into a physical address with the DevHlp_VirtToPhys, for later use at interrupt time.

The DevHlps AllocPhys and FreePhys allow the physical device driver to allocate and free a fixed amount of memory. The physical device driver must use the DevHlp_PhysToVirt, DevHlp_PhysToGDTSelector, or DevHlp_ PageListToLin to obtain a virtual address to access the memory.