SEC 2.0 Reference Device Driver User’s Guide, Rev. 0
Freescale Semiconductor PRELIMINARY—SUBJECT TO CHANGE WITHOUT NOTICE 13
User Interface
scatter-composed, as opposed to direct, contiguous memory (for instance, key data could be in contiguous system
memory, while ciphertext data will be in fragmented user memory).
A problem with marking buffers using this method is that there is no means for the caller to clearly identify which
bit in scatterBufs matches any given pointer in the request, since the data description portion of different requests
cannot be consistent or of any particular order.
A helper function, MarkScatterBuffer(), is therefore made available by the driver to make the bit/pointer
association logic in the driver accessible to the caller. It's form is:
MarkScatterBuffer(void *r equest, void *buffer);
where request points to the request block being built (the opId element must be set prior to call), and buffer
points to the element within the request which references a scattered buffer. It wil l then mark the necessary bit in
scatterBufs that defines this buffer for this sp ecific request type.
3.3.7.3 Direct Scatter-Gather Usage Example
In order to make this usage clear, an example is presented. Assume that a triple DES encryption operation is to be
constructed, where the input and output buf fers are located in fragmented user memory, a nd the cipher keys and IV
are contained in system memory. A DES_LOADCTX_CRYPT_REQ is zero-allocated as encReq, and construc ted:
/* set up encryption operation */
encReq.opId = DPD_TDES_CBC_CTX_ENCRY PT;
encReq.notify = notifier;
encReq.notify_on_error = not ifier;
encReq.inIvBytes = 8;
encReq.keyBytes = 24;
encReq.inBytes = bufsize;
encReq.inIvData = iv;
encReq.keyData = cipherKey;
encReq.inData = (unsigned char *)input; /* thi s buffer is scattered */
encReq.outIvBytes = 8;
encReq.outIvData = ctx;
encReq.outData = (unsigned char *)outpu t; /* this buffer is sc attered */
MarkScatterBuffer(&encR eq, &encReq.input);
MarkScatterBuffer(&encR eq, &encReq.output);
Upon completion of the two mark calls, encReq.scatterBufs will have two bits set within it that the driver
knows how to interpret as meaning that the intended buffers have scatter lists defined for them, and will process
them accordingly as the DPD is built for the hardware.