All of lore.kernel.org
 help / color / mirror / Atom feed
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: grub-devel@gnu.org
Cc: Matthias Lange <matthias.lange@kernkonzept.com>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>
Subject: [PATCH 4/5] ns8250: Add configuration parameter when adding ports
Date: Fri, 19 Mar 2021 09:07:27 +1100	[thread overview]
Message-ID: <20210318220728.495970-5-benh@kernel.crashing.org> (raw)
In-Reply-To: <20210318220728.495970-1-benh@kernel.crashing.org>

This will allow ports to be added with a pre-set configuration

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
 grub-core/term/ns8250.c | 25 +++++++++++++++++++------
 grub-core/term/serial.c |  2 +-
 include/grub/serial.h   |  4 ++--
 3 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/grub-core/term/ns8250.c b/grub-core/term/ns8250.c
index 183e14b3b..d783c2897 100644
--- a/grub-core/term/ns8250.c
+++ b/grub-core/term/ns8250.c
@@ -298,7 +298,7 @@ grub_ns8250_hw_get_port (const unsigned int unit)
 }
 
 char *
-grub_serial_ns8250_add_port (grub_port_t port)
+grub_serial_ns8250_add_port (grub_port_t port, struct grub_serial_config *config)
 {
   struct grub_serial_port *p;
   unsigned i;
@@ -307,6 +307,9 @@ grub_serial_ns8250_add_port (grub_port_t port)
       {
 	if (dead_ports & (1 << i))
 	  return NULL;
+	/* give the opportunity for SPCR to configure a default com port */
+	if (config)
+	  grub_serial_port_configure (&com_ports[i], config);
 	return com_names[i];
       }
 
@@ -328,22 +331,29 @@ grub_serial_ns8250_add_port (grub_port_t port)
       return NULL;
     }
   p->driver = &grub_ns8250_driver;
-  grub_serial_config_defaults (p);
   p->mmio = 0;
   p->port = port;
+  if (config)
+    grub_serial_port_configure (p, config);
+  else
+    grub_serial_config_defaults (p);
   grub_serial_register (p);  
 
   return p->name;
 }
 
 char *
-grub_serial_ns8250_add_mmio(grub_addr_t addr)
+grub_serial_ns8250_add_mmio(grub_addr_t addr, struct grub_serial_config *config)
 {
   struct grub_serial_port *p;
   unsigned i;
   for (i = 0; i < GRUB_SERIAL_PORT_NUM; i++)
-    if (com_ports[i].mmio &&  com_ports[i].mmio_base == addr)
-	return com_names[i];
+    if (com_ports[i].mmio && com_ports[i].mmio_base == addr)
+      {
+        if (config)
+          grub_serial_port_configure (&com_ports[i], config);
+        return com_names[i];
+      }
 
   p = grub_malloc (sizeof (*p));
   if (!p)
@@ -355,9 +365,12 @@ grub_serial_ns8250_add_mmio(grub_addr_t addr)
       return NULL;
     }
   p->driver = &grub_ns8250_driver;
-  grub_serial_config_defaults (p);
   p->mmio = 1;
   p->mmio_base = addr;
+  if (config)
+    grub_serial_port_configure (p, config);
+  else
+    grub_serial_config_defaults (p);
   grub_serial_register (p);
 
   return p->name;
diff --git a/grub-core/term/serial.c b/grub-core/term/serial.c
index 7d4dbb2de..313341f53 100644
--- a/grub-core/term/serial.c
+++ b/grub-core/term/serial.c
@@ -156,7 +156,7 @@ grub_serial_find (const char *name)
       && grub_isxdigit (name [sizeof ("port") - 1]))
     {
       name = grub_serial_ns8250_add_port (grub_strtoul (&name[sizeof ("port") - 1],
-							0, 16));
+							0, 16), NULL);
       if (!name)
 	return NULL;
 
diff --git a/include/grub/serial.h b/include/grub/serial.h
index a5756cd25..5677dae33 100644
--- a/include/grub/serial.h
+++ b/include/grub/serial.h
@@ -184,8 +184,8 @@ grub_serial_config_defaults (struct grub_serial_port *port)
 
 #if defined(__mips__) || defined (__i386__) || defined (__x86_64__)
 void grub_ns8250_init (void);
-char *grub_serial_ns8250_add_port (grub_port_t port);
-char *grub_serial_ns8250_add_mmio(grub_addr_t addr);
+char *grub_serial_ns8250_add_port (grub_port_t port, struct grub_serial_config *config);
+char *grub_serial_ns8250_add_mmio(grub_addr_t addr, struct grub_serial_config *config);
 #endif
 #ifdef GRUB_MACHINE_IEEE1275
 void grub_ofserial_init (void);
-- 
2.25.1



  parent reply	other threads:[~2021-03-18 22:08 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-18 22:07 [PATCH 0/5] serial: Add MMIO & SPCR support for AWS EC2 metal instances Benjamin Herrenschmidt
2021-03-18 22:07 ` [PATCH 1/5] acpi: Export a generic grub_acpi_find_table Benjamin Herrenschmidt
2021-03-18 22:07 ` [PATCH 2/5] acpi: Add SPCR and generic address definitions Benjamin Herrenschmidt
2021-03-18 22:07 ` [PATCH 3/5] ns8250: Add base support for MMIO UARTs Benjamin Herrenschmidt
2021-03-19 17:16   ` Glenn Washburn
2021-03-19 23:30     ` Benjamin Herrenschmidt
2022-05-23 17:11   ` Sven Anderson
2022-05-25  3:13     ` Benjamin Herrenschmidt
2022-08-31  5:56     ` Benjamin Herrenschmidt
2022-08-31  8:26       ` Benjamin Herrenschmidt
2022-09-02  3:58         ` Benjamin Herrenschmidt
2021-03-18 22:07 ` Benjamin Herrenschmidt [this message]
2021-03-18 22:07 ` [PATCH 5/5] ns8250: Use ACPI SPCR table when available to configure serial Benjamin Herrenschmidt
2021-03-19  0:03 ` [PATCH 0/5] serial: Add MMIO & SPCR support for AWS EC2 metal instances Glenn Washburn
2021-03-19  1:27   ` Benjamin Herrenschmidt
2021-03-19 16:25     ` Glenn Washburn
2021-03-23 18:04 ` Daniel Kiper
2021-03-23 22:23   ` Benjamin Herrenschmidt

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=20210318220728.495970-5-benh@kernel.crashing.org \
    --to=benh@kernel.crashing.org \
    --cc=grub-devel@gnu.org \
    --cc=matthias.lange@kernkonzept.com \
    /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.