grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v3 0/2] term/serial: Add PCI-serial device support


From: Glenn Washburn
Subject: [PATCH v3 0/2] term/serial: Add PCI-serial device support
Date: Sat, 13 May 2023 02:54:50 -0500

This series adds support for discovering serial devices on the PCI bus.
I've modified Peter's v2 patches to include feedback from Daniel. I've
also added a changes suggested by Peter to expose serial devices on the
PCI bus as "pci,XX:XX.X" instead of "pciN". This is less likely to change
due to a hardware reconfiguration. For instance, if there is one PCI serial
device at 02:00.0, with the pciN naming, there will exist a pci0 serial
device. If later, the hardware configuration is changed such that a PCI
serial device is added at 01:00.0, then GRUB will set pci0 to the newly
added serial device and pci1 will be the old one. This could cause
for the user as to why adding another serial device makes the previous
device "stop working". I have tested these additional changes in QEMU by
adding a virtual PCI serial device and verified that GRUB does show
additional serial devices to choose for the output terminal. The changes
from v2 are below and pretty minimal.

Glenn

peterz@infradead.org (2):
  term/serial: Add support for PCI serial devices
  pci: Rename GRUB_PCI_CLASS_*

 docs/grub.texi                      | 13 ++++-
 grub-core/Makefile.core.def         |  1 +
 grub-core/kern/i386/qemu/init.c     |  4 +-
 grub-core/term/pci/serial.c         | 91 +++++++++++++++++++++++++++++
 grub-core/term/serial.c             |  6 +-
 grub-core/video/efi_uga.c           |  2 +-
 grub-core/video/radeon_fuloong2e.c  |  2 +-
 grub-core/video/radeon_yeeloong3a.c |  2 +-
 grub-core/video/sis315pro.c         |  2 +-
 grub-core/video/sm712.c             |  2 +-
 include/grub/pci.h                  |  9 ++-
 include/grub/serial.h               |  4 ++
 12 files changed, 125 insertions(+), 13 deletions(-)
 create mode 100644 grub-core/term/pci/serial.c

Range-diff against v2:
1:  c186d56bf7ff ! 1:  17bb8f10447a term/serial: Add support for PCI serial 
devices
    @@ Commit message
         GRUB_SERIAL_COMMAND="serial --port=0x40a0 --speed=115200"
         GRUB_TERMINAL="serial console"
     
    +    Documentation is added to note that serial devices found on the PCI 
bus will
    +    be exposed as "pci,XX:XX.X" and how to find serial terminal logical 
names.
    +    Also, some minor documentation improvements were added.
    +
    +    This can be tested in QEMU by adding a pci-serial device, eg. using 
the option
    +    "-device pci-serial".
    +
         Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    +    Tested-by: Glenn Washburn <development@efficientek.com>
    +
    + ## docs/grub.texi ##
    +@@ docs/grub.texi: grub> @kbd{terminal_input serial; terminal_output 
serial}
    + The command @command{serial} initializes the serial unit 0 with the
    + speed 9600bps. The serial unit 0 is usually called @samp{COM1}, so, if
    + you want to use COM2, you must specify @samp{--unit=1} instead. This
    +-command accepts many other options, so please refer to @ref{serial},
    +-for more details.
    ++command accepts many other options, @pxref{serial} for more details.
    + 
    + Without argument or with @samp{--port=auto}, GRUB will attempt to use
    + ACPI when available to auto-detect the default serial port and its
    +@@ docs/grub.texi: Additionally, an MMIO address can be suffixed with:
    + @samp{.q} for 64-bit long long word access
    + @end itemize
    + 
    ++Also, @var{port} can be of the form @samp{pci,XX:XX.X} to indicate a 
serial
    ++device exposed on the PCI bus.
    ++
    + @var{speed} is the transmission speed; default is 9600. @var{word} and
    + @var{stop} are the number of data bits and stop bits. Data bits must
    + be in the range 5-8 and stop bits must be 1 or 2. Default is 8 data
    +@@ docs/grub.texi: The serial port is not used as a communication channel 
