[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 03/88] esp.c: add FIFO wraparound support to esp_fifo_pop_buf()
|
From: |
Mark Cave-Ayland |
|
Subject: |
[PATCH 03/88] esp.c: add FIFO wraparound support to esp_fifo_pop_buf() |
|
Date: |
Fri, 12 Jan 2024 12:52:55 +0000 |
The fifo8_pop_buf() function returns a pointer to the FIFO buffer up to the
specified length. Since the FIFO buffer is modelled as an array then once
the FIFO wraps around, only the continuous portion of the buffer can be
returned.
In future the use of continuous and unaligned accesses will advance the
internal FIFO head pointer, so modify esp_fifo_pop_buf() to ensure that
any wraparound content is also returned up to the requested length.
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
hw/scsi/esp.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c
index b382865426..8d8f6a817a 100644
--- a/hw/scsi/esp.c
+++ b/hw/scsi/esp.c
@@ -121,17 +121,30 @@ static uint8_t esp_fifo_pop(Fifo8 *fifo)
static uint32_t esp_fifo_pop_buf(Fifo8 *fifo, uint8_t *dest, int maxlen)
{
const uint8_t *buf;
- uint32_t n;
+ uint32_t n, n2;
+ int len;
if (maxlen == 0) {
return 0;
}
- buf = fifo8_pop_buf(fifo, maxlen, &n);
+ len = maxlen;
+ buf = fifo8_pop_buf(fifo, len, &n);
if (dest) {
memcpy(dest, buf, n);
}
+ /* Add FIFO wraparound if needed */
+ len -= n;
+ len = MIN(len, fifo8_num_used(fifo));
+ if (len) {
+ buf = fifo8_pop_buf(fifo, len, &n2);
+ if (dest) {
+ memcpy(&dest[n], buf, n2);
+ }
+ n += n2;
+ }
+
return n;
}
--
2.39.2
- [PATCH 00/88] esp: rework ESP emulation to use a SCSI phase-based state machine, Mark Cave-Ayland, 2024/01/12
- [PATCH 02/88] esp: move existing request cancel check into esp_select(), Mark Cave-Ayland, 2024/01/12
- [PATCH 04/88] esp: remove FIFO clear from esp_select(), Mark Cave-Ayland, 2024/01/12
- [PATCH 06/88] esp: update esp_set_tc() to set STAT_TC flag, Mark Cave-Ayland, 2024/01/12
- [PATCH 05/88] esp: move esp_select() to ESP selection commands from get_cmd(), Mark Cave-Ayland, 2024/01/12
- [PATCH 01/88] esp: don't clear cmdfifo when esp_select() fails in get_cmd(), Mark Cave-Ayland, 2024/01/12
- [PATCH 03/88] esp.c: add FIFO wraparound support to esp_fifo_pop_buf(),
Mark Cave-Ayland <=
- [PATCH 07/88] esp: start removal of manual STAT_TC setting when transfer counter reaches zero, Mark Cave-Ayland, 2024/01/12
- [PATCH 08/88] esp: move command execution logic to new esp_run_cmd() function, Mark Cave-Ayland, 2024/01/12
- [PATCH 09/88] esp: update TC check logic in do_dma_pdma_cb() to check for TC == 0, Mark Cave-Ayland, 2024/01/12
- [PATCH 10/88] esp: move buffer and TC logic into separate to/from device paths in esp_do_dma(), Mark Cave-Ayland, 2024/01/12
- [PATCH 11/88] esp.c: remove unused case from esp_pdma_read(), Mark Cave-Ayland, 2024/01/12
- [PATCH 12/88] esp.c: don't accumulate directly into cmdfifo, Mark Cave-Ayland, 2024/01/12
- [PATCH 13/88] esp.c: decrement the TC during MESSAGE OUT and COMMAND phases, Mark Cave-Ayland, 2024/01/12
- [PATCH 14/88] esp.c: introduce esp_set_phase() helper function, Mark Cave-Ayland, 2024/01/12
- [PATCH 15/88] esp.c: remove another set of manual STAT_TC updates, Mark Cave-Ayland, 2024/01/12
- [PATCH 16/88] esp.c: remove MacOS TI workaround that pads FIFO transfers to ESP_FIFO_SZ, Mark Cave-Ayland, 2024/01/12