All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Kiper <dkiper@net-space.pl>
To: peterz@infradead.org
Cc: grub-devel@gnu.org, development@efficientek.com
Subject: Re: [PATCH v2 2/3] term/serial: Add support for PCI serial devices
Date: Wed, 21 Dec 2022 13:59:02 +0100	[thread overview]
Message-ID: <20221221125902.jw5kjwmxupeozt3b@tomti.i.net-space.pl> (raw)
In-Reply-To: <20220826111358.334758397@alderlake.programming.kicks-ass.net>

Sorry for late reply...

May I ask you to send the patches using "git send-email"?

On Fri, Aug 26, 2022 at 01:01:44PM +0200, peterz@infradead.org wrote:
> Loosely based on early_pci_serial_init() from Linux, allow GRUB to make
> use of PCI serial devices.
>
> Specifically, my Alderlake NUC exposes the Intel AMT SoL UART as a PCI
> enumerated device but doesn't include it in the EFI tables.
>
> Tested and confirmed working on a "Lenovo P360 Tiny" with Intel AMT
> enabled. This specific machine has (from lspci -vv):
>
> 00:16.3 Serial controller: Intel Corporation Device 7aeb (rev 11) (prog-if 02 [16550])
>         DeviceName: Onboard - Other
>         Subsystem: Lenovo Device 330e
>         Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
>         Status: Cap+ 66MHz+ UDF- FastB2B+ ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
>         Interrupt: pin D routed to IRQ 19
>         Region 0: I/O ports at 40a0 [size=8]
>         Region 1: Memory at b4224000 (32-bit, non-prefetchable) [size=4K]
>         Capabilities: [40] MSI: Enable- Count=1/1 Maskable- 64bit+
>                 Address: 0000000000000000  Data: 0000
>         Capabilities: [50] Power Management version 3
>                 Flags: PMEClk- DSI+ D1- D2- AuxCurrent=0mA PME(D0-,D1-,D2-,D3hot-,D3cold-)
>                 Status: D0 NoSoftRst+ PME-Enable- DSel=0 DScale=0 PME-
>         Kernel driver in use: serial
>
> >From which the following config (/etc/default/grub) gets a working
> serial setup:
>
> GRUB_CMDLINE_LINUX="console=tty0 earlyprintk=pciserial,00:16.3,115200 console=ttyS0,115200"
> GRUB_SERIAL_COMMAND="serial --port=0x40a0 --speed=115200"

Please add a blurb how to use this driver to the docs/grub.texi file.

