This lets scsi-disk avoid a bounce buffer. Signed-off-by: Paolo Bonzini <pbonz...@redhat.com> --- hw/scsi-bus.c | 16 ++++++++++++---- hw/scsi-disk.c | 21 ++++++++++++++++----- hw/scsi.h | 3 +++ 3 files changed, 31 insertions(+), 9 deletions(-)
diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c index 3b545ed..8e888e8 100644 --- a/hw/scsi-bus.c +++ b/hw/scsi-bus.c @@ -618,6 +618,8 @@ void scsi_req_unref(SCSIRequest *req) if (req->dev->info->free_req) { req->dev->info->free_req(req); } + qemu_iovec_reset(&req->qiov); + qemu_iovec_destroy(&req->qiov); qemu_free(req); } } @@ -634,13 +636,19 @@ void scsi_req_continue(SCSIRequest *req) } } -/* Called by the devices when data is ready for the HBA. The HBA should - start a DMA operation to read or fill the device's data buffer. - Once it completes, calling scsi_req_continue will restart I/O. */ +/* Called by the devices when data is ready for the HBA. Depending on + the transfer method it will call either unmap_iovec or transfer_data. + Execution of the command resumes when the HBA calls scsi_req_continue; + if applicable, the HBA should do so only after completing any DMA + operations involving the request buffer. */ void scsi_req_data(SCSIRequest *req, int len) { trace_scsi_req_data(req->dev->id, req->lun, req->tag, len); - req->bus->ops->transfer_data(req, len); + if (req->has_sg_list) { + req->bus->ops->unmap_iovec(req, len); + } else { + req->bus->ops->transfer_data(req, len); + } } void scsi_req_print(SCSIRequest *req) diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 4f5ba1c..e13b633 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -139,12 +139,23 @@ static uint32_t scsi_init_iovec(SCSIDiskReq *r) { SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev); - if (!r->iov.iov_base) { - r->buflen = SCSI_DMA_BUF_SIZE; - r->iov.iov_base = qemu_blockalign(s->bs, r->buflen); + qemu_iovec_reset(&r->req.qiov); + if (r->req.bus->ops->get_iovec) { + r->req.bus->ops->get_iovec(&r->req, r->sector_count * 512); + } + if (r->req.qiov.size) { + assert((r->req.qiov.size % 512) == 0); + r->req.has_sg_list = true; + } else { + if (!r->iov.iov_base) { + r->buflen = SCSI_DMA_BUF_SIZE; + r->iov.iov_base = qemu_blockalign(s->bs, r->buflen); + } + r->iov.iov_len = MIN(r->sector_count * 512, r->buflen); + qemu_iovec_destroy(&r->req.qiov); + qemu_iovec_init_external(&r->req.qiov, &r->iov, 1); + r->req.has_sg_list = false; } - r->iov.iov_len = MIN(r->sector_count * 512, r->buflen); - qemu_iovec_init_external(&r->req.qiov, &r->iov, 1); return r->req.qiov.size / 512; } diff --git a/hw/scsi.h b/hw/scsi.h index b551b57..9627404 100644 --- a/hw/scsi.h +++ b/hw/scsi.h @@ -35,6 +35,7 @@ struct SCSIRequest { uint32_t tag; uint32_t lun; uint32_t status; + bool has_sg_list; struct { uint8_t buf[SCSI_CMD_BUF_SIZE]; int len; @@ -82,6 +83,8 @@ struct SCSIBusOps { void (*transfer_data)(SCSIRequest *req, uint32_t arg); void (*complete)(SCSIRequest *req, uint32_t arg); void (*cancel)(SCSIRequest *req); + void (*get_iovec)(SCSIRequest *req, uint64_t len); + void (*unmap_iovec)(SCSIRequest *req, uint64_t len); }; struct SCSIBus { -- 1.7.4.4