From nobody Wed Apr 16 16:47:02 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519313268432204.77794030480754; Thu, 22 Feb 2018 07:27:48 -0800 (PST) Received: from localhost ([::1]:38989 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosmh-0008Pi-BT for importer@patchew.org; Thu, 22 Feb 2018 10:27:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38281) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosiV-0004hI-HY for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosiP-0001XT-MR for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:27 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46584) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosiP-0001RM-Dm for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:21 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosiL-00020I-Ui for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:17 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:22:36 +0000 Message-Id: <20180222152307.7499-2-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 01/32] target/arm: Fix register definitions for VMIDR and VMPIDR 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 The register definitions for VMIDR and VMPIDR have separate reginfo structs for the AArch32 and AArch64 registers. However the 32-bit versions are wrong: * they use offsetof instead of offsetoflow32 to mark where the 32-bit value lives in the uint64_t CPU state field * they don't mark themselves as ARM_CP_ALIAS In particular this means that if you try to use an Arm guest CPU which enables EL2 on a big-endian host it will assert at reset: target/arm/cpu.c:114: cp_reg_check_reset: Assertion `oldvalue =3D=3D newva= lue' failed. because the reset of the 32-bit register writes to the top half of the uint64_t. Correct the errors in the structures. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- This is necessary for 'make check' to pass on big endian systems with the 'raspi3' board enabled, which is the first board which has an EL2-enabled-by-default CPU. --- target/arm/helper.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index 32e4fd4732..c5bc69b961 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -5069,8 +5069,8 @@ void register_cp_regs_for_features(ARMCPU *cpu) { .name =3D "VPIDR", .state =3D ARM_CP_STATE_AA32, .cp =3D 15, .opc1 =3D 4, .crn =3D 0, .crm =3D 0, .opc2 =3D 0, .access =3D PL2_RW, .accessfn =3D access_el3_aa32ns, - .resetvalue =3D cpu->midr, - .fieldoffset =3D offsetof(CPUARMState, cp15.vpidr_el2) }, + .resetvalue =3D cpu->midr, .type =3D ARM_CP_ALIAS, + .fieldoffset =3D offsetoflow32(CPUARMState, cp15.vpidr_el2) = }, { .name =3D "VPIDR_EL2", .state =3D ARM_CP_STATE_AA64, .opc0 =3D 3, .opc1 =3D 4, .crn =3D 0, .crm =3D 0, .opc2 =3D = 0, .access =3D PL2_RW, .resetvalue =3D cpu->midr, @@ -5078,8 +5078,8 @@ void register_cp_regs_for_features(ARMCPU *cpu) { .name =3D "VMPIDR", .state =3D ARM_CP_STATE_AA32, .cp =3D 15, .opc1 =3D 4, .crn =3D 0, .crm =3D 0, .opc2 =3D 5, .access =3D PL2_RW, .accessfn =3D access_el3_aa32ns, - .resetvalue =3D vmpidr_def, - .fieldoffset =3D offsetof(CPUARMState, cp15.vmpidr_el2) }, + .resetvalue =3D vmpidr_def, .type =3D ARM_CP_ALIAS, + .fieldoffset =3D offsetoflow32(CPUARMState, cp15.vmpidr_el2)= }, { .name =3D "VMPIDR_EL2", .state =3D ARM_CP_STATE_AA64, .opc0 =3D 3, .opc1 =3D 4, .crn =3D 0, .crm =3D 0, .opc2 =3D = 5, .access =3D PL2_RW, --=20 2.16.1 From nobody Wed Apr 16 16:47:02 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 151931327613278.48461062343631; Thu, 22 Feb 2018 07:27:56 -0800 (PST) Received: from localhost ([::1]:38991 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosmp-0008W1-9f for importer@patchew.org; Thu, 22 Feb 2018 10:27:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38252) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosiU-0004gB-20 for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosiS-0001Z6-Ah for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:26 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46586) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosiS-0001Ye-0w for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:24 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosiR-00020Z-2M for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:23 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:22:37 +0000 Message-Id: <20180222152307.7499-3-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 02/32] raspi: Add "raspi3" machine type 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: Pekka Enberg This patch adds a "raspi3" machine type, which can now be selected as the machine to run on by users via the "-M" command line option to QEMU. The machine type does *not* ignore memory transaction failures so we likely need to add some dummy devices later when people run something more complicated than what I'm using for testing. Signed-off-by: Pekka Enberg [PMM: added #ifdef TARGET_AARCH64 so we don't provide the 64-bit board in the 32-bit only arm-softmmu build.] Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Peter Maydell --- hw/arm/raspi.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c index 93121c56bf..a37881433c 100644 --- a/hw/arm/raspi.c +++ b/hw/arm/raspi.c @@ -187,3 +187,26 @@ static void raspi2_machine_init(MachineClass *mc) mc->ignore_memory_transaction_failures =3D true; }; DEFINE_MACHINE("raspi2", raspi2_machine_init) + +#ifdef TARGET_AARCH64 +static void raspi3_init(MachineState *machine) +{ + raspi_init(machine, 3); +} + +static void raspi3_machine_init(MachineClass *mc) +{ + mc->desc =3D "Raspberry Pi 3"; + mc->init =3D raspi3_init; + mc->block_default_type =3D IF_SD; + mc->no_parallel =3D 1; + mc->no_floppy =3D 1; + mc->no_cdrom =3D 1; + mc->default_cpu_type =3D ARM_CPU_TYPE_NAME("cortex-a53"); + mc->max_cpus =3D BCM2836_NCPUS; + mc->min_cpus =3D BCM2836_NCPUS; + mc->default_cpus =3D BCM2836_NCPUS; + mc->default_ram_size =3D 1024 * 1024 * 1024; +} +DEFINE_MACHINE("raspi3", raspi3_machine_init) +#endif --=20 2.16.1 From nobody Wed Apr 16 16:47:02 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 1519313119360722.8850160013835; Thu, 22 Feb 2018 07:25:19 -0800 (PST) Received: from localhost ([::1]:38972 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eoskI-0005ye-6t for importer@patchew.org; Thu, 22 Feb 2018 10:25:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38257) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosiU-0004gU-Ft for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosiT-0001Zi-7g for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:26 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46586) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosiT-0001Ye-0f for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:25 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosiR-00020n-QU for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:23 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:22:38 +0000 Message-Id: <20180222152307.7499-4-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> 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 03/32] hw/char/stm32f2xx_usart: fix TXE/TC bit handling 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 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Richard Braun I/O currently being synchronous, there is no reason to ever clear the SR_TXE bit. However the SR_TC bit may be cleared by software writing to the SR register, so set it on each write. In addition, fix the reset value of the USART status register. Signed-off-by: Richard Braun Reviewed-by: Alistair Francis [PMM: removed XXX tag from comment, since it isn't something we need to come back and fix in QEMU] Signed-off-by: Peter Maydell --- include/hw/char/stm32f2xx_usart.h | 7 ++++++- hw/char/stm32f2xx_usart.c | 12 ++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/include/hw/char/stm32f2xx_usart.h b/include/hw/char/stm32f2xx_= usart.h index 9d03a7527c..84c4029777 100644 --- a/include/hw/char/stm32f2xx_usart.h +++ b/include/hw/char/stm32f2xx_usart.h @@ -37,7 +37,12 @@ #define USART_CR3 0x14 #define USART_GTPR 0x18 =20 -#define USART_SR_RESET 0x00C00000 +/* + * NB: The reset value mentioned in "24.6.1 Status register" seems bogus. + * Looking at "Table 98 USART register map and reset values", it seems it + * should be 0xc0, and that's how real hardware behaves. + */ +#define USART_SR_RESET (USART_SR_TXE | USART_SR_TC) =20 #define USART_SR_TXE (1 << 7) #define USART_SR_TC (1 << 6) diff --git a/hw/char/stm32f2xx_usart.c b/hw/char/stm32f2xx_usart.c index 07b462d4b6..032b5fda13 100644 --- a/hw/char/stm32f2xx_usart.c +++ b/hw/char/stm32f2xx_usart.c @@ -96,12 +96,10 @@ static uint64_t stm32f2xx_usart_read(void *opaque, hwad= dr addr, switch (addr) { case USART_SR: retvalue =3D s->usart_sr; - s->usart_sr &=3D ~USART_SR_TC; qemu_chr_fe_accept_input(&s->chr); return retvalue; case USART_DR: DB_PRINT("Value: 0x%" PRIx32 ", %c\n", s->usart_dr, (char) s->usar= t_dr); - s->usart_sr |=3D USART_SR_TXE; s->usart_sr &=3D ~USART_SR_RXNE; qemu_chr_fe_accept_input(&s->chr); qemu_set_irq(s->irq, 0); @@ -137,7 +135,9 @@ static void stm32f2xx_usart_write(void *opaque, hwaddr = addr, switch (addr) { case USART_SR: if (value <=3D 0x3FF) { - s->usart_sr =3D value; + /* I/O being synchronous, TXE is always set. In addition, it m= ay + only be set by hardware, so keep it set here. */ + s->usart_sr =3D value | USART_SR_TXE; } else { s->usart_sr &=3D value; } @@ -151,8 +151,12 @@ static void stm32f2xx_usart_write(void *opaque, hwaddr= addr, /* XXX this blocks entire thread. Rewrite to use * qemu_chr_fe_write and background I/O callbacks */ qemu_chr_fe_write_all(&s->chr, &ch, 1); + /* XXX I/O are currently synchronous, making it impossible for + software to observe transient states where TXE or TC aren't + set. Unlike TXE however, which is read-only, software may + clear TC by writing 0 to the SR register, so set it again + on each write. */ s->usart_sr |=3D USART_SR_TC; - s->usart_sr &=3D ~USART_SR_TXE; } return; case USART_BRR: --=20 2.16.1 From nobody Wed Apr 16 16:47:02 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519313273366204.35696420155125; Thu, 22 Feb 2018 07:27:53 -0800 (PST) Received: from localhost ([::1]:38990 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosmm-0008Tq-Im for importer@patchew.org; Thu, 22 Feb 2018 10:27:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38268) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosiU-0004gt-W4 for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosiT-0001a0-PP for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:26 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46588) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosiT-0001ZQ-HQ for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:25 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosiS-000213-Iy for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:24 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:22:39 +0000 Message-Id: <20180222152307.7499-5-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 04/32] Fix ast2500 protection register emulation 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: Hugo Landau Some register blocks of the ast2500 are protected by protection key registers which require the right magic value to be written to those registers to allow those registers to be mutated. Register manuals indicate that writing the correct magic value to these registers should cause subsequent reads from those values to return 1, and writing any other value should cause subsequent reads to return 0. Previously, qemu implemented these registers incorrectly: the registers were handled as simple memory, meaning that writing some value x to a protection key register would result in subsequent reads from that register returning the same value x. The protection was implemented by ensuring that the current value of that register equaled the magic value. This modifies qemu to have the correct behaviour: attempts to write to a ast2500 protection register results in a transition to 1 or 0 depending on whether the written value is the correct magic. The protection logic is updated to ensure that the value of the register is nonzero. This bug caused deadlocks with u-boot HEAD: when u-boot is done with a protectable register block, it attempts to lock it by writing the bitwise inverse of the correct magic value, and then spinning forever until the register reads as zero. Since qemu implemented writes to these registers as ordinary memory writes, writing the inverse of the magic value resulted in subsequent reads returning that value, leading to u-boot spinning forever. Signed-off-by: Hugo Landau Reviewed-by: C=C3=A9dric Le Goater Acked-by: Andrew Jeffery Message-id: 20180220132627.4163-1-hlandau@devever.net [PMM: fixed incorrect code indentation] Signed-off-by: Peter Maydell --- hw/misc/aspeed_scu.c | 6 +++++- hw/misc/aspeed_sdmc.c | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/hw/misc/aspeed_scu.c b/hw/misc/aspeed_scu.c index 74537ce975..5e6d5744ee 100644 --- a/hw/misc/aspeed_scu.c +++ b/hw/misc/aspeed_scu.c @@ -191,7 +191,7 @@ static void aspeed_scu_write(void *opaque, hwaddr offse= t, uint64_t data, } =20 if (reg > PROT_KEY && reg < CPU2_BASE_SEG1 && - s->regs[PROT_KEY] !=3D ASPEED_SCU_PROT_KEY) { + !s->regs[PROT_KEY]) { qemu_log_mask(LOG_GUEST_ERROR, "%s: SCU is locked!\n", __func__); return; } @@ -199,6 +199,10 @@ static void aspeed_scu_write(void *opaque, hwaddr offs= et, uint64_t data, trace_aspeed_scu_write(offset, size, data); =20 switch (reg) { + case PROT_KEY: + s->regs[reg] =3D (data =3D=3D ASPEED_SCU_PROT_KEY) ? 1 : 0; + return; + case FREQ_CNTR_EVAL: case VGA_SCRATCH1 ... VGA_SCRATCH8: case RNG_DATA: diff --git a/hw/misc/aspeed_sdmc.c b/hw/misc/aspeed_sdmc.c index f0b3053fae..0df008e52a 100644 --- a/hw/misc/aspeed_sdmc.c +++ b/hw/misc/aspeed_sdmc.c @@ -110,7 +110,12 @@ static void aspeed_sdmc_write(void *opaque, hwaddr add= r, uint64_t data, return; } =20 - if (addr !=3D R_PROT && s->regs[R_PROT] !=3D PROT_KEY_UNLOCK) { + if (addr =3D=3D R_PROT) { + s->regs[addr] =3D (data =3D=3D PROT_KEY_UNLOCK) ? 1 : 0; + return; + } + + if (!s->regs[R_PROT]) { qemu_log_mask(LOG_GUEST_ERROR, "%s: SDMC is locked!\n", __func__); return; } @@ -123,6 +128,7 @@ static void aspeed_sdmc_write(void *opaque, hwaddr addr= , uint64_t data, data &=3D ~ASPEED_SDMC_READONLY_MASK; break; case AST2500_A0_SILICON_REV: + case AST2500_A1_SILICON_REV: data &=3D ~ASPEED_SDMC_AST2500_READONLY_MASK; break; default: --=20 2.16.1 From nobody Wed Apr 16 16:47:02 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519313125199560.3424528597918; Thu, 22 Feb 2018 07:25:25 -0800 (PST) Received: from localhost ([::1]:38973 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eoskK-00060q-7k for importer@patchew.org; Thu, 22 Feb 2018 10:25:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38284) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosiV-0004hX-SJ for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosiU-0001ae-Oi for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:27 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46590) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosiU-0001a9-Hp for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:26 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosiT-00021I-JQ for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:25 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:22:40 +0000 Message-Id: <20180222152307.7499-6-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 05/32] hw/sd/milkymist-memcard: use qemu_log_mask() 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 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Acked-by: Michael Walle Message-id: 20180216022933.10945-2-f4bug@amsat.org Signed-off-by: Peter Maydell --- hw/sd/milkymist-memcard.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/hw/sd/milkymist-memcard.c b/hw/sd/milkymist-memcard.c index 341da88552..1292c0c099 100644 --- a/hw/sd/milkymist-memcard.c +++ b/hw/sd/milkymist-memcard.c @@ -22,11 +22,12 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/log.h" #include "hw/hw.h" #include "hw/sysbus.h" #include "sysemu/sysemu.h" #include "trace.h" -#include "qemu/error-report.h" +#include "include/qapi/error.h" #include "sysemu/block-backend.h" #include "sysemu/blockdev.h" #include "hw/sd/sd.h" @@ -138,8 +139,8 @@ static uint64_t memcard_read(void *opaque, hwaddr addr, } else { r =3D s->response[s->response_read_ptr++]; if (s->response_read_ptr > s->response_len) { - error_report("milkymist_memcard: " - "read more cmd bytes than available. Clipping."); + qemu_log_mask(LOG_GUEST_ERROR, "milkymist_memcard: " + "read more cmd bytes than available. Clippin= g."); s->response_read_ptr =3D 0; } } @@ -163,8 +164,9 @@ static uint64_t memcard_read(void *opaque, hwaddr addr, break; =20 default: - error_report("milkymist_memcard: read access to unknown register 0= x" - TARGET_FMT_plx, addr << 2); + qemu_log_mask(LOG_UNIMP, "milkymist_memcard: " + "read access to unknown register 0x%" HWADDR_PRIx "\= n", + addr << 2); break; } =20 @@ -220,8 +222,9 @@ static void memcard_write(void *opaque, hwaddr addr, ui= nt64_t value, break; =20 default: - error_report("milkymist_memcard: write access to unknown register = 0x" - TARGET_FMT_plx, addr << 2); + qemu_log_mask(LOG_UNIMP, "milkymist_memcard: " + "write access to unknown register 0x%" HWADDR_PRIx "= " + "(value 0x%" PRIx64 ")\n", addr << 2, value); break; } } --=20 2.16.1 From nobody Wed Apr 16 16:47:02 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519313442369666.8510134537113; Thu, 22 Feb 2018 07:30:42 -0800 (PST) Received: from localhost ([::1]:39002 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eospK-0002RY-Q9 for importer@patchew.org; Thu, 22 Feb 2018 10:30:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38305) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosiW-0004i4-MV for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosiV-0001bR-MQ for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:28 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46590) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosiV-0001a9-FU for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:27 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosiU-00021W-CA for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:26 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:22:41 +0000 Message-Id: <20180222152307.7499-7-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 06/32] hw/sd/milkymist-memcard: split realize() out of SysBusDevice init() 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 Create the SDCard in the realize() function. Suggested-by: Michael Walle Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Acked-by: Michael Walle Message-id: 20180216022933.10945-3-f4bug@amsat.org Signed-off-by: Peter Maydell --- hw/sd/milkymist-memcard.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/hw/sd/milkymist-memcard.c b/hw/sd/milkymist-memcard.c index 1292c0c099..a8e65892c7 100644 --- a/hw/sd/milkymist-memcard.c +++ b/hw/sd/milkymist-memcard.c @@ -257,27 +257,31 @@ static void milkymist_memcard_reset(DeviceState *d) device_reset(DEVICE(s->card)); } =20 -static int milkymist_memcard_init(SysBusDevice *dev) +static void milkymist_memcard_init(Object *obj) +{ + MilkymistMemcardState *s =3D MILKYMIST_MEMCARD(obj); + SysBusDevice *dev =3D SYS_BUS_DEVICE(obj); + + memory_region_init_io(&s->regs_region, OBJECT(s), &memcard_mmio_ops, s, + "milkymist-memcard", R_MAX * 4); + sysbus_init_mmio(dev, &s->regs_region); +} + +static void milkymist_memcard_realize(DeviceState *dev, Error **errp) { MilkymistMemcardState *s =3D MILKYMIST_MEMCARD(dev); - DriveInfo *dinfo; BlockBackend *blk; + DriveInfo *dinfo; =20 /* FIXME use a qdev drive property instead of drive_get_next() */ dinfo =3D drive_get_next(IF_SD); blk =3D dinfo ? blk_by_legacy_dinfo(dinfo) : NULL; s->card =3D sd_init(blk, false); if (s->card =3D=3D NULL) { - return -1; + error_setg(errp, "failed to init SD card"); + return; } - s->enabled =3D blk && blk_is_inserted(blk); - - memory_region_init_io(&s->regs_region, OBJECT(s), &memcard_mmio_ops, s, - "milkymist-memcard", R_MAX * 4); - sysbus_init_mmio(dev, &s->regs_region); - - return 0; } =20 static const VMStateDescription vmstate_milkymist_memcard =3D { @@ -300,9 +304,8 @@ static const VMStateDescription vmstate_milkymist_memca= rd =3D { static void milkymist_memcard_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); - SysBusDeviceClass *k =3D SYS_BUS_DEVICE_CLASS(klass); =20 - k->init =3D milkymist_memcard_init; + dc->realize =3D milkymist_memcard_realize; dc->reset =3D milkymist_memcard_reset; dc->vmsd =3D &vmstate_milkymist_memcard; /* Reason: init() method uses drive_get_next() */ @@ -313,6 +316,7 @@ static const TypeInfo milkymist_memcard_info =3D { .name =3D TYPE_MILKYMIST_MEMCARD, .parent =3D TYPE_SYS_BUS_DEVICE, .instance_size =3D sizeof(MilkymistMemcardState), + .instance_init =3D milkymist_memcard_init, .class_init =3D milkymist_memcard_class_init, }; =20 --=20 2.16.1 From nobody Wed Apr 16 16:47:02 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519313429328233.36832537930104; Thu, 22 Feb 2018 07:30:29 -0800 (PST) Received: from localhost ([::1]:39001 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eospF-0002NP-3H for importer@patchew.org; Thu, 22 Feb 2018 10:30:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38315) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosiX-0004ip-B0 for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosiW-0001bk-9L for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:29 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46592) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosiW-0001b9-1x for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:28 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosiV-00021n-4o for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:27 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:22:42 +0000 Message-Id: <20180222152307.7499-8-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 07/32] hw/sd/milkymist-memcard: expose a SDBus and connect the SDCard to it 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 using the sdbus_*() API. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Acked-by: Michael Walle Message-id: 20180216022933.10945-4-f4bug@amsat.org Signed-off-by: Peter Maydell --- hw/sd/milkymist-memcard.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/hw/sd/milkymist-memcard.c b/hw/sd/milkymist-memcard.c index a8e65892c7..5570c1e9a0 100644 --- a/hw/sd/milkymist-memcard.c +++ b/hw/sd/milkymist-memcard.c @@ -69,7 +69,7 @@ struct MilkymistMemcardState { SysBusDevice parent_obj; =20 MemoryRegion regs_region; - SDState *card; + SDBus sdbus; =20 int command_write_ptr; int response_read_ptr; @@ -105,7 +105,7 @@ static void memcard_sd_command(MilkymistMemcardState *s) req.crc =3D s->command[5]; =20 s->response[0] =3D req.cmd; - s->response_len =3D sd_do_command(s->card, &req, s->response+1); + s->response_len =3D sdbus_do_command(&s->sdbus, &req, s->response + 1); s->response_read_ptr =3D 0; =20 if (s->response_len =3D=3D 16) { @@ -150,10 +150,10 @@ static uint64_t memcard_read(void *opaque, hwaddr add= r, r =3D 0xffffffff; } else { r =3D 0; - r |=3D sd_read_data(s->card) << 24; - r |=3D sd_read_data(s->card) << 16; - r |=3D sd_read_data(s->card) << 8; - r |=3D sd_read_data(s->card); + r |=3D sdbus_read_data(&s->sdbus) << 24; + r |=3D sdbus_read_data(&s->sdbus) << 16; + r |=3D sdbus_read_data(&s->sdbus) << 8; + r |=3D sdbus_read_data(&s->sdbus); } break; case R_CLK2XDIV: @@ -207,10 +207,10 @@ static void memcard_write(void *opaque, hwaddr addr, = uint64_t value, if (!s->enabled) { break; } - sd_write_data(s->card, (value >> 24) & 0xff); - sd_write_data(s->card, (value >> 16) & 0xff); - sd_write_data(s->card, (value >> 8) & 0xff); - sd_write_data(s->card, value & 0xff); + sdbus_write_data(&s->sdbus, (value >> 24) & 0xff); + sdbus_write_data(&s->sdbus, (value >> 16) & 0xff); + sdbus_write_data(&s->sdbus, (value >> 8) & 0xff); + sdbus_write_data(&s->sdbus, value & 0xff); break; case R_ENABLE: s->regs[addr] =3D value; @@ -251,10 +251,6 @@ static void milkymist_memcard_reset(DeviceState *d) for (i =3D 0; i < R_MAX; i++) { s->regs[i] =3D 0; } - /* Since we're still using the legacy SD API the card is not plugged - * into any bus, and we must reset it manually. - */ - device_reset(DEVICE(s->card)); } =20 static void milkymist_memcard_init(Object *obj) @@ -270,15 +266,23 @@ static void milkymist_memcard_init(Object *obj) static void milkymist_memcard_realize(DeviceState *dev, Error **errp) { MilkymistMemcardState *s =3D MILKYMIST_MEMCARD(dev); + DeviceState *carddev; BlockBackend *blk; DriveInfo *dinfo; + Error *err =3D NULL; =20 + qbus_create_inplace(&s->sdbus, sizeof(s->sdbus), TYPE_SD_BUS, + dev, "sd-bus"); + + /* Create and plug in the sd card */ /* FIXME use a qdev drive property instead of drive_get_next() */ dinfo =3D drive_get_next(IF_SD); blk =3D dinfo ? blk_by_legacy_dinfo(dinfo) : NULL; - s->card =3D sd_init(blk, false); - if (s->card =3D=3D NULL) { - error_setg(errp, "failed to init SD card"); + carddev =3D qdev_create(&s->sdbus.qbus, TYPE_SD_CARD); + qdev_prop_set_drive(carddev, "drive", blk, &err); + object_property_set_bool(OBJECT(carddev), true, "realized", &err); + if (err) { + error_setg(errp, "failed to init SD card: %s", error_get_pretty(er= r)); return; } s->enabled =3D blk && blk_is_inserted(blk); --=20 2.16.1 From nobody Wed Apr 16 16:47:02 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519313613751933.1968113544543; Thu, 22 Feb 2018 07:33:33 -0800 (PST) Received: from localhost ([::1]:39019 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eossF-00050Y-0S for importer@patchew.org; Thu, 22 Feb 2018 10:33:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38341) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosiY-0004jf-E5 for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosiX-0001cX-8n for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:30 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46594) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosiX-0001bp-1a for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:29 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosiW-000222-4D for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:28 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:22:43 +0000 Message-Id: <20180222152307.7499-9-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 08/32] hw/sd/ssi-sd: use the SDBus API, connect the SDCard to the bus 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 On reset the bus will reset the card, we can now drop the device_reset() call. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Message-id: 20180216022933.10945-5-f4bug@amsat.org Signed-off-by: Peter Maydell --- hw/sd/ssi-sd.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c index f88f509e0a..ae04b6641b 100644 --- a/hw/sd/ssi-sd.c +++ b/hw/sd/ssi-sd.c @@ -47,7 +47,7 @@ typedef struct { int32_t arglen; int32_t response_pos; int32_t stopping; - SDState *sd; + SDBus sdbus; } ssi_sd_state; =20 #define TYPE_SSI_SD "ssi-sd" @@ -100,7 +100,7 @@ static uint32_t ssi_sd_transfer(SSISlave *dev, uint32_t= val) request.arg =3D (s->cmdarg[0] << 24) | (s->cmdarg[1] << 16) | (s->cmdarg[2] << 8) | s->cmdarg[3]; DPRINTF("CMD%d arg 0x%08x\n", s->cmd, request.arg); - s->arglen =3D sd_do_command(s->sd, &request, longresp); + s->arglen =3D sdbus_do_command(&s->sdbus, &request, longresp); if (s->arglen <=3D 0) { s->arglen =3D 1; s->response[0] =3D 4; @@ -177,7 +177,7 @@ static uint32_t ssi_sd_transfer(SSISlave *dev, uint32_t= val) DPRINTF("Response 0x%02x\n", s->response[s->response_pos]); return s->response[s->response_pos++]; } - if (sd_data_ready(s->sd)) { + if (sdbus_data_ready(&s->sdbus)) { DPRINTF("Data read\n"); s->mode =3D SSI_SD_DATA_START; } else { @@ -190,8 +190,8 @@ static uint32_t ssi_sd_transfer(SSISlave *dev, uint32_t= val) s->mode =3D SSI_SD_DATA_READ; return 0xfe; case SSI_SD_DATA_READ: - val =3D sd_read_data(s->sd); - if (!sd_data_ready(s->sd)) { + val =3D sdbus_read_data(&s->sdbus); + if (!sdbus_data_ready(&s->sdbus)) { DPRINTF("Data read end\n"); s->mode =3D SSI_SD_CMD; } @@ -242,13 +242,24 @@ static const VMStateDescription vmstate_ssi_sd =3D { static void ssi_sd_realize(SSISlave *d, Error **errp) { ssi_sd_state *s =3D FROM_SSI_SLAVE(ssi_sd_state, d); + DeviceState *carddev; DriveInfo *dinfo; + Error *err =3D NULL; =20 + qbus_create_inplace(&s->sdbus, sizeof(s->sdbus), TYPE_SD_BUS, + DEVICE(d), "sd-bus"); + + /* Create and plug in the sd card */ /* FIXME use a qdev drive property instead of drive_get_next() */ dinfo =3D drive_get_next(IF_SD); - s->sd =3D sd_init(dinfo ? blk_by_legacy_dinfo(dinfo) : NULL, true); - if (s->sd =3D=3D NULL) { - error_setg(errp, "Device initialization failed."); + carddev =3D qdev_create(&s->sdbus.qbus, TYPE_SD_CARD); + if (dinfo) { + qdev_prop_set_drive(carddev, "drive", blk_by_legacy_dinfo(dinfo), = &err); + } + object_property_set_bool(OBJECT(carddev), true, "spi", &err); + object_property_set_bool(OBJECT(carddev), true, "realized", &err); + if (err) { + error_setg(errp, "failed to init SD card: %s", error_get_pretty(er= r)); return; } } @@ -264,11 +275,6 @@ static void ssi_sd_reset(DeviceState *dev) s->arglen =3D 0; s->response_pos =3D 0; s->stopping =3D 0; - - /* Since we're still using the legacy SD API the card is not plugged - * into any bus, and we must reset it manually. - */ - device_reset(DEVICE(s->sd)); } =20 static void ssi_sd_class_init(ObjectClass *klass, void *data) --=20 2.16.1 From nobody Wed Apr 16 16:47:02 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519313792681718.0367430569572; Thu, 22 Feb 2018 07:36:32 -0800 (PST) Received: from localhost ([::1]:39038 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosv6-0007XM-IA for importer@patchew.org; Thu, 22 Feb 2018 10:36:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38353) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosiZ-0004kW-9D for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosiY-0001dk-7c for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:31 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46596) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosiY-0001cp-0c for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:30 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosiX-00022G-4C for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:29 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:22:44 +0000 Message-Id: <20180222152307.7499-10-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 09/32] sdcard: reorder SDState struct members 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 place card registers first, this will ease further code movements. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Message-id: 20180215220540.6556-2-f4bug@amsat.org Signed-off-by: Peter Maydell --- hw/sd/sd.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 9ac9b63ff8..ce1f2fdf76 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -88,16 +88,21 @@ enum SDCardStates { struct SDState { DeviceState parent_obj; =20 - uint32_t mode; /* current card mode, one of SDCardModes */ - int32_t state; /* current card state, one of SDCardStates */ + /* SD Memory Card Registers */ uint32_t ocr; - QEMUTimer *ocr_power_timer; uint8_t scr[8]; uint8_t cid[16]; uint8_t csd[16]; uint16_t rca; uint32_t card_status; uint8_t sd_status[64]; + + /* Configurable properties */ + BlockBackend *blk; + bool spi; + + uint32_t mode; /* current card mode, one of SDCardModes */ + int32_t state; /* current card state, one of SDCardStates */ uint32_t vhs; bool wp_switch; unsigned long *wp_groups; @@ -110,8 +115,6 @@ struct SDState { uint8_t pwd[16]; uint32_t pwd_len; uint8_t function_group[6]; - - bool spi; uint8_t current_cmd; /* True if we will handle the next command as an ACMD. Note that this = does * *not* track the APP_CMD status bit! @@ -123,8 +126,7 @@ struct SDState { uint8_t data[512]; qemu_irq readonly_cb; qemu_irq inserted_cb; - BlockBackend *blk; - + QEMUTimer *ocr_power_timer; bool enable; uint8_t dat_lines; bool cmd_line; --=20 2.16.1 From nobody Wed Apr 16 16:47:02 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519313607199637.3002634622311; Thu, 22 Feb 2018 07:33:27 -0800 (PST) Received: from localhost ([::1]:39018 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eossA-0004w7-Bb for importer@patchew.org; Thu, 22 Feb 2018 10:33:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38367) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosia-0004lv-Ht for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosiZ-0001ef-9s for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:32 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46598) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosiZ-0001dy-03 for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:31 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosiY-00022U-0q for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:30 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:22:45 +0000 Message-Id: <20180222152307.7499-11-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 10/32] sdcard: replace DPRINTF() by trace events 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 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Message-id: 20180215220540.6556-3-f4bug@amsat.org Signed-off-by: Peter Maydell --- hw/sd/sd.c | 32 ++++++++++++++++++++++++++------ hw/sd/trace-events | 6 ++++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index ce1f2fdf76..72e9b47e34 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -40,6 +40,7 @@ #include "qemu/error-report.h" #include "qemu/timer.h" #include "qemu/log.h" +#include "trace.h" =20 //#define DEBUG_SD 1 =20 @@ -132,6 +133,26 @@ struct SDState { bool cmd_line; }; =20 +static const char *sd_state_name(enum SDCardStates state) +{ + static const char *state_name[] =3D { + [sd_idle_state] =3D "idle", + [sd_ready_state] =3D "ready", + [sd_identification_state] =3D "identification", + [sd_standby_state] =3D "standby", + [sd_transfer_state] =3D "transfer", + [sd_sendingdata_state] =3D "sendingdata", + [sd_receivingdata_state] =3D "receivingdata", + [sd_programming_state] =3D "programming", + [sd_disconnect_state] =3D "disconnect", + }; + if (state =3D=3D sd_inactive_state) { + return "inactive"; + } + assert(state <=3D ARRAY_SIZE(state_name)); + return state_name[state]; +} + static uint8_t sd_get_dat_lines(SDState *sd) { return sd->enable ? sd->dat_lines : 0; @@ -776,6 +797,8 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, uint32_t rca =3D 0x0000; uint64_t addr =3D (sd->ocr & (1 << 30)) ? (uint64_t) req.arg << 9 : re= q.arg; =20 + trace_sdcard_normal_command(req.cmd, req.arg, sd_state_name(sd->state)= ); + /* Not interpreting this as an app command */ sd->card_status &=3D ~APP_CMD; =20 @@ -790,7 +813,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, sd->multi_blk_cnt =3D 0; } =20 - DPRINTF("CMD%d 0x%08x state %d\n", req.cmd, req.arg, sd->state); switch (req.cmd) { /* Basic commands (Class 0 and Class 1) */ case 0: /* CMD0: GO_IDLE_STATE */ @@ -1310,8 +1332,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, return sd_r1; =20 case 56: /* CMD56: GEN_CMD */ - fprintf(stderr, "SD: GEN_CMD 0x%08x\n", req.arg); - switch (sd->state) { case sd_transfer_state: sd->data_offset =3D 0; @@ -1345,7 +1365,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, static sd_rsp_type_t sd_app_command(SDState *sd, SDRequest req) { - DPRINTF("ACMD%d 0x%08x\n", req.cmd, req.arg); + trace_sdcard_app_command(req.cmd, req.arg); sd->card_status |=3D APP_CMD; switch (req.cmd) { case 6: /* ACMD6: SET_BUS_WIDTH */ @@ -1606,8 +1626,7 @@ send_response: =20 static void sd_blk_read(SDState *sd, uint64_t addr, uint32_t len) { - DPRINTF("sd_blk_read: addr =3D 0x%08llx, len =3D %d\n", - (unsigned long long) addr, len); + trace_sdcard_read_block(addr, len); if (!sd->blk || blk_pread(sd->blk, addr, sd->data, len) < 0) { fprintf(stderr, "sd_blk_read: read error on host side\n"); } @@ -1615,6 +1634,7 @@ static void sd_blk_read(SDState *sd, uint64_t addr, u= int32_t len) =20 static void sd_blk_write(SDState *sd, uint64_t addr, uint32_t len) { + trace_sdcard_write_block(addr, len); if (!sd->blk || blk_pwrite(sd->blk, addr, sd->data, len, 0) < 0) { fprintf(stderr, "sd_blk_write: write error on host side\n"); } diff --git a/hw/sd/trace-events b/hw/sd/trace-events index 0f8536db32..75dac5a2cd 100644 --- a/hw/sd/trace-events +++ b/hw/sd/trace-events @@ -23,6 +23,12 @@ sdhci_read_dataport(uint16_t data_count) "all %u bytes o= f data have been read fr sdhci_write_dataport(uint16_t data_count) "write buffer filled with %u byt= es of data" sdhci_capareg(const char *desc, uint16_t val) "%s: %u" =20 +# hw/sd/sd.c +sdcard_normal_command(uint8_t cmd, uint32_t arg, const char *state) "CMD%d= arg 0x%08x (state %s)" +sdcard_app_command(uint8_t acmd, uint32_t arg) "ACMD%d arg 0x%08x" +sdcard_read_block(uint64_t addr, uint32_t len) "addr 0x%" PRIx64 " size 0x= %x" +sdcard_write_block(uint64_t addr, uint32_t len) "addr 0x%" PRIx64 " size 0= x%x" + # hw/sd/milkymist-memcard.c milkymist_memcard_memory_read(uint32_t addr, uint32_t value) "addr 0x%08x = value 0x%08x" milkymist_memcard_memory_write(uint32_t addr, uint32_t value) "addr 0x%08x= value 0x%08x" --=20 2.16.1 From nobody Wed Apr 16 16:47:02 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519313170652749.3685967425727; Thu, 22 Feb 2018 07:26:10 -0800 (PST) Received: from localhost ([::1]:38980 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosl7-0006sS-NN for importer@patchew.org; Thu, 22 Feb 2018 10:26:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38377) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosib-0004my-7m for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosia-0001fQ-8p for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:33 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46598) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosia-0001dy-0i for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:32 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosiY-00022i-RO for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:30 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:22:46 +0000 Message-Id: <20180222152307.7499-12-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 11/32] sdcard: add a trace event for command responses 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 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Message-id: 20180215220540.6556-4-f4bug@amsat.org Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- hw/sd/sd.c | 27 ++++++++++++++++++++++++--- hw/sd/trace-events | 1 + 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 72e9b47e34..8f72cde534 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -153,6 +153,27 @@ static const char *sd_state_name(enum SDCardStates sta= te) return state_name[state]; } =20 +static const char *sd_response_name(sd_rsp_type_t rsp) +{ + static const char *response_name[] =3D { + [sd_r0] =3D "RESP#0 (no response)", + [sd_r1] =3D "RESP#1 (normal cmd)", + [sd_r2_i] =3D "RESP#2 (CID reg)", + [sd_r2_s] =3D "RESP#2 (CSD reg)", + [sd_r3] =3D "RESP#3 (OCR reg)", + [sd_r6] =3D "RESP#6 (RCA)", + [sd_r7] =3D "RESP#7 (operating voltage)", + }; + if (rsp =3D=3D sd_illegal) { + return "ILLEGAL RESP"; + } + if (rsp =3D=3D sd_r1b) { + rsp =3D sd_r1; + } + assert(rsp <=3D ARRAY_SIZE(response_name)); + return response_name[rsp]; +} + static uint8_t sd_get_dat_lines(SDState *sd) { return sd->enable ? sd->dat_lines : 0; @@ -1596,10 +1617,12 @@ send_response: =20 case sd_r0: case sd_illegal: - default: rsplen =3D 0; break; + default: + g_assert_not_reached(); } + trace_sdcard_response(sd_response_name(rtype), rsplen); =20 if (rtype !=3D sd_illegal) { /* Clear the "clear on valid command" status bits now we've @@ -1616,8 +1639,6 @@ send_response: DPRINTF(" %02x", response[i]); } DPRINTF(" state %d\n", sd->state); - } else { - DPRINTF("No response %d\n", sd->state); } #endif =20 diff --git a/hw/sd/trace-events b/hw/sd/trace-events index 75dac5a2cd..b2aa19ec0d 100644 --- a/hw/sd/trace-events +++ b/hw/sd/trace-events @@ -26,6 +26,7 @@ sdhci_capareg(const char *desc, uint16_t val) "%s: %u" # hw/sd/sd.c sdcard_normal_command(uint8_t cmd, uint32_t arg, const char *state) "CMD%d= arg 0x%08x (state %s)" sdcard_app_command(uint8_t acmd, uint32_t arg) "ACMD%d arg 0x%08x" +sdcard_response(const char *rspdesc, int rsplen) "%s (sz:%d)" sdcard_read_block(uint64_t addr, uint32_t len) "addr 0x%" PRIx64 " size 0x= %x" sdcard_write_block(uint64_t addr, uint32_t len) "addr 0x%" PRIx64 " size 0= x%x" =20 --=20 2.16.1 From nobody Wed Apr 16 16:47:02 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 15193143017491008.1052573157731; Thu, 22 Feb 2018 07:45:01 -0800 (PST) Received: from localhost ([::1]:39083 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eot3J-0006z7-05 for importer@patchew.org; Thu, 22 Feb 2018 10:44:57 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38408) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosid-0004pQ-7i for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosia-0001fp-Qp for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:35 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46600) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosia-0001fC-JR for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:32 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosiZ-00022z-Lk for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:31 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:22:47 +0000 Message-Id: <20180222152307.7499-13-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 12/32] sdcard: replace fprintf() by qemu_hexdump() 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 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Message-id: 20180215220540.6556-5-f4bug@amsat.org Signed-off-by: Peter Maydell --- hw/sd/sd.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 8f72cde534..ceab263970 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -44,13 +44,6 @@ =20 //#define DEBUG_SD 1 =20 -#ifdef DEBUG_SD -#define DPRINTF(fmt, ...) \ -do { fprintf(stderr, "SD: " fmt , ## __VA_ARGS__); } while (0) -#else -#define DPRINTF(fmt, ...) do {} while(0) -#endif - #define ACMD41_ENQUIRY_MASK 0x00ffffff #define OCR_POWER_UP 0x80000000 #define OCR_POWER_DELAY_NS 500000 /* 0.5ms */ @@ -1632,14 +1625,7 @@ send_response: } =20 #ifdef DEBUG_SD - if (rsplen) { - int i; - DPRINTF("Response:"); - for (i =3D 0; i < rsplen; i++) { - DPRINTF(" %02x", response[i]); - } - DPRINTF(" state %d\n", sd->state); - } + qemu_hexdump((const char *)response, stderr, "Response", rsplen); #endif =20 return rsplen; --=20 2.16.1 From nobody Wed Apr 16 16:47:02 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 151931396685998.28199817486836; Thu, 22 Feb 2018 07:39:26 -0800 (PST) Received: from localhost ([::1]:39051 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosxx-000206-6O for importer@patchew.org; Thu, 22 Feb 2018 10:39:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38406) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosid-0004pL-5B for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosib-0001gd-Pt for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:35 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46600) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosib-0001fC-Hd for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:33 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosia-00023D-Fk for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:32 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:22:48 +0000 Message-Id: <20180222152307.7499-14-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 13/32] sdcard: add more trace events 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 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Alistair Francis Message-id: 20180215220540.6556-6-f4bug@amsat.org Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- hw/sd/sd.c | 32 ++++++++++++++++++++++++++------ hw/sd/trace-events | 13 +++++++++++++ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index ceab263970..564f7a9bfd 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -179,6 +179,8 @@ static bool sd_get_cmd_line(SDState *sd) =20 static void sd_set_voltage(SDState *sd, uint16_t millivolts) { + trace_sdcard_set_voltage(millivolts); + switch (millivolts) { case 3001 ... 3600: /* SD_VOLTAGE_3_3V */ case 2001 ... 3000: /* SD_VOLTAGE_3_0V */ @@ -274,6 +276,7 @@ static void sd_ocr_powerup(void *opaque) { SDState *sd =3D opaque; =20 + trace_sdcard_powerup(); /* Set powered up bit in OCR */ assert(!(sd->ocr & OCR_POWER_UP)); sd->ocr |=3D OCR_POWER_UP; @@ -477,6 +480,7 @@ static void sd_reset(DeviceState *dev) uint64_t size; uint64_t sect; =20 + trace_sdcard_reset(); if (sd->blk) { blk_get_geometry(sd->blk, §); } else { @@ -530,7 +534,10 @@ static void sd_cardchange(void *opaque, bool load, Err= or **errp) bool readonly =3D sd_get_readonly(sd); =20 if (inserted) { + trace_sdcard_inserted(readonly); sd_reset(dev); + } else { + trace_sdcard_ejected(); } =20 /* The IRQ notification is for legacy non-QOM SD controller devices; @@ -662,6 +669,7 @@ static void sd_erase(SDState *sd) uint64_t erase_start =3D sd->erase_start; uint64_t erase_end =3D sd->erase_end; =20 + trace_sdcard_erase(); if (!sd->erase_start || !sd->erase_end) { sd->card_status |=3D ERASE_SEQ_ERROR; return; @@ -751,6 +759,11 @@ static void sd_lock_command(SDState *sd) else pwd_len =3D 0; =20 + if (lock) { + trace_sdcard_lock(); + } else { + trace_sdcard_unlock(); + } if (erase) { if (!(sd->card_status & CARD_IS_LOCKED) || sd->blk_len > 1 || set_pwd || clr_pwd || lock || sd->wp_switch || @@ -1077,10 +1090,12 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, case 16: /* CMD16: SET_BLOCKLEN */ switch (sd->state) { case sd_transfer_state: - if (req.arg > (1 << HWBLOCK_SHIFT)) + if (req.arg > (1 << HWBLOCK_SHIFT)) { sd->card_status |=3D BLOCK_LEN_ERROR; - else + } else { + trace_sdcard_set_blocklen(req.arg); sd->blk_len =3D req.arg; + } =20 return sd_r1; =20 @@ -1452,10 +1467,13 @@ static sd_rsp_type_t sd_app_command(SDState *sd, if ((req.arg & ACMD41_ENQUIRY_MASK) !=3D 0) { timer_del(sd->ocr_power_timer); sd_ocr_powerup(sd); - } else if (!timer_pending(sd->ocr_power_timer)) { - timer_mod_ns(sd->ocr_power_timer, - (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) - + OCR_POWER_DELAY_NS)); + } else { + trace_sdcard_inquiry_cmd41(); + if (!timer_pending(sd->ocr_power_timer)) { + timer_mod_ns(sd->ocr_power_timer, + (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + + OCR_POWER_DELAY_NS)); + } } } =20 @@ -1668,6 +1686,7 @@ void sd_write_data(SDState *sd, uint8_t value) if (sd->card_status & (ADDRESS_ERROR | WP_VIOLATION)) return; =20 + trace_sdcard_write_data(sd->current_cmd, value); switch (sd->current_cmd) { case 24: /* CMD24: WRITE_SINGLE_BLOCK */ sd->data[sd->data_offset ++] =3D value; @@ -1805,6 +1824,7 @@ uint8_t sd_read_data(SDState *sd) =20 io_len =3D (sd->ocr & (1 << 30)) ? 512 : sd->blk_len; =20 + trace_sdcard_read_data(sd->current_cmd, io_len); switch (sd->current_cmd) { case 6: /* CMD6: SWITCH_FUNCTION */ ret =3D sd->data[sd->data_offset ++]; diff --git a/hw/sd/trace-events b/hw/sd/trace-events index b2aa19ec0d..3040d32560 100644 --- a/hw/sd/trace-events +++ b/hw/sd/trace-events @@ -27,8 +27,21 @@ sdhci_capareg(const char *desc, uint16_t val) "%s: %u" sdcard_normal_command(uint8_t cmd, uint32_t arg, const char *state) "CMD%d= arg 0x%08x (state %s)" sdcard_app_command(uint8_t acmd, uint32_t arg) "ACMD%d arg 0x%08x" sdcard_response(const char *rspdesc, int rsplen) "%s (sz:%d)" +sdcard_powerup(void) "" +sdcard_inquiry_cmd41(void) "" +sdcard_set_enable(bool current_state, bool new_state) "%u -> %u" +sdcard_reset(void) "" +sdcard_set_blocklen(uint16_t length) "0x%04x" +sdcard_inserted(bool readonly) "read_only: %u" +sdcard_ejected(void) "" +sdcard_erase(void) "" +sdcard_lock(void) "" +sdcard_unlock(void) "" sdcard_read_block(uint64_t addr, uint32_t len) "addr 0x%" PRIx64 " size 0x= %x" sdcard_write_block(uint64_t addr, uint32_t len) "addr 0x%" PRIx64 " size 0= x%x" +sdcard_write_data(uint8_t cmd, uint8_t value) "CMD%02d value 0x%02x" +sdcard_read_data(uint8_t cmd, int length) "CMD%02d len %d" +sdcard_set_voltage(uint16_t millivolts) "%u mV" =20 # hw/sd/milkymist-memcard.c milkymist_memcard_memory_read(uint32_t addr, uint32_t value) "addr 0x%08x = value 0x%08x" --=20 2.16.1 From nobody Wed Apr 16 16:47:02 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519313446069917.9060202054085; Thu, 22 Feb 2018 07:30:46 -0800 (PST) Received: from localhost ([::1]:39004 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eospU-0002bX-OM for importer@patchew.org; Thu, 22 Feb 2018 10:30:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38427) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosie-0004qz-Mh for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosic-0001hF-EX for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:36 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46602) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosic-0001gY-6u for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:34 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosib-00023U-98 for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:33 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:22:49 +0000 Message-Id: <20180222152307.7499-15-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 14/32] sdcard: define SDMMC_CMD_MAX instead of using the magic '64' 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 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Message-id: 20180215220540.6556-8-f4bug@amsat.org Signed-off-by: Peter Maydell --- hw/sd/sdmmc-internal.h | 15 +++++++++++++++ hw/sd/sd.c | 22 ++++++++++++++++------ 2 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 hw/sd/sdmmc-internal.h diff --git a/hw/sd/sdmmc-internal.h b/hw/sd/sdmmc-internal.h new file mode 100644 index 0000000000..0e96cb0081 --- /dev/null +++ b/hw/sd/sdmmc-internal.h @@ -0,0 +1,15 @@ +/* + * SD/MMC cards common + * + * Copyright (c) 2018 Philippe Mathieu-Daud=C3=A9 + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#ifndef SD_INTERNAL_H +#define SD_INTERNAL_H + +#define SDMMC_CMD_MAX 64 + +#endif diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 564f7a9bfd..90d1e27ee7 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -40,6 +40,7 @@ #include "qemu/error-report.h" #include "qemu/timer.h" #include "qemu/log.h" +#include "sdmmc-internal.h" #include "trace.h" =20 //#define DEBUG_SD 1 @@ -215,18 +216,21 @@ static void sd_set_mode(SDState *sd) } } =20 -static const sd_cmd_type_t sd_cmd_type[64] =3D { +static const sd_cmd_type_t sd_cmd_type[SDMMC_CMD_MAX] =3D { sd_bc, sd_none, sd_bcr, sd_bcr, sd_none, sd_none, sd_none, sd_ac, sd_bcr, sd_ac, sd_ac, sd_adtc, sd_ac, sd_ac, sd_none, sd_ac, + /* 16 */ sd_ac, sd_adtc, sd_adtc, sd_none, sd_none, sd_none, sd_none, sd_none, sd_adtc, sd_adtc, sd_adtc, sd_adtc, sd_ac, sd_ac, sd_adtc, sd_none, + /* 32 */ sd_ac, sd_ac, sd_none, sd_none, sd_none, sd_none, sd_ac, sd_none, sd_none, sd_none, sd_bc, sd_none, sd_none, sd_none, sd_none, sd_none, + /* 48 */ sd_none, sd_none, sd_none, sd_none, sd_none, sd_none, sd_none, sd_ac, sd_adtc, sd_none, sd_none, sd_none, sd_none, sd_none, sd_none, sd_none, }; =20 -static const int sd_cmd_class[64] =3D { +static const int sd_cmd_class[SDMMC_CMD_MAX] =3D { 0, 0, 0, 0, 0, 9, 10, 0, 0, 0, 0, 1, 0, 0, 0, 0, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 6, 6, 6, 6, 5, 5, 10, 10, 10, 10, 5, 9, 9, 9, 7, 7, 7, 7, 7, 7, @@ -829,8 +833,8 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, /* Not interpreting this as an app command */ sd->card_status &=3D ~APP_CMD; =20 - if (sd_cmd_type[req.cmd & 0x3F] =3D=3D sd_ac - || sd_cmd_type[req.cmd & 0x3F] =3D=3D sd_adtc) { + if (sd_cmd_type[req.cmd] =3D=3D sd_ac + || sd_cmd_type[req.cmd] =3D=3D sd_adtc) { rca =3D req.arg >> 16; } =20 @@ -1542,8 +1546,8 @@ static int cmd_valid_while_locked(SDState *sd, SDRequ= est *req) if (req->cmd =3D=3D 16 || req->cmd =3D=3D 55) { return 1; } - return sd_cmd_class[req->cmd & 0x3F] =3D=3D 0 - || sd_cmd_class[req->cmd & 0x3F] =3D=3D 7; + return sd_cmd_class[req->cmd] =3D=3D 0 + || sd_cmd_class[req->cmd] =3D=3D 7; } =20 int sd_do_command(SDState *sd, SDRequest *req, @@ -1562,6 +1566,12 @@ int sd_do_command(SDState *sd, SDRequest *req, goto send_response; } =20 + if (req->cmd >=3D SDMMC_CMD_MAX) { + qemu_log_mask(LOG_GUEST_ERROR, "SD: incorrect command 0x%02x\n", + req->cmd); + req->cmd &=3D 0x3f; + } + if (sd->card_status & CARD_IS_LOCKED) { if (!cmd_valid_while_locked(sd, req)) { sd->card_status |=3D ILLEGAL_COMMAND; --=20 2.16.1 From nobody Wed Apr 16 16:47:02 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519314485724356.9647068770977; Thu, 22 Feb 2018 07:48:05 -0800 (PST) Received: from localhost ([::1]:39114 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eot6K-00016s-Te for importer@patchew.org; Thu, 22 Feb 2018 10:48:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38483) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosih-0004ur-UX for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosid-0001iG-DM for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:39 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46604) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosid-0001hW-6e for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:35 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosic-00023i-8x for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:34 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:22:50 +0000 Message-Id: <20180222152307.7499-16-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 15/32] sdcard: use G_BYTE from cutils 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 code is now easier to read. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Message-id: 20180215220540.6556-11-f4bug@amsat.org Signed-off-by: Peter Maydell --- hw/sd/sd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 90d1e27ee7..b3698e34ad 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -36,6 +36,7 @@ #include "hw/sd/sd.h" #include "qapi/error.h" #include "qemu/bitmap.h" +#include "qemu/cutils.h" #include "hw/qdev-properties.h" #include "qemu/error-report.h" #include "qemu/timer.h" @@ -343,7 +344,7 @@ static void sd_set_csd(SDState *sd, uint64_t size) uint32_t sectsize =3D (1 << (SECTOR_SHIFT + 1)) - 1; uint32_t wpsize =3D (1 << (WPGROUP_SHIFT + 1)) - 1; =20 - if (size <=3D 0x40000000) { /* Standard Capacity SD */ + if (size <=3D 1 * G_BYTE) { /* Standard Capacity SD */ sd->csd[0] =3D 0x00; /* CSD structure */ sd->csd[1] =3D 0x26; /* Data read access-time-1 */ sd->csd[2] =3D 0x00; /* Data read access-time-2 */ --=20 2.16.1 From nobody Wed Apr 16 16:47:02 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519313969451665.9202491550237; Thu, 22 Feb 2018 07:39:29 -0800 (PST) Received: from localhost ([::1]:39052 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosy0-00023k-IG for importer@patchew.org; Thu, 22 Feb 2018 10:39:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38446) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosif-0004s6-Ic for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosie-0001jL-C5 for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:37 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46604) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosie-0001hW-43 for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:36 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosid-00023w-10 for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:35 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:22:51 +0000 Message-Id: <20180222152307.7499-17-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 16/32] sdcard: use the registerfields API to access the OCR register 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 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Message-id: 20180215220540.6556-12-f4bug@amsat.org Signed-off-by: Peter Maydell --- include/hw/sd/sd.h | 1 - hw/sd/sd.c | 21 +++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/include/hw/sd/sd.h b/include/hw/sd/sd.h index bf1eb0713c..9bdb3c9285 100644 --- a/include/hw/sd/sd.h +++ b/include/hw/sd/sd.h @@ -53,7 +53,6 @@ #define READY_FOR_DATA (1 << 8) #define APP_CMD (1 << 5) #define AKE_SEQ_ERROR (1 << 3) -#define OCR_CCS_BITN 30 =20 typedef enum { SD_VOLTAGE_0_4V =3D 400, /* currently not supported */ diff --git a/hw/sd/sd.c b/hw/sd/sd.c index b3698e34ad..706cb52668 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -32,6 +32,7 @@ #include "qemu/osdep.h" #include "hw/qdev.h" #include "hw/hw.h" +#include "hw/registerfields.h" #include "sysemu/block-backend.h" #include "hw/sd/sd.h" #include "qapi/error.h" @@ -47,8 +48,6 @@ //#define DEBUG_SD 1 =20 #define ACMD41_ENQUIRY_MASK 0x00ffffff -#define OCR_POWER_UP 0x80000000 -#define OCR_POWER_DELAY_NS 500000 /* 0.5ms */ =20 typedef enum { sd_r0 =3D 0, /* no response */ @@ -271,6 +270,11 @@ static uint16_t sd_crc16(void *message, size_t width) return shift_reg; } =20 +#define OCR_POWER_DELAY_NS 500000 /* 0.5ms */ + +FIELD(OCR, CARD_CAPACITY, 30, 1) /* 0:SDSC, 1:SDHC/SDXC */ +FIELD(OCR, CARD_POWER_UP, 31, 1) + static void sd_set_ocr(SDState *sd) { /* All voltages OK, Standard Capacity SD Memory Card, not yet powered = up */ @@ -282,9 +286,10 @@ static void sd_ocr_powerup(void *opaque) SDState *sd =3D opaque; =20 trace_sdcard_powerup(); - /* Set powered up bit in OCR */ - assert(!(sd->ocr & OCR_POWER_UP)); - sd->ocr |=3D OCR_POWER_UP; + assert(!FIELD_EX32(sd->ocr, OCR, CARD_POWER_UP)); + + /* card power-up OK */ + sd->ocr =3D FIELD_DP32(sd->ocr, OCR, CARD_POWER_UP, 1); } =20 static void sd_set_scr(SDState *sd) @@ -570,7 +575,7 @@ static bool sd_ocr_vmstate_needed(void *opaque) SDState *sd =3D opaque; =20 /* Include the OCR state (and timer) if it is not yet powered up */ - return !(sd->ocr & OCR_POWER_UP); + return !FIELD_EX32(sd->ocr, OCR, CARD_POWER_UP); } =20 static const VMStateDescription sd_ocr_vmstate =3D { @@ -680,7 +685,7 @@ static void sd_erase(SDState *sd) return; } =20 - if (extract32(sd->ocr, OCR_CCS_BITN, 1)) { + if (FIELD_EX32(sd->ocr, OCR, CARD_CAPACITY)) { /* High capacity memory card: erase units are 512 byte blocks */ erase_start *=3D 512; erase_end *=3D 512; @@ -1468,7 +1473,7 @@ static sd_rsp_type_t sd_app_command(SDState *sd, * UEFI, which sends an initial enquiry ACMD41, but * assumes that the card is in ready state as soon as it * sees the power up bit set. */ - if (!(sd->ocr & OCR_POWER_UP)) { + if (!FIELD_EX32(sd->ocr, OCR, CARD_POWER_UP)) { if ((req.arg & ACMD41_ENQUIRY_MASK) !=3D 0) { timer_del(sd->ocr_power_timer); sd_ocr_powerup(sd); --=20 2.16.1 From nobody Wed Apr 16 16:47:02 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519314134853848.250202793853; Thu, 22 Feb 2018 07:42:14 -0800 (PST) Received: from localhost ([::1]:39068 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eot0g-0004X4-11 for importer@patchew.org; Thu, 22 Feb 2018 10:42:14 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38451) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosif-0004sU-Q5 for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosie-0001k4-T8 for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:37 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46606) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosie-0001ix-Mc for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:36 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosid-00024C-O4 for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:35 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:22:52 +0000 Message-Id: <20180222152307.7499-18-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 17/32] sdcard: Don't always set the high capacity bit 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 Don't set the high capacity bit by default as it will be set if required in the sd_set_csd() function. [based on a patch from Alistair Francis and Peter Ogden from qemu/xilinx tag xilinx-v2015.4] Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Message-id: 20180215221325.7611-2-f4bug@amsat.org Signed-off-by: Peter Maydell --- hw/sd/sd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 706cb52668..cc347ff782 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -290,6 +290,10 @@ static void sd_ocr_powerup(void *opaque) =20 /* card power-up OK */ sd->ocr =3D FIELD_DP32(sd->ocr, OCR, CARD_POWER_UP, 1); + + if (sd->size > 1 * G_BYTE) { + sd->ocr =3D FIELD_DP32(sd->ocr, OCR, CARD_CAPACITY, 1); + } } =20 static void sd_set_scr(SDState *sd) @@ -394,7 +398,6 @@ static void sd_set_csd(SDState *sd, uint64_t size) sd->csd[13] =3D 0x40; sd->csd[14] =3D 0x00; sd->csd[15] =3D 0x00; - sd->ocr |=3D 1 << 30; /* High Capacity SD Memory Card */ } } =20 --=20 2.16.1 From nobody Wed Apr 16 16:47:02 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519314670140554.7512610310355; Thu, 22 Feb 2018 07:51:10 -0800 (PST) Received: from localhost ([::1]:39133 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eot9J-0003ef-9a for importer@patchew.org; Thu, 22 Feb 2018 10:51:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38517) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosij-0004xN-UR for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosif-0001kw-QA for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:41 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46606) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosif-0001ix-IX for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:37 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosie-00024R-G7 for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:36 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:22:53 +0000 Message-Id: <20180222152307.7499-19-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 18/32] sdcard: update the CSD CRC register regardless the CSD structure version 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 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Message-id: 20180215221325.7611-3-f4bug@amsat.org Signed-off-by: Peter Maydell --- hw/sd/sd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index cc347ff782..110f2f1d0a 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -378,7 +378,6 @@ static void sd_set_csd(SDState *sd, uint64_t size) sd->csd[13] =3D 0x20 | /* Max. write data block length */ ((HWBLOCK_SHIFT << 6) & 0xc0); sd->csd[14] =3D 0x00; /* File format group */ - sd->csd[15] =3D (sd_crc7(sd->csd, 15) << 1) | 1; } else { /* SDHC */ size /=3D 512 * 1024; size -=3D 1; @@ -397,8 +396,8 @@ static void sd_set_csd(SDState *sd, uint64_t size) sd->csd[12] =3D 0x0a; sd->csd[13] =3D 0x40; sd->csd[14] =3D 0x00; - sd->csd[15] =3D 0x00; } + sd->csd[15] =3D (sd_crc7(sd->csd, 15) << 1) | 1; } =20 static void sd_set_rca(SDState *sd) --=20 2.16.1 From nobody Wed Apr 16 16:47:02 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519313793855294.2864272181448; Thu, 22 Feb 2018 07:36:33 -0800 (PST) Received: from localhost ([::1]:39039 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosvB-0007dZ-21 for importer@patchew.org; Thu, 22 Feb 2018 10:36:33 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38468) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosih-0004u2-6p for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosig-0001lJ-Ap for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:39 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46608) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosig-0001ke-3U for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:38 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosif-00024i-6E for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:37 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:22:54 +0000 Message-Id: <20180222152307.7499-20-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 19/32] sdcard: fix the 'maximum data transfer rate' to 25MHz 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 To comply with Spec v1.10 (and 2.00, 3.01): . TRAN_SPEED for current SD Memory Cards that field must be always 0_0110_010b (032h) wh= ich is equal to 25MHz - the mandatory maximum operating frequency of SD Memory Car= d. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Message-id: 20180215221325.7611-4-f4bug@amsat.org [PMM: fixed comment indent] Signed-off-by: Peter Maydell --- hw/sd/sd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 110f2f1d0a..3526269dbe 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -357,7 +357,7 @@ static void sd_set_csd(SDState *sd, uint64_t size) sd->csd[0] =3D 0x00; /* CSD structure */ sd->csd[1] =3D 0x26; /* Data read access-time-1 */ sd->csd[2] =3D 0x00; /* Data read access-time-2 */ - sd->csd[3] =3D 0x5a; /* Max. data transfer rate */ + sd->csd[3] =3D 0x32; /* Max. data transfer rate: 25 MHz */ sd->csd[4] =3D 0x5f; /* Card Command Classes */ sd->csd[5] =3D 0x50 | /* Max. read data block length */ HWBLOCK_SHIFT; --=20 2.16.1 From nobody Wed Apr 16 16:47:02 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 151931362518474.52774582091138; Thu, 22 Feb 2018 07:33:45 -0800 (PST) Received: from localhost ([::1]:39021 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eossS-00059Y-Cp for importer@patchew.org; Thu, 22 Feb 2018 10:33:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38485) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosii-0004v7-6d for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosih-0001mO-7U for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:40 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46608) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosih-0001ke-0P for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:39 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosif-00024x-TU for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:37 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:22:55 +0000 Message-Id: <20180222152307.7499-21-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 20/32] sdcard: clean the SCR register and add few comments 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 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Message-id: 20180215221325.7611-5-f4bug@amsat.org Signed-off-by: Peter Maydell --- hw/sd/sd.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 3526269dbe..c87142d648 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -298,10 +298,13 @@ static void sd_ocr_powerup(void *opaque) =20 static void sd_set_scr(SDState *sd) { - sd->scr[0] =3D 0x00; /* SCR Structure */ - sd->scr[1] =3D 0x2f; /* SD Security Support */ - sd->scr[2] =3D 0x00; + sd->scr[0] =3D (0 << 4) /* SCR version 1.0 */ + | 0; /* Spec Versions 1.0 and 1.01 */ + sd->scr[1] =3D (2 << 4) /* SDSC Card (Security Version 1.01) */ + | 0b0101; /* 1-bit or 4-bit width bus modes */ + sd->scr[2] =3D 0x00; /* Extended Security is not supported. */ sd->scr[3] =3D 0x00; + /* reserved for manufacturer usage */ sd->scr[4] =3D 0x00; sd->scr[5] =3D 0x00; sd->scr[6] =3D 0x00; --=20 2.16.1 From nobody Wed Apr 16 16:47:02 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519313384814920.7070767732662; Thu, 22 Feb 2018 07:29:44 -0800 (PST) Received: from localhost ([::1]:39000 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosoZ-0001m8-Vz for importer@patchew.org; Thu, 22 Feb 2018 10:29:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38502) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosij-0004wE-30 for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosih-0001mz-Oh for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:41 -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 1eosih-0001ls-Hb for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:39 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosig-00025D-K1 for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:38 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:22:56 +0000 Message-Id: <20180222152307.7499-22-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 21/32] sdcard: remove commands from unsupported old MMC specification 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 This device does not model MMCA Specification previous to v4.2 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Message-id: 20180215221325.7611-6-f4bug@amsat.org Signed-off-by: Peter Maydell --- hw/sd/sd.c | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index c87142d648..e55bf1fa75 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1037,24 +1037,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, } break; =20 - case 11: /* CMD11: READ_DAT_UNTIL_STOP */ - if (sd->spi) - goto bad_cmd; - switch (sd->state) { - case sd_transfer_state: - sd->state =3D sd_sendingdata_state; - sd->data_start =3D req.arg; - sd->data_offset =3D 0; - - if (sd->data_start + sd->blk_len > sd->size) - sd->card_status |=3D ADDRESS_ERROR; - return sd_r0; - - default: - break; - } - break; - case 12: /* CMD12: STOP_TRANSMISSION */ switch (sd->state) { case sd_sendingdata_state: @@ -1862,21 +1844,6 @@ uint8_t sd_read_data(SDState *sd) sd->state =3D sd_transfer_state; break; =20 - case 11: /* CMD11: READ_DAT_UNTIL_STOP */ - if (sd->data_offset =3D=3D 0) - BLK_READ_BLOCK(sd->data_start, io_len); - ret =3D sd->data[sd->data_offset ++]; - - if (sd->data_offset >=3D io_len) { - sd->data_start +=3D io_len; - sd->data_offset =3D 0; - if (sd->data_start + io_len > sd->size) { - sd->card_status |=3D ADDRESS_ERROR; - break; - } - } - break; - case 13: /* ACMD13: SD_STATUS */ ret =3D sd->sd_status[sd->data_offset ++]; =20 --=20 2.16.1 From nobody Wed Apr 16 16:47:02 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 From nobody Wed Apr 16 16:47:02 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519313808191368.6365050095201; Thu, 22 Feb 2018 07:36:48 -0800 (PST) Received: from localhost ([::1]:39040 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosvP-0007oL-D0 for importer@patchew.org; Thu, 22 Feb 2018 10:36:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38578) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosin-00051z-Ga for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosij-0001ow-BJ for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:45 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46612) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosij-0001na-2Z for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:41 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosii-00025j-55 for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:40 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:22:58 +0000 Message-Id: <20180222152307.7499-24-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 23/32] sdcard: use the correct masked OCR in the R3 reply 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 use the registerfields API to access the OCR register Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Message-id: 20180215221325.7611-8-f4bug@amsat.org Signed-off-by: Peter Maydell --- hw/sd/sd.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 3e1f7e51ad..5044a306e4 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -47,8 +47,6 @@ =20 //#define DEBUG_SD 1 =20 -#define ACMD41_ENQUIRY_MASK 0x00ffffff - typedef enum { sd_r0 =3D 0, /* no response */ sd_r1, /* normal response command */ @@ -272,13 +270,26 @@ static uint16_t sd_crc16(void *message, size_t width) =20 #define OCR_POWER_DELAY_NS 500000 /* 0.5ms */ =20 +FIELD(OCR, VDD_VOLTAGE_WINDOW, 0, 24) +FIELD(OCR, VDD_VOLTAGE_WIN_LO, 0, 8) +FIELD(OCR, DUAL_VOLTAGE_CARD, 7, 1) +FIELD(OCR, VDD_VOLTAGE_WIN_HI, 8, 16) +FIELD(OCR, ACCEPT_SWITCH_1V8, 24, 1) /* Only UHS-I */ +FIELD(OCR, UHS_II_CARD, 29, 1) /* Only UHS-II */ FIELD(OCR, CARD_CAPACITY, 30, 1) /* 0:SDSC, 1:SDHC/SDXC */ FIELD(OCR, CARD_POWER_UP, 31, 1) =20 +#define ACMD41_ENQUIRY_MASK 0x00ffffff +#define ACMD41_R3_MASK (R_OCR_VDD_VOLTAGE_WIN_HI_MASK \ + | R_OCR_ACCEPT_SWITCH_1V8_MASK \ + | R_OCR_UHS_II_CARD_MASK \ + | R_OCR_CARD_CAPACITY_MASK \ + | R_OCR_CARD_POWER_UP_MASK) + static void sd_set_ocr(SDState *sd) { - /* All voltages OK, Standard Capacity SD Memory Card, not yet powered = up */ - sd->ocr =3D 0x00ffff00; + /* All voltages OK */ + sd->ocr =3D R_OCR_VDD_VOLTAGE_WIN_HI_MASK; } =20 static void sd_ocr_powerup(void *opaque) @@ -446,7 +457,7 @@ static void sd_response_r1_make(SDState *sd, uint8_t *r= esponse) =20 static void sd_response_r3_make(SDState *sd, uint8_t *response) { - stl_be_p(response, sd->ocr); + stl_be_p(response, sd->ocr & ACMD41_R3_MASK); } =20 static void sd_response_r6_make(SDState *sd, uint8_t *response) --=20 2.16.1 From nobody Wed Apr 16 16:47:02 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519313745835504.5291302064197; Thu, 22 Feb 2018 07:35:45 -0800 (PST) Received: from localhost ([::1]:39034 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosuO-0006t0-Rx for importer@patchew.org; Thu, 22 Feb 2018 10:35:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38556) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosil-0004ze-P6 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 1eosik-0001pp-7Z for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:43 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46612) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosij-0001na-W5 for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:42 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosii-00025x-Sa for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:40 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:22:59 +0000 Message-Id: <20180222152307.7499-25-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 24/32] sdcard: use the registerfields API for the CARD_STATUS register masks 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 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Alistair Francis Message-id: 20180215221325.7611-9-f4bug@amsat.org Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- hw/sd/sd.c | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 5044a306e4..cc5caaf4f0 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -419,14 +419,56 @@ static void sd_set_rca(SDState *sd) sd->rca +=3D 0x4567; } =20 +FIELD(CSR, AKE_SEQ_ERROR, 3, 1) +FIELD(CSR, APP_CMD, 5, 1) +FIELD(CSR, FX_EVENT, 6, 1) +FIELD(CSR, READY_FOR_DATA, 8, 1) +FIELD(CSR, CURRENT_STATE, 9, 4) +FIELD(CSR, ERASE_RESET, 13, 1) +FIELD(CSR, CARD_ECC_DISABLED, 14, 1) +FIELD(CSR, WP_ERASE_SKIP, 15, 1) +FIELD(CSR, CSD_OVERWRITE, 16, 1) +FIELD(CSR, DEFERRED_RESPONSE, 17, 1) +FIELD(CSR, ERROR, 19, 1) +FIELD(CSR, CC_ERROR, 20, 1) +FIELD(CSR, CARD_ECC_FAILED, 21, 1) +FIELD(CSR, ILLEGAL_COMMAND, 22, 1) +FIELD(CSR, COM_CRC_ERROR, 23, 1) +FIELD(CSR, LOCK_UNLOCK_FAILED, 24, 1) +FIELD(CSR, CARD_IS_LOCKED, 25, 1) +FIELD(CSR, WP_VIOLATION, 26, 1) +FIELD(CSR, ERASE_PARAM, 27, 1) +FIELD(CSR, ERASE_SEQ_ERROR, 28, 1) +FIELD(CSR, BLOCK_LEN_ERROR, 29, 1) +FIELD(CSR, ADDRESS_ERROR, 30, 1) +FIELD(CSR, OUT_OF_RANGE, 31, 1) + /* Card status bits, split by clear condition: * A : According to the card current state * B : Always related to the previous command * C : Cleared by read */ -#define CARD_STATUS_A 0x02004100 -#define CARD_STATUS_B 0x00c01e00 -#define CARD_STATUS_C 0xfd39a028 +#define CARD_STATUS_A (R_CSR_READY_FOR_DATA_MASK \ + | R_CSR_CARD_ECC_DISABLED_MASK \ + | R_CSR_CARD_IS_LOCKED_MASK) +#define CARD_STATUS_B (R_CSR_CURRENT_STATE_MASK \ + | R_CSR_ILLEGAL_COMMAND_MASK \ + | R_CSR_COM_CRC_ERROR_MASK) +#define CARD_STATUS_C (R_CSR_AKE_SEQ_ERROR_MASK \ + | R_CSR_APP_CMD_MASK \ + | R_CSR_ERASE_RESET_MASK \ + | R_CSR_WP_ERASE_SKIP_MASK \ + | R_CSR_CSD_OVERWRITE_MASK \ + | R_CSR_ERROR_MASK \ + | R_CSR_CC_ERROR_MASK \ + | R_CSR_CARD_ECC_FAILED_MASK \ + | R_CSR_LOCK_UNLOCK_FAILED_MASK \ + | R_CSR_WP_VIOLATION_MASK \ + | R_CSR_ERASE_PARAM_MASK \ + | R_CSR_ERASE_SEQ_ERROR_MASK \ + | R_CSR_BLOCK_LEN_ERROR_MASK \ + | R_CSR_ADDRESS_ERROR_MASK \ + | R_CSR_OUT_OF_RANGE_MASK) =20 static void sd_set_cardstatus(SDState *sd) { --=20 2.16.1 From nobody Wed Apr 16 16:47:02 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 1519313923893992.6901145498761; Thu, 22 Feb 2018 07:38:43 -0800 (PST) Received: from localhost ([::1]:39050 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosxB-000150-6c for importer@patchew.org; Thu, 22 Feb 2018 10:38:37 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38565) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosim-00050I-AD for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosik-0001qe-Ux for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:44 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46614) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosik-0001pM-OA for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:42 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosij-00026D-JP for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:41 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:23:00 +0000 Message-Id: <20180222152307.7499-26-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 25/32] sdcard: handle CMD54 (SDIO) 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 Linux uses it to poll the bus before polling for a card. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Message-id: 20180215221325.7611-10-f4bug@amsat.org Signed-off-by: Peter Maydell --- hw/sd/sd.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index cc5caaf4f0..63da05eaef 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1371,9 +1371,8 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, } break; =20 - case 52: - case 53: - /* CMD52, CMD53: reserved for SDIO cards + case 52 ... 54: + /* CMD52, CMD53, CMD54: reserved for SDIO cards * (see the SDIO Simplified Specification V2.0) * Handle as illegal command but do not complain * on stderr, as some OSes may use these in their --=20 2.16.1 From nobody Wed Apr 16 16:47:02 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519313980602293.10308252903326; Thu, 22 Feb 2018 07:39:40 -0800 (PST) Received: from localhost ([::1]:39053 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosyB-0002Ek-4q for importer@patchew.org; Thu, 22 Feb 2018 10:39:39 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38595) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosip-000543-6R for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosio-0001uY-9B for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:47 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46616) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosio-0001tO-2F for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:46 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosin-00026T-3S for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:45 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:23:01 +0000 Message-Id: <20180222152307.7499-27-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 26/32] sdcard: handle the Security Specification commands 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 returning sd_illegal, since they are not implemented. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Message-id: 20180215221325.7611-11-f4bug@amsat.org [PMM: tweak multiline comment format] Signed-off-by: Peter Maydell --- hw/sd/sd.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 63da05eaef..f13f33efca 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1546,6 +1546,18 @@ static sd_rsp_type_t sd_app_command(SDState *sd, } break; =20 + case 18: /* Reserved for SD security applications */ + case 25: + case 26: + case 38: + case 43 ... 49: + /* Refer to the "SD Specifications Part3 Security Specification" f= or + * information about the SD Security Features. + */ + qemu_log_mask(LOG_UNIMP, "SD: CMD%i Security not implemented\n", + req.cmd); + return sd_illegal; + default: /* Fall back to standard commands. */ return sd_normal_command(sd, req); --=20 2.16.1 From nobody Wed Apr 16 16:47:02 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15193143133171006.7955928969183; Thu, 22 Feb 2018 07:45:13 -0800 (PST) Received: from localhost ([::1]:39087 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eot3Y-0007Cp-Jy for importer@patchew.org; Thu, 22 Feb 2018 10:45:12 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38613) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosiq-00055a-Ln for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosip-0001vz-L2 for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:48 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46618) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosip-0001vB-DD for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:47 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosio-00026h-EZ for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:46 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:23:02 +0000 Message-Id: <20180222152307.7499-28-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 27/32] sdcard: use a more descriptive label 'unimplemented_spi_cmd' 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 Suggested-by: Alistair Francis Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Message-id: 20180215221325.7611-12-f4bug@amsat.org Signed-off-by: Peter Maydell --- hw/sd/sd.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index f13f33efca..34080f0e4c 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1179,8 +1179,9 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, =20 /* Block write commands (Class 4) */ case 24: /* CMD24: WRITE_SINGLE_BLOCK */ - if (sd->spi) - goto unimplemented_cmd; + if (sd->spi) { + goto unimplemented_spi_cmd; + } switch (sd->state) { case sd_transfer_state: /* Writing in SPI mode not implemented. */ @@ -1205,8 +1206,9 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, break; =20 case 25: /* CMD25: WRITE_MULTIPLE_BLOCK */ - if (sd->spi) - goto unimplemented_cmd; + if (sd->spi) { + goto unimplemented_spi_cmd; + } switch (sd->state) { case sd_transfer_state: /* Writing in SPI mode not implemented. */ @@ -1246,8 +1248,9 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, break; =20 case 27: /* CMD27: PROGRAM_CSD */ - if (sd->spi) - goto unimplemented_cmd; + if (sd->spi) { + goto unimplemented_spi_cmd; + } switch (sd->state) { case sd_transfer_state: sd->state =3D sd_receivingdata_state; @@ -1357,8 +1360,9 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, =20 /* Lock card commands (Class 7) */ case 42: /* CMD42: LOCK_UNLOCK */ - if (sd->spi) - goto unimplemented_cmd; + if (sd->spi) { + goto unimplemented_spi_cmd; + } switch (sd->state) { case sd_transfer_state: sd->state =3D sd_receivingdata_state; @@ -1409,7 +1413,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, qemu_log_mask(LOG_GUEST_ERROR, "SD: Unknown CMD%i\n", req.cmd); return sd_illegal; =20 - unimplemented_cmd: + unimplemented_spi_cmd: /* Commands that are recognised but not yet implemented in SPI mod= e. */ qemu_log_mask(LOG_UNIMP, "SD: CMD%i not implemented in SPI mode\n", req.cmd); --=20 2.16.1 From nobody Wed Apr 16 16:47:02 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519314093679886.8732030315529; Thu, 22 Feb 2018 07:41:33 -0800 (PST) Received: from localhost ([::1]:39067 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eoszx-0003rt-OA for importer@patchew.org; Thu, 22 Feb 2018 10:41:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38634) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosir-00056Y-IN for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosiq-0001x0-J9 for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:49 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46618) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosiq-0001vB-B0 for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:48 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosip-00026v-6L for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:47 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:23:03 +0000 Message-Id: <20180222152307.7499-29-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 28/32] sdcard: handles more commands in SPI mode 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 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Message-id: 20180215221325.7611-13-f4bug@amsat.org Signed-off-by: Peter Maydell --- hw/sd/sd.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 34080f0e4c..ff7ace3491 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1386,9 +1386,11 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, =20 /* Application specific commands (Class 8) */ case 55: /* CMD55: APP_CMD */ - if (sd->rca !=3D rca) - return sd_r0; - + if (!sd->spi) { + if (sd->rca !=3D rca) { + return sd_r0; + } + } sd->expecting_acmd =3D true; sd->card_status |=3D APP_CMD; return sd_r1; @@ -1408,6 +1410,18 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, } break; =20 + case 58: /* CMD58: READ_OCR (SPI) */ + if (!sd->spi) { + goto bad_cmd; + } + return sd_r3; + + case 59: /* CMD59: CRC_ON_OFF (SPI) */ + if (!sd->spi) { + goto bad_cmd; + } + goto unimplemented_spi_cmd; + default: bad_cmd: qemu_log_mask(LOG_GUEST_ERROR, "SD: Unknown CMD%i\n", req.cmd); @@ -1431,6 +1445,9 @@ static sd_rsp_type_t sd_app_command(SDState *sd, sd->card_status |=3D APP_CMD; switch (req.cmd) { case 6: /* ACMD6: SET_BUS_WIDTH */ + if (sd->spi) { + goto unimplemented_spi_cmd; + } switch (sd->state) { case sd_transfer_state: sd->sd_status[0] &=3D 0x3f; @@ -1565,6 +1582,12 @@ static sd_rsp_type_t sd_app_command(SDState *sd, default: /* Fall back to standard commands. */ return sd_normal_command(sd, req); + + unimplemented_spi_cmd: + /* Commands that are recognised but not yet implemented in SPI mod= e. */ + qemu_log_mask(LOG_UNIMP, "SD: CMD%i not implemented in SPI mode\n", + req.cmd); + return sd_illegal; } =20 qemu_log_mask(LOG_GUEST_ERROR, "SD: ACMD%i in a wrong state\n", req.cm= d); --=20 2.16.1 From nobody Wed Apr 16 16:47:02 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519314138641942.5289687567521; Thu, 22 Feb 2018 07:42:18 -0800 (PST) Received: from localhost ([::1]:39069 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eot0i-0004Yt-Pj for importer@patchew.org; Thu, 22 Feb 2018 10:42:16 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38637) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosir-00056j-QT for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosir-0001xf-2I for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:49 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46620) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosiq-0001wQ-RH for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:48 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosip-00027B-TL for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:47 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:23:04 +0000 Message-Id: <20180222152307.7499-30-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 29/32] sdcard: check the card is in correct state for APP CMD (CMD55) 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 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Message-id: 20180215221325.7611-14-f4bug@amsat.org Signed-off-by: Peter Maydell --- hw/sd/sd.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index ff7ace3491..d6dd2b9a15 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1386,6 +1386,14 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, =20 /* Application specific commands (Class 8) */ case 55: /* CMD55: APP_CMD */ + switch (sd->state) { + case sd_ready_state: + case sd_identification_state: + case sd_inactive_state: + return sd_illegal; + default: + break; + } if (!sd->spi) { if (sd->rca !=3D rca) { return sd_r0; --=20 2.16.1 From nobody Wed Apr 16 16:47:02 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 1519314301746186.71168754504083; Thu, 22 Feb 2018 07:45:01 -0800 (PST) Received: from localhost ([::1]:39084 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eot3I-0006za-0J for importer@patchew.org; Thu, 22 Feb 2018 10:44:56 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38653) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosis-000589-Pi for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosir-0001yX-W5 for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:50 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46620) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosir-0001wQ-Pc for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:49 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosiq-00027Q-LQ for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:48 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:23:05 +0000 Message-Id: <20180222152307.7499-31-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 30/32] sdcard: warn if host uses an incorrect address for APP CMD (CMD55) 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 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Message-id: 20180215221325.7611-15-f4bug@amsat.org Signed-off-by: Peter Maydell --- hw/sd/sd.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index d6dd2b9a15..c8351d4f0b 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1391,6 +1391,11 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, case sd_identification_state: case sd_inactive_state: return sd_illegal; + case sd_idle_state: + if (rca) { + qemu_log_mask(LOG_GUEST_ERROR, + "SD: illegal RCA 0x%04x for APP_CMD\n", req.= cmd); + } default: break; } --=20 2.16.1 From nobody Wed Apr 16 16:47:02 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519314150673938.3327708896035; Thu, 22 Feb 2018 07:42:30 -0800 (PST) Received: from localhost ([::1]:39070 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eot0v-0004kv-Qi for importer@patchew.org; Thu, 22 Feb 2018 10:42:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38663) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosit-00058h-EI for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosis-0001zD-Gx for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:51 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46622) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosis-0001yC-9k for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:50 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosir-00027g-C0 for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:49 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:23:06 +0000 Message-Id: <20180222152307.7499-32-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 31/32] sdcard: simplify SEND_IF_COND (CMD8) 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 replace switch(single case) -> if() Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Message-id: 20180215221325.7611-16-f4bug@amsat.org Signed-off-by: Peter Maydell --- hw/sd/sd.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index c8351d4f0b..25fce7d6b6 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1008,23 +1008,19 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, =20 case 8: /* CMD8: SEND_IF_COND */ /* Physical Layer Specification Version 2.00 command */ - switch (sd->state) { - case sd_idle_state: - sd->vhs =3D 0; - - /* No response if not exactly one VHS bit is set. */ - if (!(req.arg >> 8) || (req.arg >> (ctz32(req.arg & ~0xff) + 1= ))) { - return sd->spi ? sd_r7 : sd_r0; - } - - /* Accept. */ - sd->vhs =3D req.arg; - return sd_r7; - - default: + if (sd->state !=3D sd_idle_state) { break; } - break; + sd->vhs =3D 0; + + /* No response if not exactly one VHS bit is set. */ + if (!(req.arg >> 8) || (req.arg >> (ctz32(req.arg & ~0xff) + 1))) { + return sd->spi ? sd_r7 : sd_r0; + } + + /* Accept. */ + sd->vhs =3D req.arg; + return sd_r7; =20 case 9: /* CMD9: SEND_CSD */ switch (sd->state) { --=20 2.16.1 From nobody Wed Apr 16 16:47:02 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519314839579778.3827263805257; Thu, 22 Feb 2018 07:53:59 -0800 (PST) Received: from localhost ([::1]:39150 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eotC2-0006CB-MC for importer@patchew.org; Thu, 22 Feb 2018 10:53:58 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38678) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosiu-00059i-EH for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosit-0001zz-El for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:52 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46622) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosit-0001yC-7L for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:51 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosis-00027v-2q for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:50 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:23:07 +0000 Message-Id: <20180222152307.7499-33-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 32/32] sdcard: simplify SD_SEND_OP_COND (ACMD41) 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 replace switch(single case) -> if() Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Message-id: 20180215221325.7611-17-f4bug@amsat.org Signed-off-by: Peter Maydell --- hw/sd/sd.c | 56 ++++++++++++++++++++++++++------------------------------ 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 25fce7d6b6..933890e86f 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1512,45 +1512,41 @@ static sd_rsp_type_t sd_app_command(SDState *sd, sd->state =3D sd_transfer_state; return sd_r1; } - switch (sd->state) { - case sd_idle_state: - /* If it's the first ACMD41 since reset, we need to decide - * whether to power up. If this is not an enquiry ACMD41, - * we immediately report power on and proceed below to the - * ready state, but if it is, we set a timer to model a - * delay for power up. This works around a bug in EDK2 - * UEFI, which sends an initial enquiry ACMD41, but - * assumes that the card is in ready state as soon as it - * sees the power up bit set. */ - if (!FIELD_EX32(sd->ocr, OCR, CARD_POWER_UP)) { - if ((req.arg & ACMD41_ENQUIRY_MASK) !=3D 0) { - timer_del(sd->ocr_power_timer); - sd_ocr_powerup(sd); - } else { - trace_sdcard_inquiry_cmd41(); - if (!timer_pending(sd->ocr_power_timer)) { - timer_mod_ns(sd->ocr_power_timer, - (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) - + OCR_POWER_DELAY_NS)); - } + if (sd->state !=3D sd_idle_state) { + break; + } + /* If it's the first ACMD41 since reset, we need to decide + * whether to power up. If this is not an enquiry ACMD41, + * we immediately report power on and proceed below to the + * ready state, but if it is, we set a timer to model a + * delay for power up. This works around a bug in EDK2 + * UEFI, which sends an initial enquiry ACMD41, but + * assumes that the card is in ready state as soon as it + * sees the power up bit set. */ + if (!FIELD_EX32(sd->ocr, OCR, CARD_POWER_UP)) { + if ((req.arg & ACMD41_ENQUIRY_MASK) !=3D 0) { + timer_del(sd->ocr_power_timer); + sd_ocr_powerup(sd); + } else { + trace_sdcard_inquiry_cmd41(); + if (!timer_pending(sd->ocr_power_timer)) { + timer_mod_ns(sd->ocr_power_timer, + (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + + OCR_POWER_DELAY_NS)); } } + } =20 + if (FIELD_EX32(sd->ocr & req.arg, OCR, VDD_VOLTAGE_WINDOW)) { /* We accept any voltage. 10000 V is nothing. * * Once we're powered up, we advance straight to ready state * unless it's an enquiry ACMD41 (bits 23:0 =3D=3D 0). */ - if (req.arg & ACMD41_ENQUIRY_MASK) { - sd->state =3D sd_ready_state; - } - - return sd_r3; - - default: - break; + sd->state =3D sd_ready_state; } - break; + + return sd_r3; =20 case 42: /* ACMD42: SET_CLR_CARD_DETECT */ switch (sd->state) { --=20 2.16.1