diff mbox

[RFC,18/29] xen/arm: add generic UART to get the device in the device tree

Message ID b6b9bae716f1a337192d13ba985dedde97225456.1367188423.git.julien.grall@linaro.org
State Changes Requested, archived
Headers show

Commit Message

Julien Grall April 28, 2013, 11:02 p.m. UTC
This generic UART will find the right UART via xen command line
with com1=myserial.

"myserial" is the alias of the UART in the device tree. Xen will retrieve
the information via the device tree and call the initialization function for
this specific UART thanks to the device API.

Signed-off-by: Julien Grall <julien.grall@linaro.org>
---
 xen/arch/arm/setup.c        |    3 +-
 xen/drivers/char/Makefile   |    1 +
 xen/drivers/char/arm-uart.c |   76 +++++++++++++++++++++++++++++++++++++++++++
 xen/include/xen/serial.h    |    8 +++++
 4 files changed, 87 insertions(+), 1 deletion(-)
 create mode 100644 xen/drivers/char/arm-uart.c

Comments

Ian Campbell April 29, 2013, 3:51 p.m. UTC | #1
On Mon, 2013-04-29 at 00:02 +0100, Julien Grall wrote:
> This generic UART will find the right UART via xen command line
> with com1=myserial.
> 
> "myserial" is the alias of the UART in the device tree. Xen will retrieve
> the information via the device tree and call the initialization function for
> this specific UART thanks to the device API.
> 
> Signed-off-by: Julien Grall <julien.grall@linaro.org>
> ---
>  xen/arch/arm/setup.c        |    3 +-
>  xen/drivers/char/Makefile   |    1 +
>  xen/drivers/char/arm-uart.c |   76 +++++++++++++++++++++++++++++++++++++++++++
>  xen/include/xen/serial.h    |    8 +++++
>  4 files changed, 87 insertions(+), 1 deletion(-)
>  create mode 100644 xen/drivers/char/arm-uart.c
> 
> diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
> index 51f4bba..e5d8724 100644
> --- a/xen/arch/arm/setup.c
> +++ b/xen/arch/arm/setup.c
> @@ -434,8 +434,9 @@ void __init start_xen(unsigned long boot_phys_offset,
>  #ifdef EARLY_UART_ADDRESS
>      /* TODO Need to get device tree or command line for UART address */
>      pl011_init(0, FIXMAP_ADDR(FIXMAP_CONSOLE));
> -    console_init_preirq();
>  #endif
> +    arm_uart_init();
> +    console_init_preirq();
>  
>      /* FIXME: Do something smarter */
>      dt_switch_to_printk();
> diff --git a/xen/drivers/char/Makefile b/xen/drivers/char/Makefile
> index ab2246d..e68a54a 100644
> --- a/xen/drivers/char/Makefile
> +++ b/xen/drivers/char/Makefile
> @@ -2,4 +2,5 @@ obj-y += console.o
>  obj-$(HAS_NS16550) += ns16550.o
>  obj-$(HAS_PL011) += pl011.o
>  obj-$(HAS_EHCI) += ehci-dbgp.o
> +obj-$(CONFIG_ARM) += arm-uart.o
>  obj-y += serial.o
> diff --git a/xen/drivers/char/arm-uart.c b/xen/drivers/char/arm-uart.c
> new file mode 100644
> index 0000000..e242ae2
> --- /dev/null
> +++ b/xen/drivers/char/arm-uart.c
> @@ -0,0 +1,76 @@
> +/*
> + * xen/drivers/char/arm-uart.c
> + *
> + * Generic ARM uart retrieved via the device tree
> + *
> + * Julien Grall <julien.grall@linaro.org>
> + * Copyright (c) 2013 Linaro Limited.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + */
> +
> +#include <asm/device.h>
> +#include <asm/early_printk.h>
> +#include <asm/types.h>
> +#include <xen/console.h>
> +#include <xen/device_tree.h>
> +#include <xen/mm.h>
> +#include <xen/serial.h>
> +
> +/*
> + * Configure serial port with string: devname
> + * Where devname is the alias of the device in the device tree
> + */
> +static char __initdata opt_com1[30] = "";
> +string_param("com1", opt_com1);

com1 is a bit of an x86-ism. Can we use e.g. uart0 or does common code
constrain us here?

Better would be to arrange things such that console=myserial does the
lookup. Then myserial=<foo> sets options for that device.

I think you would need to add a call to dt_console_init to
console_init_preirq(), in the "Where should console output go?" loop.

Ian.
Julien Grall April 29, 2013, 5:24 p.m. UTC | #2
On 04/29/2013 04:51 PM, Ian Campbell wrote:

> On Mon, 2013-04-29 at 00:02 +0100, Julien Grall wrote:
>> This generic UART will find the right UART via xen command line
>> with com1=myserial.
>>
>> "myserial" is the alias of the UART in the device tree. Xen will retrieve
>> the information via the device tree and call the initialization function for
>> this specific UART thanks to the device API.
>>
>> Signed-off-by: Julien Grall <julien.grall@linaro.org>
>> ---
>>  xen/arch/arm/setup.c        |    3 +-
>>  xen/drivers/char/Makefile   |    1 +
>>  xen/drivers/char/arm-uart.c |   76 +++++++++++++++++++++++++++++++++++++++++++
>>  xen/include/xen/serial.h    |    8 +++++
>>  4 files changed, 87 insertions(+), 1 deletion(-)
>>  create mode 100644 xen/drivers/char/arm-uart.c
>>
>> diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
>> index 51f4bba..e5d8724 100644
>> --- a/xen/arch/arm/setup.c
>> +++ b/xen/arch/arm/setup.c
>> @@ -434,8 +434,9 @@ void __init start_xen(unsigned long boot_phys_offset,
>>  #ifdef EARLY_UART_ADDRESS
>>      /* TODO Need to get device tree or command line for UART address */
>>      pl011_init(0, FIXMAP_ADDR(FIXMAP_CONSOLE));
>> -    console_init_preirq();
>>  #endif
>> +    arm_uart_init();
>> +    console_init_preirq();
>>  
>>      /* FIXME: Do something smarter */
>>      dt_switch_to_printk();
>> diff --git a/xen/drivers/char/Makefile b/xen/drivers/char/Makefile
>> index ab2246d..e68a54a 100644
>> --- a/xen/drivers/char/Makefile
>> +++ b/xen/drivers/char/Makefile
>> @@ -2,4 +2,5 @@ obj-y += console.o
>>  obj-$(HAS_NS16550) += ns16550.o
>>  obj-$(HAS_PL011) += pl011.o
>>  obj-$(HAS_EHCI) += ehci-dbgp.o
>> +obj-$(CONFIG_ARM) += arm-uart.o
>>  obj-y += serial.o
>> diff --git a/xen/drivers/char/arm-uart.c b/xen/drivers/char/arm-uart.c
>> new file mode 100644
>> index 0000000..e242ae2
>> --- /dev/null
>> +++ b/xen/drivers/char/arm-uart.c
>> @@ -0,0 +1,76 @@
>> +/*
>> + * xen/drivers/char/arm-uart.c
>> + *
>> + * Generic ARM uart retrieved via the device tree
>> + *
>> + * Julien Grall <julien.grall@linaro.org>
>> + * Copyright (c) 2013 Linaro Limited.
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License as published by
>> + * the Free Software Foundation; either version 2 of the License, or
>> + * (at your option) any later version.
>> + *
>> + * This program is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>> + * GNU General Public License for more details.
>> + */
>> +
>> +#include <asm/device.h>
>> +#include <asm/early_printk.h>
>> +#include <asm/types.h>
>> +#include <xen/console.h>
>> +#include <xen/device_tree.h>
>> +#include <xen/mm.h>
>> +#include <xen/serial.h>
>> +
>> +/*
>> + * Configure serial port with string: devname
>> + * Where devname is the alias of the device in the device tree
>> + */
>> +static char __initdata opt_com1[30] = "";
>> +string_param("com1", opt_com1);
> 
> com1 is a bit of an x86-ism. Can we use e.g. uart0 or does common code
> constrain us here?

>

> Better would be to arrange things such that console=myserial does the
> lookup. Then myserial=<foo> sets options for that device.
> 
> I think you would need to add a call to dt_console_init to
> console_init_preirq(), in the "Where should console output go?" loop.


I don't see an easy solution with dt_console_init.
serial_parse_handle hardcodes the name of the serial, which only
supports com1, com2, dbgp. Sadly, the serial initialization is made in
the same function.

If I understand your suggestion, you suggest to use console=myserial
where *myserial* is the alias on the DTB, right? In this case the name
could clash with the hardcoded ones in Xen that is not good.
Ian Campbell April 30, 2013, 9:09 a.m. UTC | #3
On Mon, 2013-04-29 at 18:24 +0100, Julien Grall wrote:
> On 04/29/2013 04:51 PM, Ian Campbell wrote:
> 
> > On Mon, 2013-04-29 at 00:02 +0100, Julien Grall wrote:
> >> This generic UART will find the right UART via xen command line
> >> with com1=myserial.
> >>
> >> "myserial" is the alias of the UART in the device tree. Xen will retrieve
> >> the information via the device tree and call the initialization function for
> >> this specific UART thanks to the device API.
> >>
> >> Signed-off-by: Julien Grall <julien.grall@linaro.org>
> >> ---
> >>  xen/arch/arm/setup.c        |    3 +-
> >>  xen/drivers/char/Makefile   |    1 +
> >>  xen/drivers/char/arm-uart.c |   76 +++++++++++++++++++++++++++++++++++++++++++
> >>  xen/include/xen/serial.h    |    8 +++++
> >>  4 files changed, 87 insertions(+), 1 deletion(-)
> >>  create mode 100644 xen/drivers/char/arm-uart.c
> >>
> >> diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
> >> index 51f4bba..e5d8724 100644
> >> --- a/xen/arch/arm/setup.c
> >> +++ b/xen/arch/arm/setup.c
> >> @@ -434,8 +434,9 @@ void __init start_xen(unsigned long boot_phys_offset,
> >>  #ifdef EARLY_UART_ADDRESS
> >>      /* TODO Need to get device tree or command line for UART address */
> >>      pl011_init(0, FIXMAP_ADDR(FIXMAP_CONSOLE));
> >> -    console_init_preirq();
> >>  #endif
> >> +    arm_uart_init();
> >> +    console_init_preirq();
> >>  
> >>      /* FIXME: Do something smarter */
> >>      dt_switch_to_printk();
> >> diff --git a/xen/drivers/char/Makefile b/xen/drivers/char/Makefile
> >> index ab2246d..e68a54a 100644
> >> --- a/xen/drivers/char/Makefile
> >> +++ b/xen/drivers/char/Makefile
> >> @@ -2,4 +2,5 @@ obj-y += console.o
> >>  obj-$(HAS_NS16550) += ns16550.o
> >>  obj-$(HAS_PL011) += pl011.o
> >>  obj-$(HAS_EHCI) += ehci-dbgp.o
> >> +obj-$(CONFIG_ARM) += arm-uart.o
> >>  obj-y += serial.o
> >> diff --git a/xen/drivers/char/arm-uart.c b/xen/drivers/char/arm-uart.c
> >> new file mode 100644
> >> index 0000000..e242ae2
> >> --- /dev/null
> >> +++ b/xen/drivers/char/arm-uart.c
> >> @@ -0,0 +1,76 @@
> >> +/*
> >> + * xen/drivers/char/arm-uart.c
> >> + *
> >> + * Generic ARM uart retrieved via the device tree
> >> + *
> >> + * Julien Grall <julien.grall@linaro.org>
> >> + * Copyright (c) 2013 Linaro Limited.
> >> + *
> >> + * This program is free software; you can redistribute it and/or modify
> >> + * it under the terms of the GNU General Public License as published by
> >> + * the Free Software Foundation; either version 2 of the License, or
> >> + * (at your option) any later version.
> >> + *
> >> + * This program is distributed in the hope that it will be useful,
> >> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> >> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> >> + * GNU General Public License for more details.
> >> + */
> >> +
> >> +#include <asm/device.h>
> >> +#include <asm/early_printk.h>
> >> +#include <asm/types.h>
> >> +#include <xen/console.h>
> >> +#include <xen/device_tree.h>
> >> +#include <xen/mm.h>
> >> +#include <xen/serial.h>
> >> +
> >> +/*
> >> + * Configure serial port with string: devname
> >> + * Where devname is the alias of the device in the device tree
> >> + */
> >> +static char __initdata opt_com1[30] = "";
> >> +string_param("com1", opt_com1);
> > 
> > com1 is a bit of an x86-ism. Can we use e.g. uart0 or does common code
> > constrain us here?
> 
> >
> 
> > Better would be to arrange things such that console=myserial does the
> > lookup. Then myserial=<foo> sets options for that device.
> > 
> > I think you would need to add a call to dt_console_init to
> > console_init_preirq(), in the "Where should console output go?" loop.
> 
> 
> I don't see an easy solution with dt_console_init.
> serial_parse_handle hardcodes the name of the serial, which only
> supports com1, com2, dbgp. Sadly, the serial initialization is made in
> the same function.

Couldn't it also hardcode a call to a "is this a dt serial alias"
function?

> If I understand your suggestion, you suggest to use console=myserial
> where *myserial* is the alias on the DTB, right?

Right.

> In this case the name could clash with the hardcoded ones in Xen that is not good.

console=dt:<alias> ? Or to be honest I'm not sure that having the dt
aliases shadow the Xen hardcoded ones would be a bad thing -- the x86
centric com<X> definition hardcoded in Xen is hardly likely to be useful
on ARM or any DT using platform.

Ian.
Julien Grall April 30, 2013, 11:05 a.m. UTC | #4
On 30 April 2013 10:09, Ian Campbell <Ian.Campbell@citrix.com> wrote:

> On Mon, 2013-04-29 at 18:24 +0100, Julien Grall wrote:
> > On 04/29/2013 04:51 PM, Ian Campbell wrote:
> >
> > > On Mon, 2013-04-29 at 00:02 +0100, Julien Grall wrote:
> > >> This generic UART will find the right UART via xen command line
> > >> with com1=myserial.
> > >>
> > >> "myserial" is the alias of the UART in the device tree. Xen will
> retrieve
> > >> the information via the device tree and call the initialization
> function for
> > >> this specific UART thanks to the device API.
> > >>
> > >> Signed-off-by: Julien Grall <julien.grall@linaro.org>
> > >> ---
> > >>  xen/arch/arm/setup.c        |    3 +-
> > >>  xen/drivers/char/Makefile   |    1 +
> > >>  xen/drivers/char/arm-uart.c |   76
> +++++++++++++++++++++++++++++++++++++++++++
> > >>  xen/include/xen/serial.h    |    8 +++++
> > >>  4 files changed, 87 insertions(+), 1 deletion(-)
> > >>  create mode 100644 xen/drivers/char/arm-uart.c
> > >>
> > >> diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
> > >> index 51f4bba..e5d8724 100644
> > >> --- a/xen/arch/arm/setup.c
> > >> +++ b/xen/arch/arm/setup.c
> > >> @@ -434,8 +434,9 @@ void __init start_xen(unsigned long
> boot_phys_offset,
> > >>  #ifdef EARLY_UART_ADDRESS
> > >>      /* TODO Need to get device tree or command line for UART address
> */
> > >>      pl011_init(0, FIXMAP_ADDR(FIXMAP_CONSOLE));
> > >> -    console_init_preirq();
> > >>  #endif
> > >> +    arm_uart_init();
> > >> +    console_init_preirq();
> > >>
> > >>      /* FIXME: Do something smarter */
> > >>      dt_switch_to_printk();
> > >> diff --git a/xen/drivers/char/Makefile b/xen/drivers/char/Makefile
> > >> index ab2246d..e68a54a 100644
> > >> --- a/xen/drivers/char/Makefile
> > >> +++ b/xen/drivers/char/Makefile
> > >> @@ -2,4 +2,5 @@ obj-y += console.o
> > >>  obj-$(HAS_NS16550) += ns16550.o
> > >>  obj-$(HAS_PL011) += pl011.o
> > >>  obj-$(HAS_EHCI) += ehci-dbgp.o
> > >> +obj-$(CONFIG_ARM) += arm-uart.o
> > >>  obj-y += serial.o
> > >> diff --git a/xen/drivers/char/arm-uart.c b/xen/drivers/char/arm-uart.c
> > >> new file mode 100644
> > >> index 0000000..e242ae2
> > >> --- /dev/null
> > >> +++ b/xen/drivers/char/arm-uart.c
> > >> @@ -0,0 +1,76 @@
> > >> +/*
> > >> + * xen/drivers/char/arm-uart.c
> > >> + *
> > >> + * Generic ARM uart retrieved via the device tree
> > >> + *
> > >> + * Julien Grall <julien.grall@linaro.org>
> > >> + * Copyright (c) 2013 Linaro Limited.
> > >> + *
> > >> + * This program is free software; you can redistribute it and/or
> modify
> > >> + * it under the terms of the GNU General Public License as published
> by
> > >> + * the Free Software Foundation; either version 2 of the License, or
> > >> + * (at your option) any later version.
> > >> + *
> > >> + * This program is distributed in the hope that it will be useful,
> > >> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > >> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > >> + * GNU General Public License for more details.
> > >> + */
> > >> +
> > >> +#include <asm/device.h>
> > >> +#include <asm/early_printk.h>
> > >> +#include <asm/types.h>
> > >> +#include <xen/console.h>
> > >> +#include <xen/device_tree.h>
> > >> +#include <xen/mm.h>
> > >> +#include <xen/serial.h>
> > >> +
> > >> +/*
> > >> + * Configure serial port with string: devname
> > >> + * Where devname is the alias of the device in the device tree
> > >> + */
> > >> +static char __initdata opt_com1[30] = "";
> > >> +string_param("com1", opt_com1);
> > >
> > > com1 is a bit of an x86-ism. Can we use e.g. uart0 or does common code
> > > constrain us here?
> >
> > >
> >
> > > Better would be to arrange things such that console=myserial does the
> > > lookup. Then myserial=<foo> sets options for that device.
> > >
> > > I think you would need to add a call to dt_console_init to
> > > console_init_preirq(), in the "Where should console output go?" loop.
> >
> >
> > I don't see an easy solution with dt_console_init.
> > serial_parse_handle hardcodes the name of the serial, which only
> > supports com1, com2, dbgp. Sadly, the serial initialization is made in
> > the same function.
>
> Couldn't it also hardcode a call to a "is this a dt serial alias"
> function?


Indeed. Can we assume Xen on Arm will use only one UART? We can modify
the behaviour later.


>  > If I understand your suggestion, you suggest to use console=myserial
> > where *myserial* is the alias on the DTB, right?
>
> Right.
>
> > In this case the name could clash with the hardcoded ones in Xen that is
> not good.
>
> console=dt:<alias> ? Or to be honest I'm not sure that having the dt
> aliases shadow the Xen hardcoded ones would be a bad thing -- the x86
> centric com<X> definition hardcoded in Xen is hardly likely to be useful
> on ARM or any DT using platform.
>

I prefer dt:<alias> but how do we parse the configuration for the UART?
Do we use dt:<alias>=configuration on the command line? In this case
I don't see function to retrieve a non-defined parameters on the command
line.

We should also take care about video card. In the future, the devices will
be retrieved from the DTS.
Ian Campbell April 30, 2013, 12:41 p.m. UTC | #5
>         Couldn't it also hardcode a call to a "is this a dt serial
>         alias"
>         function?
> 
> 
> Indeed. Can we assume Xen on Arm will use only one UART? We can modify
> the behaviour later.

This seems acceptable to me.
>  
>         > If I understand your suggestion, you suggest to use
>         console=myserial
>         > where *myserial* is the alias on the DTB, right?
>         
>         
>         Right.
>         
>         > In this case the name could clash with the hardcoded ones in
>         Xen that is not good.
>         
>         
>         console=dt:<alias> ? Or to be honest I'm not sure that having
>         the dt
>         aliases shadow the Xen hardcoded ones would be a bad thing --
>         the x86
>         centric com<X> definition hardcoded in Xen is hardly likely to
>         be useful
>         on ARM or any DT using platform.
> 
> 
> I prefer dt:<alias> but how do we parse the configuration for the
> UART?
> 
> Do we use dt:<alias>=configuration on the command line? In this case
> I don't see function to retrieve a non-defined parameters on the
> command line.

Hrm, yes.

Perhaps dtuart=, applied to whichever dt:<alias> you choose?

> We should also take care about video card. In the future, the devices
> will be retrieved from the DTS.

In that case perhaps: console=dtuart:<alias> and =dtfb:<alias>?

Ian.
Julien Grall April 30, 2013, 1:37 p.m. UTC | #6
On 04/30/2013 01:41 PM, Ian Campbell wrote:

> 
> 
>>         Couldn't it also hardcode a call to a "is this a dt serial
>>         alias"
>>         function?
>>
>>
>> Indeed. Can we assume Xen on Arm will use only one UART? We can modify
>> the behaviour later.
> 
> This seems acceptable to me.
>>  
>>         > If I understand your suggestion, you suggest to use
>>         console=myserial
>>         > where *myserial* is the alias on the DTB, right?
>>         
>>         
>>         Right.
>>         
>>         > In this case the name could clash with the hardcoded ones in
>>         Xen that is not good.
>>         
>>         
>>         console=dt:<alias> ? Or to be honest I'm not sure that having
>>         the dt
>>         aliases shadow the Xen hardcoded ones would be a bad thing --
>>         the x86
>>         centric com<X> definition hardcoded in Xen is hardly likely to
>>         be useful
>>         on ARM or any DT using platform.
>>
>>
>> I prefer dt:<alias> but how do we parse the configuration for the
>> UART?
>>
>> Do we use dt:<alias>=configuration on the command line? In this case
>> I don't see function to retrieve a non-defined parameters on the
>> command line.
> 
> Hrm, yes.
> 
> Perhaps dtuart=, applied to whichever dt:<alias> you choose?
> 
>> We should also take care about video card. In the future, the devices
>> will be retrieved from the DTS.
> 
> In that case perhaps: console=dtuart:<alias> and =dtfb:<alias>?


Sounds good for me. I will rework the patch with that.
diff mbox

Patch

diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
index 51f4bba..e5d8724 100644
--- a/xen/arch/arm/setup.c
+++ b/xen/arch/arm/setup.c
@@ -434,8 +434,9 @@  void __init start_xen(unsigned long boot_phys_offset,
 #ifdef EARLY_UART_ADDRESS
     /* TODO Need to get device tree or command line for UART address */
     pl011_init(0, FIXMAP_ADDR(FIXMAP_CONSOLE));
-    console_init_preirq();
 #endif
+    arm_uart_init();
+    console_init_preirq();
 
     /* FIXME: Do something smarter */
     dt_switch_to_printk();
diff --git a/xen/drivers/char/Makefile b/xen/drivers/char/Makefile
index ab2246d..e68a54a 100644
--- a/xen/drivers/char/Makefile
+++ b/xen/drivers/char/Makefile
@@ -2,4 +2,5 @@  obj-y += console.o
 obj-$(HAS_NS16550) += ns16550.o
 obj-$(HAS_PL011) += pl011.o
 obj-$(HAS_EHCI) += ehci-dbgp.o
+obj-$(CONFIG_ARM) += arm-uart.o
 obj-y += serial.o
diff --git a/xen/drivers/char/arm-uart.c b/xen/drivers/char/arm-uart.c
new file mode 100644
index 0000000..e242ae2
--- /dev/null
+++ b/xen/drivers/char/arm-uart.c
@@ -0,0 +1,76 @@ 
+/*
+ * xen/drivers/char/arm-uart.c
+ *
+ * Generic ARM uart retrieved via the device tree
+ *
+ * Julien Grall <julien.grall@linaro.org>
+ * Copyright (c) 2013 Linaro Limited.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <asm/device.h>
+#include <asm/early_printk.h>
+#include <asm/types.h>
+#include <xen/console.h>
+#include <xen/device_tree.h>
+#include <xen/mm.h>
+#include <xen/serial.h>
+
+/*
+ * Configure serial port with string: devname
+ * Where devname is the alias of the device in the device tree
+ */
+static char __initdata opt_com1[30] = "";
+string_param("com1", opt_com1);
+
+void __init arm_uart_init(void)
+{
+    struct dt_device_node *dev;
+    int ret;
+    u64 addr, size;
+    struct serial_arm_defaults defaults;
+
+    if ( !console_has("com1") || !strcmp(opt_com1, "") )
+    {
+        early_printk("No console\n");
+        return;
+    }
+
+    early_printk("Looking for serial console %s\n", opt_com1);
+    dev = dt_find_node_by_alias(opt_com1);
+
+    if ( !dev )
+    {
+        early_printk("Unable to find device \"%s\"\n", opt_com1);
+        return;
+    }
+
+    ret = dt_device_get_address(dev, 0, &addr, &size);
+    if ( ret )
+    {
+        early_printk("Unable to retrieve the base address of the serial\n");
+        return;
+    }
+
+    clear_fixmap(FIXMAP_CONSOLE);
+    set_fixmap(FIXMAP_CONSOLE, addr >> PAGE_SHIFT, DEV_SHARED);
+
+    addr = FIXMAP_ADDR(FIXMAP_CONSOLE) + (addr & (PAGE_SIZE - 1));
+
+    defaults.index = 0;
+    defaults.register_base_address = addr;
+
+    ret = device_init(dev, DEVICE_SERIAL, &defaults);
+
+    if ( ret )
+        early_printk("Unable to initialize serial: %d\n", ret);
+}
diff --git a/xen/include/xen/serial.h b/xen/include/xen/serial.h
index 5de5171..2579ce8 100644
--- a/xen/include/xen/serial.h
+++ b/xen/include/xen/serial.h
@@ -9,6 +9,7 @@ 
 #ifndef __XEN_SERIAL_H__
 #define __XEN_SERIAL_H__
 
+#include <xen/init.h>
 #include <xen/spinlock.h>
 
 struct cpu_user_regs;
@@ -156,6 +157,13 @@  void ns16550_init(int index, struct ns16550_defaults *defaults);
 void ehci_dbgp_init(void);
 
 void pl011_init(int index, unsigned long register_base_address);
+/* Default value for UART on ARM boards */
+struct serial_arm_defaults {
+    int index;                              /* Serial index */
+    unsigned long register_base_address;    /* Virtual base address */
+};
+void __init arm_uart_init(void);
+
 
 struct physdev_dbgp_op;
 int dbgp_op(const struct physdev_dbgp_op *);