From nobody Wed Apr 16 18:04:13 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519313570568597.827452585997; Thu, 22 Feb 2018 07:32:50 -0800 (PST) Received: from localhost ([::1]:39017 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosrU-0004Lg-J3 for importer@patchew.org; Thu, 22 Feb 2018 10:32:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38533) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosik-0004yC-K1 for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosii-0001oB-SL for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:42 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46610) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosii-0001ls-Fh for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:40 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosih-00025S-BO for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:39 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:22:57 +0000 Message-Id: <20180222152307.7499-23-peter.maydell@linaro.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180222152307.7499-1-peter.maydell@linaro.org> References: <20180222152307.7499-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 22/32] sdcard: simplify using the ldst API X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 From: Philippe Mathieu-Daud=C3=A9 the code is easier to review/refactor. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Message-id: 20180215221325.7611-7-f4bug@amsat.org Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- hw/sd/sd.c | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index e55bf1fa75..3e1f7e51ad 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -431,57 +431,39 @@ static int sd_req_crc_validate(SDRequest *req) { uint8_t buffer[5]; buffer[0] =3D 0x40 | req->cmd; - buffer[1] =3D (req->arg >> 24) & 0xff; - buffer[2] =3D (req->arg >> 16) & 0xff; - buffer[3] =3D (req->arg >> 8) & 0xff; - buffer[4] =3D (req->arg >> 0) & 0xff; + stl_be_p(&buffer[1], req->arg); return 0; return sd_crc7(buffer, 5) !=3D req->crc; /* TODO */ } =20 static void sd_response_r1_make(SDState *sd, uint8_t *response) { - uint32_t status =3D sd->card_status; + stl_be_p(response, sd->card_status); + /* Clear the "clear on read" status bits */ sd->card_status &=3D ~CARD_STATUS_C; - - response[0] =3D (status >> 24) & 0xff; - response[1] =3D (status >> 16) & 0xff; - response[2] =3D (status >> 8) & 0xff; - response[3] =3D (status >> 0) & 0xff; } =20 static void sd_response_r3_make(SDState *sd, uint8_t *response) { - response[0] =3D (sd->ocr >> 24) & 0xff; - response[1] =3D (sd->ocr >> 16) & 0xff; - response[2] =3D (sd->ocr >> 8) & 0xff; - response[3] =3D (sd->ocr >> 0) & 0xff; + stl_be_p(response, sd->ocr); } =20 static void sd_response_r6_make(SDState *sd, uint8_t *response) { - uint16_t arg; uint16_t status; =20 - arg =3D sd->rca; status =3D ((sd->card_status >> 8) & 0xc000) | ((sd->card_status >> 6) & 0x2000) | (sd->card_status & 0x1fff); sd->card_status &=3D ~(CARD_STATUS_C & 0xc81fff); - - response[0] =3D (arg >> 8) & 0xff; - response[1] =3D arg & 0xff; - response[2] =3D (status >> 8) & 0xff; - response[3] =3D status & 0xff; + stw_be_p(response + 0, sd->rca); + stw_be_p(response + 2, status); } =20 static void sd_response_r7_make(SDState *sd, uint8_t *response) { - response[0] =3D (sd->vhs >> 24) & 0xff; - response[1] =3D (sd->vhs >> 16) & 0xff; - response[2] =3D (sd->vhs >> 8) & 0xff; - response[3] =3D (sd->vhs >> 0) & 0xff; + stl_be_p(response, sd->vhs); } =20 static inline uint64_t sd_addr_to_wpnum(uint64_t addr) @@ -727,7 +709,7 @@ static uint32_t sd_wpbits(SDState *sd, uint64_t addr) =20 static void sd_function_switch(SDState *sd, uint32_t arg) { - int i, mode, new_func, crc; + int i, mode, new_func; mode =3D !!(arg & 0x80000000); =20 sd->data[0] =3D 0x00; /* Maximum current consumption */ @@ -751,9 +733,7 @@ static void sd_function_switch(SDState *sd, uint32_t ar= g) sd->data[14 + (i >> 1)] =3D new_func << ((i * 4) & 4); } memset(&sd->data[17], 0, 47); - crc =3D sd_crc16(sd->data, 64); - sd->data[65] =3D crc >> 8; - sd->data[66] =3D crc & 0xff; + stw_be_p(sd->data + 65, sd_crc16(sd->data, 64)); } =20 static inline bool sd_wp_addr(SDState *sd, uint64_t addr) --=20 2.16.1