From patchwork Thu Feb 22 15:22:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 129267 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp2142799edc; Thu, 22 Feb 2018 07:31:01 -0800 (PST) X-Google-Smtp-Source: AH8x2256z9DsQjWUg104As50tTlKCpm+gws1sidvxKL5ZiMK4SaMk0/BPm5kkCfB4ikiTmppnInW X-Received: by 10.13.216.194 with SMTP id a185mr3832964ywe.193.1519313461144; Thu, 22 Feb 2018 07:31:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519313461; cv=none; d=google.com; s=arc-20160816; b=ypeGGzBkXtLoF8JH9gIUZCWDF1qf4TwZbTJCcwWnb+HQSTbXveY6a4bsgMmcKO+8J8 Vt3TWNtX5JXN3o6LzlU7MtRjDO4eR8owlAyKDFfEFZHD37fwSRPZt8y0t+OvKJ7R8zoT qU6nIJloh0QEAniT909TRKQrKYBWl0PVF+y1OgRme0RILoca5xVyHT1XcvUhQ06rc4bz QiRQkzA4X1yrSGLdGxvuckB1PHqfywlVsvMfTlDGLGPuKs/MnVsANTwSIAODqwrKEyWS hv+cvMlNoKl52TYhrfd1c4pijJFbJHKSj/9OD+2/+SP1yDUqd0TH+tKf5MIk2M9H4lht iOsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:arc-authentication-results; bh=aOKsmrRxjPaEdflSiyd6GbC9NRgL9h6UsSYRyoyfFFo=; b=cT+vEKj2p6GV8n9fBIhZNH3M6l1RKZN1jVAu7TnIIOLSGtGc/+ojhWxDHsOjTE3XrF 6yckH/c24jqwERPQ6m7ukKCb2onFwsRZFQ6ItrdzNqgJjIYDmtenW25nIRCS/Y1txJeX 9L/wl2sXJ13Ip5KcjTJI9OxKkvyeXa56fe1ouyCTqLuuw193kKb3Iwcdpf9O46exm5jK zIlVnumLIbnignwfL5XAOQVsK7hzegrlIqfWfp4ytqh1OQ45fMInJ0e4MyjdbnUgsP8h 1h2LyJm2qRqEacSn5HHBTT5UsXn/F+D8blLo55jX06tsfmBoMf1+/J1Y4i9fx9gw/2RK IPlw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id d66-v6si49427ybb.222.2018.02.22.07.31.00 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 22 Feb 2018 07:31:01 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:39010 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eospo-000370-Gn for patch@linaro.org; Thu, 22 Feb 2018 10:31:00 -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 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Philippe Mathieu-Daudé the code is easier to review/refactor. Signed-off-by: Philippe Mathieu-Daudé 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(-) -- 2.16.1 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] = 0x40 | req->cmd; - buffer[1] = (req->arg >> 24) & 0xff; - buffer[2] = (req->arg >> 16) & 0xff; - buffer[3] = (req->arg >> 8) & 0xff; - buffer[4] = (req->arg >> 0) & 0xff; + stl_be_p(&buffer[1], req->arg); return 0; return sd_crc7(buffer, 5) != req->crc; /* TODO */ } static void sd_response_r1_make(SDState *sd, uint8_t *response) { - uint32_t status = sd->card_status; + stl_be_p(response, sd->card_status); + /* Clear the "clear on read" status bits */ sd->card_status &= ~CARD_STATUS_C; - - response[0] = (status >> 24) & 0xff; - response[1] = (status >> 16) & 0xff; - response[2] = (status >> 8) & 0xff; - response[3] = (status >> 0) & 0xff; } static void sd_response_r3_make(SDState *sd, uint8_t *response) { - response[0] = (sd->ocr >> 24) & 0xff; - response[1] = (sd->ocr >> 16) & 0xff; - response[2] = (sd->ocr >> 8) & 0xff; - response[3] = (sd->ocr >> 0) & 0xff; + stl_be_p(response, sd->ocr); } static void sd_response_r6_make(SDState *sd, uint8_t *response) { - uint16_t arg; uint16_t status; - arg = sd->rca; status = ((sd->card_status >> 8) & 0xc000) | ((sd->card_status >> 6) & 0x2000) | (sd->card_status & 0x1fff); sd->card_status &= ~(CARD_STATUS_C & 0xc81fff); - - response[0] = (arg >> 8) & 0xff; - response[1] = arg & 0xff; - response[2] = (status >> 8) & 0xff; - response[3] = status & 0xff; + stw_be_p(response + 0, sd->rca); + stw_be_p(response + 2, status); } static void sd_response_r7_make(SDState *sd, uint8_t *response) { - response[0] = (sd->vhs >> 24) & 0xff; - response[1] = (sd->vhs >> 16) & 0xff; - response[2] = (sd->vhs >> 8) & 0xff; - response[3] = (sd->vhs >> 0) & 0xff; + stl_be_p(response, sd->vhs); } 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) static void sd_function_switch(SDState *sd, uint32_t arg) { - int i, mode, new_func, crc; + int i, mode, new_func; mode = !!(arg & 0x80000000); sd->data[0] = 0x00; /* Maximum current consumption */ @@ -751,9 +733,7 @@ static void sd_function_switch(SDState *sd, uint32_t arg) sd->data[14 + (i >> 1)] = new_func << ((i * 4) & 4); } memset(&sd->data[17], 0, 47); - crc = sd_crc16(sd->data, 64); - sd->data[65] = crc >> 8; - sd->data[66] = crc & 0xff; + stw_be_p(sd->data + 65, sd_crc16(sd->data, 64)); } static inline bool sd_wp_addr(SDState *sd, uint64_t addr)