Date: Wed, 6 Aug 2014 01:35:07 GMT From: astarasikov@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271975 - in soc2014/astarasikov/head/sys: arm/goldfish dev/uart Message-ID: <201408060135.s761Z7hV015113@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: astarasikov Date: Wed Aug 6 01:35:07 2014 New Revision: 271975 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271975 Log: [goldfish] rework UART to print very early dmesg Modified: soc2014/astarasikov/head/sys/arm/goldfish/goldfish_uart.c soc2014/astarasikov/head/sys/dev/uart/uart.h soc2014/astarasikov/head/sys/dev/uart/uart_bus_fdt.c soc2014/astarasikov/head/sys/dev/uart/uart_tty.c Modified: soc2014/astarasikov/head/sys/arm/goldfish/goldfish_uart.c ============================================================================== --- soc2014/astarasikov/head/sys/arm/goldfish/goldfish_uart.c Wed Aug 6 01:34:05 2014 (r271974) +++ soc2014/astarasikov/head/sys/arm/goldfish/goldfish_uart.c Wed Aug 6 01:35:07 2014 (r271975) @@ -27,24 +27,21 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); -#include <sys/types.h> #include <sys/param.h> #include <sys/systm.h> #include <sys/bus.h> +#include <sys/conf.h> #include <sys/cons.h> -#include <sys/consio.h> -#include <sys/kernel.h> -#include <sys/module.h> +#include <sys/tty.h> #include <sys/rman.h> - #include <machine/bus.h> #include <machine/intr.h> -#include <dev/fdt/fdt_common.h> -#include <dev/ofw/openfirm.h> +#include <dev/uart/uart.h> +#include <dev/uart/uart_cpu.h> +#include <dev/uart/uart_bus.h> -#include <dev/ofw/ofw_bus.h> -#include <dev/ofw/ofw_bus_subr.h> +#include "uart_if.h" enum goldfish_guart_regs { TTY_PUT_CHAR = 0x00, @@ -61,147 +58,183 @@ TTY_CMD_READ_BUFFER = 3, }; -struct goldfish_guart_softc { - struct resource * li_res; - bus_space_tag_t li_bst; - bus_space_handle_t li_bsh; +/* + * Low-level UART interface. + */ +static int goldfish_probe(struct uart_bas *bas); +static void goldfish_init(struct uart_bas *bas, int, int, int, int); +static void goldfish_term(struct uart_bas *bas); +static void goldfish_putc(struct uart_bas *bas, int); +static int goldfish_rxready(struct uart_bas *bas); +static int goldfish_getc(struct uart_bas *bas, struct mtx *mtx); + +extern SLIST_HEAD(uart_devinfo_list, uart_devinfo) uart_sysdevs; + +struct uart_ops uart_goldfish_ops = { + .probe = goldfish_probe, + .init = goldfish_init, + .term = goldfish_term, + .putc = goldfish_putc, + .rxready = goldfish_rxready, + .getc = goldfish_getc, }; -static int goldfish_guart_probe(device_t); -static int goldfish_guart_attach(device_t); +static int +goldfish_probe(struct uart_bas *bas) +{ + return (0); +} + +static void +goldfish_init(struct uart_bas *bas, int baudrate, int databits, int stopbits, + int parity) +{ +} -static struct goldfish_guart_softc *uart_softc = NULL; +static void +goldfish_term(struct uart_bas *bas) +{ +} -#define uart_read_4(reg) \ - bus_space_read_4(uart_softc->li_bst, uart_softc->li_bsh, reg) -#define uart_write_4(reg, val) \ - bus_space_write_4(uart_softc->li_bst, uart_softc->li_bsh, reg, val) +static void +goldfish_putc(struct uart_bas *bas, int c) +{ + uart_setreg(bas, TTY_PUT_CHAR, c); +} static int -goldfish_guart_probe(device_t dev) +goldfish_rxready(struct uart_bas *bas) { - if (!ofw_bus_is_compatible(dev, "arm,goldfish-uart")) - return (ENXIO); - - device_set_desc(dev, "Goldfish (Android Emulator) UART"); - return (BUS_PROBE_DEFAULT); + return 0; + //return (!!uart_getreg(bas, TTY_BYTES_READY)); } static int -goldfish_guart_attach(device_t dev) +goldfish_getc(struct uart_bas *bas, struct mtx *mtx) { - struct goldfish_guart_softc *sc = device_get_softc(dev); - int rid = 0; + int c = 0; + //uart_setreg(bas, TTY_DATA_PTR, (int)&c); + //uart_setreg(bas, TTY_DATA_LEN, 1); + //uart_setreg(bas, TTY_CMD, TTY_CMD_READ_BUFFER); + return c; +} + +static int goldfish_bus_probe(struct uart_softc *sc); +static int goldfish_bus_attach(struct uart_softc *sc); +static int goldfish_bus_flush(struct uart_softc *, int); +static int goldfish_bus_getsig(struct uart_softc *); +static int goldfish_bus_ioctl(struct uart_softc *, int, intptr_t); +static int goldfish_bus_ipend(struct uart_softc *); +static int goldfish_bus_param(struct uart_softc *, int, int, int, int); +static int goldfish_bus_receive(struct uart_softc *); +static int goldfish_bus_setsig(struct uart_softc *, int); +static int goldfish_bus_transmit(struct uart_softc *); + +static kobj_method_t goldfish_methods[] = { + KOBJMETHOD(uart_probe, goldfish_bus_probe), + KOBJMETHOD(uart_attach, goldfish_bus_attach), + KOBJMETHOD(uart_flush, goldfish_bus_flush), + KOBJMETHOD(uart_getsig, goldfish_bus_getsig), + KOBJMETHOD(uart_ioctl, goldfish_bus_ioctl), + KOBJMETHOD(uart_ipend, goldfish_bus_ipend), + KOBJMETHOD(uart_param, goldfish_bus_param), + KOBJMETHOD(uart_receive, goldfish_bus_receive), + KOBJMETHOD(uart_setsig, goldfish_bus_setsig), + KOBJMETHOD(uart_transmit, goldfish_bus_transmit), - if (uart_softc) - return (ENXIO); + {0, 0 } +}; - sc->li_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); - if (!sc->li_res) - return (ENXIO); +int +goldfish_bus_probe(struct uart_softc *sc) +{ - sc->li_bst = rman_get_bustag(sc->li_res); - sc->li_bsh = rman_get_bushandle(sc->li_res); - uart_softc = sc; + sc->sc_txfifosz = 16; + sc->sc_rxfifosz = 16; - uart_write_4(0, 'h'); - uart_write_4(0, 'e'); - uart_write_4(0, 'l'); - uart_write_4(0, 'l'); - uart_write_4(0, 'o'); - uart_write_4(0, '\n'); return (0); } -static device_method_t goldfish_guart_methods[] = { - DEVMETHOD(device_probe, goldfish_guart_probe), - DEVMETHOD(device_attach, goldfish_guart_attach), - { 0, 0 } -}; - -static driver_t goldfish_guart_driver = { - "guart", - goldfish_guart_methods, - sizeof(struct goldfish_guart_softc), -}; - -static devclass_t goldfish_guart_devclass; +static int +goldfish_bus_attach(struct uart_softc *sc) +{ -//DRIVER_MODULE(guart, simplebus, goldfish_guart_driver, goldfish_guart_devclass, 0, 0); -EARLY_DRIVER_MODULE(guart, fdtbus, goldfish_guart_driver, - goldfish_guart_devclass, 0, 0, BUS_PASS_BUS); -EARLY_DRIVER_MODULE(guart, simplebus, goldfish_guart_driver, - goldfish_guart_devclass, 0, 0, BUS_PASS_BUS); + sc->sc_hwiflow = 0; + sc->sc_hwoflow = 0; -static void -uart_setreg(uint32_t reg, uint32_t val) -{ - if (uart_softc) - uart_write_4(reg, val); + return (0); } -static void -ub_putc(unsigned char c) +static int +goldfish_bus_transmit(struct uart_softc *sc) { - if (c == '\n') - ub_putc('\r'); + int i; - uart_setreg(TTY_PUT_CHAR, c); -} + //uart_lock(sc->sc_hwmtx); -static cn_probe_t uart_cnprobe; -static cn_init_t uart_cninit; -static cn_term_t uart_cnterm; -static cn_getc_t uart_cngetc; -static cn_putc_t uart_cnputc; -static cn_grab_t uart_cngrab; -static cn_ungrab_t uart_cnungrab; + for (i = 0; i < sc->sc_txdatasz; i++) { + goldfish_putc(&sc->sc_bas, sc->sc_txbuf[i]); + //uart_barrier(&sc->sc_bas); + } + + //sc->sc_txbusy = 1; + //uart_unlock(sc->sc_hwmtx); + + return (0); +} -void -uart_cnputc(struct consdev *cp, int c) +static int +goldfish_bus_setsig(struct uart_softc *sc, int sig) { - ub_putc(c); + + return (0); } -int -uart_cngetc(struct consdev * cp) +static int +goldfish_bus_receive(struct uart_softc *sc) { - uint32_t bytes_in_buf = uart_read_4(TTY_BYTES_READY); - if (bytes_in_buf) { - char c = 0; - uart_setreg(TTY_DATA_PTR, (uint32_t)&c); - uart_setreg(TTY_DATA_LEN, 1); - uart_setreg(TTY_CMD, TTY_CMD_READ_BUFFER); - return c; - } - return 0; + return (0); } -static void -uart_cngrab(struct consdev *cp) +static int +goldfish_bus_param(struct uart_softc *sc, int baudrate, int databits, + int stopbits, int parity) { + return (0); } -static void -uart_cnungrab(struct consdev *cp) +static int +goldfish_bus_ipend(struct uart_softc *sc) { + return (0); } -static void -uart_cnprobe(struct consdev *cp) +static int +goldfish_bus_flush(struct uart_softc *sc, int what) { - sprintf(cp->cn_name, "uart_goldfish"); - cp->cn_pri = CN_NORMAL; + + return (0); } -static void -uart_cninit(struct consdev *cp) +static int +goldfish_bus_getsig(struct uart_softc *sc) { + + return (0); } -static void -uart_cnterm(struct consdev * cp) +static int +goldfish_bus_ioctl(struct uart_softc *sc, int request, intptr_t data) { + + return (EINVAL); } -CONSOLE_DRIVER(uart); +struct uart_class uart_goldfish_class = { + "goldfish class", + goldfish_methods, + 1, + .uc_ops = &uart_goldfish_ops, + .uc_range = 8, + .uc_rclk = 0, +}; Modified: soc2014/astarasikov/head/sys/dev/uart/uart.h ============================================================================== --- soc2014/astarasikov/head/sys/dev/uart/uart.h Wed Aug 6 01:34:05 2014 (r271974) +++ soc2014/astarasikov/head/sys/dev/uart/uart.h Wed Aug 6 01:35:07 2014 (r271975) @@ -77,6 +77,7 @@ extern struct uart_class uart_ti8250_class __attribute__((weak)); extern struct uart_class uart_vybrid_class __attribute__((weak)); extern struct uart_class at91_usart_class __attribute__((weak)); +extern struct uart_class uart_goldfish_class __attribute__((weak)); #ifdef FDT struct ofw_compat_data; Modified: soc2014/astarasikov/head/sys/dev/uart/uart_bus_fdt.c ============================================================================== --- soc2014/astarasikov/head/sys/dev/uart/uart_bus_fdt.c Wed Aug 6 01:34:05 2014 (r271974) +++ soc2014/astarasikov/head/sys/dev/uart/uart_bus_fdt.c Wed Aug 6 01:35:07 2014 (r271975) @@ -71,6 +71,7 @@ */ static struct ofw_compat_data compat_data[] = { {"arm,pl011", (uintptr_t)&uart_pl011_class}, + {"arm,goldfish-uart", (uintptr_t)&uart_goldfish_class}, {"atmel,at91rm9200-usart",(uintptr_t)&at91_usart_class}, {"atmel,at91sam9260-usart",(uintptr_t)&at91_usart_class}, {"cadence,uart", (uintptr_t)&uart_cdnc_class}, Modified: soc2014/astarasikov/head/sys/dev/uart/uart_tty.c ============================================================================== --- soc2014/astarasikov/head/sys/dev/uart/uart_tty.c Wed Aug 6 01:34:05 2014 (r271974) +++ soc2014/astarasikov/head/sys/dev/uart/uart_tty.c Wed Aug 6 01:35:07 2014 (r271975) @@ -133,7 +133,9 @@ static int uart_cngetc(struct consdev *cp) { - + if (!cp || !cp->cn_arg) { + return 0; + } return (uart_poll(cp->cn_arg)); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201408060135.s761Z7hV015113>