From: Wei Xu <xuwei5@hisilicon.com>
To: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: Stefano Stabellini <sstabellini@kernel.org>,
Julien Grall <julien@xen.org>,
"Zengtao \(B\)" <prime.zeng@hisilicon.com>, Wei Liu <wl@xen.org>,
Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
George Dunlap <George.Dunlap@eu.citrix.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Ian Jackson <ian.jackson@eu.citrix.com>,
Linuxarm <linuxarm@huawei.com>,
xuwei5@hisilicon.com,
Shameerali Kolothum Thodi <shameerali.kolothum.thodi@huawei.com>
Subject: [Xen-devel] [PATCH v3] ns16550: Add ACPI support for ARM only
Date: Mon, 3 Feb 2020 19:21:31 +0800 [thread overview]
Message-ID: <5E38023B.8090306@hisilicon.com> (raw)
Parse the ACPI SPCR table and initialize the 16550 compatible serial port
for ARM only. Currently we only support one UART on ARM. Some fields
which we do not care yet on ARM are ignored.
Signed-off-by: Wei Xu <xuwei5@hisilicon.com>
---
Changes in v3:
- address the code style comments from Jan
- use container_of to do cast
- list all fields we ignored
- check the console redirection is disabled or not before init the uart
- init the uart io_size and width via spcr->serial_port
Changes in v2:
- improve commit message
- remove the spcr initialization
- add comments for the uart initialization and configuration
- adjust the code style issue
- limit the code only built on ACPI and ARM
---
xen/drivers/char/ns16550.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 75 insertions(+)
diff --git a/xen/drivers/char/ns16550.c b/xen/drivers/char/ns16550.c
index aa87c57..741b510 100644
--- a/xen/drivers/char/ns16550.c
+++ b/xen/drivers/char/ns16550.c
@@ -1620,6 +1620,81 @@ DT_DEVICE_START(ns16550, "NS16550 UART", DEVICE_SERIAL)
DT_DEVICE_END
#endif /* HAS_DEVICE_TREE */
+
+#if defined(CONFIG_ACPI) && defined(CONFIG_ARM)
+#include <xen/acpi.h>
+
+static int __init ns16550_acpi_uart_init(const void *data)
+{
+ struct acpi_table_header *table;
+ struct acpi_table_spcr *spcr;
+ acpi_status status;
+ /*
+ * Same as the DT part.
+ * Only support one UART on ARM which happen to be ns16550_com[0].
+ */
+ struct ns16550 *uart = &ns16550_com[0];
+
+ status = acpi_get_table(ACPI_SIG_SPCR, 0, &table);
+ if ( ACPI_FAILURE(status) )
+ {
+ printk("ns16550: Failed to get SPCR table\n");
+ return -EINVAL;
+ }
+
+ spcr = container_of(table, struct acpi_table_spcr, header);
+
+ /*
+ * The serial port address may be 0 for example
+ * if the console redirection is disabled.
+ */
+ if ( unlikely(!spcr->serial_port.address) )
+ {
+ printk("ns16550: the serial port address is invalid\n");
+ return -EINVAL;
+ }
+
+ ns16550_init_common(uart);
+
+ /*
+ * The baud rate is pre-configured by the firmware.
+ * And currently the ACPI part is only targeting ARM so the following
+ * fields pc_interrupt, pci_device_id, pci_vendor_id, pci_bus, pci_device,
+ * pci_function, pci_flags, pci_segment and flow_control which we do not
+ * care yet are ignored.
+ */
+ uart->baud = BAUD_AUTO;
+ uart->data_bits = 8;
+ uart->parity = spcr->parity;
+ uart->stop_bits = spcr->stop_bits;
+ uart->io_base = spcr->serial_port.address;
+ uart->io_size = spcr->serial_port.bit_width;
+ uart->reg_shift = spcr->serial_port.bit_offset;
+ uart->reg_width = spcr->serial_port.access_width;
+
+ /* The trigger/polarity information is not available in spcr. */
+ irq_set_type(spcr->interrupt, IRQ_TYPE_LEVEL_HIGH);
+ uart->irq = spcr->interrupt;
+
+ uart->vuart.base_addr = uart->io_base;
+ uart->vuart.size = uart->io_size;
+ uart->vuart.data_off = UART_THR << uart->reg_shift;
+ uart->vuart.status_off = UART_LSR << uart->reg_shift;
+ uart->vuart.status = UART_LSR_THRE | UART_LSR_TEMT;
+
+ /* Register with generic serial driver. */
+ serial_register_uart(SERHND_DTUART, &ns16550_driver, uart);
+
+ return 0;
+}
+
+ACPI_DEVICE_START(ans16550, "NS16550 UART", DEVICE_SERIAL)
+ .class_type = ACPI_DBG2_16550_COMPATIBLE,
+ .init = ns16550_acpi_uart_init,
+ACPI_DEVICE_END
+
+#endif /* CONFIG_ACPI && CONFIG_ARM */
+
/*
* Local variables:
* mode: C
--
2.8.1
.
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next reply other threads:[~2020-02-03 11:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-03 11:21 Wei Xu [this message]
2020-02-17 13:53 ` [Xen-devel] [PATCH v3] ns16550: Add ACPI support for ARM only Jan Beulich
2020-02-20 7:44 ` Wei Xu
2020-02-20 8:33 ` Jan Beulich
2020-02-20 9:59 ` Wei Xu
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=5E38023B.8090306@hisilicon.com \
--to=xuwei5@hisilicon.com \
--cc=George.Dunlap@eu.citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=julien@xen.org \
--cc=konrad.wilk@oracle.com \
--cc=linuxarm@huawei.com \
--cc=prime.zeng@hisilicon.com \
--cc=shameerali.kolothum.thodi@huawei.com \
--cc=sstabellini@kernel.org \
--cc=wl@xen.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.