From patchwork Fri Aug 14 09:23:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 276488 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNWANTED_LANGUAGE_BODY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D02FBC433E1 for ; Fri, 14 Aug 2020 10:12:37 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9AACA2074D for ; Fri, 14 Aug 2020 10:12:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PX12473c" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9AACA2074D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:50150 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6WhQ-0008UT-TJ for qemu-devel@archiver.kernel.org; Fri, 14 Aug 2020 06:12:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46728) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k6VwI-0005QR-4O; Fri, 14 Aug 2020 05:23:54 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]:33386) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k6VwG-0004KG-9t; Fri, 14 Aug 2020 05:23:53 -0400 Received: by mail-wr1-x430.google.com with SMTP id p20so7751501wrf.0; Fri, 14 Aug 2020 02:23:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+/2SLK598ki9weuwoeMpo5eHHltzo6y+gY/RQh6VyAk=; b=PX12473c23LrbCmGbqsqd0i8e3/cdApRFg7qEOgnBPptG/gkERKztbM59bK3qHH6y7 q80yfgzBYfGlgElyAq5VYZvPyq+KJMJbDnSjrzn8vTckyLSupraujbpoeKqNDN4hJMEy eFFGfySCVfVHgIPucQ/8A0mB1Nkm6+y4Uf2rQxpg7qBaG5ozC0Hh4wH5A0DMsESvteuU YhtCVF1EbCK6g7Q+pcGN+2C+Z5h3SYTMSXQOnRAMPRuOlM1Jgq5vSj2wqoMiUkyylPmR ff07PZbEGGHQVqPjmA4Ik55FV1zpKm8d3xcSaGiXUl4QbkP+aBhDXZ7DFFQ9je7LRrc2 pubw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=+/2SLK598ki9weuwoeMpo5eHHltzo6y+gY/RQh6VyAk=; b=lR2/eyFHFvERebIhz70YtHiwps2mF2fn/HLXj2FWE15zRZZ4yqLzmzuMAUPSfIUcXn MBWB6B1x9LfJ2HAZ8N0FY2E2eKaxOqJTRL3BKqKvp725fR/uM1ZZq0TUpMK+fyhVnnPt 9mIWGjOLA1TZEB4Pc7kyFj+6XWXQXi0siE/krtnP7ZI7AXdrTbizsTgPBxi9pDmMzJ73 tP7jbt3Ka5kE+6MBB6IZ7qD6fu/7zJ0TM8jOJoXrbb3nPTFNKyL5W2AcuBxfwdsgFDhF UbgrJGIPZmlM95ROQ/0FOgaucfQiCaJGxkTz6DsZ+RzjYxQs7qbZ0Db9xq+Y5cwaCSku dnUg== X-Gm-Message-State: AOAM532EziSmx4+zy2Ij4Cgmh+ajv9w0G03hs3oXXCGt3IweytGbYHSp ZeZyUdbIOXMrkEHkYJ1qsNyBX+hhkWM= X-Google-Smtp-Source: ABdhPJwZA41u3GgvezYq4b8hIR0u1WEW5lshX5MCe0UC4Tyc522pC0Qabo37eAPQ0Mev/tKsjvhdEg== X-Received: by 2002:a5d:6047:: with SMTP id j7mr1828972wrt.315.1597397029912; Fri, 14 Aug 2020 02:23:49 -0700 (PDT) Received: from localhost.localdomain (121.red-81-40-121.staticip.rima-tde.net. [81.40.121.121]) by smtp.gmail.com with ESMTPSA id b11sm12889395wrq.32.2020.08.14.02.23.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Aug 2020 02:23:49 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 1/7] hw/sd: Rename read/write_data() as read/write_byte() Date: Fri, 14 Aug 2020 11:23:40 +0200 Message-Id: <20200814092346.21825-2-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200814092346.21825-1-f4bug@amsat.org> References: <20200814092346.21825-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x430.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Andrew Baumann , Beniamino Galvani , Michael Walle , qemu-arm@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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é --- include/hw/sd/sd.h | 19 +++++++++++++++++-- include/hw/sd/sdcard_legacy.h | 4 ++-- hw/sd/core.c | 4 ++-- hw/sd/omap_mmc.c | 8 ++++---- hw/sd/sd.c | 16 ++++++++-------- 5 files changed, 33 insertions(+), 18 deletions(-) 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, 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; From patchwork Fri Aug 14 09:23:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 276463 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A26FFC433DF for ; Fri, 14 Aug 2020 10:48:32 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6F1B820781 for ; Fri, 14 Aug 2020 10:48:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="djomzGOt" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6F1B820781 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:48680 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6XGB-00076B-OI for qemu-devel@archiver.kernel.org; Fri, 14 Aug 2020 06:48:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46766) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k6VwL-0005YJ-5S; Fri, 14 Aug 2020 05:23:57 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:56177) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k6VwJ-0004Kk-B1; Fri, 14 Aug 2020 05:23:56 -0400 Received: by mail-wm1-x343.google.com with SMTP id 9so6904209wmj.5; Fri, 14 Aug 2020 02:23:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QAYdy+M4KLzrq8A3jXi6N+nqKx4PGoeP0poZ5UugJaY=; b=djomzGOtmPN9ZGwy5IA+vzcREuwN5ab8IMkoF0SwiGxDb+RVvmL+tReZLMSqXzVL+U UBKJZOXR8UqGsclFHlZ7/HsjAP2/evNcOZrTYvbOTyToWiuHFiSkqqEbuixdWPG5VIZ8 FrcK7t6aybelyvSWmkIM6N36lnTDP06Lyz7BbPV7YduppRFqQpxyFE/Ph1o8XZmUSiVv LqMpydPqOeGeFzOhOnBRDCaHQABEb2q7pThzN506o4KiQRfsanoFfQL1Tj3sRW6LO4uA hWv46DUuBC+V9NYTAjGlAI834oYvo1nhzgQDv8zf4dJNVVFyTazwk2gfbLZ2G3RJ9lRm U7KQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=QAYdy+M4KLzrq8A3jXi6N+nqKx4PGoeP0poZ5UugJaY=; b=QXTY10A/URsnrUvwbBQcrNoyYiqSXE/nwtbOzP39AmoEAwa+Sz1Wt5lC4g7+NbfN65 FNMQ/qmi5eEhR9LkClBOokGWQODMrKndwNN3rm0XsSAL8E1AYGPFJSy1zSBrTR4EKFpK pkCee9zI2sACMtL125erdxPUzCLc1/bLAp3lBp1YmeDf5M16WVuWJFA4wsr2fflt1Djz TTYVbd0TCU/s3MGlN5IZVvX4Ue/8QXfbdR3A73fAN3ZG6uskqaXclh7bQvnoRxa/s9c4 eLErU/F7KYD549+Ng5gVqz1NOO4241U0WvsTcbOQANxPwpe3BWBIB/vI+joXl+TIg6Ev D83Q== X-Gm-Message-State: AOAM533DPrzW7ZLUUEOe/ewObyzFZjg1cGG9zQrQ06MnANjhiIPgfbxZ anCO9w6/ETwZ7lhd/G3TA1uL58uwOV4= X-Google-Smtp-Source: ABdhPJy4SH2z7IMz6a62jRzF2ZMnIN2lXHucUcadEPE0iCroY+km7+UMdlMwFYtvG3wH31LS3igA7g== X-Received: by 2002:a1c:14e:: with SMTP id 75mr1826177wmb.151.1597397032414; Fri, 14 Aug 2020 02:23:52 -0700 (PDT) Received: from localhost.localdomain (121.red-81-40-121.staticip.rima-tde.net. [81.40.121.121]) by smtp.gmail.com with ESMTPSA id b11sm12889395wrq.32.2020.08.14.02.23.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Aug 2020 02:23:51 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 3/7] hw/sd: Rename sdbus_read_data() as sdbus_read_byte() Date: Fri, 14 Aug 2020 11:23:42 +0200 Message-Id: <20200814092346.21825-4-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200814092346.21825-1-f4bug@amsat.org> References: <20200814092346.21825-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::343; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-x343.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Andrew Baumann , Beniamino Galvani , Michael Walle , qemu-arm@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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é --- include/hw/sd/sd.h | 10 +++++++++- 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 +- 9 files changed, 27 insertions(+), 19 deletions(-) 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); 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; From patchwork Fri Aug 14 09:23:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 276486 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7288C433E1 for ; Fri, 14 Aug 2020 10:14:29 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A07632074D for ; Fri, 14 Aug 2020 10:14:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QCAV0i9q" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A07632074D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:59312 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6WjE-0003n8-TO for qemu-devel@archiver.kernel.org; Fri, 14 Aug 2020 06:14:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46804) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k6VwN-0005dO-Df; Fri, 14 Aug 2020 05:23:59 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:39017) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k6VwL-0004LE-KG; Fri, 14 Aug 2020 05:23:59 -0400 Received: by mail-wr1-x443.google.com with SMTP id a5so7731015wrm.6; Fri, 14 Aug 2020 02:23:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aLPTEwW8IgyfTmT0h1xzh2aMoPhT9+v6krhNFnB9JEQ=; b=QCAV0i9qsFINmIhKsoAX/iB8/CeY2K3JOfrLM1OKkDnM44nXnW7OFUPOxm1lX1/3Rw e4mdfnW5R4yGSQwGIJoxiVeTCl8JiZHENfKZ/qj36kY+r3sik1sOKjPJZ/VD+3okCXgi R+N4iA2QvS6tfZVpIr6eG4JgbRrQ7uQqjLi9DdFJwRH1RRiL3L+tagRx7cUl1UBgvO/V TKQ8yqPtF9IFk+Ab9p7qtIv2lBZUSo/zyH/nXTeUyWXnKnffkrOma3TeLRbxbCgflU8t L5Thmtd/AFLEuk7HCnIFaHI1EjkZ/vsiJwgrZnfCBIPVe9rOAaOy3UHG6W/3QP7VUiHK 8PRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=aLPTEwW8IgyfTmT0h1xzh2aMoPhT9+v6krhNFnB9JEQ=; b=eq5HwMmb5eHMju+DjwzfeKr2p64lOtnknzpdzQCvqMQjy92yrLNcakpFrFgZ6Rx3Qt YnTEjgFU/VM6dh1xOBujylT51+1tm8RiuGBoa0RaBqxmXy7oQe40NaKa8ITJBHOuJVay Cv1yBLzxBzwZySKPkL/YC3lm6grjTyWqcbSDPdEyG7iLMqMcYI+ECUficsL3odBCYbBF +1LUdifu4fhOFWd0lZA+W2n211hKXbHY5nbopzWNd9ci4aBW+r5cy/PIeZq903m3UYKO Z0tOPW3O4hKCExgAM8Gqi3AISYdMOEfbqQpFlXLNcATamv5rbxZl7T63NPgyzw7n7EjB kctg== X-Gm-Message-State: AOAM532nUpGcImjZ8KMzR6H3gxydF90+PZT3AiUpNLSKc8QEwpeEXot7 058jvUa5RnJrorvZgDKjfQZjecOC/Ps= X-Google-Smtp-Source: ABdhPJx1WiV97w8YG2HFyop4igZGjblk6Taew3kw1v527htk2VOINl+X+yAbEXGQIB9eP/v0sA5ZrQ== X-Received: by 2002:adf:c552:: with SMTP id s18mr1799513wrf.209.1597397035016; Fri, 14 Aug 2020 02:23:55 -0700 (PDT) Received: from localhost.localdomain (121.red-81-40-121.staticip.rima-tde.net. [81.40.121.121]) by smtp.gmail.com with ESMTPSA id b11sm12889395wrq.32.2020.08.14.02.23.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Aug 2020 02:23:54 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 5/7] hw/sd: Use sdbus_write_data() instead of sdbus_write_byte when possible Date: Fri, 14 Aug 2020 11:23:44 +0200 Message-Id: <20200814092346.21825-6-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200814092346.21825-1-f4bug@amsat.org> References: <20200814092346.21825-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::443; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x443.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Andrew Baumann , Beniamino Galvani , Michael Walle , qemu-arm@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Use the recently added sdbus_write_data() to write multiple bytes at once, instead of looping calling sdbus_write_byte(). Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/allwinner-sdhost.c | 14 +++++--------- hw/sd/milkymist-memcard.c | 7 +++---- hw/sd/sdhci.c | 18 ++++-------------- 3 files changed, 12 insertions(+), 27 deletions(-) diff --git a/hw/sd/allwinner-sdhost.c b/hw/sd/allwinner-sdhost.c index c004aa39da..eea5659c5f 100644 --- a/hw/sd/allwinner-sdhost.c +++ b/hw/sd/allwinner-sdhost.c @@ -333,10 +333,7 @@ static uint32_t allwinner_sdhost_process_desc(AwSdHostState *s, if (is_write) { cpu_physical_memory_read((desc->addr & DESC_SIZE_MASK) + num_done, buf, buf_bytes); - - for (uint32_t i = 0; i < buf_bytes; i++) { - sdbus_write_byte(&s->sdbus, buf[i]); - } + sdbus_write_data(&s->sdbus, buf, buf_bytes); /* Read from SD bus */ } else { @@ -548,6 +545,7 @@ static void allwinner_sdhost_write(void *opaque, hwaddr offset, uint64_t value, unsigned size) { AwSdHostState *s = AW_SDHOST(opaque); + uint32_t u32; trace_allwinner_sdhost_write(offset, value, size); @@ -654,11 +652,9 @@ static void allwinner_sdhost_write(void *opaque, hwaddr offset, s->startbit_detect = value; break; case REG_SD_FIFO: /* Read/Write FIFO */ - 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)); + u32 = cpu_to_le32(value); + sdbus_write_data(&s->sdbus, &u32, sizeof(u32)); + allwinner_sdhost_update_transfer_cnt(s, sizeof(u32)); allwinner_sdhost_auto_stop(s); allwinner_sdhost_update_irq(s); break; diff --git a/hw/sd/milkymist-memcard.c b/hw/sd/milkymist-memcard.c index e8d055bb89..12e091a46e 100644 --- a/hw/sd/milkymist-memcard.c +++ b/hw/sd/milkymist-memcard.c @@ -181,6 +181,7 @@ static void memcard_write(void *opaque, hwaddr addr, uint64_t value, unsigned size) { MilkymistMemcardState *s = opaque; + uint32_t val32; trace_milkymist_memcard_memory_write(addr, value); @@ -209,10 +210,8 @@ static void memcard_write(void *opaque, hwaddr addr, uint64_t value, if (!s->enabled) { break; } - 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); + val32 = cpu_to_be32(value); + sdbus_write_data(&s->sdbus, &val32, sizeof(val32)); break; case R_ENABLE: s->regs[addr] = value; diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c index b897b1121b..ddf3691561 100644 --- a/hw/sd/sdhci.c +++ b/hw/sd/sdhci.c @@ -496,8 +496,6 @@ static uint32_t sdhci_read_dataport(SDHCIState *s, unsigned size) /* Write data from host controller FIFO to card */ static void sdhci_write_block_to_card(SDHCIState *s) { - int index = 0; - if (s->prnsts & SDHC_SPACE_AVAILABLE) { if (s->norintstsen & SDHC_NISEN_WBUFRDY) { s->norintsts |= SDHC_NIS_WBUFRDY; @@ -514,9 +512,7 @@ static void sdhci_write_block_to_card(SDHCIState *s) } } - for (index = 0; index < (s->blksize & BLOCK_SIZE_MASK); index++) { - sdbus_write_byte(&s->sdbus, s->fifo_buffer[index]); - } + sdbus_write_data(&s->sdbus, s->fifo_buffer, s->blksize & BLOCK_SIZE_MASK); /* Next data can be written through BUFFER DATORT register */ s->prnsts |= SDHC_SPACE_AVAILABLE; @@ -641,9 +637,7 @@ static void sdhci_sdma_transfer_multi_blocks(SDHCIState *s) &s->fifo_buffer[begin], s->data_count - begin); s->sdmasysad += s->data_count - begin; if (s->data_count == block_size) { - for (n = 0; n < block_size; n++) { - sdbus_write_byte(&s->sdbus, s->fifo_buffer[n]); - } + sdbus_write_data(&s->sdbus, s->fifo_buffer, block_size); s->data_count = 0; if (s->trnmod & SDHC_TRNS_BLK_CNT_EN) { s->blkcnt--; @@ -678,9 +672,7 @@ static void sdhci_sdma_transfer_single_block(SDHCIState *s) dma_memory_write(s->dma_as, s->sdmasysad, s->fifo_buffer, datacnt); } else { dma_memory_read(s->dma_as, s->sdmasysad, s->fifo_buffer, datacnt); - for (n = 0; n < datacnt; n++) { - sdbus_write_byte(&s->sdbus, s->fifo_buffer[n]); - } + sdbus_write_data(&s->sdbus, s->fifo_buffer, datacnt); } s->blkcnt--; @@ -814,9 +806,7 @@ static void sdhci_do_adma(SDHCIState *s) s->data_count - begin); dscr.addr += s->data_count - begin; if (s->data_count == block_size) { - for (n = 0; n < block_size; n++) { - sdbus_write_byte(&s->sdbus, s->fifo_buffer[n]); - } + sdbus_write_data(&s->sdbus, s->fifo_buffer, block_size); s->data_count = 0; if (s->trnmod & SDHC_TRNS_BLK_CNT_EN) { s->blkcnt--;