Pranavkumar Sawargaonkar
2013-Sep-20 09:52 UTC
[PATCH 0/4] 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 -- 1.8.2.1
Pranavkumar Sawargaonkar
2013-Sep-20 09:52 UTC
[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. Signed-off-by: Anup Patel <anup.patel@linaro.org> Signed-off-by: Pranavkumar Sawargaonkar <pranavkumar@linaro.org> --- 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 diff --git a/xen/arch/arm/Rules.mk b/xen/arch/arm/Rules.mk index bd79b26..b36120e 100644 --- a/xen/arch/arm/Rules.mk +++ b/xen/arch/arm/Rules.mk @@ -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 diff --git a/xen/arch/arm/arm64/debug-xgene-storm.inc b/xen/arch/arm/arm64/debug-xgene-storm.inc new file mode 100644 index 0000000..ebbb8d2 --- /dev/null +++ b/xen/arch/arm/arm64/debug-xgene-storm.inc @@ -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. + * + * 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 + +/* 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 + +/* 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: + */ diff --git a/xen/arch/arm/platforms/Makefile b/xen/arch/arm/platforms/Makefile index 4aa82e8..8a6709f 100644 --- a/xen/arch/arm/platforms/Makefile +++ b/xen/arch/arm/platforms/Makefile @@ -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 diff --git a/xen/arch/arm/platforms/xgene-storm.c b/xen/arch/arm/platforms/xgene-storm.c new file mode 100644 index 0000000..8e2b3b6 --- /dev/null +++ b/xen/arch/arm/platforms/xgene-storm.c @@ -0,0 +1,57 @@ +/* + * xen/arch/arm/platforms/xgene-storm.c + * + * Applied Micro''s X-Gene specific settings + * + * Pranavkumar Sawargaonkar <psawargaonkar@apm.com> + * Anup Patel <apatel@apm.com> + * 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> +#include <asm/early_printk.h> + +static void xgene_storm_reset(void) +{ +} + +static int xgene_storm_init(void) +{ + return 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: + */ -- 1.8.2.1
Pranavkumar Sawargaonkar
2013-Sep-20 09:52 UTC
[PATCH 2/4] xen: arm64: Add APM implementor id to processor implementers.
This patch updates the list of processor implementers with APM implementor id. Signed-off-by: Anup Patel <anup.patel@linaro.org> Signed-off-by: Pranavkumar Sawargaonkar <pranavkumar@linaro.org> --- xen/arch/arm/setup.c | 1 + 1 file changed, 1 insertion(+) diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 4b31623..0ad5668 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -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", -- 1.8.2.1
Pranavkumar Sawargaonkar
2013-Sep-20 09:52 UTC
[PATCH 3/4] xen: drivers: char: Add Device Tree Based NS16550 UART driver.
This patch adds a device tree based driver for ns16550 UART. Signed-off-by: Anup Patel <anup.patel@linaro.org> Signed-off-by: Pranavkumar Sawargaonkar <pranavkumar@linaro.org> --- 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 diff --git a/xen/drivers/char/Makefile b/xen/drivers/char/Makefile index 911b788..7c22a1b 100644 --- a/xen/drivers/char/Makefile +++ b/xen/drivers/char/Makefile @@ -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 diff --git a/xen/drivers/char/ns16550-dt.c b/xen/drivers/char/ns16550-dt.c new file mode 100644 index 0000000..74d2b57 --- /dev/null +++ b/xen/drivers/char/ns16550-dt.c @@ -0,0 +1,302 @@ +/* + * xen/drivers/char/ns16550.c + * + * Driver for ns16550 UART based on DT bindigs. + * + * Pranavkumar Sawargaonkar <psawargaonkar@apm.com> + * Anup Patel <apatel@apm.com> + * 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: + */ -- 1.8.2.1
Pranavkumar Sawargaonkar
2013-Sep-20 09:52 UTC
[PATCH 4/4] xen: arm: arm64: Enabling compilation of device tree based ns16550 UART.
This patch enables compilation of device tree based NS16550 UART driver for arm64. Signed-off-by: Anup Patel <anup.patel@linaro.org> Signed-off-by: Pranavkumar Sawargaonkar <pranavkumar@linaro.org> --- config/arm64.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/config/arm64.mk b/config/arm64.mk index 49055fa..435173e 100644 --- a/config/arm64.mk +++ b/config/arm64.mk @@ -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 -- 1.8.2.1
Julien Grall
2013-Sep-20 12:09 UTC
Re: [PATCH 1/4] xen: arm64: Add Basic Platform support for APM X-Gene Storm.
On 09/20/2013 10:52 AM, Pranavkumar Sawargaonkar wrote:> 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.> Initial platform stubs for APM X-Gene. > > Signed-off-by: Anup Patel <anup.patel@linaro.org> > Signed-off-by: Pranavkumar Sawargaonkar <pranavkumar@linaro.org> > --- > 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 > > diff --git a/xen/arch/arm/Rules.mk b/xen/arch/arm/Rules.mk > index bd79b26..b36120e 100644 > --- a/xen/arch/arm/Rules.mk > +++ b/xen/arch/arm/Rules.mk > @@ -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 > diff --git a/xen/arch/arm/arm64/debug-xgene-storm.inc b/xen/arch/arm/arm64/debug-xgene-storm.inc > new file mode 100644 > index 0000000..ebbb8d2 > --- /dev/null > +++ b/xen/arch/arm/arm64/debug-xgene-storm.inc > @@ -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. > + * > + * 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? To be more generic, you should allow a different shift via EARLY_UART_REG_SHIFT (see arm32/debug-8250.inc) and use this define.> + > +/* 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 > +.endmearly_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.> + > +/* 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: > + */ > diff --git a/xen/arch/arm/platforms/Makefile b/xen/arch/arm/platforms/Makefile > index 4aa82e8..8a6709f 100644 > --- a/xen/arch/arm/platforms/Makefile > +++ b/xen/arch/arm/platforms/Makefile > @@ -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?> diff --git a/xen/arch/arm/platforms/xgene-storm.c b/xen/arch/arm/platforms/xgene-storm.c > new file mode 100644 > index 0000000..8e2b3b6 > --- /dev/null > +++ b/xen/arch/arm/platforms/xgene-storm.c > @@ -0,0 +1,57 @@ > +/* > + * xen/arch/arm/platforms/xgene-storm.c > + * > + * Applied Micro''s X-Gene specific settings > + * > + * Pranavkumar Sawargaonkar <psawargaonkar@apm.com> > + * Anup Patel <apatel@apm.com> > + * 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> > +#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.> +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: > + */ >-- Julien Grall
Julien Grall
2013-Sep-20 12:10 UTC
Re: [PATCH 2/4] xen: arm64: Add APM implementor id to processor implementers.
On 09/20/2013 10:52 AM, Pranavkumar Sawargaonkar wrote:> This patch updates the list of processor implementers with APM implementor id. > > Signed-off-by: Anup Patel <anup.patel@linaro.org> > Signed-off-by: Pranavkumar Sawargaonkar <pranavkumar@linaro.org>Acked-by: Julien Grall <julien.grall@linaro.org>> --- > xen/arch/arm/setup.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c > index 4b31623..0ad5668 100644 > --- a/xen/arch/arm/setup.c > +++ b/xen/arch/arm/setup.c > @@ -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", >-- Julien Grall
Pranavkumar Sawargaonkar
2013-Sep-20 13:28 UTC
Re: [PATCH 1/4] xen: arm64: Add Basic Platform support for APM X-Gene Storm.
HI Julien, On Fri, Sep 20, 2013 at 5:39 PM, Julien Grall <julien.grall@linaro.org> wrote:> On 09/20/2013 10:52 AM, Pranavkumar Sawargaonkar wrote: >> 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.> > 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 ??> > Also, can you divide this patch in 2 part: > - Early printk support; > - Initial platform support. >Sure i will do it.>> Initial platform stubs for APM X-Gene. >> >> Signed-off-by: Anup Patel <anup.patel@linaro.org> >> Signed-off-by: Pranavkumar Sawargaonkar <pranavkumar@linaro.org> >> --- >> 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 >> >> diff --git a/xen/arch/arm/Rules.mk b/xen/arch/arm/Rules.mk >> index bd79b26..b36120e 100644 >> --- a/xen/arch/arm/Rules.mk >> +++ b/xen/arch/arm/Rules.mk >> @@ -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 >> diff --git a/xen/arch/arm/arm64/debug-xgene-storm.inc b/xen/arch/arm/arm64/debug-xgene-storm.inc >> new file mode 100644 >> index 0000000..ebbb8d2 >> --- /dev/null >> +++ b/xen/arch/arm/arm64/debug-xgene-storm.inc >> @@ -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. >> + * >> + * 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.Sure, i will do.> >> + >> +/* 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. > > >> + >> +/* 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: >> + */ >> diff --git a/xen/arch/arm/platforms/Makefile b/xen/arch/arm/platforms/Makefile >> index 4aa82e8..8a6709f 100644 >> --- a/xen/arch/arm/platforms/Makefile >> +++ b/xen/arch/arm/platforms/Makefile >> @@ -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?But then arm32 boards should be only compiled for arm32 ?> >> diff --git a/xen/arch/arm/platforms/xgene-storm.c b/xen/arch/arm/platforms/xgene-storm.c >> new file mode 100644 >> index 0000000..8e2b3b6 >> --- /dev/null >> +++ b/xen/arch/arm/platforms/xgene-storm.c >> @@ -0,0 +1,57 @@ >> +/* >> + * xen/arch/arm/platforms/xgene-storm.c >> + * >> + * Applied Micro''s X-Gene specific settings >> + * >> + * Pranavkumar Sawargaonkar <psawargaonkar@apm.com> >> + * Anup Patel <apatel@apm.com> >> + * 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> >> +#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. > >> +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: >> + */ >> > > > -- > Julien Grall > > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xen.org > http://lists.xen.org/xen-develThanks, Pranav
Ian Campbell
2013-Sep-20 13:38 UTC
Re: [PATCH 1/4] xen: arm64: Add Basic Platform support for APM X-Gene Storm.
On Fri, 2013-09-20 at 18:58 +0530, Pranavkumar Sawargaonkar wrote:> HI Julien, > > On Fri, Sep 20, 2013 at 5:39 PM, Julien Grall <julien.grall@linaro.org> wrote: > > On 09/20/2013 10:52 AM, Pranavkumar Sawargaonkar wrote: > >> 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.
Ian Campbell
2013-Sep-20 13:40 UTC
Re: [PATCH 3/4] xen: drivers: char: Add Device Tree Based NS16550 UART driver.
On Fri, 2013-09-20 at 15:22 +0530, Pranavkumar Sawargaonkar wrote:> 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?> > Signed-off-by: Anup Patel <anup.patel@linaro.org> > Signed-off-by: Pranavkumar Sawargaonkar <pranavkumar@linaro.org> > --- > 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 > > diff --git a/xen/drivers/char/Makefile b/xen/drivers/char/Makefile > index 911b788..7c22a1b 100644 > --- a/xen/drivers/char/Makefile > +++ b/xen/drivers/char/Makefile > @@ -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 > diff --git a/xen/drivers/char/ns16550-dt.c b/xen/drivers/char/ns16550-dt.c > new file mode 100644 > index 0000000..74d2b57 > --- /dev/null > +++ b/xen/drivers/char/ns16550-dt.c > @@ -0,0 +1,302 @@ > +/* > + * xen/drivers/char/ns16550.c > + * > + * Driver for ns16550 UART based on DT bindigs. > + * > + * Pranavkumar Sawargaonkar <psawargaonkar@apm.com> > + * Anup Patel <apatel@apm.com> > + * 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: > + */
Julien Grall
2013-Sep-20 13:41 UTC
Re: [PATCH 1/4] xen: arm64: Add Basic Platform support for APM X-Gene Storm.
On 09/20/2013 02:28 PM, Pranavkumar Sawargaonkar wrote:> HI Julien, > > On Fri, Sep 20, 2013 at 5:39 PM, Julien Grall <julien.grall@linaro.org> wrote: >> On 09/20/2013 10:52 AM, Pranavkumar Sawargaonkar wrote: >>> 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 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.>> 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. -- Julien Grall
Pranavkumar Sawargaonkar
2013-Sep-20 13:55 UTC
Re: [PATCH 3/4] xen: drivers: char: Add Device Tree Based NS16550 UART driver.
Hi Ian, On Fri, Sep 20, 2013 at 7:10 PM, Ian Campbell <ian.campbell@citrix.com> wrote:> On Fri, 2013-09-20 at 15:22 +0530, Pranavkumar Sawargaonkar wrote: >> 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 ?> >> >> Signed-off-by: Anup Patel <anup.patel@linaro.org> >> Signed-off-by: Pranavkumar Sawargaonkar <pranavkumar@linaro.org> >> --- >> 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 >> >> diff --git a/xen/drivers/char/Makefile b/xen/drivers/char/Makefile >> index 911b788..7c22a1b 100644 >> --- a/xen/drivers/char/Makefile >> +++ b/xen/drivers/char/Makefile >> @@ -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 >> diff --git a/xen/drivers/char/ns16550-dt.c b/xen/drivers/char/ns16550-dt.c >> new file mode 100644 >> index 0000000..74d2b57 >> --- /dev/null >> +++ b/xen/drivers/char/ns16550-dt.c >> @@ -0,0 +1,302 @@ >> +/* >> + * xen/drivers/char/ns16550.c >> + * >> + * Driver for ns16550 UART based on DT bindigs. >> + * >> + * Pranavkumar Sawargaonkar <psawargaonkar@apm.com> >> + * Anup Patel <apatel@apm.com> >> + * 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: >> + */ > > > > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xen.org > http://lists.xen.org/xen-develThanks, Pranav
Pranavkumar Sawargaonkar
2013-Sep-20 13:59 UTC
Re: [PATCH 1/4] xen: arm64: Add Basic Platform support for APM X-Gene Storm.
Hi Ian, On Fri, Sep 20, 2013 at 7:08 PM, Ian Campbell <ian.campbell@citrix.com> wrote:> On Fri, 2013-09-20 at 18:58 +0530, Pranavkumar Sawargaonkar wrote: >> HI Julien, >> >> On Fri, Sep 20, 2013 at 5:39 PM, Julien Grall <julien.grall@linaro.org> wrote: >> > On 09/20/2013 10:52 AM, Pranavkumar Sawargaonkar wrote: >> >> 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.No because that is arm32 assembly. Probably i will add/port similar debug-8250.inc for arm64.> >Thanks, Pranav
Ian Campbell
2013-Sep-20 14:06 UTC
Re: [PATCH 1/4] xen: arm64: Add Basic Platform support for APM X-Gene Storm.
On Fri, 2013-09-20 at 19:29 +0530, Pranavkumar Sawargaonkar wrote:> Hi Ian, > > On Fri, Sep 20, 2013 at 7:08 PM, Ian Campbell <ian.campbell@citrix.com> wrote: > > On Fri, 2013-09-20 at 18:58 +0530, Pranavkumar Sawargaonkar wrote: > >> HI Julien, > >> > >> On Fri, Sep 20, 2013 at 5:39 PM, Julien Grall <julien.grall@linaro.org> wrote: > >> > On 09/20/2013 10:52 AM, Pranavkumar Sawargaonkar wrote: > >> >> 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. > > No because that is arm32 assembly.Doh, Obviously! Sorry, need to have breakfast/coffee before commenting next time!> 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.
Ian Campbell
2013-Sep-20 14:08 UTC
Re: [PATCH 3/4] xen: drivers: char: Add Device Tree Based NS16550 UART driver.
On Fri, 2013-09-20 at 19:25 +0530, Pranavkumar Sawargaonkar wrote:> Hi Ian, > > On Fri, Sep 20, 2013 at 7:10 PM, Ian Campbell <ian.campbell@citrix.com> wrote: > > On Fri, 2013-09-20 at 15:22 +0530, Pranavkumar Sawargaonkar wrote: > >> 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 ?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/