From patchwork Wed Nov 23 15:24:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 13053814 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68379C433FE for ; Wed, 23 Nov 2022 15:24:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236308AbiKWPYu (ORCPT ); Wed, 23 Nov 2022 10:24:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236307AbiKWPYr (ORCPT ); Wed, 23 Nov 2022 10:24:47 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 591146253 for ; Wed, 23 Nov 2022 07:24:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669217083; bh=027uEDEoyIMA+UzasI1Z+4I8GRT//yG5VhZ4T1R/Nn0=; h=X-UI-Sender-Class:From:To:Subject:Date; b=cVc2fP+zU+UxGicl42lAWMocLQYs0+7O3D9k1u2UFQWfGwuZEmyIjqgd3ivLUZiaO nEb/deKdzJ9LDQZP+LGJpACMkcL77GprxwUy+TaKFWJQXSPu9wk6iOU+ozykX55qEU ep3H0wACf7NVAF1B9Ne4IRgcUQpfidTwHLsSJkmnb3Gw/WrBvYPB66Dh55j5d/gF0s cDcpiOxETMPg+oeocqPodC+Zp6aMKcipJj+GzHEdlKROwyYonM/xj/0V5sgy2dGNJG kxUAyIuUGmZyq8J26zukklAy4+ja3QcCMU7GaJwAAdyRGxbZ/f8qSARIw8LW9ZwfD6 P58CJCQTx5oBg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from p100.fritz.box ([92.116.168.154]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MYvY2-1oT5Ct2nBI-00UpTl for ; Wed, 23 Nov 2022 16:24:43 +0100 From: Helge Deller To: linux-parisc@vger.kernel.org Subject: [PATCH 1/2] parisc: Add unlocked functions for pdc_iodc_getc() and pdc_iodc_print() Date: Wed, 23 Nov 2022 16:24:34 +0100 Message-Id: <20221123152435.276718-1-deller@gmx.de> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-Provags-ID: V03:K1:PWW0fMar43FZZjFRlcUzWuwH14fJb3ZfC0rxDNpEp3C4D2LAEET IMzneJulX55S3cd2chvrhoB3KVDAW6V3b6hYaqOPS9NidxUbg82e1URw1nXj3meaw0Yrtwt lbVasgzRAqHdo4ryaMqXXc4mVYUSl508BNHXGpSMuCJpaAgJFm3qMT+N2G5wB/bcZXXM3Nj Q+ug+ASdSn/3Ua0Gnlr2A== UI-OutboundReport: notjunk:1;M01:P0:LTKW4s3jjV0=;5Ov9T96spGH3gNMHZs4UadSzGgA ZpfyH+X/JW361JbYmXebqPSyuyd8+ih1P5+wE1c2sdTAiYeKXaf56oM1lxyO1oJbkg2oHZqct 2B8dJluIOPCICgP7dNvX4In7bo7hLt5/EBZ1EgpcXRI0oLlXuSi4QWgJ3T1FgYt5A0XaG0v/D UBRxx4P/0vCdbovyNZAe8ytdW417G4VR7bc/T1r8hl6PWtTlINuyWA6DtFwkfiNuYyWCflG08 dpz1VDkOp5Sn85izsEjIWoBJt5dDmvBgjmlF5zDQF2rfrf4HfZSRokz1Z1fc6CaPZzba/dZuQ j1mOUdP7tyT4MYot0BATQGMeehz60RUwAuSXXoY94JA5f091UaZM1/VDRDqDSmNIQr7Qukpr5 nSd4EHBUI7H4bWWejlU0zHHMbEd7W6TM9eAEDhKFprS38aGZ12qGOA+fGJGnRh/POpiY3SlUA OXLcjY0E1NjwOpNlSQk8zYr7TeOWwcU+u+LgjhwT1OdA4IHODH/gwSilRIGM1zW3gGPA8AfQh 3IXpw2sv6sMKvAU0UbSKKuZR9PpcrBe29DTMxew/RUbmeDKQAdgfh6DMeau639T3gLtZQT9M+ jtxL88vbjyCAuCWtP1fEyetJ5OsqDLn1RbZrkkZG7hkR4OW5Mvc6a1H48QhSxNDxyLG+DqPa1 liARrtpiTr8Rs108agPfhbJStZm699sJJ1jX/XGJzPlQgjLmxjQKi6/UMiaIViSFo+MnjRDdY xzG91oPVkHU0a52SEBMVoWFx8jJFuYWLvKUa1rmjLeffqJJFANPCSuPRDlimhb2BKej1p4fPl hfUS1ljnx1AxoiSdgI6w5d2I/Tf9PUcrehOooTrG0qB6RO21UHVCqbxvyxsiuT+duBA3rtc54 EnzeUPM9ScR9WhI2Eq07cNkk4osPcEIuISiwIpcHyX5DKfhmG3PFgzqlWilQtAoXz2JK7Qr8g Emhp+w== Precedence: bulk List-ID: X-Mailing-List: linux-parisc@vger.kernel.org The built-in kernel debugger (kgdb) deadlocks if we use spinlocks (which should protect against concurrent firmware calls) to get keyboard input or to output to the console. Since we are in debugger mode anyway, we can simply avoid using this protection mechanism, which is why this patch adds unlocked keyboard input/console output functions which will be used by a follow-up patch. In addition save some static bytes by reusing pdc_result[] as iodc_retbuf[] and by reducing the memory footprint of iodc_dbuf[]. Signed-off-by: Helge Deller --- arch/parisc/include/asm/pdc.h | 2 + arch/parisc/kernel/firmware.c | 70 +++++++++++++++++++++-------------- 2 files changed, 45 insertions(+), 27 deletions(-) -- 2.38.1 diff --git a/arch/parisc/include/asm/pdc.h b/arch/parisc/include/asm/pdc.h index fcbcf9a96c11..bca1458b7c44 100644 --- a/arch/parisc/include/asm/pdc.h +++ b/arch/parisc/include/asm/pdc.h @@ -83,7 +83,9 @@ int pdc_soft_power_button(int sw_control); void pdc_io_reset(void); void pdc_io_reset_devices(void); int pdc_iodc_getc(void); +int pdc_iodc_getc_unlocked(void); int pdc_iodc_print(const unsigned char *str, unsigned count); +int pdc_iodc_print_unlocked(const unsigned char *str, unsigned count); void pdc_emergency_unlock(void); int pdc_sti_call(unsigned long func, unsigned long flags, diff --git a/arch/parisc/kernel/firmware.c b/arch/parisc/kernel/firmware.c index 6a7e315bcc2e..6c2bfd6d36b2 100644 --- a/arch/parisc/kernel/firmware.c +++ b/arch/parisc/kernel/firmware.c @@ -1288,25 +1288,14 @@ void pdc_io_reset_devices(void) #endif /* defined(BOOTLOADER) */ -/* locked by pdc_console_lock */ -static int __attribute__((aligned(8))) iodc_retbuf[32]; -static char __attribute__((aligned(64))) iodc_dbuf[4096]; +/* locked by pdc_lock */ +static char __attribute__((aligned(64))) iodc_dbuf[1024]; -/** - * pdc_iodc_print - Console print using IODC. - * @str: the string to output. - * @count: length of str - * - * Note that only these special chars are architected for console IODC io: - * BEL, BS, CR, and LF. Others are passed through. - * Since the HP console requires CR+LF to perform a 'newline', we translate - * "\n" to "\r\n". - */ -int pdc_iodc_print(const unsigned char *str, unsigned count) +int pdc_iodc_print_unlocked(const unsigned char *str, unsigned count) { unsigned int i; - unsigned long flags; + count = min(count, sizeof(iodc_dbuf)); for (i = 0; i < count;) { switch(str[i]) { case '\n': @@ -1322,16 +1311,35 @@ int pdc_iodc_print(const unsigned char *str, unsigned count) } print: - spin_lock_irqsave(&pdc_lock, flags); - real32_call(PAGE0->mem_cons.iodc_io, - (unsigned long)PAGE0->mem_cons.hpa, ENTRY_IO_COUT, - PAGE0->mem_cons.spa, __pa(PAGE0->mem_cons.dp.layers), - __pa(iodc_retbuf), 0, __pa(iodc_dbuf), i, 0); - spin_unlock_irqrestore(&pdc_lock, flags); + real32_call(PAGE0->mem_cons.iodc_io, + (unsigned long)PAGE0->mem_cons.hpa, ENTRY_IO_COUT, + PAGE0->mem_cons.spa, __pa(PAGE0->mem_cons.dp.layers), + __pa(pdc_result), 0, __pa(iodc_dbuf), i, 0); return i; } +/** + * pdc_iodc_print - Console print using IODC. + * @str: the string to output. + * @count: length of str + * + * Note that only these special chars are architected for console IODC io: + * BEL, BS, CR, and LF. Others are passed through. + * Since the HP console requires CR+LF to perform a 'newline', we translate + * "\n" to "\r\n". + */ +int pdc_iodc_print(const unsigned char *str, unsigned count) +{ + unsigned long flags; + int ret; + + spin_lock_irqsave(&pdc_lock, flags); + ret = pdc_iodc_print_unlocked(str, count); + spin_unlock_irqrestore(&pdc_lock, flags); + return ret; +} + #if !defined(BOOTLOADER) /** * pdc_iodc_getc - Read a character (non-blocking) from the PDC console. @@ -1339,26 +1347,23 @@ int pdc_iodc_print(const unsigned char *str, unsigned count) * Read a character (non-blocking) from the PDC console, returns -1 if * key is not present. */ -int pdc_iodc_getc(void) +int pdc_iodc_getc_unlocked(void) { int ch; int status; - unsigned long flags; /* Bail if no console input device. */ if (!PAGE0->mem_kbd.iodc_io) return 0; /* wait for a keyboard (rs232)-input */ - spin_lock_irqsave(&pdc_lock, flags); real32_call(PAGE0->mem_kbd.iodc_io, (unsigned long)PAGE0->mem_kbd.hpa, ENTRY_IO_CIN, PAGE0->mem_kbd.spa, __pa(PAGE0->mem_kbd.dp.layers), - __pa(iodc_retbuf), 0, __pa(iodc_dbuf), 1, 0); + __pa(pdc_result), 0, __pa(iodc_dbuf), 1, 0); ch = *iodc_dbuf; - status = *iodc_retbuf; - spin_unlock_irqrestore(&pdc_lock, flags); + status = *pdc_result; if (status == 0) return -1; @@ -1366,6 +1371,17 @@ int pdc_iodc_getc(void) return ch; } +int pdc_iodc_getc(void) +{ + unsigned long flags; + int ch; + + spin_lock_irqsave(&pdc_lock, flags); + ch = pdc_iodc_getc_unlocked(); + spin_unlock_irqrestore(&pdc_lock, flags); + return ch; +} + int pdc_sti_call(unsigned long func, unsigned long flags, unsigned long inptr, unsigned long outputr, unsigned long glob_cfg) From patchwork Wed Nov 23 15:24:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 13053815 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35B48C4332F for ; Wed, 23 Nov 2022 15:24:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236307AbiKWPYv (ORCPT ); Wed, 23 Nov 2022 10:24:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236514AbiKWPYs (ORCPT ); Wed, 23 Nov 2022 10:24:48 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF29A62C2 for ; Wed, 23 Nov 2022 07:24:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669217086; bh=Q5LoITtDXx1IawdeTJdtGcowSmAImxHRkeIQRt2RPiU=; h=X-UI-Sender-Class:From:To:Subject:Date:In-Reply-To:References; b=riPSG7YSJ9FcOoAMRSvmG1cyUflQvOBMmHuzyjd50d1qDyAZF3SvZ8MCcKiL22+QX ydyfzWIkJklFZaJqqEyVdaUP+7+PX78YyVOEcooKuwj8ER5ERoaMNJHEW5a2AY6W2H Xv4Ys7F1dxRbAZRJqv1OGJUv1kx1XlkW6tt+fcI29XN8kkfiQk3+XNIjKc3sU4O4bm mvvapkMBsKHvsh1spYNCLTlZpF9tp29JpOu7gsRj0Br0hqFWjsrnXirZnUpzd/cNb9 Xb2AGuzrz2z1olL39TWbp5WCbuLOy4073Gb4mzhfPXXe2w7ypupFE6+FBpvpK3gAHY PiVFHM79vpoMA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from p100.fritz.box ([92.116.168.154]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N5GDv-1p60vj0EFB-0117US for ; Wed, 23 Nov 2022 16:24:46 +0100 From: Helge Deller To: linux-parisc@vger.kernel.org Subject: [PATCH 2/2] parisc: Fix kgdb keyboard input in pdc early console driver Date: Wed, 23 Nov 2022 16:24:35 +0100 Message-Id: <20221123152435.276718-2-deller@gmx.de> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221123152435.276718-1-deller@gmx.de> References: <20221123152435.276718-1-deller@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:GdL2FuL1jxDtjabyxupCx39Y+T0Zb5lpq1AFDsSVAz/0vvprxMG bT361r8ts67Iwd8WSXwKm8ZOA2EGfUOzWDKb2MArPLJujJr5+L1NEPYJ0Hvl50oSc0GrRZI 0Q18BkgXVEikFFmx0WUClm1S/zb2Um8XmRyLvqZyi66JLCDW4YWD0pozHxAlh19viu4q8XY bK9ZLRo3M+/v2hxec//JQ== UI-OutboundReport: notjunk:1;M01:P0:K+klLJwdFfE=;/1Vzuh209ruCXRhRHq+zeOcLplX fr3DDJCha/TXlRa4MSmU14q6qDs+2NXqcCbkclovQ1Ex2ifJu5GnRF40xOYQRaBaIO61ioAar 3AuxoeKzWan2fK7S1Q3MWd10SzcProlD/3DuitfDvadtQDcmOQHjhjpH6vf6Xh/1MUacMNai5 kKKunrDClpEVPEQZLh68i6jIU/I5mqxgMSFU4wiOkxelPyojG869cqNNpv58JlHi6V3f/lUi1 vW9VPaQ6Xi3s16pEEe7O8Gg5ia7NEUzEBBUZawLLH7GZGY80Qt9EmC/O4ZJHcvC05JvSPdjXN yCX4A7Kdm5gkWyjDj75PL1IOYjlk5S0CIVX8l8yfU9pqpqnaW0sAqWtgMqJ2eBUGwQGMFLzC+ jLyYj8W2dbnrDE/qPiPDKeX/9+ra1WPmm3oeGWmyzMkH8vfze+/L++yVNoLMFhc+0rvMPynEd pPttXojfoC1UnedW00WEk/HjXf0QVKW0GkIsrMJjzVOLkebll4ulxzk3tjDh01IdX3zN7/csD 66QwVL7/7TlfAPe0IW7UNf9LIgI5+0fyA0nrDUaIpU1yxl+NTDqr/GuXDI9iCZe7f1Ektntas 2uvp55igokvIwHeqcUhWwyi5Q33yfpX937i5mAnFT5hQeiW704ve9Bw0//Q0F/SCu5L0gjTeu w1W9qeJi3gLy6gcBjhGzS8QcEcCXb7QA5X3guzL4cSnv1CJLnU9YSYaOmM6Cj4Owc6Y0FXj2F ZWjAfg7TUWZT8t1CRWz16bTYxeNFGpUkO92YkRwUn4JrG11WhduhJAf1J3wm5xIbyrfVD0e0I 1+60iXGHQ0rDGc+zeKnJZOV9wLGONS4dXbqYm44pQ//v9aQpC61S0ro3QED2IkwuI6FPncwBF KcQWdpAJqPv6wrZa4R3loP+bxWpYATlntWpc0Aca0QcrlS2ruMj91hJYNuJo38N7AZnoDiUvD trLa+w== Precedence: bulk List-ID: X-Mailing-List: linux-parisc@vger.kernel.org Commit 027c3d345e2a ("parisc: Convert PDC console to an early console") broke (physical) keyboard input for kgdb due to the spinlocks used in the PDC console function. Fix it by using using PDC calls which are not protected by spinlocks. Fixes: 027c3d345e2a ("parisc: Convert PDC console to an early console") Signed-off-by: Helge Deller --- arch/parisc/kernel/pdc_cons.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) -- 2.38.1 diff --git a/arch/parisc/kernel/pdc_cons.c b/arch/parisc/kernel/pdc_cons.c index 7d0989f523d0..bb498c6d51c2 100644 --- a/arch/parisc/kernel/pdc_cons.c +++ b/arch/parisc/kernel/pdc_cons.c @@ -12,29 +12,19 @@ #include /* for PAGE0 */ #include /* for iodc_call() proto and friends */ -static DEFINE_SPINLOCK(pdc_console_lock); - static void pdc_console_write(struct console *co, const char *s, unsigned count) { int i = 0; - unsigned long flags; - spin_lock_irqsave(&pdc_console_lock, flags); do { i += pdc_iodc_print(s + i, count - i); } while (i < count); - spin_unlock_irqrestore(&pdc_console_lock, flags); } #ifdef CONFIG_KGDB static int kgdb_pdc_read_char(void) { - int c; - unsigned long flags; - - spin_lock_irqsave(&pdc_console_lock, flags); - c = pdc_iodc_getc(); - spin_unlock_irqrestore(&pdc_console_lock, flags); + int c = pdc_iodc_getc_unlocked(); return (c <= 0) ? NO_POLL_CHAR : c; } @@ -42,7 +32,7 @@ static int kgdb_pdc_read_char(void) static void kgdb_pdc_write_char(u8 chr) { if (PAGE0->mem_cons.cl_class != CL_DUPLEX) - pdc_console_write(NULL, &chr, 1); + pdc_iodc_print_unlocked(&chr, 1); } static struct kgdb_io kgdb_pdc_io_ops = {