> GRUB_TERMINAL="serial console"
>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> ---
>
> Index: grub/grub-core/Makefile.core.def
> ===================================================================
> --- grub.orig/grub-core/Makefile.core.def
> +++ grub/grub-core/Makefile.core.def
> @@ -2047,6 +2047,7 @@ module = {
>    ieee1275 = term/ieee1275/serial.c;
>    mips_arc = term/arc/serial.c;
>    efi = term/efi/serial.c;
> +  pci = term/pci/serial.c;

I think this should be "x86 = term/pci/serial.c".

>
>    enable = terminfomodule;
>    enable = ieee1275;
> Index: grub/grub-core/term/pci/serial.c
> ===================================================================
> --- /dev/null
> +++ grub/grub-core/term/pci/serial.c
> @@ -0,0 +1,95 @@
> +/*
> + *  GRUB  --  GRand Unified Bootloader
> + *  Copyright (C) 2022  Free Software Foundation, Inc.
> + *
> + *  GRUB is free software: you can redistribute it and/or modify
> + *  it under the terms of the GNU General Public License as published by
> + *  the Free Software Foundation, either version 3 of the License, or
> + *  (at your option) any later version.
> + *
> + *  GRUB is distributed in the hope that it will be useful,
> + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
> + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + *  GNU General Public License for more details.
> + *
> + *  You should have received a copy of the GNU General Public License
> + *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <grub/serial.h>
> +#include <grub/term.h>
> +#include <grub/types.h>
> +#include <grub/pci.h>
> +#include <grub/mm.h>
> +#include <grub/misc.h>
> +
> +static int
> +find_pciserial (grub_pci_device_t dev, grub_pci_id_t pciid, void *data)

grub_pci_id_t pciid __attribute__ ((unused))

> +{
> +  grub_pci_address_t cmd_addr, class_addr, bar_addr;
> +  struct grub_serial_port *port;
> +  grub_uint32_t class, bar;
> +  grub_uint16_t cmdreg;
> +  int *port_num = data;
> +  grub_err_t err;
> +
> +  (void)pciid;

... and please drop this...

> +  cmd_addr = grub_pci_make_address (dev, GRUB_PCI_REG_COMMAND);
> +  cmdreg = grub_pci_read (cmd_addr);
> +
> +  class_addr = grub_pci_make_address (dev, GRUB_PCI_REG_REVISION);
> +  class = grub_pci_read (class_addr);
> +
> +  bar_addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG0);
> +  bar = grub_pci_read (bar_addr);
> +
> +  /* 16550 compattible MODEM or SERIAL */
> +  if (((class >> 16) != GRUB_PCI_CLASS_COMMUNICATION_MODEM &&
> +       (class >> 16) != GRUB_PCI_CLASS_COMMUNICATION_SERIAL) ||
> +      ((class >> 8) & 0xff) != GRUB_PCI_SERIAL_16550_COMPATIBLE)
> +    return 0;
> +
> +  if ((bar & GRUB_PCI_ADDR_SPACE_MASK) != GRUB_PCI_ADDR_SPACE_IO)
> +    return 0;
> +
> +  port = grub_zalloc (sizeof (*port));
> +  if (port == NULL)
> +    return 0;
> +
> +  port->name = grub_xasprintf ("pci%d", (*port_num));
> +  if (port->name == NULL)
> +    goto error;
> +
> +  grub_pci_write (cmd_addr, cmdreg | GRUB_PCI_COMMAND_IO_ENABLED);
> +
> +  port->driver = &grub_ns8250_driver;
> +  port->port = bar & GRUB_PCI_ADDR_IO_MASK;
> +  err = grub_serial_config_defaults (port);
> +  if (err != GRUB_ERR_NONE)
> +    {
> +      grub_print_error ();
> +      goto error;
> +    }
> +
> +  err = grub_serial_register (port);
> +  if (err != GRUB_ERR_NONE)
> +    goto error;
> +
> +  (*port_num)++;
> +
> +  return 0;
> +
> +error:

s/error/fail/

And please add a space before label...

> +  grub_free (port->name);
> +  grub_free (port);
> +  return 0;
> +}

Daniel


  parent reply	other threads:[~2022-12-21 12:59 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-26 11:01 [PATCH v2 0/3] term/serial: Add PCI-serial device support peterz
2022-08-26 11:01 ` [PATCH v2 1/3] configure: Add -DGRUB_HAS_PCI when compiling C/C++ files on targets that support PCI peterz
2022-08-26 11:01 ` [PATCH v2 2/3] term/serial: Add support for PCI serial devices peterz
2022-08-26 18:32   ` Glenn Washburn
2022-08-29 10:53     ` Peter Zijlstra
2022-08-30 19:51       ` Glenn Washburn
2022-12-21 12:59   ` Daniel Kiper [this message]
2023-01-26  9:37     ` Peter Zijlstra
2023-01-26 21:16       ` Glenn Washburn
2023-02-09 10:36       ` Peter Zijlstra
2023-02-09 14:52         ` Daniel Kiper
2023-02-12 21:23           ` Benjamin Herrenschmidt
2023-02-14 13:49             ` Daniel Kiper
2022-08-26 11:01 ` [PATCH v2 3/3] pci: Rename GRUB_PCI_CLASS_* peterz
2022-12-21 15:52   ` Daniel Kiper
2022-08-31  6:18 ` [PATCH v2 0/3] term/serial: Add PCI-serial device support Herrenschmidt, Benjamin
2022-12-17 17:52 ` Glenn Washburn

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=20221221125902.jw5kjwmxupeozt3b@tomti.i.net-space.pl \
    --to=dkiper@net-space.pl \
    --cc=development@efficientek.com \
    --cc=grub-devel@gnu.org \
    --cc=peterz@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.