diff options
author | Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> | 2021-03-04 22:10:30 +0000 |
---|---|---|
committer | Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> | 2021-03-07 10:39:05 +0000 |
commit | c47b5835f5b8f971b10ecf5965117ffa3500d0ce (patch) | |
tree | 38093ea3ac5e1cb7addc1dd8881e777324aaa71a /hw/scsi | |
parent | 4ca2ba6fb0bdf1099a742a361d1e2ad227c3bbf4 (diff) |
esp: introduce esp_get_tc() and esp_set_tc()
These functions simplify reading and writing the TC register value without having to
manually shift each individual 8-bit value.
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20210304221103.6369-10-mark.cave-ayland@ilande.co.uk>
Diffstat (limited to 'hw/scsi')
-rw-r--r-- | hw/scsi/esp.c | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c index 5365523f6b..dd94f7b47b 100644 --- a/hw/scsi/esp.c +++ b/hw/scsi/esp.c @@ -98,6 +98,24 @@ void esp_request_cancelled(SCSIRequest *req) } } +static uint32_t esp_get_tc(ESPState *s) +{ + uint32_t dmalen; + + dmalen = s->rregs[ESP_TCLO]; + dmalen |= s->rregs[ESP_TCMID] << 8; + dmalen |= s->rregs[ESP_TCHI] << 16; + + return dmalen; +} + +static void esp_set_tc(ESPState *s, uint32_t dmalen) +{ + s->rregs[ESP_TCLO] = dmalen; + s->rregs[ESP_TCMID] = dmalen >> 8; + s->rregs[ESP_TCHI] = dmalen >> 16; +} + static void set_pdma(ESPState *s, enum pdma_origin_id origin, uint32_t index, uint32_t len) { @@ -157,9 +175,7 @@ static uint32_t get_cmd(ESPState *s, uint8_t *buf, uint8_t buflen) target = s->wregs[ESP_WBUSID] & BUSID_DID; if (s->dma) { - dmalen = s->rregs[ESP_TCLO]; - dmalen |= s->rregs[ESP_TCMID] << 8; - dmalen |= s->rregs[ESP_TCHI] << 16; + dmalen = esp_get_tc(s); if (dmalen > buflen) { return 0; } @@ -348,9 +364,7 @@ static void esp_dma_done(ESPState *s) s->rregs[ESP_RINTR] = INTR_BS; s->rregs[ESP_RSEQ] = 0; s->rregs[ESP_RFLAGS] = 0; - s->rregs[ESP_TCLO] = 0; - s->rregs[ESP_TCMID] = 0; - s->rregs[ESP_TCHI] = 0; + esp_set_tc(s, 0); esp_raise_irq(s); } @@ -535,9 +549,7 @@ static void handle_ti(ESPState *s) return; } - dmalen = s->rregs[ESP_TCLO]; - dmalen |= s->rregs[ESP_TCMID] << 8; - dmalen |= s->rregs[ESP_TCHI] << 16; + dmalen = esp_get_tc(s); if (dmalen == 0) { dmalen = 0x10000; } @@ -888,9 +900,7 @@ static void sysbus_esp_pdma_write(void *opaque, hwaddr addr, trace_esp_pdma_write(size); - dmalen = s->rregs[ESP_TCLO]; - dmalen |= s->rregs[ESP_TCMID] << 8; - dmalen |= s->rregs[ESP_TCHI] << 16; + dmalen = esp_get_tc(s); if (dmalen == 0 || s->pdma_len == 0) { return; } @@ -907,9 +917,7 @@ static void sysbus_esp_pdma_write(void *opaque, hwaddr addr, dmalen -= 2; break; } - s->rregs[ESP_TCLO] = dmalen & 0xff; - s->rregs[ESP_TCMID] = dmalen >> 8; - s->rregs[ESP_TCHI] = dmalen >> 16; + esp_set_tc(s, dmalen); if (s->pdma_len == 0 && s->pdma_cb) { esp_lower_drq(s); s->pdma_cb(s); |