Initial patches for ARM64 based APM X-Gene Storm
cover Initial patches for ARM64 based APM X-Gene Storm
This is a series of basic patchset for booting xen on APM X-Gene.
The platform support added by this patches is only skeletal code and will be enhanced later.
Pranavkumar Sawargaonkar (4):
xen: arm64: Add Basic Platform support for APM X-Gene Storm.
xen: arm64: Add APM implementor id to processor implementers.
xen: drivers: char: Add Device Tree Based NS16550 UART driver.
xen: arm: arm64: Enabling compilation of device tree based ns16550
UART.
config/arm64.mk | 1 + xen/arch/arm/Rules.mk | 5 + xen/arch/arm/arm64/debug-xgene-storm.inc | 55 ++++++ xen/arch/arm/platforms/Makefile | 1 + xen/arch/arm/platforms/xgene-storm.c | 57 ++++++ xen/arch/arm/setup.c | 1 + xen/drivers/char/Makefile | 1 + xen/drivers/char/ns16550-dt.c | 302 +++++++++++++++++++++++++++++++ 8 files changed, 423 insertions(+) create mode 100644 xen/arch/arm/arm64/debug-xgene-storm.inc create mode 100644 xen/arch/arm/platforms/xgene-storm.c create mode 100644 xen/drivers/char/ns16550-dt.c
Signature · 1 line
1.8.2.1
PATCH 1/4 xen: arm64: Add Basic Platform support for APM X-Gene Storm.
This patch adds following things:
Early printk support for APM X-Gene platform.
Initial platform stubs for APM X-Gene.
--- xen/arch/arm/Rules.mk | 5 +++ xen/arch/arm/arm64/debug-xgene-storm.inc | 55 ++++++++++++++++++++++++++++++ xen/arch/arm/platforms/Makefile | 1 + xen/arch/arm/platforms/xgene-storm.c | 57 ++++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+) create mode 100644 xen/arch/arm/arm64/debug-xgene-storm.inc create mode 100644 xen/arch/arm/platforms/xgene-storm.c
xen/arch/arm/Rules.mk +5 -0
@@ -77,6 +77,11 @@ EARLY_PRINTK_INC := 8250 EARLY_UART_BASE_ADDRESS := 0x01c28000 EARLY_UART_REG_SHIFT := 2 endif +ifeq ($(CONFIG_EARLY_PRINTK), xgene-storm) +EARLY_PRINTK_INC := xgene-storm +EARLY_PRINTK_BAUD := 115200 +EARLY_UART_BASE_ADDRESS := 0x1c020000 +endif ifneq ($(EARLY_PRINTK_INC),) EARLY_PRINTK := y
xen/arch/arm/arm64/debug-xgene-storm.inc new file +55 -0
55 lines not on this page · raw message
xen/arch/arm/platforms/Makefile +1 -0
@@ -2,3 +2,4 @@ obj-y += vexpress.o obj-y += exynos5.o obj-y += midway.o obj-y += omap5.o +obj-y += xgene-storm.o
xen/arch/arm/platforms/xgene-storm.c new file +57 -0
57 lines not on this page · raw message
Signature · 1 line
1.8.2.1
Re: [PATCH 1/4] xen: arm64: Add Basic Platform support for APM X-Gene Storm.
Quoted 2 lines · Pranavkumar Sawargaonkar
This patch adds following things:
Early printk support for APM X-Gene platform.
Does the UART is compatible with 8250?
If so, can you rename the your debug-xgene-storm.inc in debug-8250.inc? Future ARM64 server with 8250-compatible UART will be able to use the same code.
Also, can you divide this patch in 2 part:
- Early printk support;
- Initial platform support.
Quoted 47 lines
Initial platform stubs for APM X-Gene.
Signed-off-by Anup Patel <[email protected]>Signed-off-by Pranavkumar Sawargaonkar <[email protected]>--- xen/arch/arm/Rules.mk | 5 +++ xen/arch/arm/arm64/debug-xgene-storm.inc | 55 ++++++++++++++++++++++++++++++ xen/arch/arm/platforms/Makefile | 1 + xen/arch/arm/platforms/xgene-storm.c | 57 ++++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+) create mode 100644 xen/arch/arm/arm64/debug-xgene-storm.inc create mode 100644 xen/arch/arm/platforms/xgene-storm.cxen/arch/arm/Rules.mk +5
-0@@ -77,6 +77,11 @@ EARLY_PRINTK_INC := 8250 EARLY_UART_BASE_ADDRESS := 0x01c28000 EARLY_UART_REG_SHIFT := 2 endif +ifeq ($(CONFIG_EARLY_PRINTK), xgene-storm) +EARLY_PRINTK_INC := xgene-storm +EARLY_PRINTK_BAUD := 115200 +EARLY_UART_BASE_ADDRESS := 0x1c020000 +endif ifneq ($(EARLY_PRINTK_INC),) EARLY_PRINTK := yxen/arch/arm/arm64/debug-xgene-storm.inc new file +12
-0@@ -0,0 +1,55 @@ +/* + * xen/arch/arm/arm64/debug-xgene-storm.inc + * + * X-Gene Storm specific debug code + * + * Copyright (c) 2013 Applied Micro. + * + * 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. + *
xen/arch/arm/arm64/debug-xgene-storm.inc line 22
Quoted 10 lines
xen/arch/arm/arm64/debug-xgene-storm.inc new file +10
-0+ * 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 <xen/8250-uart.h> + +#define XGENE_STORM_UART_LSR 0x14 +#define XGENE_STORM_UART_THR 0x00
I guess these defines contains the shift (=4), right?
To be more generic, you should allow a different shift via EARLY_UART_REG_SHIFT (see arm32/debug-8250.inc) and use this define.
xen/arch/arm/arm64/debug-xgene-storm.inc line 29
Quoted 7 lines
xen/arch/arm/arm64/debug-xgene-storm.inc new file +7
-0+ +/* UART initialization + * rb: register which contains the UART base address + * rc: scratch register 1 + * rd: scratch register 2 */ +.macro early_uart_init rb rc rd +.endm
early_uart_init is only needed if EARLY_PRINTK_INIT_UART is defined. In your case it's not defined, so you can remove this macro.
Quoted 31 lines
xen/arch/arm/arm64/debug-xgene-storm.inc new file +26
-0+ +/* UART wait UART to be ready to transmit + * xb: register which contains the UART base address + * c: scratch register */ +.macro early_uart_ready xb c +1: + ldrb w\c, [\xb, #XGENE_STORM_UART_LSR] + and w\c, w\c, #UART_LSR_THRE + cmp w\c, #UART_LSR_THRE + b.ne 1b +.endm + +/* UART transmit character + * xb: register which contains the UART base address + * wt: register which contains the character to transmit */ +.macro early_uart_transmit xb wt + /* UART_THR transmit holding */ + strb \wt, [\xb, #XGENE_STORM_UART_THR] +.endm + +/* + * Local variables: + * mode: ASM + * indent-tabs-mode: nil + * End: + */xen/arch/arm/platforms/Makefile +0
-0
xen/arch/arm/platforms/Makefile obj-y += vexpress.o · line 5
Quoted 4 lines
xen/arch/arm/platforms/Makefile +1
-0@@ -2,3 +2,4 @@ obj-y += vexpress.o obj-y += exynos5.o obj-y += midway.o obj-y += omap5.o +obj-y += xgene-storm.o
Shouldn't it be only enabled on ARM64?
Quoted 32 lines
xen/arch/arm/platforms/xgene-storm.c new file +26
-0@@ -0,0 +1,57 @@ +/* +* xen/arch/arm/platforms/xgene-storm.c +* +* Applied Micro's X-Gene specific settings +* +* Pranavkumar Sawargaonkar <[email protected]> +* Anup Patel <[email protected]> +* Copyright (c) 2013 Applied Micro. +* +* 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 <xen/config.h> +#include <xen/device_tree.h> +#include <xen/domain_page.h> +#include <xen/mm.h> +#include <xen/vmap.h> +#include <asm/platform.h>
xen/arch/arm/platforms/xgene-storm.c line 36
Quoted 10 lines
xen/arch/arm/platforms/xgene-storm.c new file +10
-0+#include <asm/early_printk.h> + +static void xgene_storm_reset (void ) +{ +} + +static int xgene_storm_init (void ) +{ +return 0 ; +}
You don't need these empty functions, the platform code copes with empty callback.
Quoted 21 lines
xen/arch/arm/platforms/xgene-storm.c new file +20
-0+static const char const *xgene_storm_dt_compat[]__initdata = +{ +"apm,xgene-storm" , +NULL +}; + +PLATFORM_START (xgene_storm,"APM X-GENE STORM" ) + .compatible = xgene_storm_dt_compat, + .init = xgene_storm_init, + .reset = xgene_storm_reset, +PLATFORM_END + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
Julien Grall
Re: [PATCH 1/4] xen: arm64: Add Basic Platform support for APM X-Gene Storm.
HI Julien,
Quoted 5 lines · Julien Grall
Quoted 2 lines · Pranavkumar Sawargaonkar
This patch adds following things:
Early printk support for APM X-Gene platform.Does the UART is compatible with 8250?
Yes it is compatible but it is ns16550.
Quoted 4 lines
If so, can you rename the your debug-xgene-storm.inc in debug-8250.inc? Future ARM64 server with 8250-compatible UART will be able to use the same code.
I think better name would be debug-ns16550.inc ??
Quoted 5 lines
Also, can you divide this patch in 2 part:
- Early printk support;
- Initial platform support.
Sure i will do it.
Quoted 60 lines
Quoted 47 lines
Initial platform stubs for APM X-Gene.
Signed-off-by Anup Patel <[email protected]>Signed-off-by Pranavkumar Sawargaonkar <[email protected]>--- xen/arch/arm/Rules.mk | 5 +++ xen/arch/arm/arm64/debug-xgene-storm.inc | 55 ++++++++++++++++++++++++++++++ xen/arch/arm/platforms/Makefile | 1 + xen/arch/arm/platforms/xgene-storm.c | 57 ++++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+) create mode 100644 xen/arch/arm/arm64/debug-xgene-storm.inc create mode 100644 xen/arch/arm/platforms/xgene-storm.cxen/arch/arm/Rules.mk +5
-0@@ -77,6 +77,11 @@ EARLY_PRINTK_INC := 8250 EARLY_UART_BASE_ADDRESS := 0x01c28000 EARLY_UART_REG_SHIFT := 2 endif +ifeq ($(CONFIG_EARLY_PRINTK), xgene-storm) +EARLY_PRINTK_INC := xgene-storm +EARLY_PRINTK_BAUD := 115200 +EARLY_UART_BASE_ADDRESS := 0x1c020000 +endif ifneq ($(EARLY_PRINTK_INC),) EARLY_PRINTK := yxen/arch/arm/arm64/debug-xgene-storm.inc new file +12
-0@@ -0,0 +1,55 @@ +/* + * xen/arch/arm/arm64/debug-xgene-storm.inc + * + * X-Gene Storm specific debug code + * + * Copyright (c) 2013 Applied Micro. + * + * 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. + *xen/arch/arm/arm64/debug-xgene-storm.inc line 22
Quoted 10 lines
xen/arch/arm/arm64/debug-xgene-storm.inc new file +10
-0+ * 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 <xen/8250-uart.h> + +#define XGENE_STORM_UART_LSR 0x14 +#define XGENE_STORM_UART_THR 0x00I guess these defines contains the shift (=4), right?
Quoted 2 lines
To be more generic, you should allow a different shift via
EARLY_UART_REG_SHIFT(see arm32/debug-8250.inc) and use this define.
Sure, i will do.
Quoted 42 lines
xen/arch/arm/arm64/debug-xgene-storm.inc line 29
Quoted 8 lines
xen/arch/arm/arm64/debug-xgene-storm.inc new file +7
-0+ +/* UART initialization + * rb: register which contains the UART base address + * rc: scratch register 1 + * rd: scratch register 2 */ +.macro early_uart_init rb rc rd +.endm
early_uart_initis only needed ifEARLY_PRINTK_INIT_UARTis defined. In your case it's not defined, so you can remove this macro.Quoted 29 lines
xen/arch/arm/arm64/debug-xgene-storm.inc new file +26
-0+ +/* UART wait UART to be ready to transmit + * xb: register which contains the UART base address + * c: scratch register */ +.macro early_uart_ready xb c +1: + ldrb w\c, [\xb, #XGENE_STORM_UART_LSR] + and w\c, w\c, #UART_LSR_THRE + cmp w\c, #UART_LSR_THRE + b.ne 1b +.endm + +/* UART transmit character + * xb: register which contains the UART base address + * wt: register which contains the character to transmit */ +.macro early_uart_transmit xb wt + /* UART_THR transmit holding */ + strb \wt, [\xb, #XGENE_STORM_UART_THR] +.endm + +/* + * Local variables: + * mode: ASM + * indent-tabs-mode: nil + * End: + */xen/arch/arm/platforms/Makefile +0
-1--- a/xen/arch/arm/platforms/Makefile
Quoted 8 lines
xen/arch/arm/platforms/Makefile obj-y += vexpress.o · line 5
Quoted 6 lines
+++ b/xen/arch/arm/platforms/Makefile
xen/arch/arm/platforms/Makefile +1
-0@@ -2,3 +2,4 @@ obj-y += vexpress.o obj-y += exynos5.o obj-y += midway.o obj-y += omap5.o +obj-y += xgene-storm.oShouldn't it be only enabled on ARM64?
But then arm32 boards should be only compiled for arm32 ?
Quoted 73 lines
Quoted 33 lines
xen/arch/arm/platforms/xgene-storm.c new file +26
-0@@ -0,0 +1,57 @@ +/* +* xen/arch/arm/platforms/xgene-storm.c +* +* Applied Micro's X-Gene specific settings +* +* Pranavkumar Sawargaonkar <[email protected]> +* Anup Patel <[email protected]> +* Copyright (c) 2013 Applied Micro. +* +* 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 <xen/config.h> +#include <xen/device_tree.h> +#include <xen/domain_page.h> +#include <xen/mm.h> +#include <xen/vmap.h> +#include <asm/platform.h> xen/arch/arm/platforms/xgene-storm.c line 36
Quoted 10 lines
xen/arch/arm/platforms/xgene-storm.c new file +10
-0+#include <asm/early_printk.h> + +static void xgene_storm_reset (void ) +{ +} + +static int xgene_storm_init (void ) +{ +return 0 ; +}You don't need these empty functions, the platform code copes with empty callback.
Quoted 11 lines
xen/arch/arm/platforms/xgene-storm.c new file +10
-0+static const char const *xgene_storm_dt_compat[]__initdata = +{ +"apm,xgene-storm" , +NULL +}; + +PLATFORM_START (xgene_storm,"APM X-GENE STORM" ) + .compatible = xgene_storm_dt_compat, + .init = xgene_storm_init, + .reset = xgene_storm_reset,xen/arch/arm/platforms/xgene-storm.c line 57
Quoted 10 lines
xen/arch/arm/platforms/xgene-storm.c new file +10
-0+PLATFORM_END + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ --
Julien Grall
Quoted 4 lines
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Thanks,
Pranav
Re: [PATCH 1/4] xen: arm64: Add Basic Platform support for APM X-Gene Storm.
Quoted 10 lines · Pranavkumar Sawargaonkar
HI Julien,
Quoted 5 lines · Julien Grall
Quoted 2 lines · Pranavkumar Sawargaonkar
This patch adds following things:
Early printk support for APM X-Gene platform.Does the UART is compatible with 8250?
Yes it is compatible but it is ns16550.
I think you can just use the existing debug-8250.inc then. The early console is just a debug thing so does not need to be full featured.
Re: [PATCH 1/4] xen: arm64: Add Basic Platform support for APM X-Gene Storm.
Hi Ian,
Quoted 8 lines · Ian Campbell
Quoted 7 lines · Pranavkumar Sawargaonkar
HI Julien,
Quoted 4 lines · Julien Grall
Quoted 2 lines · Pranavkumar Sawargaonkar
This patch adds following things:
Early printk support for APM X-Gene platform.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Does the UART is compatible with 8250?
Yes it is compatible but it is ns16550.
I think you can just use the existing debug-8250.inc then. The early console is just a debug thing so does not need to be full featured.
No because that is arm32 assembly.
Probably i will add/port similar debug-8250.inc for arm64.
Quoted 2 lines
Thanks,
Pranav
Re: [PATCH 1/4] xen: arm64: Add Basic Platform support for APM X-Gene Storm.
Quoted 11 lines · Pranavkumar Sawargaonkar
Hi Ian,
Quoted 8 lines · Ian Campbell
Quoted 7 lines · Pranavkumar Sawargaonkar
HI Julien,
Quoted 4 lines · Julien Grall
Quoted 2 lines · Pranavkumar Sawargaonkar
This patch adds following things:
Early printk support for APM X-Gene platform.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Does the UART is compatible with 8250?
Yes it is compatible but it is ns16550.
I think you can just use the existing debug-8250.inc then. The early console is just a debug thing so does not need to be full featured.
No because that is arm32 assembly.
Doh, Obviously! Sorry, need to have breakfast/coffee before commenting next time!
Quoted 1 line
Probably i will add/port similar debug-8250.inc for arm64.
Yes, please name it as generically as possible. 8250 is probably the right thing.
Ian.
Re: [PATCH 1/4] xen: arm64: Add Basic Platform support for APM X-Gene Storm.
In reply to Pranavkumar SawargaonkarQuoted 10 lines · Pranavkumar Sawargaonkar
HI Julien,
Quoted 5 lines · Julien Grall
Quoted 2 lines · Pranavkumar Sawargaonkar
This patch adds following things:
Early printk support for APM X-Gene platform.Does the UART is compatible with 8250?
Yes it is compatible but it is ns16550.
[..]
Quoted 1 line
I think better name would be debug-ns16550.inc ??
There are some UARTs that are 8250-compatible but not ns16550-compatible. It would be better to stay as generic as possible to support numerous UART.
Quoted 7 lines
Quoted 5 lines
Also, can you divide this patch in 2 part:
- Early printk support;
- Initial platform support.Shouldn't it be only enabled on ARM64?
But then arm32 boards should be only compiled for arm32 ?
Right :). We begin to have multiple platforms that are only supported in one architecture (arm32 or arm64). So it's good time to introduce a way to compile only supported platform.
Signature · 1 line
Julien Grall
PATCH 2/4 xen: arm64: Add APM implementor id to processor implementers.
In reply to Pranavkumar SawargaonkarThis patch updates the list of processor implementers with APM implementor id.
--- xen/arch/arm/setup.c | 1 + 1 file changed, 1 insertion(+)
xen/arch/arm/setup.c +1 -0
@@ -62,6 +62,7 @@ static const char * __initdata processor_implementers[] = { ['A'] = "ARM Limited", ['D'] = "Digital Equipment Corp", ['M'] = "Motorola, Freescale Semiconductor Inc.", + ['P'] = "Applied Micro", ['Q'] = "Qualcomm Inc.", ['V'] = "Marvell Semiconductor Inc.", ['i'] = "Intel Corporation",
Signature · 1 line
1.8.2.1
Re: [PATCH 2/4] xen: arm64: Add APM implementor id to processor implementers.
Quoted 4 lines · Pranavkumar Sawargaonkar
This patch updates the list of processor implementers with APM implementor id.
Signed-off-by Anup Patel <[email protected]>Signed-off-by Pranavkumar Sawargaonkar <[email protected]>
Quoted 17 lines
--- xen/arch/arm/setup.c | 1 + 1 file changed, 1 insertion(+)xen/arch/arm/setup.c +1
-0@@ -62,6 +62,7 @@ static const char * __initdata processor_implementers[] = { ['A'] = "ARM Limited", ['D'] = "Digital Equipment Corp", ['M'] = "Motorola, Freescale Semiconductor Inc.", + ['P'] = "Applied Micro", ['Q'] = "Qualcomm Inc.", ['V'] = "Marvell Semiconductor Inc.", ['i'] = "Intel Corporation",
Signature · 1 line
Julien Grall
PATCH 3/4 xen: drivers: char: Add Device Tree Based NS16550 UART driver.
In reply to Pranavkumar SawargaonkarThis patch adds a device tree based driver for ns16550 UART.
--- xen/drivers/char/Makefile | 1 + xen/drivers/char/ns16550-dt.c | 302 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 303 insertions(+) create mode 100644 xen/drivers/char/ns16550-dt.c
xen/drivers/char/Makefile +1 -0
@@ -5,4 +5,5 @@ obj-$(HAS_EXYNOS4210) += exynos4210-uart.o obj-$(HAS_OMAP) += omap-uart.o obj-$(HAS_EHCI) += ehci-dbgp.o obj-$(CONFIG_ARM) += dt-uart.o +obj-$(HAS_NS16550_DT) += ns16550-dt.o obj-y += serial.o
xen/drivers/char/ns16550-dt.c new file +302 -0
302 lines not on this page · raw message
Signature · 1 line
1.8.2.1
Re: [PATCH 3/4] xen: drivers: char: Add Device Tree Based NS16550 UART driver.
Quoted 1 line · Pranavkumar Sawargaonkar
This patch adds a device tree based driver for ns16550 UART.
I posted patches last week (or the week before) to support the cubieboard2 and that series included a patch to enable the existing ns16550 driver to be used on DT as well. I think that is better than duplicating the majority of the driver just differ in a few probe routines.
Does that approach work for you?
Quoted 327 lines
Signed-off-by Anup Patel <[email protected]>Signed-off-by Pranavkumar Sawargaonkar <[email protected]>--- xen/drivers/char/Makefile | 1 + xen/drivers/char/ns16550-dt.c | 302 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 303 insertions(+) create mode 100644 xen/drivers/char/ns16550-dt.cxen/drivers/char/Makefile +1
-0@@ -5,4 +5,5 @@ obj-$(HAS_EXYNOS4210) += exynos4210-uart.o obj-$(HAS_OMAP) += omap-uart.o obj-$(HAS_EHCI) += ehci-dbgp.o obj-$(CONFIG_ARM) += dt-uart.o +obj-$(HAS_NS16550_DT) += ns16550-dt.o obj-y += serial.oxen/drivers/char/ns16550-dt.c new file +302
-0@@ -0,0 +1,302 @@ +/* +* xen/drivers/char/ns16550.c +* +* Driver for ns16550 UART based on DT bindigs. +* +* Pranavkumar Sawargaonkar <[email protected]> +* Anup Patel <[email protected]> +* Copyright (c) 2013 Applied Micro. +* +* 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 <xen/config.h> +#include <xen/console.h> +#include <xen/serial.h> +#include <xen/init.h> +#include <xen/irq.h> +#include <asm/early_printk.h> +#include <xen/device_tree.h> +#include <xen/errno.h> +#include <asm/device.h> +#include <xen/mm.h> +#include <xen/vmap.h> +#include <xen/8250-uart.h> + +static struct ns16550 { +unsigned int baud, clock_hz, data_bits, parity, stop_bits; +unsigned int fifo_size; +unsigned int reg_align;/* Regs alignement */ +struct dt_irq irq; +void __iomem *regs; +/* UART with IRQ line: interrupt-driven I/O. */ +struct irqaction irqaction; +struct vuart_info vuart; +} ns16550_com = {0 }; + + +static char ns16550_read (struct ns16550 *uart,int reg) +{ +return ioreadl ((uart)->regs + (reg * (uart->reg_align))); +} + +static void ns16550_write (struct ns16550 *uart,int reg,char c) +{ +iowritel ((uart)->regs + (reg * (uart->reg_align)), c); +} + +static void ns16550_interrupt (int irq,void *data,struct cpu_user_regs *regs) +{ +struct serial_port *port = data; +struct ns16550 *uart = port->uart; + +while ( !(ns16550_read (uart,UART_IIR ) &UART_IIR_NOINT ) ) + { +char lsr =ns16550_read (uart,UART_LSR ); +if ( lsr &UART_LSR_THRE ) +serial_tx_interrupt (port, regs); +if ( lsr &UART_LSR_DR ) +serial_rx_interrupt (port, regs); + } +} + +static void ns16550_setup_preirq (struct ns16550 *uart) +{ +unsigned char lcr; +unsigned int divisor; + + lcr = (uart->data_bits -5 ) | ((uart->stop_bits -1 ) <<2 ) | uart->parity; + +/* No interrupts. */ +ns16550_write (uart,UART_IER ,0 ); + +/* Line control and baud-rate generator. */ +ns16550_write (uart,UART_LCR , lcr |UART_LCR_DLAB ); +if ( uart->baud !=BAUD_AUTO ) + { +/* Baud rate specified: program it into the divisor latch. */ + divisor = uart->clock_hz / (uart->baud <<4 ); +ns16550_write (uart,UART_DLL , (char )divisor); +ns16550_write (uart,UART_DLM , (char )(divisor >>8 )); + } +else + { +/* Baud rate already set: read it out from the divisor latch. */ + divisor =ns16550_read (uart,UART_DLL ); + divisor |=ns16550_read (uart,UART_DLM ) <<8 ; + uart->baud = uart->clock_hz / (divisor <<4 ); + } +ns16550_write (uart,UART_LCR , lcr); + +/* No flow ctrl: DTR and RTS are both wedged high to keep remote happy. */ +ns16550_write (uart,UART_MCR ,UART_MCR_DTR |UART_MCR_RTS ); + +/* Enable and clear the FIFOs. Set a large trigger threshold. */ +ns16550_write (uart,UART_FCR , +UART_FCR_ENABLE |UART_FCR_CLRX |UART_FCR_CLTX |UART_FCR_TRG14 ); +} + +static void __init ns16550_init_preirq (struct serial_port *port) +{ +struct ns16550 *uart = port->uart; + +ns16550_setup_preirq (uart); + +/* Check this really is a 16550+. Otherwise we have no FIFOs. */ +if ( ((ns16550_read (uart,UART_IIR ) &0xc0 ) ==0xc0 ) && + ((ns16550_read (uart,UART_FCR ) &UART_FCR_TRG14 ) ==UART_FCR_TRG14 ) ) + uart->fifo_size =16 ; +} + +static void ns16550_setup_postirq (struct ns16550 *uart) +{ +if ( uart->irq.irq >0 ) + { +/* Master interrupt enable; also keep DTR/RTS asserted. */ +ns16550_write (uart, +UART_MCR ,UART_MCR_OUT2 |UART_MCR_DTR |UART_MCR_RTS ); + +/* Enable receive and transmit interrupts. */ +ns16550_write (uart,UART_IER ,UART_IER_ERDAI |UART_IER_ETHREI ); + } +} + +static void __init ns16550_init_postirq (struct serial_port *port) +{ +struct ns16550 *uart = port->uart; +int rc, bits; + +if ( uart->irq.irq <0 ) +return ; + +/* Calculate time to fill RX FIFO and/or empty TX FIFO for polling. */ + bits = uart->data_bits + uart->stop_bits + !!uart->parity; + +if ( uart->irq.irq >0 ) + { + uart->irqaction.handler = ns16550_interrupt; + uart->irqaction.name ="ns16550" ; + uart->irqaction.dev_id = port; +if ( (rc =setup_dt_irq (&uart->irq, &uart->irqaction)) !=0 ) +printk ("ERROR: Failed to allocate ns16550 IRQ %d\n" , uart->irq.irq); + } + +ns16550_setup_postirq (uart); +} + +static int ns16550_tx_ready (struct serial_port *port) +{ +struct ns16550 *uart = port->uart; + +return ns16550_read (uart,UART_LSR ) &UART_LSR_THRE ? uart->fifo_size :0 ; +} + +static void ns16550_putc (struct serial_port *port,char c) +{ +struct ns16550 *uart = port->uart; + +ns16550_write (uart,UART_THR , c); +} + +static int ns16550_getc (struct serial_port *port,char *pc) +{ +struct ns16550 *uart = port->uart; + +if ( !(ns16550_read (uart,UART_LSR ) &UART_LSR_DR ) ) +return 0 ; + + *pc =ns16550_read (uart,UART_RBR ); +return 1 ; +} + +static void ns16550_suspend (struct serial_port *port) +{ +BUG ();// XXX +} + +static void ns16550_resume (struct serial_port *port) +{ +BUG ();// XXX +} + +static int __init ns16550_irq (struct serial_port *port) +{ +struct ns16550 *uart = port->uart; +return ((uart->irq.irq >0 ) ? uart->irq.irq :-1 ); +} + +static const struct dt_irq __init *ns16550_dt_irq (struct serial_port *port) +{ +struct ns16550 *uart = port->uart; + +return &uart->irq; +} + +static const struct vuart_info *ns16550_vuart (struct serial_port *port) +{ +struct ns16550 *uart = port->uart; + +return &uart->vuart; +} + +static struct uart_driver __read_mostly ns16550_driver = { + .init_preirq = ns16550_init_preirq, + .init_postirq = ns16550_init_postirq, + .endboot =NULL , + .suspend = ns16550_suspend, + .resume = ns16550_resume, + .tx_ready = ns16550_tx_ready, + .putc = ns16550_putc, + .getc = ns16550_getc, + .irq = ns16550_irq, + .dt_irq_get = ns16550_dt_irq, + .vuart_info = ns16550_vuart, +}; + +/* TODO: Parse UART config from the command line */ +static int __init ns16550_uart_init (struct dt_device_node *dev, +const void *data) +{ +const char *config = data; +struct ns16550 *uart; +int res; +u64 addr, size; + +if (strcmp (config,"" ) ) + { +early_printk ("WARNING: UART configuration is not supported\n" ); + } + + uart = &ns16550_com; + + uart->clock_hz =50000000 ; + uart->baud =115200 ; + uart->data_bits =8 ; + uart->parity =UART_PARITY_NONE ;/* FIXME */ + uart->stop_bits =1 ; + uart->reg_align =4 ; + + res =dt_device_get_address (dev,0 , &addr, &size); +if ( res ) + { +early_printk ("ns16550: Unable to retrieve the base" +" address of the UART\n" ); +return res; + } + + uart->regs =ioremap_attr (addr, size,PAGE_HYPERVISOR_NOCACHE ); +if ( !uart->regs ) + { +early_printk ("ns16550: Unable to map the UART memory\n" ); + +return -ENOMEM ; + } + + res =dt_device_get_irq (dev,0 , &uart->irq); +if ( res ) + { +early_printk ("ns16550: Unable to retrieve the IRQ\n" ); +return res; + } + + uart->vuart.base_addr = addr; + uart->vuart.size = size; + uart->vuart.data_off = (UART_THR * uart->reg_align) ; + uart->vuart.status_off = (UART_LSR * uart->reg_align); + uart->vuart.status =UART_LSR_THRE ; + +/* Register with generic serial driver. */ +serial_register_uart (SERHND_DTUART , &ns16550_driver, uart); + +dt_device_set_used_by (dev,DOMID_XEN ); + +return 0 ; +} + +static const char const *ns16550_dt_compat[]__initdata = +{ +"ns16550" , +NULL +}; + +DT_DEVICE_START (ns16550,"NS16550 UART" ,DEVICE_SERIAL ) + .compatible = ns16550_dt_compat, + .init = ns16550_uart_init, +DT_DEVICE_END + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Re: [PATCH 3/4] xen: drivers: char: Add Device Tree Based NS16550 UART driver.
Hi Ian,
Quoted 10 lines · Ian Campbell
Quoted 1 line · Pranavkumar Sawargaonkar
This patch adds a device tree based driver for ns16550 UART.
I posted patches last week (or the week before) to support the cubieboard2 and that series included a patch to enable the existing ns16550 driver to be used on DT as well. I think that is better than duplicating the majority of the driver just differ in a few probe routines.
Does that approach work for you?
We will be happy to try that, when will it be merged in xen git repo any idea ?
Quoted 327 lines
Quoted 327 lines
Signed-off-by Anup Patel <[email protected]>Signed-off-by Pranavkumar Sawargaonkar <[email protected]>--- xen/drivers/char/Makefile | 1 + xen/drivers/char/ns16550-dt.c | 302 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 303 insertions(+) create mode 100644 xen/drivers/char/ns16550-dt.cxen/drivers/char/Makefile +1
-0@@ -5,4 +5,5 @@ obj-$(HAS_EXYNOS4210) += exynos4210-uart.o obj-$(HAS_OMAP) += omap-uart.o obj-$(HAS_EHCI) += ehci-dbgp.o obj-$(CONFIG_ARM) += dt-uart.o +obj-$(HAS_NS16550_DT) += ns16550-dt.o obj-y += serial.oxen/drivers/char/ns16550-dt.c new file +301
-0@@ -0,0 +1,302 @@ +/* +* xen/drivers/char/ns16550.c +* +* Driver for ns16550 UART based on DT bindigs. +* +* Pranavkumar Sawargaonkar <[email protected]> +* Anup Patel <[email protected]> +* Copyright (c) 2013 Applied Micro. +* +* 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 <xen/config.h> +#include <xen/console.h> +#include <xen/serial.h> +#include <xen/init.h> +#include <xen/irq.h> +#include <asm/early_printk.h> +#include <xen/device_tree.h> +#include <xen/errno.h> +#include <asm/device.h> +#include <xen/mm.h> +#include <xen/vmap.h> +#include <xen/8250-uart.h> + +static struct ns16550 { +unsigned int baud, clock_hz, data_bits, parity, stop_bits; +unsigned int fifo_size; +unsigned int reg_align;/* Regs alignement */ +struct dt_irq irq; +void __iomem *regs; +/* UART with IRQ line: interrupt-driven I/O. */ +struct irqaction irqaction; +struct vuart_info vuart; +} ns16550_com = {0 }; + + +static char ns16550_read (struct ns16550 *uart,int reg) +{ +return ioreadl ((uart)->regs + (reg * (uart->reg_align))); +} + +static void ns16550_write (struct ns16550 *uart,int reg,char c) +{ +iowritel ((uart)->regs + (reg * (uart->reg_align)), c); +} + +static void ns16550_interrupt (int irq,void *data,struct cpu_user_regs *regs) +{ +struct serial_port *port = data; +struct ns16550 *uart = port->uart; + +while ( !(ns16550_read (uart,UART_IIR ) &UART_IIR_NOINT ) ) + { +char lsr =ns16550_read (uart,UART_LSR ); +if ( lsr &UART_LSR_THRE ) +serial_tx_interrupt (port, regs); +if ( lsr &UART_LSR_DR ) +serial_rx_interrupt (port, regs); + } +} + +static void ns16550_setup_preirq (struct ns16550 *uart) +{ +unsigned char lcr; +unsigned int divisor; + + lcr = (uart->data_bits -5 ) | ((uart->stop_bits -1 ) <<2 ) | uart->parity; + +/* No interrupts. */ +ns16550_write (uart,UART_IER ,0 ); + +/* Line control and baud-rate generator. */ +ns16550_write (uart,UART_LCR , lcr |UART_LCR_DLAB ); +if ( uart->baud !=BAUD_AUTO ) + { +/* Baud rate specified: program it into the divisor latch. */ + divisor = uart->clock_hz / (uart->baud <<4 ); +ns16550_write (uart,UART_DLL , (char )divisor); +ns16550_write (uart,UART_DLM , (char )(divisor >>8 )); + } +else + { +/* Baud rate already set: read it out from the divisor latch. */ + divisor =ns16550_read (uart,UART_DLL ); + divisor |=ns16550_read (uart,UART_DLM ) <<8 ; + uart->baud = uart->clock_hz / (divisor <<4 ); + } +ns16550_write (uart,UART_LCR , lcr); + +/* No flow ctrl: DTR and RTS are both wedged high to keep remote happy. */ +ns16550_write (uart,UART_MCR ,UART_MCR_DTR |UART_MCR_RTS ); + +/* Enable and clear the FIFOs. Set a large trigger threshold. */ +ns16550_write (uart,UART_FCR , +UART_FCR_ENABLE |UART_FCR_CLRX |UART_FCR_CLTX |UART_FCR_TRG14 ); +} + +static void __init ns16550_init_preirq (struct serial_port *port) +{ +struct ns16550 *uart = port->uart; + +ns16550_setup_preirq (uart); + +/* Check this really is a 16550+. Otherwise we have no FIFOs. */ +if ( ((ns16550_read (uart,UART_IIR ) &0xc0 ) ==0xc0 ) && + ((ns16550_read (uart,UART_FCR ) &UART_FCR_TRG14 ) ==UART_FCR_TRG14 ) ) + uart->fifo_size =16 ; +} + +static void ns16550_setup_postirq (struct ns16550 *uart) +{ +if ( uart->irq.irq >0 ) + { +/* Master interrupt enable; also keep DTR/RTS asserted. */ +ns16550_write (uart, +UART_MCR ,UART_MCR_OUT2 |UART_MCR_DTR |UART_MCR_RTS ); + +/* Enable receive and transmit interrupts. */ +ns16550_write (uart,UART_IER ,UART_IER_ERDAI |UART_IER_ETHREI ); + } +} + +static void __init ns16550_init_postirq (struct serial_port *port) +{ +struct ns16550 *uart = port->uart; +int rc, bits; + +if ( uart->irq.irq <0 ) +return ; + +/* Calculate time to fill RX FIFO and/or empty TX FIFO for polling. */ + bits = uart->data_bits + uart->stop_bits + !!uart->parity; + +if ( uart->irq.irq >0 ) + { + uart->irqaction.handler = ns16550_interrupt; + uart->irqaction.name ="ns16550" ; + uart->irqaction.dev_id = port; +if ( (rc =setup_dt_irq (&uart->irq, &uart->irqaction)) !=0 ) +printk ("ERROR: Failed to allocate ns16550 IRQ %d\n" , uart->irq.irq); + } + +ns16550_setup_postirq (uart); +} + +static int ns16550_tx_ready (struct serial_port *port) +{ +struct ns16550 *uart = port->uart; + +return ns16550_read (uart,UART_LSR ) &UART_LSR_THRE ? uart->fifo_size :0 ; +} + +static void ns16550_putc (struct serial_port *port,char c) +{ +struct ns16550 *uart = port->uart; + +ns16550_write (uart,UART_THR , c); +} + +static int ns16550_getc (struct serial_port *port,char *pc) +{ +struct ns16550 *uart = port->uart; + +if ( !(ns16550_read (uart,UART_LSR ) &UART_LSR_DR ) ) +return 0 ; + + *pc =ns16550_read (uart,UART_RBR ); +return 1 ; +} + +static void ns16550_suspend (struct serial_port *port) +{ +BUG ();// XXX +} + +static void ns16550_resume (struct serial_port *port) +{ +BUG ();// XXX +} + +static int __init ns16550_irq (struct serial_port *port) +{ +struct ns16550 *uart = port->uart; +return ((uart->irq.irq >0 ) ? uart->irq.irq :-1 ); +} + +static const struct dt_irq __init *ns16550_dt_irq (struct serial_port *port) +{ +struct ns16550 *uart = port->uart; + +return &uart->irq; +} + +static const struct vuart_info *ns16550_vuart (struct serial_port *port) +{ +struct ns16550 *uart = port->uart; + +return &uart->vuart; +} + +static struct uart_driver __read_mostly ns16550_driver = { + .init_preirq = ns16550_init_preirq, + .init_postirq = ns16550_init_postirq, + .endboot =NULL , + .suspend = ns16550_suspend, + .resume = ns16550_resume, + .tx_ready = ns16550_tx_ready, + .putc = ns16550_putc, + .getc = ns16550_getc, + .irq = ns16550_irq, + .dt_irq_get = ns16550_dt_irq, + .vuart_info = ns16550_vuart, +}; + +/* TODO: Parse UART config from the command line */ +static int __init ns16550_uart_init (struct dt_device_node *dev, +const void *data) +{ +const char *config = data; +struct ns16550 *uart; +int res; +u64 addr, size; + +if (strcmp (config,"" ) ) + { +early_printk ("WARNING: UART configuration is not supported\n" ); + } + + uart = &ns16550_com; + + uart->clock_hz =50000000 ; + uart->baud =115200 ; + uart->data_bits =8 ; + uart->parity =UART_PARITY_NONE ;/* FIXME */ + uart->stop_bits =1 ; + uart->reg_align =4 ; + + res =dt_device_get_address (dev,0 , &addr, &size); +if ( res ) + { +early_printk ("ns16550: Unable to retrieve the base" +" address of the UART\n" ); +return res; + } + + uart->regs =ioremap_attr (addr, size,PAGE_HYPERVISOR_NOCACHE ); +if ( !uart->regs ) + { +early_printk ("ns16550: Unable to map the UART memory\n" ); + +return -ENOMEM ; + } + + res =dt_device_get_irq (dev,0 , &uart->irq); +if ( res ) + { +early_printk ("ns16550: Unable to retrieve the IRQ\n" ); +return res; + } + + uart->vuart.base_addr = addr; + uart->vuart.size = size; + uart->vuart.data_off = (UART_THR * uart->reg_align) ; + uart->vuart.status_off = (UART_LSR * uart->reg_align); + uart->vuart.status =UART_LSR_THRE ; + +/* Register with generic serial driver. */ +serial_register_uart (SERHND_DTUART , &ns16550_driver, uart); + +dt_device_set_used_by (dev,DOMID_XEN ); + +return 0 ; +} + +static const char const *ns16550_dt_compat[]__initdata = +{ +"ns16550" , +NULL +}; + +DT_DEVICE_START (ns16550,"NS16550 UART" ,DEVICE_SERIAL ) + .compatible = ns16550_dt_compat, + .init = ns16550_uart_init, +DT_DEVICE_END + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End:
Quoted 8 lines
xen/drivers/char/ns16550-dt.c line 302
Quoted 1 line
xen/drivers/char/ns16550-dt.c new file +1
-0+*/ _______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Thanks,
Pranav
Re: [PATCH 3/4] xen: drivers: char: Add Device Tree Based NS16550 UART driver.
Quoted 12 lines · Pranavkumar Sawargaonkar
Hi Ian,
Quoted 9 lines · Ian Campbell
Quoted 1 line · Pranavkumar Sawargaonkar
This patch adds a device tree based driver for ns16550 UART.
I posted patches last week (or the week before) to support the cubieboard2 and that series included a patch to enable the existing ns16550 driver to be used on DT as well. I think that is better than duplicating the majority of the driver just differ in a few probe routines.
Quoted 3 lines
Quoted 1 line
Does that approach work for you?
We will be happy to try that, when will it be merged in xen git repo any idea ?
I need to repost addressing some review feedback from Julien on a prior patch which it depends on. I hope to post that early next week and get it committed asap.
In the meantime you can find the changes in
http://xenbits.xen.org/gitweb/?p=people/ianc/xen.git cubieboard
Ian/
PATCH 4/4 xen: arm: arm64: Enabling compilation of device tree based ns16550 UART.
In reply to Pranavkumar SawargaonkarThis patch enables compilation of device tree based NS16550 UART driver for arm64.
--- config/arm64.mk | 1 + 1 file changed, 1 insertion(+)
config/arm64.mk +1 -0
@@ -7,6 +7,7 @@ CONFIG_XEN_INSTALL_SUFFIX := CFLAGS += #-marm -march= -mcpu= etc HAS_PL011 := y +HAS_NS16550_DT :=y # Use only if calling $(LD) directly. LDFLAGS_DIRECT += -EL
Signature · 1 line
1.8.2.1