From nobody Thu Oct 30 15:35:21 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; dkim=fail; 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 Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1525450104213886.2045525623577; Fri, 4 May 2018 09:08:24 -0700 (PDT) Received: from localhost ([::1]:35072 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fEdFq-0000kg-Bv for importer@patchew.org; Fri, 04 May 2018 12:08:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54888) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fEd7U-0002VN-M8 for qemu-devel@nongnu.org; Fri, 04 May 2018 11:59:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fEd7T-0001TL-MX for qemu-devel@nongnu.org; Fri, 04 May 2018 11:59:40 -0400 Received: from mail-qt0-x241.google.com ([2607:f8b0:400d:c0d::241]:40071) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fEd7T-0001TD-I7 for qemu-devel@nongnu.org; Fri, 04 May 2018 11:59:39 -0400 Received: by mail-qt0-x241.google.com with SMTP id h2-v6so27972701qtp.7 for ; Fri, 04 May 2018 08:59:39 -0700 (PDT) Received: from x1.local ([138.117.48.222]) by smtp.gmail.com with ESMTPSA id a83sm8587066qkb.22.2018.05.04.08.59.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 May 2018 08:59:38 -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=tip5E7RafT6MoDrialGShF+ieHLTF658Lmvgy3Hq1K8=; b=h6N5Cmc/t2+FOIiNjXU8+Kr53YalwI1gvcqJz94KZ0dDtRu8Ecwu/jQf4MgfbEzLbu iYi3LzaL+sT6Mb43JghS5wqwfXcUvq+6CEFKpiH8W/+AZww9G07OU5s6GJtZL6NUjWih hkjZBsgndBicD5/2UY/S4G3do1FVpcg6L8AXhAeeFYoQiTu4EVmW1ubGQrqBbARnZwyG Gj+/Jh5N19yqv9xLWEAb6XrJfaW3eO4sAN+cy884lxNpOC/EnSJ1s8DbIfkIgPYNQvUj KAWiw17yfHunDjc4FThjqfKRG5hByMoa+0wemh6w2Kvk83nZ+ZRAVXaEqDOD2jdeo5qN WUIw== 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=tip5E7RafT6MoDrialGShF+ieHLTF658Lmvgy3Hq1K8=; b=taaMFI7Eeg9cIzIyXzJXl/JrJyNm/Z5tYdFIdzhv5yUh83pbUV2EsWmaKLGVWHxxS2 jQOA7x1uJKwD80L+xLsD9mAxwnIi6Ax25Y4ggvF+bmsDagVUU9qADYuEP1zuiCbvgLwN ETXUpFgULW16AbTuTTNoz1VZ4Qi5zfgOCXKFgIEB8NXm4FUtoUycDdMq5fHLkIcHfvKh dmPwP45fT3wmf7nVf+8KjyUrgl/ImeAVgBqAL7gfLlqquNMJhKc+doL8WTcgoU8MYvKf pGCOQOBm/h5GHr4nJAksbdo2Il9BPqvBW97dHRHusWmRdEEUHEPbFXF+Eb4VAvDX9eBt H20g== X-Gm-Message-State: ALQs6tAEMrFIgpw3UVohNWDmckzdsyvxsKOE+3fQDKjfPA+MKCGcefI4 T0Mr4sDy7IQgnbmCuLbUtzI= X-Google-Smtp-Source: AB8JxZrJEhVRDjY4PBLxHRJX0l3MJnBHI7G4mHW+m0fp41xTFLHg7bb5cgEbCCL3GiWrXxetP286DQ== X-Received: by 2002:a0c:989b:: with SMTP id f27-v6mr12274360qvd.115.1525449578911; Fri, 04 May 2018 08:59:38 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Peter Maydell , "Edgar E . Iglesias" Date: Fri, 4 May 2018 12:59:02 -0300 Message-Id: <20180504155918.21287-5-f4bug@amsat.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180504155918.21287-1-f4bug@amsat.org> References: <20180504155918.21287-1-f4bug@amsat.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: 2607:f8b0:400d:c0d::241 Subject: [Qemu-devel] [PATCH 04/20] sdcard: Add sd_prepare_request[_with_crc]() 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: , Cc: Paolo Bonzini , Alistair Francis , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Hajnoczi , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 The sd_prepare_request*() functions fill all the request frame members. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/sd/sd.h | 27 +++++++++++++++++++++++++++ hw/sd/sd.c | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/include/hw/sd/sd.h b/include/hw/sd/sd.h index f0b41232f7..7d9c906897 100644 --- a/include/hw/sd/sd.h +++ b/include/hw/sd/sd.h @@ -141,6 +141,33 @@ typedef struct { void (*set_readonly)(DeviceState *dev, bool readonly); } SDBusClass; =20 +/** + * sd_prepare_request: + * @req: the #SDRequest to be filled + * @cmd: the SD command + * @arg: the SD command argument + * @gen_crc: generates the frame CRC7 if true, else fill with zeroes + * + * Initialize a SD request buffer. + * + * If @gen_crc the frame checksum will be calculated + * and filled in the request buffer. + */ +void sd_prepare_request(SDRequest *req, uint8_t cmd, uint32_t arg, + bool gen_crc); + +/** + * sd_prepare_request_with_crc: + * @req: the #SDRequest to be filled + * @cmd: the SD command + * @arg: the SD command argument + * @crc: the calculated request CRC7 + * + * Initialize a SD request buffer. + */ +void sd_prepare_request_with_crc(SDRequest *req, uint8_t cmd, uint32_t arg, + uint8_t crc); + /* 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, diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 861bba197d..be75e118c0 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -489,10 +489,45 @@ static uint8_t sd_calc_frame48_crc7(uint8_t cmd, uint= 32_t arg) return sd_crc7(buffer, sizeof(buffer)); } =20 +static bool sd_verify_frame48_checksum(SDFrame48 *frame) +{ + uint8_t crc =3D sd_calc_frame48_crc7(frame->cmd, frame->arg); + + return crc =3D=3D frame->crc; +} + static int sd_req_crc_validate(SDRequest *req) { return 0; - return sd_calc_frame48_crc7(req->cmd, req->arg) !=3D req->crc; /* TODO= */ + return !sd_verify_frame48_checksum(req); /* TODO */ +} + +static void sd_update_frame48_checksum(SDFrame48 *frame) +{ + frame->crc =3D sd_calc_frame48_crc7(frame->cmd, frame->arg); +} + +static void sd_prepare_frame48(SDFrame48 *frame, uint8_t cmd, uint32_t arg, + bool gen_crc) +{ + frame->cmd =3D cmd; + frame->arg =3D arg; + frame->crc =3D 0x00; + if (gen_crc) { + sd_update_frame48_checksum(frame); + } +} + +void sd_prepare_request(SDFrame48 *req, uint8_t cmd, uint32_t arg, bool ge= n_crc) +{ + sd_prepare_frame48(req, cmd, arg, gen_crc); +} + +void sd_prepare_request_with_crc(SDRequest *req, uint8_t cmd, uint32_t arg, + uint8_t crc) +{ + sd_prepare_frame48(req, cmd, arg, /* gen_crc */ false); + req->crc =3D crc; } =20 static void sd_response_r1_make(SDState *sd, uint8_t *response) --=20 2.17.0