From patchwork Wed Nov 28 13:25:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Agner X-Patchwork-Id: 10702643 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C590914E2 for ; Wed, 28 Nov 2018 13:26:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B0A4B2D2CC for ; Wed, 28 Nov 2018 13:26:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A16DB2D2D0; Wed, 28 Nov 2018 13:26:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EE7422D2CC for ; Wed, 28 Nov 2018 13:26:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=5VblFcXOAFGJ5Xf8/SXoErquvemeZLaPodb2pXTmbJk=; b=HFGJD6CWVV7R+9 1iUt2QpF8T5FatJoPoIL4u14waY1w1Nfp5jrZ0UOm9HHPWpWCH+Dd0+s6UZk7daFjKWR3GDdH5K9u oOwCEmA44qyopvG4P2yFaWEq031oLJ8CzcER/2vR3sPbkmkU9nVG8bV7esyM5A6C2K29ZGLXk34nF //barI+0atnOmN+lDo+IGzu7zSXFFxA1TRod3DbfVxDutrtipTugJO56oFW2cgvG59VFg1XcyBkRm bA0u+/mnUoTSyg/ha+eEa9oL0/wby7LUERKG03glUl6MTTit6J3hgaL3WiQlKzXXjtszPIDYPzpvK i7u50+4yxYL6ONDOt64Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gRzr3-00034Q-R4; Wed, 28 Nov 2018 13:26:13 +0000 Received: from mail.kmu-office.ch ([2a02:418:6a02::a2]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gRzr0-00033z-BL for linux-arm-kernel@lists.infradead.org; Wed, 28 Nov 2018 13:26:12 +0000 Received: from trochilidae.toradex.int (unknown [46.140.72.82]) by mail.kmu-office.ch (Postfix) with ESMTPSA id 9BEFA5C0D8F; Wed, 28 Nov 2018 14:25:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=agner.ch; s=dkim; t=1543411556; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=kmrYbWTrsnLX4BVniuahhuRxXCpcWsRxae9zHzOhLKc=; b=SSWaLxnXQpBhGX96ZBuORbwQFgLcAsufpY+nbboGT0yGtRq1HDecRGy/TWrnGXpFU5EOAu rqAz9PnIHtXuw9/iojnpEaJQhSgxyVAcX5T+lIsvkdOSW8QwfucuvaKT/uiUHp7bTOTEMw 9T6B3J1MBoJH7f5/HCO2QJy1xriV8oQ= From: Stefan Agner To: hongxing.zhu@nxp.com, l.stach@pengutronix.de Subject: [PATCH] pci: imx6: support kernels built in Thumb-2 mode Date: Wed, 28 Nov 2018 14:25:54 +0100 Message-Id: <20181128132554.28139-1-stefan@agner.ch> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181128_052610_679453_3372FDC5 X-CRM114-Status: GOOD ( 16.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lorenzo.pieralisi@arm.com, andrew.smirnov@gmail.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, stefan@agner.ch, bhelgaas@google.com, leonard.crestez@nxp.com, festevam@gmail.com, linux-arm-kernel@lists.infradead.org, tpiepho@impinj.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add a fault handler which handles reads in Thumb-2 mode. Install the appropriate handler depending on which mode the kernel has been built. This avoids an "Unhandled fault: external abort on non-linefetch (0x1008) at 0xf0a80000" during boot on a device with a PCIe switch connected. Link: https://lore.kernel.org/linux-pci/20181126161645.8177-1-stefan@agner.ch/ Signed-off-by: Stefan Agner --- FWIW, I found this manual helpful to write the code below: http://hermes.wings.cs.wisc.edu/files/Thumb-2SupplementReferenceManual.pdf#page=43&zoom=100,0,66 -- Stefan drivers/pci/controller/dwc/pci-imx6.c | 37 ++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c index 69f86234f7c0..683deb74d69f 100644 --- a/drivers/pci/controller/dwc/pci-imx6.c +++ b/drivers/pci/controller/dwc/pci-imx6.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "pcie-designware.h" @@ -299,6 +300,37 @@ static int imx6q_pcie_abort_handler(unsigned long addr, return 1; } +static int imx6q_pcie_abort_handler_thumb2(unsigned long addr, + unsigned int fsr, struct pt_regs *regs) +{ + unsigned long pc = instruction_pointer(regs); + unsigned long instr = *(unsigned long *)pc; + unsigned long thumb2_instr = __mem_to_opcode_thumb16(instr); + int reg = thumb2_instr & 7; + + if (!__opcode_is_thumb16(instr & 0x0000ffffUL)) + return 1; + + /* Load word/byte and halfword immediate offset */ + if (((thumb2_instr & 0xe800) == 0x6800) || + ((thumb2_instr & 0xf800) == 0x8800)) { + unsigned long val; + + if (thumb2_instr & 0x1000) + val = 0xff; + else if (thumb2_instr & 0x8000) + val = 0xffff; + else + val = 0xffffffffUL; + + regs->uregs[reg] = val; + regs->ARM_pc += 2; + return 0; + } + + return 1; +} + static int imx6_pcie_attach_pd(struct device *dev) { struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev); @@ -1069,6 +1101,8 @@ static struct platform_driver imx6_pcie_driver = { static int __init imx6_pcie_init(void) { + bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL); + /* * Since probe() can be deferred we need to make sure that * hook_fault_code is not called after __init memory is freed @@ -1076,7 +1110,8 @@ static int __init imx6_pcie_init(void) * we can install the handler here without risking it * accessing some uninitialized driver state. */ - hook_fault_code(8, imx6q_pcie_abort_handler, SIGBUS, 0, + hook_fault_code(8, thumb2 ? imx6q_pcie_abort_handler_thumb2 : + imx6q_pcie_abort_handler, SIGBUS, 0, "external abort on non-linefetch"); return platform_driver_register(&imx6_pcie_driver);