From: Benjamin Leggett <benjamin@edera.io>
To: xen-devel@lists.xenproject.org
Cc: "Benjamin Leggett" <benjamin@edera.io>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Anthony PERARD" <anthony.perard@vates.tech>,
"Michal Orzel" <michal.orzel@amd.com>,
"Jan Beulich" <jbeulich@suse.com>,
"Julien Grall" <julien@xen.org>,
"Roger Pau Monné" <roger@xenproject.org>,
"Stefano Stabellini" <sstabellini@kernel.org>
Subject: [PATCH] ns16550: find the console UART on PCI when there is no legacy one
Date: Tue, 22 Sep 2026 14:43:16 -0400 [thread overview]
Message-ID: <20260922184316.324817-1-benjamin@edera.io> (raw)
Amazon EC2 bare metal instances have no UART at the legacy I/O port
0x3f8. Their only serial port is a 16550-compatible PCI device (vendor
0x1d0f, device 0x8250) with its registers in the MMIO space of BAR 0.
Today Xen has no console on these systems unless the command line
names that device, and "com1=...,pci" cannot find it, because
uart_config[] doesn't have it.
Add the device to uart_config[].
Additionally, when the port that com1 describes is not present, scan PCI
for a known UART before giving up. This way the same command line works on
systems with and without a legacy UART, and a machine-specific "pci"
option is not needed. The fallback does not run when the command line
gave an I/O base, or when it already asked for a scan with "pci" or
"amt", so explicit config keeps its current meaning. It is
for com1 only: for com2, pci_uart_config() skips the first port it
finds, so it can never match a single-port device.
When the scan finds nothing, pci_uart_config() puts back the original
base, and check_existence() does not test MMIO addresses.
On a system with a legacy UART, check_existence() passes and nothing
changes.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Benjamin Leggett <benjamin@edera.io>
---
xen/drivers/char/ns16550.c | 47 +++++++++++++++++++++++++++++++++++++-
xen/include/xen/pci_ids.h | 2 ++
2 files changed, 48 insertions(+), 1 deletion(-)
diff --git a/xen/drivers/char/ns16550.c b/xen/drivers/char/ns16550.c
index 120ac09d23..d5403598d2 100644
--- a/xen/drivers/char/ns16550.c
+++ b/xen/drivers/char/ns16550.c
@@ -64,8 +64,10 @@ static struct ns16550 {
bool intr_works;
bool force_polling;
bool dw_usr_bsy;
+ bool io_base_set; /* if =1, io_base came from the command line */
#ifdef NS16550_PCI
/* PCI card parameters. */
+ bool pci_scanned; /* if =1, pci_uart_config() already ran */
bool pb_bdf_enable; /* if =1, pb-bdf effective, port behind bridge */
bool ps_bdf_enable; /* if =1, ps_bdf effective, port on pci card */
pci_sbdf_t pci_bridge;
@@ -98,6 +100,7 @@ struct ns16550_config {
param_intel_lpss,
param_wch_ch382,
param_asix,
+ param_amazon,
} param;
};
@@ -909,6 +912,13 @@ static const struct ns16550_config_param __initconst uart_param[] = {
.bar0 = true,
.max_ports = 1,
},
+ [param_amazon] = {
+ .reg_width = 1,
+ .lsr_mask = UART_LSR_THRE,
+ .bar0 = true,
+ .mmio = true,
+ .max_ports = 1,
+ },
};
static const struct ns16550_config __initconst uart_config[] =
@@ -1255,6 +1265,12 @@ static const struct ns16550_config __initconst uart_config[] =
.dev_id = 0x9910,
.param = param_asix
},
+ /* Amazon EC2 bare metal UART, the only serial port on those systems */
+ {
+ .vendor_id = PCI_VENDOR_ID_AMAZON,
+ .dev_id = 0x8250,
+ .param = param_amazon
+ },
};
static int __init
@@ -1263,6 +1279,8 @@ pci_uart_config(struct ns16550 *uart, bool skip_amt, unsigned int idx)
u64 orig_base = uart->io_base;
unsigned int b, d, f, nextf, i;
+ uart->pci_scanned = true;
+
/* NB. Start at bus 1 to avoid AMT: a plug-in card cannot be on bus 0. */
for ( b = skip_amt ? 1 : 0; b < 0x100; b++ )
{
@@ -1618,6 +1636,7 @@ static bool __init parse_positional(struct ns16550 *uart, char **str)
#endif
{
uart->io_base = simple_strtoull(conf, &conf, 0);
+ uart->io_base_set = true;
}
}
@@ -1693,6 +1712,7 @@ static bool __init parse_namevalue_pairs(char *str, struct ns16550 *uart)
break;
}
uart->io_base = simple_strtoull(param_value, NULL, 0);
+ uart->io_base_set = true;
break;
case irq:
@@ -1805,7 +1825,32 @@ static void __init ns16550_parse_port_config(
if ( uart->io_base == 0 )
PARSE_ERR("I/O base address must be specified.");
if ( !check_existence(uart) )
- PARSE_ERR("16550-compatible serial UART not present");
+ {
+ bool present = false;
+
+#ifdef NS16550_PCI
+ /*
+ * Some systems, EC2 bare metal among them, have no legacy UART and
+ * carry their only serial port on PCI. Look for one before giving up,
+ * unless the command line named a base or already asked for a scan.
+ * com1 only: for com2 the scan skips the first port it finds, so it
+ * can never match a single-port device.
+ */
+ if ( uart == ns16550_com && !uart->io_base_set && !uart->pci_scanned )
+ {
+ pci_uart_config(uart, 1 /* skip AMT */, uart - ns16550_com);
+ /*
+ * A scan that matched nothing puts back the base we just rejected,
+ * and check_existence() passes MMIO addresses through untested, so
+ * ps_bdf_enable is what says a device was found.
+ */
+ present = uart->ps_bdf_enable && check_existence(uart);
+ }
+#endif
+
+ if ( !present )
+ PARSE_ERR("16550-compatible serial UART not present");
+ }
/* Register with generic serial driver. */
serial_register_uart(uart - ns16550_com, &ns16550_driver, uart);
diff --git a/xen/include/xen/pci_ids.h b/xen/include/xen/pci_ids.h
index fd424ef55d..a17c88dcf7 100644
--- a/xen/include/xen/pci_ids.h
+++ b/xen/include/xen/pci_ids.h
@@ -17,6 +17,8 @@
#define PCI_VENDOR_ID_WCHIC 0x1c00
+#define PCI_VENDOR_ID_AMAZON 0x1d0f
+
#define PCI_VENDOR_ID_INTEL 0x8086
#endif /* XEN_PCI_IDS_H */
--
2.55.0
next reply other threads:[~2026-09-22 18:43 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-22 18:43 Benjamin Leggett [this message]
2026-09-23 6:11 ` [PATCH] ns16550: find the console UART on PCI when there is no legacy one Jan Beulich
2026-09-23 15:38 ` Benjamin Leggett
2026-09-23 15:39 ` [PATCH] ns16550: add the Amazon EC2 PCI serial device Benjamin Leggett
2026-09-24 8:26 ` Jan Beulich
2026-10-09 20:24 ` [PATCH] ns16550: add "auto" to scan PCI only when the default base has no UART Benjamin Leggett
2026-10-12 12:30 ` Jan Beulich
2026-10-13 20:49 ` Benjamin Leggett
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=20260922184316.324817-1-benjamin@edera.io \
--to=benjamin@edera.io \
--cc=andrew.cooper3@citrix.com \
--cc=anthony.perard@vates.tech \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=roger@xenproject.org \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.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.