From: peter@hurleysoftware.com (Peter Hurley)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v5 3/6] ACPI: parse SPCR and enable matching console
Date: Tue, 22 Mar 2016 09:07:30 -0700 [thread overview]
Message-ID: <56F16DC2.7030901@hurleysoftware.com> (raw)
In-Reply-To: <CAHp75VfsayWWSgkvpgrxcER6c2rZyykbvOtm7wBQROR6SFFfWw@mail.gmail.com>
On 03/22/2016 04:09 AM, Andy Shevchenko wrote:
> On Tue, Mar 22, 2016 at 12:46 PM, Aleksey Makarov
> <aleksey.makarov@linaro.org> 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
>>
>
>> +++ 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 <linux/acpi.h>
>> +#include <linux/console.h>
>> +#include <linux/kernel.h>
>> +#include <linux/serial_core.h>
>> +
>> +static bool init_earlycon;
>> +
>> +void __init init_spcr_earlycon(void)
>> +{
>> + init_earlycon = true;
>> +}
>> +
>> +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;
>> +
>> + 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);
>
> You may use snprintf(), though my question here what would happen on
> 32-bit kernel when you supply 64-bit address as an option?
Yeah this should probably use %pa for the printf specifier.
But note this exposes underlying bug in the earlycon support, because
that was originally written without 32/64-mixed bitness in mind; ie.,
the address is parsed and handled as unsigned long in most places.
>> +
>> + 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 <linux/sizes.h>
>> #include <linux/of.h>
>> #include <linux/of_fdt.h>
>> +#include <linux/acpi.h>
>>
>> #ifdef CONFIG_FIX_EARLYCON_MEM
>> #include <asm/fixmap.h>
>> @@ -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;
>
> And you hide an error?
Well, this is a little bit tricky because "earlycon" early parameter with
missing /chosen/stdout-path node is no longer an error, since ACPI may be
specifying the earlycon instead.
Regards,
Peter Hurley
>> + }
>>
>> err = setup_earlycon(buf);
>> if (err == -ENOENT || err == -EALREADY)
>
next prev parent reply other threads:[~2016-03-22 16:07 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-22 10:46 [PATCH v5 0/6] ACPI: parse the SPCR table Aleksey Makarov
2016-03-22 10:46 ` [PATCH v5 1/6] of/serial: move earlycon early_param handling to serial Aleksey Makarov
2016-03-22 11:15 ` Rob Herring
2016-03-22 16:55 ` Aleksey Makarov
2016-03-22 12:28 ` kbuild test robot
2016-03-22 10:46 ` [PATCH v5 2/6] ACPI: add definitions of DBG2 subtypes Aleksey Makarov
2016-03-22 10:46 ` [PATCH v5 3/6] ACPI: parse SPCR and enable matching console Aleksey Makarov
2016-03-22 11:09 ` Andy Shevchenko
2016-03-22 16:07 ` Peter Hurley [this message]
2016-03-22 17:04 ` Aleksey Makarov
2016-03-22 17:21 ` Peter Hurley
2016-03-22 12:26 ` Yury Norov
2016-03-22 14:57 ` Peter Hurley
2016-03-22 16:51 ` Yury Norov
2016-03-22 17:08 ` Aleksey Makarov
2016-03-22 17:32 ` Peter Hurley
2016-03-22 10:46 ` [PATCH v5 4/6] ACPI: enable ACPI_SPCR_TABLE on ARM64 Aleksey Makarov
2016-03-22 10:46 ` [PATCH v5 5/6] serial: pl011: add console matching function Aleksey Makarov
2016-03-22 10:46 ` [PATCH v5 6/6] serial: pl011: add EARLYCON_DECLARE Aleksey Makarov
2016-03-22 16:15 ` Peter Hurley
2016-03-22 17:09 ` Aleksey Makarov
2016-03-22 17:41 ` Peter Hurley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56F16DC2.7030901@hurleysoftware.com \
--to=peter@hurleysoftware.com \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).