From patchwork Tue Feb 13 04:07:46 2018 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: 872570 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="tUvCWWAD"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zgTfJ6gX1z9s7v for ; Tue, 13 Feb 2018 15:12:56 +1100 (AEDT) Received: from localhost ([::1]:37380 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1elRxe-0003n5-U2 for incoming@patchwork.ozlabs.org; Mon, 12 Feb 2018 23:12:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52618) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1elRtb-0000n9-19 for qemu-devel@nongnu.org; Mon, 12 Feb 2018 23:08:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1elRtZ-0007ZU-Q8 for qemu-devel@nongnu.org; Mon, 12 Feb 2018 23:08:43 -0500 Received: from mail-qt0-x241.google.com ([2607:f8b0:400d:c0d::241]:39278) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1elRtZ-0007ZG-KU for qemu-devel@nongnu.org; Mon, 12 Feb 2018 23:08:41 -0500 Received: by mail-qt0-x241.google.com with SMTP id f4so2229367qtj.6 for ; Mon, 12 Feb 2018 20:08:41 -0800 (PST) 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=fIxg5fEdAV5AYm4UaAC8xvRG6zbVJk07FMpliAZ8/n0=; b=tUvCWWADN0Zmy8B+ZQ5K4sdU6Oa5z9tXzOvERdPPNMeWw+0Nj2iegThxS3lHJf8Izp t+kmYhkFRRzrP1ZEeksGDvFnbKQ5YagiaP4QFfq5AQ38jVPhRaCVs1KIngx18SAk8ekY l4/doRnUG2aEAPv9P2q5cB7lmoqD8eo1qDVL90jl6+bowk/JwFb8roCn5ieM3Boykj4M 8MYHcBL76zPYZmzX1VRbbEey0gEV+CKKJ5/9WPDfxy+X8E+YjDhzKR9Y8+Iq99UYDVUj QuAM4ZRP1Y5uVYL96MGCtCYa5XpNqZu2ClzH6Wca2lZaSwUflzUgd9WojWxa3c+gf8rW dcNA== 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=fIxg5fEdAV5AYm4UaAC8xvRG6zbVJk07FMpliAZ8/n0=; b=GPFo8Gqo9SPUboEbZ8N1Qx1NyZVdCfR1rY8v7lY7LbjKhBF//Il0Bh1WiWQIJGFNxd jqoOOcqmTQ7m+KodwLIAJk8GwmXIhdF1Ciy4OPIFpfE056YJEqIl4J44ilFAzwWXtB5j YqmaCNSWPk2uZPIdxa+4c7sX7favADByKoVtaUv2WInDHUY0KFV/u1eq4uujchMdalrd B6EyqXyDyYFRxDxsuafst5Cfb6QzkjVw+ac9ygSAmqhnqKxCYkx/lMq3bwuO+u0QQ/5K CG78qnprx2y7exLUsc0VMI87FDpyBvRCq4nR/C2K9+6/3crjTV0+qG5A8ZHROzxll3xh d+GA== X-Gm-Message-State: APf1xPCiQWWb0jTNkm2JGcHmpsWYWiPnZsDzbfpaEMif2JT8SZ55KX3s X7+WWWOxGiXPxC3Xg74EU7c= X-Google-Smtp-Source: AH8x226K2H/XWtz+enImnEueBlj9nXINL80jghFlB3T0gUA8o4FpIlOXQ/PwR1B9/Tc7O1D3TLFUng== X-Received: by 10.237.53.195 with SMTP id d3mr2768370qte.276.1518494921056; Mon, 12 Feb 2018 20:08:41 -0800 (PST) Received: from x1.local ([138.117.48.219]) by smtp.gmail.com with ESMTPSA id q2sm7350435qki.10.2018.02.12.20.08.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Feb 2018 20:08:40 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: Paolo Bonzini Date: Tue, 13 Feb 2018 01:07:46 -0300 Message-Id: <20180213040809.26021-8-f4bug@amsat.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180213040809.26021-1-f4bug@amsat.org> References: <20180213040809.26021-1-f4bug@amsat.org> MIME-Version: 1.0 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 v13 07/30] sdhci: add a 'spec_version property' (default to v2) 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: "Edgar E . Iglesias" , Peter Maydell , Fam Zheng , qemu-devel@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Alistair Francis Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Alistair Francis --- hw/sd/sdhci-internal.h | 4 ++-- include/hw/sd/sdhci.h | 2 ++ hw/sd/sdhci.c | 27 +++++++++++++++++++++++---- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/hw/sd/sdhci-internal.h b/hw/sd/sdhci-internal.h index 0991acd724..64556480a9 100644 --- a/hw/sd/sdhci-internal.h +++ b/hw/sd/sdhci-internal.h @@ -216,9 +216,9 @@ /* Slot interrupt status */ #define SDHC_SLOT_INT_STATUS 0xFC -/* HWInit Host Controller Version Register 0x0401 */ +/* HWInit Host Controller Version Register */ #define SDHC_HCVER 0xFE -#define SD_HOST_SPECv2_VERS 0x2401 +#define SDHC_HCVER_VENDOR 0x24 #define SDHC_REGISTERS_MAP_SIZE 0x100 #define SDHC_INSERTION_DELAY (NANOSECONDS_PER_SECOND) diff --git a/include/hw/sd/sdhci.h b/include/hw/sd/sdhci.h index f8d1ba3538..2a26b46f05 100644 --- a/include/hw/sd/sdhci.h +++ b/include/hw/sd/sdhci.h @@ -78,6 +78,7 @@ typedef struct SDHCIState { /* Read-only registers */ uint64_t capareg; /* Capabilities Register */ uint64_t maxcurr; /* Maximum Current Capabilities Register */ + uint16_t version; /* Host Controller Version Register */ uint8_t *fifo_buffer; /* SD host i/o FIFO buffer */ uint32_t buf_maxsz; @@ -93,6 +94,7 @@ typedef struct SDHCIState { /* Configurable properties */ bool pending_insert_quirk; /* Quirk for Raspberry Pi card insert int */ uint32_t quirks; + uint8_t sd_spec_version; } SDHCIState; /* diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c index 3602286f46..17a1348f0f 100644 --- a/hw/sd/sdhci.c +++ b/hw/sd/sdhci.c @@ -173,7 +173,8 @@ static void sdhci_reset(SDHCIState *s) timer_del(s->insert_timer); timer_del(s->transfer_timer); - /* Set all registers to 0. Capabilities registers are not cleared + + /* Set all registers to 0. Capabilities/Version registers are not cleared * and assumed to always preserve their value, given to them during * initialization */ memset(&s->sdmasysad, 0, (uintptr_t)&s->capareg - (uintptr_t)&s->sdmasysad); @@ -918,7 +919,7 @@ static uint64_t sdhci_read(void *opaque, hwaddr offset, unsigned size) ret = (uint32_t)(s->admasysaddr >> 32); break; case SDHC_SLOT_INT_STATUS: - ret = (SD_HOST_SPECv2_VERS << 16) | sdhci_slotint(s); + ret = (s->version << 16) | sdhci_slotint(s); break; default: qemu_log_mask(LOG_UNIMP, "SDHC rd_%ub @0x%02" HWADDR_PRIx " " @@ -1174,11 +1175,22 @@ static inline unsigned int sdhci_get_fifolen(SDHCIState *s) } } +static void sdhci_init_readonly_registers(SDHCIState *s, Error **errp) +{ + if (s->sd_spec_version != 2) { + error_setg(errp, "Only Spec v2 is supported"); + return; + } + s->version = (SDHC_HCVER_VENDOR << 8) | (s->sd_spec_version - 1); +} + /* --- qdev common --- */ #define DEFINE_SDHCI_COMMON_PROPERTIES(_state) \ - /* Capabilities registers provide information on supported features - * of this specific host controller implementation */ \ + DEFINE_PROP_UINT8("sd-spec-version", _state, sd_spec_version, 2), \ + \ + /* Capabilities registers provide information on supported + * features of this specific host controller implementation */ \ DEFINE_PROP_UINT64("capareg", _state, capareg, SDHC_CAPAB_REG_DEFAULT), \ DEFINE_PROP_UINT64("maxcurr", _state, maxcurr, 0) @@ -1206,6 +1218,13 @@ static void sdhci_uninitfn(SDHCIState *s) static void sdhci_common_realize(SDHCIState *s, Error **errp) { + Error *local_err = NULL; + + sdhci_init_readonly_registers(s, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } s->buf_maxsz = sdhci_get_fifolen(s); s->fifo_buffer = g_malloc0(s->buf_maxsz);