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: 118422 Delivered-To: patch@linaro.org Received: by 10.80.225.132 with SMTP id k4csp741347edl; Thu, 9 Nov 2017 02:21:31 -0800 (PST) X-Google-Smtp-Source: ABhQp+RkID+4m2cYd3sUsSTNoOm9cma1sOOxACislSrjs9wt6uDTBduGOggOuJ6WfzFgD1wXkMEs X-Received: by 10.36.44.76 with SMTP id i73mr4857582iti.41.1510222891120; Thu, 09 Nov 2017 02:21:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510222891; cv=none; d=google.com; s=arc-20160816; b=U3TP4r5MLujJttCYASIH6SYEBabHhQr7/UR2y4Uiyg7OZkIobixYi2aTQzxihCEqPH 6YMyRSGE89U+Pjqqlxwh2oyLcitO3lPr+zqwrur0JLY9FVVuB/jHJly9JT9W3Tz2wGMI Pw0G51tK6Ykom6tyWdyAtSImhAbfZRLpjDyk70eL4b2KRhKsqq7XLrZrcSxfXE2WMLHJ i7CG755zIME2HzncMSUhNuzVtRcfK23QVWxWKaUkBjhe0DtYy1io7JjDNe0dxAp7+WMH rx90nhkJf13RCbeeZyz057Hq29O6Hf9aST557GkWADVIbcYdLQkF7Nag6lBTwJuxMPQw 1hmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:cc:references:in-reply-to:message-id:date:to :from:dkim-signature:arc-authentication-results; bh=vGHOzUgYTaU9zRqQ/i7btoO2w1rObnZDrULNdF612/k=; b=Oz6czR8mv+5Tdxb0+nPPjTO5R+lmEcwwsZ4DmLnQGEVT3Cj36S6w9w3kpVywyGgW5h 3xf/7j7LnFDzMwcDPoYq2xvlREh9Yc3HhVoyRzHIAcELoW1vbTDHJ7/VLXgOqMq4awtu mrA4p3o0+572Fu/BSkwtAT63rSNCTqv61dlSHo2lMQkypuc/6WjMYgFwXWeX1REz6aFS 5gBmn7mAI4VDyHuvVIHppnLDXmjWstQb0gf4Se4BVupDOwqVGo7PZgObOym32oeFxQey zzeZax3yFK7gMn/hDcJ2WML/stTNNwGKh+MZmYKF1Ic/ogCw9RJV5yjZAWXXiaNnVSLk zYKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=YOrfbr6x; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id 72si5626567ioz.337.2017.11.09.02.21.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Nov 2017 02:21:31 -0800 (PST) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=YOrfbr6x; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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-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" 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 */