From d7ebca748e33176ede1a8675cea82271d2c0dac4 Mon Sep 17 00:00:00 2001 From: Philippe Mathieu-Daudé Date: Sun, 5 Jul 2020 23:22:10 +0200 Subject: hw/sd/pxa2xx_mmci: Do not create SD card within the SD host controller MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SD/MMC host controllers provide a SD Bus to plug SD cards, but don't come with SD card plugged in :) The machine/board object is where the SD cards are created. Since the PXA2xx is not qdevified, for now create the cards in pxa270_init() which is the SoC model. In the future we will move this to the board model. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Alistair Francis Reviewed-by: Peter Maydell Acked-by: Peter Maydell Message-Id: <20200705213350.24725-2-f4bug@amsat.org> --- include/hw/arm/pxa.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'include') diff --git a/include/hw/arm/pxa.h b/include/hw/arm/pxa.h index 8843e5f910..d99b6192da 100644 --- a/include/hw/arm/pxa.h +++ b/include/hw/arm/pxa.h @@ -89,8 +89,7 @@ void pxa2xx_lcd_vsync_notifier(PXA2xxLCDState *s, qemu_irq handler); typedef struct PXA2xxMMCIState PXA2xxMMCIState; PXA2xxMMCIState *pxa2xx_mmci_init(MemoryRegion *sysmem, hwaddr base, - BlockBackend *blk, qemu_irq irq, - qemu_irq rx_dma, qemu_irq tx_dma); + qemu_irq irq, qemu_irq rx_dma, qemu_irq tx_dma); void pxa2xx_mmci_handlers(PXA2xxMMCIState *s, qemu_irq readonly, qemu_irq coverswitch); -- cgit 1.4.1 From 38626a33145aa71b38e728ed0f178571fb49c1f7 Mon Sep 17 00:00:00 2001 From: Philippe Mathieu-Daudé Date: Thu, 15 Feb 2018 23:01:26 -0300 Subject: hw/sd/sdcard: Make sd_data_ready() static MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sd_data_ready() belongs to the legacy API. As its last user has been converted to the SDBus API, make it static. Reviewed-by: Alistair Francis Message-Id: <20180216022933.10945-7-f4bug@amsat.org> Signed-off-by: Philippe Mathieu-Daudé Acked-by: Peter Maydell --- hw/sd/sd.c | 2 +- include/hw/sd/sd.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'include') diff --git a/hw/sd/sd.c b/hw/sd/sd.c index fad9cf1ee7..a5ae5dccbe 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -2082,7 +2082,7 @@ uint8_t sd_read_data(SDState *sd) return ret; } -bool sd_data_ready(SDState *sd) +static bool sd_data_ready(SDState *sd) { return sd->state == sd_sendingdata_state; } diff --git a/include/hw/sd/sd.h b/include/hw/sd/sd.h index a84b8e274a..ace350e0e8 100644 --- a/include/hw/sd/sd.h +++ b/include/hw/sd/sd.h @@ -143,7 +143,6 @@ int sd_do_command(SDState *sd, SDRequest *req, void sd_write_data(SDState *sd, uint8_t value); uint8_t sd_read_data(SDState *sd); void sd_set_cb(SDState *sd, qemu_irq readonly, qemu_irq insert); -bool sd_data_ready(SDState *sd); /* sd_enable should not be used -- it is only used on the nseries boards, * where it is part of a broken implementation of the MMC card slot switch * (there should be two card slots which are multiplexed to a single MMC -- cgit 1.4.1 From 9006f1e706e0f41efdb62556cefe88d746add88a Mon Sep 17 00:00:00 2001 From: Philippe Mathieu-Daudé Date: Sat, 23 Dec 2017 17:29:33 -0300 Subject: hw/sd: Move sdcard legacy API to 'hw/sd/sdcard_legacy.h' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit omap_mmc.c is the last device left using the legacy sdcard API. Move the prototype declarations into a separate header, to make it clear this is a legacy API. Reviewed-by: Alistair Francis Message-Id: <20180216022933.10945-8-f4bug@amsat.org> Signed-off-by: Philippe Mathieu-Daudé Acked-by: Peter Maydell --- hw/sd/omap_mmc.c | 2 +- hw/sd/sd.c | 1 + include/hw/sd/sd.h | 16 -------------- include/hw/sd/sdcard_legacy.h | 50 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 17 deletions(-) create mode 100644 include/hw/sd/sdcard_legacy.h (limited to 'include') diff --git a/hw/sd/omap_mmc.c b/hw/sd/omap_mmc.c index 4088a8a80b..7d33c59226 100644 --- a/hw/sd/omap_mmc.c +++ b/hw/sd/omap_mmc.c @@ -23,7 +23,7 @@ #include "qemu/log.h" #include "hw/irq.h" #include "hw/arm/omap.h" -#include "hw/sd/sd.h" +#include "hw/sd/sdcard_legacy.h" struct omap_mmc_s { qemu_irq irq; diff --git a/hw/sd/sd.c b/hw/sd/sd.c index a5ae5dccbe..5c6f5c94f3 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -37,6 +37,7 @@ #include "hw/registerfields.h" #include "sysemu/block-backend.h" #include "hw/sd/sd.h" +#include "hw/sd/sdcard_legacy.h" #include "migration/vmstate.h" #include "qapi/error.h" #include "qemu/bitmap.h" diff --git a/include/hw/sd/sd.h b/include/hw/sd/sd.h index ace350e0e8..8767ab817c 100644 --- a/include/hw/sd/sd.h +++ b/include/hw/sd/sd.h @@ -136,22 +136,6 @@ typedef struct { void (*set_readonly)(DeviceState *dev, bool readonly); } SDBusClass; -/* Legacy functions to be used only by non-qdevified callers */ -SDState *sd_init(BlockBackend *bs, bool is_spi); -int sd_do_command(SDState *sd, SDRequest *req, - uint8_t *response); -void sd_write_data(SDState *sd, uint8_t value); -uint8_t sd_read_data(SDState *sd); -void sd_set_cb(SDState *sd, qemu_irq readonly, qemu_irq insert); -/* sd_enable should not be used -- it is only used on the nseries boards, - * where it is part of a broken implementation of the MMC card slot switch - * (there should be two card slots which are multiplexed to a single MMC - * controller, but instead we model it with one card and controller and - * disable the card when the second slot is selected, so it looks like the - * second slot is always empty). - */ -void sd_enable(SDState *sd, bool enable); - /* Functions to be used by qdevified callers (working via * an SDBus rather than directly with SDState) */ diff --git a/include/hw/sd/sdcard_legacy.h b/include/hw/sd/sdcard_legacy.h new file mode 100644 index 0000000000..8681f8089b --- /dev/null +++ b/include/hw/sd/sdcard_legacy.h @@ -0,0 +1,50 @@ +/* + * SD Memory Card emulation (deprecated legacy API) + * + * Copyright (c) 2006 Andrzej Zaborowski + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef HW_SDCARD_LEGACY_H +#define HW_SDCARD_LEGACY_H + +#include "hw/sd/sd.h" + +/* Legacy functions to be used only by non-qdevified callers */ +SDState *sd_init(BlockBackend *blk, bool is_spi); +int sd_do_command(SDState *card, SDRequest *request, uint8_t *response); +void sd_write_data(SDState *card, uint8_t value); +uint8_t sd_read_data(SDState *card); +void sd_set_cb(SDState *card, qemu_irq readonly, qemu_irq insert); + +/* sd_enable should not be used -- it is only used on the nseries boards, + * where it is part of a broken implementation of the MMC card slot switch + * (there should be two card slots which are multiplexed to a single MMC + * controller, but instead we model it with one card and controller and + * disable the card when the second slot is selected, so it looks like the + * second slot is always empty). + */ +void sd_enable(SDState *card, bool enable); + +#endif /* HW_SDCARD_LEGACY_H */ -- cgit 1.4.1 From c769a88d4475f648595c6a270d9d0b0f3f7f3740 Mon Sep 17 00:00:00 2001 From: Philippe Mathieu-Daudé Date: Fri, 14 Aug 2020 11:23:40 +0200 Subject: hw/sd: Rename read/write_data() as read/write_byte() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The read/write_data() methods write do a single byte access on the data line of a SD card. Rename them as read/write_byte(). Add some documentation (not in "hw/sd/sdcard_legacy.h" which we are going to remove soon). Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Message-Id: <20200814092346.21825-2-f4bug@amsat.org> --- hw/sd/core.c | 4 ++-- hw/sd/omap_mmc.c | 8 ++++---- hw/sd/sd.c | 16 ++++++++-------- include/hw/sd/sd.h | 19 +++++++++++++++++-- include/hw/sd/sdcard_legacy.h | 4 ++-- 5 files changed, 33 insertions(+), 18 deletions(-) (limited to 'include') diff --git a/hw/sd/core.c b/hw/sd/core.c index abec48bccb..79d96576ea 100644 --- a/hw/sd/core.c +++ b/hw/sd/core.c @@ -110,7 +110,7 @@ void sdbus_write_data(SDBus *sdbus, uint8_t value) if (card) { SDCardClass *sc = SD_CARD_GET_CLASS(card); - sc->write_data(card, value); + sc->write_byte(card, value); } } @@ -122,7 +122,7 @@ uint8_t sdbus_read_data(SDBus *sdbus) if (card) { SDCardClass *sc = SD_CARD_GET_CLASS(card); - value = sc->read_data(card); + value = sc->read_byte(card); } trace_sdbus_read(sdbus_name(sdbus), value); diff --git a/hw/sd/omap_mmc.c b/hw/sd/omap_mmc.c index 7d33c59226..1f946908fe 100644 --- a/hw/sd/omap_mmc.c +++ b/hw/sd/omap_mmc.c @@ -232,10 +232,10 @@ static void omap_mmc_transfer(struct omap_mmc_s *host) if (host->fifo_len > host->af_level) break; - value = sd_read_data(host->card); + value = sd_read_byte(host->card); host->fifo[(host->fifo_start + host->fifo_len) & 31] = value; if (-- host->blen_counter) { - value = sd_read_data(host->card); + value = sd_read_byte(host->card); host->fifo[(host->fifo_start + host->fifo_len) & 31] |= value << 8; host->blen_counter --; @@ -247,10 +247,10 @@ static void omap_mmc_transfer(struct omap_mmc_s *host) break; value = host->fifo[host->fifo_start] & 0xff; - sd_write_data(host->card, value); + sd_write_byte(host->card, value); if (-- host->blen_counter) { value = host->fifo[host->fifo_start] >> 8; - sd_write_data(host->card, value); + sd_write_byte(host->card, value); host->blen_counter --; } diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 5c6f5c94f3..7c9d956f11 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1809,7 +1809,7 @@ static void sd_blk_write(SDState *sd, uint64_t addr, uint32_t len) #define APP_READ_BLOCK(a, len) memset(sd->data, 0xec, len) #define APP_WRITE_BLOCK(a, len) -void sd_write_data(SDState *sd, uint8_t value) +void sd_write_byte(SDState *sd, uint8_t value) { int i; @@ -1818,7 +1818,7 @@ void sd_write_data(SDState *sd, uint8_t value) if (sd->state != sd_receivingdata_state) { qemu_log_mask(LOG_GUEST_ERROR, - "sd_write_data: not in Receiving-Data state\n"); + "%s: not in Receiving-Data state\n", __func__); return; } @@ -1940,7 +1940,7 @@ void sd_write_data(SDState *sd, uint8_t value) break; default: - qemu_log_mask(LOG_GUEST_ERROR, "sd_write_data: unknown command\n"); + qemu_log_mask(LOG_GUEST_ERROR, "%s: unknown command\n", __func__); break; } } @@ -1959,7 +1959,7 @@ static const uint8_t sd_tuning_block_pattern[SD_TUNING_BLOCK_SIZE] = { 0xbb, 0xff, 0xf7, 0xff, 0xf7, 0x7f, 0x7b, 0xde, }; -uint8_t sd_read_data(SDState *sd) +uint8_t sd_read_byte(SDState *sd) { /* TODO: Append CRCs */ uint8_t ret; @@ -1970,7 +1970,7 @@ uint8_t sd_read_data(SDState *sd) if (sd->state != sd_sendingdata_state) { qemu_log_mask(LOG_GUEST_ERROR, - "sd_read_data: not in Sending-Data state\n"); + "%s: not in Sending-Data state\n", __func__); return 0x00; } @@ -2076,7 +2076,7 @@ uint8_t sd_read_data(SDState *sd) break; default: - qemu_log_mask(LOG_GUEST_ERROR, "sd_read_data: unknown command\n"); + qemu_log_mask(LOG_GUEST_ERROR, "%s: unknown command\n", __func__); return 0x00; } @@ -2192,8 +2192,8 @@ static void sd_class_init(ObjectClass *klass, void *data) sc->get_dat_lines = sd_get_dat_lines; sc->get_cmd_line = sd_get_cmd_line; sc->do_command = sd_do_command; - sc->write_data = sd_write_data; - sc->read_data = sd_read_data; + sc->write_byte = sd_write_byte; + sc->read_byte = sd_read_byte; sc->data_ready = sd_data_ready; sc->enable = sd_enable; sc->get_inserted = sd_get_inserted; diff --git a/include/hw/sd/sd.h b/include/hw/sd/sd.h index 8767ab817c..b58b5a19af 100644 --- a/include/hw/sd/sd.h +++ b/include/hw/sd/sd.h @@ -104,8 +104,23 @@ typedef struct { /*< public >*/ int (*do_command)(SDState *sd, SDRequest *req, uint8_t *response); - void (*write_data)(SDState *sd, uint8_t value); - uint8_t (*read_data)(SDState *sd); + /** + * Write a byte to a SD card. + * @sd: card + * @value: byte to write + * + * Write a byte on the data lines of a SD card. + */ + void (*write_byte)(SDState *sd, uint8_t value); + /** + * Read a byte from a SD card. + * @sd: card + * + * Read a byte from the data lines of a SD card. + * + * Return: byte value read + */ + uint8_t (*read_byte)(SDState *sd); bool (*data_ready)(SDState *sd); void (*set_voltage)(SDState *sd, uint16_t millivolts); uint8_t (*get_dat_lines)(SDState *sd); diff --git a/include/hw/sd/sdcard_legacy.h b/include/hw/sd/sdcard_legacy.h index 8681f8089b..0dc3889555 100644 --- a/include/hw/sd/sdcard_legacy.h +++ b/include/hw/sd/sdcard_legacy.h @@ -34,8 +34,8 @@ /* Legacy functions to be used only by non-qdevified callers */ SDState *sd_init(BlockBackend *blk, bool is_spi); int sd_do_command(SDState *card, SDRequest *request, uint8_t *response); -void sd_write_data(SDState *card, uint8_t value); -uint8_t sd_read_data(SDState *card); +void sd_write_byte(SDState *card, uint8_t value); +uint8_t sd_read_byte(SDState *card); void sd_set_cb(SDState *card, qemu_irq readonly, qemu_irq insert); /* sd_enable should not be used -- it is only used on the nseries boards, -- cgit 1.4.1 From 39017143d6d7a068573da272528d7df71d0d31b4 Mon Sep 17 00:00:00 2001 From: Philippe Mathieu-Daudé Date: Fri, 14 Aug 2020 11:23:41 +0200 Subject: hw/sd: Rename sdbus_write_data() as sdbus_write_byte() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The sdbus_write_data() method do a single byte access on the data line of a SD bus. Rename it as sdbus_write_byte() and document it. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Message-Id: <20200814092346.21825-3-f4bug@amsat.org> --- hw/sd/allwinner-sdhost.c | 10 +++++----- hw/sd/bcm2835_sdhost.c | 2 +- hw/sd/core.c | 2 +- hw/sd/milkymist-memcard.c | 8 ++++---- hw/sd/pl181.c | 2 +- hw/sd/pxa2xx_mmci.c | 2 +- hw/sd/sdhci.c | 8 ++++---- include/hw/sd/sd.h | 9 ++++++++- 8 files changed, 25 insertions(+), 18 deletions(-) (limited to 'include') diff --git a/hw/sd/allwinner-sdhost.c b/hw/sd/allwinner-sdhost.c index f404e1fdb4..e05e8a3864 100644 --- a/hw/sd/allwinner-sdhost.c +++ b/hw/sd/allwinner-sdhost.c @@ -335,7 +335,7 @@ static uint32_t allwinner_sdhost_process_desc(AwSdHostState *s, buf, buf_bytes); for (uint32_t i = 0; i < buf_bytes; i++) { - sdbus_write_data(&s->sdbus, buf[i]); + sdbus_write_byte(&s->sdbus, buf[i]); } /* Read from SD bus */ @@ -654,10 +654,10 @@ static void allwinner_sdhost_write(void *opaque, hwaddr offset, s->startbit_detect = value; break; case REG_SD_FIFO: /* Read/Write FIFO */ - sdbus_write_data(&s->sdbus, value & 0xff); - sdbus_write_data(&s->sdbus, (value >> 8) & 0xff); - sdbus_write_data(&s->sdbus, (value >> 16) & 0xff); - sdbus_write_data(&s->sdbus, (value >> 24) & 0xff); + sdbus_write_byte(&s->sdbus, value & 0xff); + sdbus_write_byte(&s->sdbus, (value >> 8) & 0xff); + sdbus_write_byte(&s->sdbus, (value >> 16) & 0xff); + sdbus_write_byte(&s->sdbus, (value >> 24) & 0xff); allwinner_sdhost_update_transfer_cnt(s, sizeof(uint32_t)); allwinner_sdhost_auto_stop(s); allwinner_sdhost_update_irq(s); diff --git a/hw/sd/bcm2835_sdhost.c b/hw/sd/bcm2835_sdhost.c index 4a80fbcc86..16aba7cc92 100644 --- a/hw/sd/bcm2835_sdhost.c +++ b/hw/sd/bcm2835_sdhost.c @@ -223,7 +223,7 @@ static void bcm2835_sdhost_fifo_run(BCM2835SDHostState *s) } n--; s->datacnt--; - sdbus_write_data(&s->sdbus, value & 0xff); + sdbus_write_byte(&s->sdbus, value & 0xff); value >>= 8; } } diff --git a/hw/sd/core.c b/hw/sd/core.c index 79d96576ea..13b5ca0316 100644 --- a/hw/sd/core.c +++ b/hw/sd/core.c @@ -102,7 +102,7 @@ int sdbus_do_command(SDBus *sdbus, SDRequest *req, uint8_t *response) return 0; } -void sdbus_write_data(SDBus *sdbus, uint8_t value) +void sdbus_write_byte(SDBus *sdbus, uint8_t value) { SDState *card = get_card(sdbus); diff --git a/hw/sd/milkymist-memcard.c b/hw/sd/milkymist-memcard.c index e9f5db5e22..4128109c04 100644 --- a/hw/sd/milkymist-memcard.c +++ b/hw/sd/milkymist-memcard.c @@ -209,10 +209,10 @@ static void memcard_write(void *opaque, hwaddr addr, uint64_t value, if (!s->enabled) { break; } - sdbus_write_data(&s->sdbus, (value >> 24) & 0xff); - sdbus_write_data(&s->sdbus, (value >> 16) & 0xff); - sdbus_write_data(&s->sdbus, (value >> 8) & 0xff); - sdbus_write_data(&s->sdbus, value & 0xff); + sdbus_write_byte(&s->sdbus, (value >> 24) & 0xff); + sdbus_write_byte(&s->sdbus, (value >> 16) & 0xff); + sdbus_write_byte(&s->sdbus, (value >> 8) & 0xff); + sdbus_write_byte(&s->sdbus, value & 0xff); break; case R_ENABLE: s->regs[addr] = value; diff --git a/hw/sd/pl181.c b/hw/sd/pl181.c index 574500ce60..771bae193f 100644 --- a/hw/sd/pl181.c +++ b/hw/sd/pl181.c @@ -244,7 +244,7 @@ static void pl181_fifo_run(PL181State *s) } n--; s->datacnt--; - sdbus_write_data(&s->sdbus, value & 0xff); + sdbus_write_byte(&s->sdbus, value & 0xff); value >>= 8; } } diff --git a/hw/sd/pxa2xx_mmci.c b/hw/sd/pxa2xx_mmci.c index 2996a2ef17..07ddc2eba3 100644 --- a/hw/sd/pxa2xx_mmci.c +++ b/hw/sd/pxa2xx_mmci.c @@ -184,7 +184,7 @@ static void pxa2xx_mmci_fifo_update(PXA2xxMMCIState *s) if (s->cmdat & CMDAT_WR_RD) { while (s->bytesleft && s->tx_len) { - sdbus_write_data(&s->sdbus, s->tx_fifo[s->tx_start++]); + sdbus_write_byte(&s->sdbus, s->tx_fifo[s->tx_start++]); s->tx_start &= 0x1f; s->tx_len --; s->bytesleft --; diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c index deac181865..4bf1ee88b2 100644 --- a/hw/sd/sdhci.c +++ b/hw/sd/sdhci.c @@ -515,7 +515,7 @@ static void sdhci_write_block_to_card(SDHCIState *s) } for (index = 0; index < (s->blksize & BLOCK_SIZE_MASK); index++) { - sdbus_write_data(&s->sdbus, s->fifo_buffer[index]); + sdbus_write_byte(&s->sdbus, s->fifo_buffer[index]); } /* Next data can be written through BUFFER DATORT register */ @@ -642,7 +642,7 @@ static void sdhci_sdma_transfer_multi_blocks(SDHCIState *s) s->sdmasysad += s->data_count - begin; if (s->data_count == block_size) { for (n = 0; n < block_size; n++) { - sdbus_write_data(&s->sdbus, s->fifo_buffer[n]); + sdbus_write_byte(&s->sdbus, s->fifo_buffer[n]); } s->data_count = 0; if (s->trnmod & SDHC_TRNS_BLK_CNT_EN) { @@ -679,7 +679,7 @@ static void sdhci_sdma_transfer_single_block(SDHCIState *s) } else { dma_memory_read(s->dma_as, s->sdmasysad, s->fifo_buffer, datacnt); for (n = 0; n < datacnt; n++) { - sdbus_write_data(&s->sdbus, s->fifo_buffer[n]); + sdbus_write_byte(&s->sdbus, s->fifo_buffer[n]); } } s->blkcnt--; @@ -815,7 +815,7 @@ static void sdhci_do_adma(SDHCIState *s) dscr.addr += s->data_count - begin; if (s->data_count == block_size) { for (n = 0; n < block_size; n++) { - sdbus_write_data(&s->sdbus, s->fifo_buffer[n]); + sdbus_write_byte(&s->sdbus, s->fifo_buffer[n]); } s->data_count = 0; if (s->trnmod & SDHC_TRNS_BLK_CNT_EN) { diff --git a/include/hw/sd/sd.h b/include/hw/sd/sd.h index b58b5a19af..1e5ac955d0 100644 --- a/include/hw/sd/sd.h +++ b/include/hw/sd/sd.h @@ -158,7 +158,14 @@ void sdbus_set_voltage(SDBus *sdbus, uint16_t millivolts); uint8_t sdbus_get_dat_lines(SDBus *sdbus); bool sdbus_get_cmd_line(SDBus *sdbus); int sdbus_do_command(SDBus *sd, SDRequest *req, uint8_t *response); -void sdbus_write_data(SDBus *sd, uint8_t value); +/** + * Write a byte to a SD bus. + * @sd: bus + * @value: byte to write + * + * Write a byte on the data lines of a SD bus. + */ +void sdbus_write_byte(SDBus *sd, uint8_t value); uint8_t sdbus_read_data(SDBus *sd); bool sdbus_data_ready(SDBus *sd); bool sdbus_get_inserted(SDBus *sd); -- cgit 1.4.1 From 8467f62201fd2383d553702f9f9441e2493ece75 Mon Sep 17 00:00:00 2001 From: Philippe Mathieu-Daudé Date: Fri, 14 Aug 2020 11:23:42 +0200 Subject: hw/sd: Rename sdbus_read_data() as sdbus_read_byte() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The sdbus_read_data() method do a single byte access on the data line of a SD bus. Rename it as sdbus_read_byte() and document it. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Message-Id: <20200814092346.21825-4-f4bug@amsat.org> --- hw/sd/allwinner-sdhost.c | 10 +++++----- hw/sd/bcm2835_sdhost.c | 2 +- hw/sd/core.c | 2 +- hw/sd/milkymist-memcard.c | 8 ++++---- hw/sd/pl181.c | 2 +- hw/sd/pxa2xx_mmci.c | 2 +- hw/sd/sdhci.c | 8 ++++---- hw/sd/ssi-sd.c | 2 +- include/hw/sd/sd.h | 10 +++++++++- 9 files changed, 27 insertions(+), 19 deletions(-) (limited to 'include') diff --git a/hw/sd/allwinner-sdhost.c b/hw/sd/allwinner-sdhost.c index e05e8a3864..c004aa39da 100644 --- a/hw/sd/allwinner-sdhost.c +++ b/hw/sd/allwinner-sdhost.c @@ -341,7 +341,7 @@ static uint32_t allwinner_sdhost_process_desc(AwSdHostState *s, /* Read from SD bus */ } else { for (uint32_t i = 0; i < buf_bytes; i++) { - buf[i] = sdbus_read_data(&s->sdbus); + buf[i] = sdbus_read_byte(&s->sdbus); } cpu_physical_memory_write((desc->addr & DESC_SIZE_MASK) + num_done, buf, buf_bytes); @@ -521,10 +521,10 @@ static uint64_t allwinner_sdhost_read(void *opaque, hwaddr offset, break; case REG_SD_FIFO: /* Read/Write FIFO */ if (sdbus_data_ready(&s->sdbus)) { - res = sdbus_read_data(&s->sdbus); - res |= sdbus_read_data(&s->sdbus) << 8; - res |= sdbus_read_data(&s->sdbus) << 16; - res |= sdbus_read_data(&s->sdbus) << 24; + res = sdbus_read_byte(&s->sdbus); + res |= sdbus_read_byte(&s->sdbus) << 8; + res |= sdbus_read_byte(&s->sdbus) << 16; + res |= sdbus_read_byte(&s->sdbus) << 24; allwinner_sdhost_update_transfer_cnt(s, sizeof(uint32_t)); allwinner_sdhost_auto_stop(s); allwinner_sdhost_update_irq(s); diff --git a/hw/sd/bcm2835_sdhost.c b/hw/sd/bcm2835_sdhost.c index 16aba7cc92..2c7a675a2d 100644 --- a/hw/sd/bcm2835_sdhost.c +++ b/hw/sd/bcm2835_sdhost.c @@ -190,7 +190,7 @@ static void bcm2835_sdhost_fifo_run(BCM2835SDHostState *s) if (is_read) { n = 0; while (s->datacnt && s->fifo_len < BCM2835_SDHOST_FIFO_LEN) { - value |= (uint32_t)sdbus_read_data(&s->sdbus) << (n * 8); + value |= (uint32_t)sdbus_read_byte(&s->sdbus) << (n * 8); s->datacnt--; n++; if (n == 4) { diff --git a/hw/sd/core.c b/hw/sd/core.c index 13b5ca0316..a3b620b802 100644 --- a/hw/sd/core.c +++ b/hw/sd/core.c @@ -114,7 +114,7 @@ void sdbus_write_byte(SDBus *sdbus, uint8_t value) } } -uint8_t sdbus_read_data(SDBus *sdbus) +uint8_t sdbus_read_byte(SDBus *sdbus) { SDState *card = get_card(sdbus); uint8_t value = 0; diff --git a/hw/sd/milkymist-memcard.c b/hw/sd/milkymist-memcard.c index 4128109c04..e8d055bb89 100644 --- a/hw/sd/milkymist-memcard.c +++ b/hw/sd/milkymist-memcard.c @@ -152,10 +152,10 @@ static uint64_t memcard_read(void *opaque, hwaddr addr, r = 0xffffffff; } else { r = 0; - r |= sdbus_read_data(&s->sdbus) << 24; - r |= sdbus_read_data(&s->sdbus) << 16; - r |= sdbus_read_data(&s->sdbus) << 8; - r |= sdbus_read_data(&s->sdbus); + r |= sdbus_read_byte(&s->sdbus) << 24; + r |= sdbus_read_byte(&s->sdbus) << 16; + r |= sdbus_read_byte(&s->sdbus) << 8; + r |= sdbus_read_byte(&s->sdbus); } break; case R_CLK2XDIV: diff --git a/hw/sd/pl181.c b/hw/sd/pl181.c index 771bae193f..579d68ad83 100644 --- a/hw/sd/pl181.c +++ b/hw/sd/pl181.c @@ -223,7 +223,7 @@ static void pl181_fifo_run(PL181State *s) if (is_read) { n = 0; while (s->datacnt && s->fifo_len < PL181_FIFO_LEN) { - value |= (uint32_t)sdbus_read_data(&s->sdbus) << (n * 8); + value |= (uint32_t)sdbus_read_byte(&s->sdbus) << (n * 8); s->datacnt--; n++; if (n == 4) { diff --git a/hw/sd/pxa2xx_mmci.c b/hw/sd/pxa2xx_mmci.c index 07ddc2eba3..04f0a98f81 100644 --- a/hw/sd/pxa2xx_mmci.c +++ b/hw/sd/pxa2xx_mmci.c @@ -194,7 +194,7 @@ static void pxa2xx_mmci_fifo_update(PXA2xxMMCIState *s) } else while (s->bytesleft && s->rx_len < 32) { s->rx_fifo[(s->rx_start + (s->rx_len ++)) & 0x1f] = - sdbus_read_data(&s->sdbus); + sdbus_read_byte(&s->sdbus); s->bytesleft --; s->intreq |= INT_RXFIFO_REQ; } diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c index 4bf1ee88b2..b897b1121b 100644 --- a/hw/sd/sdhci.c +++ b/hw/sd/sdhci.c @@ -409,7 +409,7 @@ static void sdhci_read_block_from_card(SDHCIState *s) } for (index = 0; index < blk_size; index++) { - data = sdbus_read_data(&s->sdbus); + data = sdbus_read_byte(&s->sdbus); if (!FIELD_EX32(s->hostctl2, SDHC_HOSTCTL2, EXECUTE_TUNING)) { /* Device is not in tuning */ s->fifo_buffer[index] = data; @@ -601,7 +601,7 @@ static void sdhci_sdma_transfer_multi_blocks(SDHCIState *s) while (s->blkcnt) { if (s->data_count == 0) { for (n = 0; n < block_size; n++) { - s->fifo_buffer[n] = sdbus_read_data(&s->sdbus); + s->fifo_buffer[n] = sdbus_read_byte(&s->sdbus); } } begin = s->data_count; @@ -673,7 +673,7 @@ static void sdhci_sdma_transfer_single_block(SDHCIState *s) if (s->trnmod & SDHC_TRNS_READ) { for (n = 0; n < datacnt; n++) { - s->fifo_buffer[n] = sdbus_read_data(&s->sdbus); + s->fifo_buffer[n] = sdbus_read_byte(&s->sdbus); } dma_memory_write(s->dma_as, s->sdmasysad, s->fifo_buffer, datacnt); } else { @@ -774,7 +774,7 @@ static void sdhci_do_adma(SDHCIState *s) while (length) { if (s->data_count == 0) { for (n = 0; n < block_size; n++) { - s->fifo_buffer[n] = sdbus_read_data(&s->sdbus); + s->fifo_buffer[n] = sdbus_read_byte(&s->sdbus); } } begin = s->data_count; diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c index 9210ef567f..a7ef9cb922 100644 --- a/hw/sd/ssi-sd.c +++ b/hw/sd/ssi-sd.c @@ -190,7 +190,7 @@ static uint32_t ssi_sd_transfer(SSISlave *dev, uint32_t val) s->mode = SSI_SD_DATA_READ; return 0xfe; case SSI_SD_DATA_READ: - val = sdbus_read_data(&s->sdbus); + val = sdbus_read_byte(&s->sdbus); if (!sdbus_data_ready(&s->sdbus)) { DPRINTF("Data read end\n"); s->mode = SSI_SD_CMD; diff --git a/include/hw/sd/sd.h b/include/hw/sd/sd.h index 1e5ac955d0..14ffc7f475 100644 --- a/include/hw/sd/sd.h +++ b/include/hw/sd/sd.h @@ -166,7 +166,15 @@ int sdbus_do_command(SDBus *sd, SDRequest *req, uint8_t *response); * Write a byte on the data lines of a SD bus. */ void sdbus_write_byte(SDBus *sd, uint8_t value); -uint8_t sdbus_read_data(SDBus *sd); +/** + * Read a byte from a SD bus. + * @sd: bus + * + * Read a byte from the data lines of a SD bus. + * + * Return: byte value read + */ +uint8_t sdbus_read_byte(SDBus *sd); bool sdbus_data_ready(SDBus *sd); bool sdbus_get_inserted(SDBus *sd); bool sdbus_get_readonly(SDBus *sd); -- cgit 1.4.1 From e35c343dd9c18d4d3e6424e2fab38f08085875d6 Mon Sep 17 00:00:00 2001 From: Philippe Mathieu-Daudé Date: Fri, 14 Aug 2020 11:23:43 +0200 Subject: hw/sd: Add sdbus_write_data() to write multiples bytes on the data line MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a sdbus_write_data() method to write multiple bytes on the data line of a SD bus. We might improve the tracing later, for now keep logging each byte individually. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Message-Id: <20200814092346.21825-5-f4bug@amsat.org> --- hw/sd/core.c | 15 +++++++++++++++ include/hw/sd/sd.h | 9 +++++++++ 2 files changed, 24 insertions(+) (limited to 'include') diff --git a/hw/sd/core.c b/hw/sd/core.c index a3b620b802..9c2781ebf9 100644 --- a/hw/sd/core.c +++ b/hw/sd/core.c @@ -114,6 +114,21 @@ void sdbus_write_byte(SDBus *sdbus, uint8_t value) } } +void sdbus_write_data(SDBus *sdbus, const void *buf, size_t length) +{ + SDState *card = get_card(sdbus); + const uint8_t *data = buf; + + if (card) { + SDCardClass *sc = SD_CARD_GET_CLASS(card); + + for (size_t i = 0; i < length; i++) { + trace_sdbus_write(sdbus_name(sdbus), data[i]); + sc->write_byte(card, data[i]); + } + } +} + uint8_t sdbus_read_byte(SDBus *sdbus) { SDState *card = get_card(sdbus); diff --git a/include/hw/sd/sd.h b/include/hw/sd/sd.h index 14ffc7f475..3ae3e8939b 100644 --- a/include/hw/sd/sd.h +++ b/include/hw/sd/sd.h @@ -175,6 +175,15 @@ void sdbus_write_byte(SDBus *sd, uint8_t value); * Return: byte value read */ uint8_t sdbus_read_byte(SDBus *sd); +/** + * Write data to a SD bus. + * @sdbus: bus + * @buf: data to write + * @length: number of bytes to write + * + * Write multiple bytes of data on the data lines of a SD bus. + */ +void sdbus_write_data(SDBus *sdbus, const void *buf, size_t length); bool sdbus_data_ready(SDBus *sd); bool sdbus_get_inserted(SDBus *sd); bool sdbus_get_readonly(SDBus *sd); -- cgit 1.4.1 From 6505a91a77d4efcc6d54b35851abcb137cdca30a Mon Sep 17 00:00:00 2001 From: Philippe Mathieu-Daudé Date: Fri, 14 Aug 2020 11:23:45 +0200 Subject: hw/sd: Add sdbus_read_data() to read multiples bytes on the data line MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a sdbus_read_data() method to read multiple bytes on the data line of a SD bus. We might improve the tracing later, for now keep logging each byte individually. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Message-Id: <20200814092346.21825-7-f4bug@amsat.org> --- hw/sd/core.c | 15 +++++++++++++++ include/hw/sd/sd.h | 9 +++++++++ 2 files changed, 24 insertions(+) (limited to 'include') diff --git a/hw/sd/core.c b/hw/sd/core.c index 9c2781ebf9..957d116f1a 100644 --- a/hw/sd/core.c +++ b/hw/sd/core.c @@ -144,6 +144,21 @@ uint8_t sdbus_read_byte(SDBus *sdbus) return value; } +void sdbus_read_data(SDBus *sdbus, void *buf, size_t length) +{ + SDState *card = get_card(sdbus); + uint8_t *data = buf; + + if (card) { + SDCardClass *sc = SD_CARD_GET_CLASS(card); + + for (size_t i = 0; i < length; i++) { + data[i] = sc->read_byte(card); + trace_sdbus_read(sdbus_name(sdbus), data[i]); + } + } +} + bool sdbus_data_ready(SDBus *sdbus) { SDState *card = get_card(sdbus); diff --git a/include/hw/sd/sd.h b/include/hw/sd/sd.h index 3ae3e8939b..ac02d61a7a 100644 --- a/include/hw/sd/sd.h +++ b/include/hw/sd/sd.h @@ -184,6 +184,15 @@ uint8_t sdbus_read_byte(SDBus *sd); * Write multiple bytes of data on the data lines of a SD bus. */ void sdbus_write_data(SDBus *sdbus, const void *buf, size_t length); +/** + * Read data from a SD bus. + * @sdbus: bus + * @buf: buffer to read data into + * @length: number of bytes to read + * + * Read multiple bytes of data on the data lines of a SD bus. + */ +void sdbus_read_data(SDBus *sdbus, void *buf, size_t length); bool sdbus_data_ready(SDBus *sd); bool sdbus_get_inserted(SDBus *sd); bool sdbus_get_readonly(SDBus *sd); -- cgit 1.4.1