Sun Java Solaris Communities My SDN Account
 
White Paper

Endianness in the Solaris Operating Environment

 
  « Previous | Contents | Next »
 

Device Drivers and Endianness

The Issue

Sun's use of the PCI bus in some of its systems made it desirable for Sun to produce drivers for PCI devices for both Solaris (SPARC Platform Edition) and Solaris (Intel Platform Edition) from common sources. Achieving platform independence required addressing the problem of endianness, both in accesses to device registers and in the construction and reading of device data in memory, such as SCSI command and status packets. Doing so in a way that takes advantage of hardware assistance when it is available (for example, on UltraSPARC), but that also works when only software swapping is available, added to the challenge.

The Solaris Solution

The solution, introduced in Solaris?2.5, involves abstracting device register access and reading and writing of device data in memory.

Device Register Access

When mapping the registers of a device (using ddi_regs_map_setup(9F)), the driver writer provides as one of the arguments a device access attributes structure ( ddi_device_acc_attr(9S)), which specifies the characteristics of the data that the device expects. The ddi_regs_map_setup function returns an "access handle" (ddi_acc_handle_t) for use in subsequent data access function calls. The Solaris environment provides a full range of functions for accessing 8-, 16-, 32-, and 64-bit data, individually or in blocks. The access functions use the handle to transform the data as required. The driver does not need to know whether or not byte swapping is required, and if it is, whether it is accomplished by hardware or by software.

There are special functions for access to PCI configuration space. These functions know that the configuration space is little-endian, and they also know the platform-specific means of addressing configuration space.

Memory Data

A device driver writer allocates memory for DMA to and from devices using the ddi_dma_mem_alloc(9F) function. This function, like ddi_regs_map_setup, also takes a device access attributes structure as an argument and returns a handle for use in subsequent data accesses.


Note - Use the Solaris DDI when writing or porting device drivers to enable cross-platform, cross-endianness portability.


  « Previous | Contents | Next »
 

Oracle is reviewing the Sun product roadmap and will provide guidance to customers in accordance with Oracle's standard product communication policies. Any resulting features and timing of release of such features as determined by Oracle's review of roadmaps, are at the sole discretion of Oracle. All product roadmap information, whether communicated by Sun Microsystems or by Oracle, does not represent a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. It is intended for information purposes only, and may not be incorporated into any contract.