d_cflush Kernel Service

Purpose

Flushes the processor and I/O channel controller (IOCC) data caches when mapping bus device DMA with the long-term DMA_WRITE_ONLY option.

Syntax

int d_cflush (channel_id, baddr, count, daddr)
int   channel_id;
caddr_t   baddr;
size_t   count;
caddr_t   daddr;

Parameters

Item Description
channel_id Specifies the DMA channel ID returned by the d_init kernel service.
baddr Designates the address of the memory buffer.
count Specifies the length of the memory buffer transfer in bytes.
daddr Designates the address of the device corresponding to the transfer.

Description

The d_cflush kernel service should be called after data has been modified in a buffer that will undergo direct memory access (DMA) processing. Through DMA processing, this data is sent to a device where the d_master kernel service with the DMA_WRITE_ONLY option has already mapped the buffer for device DMA. The d_cflush kernel service is not required if the DMA_WRITE_ONLY option is not used or if the buffer is mapped before each DMA operation by calling the d_master kernel service.

The d_cflush kernel service flushes the processor cache for the involved cache lines and invalidates any previously retrieved data that may be in the IOCC buffers for the designated channel. This most frequently occurs when using long-term buffer mapping for DMA support to or from a device.

Long-Term DMA Buffer Mapping

The long-term DMA buffer mapping approach is frequently used when a pool of buffers is defined for sending commands and obtaining responses from an adapter using bus master DMA. This approach is also used frequently in the communications field where buffers can come from a common pool such as the mbuf pool or a pool used for protocol headers.

When using a fixed pool of buffers, the d_master kernel service is used only once to map the pool's address and range. The device driver then modifies the data in the buffers. It must also flush the data from the processor and invalidate the IOCC data cache involved in transfers with the device. The IOCC cache must be invalidated because the data in the IOCC data cache may be stale due to the last DMA operation to or from the buffer area that has just been modified for the next operation.

The d_cflush kernel service permits the flushing of the processor cache and making the required IOCC cache not valid. The device driver should use this service after modifying the data in the buffer and before sending the command to the device to start the DMA operation.

Once DMA processing has been completed, the device driver should call the d_complete service to check for errors and ensure that any data read from the device has been flushed to memory.

Note: The d_cflush kernel service is not supported on the 64-bit kernel.

Execution Environment

The d_cflush kernel service can be called from either the process or interrupt environment.

Return Values

Item Description
0 Indicates that the transfer was successfully completed.
EINVAL Indicates the presence of an invalid parameter.