From patchwork Mon Feb 3 11:21:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Xu X-Patchwork-Id: 183043 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp3865100ile; Mon, 3 Feb 2020 03:23:02 -0800 (PST) X-Google-Smtp-Source: APXvYqw8tSXl80sTSeXnWr6zOF5bNKZ89d1EmD+c1TkF3sj6bLBBSfwrnxBDS9FhZExGYy1tNE06 X-Received: by 2002:a6b:b4c4:: with SMTP id d187mr19067674iof.82.1580728982663; Mon, 03 Feb 2020 03:23:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580728982; cv=none; d=google.com; s=arc-20160816; b=O4/wnU+W1AEhHQ9cvH2SBucWfP4wnvq0ANXEd2X7zziCiaelXlvb53odmxXL0dnLlN Sep48q2glTuEmLgkZXBpoL99USgWGTExFleC7qK7uK/cjWARUmzRhI/PlP879ICjS6VI FpJ8tSaecfQ2VYYNaRuVnjQRaN+3SfycC0MYFAHxFgwTeEuKrz+IPHI96u7GYw2xX24Q scWKjFXa6ramhCyy7Cg/EaiqrI2tJHoqiLAVthx3o7XLb4Q7O5hbGMqwiWCiBYEOBxot OXfzNcmVMZK3TxVYM7GLrL+xrKRudRw+S393uL6Mz7God1kPQO1ceR+WFJEuyMkn2TB4 zG/w== 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:to:from; bh=nQ8/RTjB1iQPpKOM0oYgHCKqjj1CdhCUg7w/8bGxrc0=; b=rZ1BNXZDTd812JMzC2HYzqd8wm6jncsA5Dit246k+7EtWZYh92vhNk3/RVf+V79QSK BiKklW75KRklAxos8aCNaOP4U2JqQ1PTKRCeziqXktLbS/fVJg/DcmacUcUR6SB6aapH F1k2m81Q9OfNgcyClC189nqohI49k9OH7cHKTRsX48ps2TMd1ksyCsh46/mB8YhzRqeK wkMsbqDCfhOGwTmPMxxKEHZUMz9IyEqh9S3jxWwI8dqf4ZcwwqzzG35hgL5tx2rYk4Fi 8QTVjLRmD0/9S53LhNoyOUq0THwzRLV4Ecx1QxvEf34WtxIKjYXakovTSIY+FdxWlOQ8 rmBg== 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 k3si8936997iop.158.2020.02.03.03.23.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Feb 2020 03:23:02 -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 1iyZnW-0002Dv-Bp; Mon, 03 Feb 2020 11:21:46 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iyZnU-0002Dq-Os for xen-devel@lists.xenproject.org; Mon, 03 Feb 2020 11:21:44 +0000 X-Inumbo-ID: 5941a386-4677-11ea-8e4d-12813bfff9fa Received: from huawei.com (unknown [45.249.212.190]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5941a386-4677-11ea-8e4d-12813bfff9fa; Mon, 03 Feb 2020 11:21:41 +0000 (UTC) Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 18341B9F2C0E3571267B; Mon, 3 Feb 2020 19:21:39 +0800 (CST) Received: from [127.0.0.1] (10.57.101.250) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.439.0; Mon, 3 Feb 2020 19:21:32 +0800 From: Wei Xu To: "xen-devel@lists.xenproject.org" Message-ID: <5E38023B.8090306@hisilicon.com> Date: Mon, 3 Feb 2020 19:21:31 +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 v3] 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 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 --- 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 + +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