yuuzi41
yuuzi41

Reputation: 11

How to access physical address from a DriverKit driver?

Now I am trying to write an IOUserSCSIParallelInterfaceController driver which uses neither DMA nor PCI and emulates a SCSI target.

I realized that fBufferIOVMAddr ( https://developer.apple.com/documentation/scsicontrollerdriverkit/scsiuserparalleltask/3555105-fbufferiovmaddr ) in SCSIUserParallelTask struct given via UserProcessParallelTask method indicates a physical address and it couldn't be used as a memory address in the driver's memory space.

I need my driver to write something to the buffer and read something from the buffer because I want to make a SCSI Communication by my driver codes.

Is there any way to access memory in physical address from a DriverKit driver?

Upvotes: 1

Views: 474

Answers (1)

erich
erich

Reputation: 1

#if ARCMSR_DEBUG_UserGetDataBuffer
    if(pCCB->arcmsr_request.Cdb[0]==0xA0)/*SCSI_CMD_REPORT_LUN*/
    {
        IOBufferMemoryDescriptor *osdatabuffer = nullptr;
        uint64_t address, len, length=pCCB->request_transfer_count; /* parallelTask.fRequestedTransferCount */

        /*
        ******************************************************************************************************************************************
        **
        ** virtual kern_return_t UserGetDataBuffer(SCSIDeviceIdentifier fTargetID, uint64_t fControllerTaskIdentifier, IOBufferMemoryDescriptor **osdatabuffer);
        **
        ******************************************************************************************************************************************
        */
        if((UserGetDataBuffer(fTargetID, pCCB->fControllerTaskIdentifier, &osdatabuffer) != kIOReturnSuccess) || (osdatabuffer == NULL))
        {
            arcmsr_debug_print("ArcMSRUserSpaceDriver %d: ************************************************************************************ \n",ivars->adapter_index);
            arcmsr_debug_print("ArcMSRUserSpaceDriver %d: ** Get task data buffer error, ftargetID=%d fControllerTaskIdentifier=%d             \n",ivars->adapter_index,(int)fTargetID,(int)pCCB->fControllerTaskIdentifier);
            arcmsr_debug_print("ArcMSRUserSpaceDriver %d: ************************************************************************************ \n",ivars->adapter_index);            
            goto command_completion;
        }
        if((osdatabuffer->Map(0, 0, 0, 0, &address, &len) != kIOReturnSuccess) || (length != len))
        {
            arcmsr_debug_print("ArcMSRUserSpaceDriver %d: ************************************************************************************ \n",ivars->adapter_index);
            arcmsr_debug_print("ArcMSRUserSpaceDriver %d: ** Map task data buffer error, ftargetID=%d fControllerTaskIdentifier=%d             \n",ivars->adapter_index,(int)fTargetID,(int)pCCB->fControllerTaskIdentifier);
            arcmsr_debug_print("ArcMSRUserSpaceDriver %d: ************************************************************************************ \n",ivars->adapter_index);            
            goto command_completion;
        }
        /*
        *******************************************************************************************************************
        ** The LUN LIST LENGTH field shall contain the length in bytes of the LUN list that is available to be transferred.
        ** The LUN list length is the number of logical unit numbers in the logical unit inventory multiplied by eight.
        *******************************************************************************************************************
        */
        memset((void *)(address+3),8,1);     /* report_lun_data */
        memset((void *)(address+8),0,8);     /* first lun       */
        response.fBytesTransferred = 16;
    }
#endif

Upvotes: 0

Related Questions