Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758428AbcCVM1Y (ORCPT ); Tue, 22 Mar 2016 08:27:24 -0400 Received: from mail-bn1bon0092.outbound.protection.outlook.com ([157.56.111.92]:45088 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752592AbcCVM1P (ORCPT ); Tue, 22 Mar 2016 08:27:15 -0400 Authentication-Results: linaro.org; dkim=none (message not signed) header.d=none;linaro.org; dmarc=none action=none header.from=caviumnetworks.com; Date: Tue, 22 Mar 2016 15:26:50 +0300 From: Yury Norov To: Aleksey Makarov CC: Greg Kroah-Hartman , "Rafael J . Wysocki" , Len Brown , , , , , Russell King , Leif Lindholm , Graeme Gregory , Al Stone , Christopher Covington , Peter Hurley , "Zheng, Lv" , Jiri Slaby Subject: Re: [PATCH v5 3/6] ACPI: parse SPCR and enable matching console Message-ID: <20160322122650.GA10616@yury-N73SV> References: <1458643595-14719-1-git-send-email-aleksey.makarov@linaro.org> <1458643595-14719-4-git-send-email-aleksey.makarov@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <1458643595-14719-4-git-send-email-aleksey.makarov@linaro.org> User-Agent: Mutt/1.5.23 (2014-03-12) X-Originating-IP: [95.143.213.121] X-ClientProxiedBy: AM3PR01CA056.eurprd01.prod.exchangelabs.com (10.141.191.46) To BY2PR07MB615.namprd07.prod.outlook.com (10.141.222.150) X-MS-Office365-Filtering-Correlation-Id: f825bd6d-c936-4e7e-85c1-08d3524d4916 X-Microsoft-Exchange-Diagnostics: 1;BY2PR07MB615;2:OWBv6TeFe6JO8+ah0KI/tcSnSSwASi/OOMQfjAV6mycBH83zm5Y/Qdy+YCSrlPJ/CETqEF6k4iVaSXZ8NhXqPfnsXBT4B5OiEiaavM8NSVGmrkQ91/gTgWMonoEnmHltD3Hh8axfMYWyMyiS9kACoFElucb1niGX4OjrUyXNTlQSev+NtVs70L4kMHXj0m3l;3:boZQ2+wA3RxRKCbG+tfyOWNHF9JnaIqdfQLU2wmAznMGrqoupUqLvzhb9GuNmhOSxQnotWZeukd1R70tIYvkp0LdYKDDgKI4aim+eyzp/96imwXJ7Vb8Wc8FVmy6NSzu X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR07MB615; X-Microsoft-Exchange-Diagnostics: 1;BY2PR07MB615;25:yGtYaNjvzONsy3h4edxPC2xy6IAxM8z13/2kRUrWiNcMQwB7KYOhHU7VY+u464rqv804xh/sFYPKF6HYZy09ZcFI+gUX4wdVjQqGBZ1IgqSDw9JeU1FC0bTh2ClnVtp9dI8cXyWpIYUyX8tw0a7MYLa3r59HNEcspiAwgx0Y8DPQAE1PFZ5PB6i6SBvr7OAULDMNfOZutlHeGUEUGZQhqualvRC3CGphsqLyZru2f4phUnpvgh/uZhn9LuJ1v2lPc2QwxXLVIhO6EJA7PDN9wB5+vSCJM5sUInyWwCmlLoNAOSJXbD3G+fdK1xWzzu4lTP50tFNglVvemBth1TC3vLhI/eG645mwfk3OZoh/Ua61Cz99XUGSpOHC0bKZvTiDbqg+/VEVMXI5qfjzDfmXrMhrumK2kF0X+GrS7ikFz+ABuS4qALsaRChfbeDkeFgF2lbx5I80Oo8AtptbjMDG7Rscc9RAAAv1qXC/XiFu9h0fV/W8FWmoopfXERNuCrfdhjocwdQexBTrLd7+qypLK6ezMrSMYk9/g0hW/FhdjADGUWalPC3oLEPqybngL48pARpNPXeuqwYdi2QH9xiTEjMr8EV7hY/F1gcRrqWqTEg2SupE1HtDFFP2+0xKa3TFWjel9yyWYGi5vtWl4sXcEDiN/P6drGxrPVhaoWxxh/bD/0vgDJqk173ni58x/xWhLnmI6Xj9wIaUDtbN1c9f69OIh6JjyWvpK4889QPEsqE= X-Microsoft-Exchange-Diagnostics: 1;BY2PR07MB615;20:w6d7bKnr/dWoYVwXcZK+KunovEjf/4k/RZy30rh76aoAAPhHeIuwDLyR/gfHO6Vrx4wNAfSyYp+CFjdXuSGp/AnGcXhn/Nq45x3BoYQOLLSW+r4n3/XJPvS2n79AbtCANyUMPQw/BR2QLf/FS8vumpyB84HKvlopPe3DhycRbA5PSrglmiPOXqI4Mj1TlgafPms5ni9+Liv/zlA3MwRZFJqAEjlsv9UGKmTjjIyGfvLWITLKWkVjUlnDs7TRvGedi7kYZRt6VVAQS4p/oOern9qIrDNKLFbAuZrGIdGBwv4JlK6QScdMXiEjHytgJIjktPXCS0+F5RNbHXepG3iIt/m7KMIoEKpxPRG+4zlcNFxqXBVMLQEu8BRts+NSG69tLIe5LnaUUm16PEwJ11UCNku+VYDg4JiEvixvHbMyRvYqdujmjxdPXyILQc5Ozb6bE6gsiSAngfrqOTIvJrUVbBfTLHuv+9ot63cm8rNixY8bKr2wtsuLSm4JTX7JtDfHh19zvbiSPck4oci5jdRwJCfftjhPP3CivTRt3cAz4oN+cvSCzvmvHXM95II9uTRZ+W7qDoOm0iRA1hMpLV+vp+ZMvDgO0OHlFaVLjxtdSG8= 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:BY2PR07MB615;BCL:0;PCL:0;RULEID:;SRVR:BY2PR07MB615; X-Microsoft-Exchange-Diagnostics: 1;BY2PR07MB615;4:887P3juMAsB4HdIU4AE+BM1Qjo1i3kWai67BwuHWgBfN8fMhyfu+dKaWDZqsbnxtlDlT43WHjm6C3PSeadQiLh1jXq3/2gTydqFFXmOImj4SzNiCGwU6xZIpP7FyIkQFQCOxGYn5Hglp9bA4QjrGGUff/E5p6Mmz3Uq9zfzI3Fx5H/pR/Z/z1dahTEprW4+xefxpaN8nvexEvGfXTE8LhZsgE7Q4BiZahcJH9VP/IPyZKGLl+zxOl/gH9hO+oRVeQu+gbC4LnGsMCbPQd/tIs7NtK2QuYPjyUm8hwEYgq6QhhmiEMuPtePsTXnh3YFsQGrTqaRf1FD6vfo3fwnTmm56/8Hqb3hpEb7fhm9TCWFpyH6Aw0nk9mPTK6oVhYZS/ X-Forefront-PRVS: 08897B549D X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6069001)(6009001)(24454002)(3905003)(5008740100001)(19580395003)(83506001)(19580405001)(54356999)(50986999)(76176999)(33656002)(50466002)(66066001)(76506005)(77096005)(42186005)(97756001)(2906002)(4326007)(46406003)(47776003)(1076002)(3846002)(1096002)(586003)(92566002)(33716001)(81166005)(15975445007)(110136002)(5004730100002)(4001350100001)(23726003)(6116002)(2950100001)(189998001)(2004002);DIR:OUT;SFP:1101;SCL:1;SRVR:BY2PR07MB615;H:localhost;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BY2PR07MB615;23:YJTDzl9bwSKzIOr7C847wtcSr1aor1xppms/mPDNPY?= =?us-ascii?Q?ip4B2jq5WR9/6U8PSCzfqqNxts/9OIS04EH0YsD+yXWDEOhUZHhfEw9+vcRn?= =?us-ascii?Q?uOHiEjFFxgS18W6zRKRfbIXS6YZse9ztNoXunFZmcYHgAAUW4rWcxgzir/q2?= =?us-ascii?Q?Kp/NyaEvB89qKbliyC4l5jxhapJOTfIjaJO2bgjP+CJajyWowchAVD67aQR0?= =?us-ascii?Q?ySCNBfSQK8AXKpxzsqPyZM3eWj35dmdMZWJWyXmwZpW9pYJr5PQNjKKqoXt1?= =?us-ascii?Q?f1i/jauxVBZuqdGdYkZHfIgJ/FBkI0NgMCDsH4k3GCDh+oZqHm9ueExkVRW0?= =?us-ascii?Q?O4zq/blEuBDZ8tqNCU1NmS3tGWx/Trzcq0UCCWZB4kB4PBKM+7Z5VH86y5YZ?= =?us-ascii?Q?eGYqQLY1ijtVmJ4h6h7tjcrT+BbFnwF5QAraWNFkOY1IBnyjDTD96Dv6yuCU?= =?us-ascii?Q?XBIQfYVHkkOBFIJ7265CFIFvhpQPEfNLt2YzyPdu33gnzcUQKEbfyhiBu8Uq?= =?us-ascii?Q?eT/IFX8eswWlK/XRgmpYtPluWmu8mNK4OaSmW0cODS2hjYhT/4/OxPXKLe4E?= =?us-ascii?Q?k8mXGGCkPjY4bRcEmKhug2ucyrvXISDfXxs8GwyIPB14irunyGkwHA1m/gzd?= =?us-ascii?Q?2InP2GDim7qpRm5NtNmsec4SCMhGRqTsneMRgqePlNzSzlkW5G5C93bwRfq2?= =?us-ascii?Q?7di+WfWNlONqoATvEXwr41DtVQvmUcBHPNxO8KxMYM4+9aCskmpUVlUnHLp3?= =?us-ascii?Q?ORY0/AxGa2GgM5wQmiDqkRcDcIMqncWwahIA1PHidqSzzwybb7b4VPfoM09i?= =?us-ascii?Q?VvoGtekDyeN3m11KLGdR4quM4GqPCAfYBI6FRoMJ8MMpJaHsRdjN6EnmVakf?= =?us-ascii?Q?iGJ9+qBW4OavubhFENJDv62ze7dQqeFCIgIUNra2QQ3mOOtO97iPM0Cmd/0k?= =?us-ascii?Q?p+pbLX1M8UTwirsJyzm6zrGeGBhaN8GrI7AjWXxz7/uVJUPskLRdgoJeh/zu?= =?us-ascii?Q?QQ3f6gHpKClPvtC7ByFYGRpl2alaOoJsHywt9h5E2dWQ=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;BY2PR07MB615;5:XJkamnIfpc+Ke3nB6g0HlXWato15Co8A1guH65i/NMO/cHbe1KKX7fOhuc+bGuBuflzSI7RDrIW05PJqRaWfOiXiR+6OqYUQqfM6DQ81ibMO5x4irKpKcEBREwDbaD6QiFdevFgbA2OxQW9RaDltbg==;24:IXUwLamPc53OR2JNGIOuXH8Xg715aVFRBrVWxKkc8MKKBxFi0KjvrLXlKwtuHXdF7Mtyg5T3bFgJPngZpnWntGjQxnu5SRQxmefx+X6u2XQ= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Mar 2016 12:27:07.6075 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR07MB615 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 6308 Lines: 221 On Tue, Mar 22, 2016 at 01:46:30PM +0300, Aleksey Makarov wrote: > 'ARM Server Base Boot Requiremets' [1] mentions SPCR (Serial Port > Console Redirection Table) [2] as a mandatory ACPI table that > specifies the configuration of serial console. > > Parse this table, setup earlycon and enable the specified console. > > Thanks to Peter Hurley for explaining how this should work. > > [1] http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.den0044a/index.html > [2] https://msdn.microsoft.com/en-us/library/windows/hardware/dn639132(v=vs.85).aspx > > Signed-off-by: Aleksey Makarov > --- > drivers/acpi/Kconfig | 3 ++ > drivers/acpi/Makefile | 1 + > drivers/acpi/spcr.c | 102 ++++++++++++++++++++++++++++++++++++++++++ > drivers/tty/serial/earlycon.c | 13 ++++-- > include/linux/acpi.h | 8 ++++ > 5 files changed, 123 insertions(+), 4 deletions(-) > create mode 100644 drivers/acpi/spcr.c > > diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig > index 65fb483..5611eb6 100644 > --- a/drivers/acpi/Kconfig > +++ b/drivers/acpi/Kconfig > @@ -77,6 +77,9 @@ config ACPI_DEBUGGER_USER > > endif > > +config ACPI_SPCR_TABLE > + bool > + > config ACPI_SLEEP > bool > depends on SUSPEND || HIBERNATION > diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile > index 7395928..f70ae14 100644 > --- a/drivers/acpi/Makefile > +++ b/drivers/acpi/Makefile > @@ -82,6 +82,7 @@ obj-$(CONFIG_ACPI_EC_DEBUGFS) += ec_sys.o > obj-$(CONFIG_ACPI_CUSTOM_METHOD)+= custom_method.o > obj-$(CONFIG_ACPI_BGRT) += bgrt.o > obj-$(CONFIG_ACPI_CPPC_LIB) += cppc_acpi.o > +obj-$(CONFIG_ACPI_SPCR_TABLE) += spcr.o > obj-$(CONFIG_ACPI_DEBUGGER_USER) += acpi_dbg.o > > # processor has its own "processor." module_param namespace > diff --git a/drivers/acpi/spcr.c b/drivers/acpi/spcr.c > new file mode 100644 > index 0000000..1ec82f9 > --- /dev/null > +++ b/drivers/acpi/spcr.c > @@ -0,0 +1,102 @@ > +/* > + * Copyright (c) 2012, Intel Corporation > + * Copyright (c) 2015, Red Hat, Inc. > + * Copyright (c) 2015, 2016 Linaro Ltd. > + * > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License version 2 as > + * published by the Free Software Foundation. > + * > + */ > + > +#define pr_fmt(fmt) "ACPI: SPCR: " fmt > + > +#include > +#include > +#include > +#include > + > +static bool init_earlycon; > + > +void __init init_spcr_earlycon(void) > +{ > + init_earlycon = true; > +} > + 1. I see you keep in mind multiple access. Then you'd worry about race conditions as well. In this case, I'd consider atomic access to variable. 2. It seems you need is_init() helper too. > +int __init parse_spcr(void) > +{ > + static char opts[64]; > + struct acpi_table_spcr *table; > + acpi_size table_size; > + acpi_status status; > + char *uart; > + char *iotype; > + int baud_rate; > + int err = 0; You can do not initialize 'err'. > + > + status = acpi_get_table_with_size(ACPI_SIG_SPCR, 0, > + (struct acpi_table_header **)&table, > + &table_size); > + > + if (ACPI_FAILURE(status)) > + return -ENOENT; > + > + if (table->header.revision < 2) { > + err = -EINVAL; > + pr_err("wrong table version\n"); > + goto done; > + } > + > + iotype = (table->serial_port.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) ? > + "mmio" : "io"; > + > + switch (table->interface_type) { > + case ACPI_DBG2_ARM_SBSA_32BIT: > + iotype = "mmio32"; > + /* fall through */ > + case ACPI_DBG2_ARM_PL011: > + case ACPI_DBG2_ARM_SBSA_GENERIC: > + case ACPI_DBG2_BCM2835: > + uart = "pl011"; > + break; > + case ACPI_DBG2_16550_COMPATIBLE: > + case ACPI_DBG2_16550_SUBSET: > + uart = "uart"; > + break; > + default: > + err = -ENOENT; > + goto done; > + } > + > + switch (table->baud_rate) { > + case 3: > + baud_rate = 9600; > + break; > + case 4: > + baud_rate = 19200; > + break; > + case 6: > + baud_rate = 57600; > + break; > + case 7: > + baud_rate = 115200; > + break; > + default: > + err = -ENOENT; > + goto done; > + } > + > + sprintf(opts, "%s,%s,0x%llx,%d", uart, iotype, > + table->serial_port.address, baud_rate); As 'opts' is static, don't you need to take some measures to prevent concurrent access. The simpler measure for me is to declare it on stack. > + > + pr_info("console: %s", opts); > + > + if (init_earlycon) > + setup_earlycon(opts); > + > + err = add_preferred_console(uart, 0, opts + strlen(uart) + 1); > + > +done: > + early_acpi_os_unmap_memory((void __iomem *)table, table_size); > + return err; > +} > diff --git a/drivers/tty/serial/earlycon.c b/drivers/tty/serial/earlycon.c > index d217366..ec030c9 100644 > --- a/drivers/tty/serial/earlycon.c > +++ b/drivers/tty/serial/earlycon.c > @@ -22,6 +22,7 @@ > #include > #include > #include > +#include > > #ifdef CONFIG_FIX_EARLYCON_MEM > #include > @@ -206,11 +207,15 @@ static int __init param_setup_earlycon(char *buf) > int err; > > /* > - * Just 'earlycon' is a valid param for devicetree earlycons; > - * don't generate a warning from parse_early_params() in that case > + * Just 'earlycon' is a valid param for devicetree and ACPI SPCR > + * earlycons; don't generate a warning from parse_early_params() > + * in that case > */ > - if (!buf || !buf[0]) > - return early_init_dt_scan_chosen_serial(); > + if (!buf || !buf[0]) { > + init_spcr_earlycon(); > + early_init_dt_scan_chosen_serial(); > + return 0; > + } > > err = setup_earlycon(buf); > if (err == -ENOENT || err == -EALREADY) > diff --git a/include/linux/acpi.h b/include/linux/acpi.h > index 06ed7e5..ebbb212 100644 > --- a/include/linux/acpi.h > +++ b/include/linux/acpi.h > @@ -1004,4 +1004,12 @@ static inline struct fwnode_handle *acpi_get_next_subnode(struct device *dev, > #define acpi_probe_device_table(t) ({ int __r = 0; __r;}) > #endif > > +#ifdef CONFIG_ACPI_SPCR_TABLE > +int parse_spcr(void); > +void init_spcr_earlycon(void); > +#else > +static inline int parse_spcr(void) { return 0; } > +static inline void init_spcr_earlycon(void) {} > +#endif > + > #endif /*_LINUX_ACPI_H*/ > -- > 2.7.4