From nobody Wed May 1 20:11:48 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1582507135; cv=none; d=zohomail.com; s=zohoarc; b=luOIZgYkjF1St6QKrTk9HkWBdpCmXKV5opff6RiqUNG4MBmGtTGOBEpfq79rtcGUP9lbMrQW3sFeJD9FSNsZZPT1DcqETwmdrFvlHe1AxTxYk2V+qisgBZ2+kog5S37Z5i8DgdIcyTrcYCeVT0vUdE06UsQMyVYBFzo9zJ73bt0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582507135; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=IpOoMtdam5O1mGWje5QXsaFKMyY+x0RUR4Z2SSpvWMc=; b=DHf92xA05KnnTPslHhkXOhCZD8TiuRPpjv0/eR26EXW29UMOJNgOBMytl+GCzQgsO6Pw2KqFNQYVoA3jU98HAS091p6ZQQar4FPk4s1AVpLg6PYwrmBEc4V1oeRugB/ZNtGGyDUwixzNKi5KaqD03uaOy59vn4o6h8mjU7Xt4Ts= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 158250713503419.109845432283123; Sun, 23 Feb 2020 17:18:55 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j62Nt-0003Jv-0U; Mon, 24 Feb 2020 01:18:09 +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 1j62Nr-0003Jq-RZ for xen-devel@lists.xenproject.org; Mon, 24 Feb 2020 01:18:07 +0000 Received: from huawei.com (unknown [45.249.212.191]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 813a801a-56a3-11ea-8a90-12813bfff9fa; Mon, 24 Feb 2020 01:18:04 +0000 (UTC) Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 7E92E6194054AA64F5F3; Mon, 24 Feb 2020 09:18:02 +0800 (CST) Received: from [127.0.0.1] (10.57.101.250) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.439.0; Mon, 24 Feb 2020 09:17:55 +0800 X-Inumbo-ID: 813a801a-56a3-11ea-8a90-12813bfff9fa To: "xen-devel@lists.xenproject.org" From: Wei Xu Message-ID: <5E532442.1040401@hisilicon.com> Date: Mon, 24 Feb 2020 09:17:54 +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 v5] 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 Reviewed-by: Jan Beulich Acked-by: Julien Grall --- Changes in v5: - check the serial port address space before checking the address 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..425e044 100644 --- a/xen/drivers/char/ns16550.c +++ b/xen/drivers/char/ns16550.c @@ -1620,6 +1620,85 @@ DT_DEVICE_START(ns16550, "NS16550 UART", DEVICE_SERI= AL) 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 =3D &ns16550_com[0]; + + status =3D acpi_get_table(ACPI_SIG_SPCR, 0, &table); + if ( ACPI_FAILURE(status) ) + { + printk("ns16550: Failed to get SPCR table\n"); + return -EINVAL; + } + + spcr =3D container_of(table, struct acpi_table_spcr, header); + + if ( unlikely(spcr->serial_port.space_id !=3D ACPI_ADR_SPACE_SYSTEM_ME= MORY) ) + { + printk("ns16550: Address space type is not mmio\n"); + return -EINVAL; + } + + /* + * 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; + } + + 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_contr= ol + * field and all PCI related ones which we do not care yet are ignored. + */ + uart->baud =3D BAUD_AUTO; + uart->data_bits =3D 8; + uart->parity =3D spcr->parity; + uart->stop_bits =3D spcr->stop_bits; + uart->io_base =3D spcr->serial_port.address; + uart->io_size =3D spcr->serial_port.bit_width; + uart->reg_shift =3D spcr->serial_port.bit_offset; + uart->reg_width =3D 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 =3D spcr->interrupt; + + uart->vuart.base_addr =3D uart->io_base; + uart->vuart.size =3D uart->io_size; + uart->vuart.data_off =3D UART_THR << uart->reg_shift; + uart->vuart.status_off =3D UART_LSR << uart->reg_shift; + uart->vuart.status =3D 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 =3D ACPI_DBG2_16550_COMPATIBLE, + .init =3D ns16550_acpi_uart_init, +ACPI_DEVICE_END + +#endif /* CONFIG_ACPI && CONFIG_ARM */ + /* * Local variables: * mode: C --=20 2.8.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel