[Xen-devel] [PATCH v4] ns16550: Add ACPI support for ARM only

Wei Xu posted 1 patch 4 years, 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/xen tags/patchew/5E4F3EF4.4050701@hisilicon.com
There is a newer version of this series
xen/drivers/char/ns16550.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 79 insertions(+)
[Xen-devel] [PATCH v4] ns16550: Add ACPI support for ARM only
Posted by Wei Xu 4 years, 1 month ago
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 <xuwei5@hisilicon.com>

---
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 <xen/acpi.h>
+
+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
-- 
2.8.1


.


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v4] ns16550: Add ACPI support for ARM only
Posted by Jan Beulich 4 years, 1 month ago
On 21.02.2020 03:22, Wei Xu wrote:
> --- 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 <xen/acpi.h>
> +
> +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;
> +    }

The space_id field qualifies the address one, i.e. whether a value of
zero can sensibly mean "disabled" depends on the address space. Hence
logically the address space check should come first.

This is the last thing I'd like to see changed. I won't give the
patch my ack though, as I think it should be an Arm maintainer to ack
it.

Jan

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v4] ns16550: Add ACPI support for ARM only
Posted by Julien Grall 4 years, 1 month ago

On 21/02/2020 14:02, Jan Beulich wrote:
> On 21.02.2020 03:22, Wei Xu wrote:
>> --- 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 <xen/acpi.h>
>> +
>> +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;
>> +    }
> 
> The space_id field qualifies the address one, i.e. whether a value of
> zero can sensibly mean "disabled" depends on the address space. Hence
> logically the address space check should come first.
> 
> This is the last thing I'd like to see changed. I won't give the
> patch my ack though, as I think it should be an Arm maintainer to ack
> it.

Acked-by: Julien Grall <julien@xen.org>

Although, a reviewed-by tag from you would be nice as you did most of 
the review for this patch.

Cheers,

-- 
Julien Grall

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v4] ns16550: Add ACPI support for ARM only
Posted by Jan Beulich 4 years, 1 month ago
On 21.02.2020 15:57, Julien Grall wrote:
> On 21/02/2020 14:02, Jan Beulich wrote:
>> On 21.02.2020 03:22, Wei Xu wrote:
>>> --- 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 <xen/acpi.h>
>>> +
>>> +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;
>>> +    }
>>
>> The space_id field qualifies the address one, i.e. whether a value of
>> zero can sensibly mean "disabled" depends on the address space. Hence
>> logically the address space check should come first.
>>
>> This is the last thing I'd like to see changed. I won't give the
>> patch my ack though, as I think it should be an Arm maintainer to ack
>> it.
> 
> Acked-by: Julien Grall <julien@xen.org>
> 
> Although, a reviewed-by tag from you would be nice as you did most of 
> the review for this patch.

Well, to clarify - this is one of the very few (afaict) cases where our
R-b implying A-b (when people are entitled to ack the respective code)
gets in the way. If this wasn't the case, I'd have given the former,
making it clear (also later from just looking at the resulting commit)
that the (only) ack came from an Arm person.

Jan

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v4] ns16550: Add ACPI support for ARM only
Posted by Wei Xu 4 years, 1 month ago
Hi Jan,

On 2020/2/21 23:07, Jan Beulich wrote:
> On 21.02.2020 15:57, Julien Grall wrote:
>> On 21/02/2020 14:02, Jan Beulich wrote:
>>> On 21.02.2020 03:22, Wei Xu wrote:
>>>> --- 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 <xen/acpi.h>
>>>> +
>>>> +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;
>>>> +    }
>>>
>>> The space_id field qualifies the address one, i.e. whether a value of
>>> zero can sensibly mean "disabled" depends on the address space. Hence
>>> logically the address space check should come first.
>>>
>>> This is the last thing I'd like to see changed. I won't give the
>>> patch my ack though, as I think it should be an Arm maintainer to ack
>>> it.
>>
>> Acked-by: Julien Grall <julien@xen.org>
>>
>> Although, a reviewed-by tag from you would be nice as you did most of 
>> the review for this patch.
> 
> Well, to clarify - this is one of the very few (afaict) cases where our
> R-b implying A-b (when people are entitled to ack the respective code)
> gets in the way. If this wasn't the case, I'd have given the former,
> making it clear (also later from just looking at the resulting commit)
> that the (only) ack came from an Arm person.

I will check the address space in the v5 and add your R-b.
Thanks!

Best Regards,
Wei

