From patchwork Wed Feb 24 22:47:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Baumann X-Patchwork-Id: 8414911 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 326AD9F2F0 for ; Wed, 24 Feb 2016 22:48:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2C55A20266 for ; Wed, 24 Feb 2016 22:48:31 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 042F120373 for ; Wed, 24 Feb 2016 22:48:30 +0000 (UTC) Received: from localhost ([::1]:38861 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYiEP-0003d8-En for patchwork-qemu-devel@patchwork.kernel.org; Wed, 24 Feb 2016 17:48:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47332) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYiEE-0003bO-Ob for qemu-devel@nongnu.org; Wed, 24 Feb 2016 17:48:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aYiEA-00048W-4M for qemu-devel@nongnu.org; Wed, 24 Feb 2016 17:48:18 -0500 Received: from mail-by2on0129.outbound.protection.outlook.com ([207.46.100.129]:14010 helo=na01-by2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYiE9-00048K-SF for qemu-devel@nongnu.org; Wed, 24 Feb 2016 17:48:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=aTvBsFwieeIQTfM97+IaLBz5ohTH5HvVO+sAHyhHDig=; b=RBizxHC5o0rTwkeNg9qTkSzeIQMfpyhaW/A9BEdLk9mam6moG9giatd9KYB2oiOOoFZI++B5ncLcJzQlE6N3f1c+kLNqHQQzQZFn5AI6JaZZS2b9Fjqf1LSs3RrJUUaPEMM67Gl68JeOLvjAYOiAbq5N6iLEq9CluaUGhZcaKi0= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none; nongnu.org; dmarc=none action=none header.from=microsoft.com; Received: from baumann-desk.redmond.corp.microsoft.com (2001:4898:80e8:d::724) by BLUPR0301MB2036.namprd03.prod.outlook.com (10.164.22.26) with Microsoft SMTP Server (TLS) id 15.1.409.15; Wed, 24 Feb 2016 22:48:11 +0000 From: Andrew Baumann To: Date: Wed, 24 Feb 2016 14:47:55 -0800 Message-ID: <1456354075-8424-3-git-send-email-Andrew.Baumann@microsoft.com> X-Mailer: git-send-email 2.5.1 In-Reply-To: <1456354075-8424-1-git-send-email-Andrew.Baumann@microsoft.com> References: <1456354075-8424-1-git-send-email-Andrew.Baumann@microsoft.com> MIME-Version: 1.0 X-Originating-IP: [2001:4898:80e8:d::724] X-ClientProxiedBy: CO2PR05CA041.namprd05.prod.outlook.com (10.141.241.169) To BLUPR0301MB2036.namprd03.prod.outlook.com (25.164.22.26) X-MS-Office365-Filtering-Correlation-Id: 1d0f9068-2ce9-4969-5c59-08d33d6c92f7 X-Microsoft-Exchange-Diagnostics: 1; BLUPR0301MB2036; 2:OSS8cTFyKINoS3cPp2K6r61HEFtB7oV84ECa4giadw22JwPrQhRJ4vII0wzRl0UXUG/i2zPC4m44BNv972imm+9dCEeDZry4t9JC45pu8oJeZneNZ6AXrGVUy6gPrD11+MdaPVW3LYDW1Nqq0LmUGRIxtvBCYn3G/IZsI0Me8w9BnfldG5xstqjlwf6USVik; 3:d07o99YVHTx9wzsJ6kGbSJub9tBxlkR6ax8hkmLx5jtM01qttEk48QGbBq0htRlIqGhQvAdQzw68BbhlbgocmOq3OSTTObattzAyoVLG+D0ehtY19oxLvRVCGYROarLJ; 25:esA/uz740yLRw2el/91TVe3jxjHlGb5afmYmWpgdHe/K2Gof01k32fDRiR+jPiHRZwowR86sAUXG80oJIWePRXpJQuGuqVtnoJJZc/ZsOxC1XyBzYzw9KEfF6D2N38Lhj0JgFrdGo1pcwUsAuYGmDB4doYFN/sG8TcUEm1ULFflHTEFSiO7K30Tce7eYKWLXI1y3oR4URPuHcQcJ3lbLEmVlkiPDQGYwvoYmLI/rjiDolCzNP8lMQIPRjcNVJTS4O9Vb2P4DROjD2IxKZVVFPp5nLBfbLbnfv79+fJSsMbnwwxcUuyQWYXaJ30Dgk4aYUbK5aiVrkvgospxK+Z6L7w== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR0301MB2036; X-Microsoft-Exchange-Diagnostics: 1; BLUPR0301MB2036; 20:FcWR3byYeRAdpp/2FIl8591ZuxWJLH7ptdwDWaLEVLq/A0MqnrGaWBCWIhFFjhTpXtufYbFbhXEgyIx3MigHj8iITPBEkzoQAWSTgrS3d9APj0Xw1WamKEg9pRs3I+6JDlro0s/2rqEpgmmO1+MQikCHirvf84zST1NG8/97TONKqTijgRUIazk5AjkU5Oz3wsGgvItmmso5hrxm5nBC/PsArbSj6mE7XAYmgt8tOj95m07pufcx6jEk0r0r9RKIxrx2boK0QmjBgyejp4/2DGnTmVXXdM29RrPNPMUvTPzBmhaVMURWrMScIJ7Qzby9g3QBQ2NafWv3wQYDU9z05v7Rf8unHq5shJNI1/500/Zy/gsmNFjGFGI4qkm7IULkD540X7Qy2opURbOBBuEF9NTI4JGPfU+4u6/6NHWBHAnGKUGx6V/CdYyzEFd3hlnECeblpm6V2UqX6Msi55I4r5GRDM4+zOESGb2H0RiNmOKYsTL4Xc+LaPUEY9/780pd; 4:sEsR7/7Snmvlv4sZwqXasHneI58cx1hRSDK4i1784XfdKfNsoHghb+vp+ElPhGIzKfIDJzDBWposYa6ajlilYhLr4iu+KTtZ0loudsQ9fJnJY1YNNnYG3ip+MeTXH+9rYKzCIQnwAxynlpaxWNRhQyLHpsaxkB2lgR1M3UppR+ZZWFpwqsqgDHGxLChjWxDMjMzwIl4jSsNOi8R4rIHBxcWP7Viaf/oslvo2hurjl3ZPqxbiNjI0DNuipKxkDJrEnt0C5BjIEo2JQcHZbC/NY7tzZZETT7kxszshEZUtnbjeQ/V+eXALvR5+wqAn6xRHdU3/AwtFEbhv9bAOEY75TLuARJgRGcZAFH1lrrQ2VI4qfiN6D4RAOmBuNglGSnB0 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046); SRVR:BLUPR0301MB2036; BCL:0; PCL:0; RULEID:; SRVR:BLUPR0301MB2036; X-Forefront-PRVS: 08626BE3A5 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(42186005)(50986999)(76176999)(189998001)(107886002)(5001960100002)(110136002)(87976001)(1096002)(36756003)(4001430100002)(47776003)(5008740100001)(2906002)(4326007)(586003)(5004730100002)(48376002)(50466002)(6116002)(50226001)(229853001)(92566002)(2351001)(15975445007)(40100003)(5005710100001)(122386002)(86612001)(5003940100001)(2950100001)(77096005)(10090500001)(19580405001)(19580395003)(86362001)(10290500002)(7059030); DIR:OUT; SFP:1102; SCL:1; SRVR:BLUPR0301MB2036; H:baumann-desk.redmond.corp.microsoft.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BLUPR0301MB2036; 23:0bcQTaq0+oZEFQ/LoKyGYMXwbLSkyuejqr5TcXH?= =?us-ascii?Q?Ds6FmbXzCceXBeGjcMgVLGYwcncM+hqsbrQiObHaKUl1ojhYIHorgM3uMNcD?= =?us-ascii?Q?P7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kt25H8jKNk/qwCG4?= =?us-ascii?Q?Q6V1lM573P/9mAmSUPxLJHO6okevqZIu4IkJL5Xe8MUTA+Ncx3xNpIy+jIs6?= =?us-ascii?Q?yAKzBoK+aw6UuNFwF0YegXmOOMwHDBxED4zMUgPQvz5b+/n436Pb8CvnGRdF?= =?us-ascii?Q?reYyqo7ha7xk=3D?= X-Microsoft-Exchange-Diagnostics: 1; BLUPR0301MB2036; 5:T++iSSzjdWd/J/PlkxLfaQIDLYmtCHX7CZ0JGMA0qhIAqXG7yAaY2bfMLHpYFv0qT8taNtOjo+lhfu26gqwClQEzFWV++950s1j1fK/ZGTScLNz2AO0saSs+AtkmTQ324o2Kd9wLS4CPgZzrXY5XHw==; 24:BriyiL3zt47wZsxFt5UdL7bONROJ4IJiYDVPNhEzMEMhrtuSHSWC84QHwDiX6dLok4Hhz55D+Klc4atE+EnDBdNSry5UUFkiGPC/SFbFpRQ= X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2016 22:48:11.3630 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR0301MB2036 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 X-Received-From: 207.46.100.129 Cc: Peter Maydell , Igor Mitsyanko , Andrew Baumann , Sai Pavan Boddu , Peter Crosthwaite , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH v3 2/2] sdhci: add quirk property for card insert interrupt status on Raspberry Pi X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This quirk is a workaround for the following hardware behaviour, on which UEFI (specifically, the bootloader for Windows on Pi2) depends: 1. at boot with an SD card present, the interrupt status/enable registers are initially zero 2. upon enabling it in the interrupt enable register, the card insert bit in the interrupt status register is immediately set 3. after a subsequent controller reset, the card insert interrupt does not fire, even if enabled in the interrupt enable register The implementation uses a pending_insert bool, which can be set via a property (enabling the quirk) and is cleared and remains clear once the interrupt has been delivered. Signed-off-by: Andrew Baumann --- There's a fairly extensive discussion of the hardware behaviour that this patch seeks to model in the thread at: https://lists.gnu.org/archive/html/qemu-devel/2016-01/msg00605.html v3: changed to use subsection for vmstate, to preserve backward compatibility v2: changed implementation to use pending_insert bool rather than masking norintsts at read time, since the older version diverges from actual hardware behaviour when an interrupt is masked without being acked hw/sd/sdhci.c | 33 ++++++++++++++++++++++++++++++++- include/hw/sd/sdhci.h | 1 + 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c index f175b30..db34d78 100644 --- a/hw/sd/sdhci.c +++ b/hw/sd/sdhci.c @@ -204,6 +204,7 @@ static void sdhci_reset(SDHCIState *s) s->data_count = 0; s->stopped_state = sdhc_not_stopped; + s->pending_insert = false; } static void sdhci_data_transfer(void *opaque); @@ -1095,6 +1096,12 @@ sdhci_write(void *opaque, hwaddr offset, uint64_t val, unsigned size) } else { s->norintsts &= ~SDHC_NIS_ERR; } + /* Quirk for Raspberry Pi: pending card insert interrupt + * appears when first enabled after power on */ + if ((s->norintstsen & SDHC_NISEN_INSERT) && s->pending_insert) { + s->norintsts |= SDHC_NIS_INSERT; + s->pending_insert = false; + } sdhci_update_irq(s); break; case SDHC_NORINTSIGEN: @@ -1181,6 +1188,24 @@ static void sdhci_uninitfn(SDHCIState *s) s->fifo_buffer = NULL; } +static bool sdhci_pending_insert_vmstate_needed(void *opaque) +{ + SDHCIState *s = opaque; + + return s->pending_insert; +} + +static const VMStateDescription sdhci_pending_insert_vmstate = { + .name = "sdhci/pending-insert", + .version_id = 1, + .minimum_version_id = 1, + .needed = sdhci_pending_insert_vmstate_needed, + .fields = (VMStateField[]) { + VMSTATE_BOOL(pending_insert, SDHCIState), + VMSTATE_END_OF_LIST() + }, +}; + const VMStateDescription sdhci_vmstate = { .name = "sdhci", .version_id = 1, @@ -1215,7 +1240,11 @@ const VMStateDescription sdhci_vmstate = { VMSTATE_TIMER_PTR(insert_timer, SDHCIState), VMSTATE_TIMER_PTR(transfer_timer, SDHCIState), VMSTATE_END_OF_LIST() - } + }, + .subsections = (const VMStateDescription*[]) { + &sdhci_pending_insert_vmstate, + NULL + }, }; /* Capabilities registers provide information on supported features of this @@ -1224,6 +1253,8 @@ static Property sdhci_pci_properties[] = { DEFINE_PROP_UINT32("capareg", SDHCIState, capareg, SDHC_CAPAB_REG_DEFAULT), DEFINE_PROP_UINT32("maxcurr", SDHCIState, maxcurr, 0), + DEFINE_PROP_BOOL("pending-insert-quirk", SDHCIState, pending_insert, + false), DEFINE_PROP_END_OF_LIST(), }; diff --git a/include/hw/sd/sdhci.h b/include/hw/sd/sdhci.h index 4816516..aab7cf0 100644 --- a/include/hw/sd/sdhci.h +++ b/include/hw/sd/sdhci.h @@ -76,6 +76,7 @@ typedef struct SDHCIState { uint32_t buf_maxsz; uint16_t data_count; /* current element in FIFO buffer */ uint8_t stopped_state;/* Current SDHC state */ + bool pending_insert;/* Quirk for Raspberry Pi card insert interrupt */ /* Buffer Data Port Register - virtual access point to R and W buffers */ /* Software Reset Register - always reads as 0 */ /* Force Event Auto CMD12 Error Interrupt Reg - write only */