From patchwork Fri Feb 21 02:22:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Xu X-Patchwork-Id: 183671 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp1289997ile; Thu, 20 Feb 2020 18:24:41 -0800 (PST) X-Google-Smtp-Source: APXvYqw67Wr50wd5yjL+XqQtM6DjUFKxFnRM/y6HQacllx0mI1oK/o5FrPZsE++MrrxVOhyqY9gt X-Received: by 2002:a92:d5cf:: with SMTP id d15mr31790106ilq.306.1582251881315; Thu, 20 Feb 2020 18:24:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582251881; cv=none; d=google.com; s=arc-20160816; b=InlIJZE+a4W4NfkyFQgJTFggpEs/lUkiThNzHsNyS4v+QUuykOaqvSVZghIaN2XTAV BssoDAi4hmwS3WW8vnJF67qenS8wvZmiZum5fgttTWEo/9iR+M22mSiJOCFjQTaN4+r1 b60jtFyHcMoEpKVNnCxD/HZBPE7FUPKYe52nY/C9yj2vrvJpC1l/sbEjJ2B52hXsGQNs 8VN9A+dfmSbIqVvF7JML+j9SIdNcBNx17Y+gmYiGsYLZNhM+tcInu6Y6qsF/DX/cShB3 sERVaTNqHThkDm9vIU28hRD7/pbw1I38CSoWUIB76gcISdEgBE9GmgCMH3jbG+gtGUTk RFAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-unsubscribe:list-id:precedence:subject :mime-version:user-agent:date:message-id:from:to; bh=3madhk35Bg6g1G6FpBZ+xA3vVAz7GYp0VCa9KWidxvY=; b=uubERZDYwOapnn0LRXbwUT3tbzCkDmvKkaL0S0ZWKgRy/X2vkt/GRtdgLX4QAAoRSH LGLxNtQ69TVVXVZ1XyLoAPCbuUqg/TePYmtxisOl5QDAUYB9C7/XGJz2OYVHYx6cS6Cp FQYbZRWNFgMhLPigMwemKgX2YE/0eYYgaSRqXCCZBPlfyy9D+kdbz2zOEsg0FQnme/un 5WynJz+X2PmfMP8B2mdxsqEUm8LnIh6f/xINH3Bx3Q1nOH9aloFfwR+lCYWtN1RC+8um 9gRorbBJadSCvedeUB6MW01nLpWQB/jhH8TNjzZ5rzWBtx4ppAC64z4QhC1kJC4apkNG UyxQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id w11si820440ilo.48.2020.02.20.18.24.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Feb 2020 18:24:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j4xy1-0002Sc-Ur; Fri, 21 Feb 2020 02:23:01 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j4xy1-0002SW-1F for xen-devel@lists.xenproject.org; Fri, 21 Feb 2020 02:23:01 +0000 X-Inumbo-ID: 10f3c20c-5451-11ea-aa99-bc764e2007e4 Received: from huawei.com (unknown [45.249.212.35]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 10f3c20c-5451-11ea-aa99-bc764e2007e4; Fri, 21 Feb 2020 02:22:56 +0000 (UTC) Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 1F52AEF3A4E48F9BA922; Fri, 21 Feb 2020 10:22:53 +0800 (CST) Received: from [127.0.0.1] (10.57.101.250) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.439.0; Fri, 21 Feb 2020 10:22:45 +0800 To: "xen-devel@lists.xenproject.org" From: Wei Xu Message-ID: <5E4F3EF4.4050701@hisilicon.com> Date: Fri, 21 Feb 2020 10:22:44 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 X-Originating-IP: [10.57.101.250] X-CFilter-Loop: Reflected Subject: [Xen-devel] [PATCH v4] ns16550: Add ACPI support for ARM only X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Julien Grall , "Zengtao \(B\)" , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Linuxarm , xuwei5@hisilicon.com, Shameerali Kolothum Thodi , Jan Beulich Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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 Acked-by: Julien Grall --- Changes in v4: - change the print when the serial port address is 0 - check the serial port address space id before initializing - change the comment for the ignored PCIe fields 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 | 79 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/xen/drivers/char/ns16550.c b/xen/drivers/char/ns16550.c index aa87c57..dc8ac4c 100644 --- a/xen/drivers/char/ns16550.c +++ b/xen/drivers/char/ns16550.c @@ -1620,6 +1620,85 @@ DT_DEVICE_START(ns16550, "NS16550 UART", DEVICE_SERIAL) DT_DEVICE_END #endif /* HAS_DEVICE_TREE */ + +#if defined(CONFIG_ACPI) && defined(CONFIG_ARM) +#include + +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: Console redirection is disabled\n"); + return -EINVAL; + } + + if ( unlikely(spcr->serial_port.space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY) ) + { + printk("ns16550: Address space type is not mmio\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 flow_control + * field and all PCI related ones 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