unless the
    + @command{terminal_input} or @command{terminal_output} command is used
    + (@pxref{terminal_input}, @pxref{terminal_output}).
    + 
    ++Note, valid @var{port} values, excluding IO port addresses, can be found
    ++by listing terminals with @command{terminal_output}, selecting all names
    ++prefixed by @samp{serial_} and removing that prefix.
    ++
    + Examples:
    + @example
    +-serial --port=3f8 --speed=9600
    ++serial --port=0x3f8 --speed=9600
    + serial --port=mmio,fefb0000.l --speed=115200
    ++serial --port=pci,00:16.3 --speed=115200
    + @end example
    + 
    + See also @ref{Serial terminal}.
     
      ## grub-core/Makefile.core.def ##
     @@ grub-core/Makefile.core.def: module = {
        ieee1275 = term/ieee1275/serial.c;
        mips_arc = term/arc/serial.c;
        efi = term/efi/serial.c;
    -+  pci = term/pci/serial.c;
    ++  x86 = term/pci/serial.c;
      
        enable = terminfomodule;
        enable = ieee1275;
    @@ grub-core/term/pci/serial.c (new)
     @@
     +/*
     + *  GRUB  --  GRand Unified Bootloader
    -+ *  Copyright (C) 2022  Free Software Foundation, Inc.
    ++ *  Copyright (C) 2023  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
    @@ grub-core/term/pci/serial.c (new)
     +#include <grub/misc.h>
     +
     +static int
    -+find_pciserial (grub_pci_device_t dev, grub_pci_id_t pciid, void *data)
    ++find_pciserial (grub_pci_device_t dev, grub_pci_id_t pciid __attribute__ 
((unused)), void *data __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;
    -+
     +  cmd_addr = grub_pci_make_address (dev, GRUB_PCI_REG_COMMAND);
     +  cmdreg = grub_pci_read (cmd_addr);
     +
    @@ grub-core/term/pci/serial.c (new)
     +  if (port == NULL)
     +    return 0;
     +
    -+  port->name = grub_xasprintf ("pci%d", (*port_num));
    ++  port->name = grub_xasprintf ("pci,%02x:%02x.%x",
    ++                         grub_pci_get_bus (dev),
    ++                         grub_pci_get_device (dev),
    ++                         grub_pci_get_function (dev));
     +  if (port->name == NULL)
    -+    goto error;
    ++    goto fail;
     +
     +  grub_pci_write (cmd_addr, cmdreg | GRUB_PCI_COMMAND_IO_ENABLED);
     +
    @@ grub-core/term/pci/serial.c (new)
     +  if (err != GRUB_ERR_NONE)
     +    {
     +      grub_print_error ();
    -+      goto error;
    ++      goto fail;
     +    }
     +
     +  err = grub_serial_register (port);
     +  if (err != GRUB_ERR_NONE)
    -+    goto error;
    -+
    -+  (*port_num)++;
    ++    goto fail;
     +
     +  return 0;
     +
    -+error:
    ++ fail:
     +  grub_free (port->name);
     +  grub_free (port);
     +  return 0;
    @@ grub-core/term/pci/serial.c (new)
     +void
     +grub_pciserial_init (void)
     +{
    -+  int port_num;
    -+
    -+  grub_pci_iterate (find_pciserial, &port_num);
    ++  grub_pci_iterate (find_pciserial, NULL);
     +}
     
      ## grub-core/term/serial.c ##
    +@@ grub-core/term/serial.c: grub_cmd_serial (grub_extcmd_context_t ctxt, 
int argc, char **args)
    + 
    +   if (state[OPTION_PORT].set)
    +     {
    +-      if (grub_strncmp (state[OPTION_PORT].arg, "mmio,", sizeof ("mmio,") 
- 1) == 0)
    ++      if (grub_strncmp (state[OPTION_PORT].arg, "mmio,", sizeof ("mmio,") 
- 1) == 0 ||
    ++    grub_strncmp (state[OPTION_PORT].arg, "pci,", sizeof ("pci,") - 1) == 
0)
    +           grub_snprintf (pname, sizeof (pname), "%s", state[1].arg);
    +       else
    +           grub_snprintf (pname, sizeof (pname), "port%lx",
     @@ grub-core/term/serial.c: GRUB_MOD_INIT(serial)
      #ifdef GRUB_MACHINE_ARC
        grub_arcserial_init ();
2:  4aa0e0db57a8 = 2:  0eb2d7c01d9b pci: Rename GRUB_PCI_CLASS_*
-- 
2.34.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]