From e1e00c951b4c87584c144f6077737314f50a714a Mon Sep 17 00:00:00 2001 From: joevt Date: Sun, 10 Mar 2024 21:10:40 -0700 Subject: [PATCH] sc53c94: Split real_dma_xfer. Create real_dma_xfer_out and real_dma_xfer_in methods. --- devices/common/scsi/sc53c94.cpp | 59 +++++++++++++++++---------------- devices/common/scsi/sc53c94.h | 3 +- devices/ioctrl/amic.cpp | 5 ++- 3 files changed, 37 insertions(+), 30 deletions(-) diff --git a/devices/common/scsi/sc53c94.cpp b/devices/common/scsi/sc53c94.cpp index 07dbac0..e883cd5 100644 --- a/devices/common/scsi/sc53c94.cpp +++ b/devices/common/scsi/sc53c94.cpp @@ -632,20 +632,38 @@ bool Sc53C94::rcv_data() return true; } -void Sc53C94::real_dma_xfer(int direction) +void Sc53C94::real_dma_xfer_out() +{ + // transfer data from host's memory to target + + while (this->xfer_count) { + uint32_t got_bytes; + uint8_t* src_ptr; + this->dma_ch->pull_data(std::min((int)this->xfer_count, DATA_FIFO_MAX), + &got_bytes, &src_ptr); + std::memcpy(this->data_fifo, src_ptr, got_bytes); + this->data_fifo_pos = got_bytes; + this->bus_obj->push_data(this->target_id, this->data_fifo, this->data_fifo_pos); + + this->xfer_count -= this->data_fifo_pos; + this->data_fifo_pos = 0; + if (!this->xfer_count) { + this->status |= STAT_TC; // signal zero transfer count + this->cur_state = SeqState::XFER_END; + this->sequencer(); + } + } +} + +void Sc53C94::real_dma_xfer_in() { bool is_done = false; - if (direction) { - uint32_t got_bytes; - uint8_t* src_ptr; + // transfer data from target to host's memory - while (this->xfer_count) { - this->dma_ch->pull_data(std::min((int)this->xfer_count, DATA_FIFO_MAX), - &got_bytes, &src_ptr); - std::memcpy(this->data_fifo, src_ptr, got_bytes); - this->data_fifo_pos = got_bytes; - this->bus_obj->push_data(this->target_id, this->data_fifo, this->data_fifo_pos); + while (this->xfer_count) { + if (this->data_fifo_pos) { + this->dma_ch->push_data((char*)this->data_fifo, this->data_fifo_pos); this->xfer_count -= this->data_fifo_pos; this->data_fifo_pos = 0; @@ -656,25 +674,10 @@ void Sc53C94::real_dma_xfer(int direction) this->sequencer(); } } - } else { // transfer data from target to host's memory - while (this->xfer_count) { - if (this->data_fifo_pos) { - this->dma_ch->push_data((char*)this->data_fifo, this->data_fifo_pos); - this->xfer_count -= this->data_fifo_pos; - this->data_fifo_pos = 0; - if (!this->xfer_count) { - is_done = true; - this->status |= STAT_TC; // signal zero transfer count - this->cur_state = SeqState::XFER_END; - this->sequencer(); - } - } - - // see if we need to refill FIFO - if (!this->data_fifo_pos && !is_done) { - this->sequencer(); - } + // see if we need to refill FIFO + if (!this->data_fifo_pos && !is_done) { + this->sequencer(); } } } diff --git a/devices/common/scsi/sc53c94.h b/devices/common/scsi/sc53c94.h index 2711baa..da4ab80 100644 --- a/devices/common/scsi/sc53c94.h +++ b/devices/common/scsi/sc53c94.h @@ -207,7 +207,8 @@ public: void pseudo_dma_write(uint16_t data); // real DMA control - void real_dma_xfer(int direction); + void real_dma_xfer_out(); + void real_dma_xfer_in(); void set_dma_channel(DmaBidirChannel *dma_ch) { this->dma_ch = dma_ch; diff --git a/devices/ioctrl/amic.cpp b/devices/ioctrl/amic.cpp index 11f689b..d8a9882 100644 --- a/devices/ioctrl/amic.cpp +++ b/devices/ioctrl/amic.cpp @@ -384,7 +384,10 @@ void AMIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) } if (value & 2) { // RUN bit set? this->curio_dma->reinit(this->scsi_dma_base); - this->scsi->real_dma_xfer((value >> 6) & 1); + if (value & (1 << 6)) + this->scsi->real_dma_xfer_out(); + else + this->scsi->real_dma_xfer_in(); } this->curio_dma->write_ctrl(value); break;