From patchwork Thu Nov 9 10:19:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bhupinder Thakur X-Patchwork-Id: 10050749 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E8E23603FF for ; Thu, 9 Nov 2017 10:21:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB8D22AC20 for ; Thu, 9 Nov 2017 10:21:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D08F52AC28; Thu, 9 Nov 2017 10:21:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Flag: YES X-Spam-Level: ** X-Spam-Status: Yes, score=2.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_BL_SPAMCOP_NET, RCVD_IN_DNSWL_MED, RCVD_IN_SBL_CSS, RCVD_IN_SORBS_WEB, T_DKIM_INVALID autolearn=no version=3.3.1 X-Spam-Report: * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, * medium trust * [192.237.175.120 listed in list.dnswl.org] * 1.3 RCVD_IN_BL_SPAMCOP_NET RBL: Received via a relay in bl.spamcop.net * [Blocked - see ] * 3.3 RCVD_IN_SBL_CSS RBL: Received via a relay in Spamhaus SBL-CSS * [103.5.19.18 listed in zen.spamhaus.org] * 1.5 RCVD_IN_SORBS_WEB RBL: SORBS: sender is an abusable web server * [103.5.19.18 listed in dnsbl.sorbs.net] * -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] * 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily * valid * 0.0 T_DKIM_INVALID DKIM-Signature header exists but is not valid Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 63A042AC22 for ; Thu, 9 Nov 2017 10:21:55 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eCjvy-0007YB-6I; Thu, 09 Nov 2017 10:19:42 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eCjvw-0007Xk-M0 for xen-devel@lists.xenproject.org; Thu, 09 Nov 2017 10:19:40 +0000 Received: from [85.158.139.211] by server-5.bemta-5.messagelabs.com id 1E/AC-02209-BBB240A5; Thu, 09 Nov 2017 10:19:39 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrHIsWRWlGSWpSXmKPExsVyMfTAEd3d2ix RBvf3CVt83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBl3XkxiLThgVNFx5CBbA+Nx9S5GLg4hgRmM EvO2HmQCcVgE5jFLvH/SBeZICPSzSsz6/RvI4QRy8iT+bLvGCGGnSfzo28EMYZdLnP22BywuJ KAlcfTUbFaIsS1MEksv/2HrYuTgYBMwkZjVIQFSIyKgJHFv1WSwBcwCz5kkDk34CjZIWMBf4u zfnSwgNouAqsTmxefAFvMKeEtMPH+ZBWKZnMTNc51g9ZwCPhINBxcxgcwXAqp588F7AqPgAka GVYwaxalFZalFukYGeklFmekZJbmJmTm6hgamermpxcWJ6ak5iUnFesn5uZsYgSFXz8DAuIOx cbbfIUZJDiYlUd4Hr5iihPiS8lMqMxKLM+KLSnNSiw8xynBwKEnwCmuxRAkJFqWmp1akZeYAg x8mLcHBoyTCqwyS5i0uSMwtzkyHSJ1itOe4cOfSHyaOA3tuAclnM183MHNMu9raxCzEkpefly olzusE0iYA0pZRmgc3FBatlxhlpYR5GRkYGIR4ClKLcjNLUOVfMYpzMCoJ8zaCTOHJzCuB2/0 K6CwmoLOi2cHOKklESEk1MLY/cTFRTjDZXLFmiV7k/l/bZrvU3+5PTt/06t0p92WsRWd3f4s/ 3VKf5MvkYJy57t1WmTnvLhkfiKvgqmjL9utgsVyWt2Z5f2rva9np9WslbyrtDdzbXz9tka+ww pG61Ud6IpS2PRFOtDI8b+i0YHoxf6pE3pOPmYkT7+3iirli/8hs1nrlPiWW4oxEQy3mouJEAL YWtUvRAgAA X-Env-Sender: bhupinder.thakur@linaro.org X-Msg-Ref: server-9.tower-206.messagelabs.com!1510222778!106561799!1 X-Originating-IP: [209.85.192.196] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 52190 invoked from network); 9 Nov 2017 10:19:39 -0000 Received: from mail-pf0-f196.google.com (HELO mail-pf0-f196.google.com) (209.85.192.196) by server-9.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 9 Nov 2017 10:19:39 -0000 Received: by mail-pf0-f196.google.com with SMTP id d28so3947214pfe.2 for ; Thu, 09 Nov 2017 02:19:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4TddATP8edKi6c+3AR0UpJI3K3xszjTdYmYscwX/lyE=; b=YOrfbr6xFYGbYHv8G7Q+2SyGVdtURarHXWMDk1fwqI9G+YiwHgBD/VYekiEJ9Vvh/8 xvCLzyvCXgApnz/4LqOw3H7VamNIDM5FMPDGhCt9Hz2H64Z3PqStpFz7xON/mFVAcfpy 3tRV0jSZ9Jw/m4g3KwgSDGC0pXg/y+VdyfkRc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4TddATP8edKi6c+3AR0UpJI3K3xszjTdYmYscwX/lyE=; b=jhwAVIGa74fdBF02oYeI4/aPdRmxJYO5A/Zp2LxRq2M5bHvajAa7iKENDq9odvDbVT dgIw1K38ONJcjx+eew7ojbrOR7Wstwr97iGv7fhGsAZGuaSaI7fiS57xkYrlZ7Ukwbbr H2W1komRKTl6lWehnUsp+FnBlOLeRdHd95Jr7cn8WhzxBZ36jPjJv1kPIRU0LBlIAeN5 lWT4FP9vuzLJ+SuFWZ1vvcabOwv/lMXfTOUteSuqGyV+t63GHoFAu6eUO0W7fWCyRNPu ZeHh3qe/O4S1JG3pKRgT470EVrqV8AHUepfWNuclYLRunq9/nLuZh4YNOHtbC7UW0MDQ 6x+A== X-Gm-Message-State: AJaThX4IiKrZq8pLmrrvgb/HblzAEXiNKtEYzyXRA8i4mb02j+/80jVr +TFgIVGiXjXihMj1tDGBTex8DRvCaf0= X-Google-Smtp-Source: ABhQp+QzyS00vsQztrBjNJbR7rMiwQDABJB4X6WOEYNr40M6VJtDCeiukgqBJWUwWW5rB62i5Wi8rw== X-Received: by 10.98.147.23 with SMTP id b23mr3626946pfe.5.1510222777433; Thu, 09 Nov 2017 02:19:37 -0800 (PST) Received: from blr-ubuntu-linaro.wlan.qualcomm.com ([103.5.19.18]) by smtp.gmail.com with ESMTPSA id f12sm11467975pga.7.2017.11.09.02.19.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 09 Nov 2017 02:19:36 -0800 (PST) From: Bhupinder Thakur To: xen-devel@lists.xenproject.org Date: Thu, 9 Nov 2017 15:49:23 +0530 Message-Id: <1510222764-11746-2-git-send-email-bhupinder.thakur@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510222764-11746-1-git-send-email-bhupinder.thakur@linaro.org> References: <1510222764-11746-1-git-send-email-bhupinder.thakur@linaro.org> Cc: Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich Subject: [Xen-devel] [PATCH 1/2 v2] xen: Add support for initializing 16550 UART using ACPI X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Currently, Xen supports only DT based initialization of 16550 UART. This patch adds support for initializing 16550 UART using ACPI SPCR table. This patch also makes the uart initialization code common between DT and ACPI based initialization. Signed-off-by: Bhupinder Thakur --- TBD: There was one review comment from Julien about how the uart->io_size is being calculated. Currently, I am calulating the io_size based on address of the last UART register. pci_uart_config also calcualates the uart->io_size like this: uart->io_size = max(8U << param->reg_shift, param->uart_offset); I am not sure whether we can use similar logic for calculating uart->io_size. Changes since v1: - Reused common code between DT and ACPI based initializations CC: Andrew Cooper CC: George Dunlap CC: Ian Jackson CC: Jan Beulich CC: Konrad Rzeszutek Wilk CC: Stefano Stabellini CC: Tim Deegan CC: Wei Liu CC: Julien Grall xen/drivers/char/ns16550.c | 132 ++++++++++++++++++++++++++++++++++++++++---- xen/include/xen/8250-uart.h | 1 + 2 files changed, 121 insertions(+), 12 deletions(-) diff --git a/xen/drivers/char/ns16550.c b/xen/drivers/char/ns16550.c index e0f8199..cf42fce 100644 --- a/xen/drivers/char/ns16550.c +++ b/xen/drivers/char/ns16550.c @@ -1463,18 +1463,13 @@ void __init ns16550_init(int index, struct ns16550_defaults *defaults) } #ifdef CONFIG_HAS_DEVICE_TREE -static int __init ns16550_uart_dt_init(struct dt_device_node *dev, - const void *data) +static int ns16550_init_dt(struct ns16550 *uart, + const struct dt_device_node *dev) { - struct ns16550 *uart; - int res; + int res = 0; u32 reg_shift, reg_width; u64 io_size; - uart = &ns16550_com[0]; - - ns16550_init_common(uart); - uart->baud = BAUD_AUTO; uart->data_bits = 8; uart->parity = UART_PARITY_NONE; @@ -1510,18 +1505,103 @@ static int __init ns16550_uart_dt_init(struct dt_device_node *dev, uart->dw_usr_bsy = dt_device_is_compatible(dev, "snps,dw-apb-uart"); + return res; +} +#else +static int ns16550_init_dt(struct ns16550 *uart, + const struct dt_device_node *dev) +{ + return -EINVAL; +} +#endif + +#ifdef CONFIG_ACPI +#include +static int ns16550_init_acpi(struct ns16550 *uart, + const void *data) +{ + struct acpi_table_spcr *spcr = NULL; + int status = 0; + + status = acpi_get_table(ACPI_SIG_SPCR, 0, + (struct acpi_table_header **)&spcr); + + if ( ACPI_FAILURE(status) ) + { + printk("ns16550: Failed to get SPCR table\n"); + return -EINVAL; + } + + 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->irq = spcr->interrupt; + uart->reg_width = spcr->serial_port.bit_width / 8; + uart->reg_shift = 0; + uart->io_size = UART_MAX_REG << uart->reg_shift; + + irq_set_type(spcr->interrupt, spcr->interrupt_type); + + return 0; +} +#else +static int ns16550_init_acpi(struct ns16550 *uart, + const void *data) +{ + return -EINVAL; +} +#endif + +static int ns16550_uart_init(struct ns16550 **puart, + const void *data, bool acpi) +{ + struct ns16550 *uart = &ns16550_com[0]; + + *puart = uart; + + ns16550_init_common(uart); + + return ( acpi ) ? ns16550_init_acpi(uart, data) + : ns16550_init_dt(uart, data); +} + +static void ns16550_vuart_init(struct ns16550 *uart) +{ +#ifdef CONFIG_ARM uart->vuart.base_addr = uart->io_base; uart->vuart.size = uart->io_size; - uart->vuart.data_off = UART_THR <reg_shift; - uart->vuart.status_off = UART_LSR<reg_shift; - uart->vuart.status = UART_LSR_THRE|UART_LSR_TEMT; + 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; +#endif +} +static void ns16550_register_uart(struct ns16550 *uart) +{ /* Register with generic serial driver. */ serial_register_uart(uart - ns16550_com, &ns16550_driver, uart); +} + +#ifdef CONFIG_HAS_DEVICE_TREE +static int __init ns16550_uart_dt_init(struct dt_device_node *dev, + const void *data) +{ + struct ns16550 *uart; + int ret = 0; + + ret = ns16550_uart_init(&uart, dev, false); + if ( ret ) + return ret; + + ns16550_vuart_init(uart); + + ns16550_register_uart(uart); dt_device_set_used_by(dev, DOMID_XEN); - return 0; + return ret; } static const struct dt_device_match ns16550_dt_match[] __initconst = @@ -1538,6 +1618,34 @@ DT_DEVICE_START(ns16550, "NS16550 UART", DEVICE_SERIAL) DT_DEVICE_END #endif /* HAS_DEVICE_TREE */ + +#ifdef CONFIG_ACPI +static int __init ns16550_acpi_uart_init(const void *data) +{ + struct ns16550 *uart; + int ret = 0; + + ret = ns16550_uart_init(&uart, data, true); + if ( ret ) + return ret; + + ns16550_vuart_init(uart); + + ns16550_register_uart(uart); + + return ret; +} + +ACPI_DEVICE_START(ns16550c, "16550 COMPAT UART", DEVICE_SERIAL) + .class_type = ACPI_DBG2_16550_COMPATIBLE, + .init = ns16550_acpi_uart_init, +ACPI_DEVICE_END +ACPI_DEVICE_START(ns16550s, "16550 SUBSET UART", DEVICE_SERIAL) + .class_type = ACPI_DBG2_16550_SUBSET, + .init = ns16550_acpi_uart_init, +ACPI_DEVICE_END + +#endif /* * Local variables: * mode: C diff --git a/xen/include/xen/8250-uart.h b/xen/include/xen/8250-uart.h index 5c3bac3..1b3e137 100644 --- a/xen/include/xen/8250-uart.h +++ b/xen/include/xen/8250-uart.h @@ -35,6 +35,7 @@ #define UART_USR 0x1f /* Status register (DW) */ #define UART_DLL 0x00 /* divisor latch (ls) (DLAB=1) */ #define UART_DLM 0x01 /* divisor latch (ms) (DLAB=1) */ +#define UART_MAX_REG (UART_USR + 1) /* Interrupt Enable Register */ #define UART_IER_ERDAI 0x01 /* rx data recv'd */