FreeBSD/sys/kern/subr_bus_dma.c
/*
 * Load a cam control block.
 */
Load a cam control block.
Load a cam control block .
static int
_bus_dmamap_load_ccb(bus_dma_tag_t dmat, bus_dmamap_t map, union ccb *ccb,
		    int *nsegs, int flags)
{
	struct ccb_hdr *ccb_h;
	void *data_ptr;
	int error;
	uint32_t dxfer_len;
	uint16_t sglist_cnt;
	error = 0;
	ccb_h = &ccb->ccb_h;
	switch (ccb_h->func_code) {
	case XPT_SCSI_IO: {
		struct ccb_scsiio *csio;
		csio = &ccb->csio;
		data_ptr = csio->data_ptr;
		dxfer_len = csio->dxfer_len;
		sglist_cnt = csio->sglist_cnt;
		break;
	}
	case XPT_CONT_TARGET_IO: {
		struct ccb_scsiio *ctio;
		ctio = &ccb->ctio;
		data_ptr = ctio->data_ptr;
		dxfer_len = ctio->dxfer_len;
		sglist_cnt = ctio->sglist_cnt;
		break;
	}
	case XPT_ATA_IO: {
		struct ccb_ataio *ataio;
		ataio = &ccb->ataio;
		data_ptr = ataio->data_ptr;
		dxfer_len = ataio->dxfer_len;
		sglist_cnt = 0;
		break;
	}
	default:
		panic("_bus_dmamap_load_ccb: Unsupported func code %d",
		    ccb_h->func_code);
	}
	switch ((ccb_h->flags & CAM_DATA_MASK)) {
	case CAM_DATA_VADDR:
		error = _bus_dmamap_load_buffer(dmat, map, data_ptr, dxfer_len,
		    kernel_pmap, flags, NULL, nsegs);
		break;
	case CAM_DATA_PADDR:
		error = _bus_dmamap_load_phys(dmat, map,
		    (vm_paddr_t)(uintptr_t)data_ptr, dxfer_len, flags, NULL,
		    nsegs);
		break;
	case CAM_DATA_SG:
		error = _bus_dmamap_load_vlist(dmat, map,
		    (bus_dma_segment_t *)data_ptr, sglist_cnt, kernel_pmap,
		    nsegs, flags, 0, dxfer_len);
		break;
	case CAM_DATA_SG_PADDR:
		error = _bus_dmamap_load_plist(dmat, map,
		    (bus_dma_segment_t *)data_ptr, sglist_cnt, nsegs, flags);
		break;
	case CAM_DATA_BIO:
		error = _bus_dmamap_load_bio(dmat, map, (struct bio *)data_ptr,
		    nsegs, flags);
		break;
	default:
		panic("_bus_dmamap_load_ccb: flags 0x%X unimplemented",
		    ccb_h->flags);
	}
	return (error);
}
static int _bus_dmamap_load_ccb ( bus_dma_tag_t dmat , bus_dmamap_t map , union ccb * ccb , int * nsegs , int flags ) { struct ccb_hdr * ccb_h ; void * data_ptr ; int error ; uint32_t dxfer_len ; uint16_t sglist_cnt ; error = 0 ; ccb_h = & ccb -> ccb_h ; switch ( ccb_h -> func_code ) { case XPT_SCSI_IO : { struct ccb_scsiio * csio ; csio = & ccb -> csio ; data_ptr = csio -> data_ptr ; dxfer_len = csio -> dxfer_len ; sglist_cnt = csio -> sglist_cnt ; break ; } case XPT_CONT_TARGET_IO : { struct ccb_scsiio * ctio ; ctio = & ccb -> ctio ; data_ptr = ctio -> data_ptr ; dxfer_len = ctio -> dxfer_len ; sglist_cnt = ctio -> sglist_cnt ; break ; } case XPT_ATA_IO : { struct ccb_ataio * ataio ; ataio = & ccb -> ataio ; data_ptr = ataio -> data_ptr ; dxfer_len = ataio -> dxfer_len ; sglist_cnt = 0 ; break ; } default : panic ( " " , ccb_h -> func_code ) ; } switch ( ( ccb_h -> flags & CAM_DATA_MASK ) ) { case CAM_DATA_VADDR : error = _bus_dmamap_load_buffer ( dmat , map , data_ptr , dxfer_len , kernel_pmap , flags , NULL , nsegs ) ; break ; case CAM_DATA_PADDR : error = _bus_dmamap_load_phys ( dmat , map , ( vm_paddr_t ) ( uintptr_t ) data_ptr , dxfer_len , flags , NULL , nsegs ) ; break ; case CAM_DATA_SG : error = _bus_dmamap_load_vlist ( dmat , map , ( bus_dma_segment_t * ) data_ptr , sglist_cnt , kernel_pmap , nsegs , flags , 0 , dxfer_len ) ; break ; case CAM_DATA_SG_PADDR : error = _bus_dmamap_load_plist ( dmat , map , ( bus_dma_segment_t * ) data_ptr , sglist_cnt , nsegs , flags ) ; break ; case CAM_DATA_BIO : error = _bus_dmamap_load_bio ( dmat , map , ( struct bio * ) data_ptr , nsegs , flags ) ; break ; default : panic ( " " , ccb_h -> flags ) ; } return ( error ) ; }
Load a cam control block.
Load a cam control block .