> 
> Jan
> 
> .
> 


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v4] ns16550: Add ACPI support for ARM only
Posted by Jan Beulich 4 years, 1 month ago
On 24.02.2020 02:06, Wei Xu wrote:
> On 2020/2/21 23:07, Jan Beulich wrote:
>> On 21.02.2020 15:57, Julien Grall wrote:
>>> On 21/02/2020 14:02, Jan Beulich wrote:
>>>> On 21.02.2020 03:22, Wei Xu wrote:
>>>>> --- 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 <xen/acpi.h>
>>>>> +
>>>>> +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;
>>>>> +    }
>>>>
>>>> The space_id field qualifies the address one, i.e. whether a value of
>>>> zero can sensibly mean "disabled" depends on the address space. Hence
>>>> logically the address space check should come first.
>>>>
>>>> This is the last thing I'd like to see changed. I won't give the
>>>> patch my ack though, as I think it should be an Arm maintainer to ack
>>>> it.
>>>
>>> Acked-by: Julien Grall <julien@xen.org>
>>>
>>> Although, a reviewed-by tag from you would be nice as you did most of 
>>> the review for this patch.
>>
>> Well, to clarify - this is one of the very few (afaict) cases where our
>> R-b implying A-b (when people are entitled to ack the respective code)
>> gets in the way. If this wasn't the case, I'd have given the former,
>> making it clear (also later from just looking at the resulting commit)
>> that the (only) ack came from an Arm person.
> 
> I will check the address space in the v5 and add your R-b.

I guess some misunderstanding has occurred? You're already checking the
address space in v4 (and I did already commit it this way on Friday).
And as indicated I intentionally elected to not provide my R-b for this
patch, for the reason given above.

Jan

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v4] ns16550: Add ACPI support for ARM only
Posted by Wei Xu 4 years, 1 month ago
Hi Jan,

On 2020/2/25 20:25, Jan Beulich wrote:
> On 24.02.2020 02:06, Wei Xu wrote:
>> On 2020/2/21 23:07, Jan Beulich wrote:
>>> On 21.02.2020 15:57, Julien Grall wrote:
>>>> On 21/02/2020 14:02, Jan Beulich wrote:
>>>>> On 21.02.2020 03:22, Wei Xu wrote:
>>>>>> --- 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 <xen/acpi.h>
>>>>>> +
>>>>>> +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;
>>>>>> +    }
>>>>>
>>>>> The space_id field qualifies the address one, i.e. whether a value of
>>>>> zero can sensibly mean "disabled" depends on the address space. Hence
>>>>> logically the address space check should come first.
>>>>>
>>>>> This is the last thing I'd like to see changed. I won't give the
>>>>> patch my ack though, as I think it should be an Arm maintainer to ack
>>>>> it.
>>>>
>>>> Acked-by: Julien Grall <julien@xen.org>
>>>>
>>>> Although, a reviewed-by tag from you would be nice as you did most of 
>>>> the review for this patch.
>>>
>>> Well, to clarify - this is one of the very few (afaict) cases where our
>>> R-b implying A-b (when people are entitled to ack the respective code)
>>> gets in the way. If this wasn't the case, I'd have given the former,
>>> making it clear (also later from just looking at the resulting commit)
>>> that the (only) ack came from an Arm person.
>>
>> I will check the address space in the v5 and add your R-b.
> 
> I guess some misunderstanding has occurred? You're already checking the
> address space in v4 (and I did already commit it this way on Friday).
> And as indicated I intentionally elected to not provide my R-b for this
> patch, for the reason given above.

Sorry, I misunderstood.
Thanks for clarifying!

Best Regards,
Wei

> 
> Jan
> 
> .
> 


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v4] ns16550: Add ACPI support for ARM only
Posted by Wei Xu 4 years, 1 month ago
Hi Julien,

On 2020/2/21 22:57, Julien Grall wrote:
> 
> 
> On 21/02/2020 14:02, Jan Beulich wrote:
>> On 21.02.2020 03:22, Wei Xu wrote:
>>> --- 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 <xen/acpi.h>
>>> +
>>> +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;
>>> +    }
>>
>> The space_id field qualifies the address one, i.e. whether a value of
>> zero can sensibly mean "disabled" depends on the address space. Hence
>> logically the address space check should come first.
>>
>> This is the last thing I'd like to see changed. I won't give the
>> patch my ack though, as I think it should be an Arm maintainer to ack
>> it.
> 
> Acked-by: Julien Grall <julien@xen.org>

Thanks!

Best Regards,
Wei

> 
> Although, a reviewed-by tag from you would be nice as you did most of the review for this patch.
> 
> Cheers,
> 


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel