esp: move pdma_len and TC logic into esp_pdma_read()/esp_pdma_write()

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-18-mark.cave-ayland@ilande.co.uk>
This commit is contained in:
Mark Cave-Ayland 2021-03-04 22:10:38 +00:00
parent 6e3fafa8bb
commit 8da90e8194

View File

@ -153,22 +153,45 @@ static uint8_t *get_pdma_buf(ESPState *s)
static uint8_t esp_pdma_read(ESPState *s) static uint8_t esp_pdma_read(ESPState *s)
{ {
uint32_t dmalen = esp_get_tc(s);
uint8_t val;
if (dmalen == 0 || s->pdma_len == 0) {
return 0;
}
switch (s->pdma_origin) { switch (s->pdma_origin) {
case PDMA: case PDMA:
return s->pdma_buf[s->pdma_cur++]; val = s->pdma_buf[s->pdma_cur++];
break;
case TI: case TI:
return s->ti_buf[s->pdma_cur++]; val = s->ti_buf[s->pdma_cur++];
break;
case CMD: case CMD:
return s->cmdbuf[s->pdma_cur++]; val = s->cmdbuf[s->pdma_cur++];
break;
case ASYNC: case ASYNC:
return s->async_buf[s->pdma_cur++]; val = s->async_buf[s->pdma_cur++];
break;
default: default:
g_assert_not_reached(); g_assert_not_reached();
} }
s->pdma_len--;
dmalen--;
esp_set_tc(s, dmalen);
return val;
} }
static void esp_pdma_write(ESPState *s, uint8_t val) static void esp_pdma_write(ESPState *s, uint8_t val)
{ {
uint32_t dmalen = esp_get_tc(s);
if (dmalen == 0 || s->pdma_len == 0) {
return;
}
switch (s->pdma_origin) { switch (s->pdma_origin) {
case PDMA: case PDMA:
s->pdma_buf[s->pdma_cur++] = val; s->pdma_buf[s->pdma_cur++] = val;
@ -185,6 +208,10 @@ static void esp_pdma_write(ESPState *s, uint8_t val)
default: default:
g_assert_not_reached(); g_assert_not_reached();
} }
s->pdma_len--;
dmalen--;
esp_set_tc(s, dmalen);
} }
static int get_cmd_cb(ESPState *s) static int get_cmd_cb(ESPState *s)
@ -944,27 +971,18 @@ static void sysbus_esp_pdma_write(void *opaque, hwaddr addr,
{ {
SysBusESPState *sysbus = opaque; SysBusESPState *sysbus = opaque;
ESPState *s = ESP(&sysbus->esp); ESPState *s = ESP(&sysbus->esp);
uint32_t dmalen = esp_get_tc(s);
trace_esp_pdma_write(size); trace_esp_pdma_write(size);
if (dmalen == 0 || s->pdma_len == 0) {
return;
}
switch (size) { switch (size) {
case 1: case 1:
esp_pdma_write(s, val); esp_pdma_write(s, val);
s->pdma_len--;
dmalen--;
break; break;
case 2: case 2:
esp_pdma_write(s, val >> 8); esp_pdma_write(s, val >> 8);
esp_pdma_write(s, val); esp_pdma_write(s, val);
s->pdma_len -= 2;
dmalen -= 2;
break; break;
} }
esp_set_tc(s, dmalen);
if (s->pdma_len == 0 && s->pdma_cb) { if (s->pdma_len == 0 && s->pdma_cb) {
esp_lower_drq(s); esp_lower_drq(s);
s->pdma_cb(s); s->pdma_cb(s);
@ -988,17 +1006,13 @@ static uint64_t sysbus_esp_pdma_read(void *opaque, hwaddr addr,
switch (size) { switch (size) {
case 1: case 1:
val = esp_pdma_read(s); val = esp_pdma_read(s);
s->pdma_len--;
dmalen--;
break; break;
case 2: case 2:
val = esp_pdma_read(s); val = esp_pdma_read(s);
val = (val << 8) | esp_pdma_read(s); val = (val << 8) | esp_pdma_read(s);
s->pdma_len -= 2;
dmalen -= 2;
break; break;
} }
esp_set_tc(s, dmalen); dmalen = esp_get_tc(s);
if (dmalen == 0 || (s->pdma_len == 0 && s->pdma_cb)) { if (dmalen == 0 || (s->pdma_len == 0 && s->pdma_cb)) {
esp_lower_drq(s); esp_lower_drq(s);
s->pdma_cb(s); s->pdma_cb(s);