Module Name: src Committed By: jmcneill Date: Sat Feb 7 17:20:17 UTC 2015
Added Files: src/sys/arch/arm/amlogic: amlogic_board.c amlogic_com.c amlogic_comreg.h amlogic_intr.h amlogic_io.c amlogic_reg.h amlogic_space.c amlogic_var.h files.amlogic src/sys/arch/evbarm/amlogic: amlogic_machdep.c amlogic_start.S genassym.cf platform.h src/sys/arch/evbarm/conf: ODROID-C1 files.amlogic mk.amlogic std.amlogic Log Message: Work-in-progress Odroid-C1 support. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/sys/arch/arm/amlogic/amlogic_board.c \ src/sys/arch/arm/amlogic/amlogic_com.c \ src/sys/arch/arm/amlogic/amlogic_comreg.h \ src/sys/arch/arm/amlogic/amlogic_intr.h \ src/sys/arch/arm/amlogic/amlogic_io.c \ src/sys/arch/arm/amlogic/amlogic_reg.h \ src/sys/arch/arm/amlogic/amlogic_space.c \ src/sys/arch/arm/amlogic/amlogic_var.h \ src/sys/arch/arm/amlogic/files.amlogic cvs rdiff -u -r0 -r1.1 src/sys/arch/evbarm/amlogic/amlogic_machdep.c \ src/sys/arch/evbarm/amlogic/amlogic_start.S \ src/sys/arch/evbarm/amlogic/genassym.cf \ src/sys/arch/evbarm/amlogic/platform.h cvs rdiff -u -r0 -r1.1 src/sys/arch/evbarm/conf/ODROID-C1 \ src/sys/arch/evbarm/conf/files.amlogic \ src/sys/arch/evbarm/conf/mk.amlogic src/sys/arch/evbarm/conf/std.amlogic Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Added files: Index: src/sys/arch/arm/amlogic/amlogic_board.c diff -u /dev/null src/sys/arch/arm/amlogic/amlogic_board.c:1.1 --- /dev/null Sat Feb 7 17:20:17 2015 +++ src/sys/arch/arm/amlogic/amlogic_board.c Sat Feb 7 17:20:17 2015 @@ -0,0 +1,65 @@ +/* $NetBSD: amlogic_board.c,v 1.1 2015/02/07 17:20:17 jmcneill Exp $ */ + +/*- + * Copyright (c) 2015 Jared D. McNeill <jmcne...@invisible.ca> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "opt_amlogic.h" + +#include <sys/cdefs.h> +__KERNEL_RCSID(0, "$NetBSD: amlogic_board.c,v 1.1 2015/02/07 17:20:17 jmcneill Exp $"); + +#define _ARM32_BUS_DMA_PRIVATE +#include <sys/param.h> +#include <sys/bus.h> +#include <sys/cpu.h> +#include <sys/device.h> + +#include <uvm/uvm_extern.h> + +#include <arm/bootconfig.h> +#include <arm/cpufunc.h> + +#include <arm/amlogic/amlogic_reg.h> +#include <arm/amlogic/amlogic_var.h> + +bus_space_handle_t amlogic_core_bsh; + +struct arm32_bus_dma_tag amlogic_dma_tag = { + _BUS_DMAMAP_FUNCS, + _BUS_DMAMEM_FUNCS, + _BUS_DMATAG_FUNCS, +}; + +void +amlogic_bootstrap(void) +{ + int error; + + error = bus_space_map(&amlogic_bs_tag, AMLOGIC_CORE_BASE, + AMLOGIC_CORE_SIZE, 0, &amlogic_core_bsh); + if (error) + panic("%s: failed to map CORE registers: %d", __func__, error); +} Index: src/sys/arch/arm/amlogic/amlogic_com.c diff -u /dev/null src/sys/arch/arm/amlogic/amlogic_com.c:1.1 --- /dev/null Sat Feb 7 17:20:17 2015 +++ src/sys/arch/arm/amlogic/amlogic_com.c Sat Feb 7 17:20:17 2015 @@ -0,0 +1,121 @@ +/* $NetBSD: amlogic_com.c,v 1.1 2015/02/07 17:20:17 jmcneill Exp $ */ + +/*- + * Copyright (c) 2013 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas of 3am Software Foundry. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "locators.h" + +#include <sys/cdefs.h> + +__KERNEL_RCSID(1, "$NetBSD: amlogic_com.c,v 1.1 2015/02/07 17:20:17 jmcneill Exp $"); + +#include <sys/param.h> +#include <sys/bus.h> +#include <sys/device.h> +#include <sys/intr.h> +#include <sys/systm.h> +#include <sys/time.h> +#include <sys/termios.h> + +#include <arm/amlogic/amlogic_reg.h> +#include <arm/amlogic/amlogic_var.h> + +#include <dev/ic/comvar.h> + +static int amlogic_com_match(device_t, cfdata_t, void *); +static void amlogic_com_attach(device_t, device_t, void *); + +struct amlogic_com_softc { + struct com_softc asc_sc; + void *asc_ih; +}; + +CFATTACH_DECL_NEW(amlogic_com, sizeof(struct amlogic_com_softc), + amlogic_com_match, amlogic_com_attach, NULL, NULL); + +static int amlogic_com_ports; + +static int +amlogic_com_match(device_t parent, cfdata_t cf, void *aux) +{ + struct amlogicio_attach_args * const aio = aux; + const struct amlogic_locators * const loc = &aio->aio_loc; + bus_space_tag_t iot = aio->aio_core_a4x_bst; + bus_space_handle_t bsh; + + KASSERT(!strcmp(cf->cf_name, loc->loc_name)); + KASSERT((amlogic_com_ports & __BIT(loc->loc_port)) == 0); + KASSERT(cf->cf_loc[AMLOGICIOCF_PORT] == AMLOGICIOCF_PORT_DEFAULT + || cf->cf_loc[AMLOGICIOCF_PORT] == loc->loc_port); + + if (com_is_console(iot, AMLOGIC_CORE_BASE + loc->loc_offset, NULL)) + return 1; + + bus_space_subregion(iot, aio->aio_bsh, + loc->loc_offset, loc->loc_size, &bsh); + + const int rv = comprobe1(iot, bsh); + + return rv; +} + +static void +amlogic_com_attach(device_t parent, device_t self, void *aux) +{ + struct amlogic_com_softc * const asc = device_private(self); + struct com_softc * const sc = &asc->asc_sc; + struct amlogicio_attach_args * const aio = aux; + const struct amlogic_locators * const loc = &aio->aio_loc; + bus_space_tag_t iot = aio->aio_core_a4x_bst; + const bus_addr_t iobase = AMLOGIC_CORE_BASE + loc->loc_offset; + bus_space_handle_t ioh; + + amlogic_com_ports |= __BIT(loc->loc_port); + + sc->sc_dev = self; + sc->sc_frequency = AMLOGIC_UART_FREQ; + sc->sc_type = COM_TYPE_NORMAL; + + if (com_is_console(iot, iobase, &ioh) == 0 + && bus_space_subregion(iot, aio->aio_bsh, + loc->loc_offset / 4, loc->loc_size, &ioh)) { + panic(": can't map registers"); + } + COM_INIT_REGS(sc->sc_regs, iot, ioh, iobase); + + com_attach_subr(sc); + aprint_naive("\n"); + + KASSERT(loc->loc_intr != AMLOGICIO_INTR_DEFAULT); + asc->asc_ih = intr_establish(loc->loc_intr, IPL_SERIAL, + IST_EDGE | IST_MPSAFE, comintr, sc); + if (asc->asc_ih == NULL) + panic("%s: failed to establish interrupt %d", + device_xname(self), loc->loc_intr); +} Index: src/sys/arch/arm/amlogic/amlogic_comreg.h diff -u /dev/null src/sys/arch/arm/amlogic/amlogic_comreg.h:1.1 --- /dev/null Sat Feb 7 17:20:17 2015 +++ src/sys/arch/arm/amlogic/amlogic_comreg.h Sat Feb 7 17:20:17 2015 @@ -0,0 +1,42 @@ +/* $NetBSD: amlogic_comreg.h,v 1.1 2015/02/07 17:20:17 jmcneill Exp $ */ + +/*- + * Copyright (c) 2015 Jared D. McNeill <jmcne...@invisible.ca> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _ARM_AMLOGIC_COMREG_H +#define _ARM_AMLOGIC_COMREG_H + +#define UART_WFIFO_REG 0x00 +#define UART_RFIFO_REG 0x04 +#define UART_CONTROL_REG 0x08 +#define UART_STATUS_REG 0x0c +#define UART_MISC_REG 0x10 +#define UART_REG5_REG 0x14 + +#define UART_STATUS_TX_BUSY __BIT(25) +#define UART_STATUS_TX_EMPTY __BIT(22) + +#endif /* _ARM_AMLOGIC_COMREG_H */ Index: src/sys/arch/arm/amlogic/amlogic_intr.h diff -u /dev/null src/sys/arch/arm/amlogic/amlogic_intr.h:1.1 --- /dev/null Sat Feb 7 17:20:17 2015 +++ src/sys/arch/arm/amlogic/amlogic_intr.h Sat Feb 7 17:20:17 2015 @@ -0,0 +1,41 @@ +/* $NetBSD: amlogic_intr.h,v 1.1 2015/02/07 17:20:17 jmcneill Exp $ */ + +/*- + * Copyright (c) 2015 Jared D. McNeill <jmcne...@invisible.ca> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _ARM_AMLOGIC_INTR_H +#define _ARM_AMLOGIC_INTR_H + +#define PIC_MAXSOURCES 224 +#define PIC_MAXMAXSOURCES 256 + +#include <arm/cortex/gic_intr.h> +#include <arm/cortex/a9tmr_intr.h> + +#define AMLOGIC_INTR_UART2AO 70 +#define AMLOGIC_INTR_UART0AO 122 + +#endif /* _ARM_AMLOGIC_INTR_H */ Index: src/sys/arch/arm/amlogic/amlogic_io.c diff -u /dev/null src/sys/arch/arm/amlogic/amlogic_io.c:1.1 --- /dev/null Sat Feb 7 17:20:17 2015 +++ src/sys/arch/arm/amlogic/amlogic_io.c Sat Feb 7 17:20:17 2015 @@ -0,0 +1,121 @@ +/* $NetBSD: amlogic_io.c,v 1.1 2015/02/07 17:20:17 jmcneill Exp $ */ + +/*- + * Copyright (c) 2015 Jared D. McNeill <jmcne...@invisible.ca> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "opt_amlogic.h" + +#include <sys/cdefs.h> +__KERNEL_RCSID(0, "$NetBSD: amlogic_io.c,v 1.1 2015/02/07 17:20:17 jmcneill Exp $"); + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/device.h> + +#include <machine/cpu.h> +#include <sys/bus.h> + +#include <arm/mainbus/mainbus.h> +#include <arm/amlogic/amlogic_reg.h> +#include <arm/amlogic/amlogic_var.h> + +#include "locators.h" + +static int amlogicio_match(device_t, cfdata_t, void *); +static void amlogicio_attach(device_t, device_t, void *); + +CFATTACH_DECL_NEW(amlogic_io, 0, + amlogicio_match, amlogicio_attach, NULL, NULL); + +static int amlogicio_print(void *, const char *); +static int amlogicio_find(device_t, cfdata_t, const int *, void *); + +static bool amlogicio_found = false; + +static const struct amlogic_locators amlogic_locators[] = { + { "com", AMLOGIC_UART0AO_OFFSET, AMLOGIC_UART_SIZE, 0, AMLOGIC_INTR_UART0AO }, + { "com", AMLOGIC_UART2AO_OFFSET, AMLOGIC_UART_SIZE, 2, AMLOGIC_INTR_UART2AO }, +}; + +int +amlogicio_match(device_t parent, cfdata_t cf, void *aux) +{ + if (amlogicio_found) + return 0; + return 1; +} + +void +amlogicio_attach(device_t parent, device_t self, void *aux) +{ + amlogicio_found = true; + + aprint_naive("\n"); + aprint_normal("\n"); + + const struct amlogic_locators * const eloc = + amlogic_locators + __arraycount(amlogic_locators); + for (const struct amlogic_locators *loc = amlogic_locators; + loc < eloc; + loc++) { + struct amlogicio_attach_args aio = { + .aio_loc = *loc, + .aio_core_bst = &amlogic_bs_tag, + .aio_core_a4x_bst = &amlogic_a4x_bs_tag, + .aio_bsh = amlogic_core_bsh, + .aio_dmat = &amlogic_dma_tag, + }; + cfdata_t cf = config_search_ia(amlogicio_find, self, + "amlogicio", &aio); + if (cf != NULL) + config_attach(self, cf, &aio, amlogicio_print); + } +} + +int +amlogicio_print(void *aux, const char *pnp) +{ + const struct amlogicio_attach_args * const aio = aux; + + if (aio->aio_loc.loc_port != AMLOGICIOCF_PORT_DEFAULT) + aprint_normal(" port %d", aio->aio_loc.loc_port); + + return UNCONF; +} + +static int +amlogicio_find(device_t parent, cfdata_t cf, const int *ldesc, void *aux) +{ + const struct amlogicio_attach_args * const aio = aux; + const struct amlogic_locators * const loc = &aio->aio_loc; + const int port = cf->cf_loc[AMLOGICIOCF_PORT]; + + if (strcmp(cf->cf_name, loc->loc_name) + || (port != AMLOGICIOCF_PORT_DEFAULT && port != loc->loc_port)) + return 0; + + return config_match(parent, cf, aux); +} Index: src/sys/arch/arm/amlogic/amlogic_reg.h diff -u /dev/null src/sys/arch/arm/amlogic/amlogic_reg.h:1.1 --- /dev/null Sat Feb 7 17:20:17 2015 +++ src/sys/arch/arm/amlogic/amlogic_reg.h Sat Feb 7 17:20:17 2015 @@ -0,0 +1,48 @@ +/* $NetBSD: amlogic_reg.h,v 1.1 2015/02/07 17:20:17 jmcneill Exp $ */ + +/*- + * Copyright (c) 2015 Jared D. McNeill <jmcne...@invisible.ca> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _ARM_AMLOGIC_REG_H +#define _ARM_AMLOGIC_REG_H + +#define CONSADDR_VA (CONSADDR - AMLOGIC_CORE_BASE + AMLOGIC_CORE_VBASE) + +#define AMLOGIC_CORE_BASE 0xc0000000 +#define AMLOGIC_CORE_SIZE 0x10200000 +#define AMLOGIC_CORE_VBASE 0xe0000000 + +#define AMLOGIC_UART0_OFFSET 0x01102130 +#define AMLOGIC_UART1_OFFSET 0x01102137 +#define AMLOGIC_UART2_OFFSET 0x011021c0 +#define AMLOGIC_UART0AO_OFFSET 0x081004c0 +#define AMLOGIC_UART2AO_OFFSET 0x081004e0 +#define AMLOGIC_UART_SIZE 0x20 +#define AMLOGIC_UART_FREQ 24000000 + +#define AMLOGIC_PL310_OFFSET 0x04200000 + +#endif /* _ARM_AMLOGIC_REG_H */ Index: src/sys/arch/arm/amlogic/amlogic_space.c diff -u /dev/null src/sys/arch/arm/amlogic/amlogic_space.c:1.1 --- /dev/null Sat Feb 7 17:20:17 2015 +++ src/sys/arch/arm/amlogic/amlogic_space.c Sat Feb 7 17:20:17 2015 @@ -0,0 +1,425 @@ +/* $NetBSD: amlogic_space.c,v 1.1 2015/02/07 17:20:17 jmcneill Exp $ */ + +/*- + * Copyright (c) 2012 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Nick Hudson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + + +#include <sys/cdefs.h> +__KERNEL_RCSID(0, "$NetBSD: amlogic_space.c,v 1.1 2015/02/07 17:20:17 jmcneill Exp $"); + +#include <sys/param.h> +#include <sys/systm.h> + +#include <uvm/uvm_extern.h> + +#include <sys/bus.h> + +/* Prototypes for all the bus_space structure functions */ +bs_protos(amlogic); +bs_protos(amlogic_a4x); +bs_protos(a4x); +bs_protos(bs_notimpl); +bs_protos(generic); +bs_protos(generic_armv4); + +#if __ARMEB__ +#define NSWAP(n) n ## _swap +#else +#define NSWAP(n) n +#endif + +struct bus_space amlogic_bs_tag = { + /* cookie */ + (void *) 0, + + /* mapping/unmapping */ + amlogic_bs_map, + amlogic_bs_unmap, + amlogic_bs_subregion, + + /* allocation/deallocation */ + amlogic_bs_alloc, /* not implemented */ + amlogic_bs_free, /* not implemented */ + + /* get kernel virtual address */ + amlogic_bs_vaddr, + + /* mmap */ + amlogic_bs_mmap, + + /* barrier */ + amlogic_bs_barrier, + + /* read (single) */ + generic_bs_r_1, + NSWAP(generic_armv4_bs_r_2), + NSWAP(generic_bs_r_4), + bs_notimpl_bs_r_8, + + /* read multiple */ + generic_bs_rm_1, + NSWAP(generic_armv4_bs_rm_2), + NSWAP(generic_bs_rm_4), + bs_notimpl_bs_rm_8, + + /* read region */ + generic_bs_rr_1, + NSWAP(generic_armv4_bs_rr_2), + NSWAP(generic_bs_rr_4), + bs_notimpl_bs_rr_8, + + /* write (single) */ + generic_bs_w_1, + NSWAP(generic_armv4_bs_w_2), + NSWAP(generic_bs_w_4), + bs_notimpl_bs_w_8, + + /* write multiple */ + generic_bs_wm_1, + NSWAP(generic_armv4_bs_wm_2), + NSWAP(generic_bs_wm_4), + bs_notimpl_bs_wm_8, + + /* write region */ + generic_bs_wr_1, + NSWAP(generic_armv4_bs_wr_2), + NSWAP(generic_bs_wr_4), + bs_notimpl_bs_wr_8, + + /* set multiple */ + bs_notimpl_bs_sm_1, + bs_notimpl_bs_sm_2, + bs_notimpl_bs_sm_4, + bs_notimpl_bs_sm_8, + + /* set region */ + generic_bs_sr_1, + NSWAP(generic_armv4_bs_sr_2), + bs_notimpl_bs_sr_4, + bs_notimpl_bs_sr_8, + + /* copy */ + bs_notimpl_bs_c_1, + generic_armv4_bs_c_2, + bs_notimpl_bs_c_4, + bs_notimpl_bs_c_8, + +#ifdef __BUS_SPACE_HAS_STREAM_METHODS + /* read (single) */ + generic_bs_r_1, + NSWAP(generic_armv4_bs_r_2), + NSWAP(generic_bs_r_4), + bs_notimpl_bs_r_8, + + /* read multiple */ + generic_bs_rm_1, + NSWAP(generic_armv4_bs_rm_2), + NSWAP(generic_bs_rm_4), + bs_notimpl_bs_rm_8, + + /* read region */ + generic_bs_rr_1, + NSWAP(generic_armv4_bs_rr_2), + NSWAP(generic_bs_rr_4), + bs_notimpl_bs_rr_8, + + /* write (single) */ + generic_bs_w_1, + NSWAP(generic_armv4_bs_w_2), + NSWAP(generic_bs_w_4), + bs_notimpl_bs_w_8, + + /* write multiple */ + generic_bs_wm_1, + NSWAP(generic_armv4_bs_wm_2), + NSWAP(generic_bs_wm_4), + bs_notimpl_bs_wm_8, + + /* write region */ + generic_bs_wr_1, + NSWAP(generic_armv4_bs_wr_2), + NSWAP(generic_bs_wr_4), + bs_notimpl_bs_wr_8, +#endif +}; + +struct bus_space amlogic_a4x_bs_tag = { + /* cookie */ + (void *) 0, + + /* mapping/unmapping */ + amlogic_bs_map, + amlogic_bs_unmap, + amlogic_a4x_bs_subregion, + + /* allocation/deallocation */ + amlogic_bs_alloc, /* not implemented */ + amlogic_bs_free, /* not implemented */ + + /* get kernel virtual address */ + amlogic_bs_vaddr, + + /* mmap */ + amlogic_a4x_bs_mmap, + + /* barrier */ + amlogic_bs_barrier, + + /* read (single) */ + a4x_bs_r_1, + NSWAP(a4x_bs_r_2), + NSWAP(a4x_bs_r_4), + bs_notimpl_bs_r_8, + + /* read multiple */ + a4x_bs_rm_1, + NSWAP(a4x_bs_rm_2), + NSWAP(a4x_bs_rm_4), + bs_notimpl_bs_rm_8, + + /* read region */ + bs_notimpl_bs_rr_1, + bs_notimpl_bs_rr_2, + bs_notimpl_bs_rr_4, + bs_notimpl_bs_rr_8, + + /* write (single) */ + a4x_bs_w_1, + NSWAP(a4x_bs_w_2), + NSWAP(a4x_bs_w_4), + bs_notimpl_bs_w_8, + + /* write multiple */ + a4x_bs_wm_1, + NSWAP(a4x_bs_wm_2), + NSWAP(a4x_bs_wm_4), + bs_notimpl_bs_wm_8, + + /* write region */ + bs_notimpl_bs_wr_1, + bs_notimpl_bs_wr_2, + bs_notimpl_bs_wr_4, + bs_notimpl_bs_wr_8, + + /* set multiple */ + bs_notimpl_bs_sm_1, + bs_notimpl_bs_sm_2, + bs_notimpl_bs_sm_4, + bs_notimpl_bs_sm_8, + + /* set region */ + bs_notimpl_bs_sr_1, + bs_notimpl_bs_sr_2, + bs_notimpl_bs_sr_4, + bs_notimpl_bs_sr_8, + + /* copy */ + bs_notimpl_bs_c_1, + bs_notimpl_bs_c_2, + bs_notimpl_bs_c_4, + bs_notimpl_bs_c_8, + +#ifdef __BUS_SPACE_HAS_STREAM_METHODS + /* read (single) */ + a4x_bs_r_1, + NSWAP(a4x_bs_r_2), + NSWAP(a4x_bs_r_4), + bs_notimpl_bs_r_8, + + /* read multiple */ + a4x_bs_rm_1, + NSWAP(a4x_bs_rm_2), + NSWAP(a4x_bs_rm_4), + bs_notimpl_bs_rm_8, + + /* read region */ + a4x_bs_rr_1, + NSWAP(a4x_bs_rr_2), + NSWAP(a4x_bs_rr_4), + bs_notimpl_bs_rr_8, + + /* write (single) */ + a4x_bs_w_1, + NSWAP(a4x_bs_w_2), + NSWAP(a4x_bs_w_4), + bs_notimpl_bs_w_8, + + /* write multiple */ + a4x_bs_wm_1, + NSWAP(a4x_bs_wm_2), + NSWAP(a4x_bs_wm_4), + bs_notimpl_bs_wm_8, + + /* write region */ + a4x_bs_wr_1, + NSWAP(a4x_bs_wr_2), + NSWAP(a4x_bs_wr_4), + bs_notimpl_bs_wr_8, +#endif +}; + +int +amlogic_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flag, + bus_space_handle_t *bshp) +{ + u_long startpa, endpa, pa; + const struct pmap_devmap *pd; + vaddr_t va; + + if ((pd = pmap_devmap_find_pa(bpa, size)) != NULL) { + /* Device was statically mapped. */ + *bshp = pd->pd_va + (bpa - pd->pd_pa); + return 0; + } + + startpa = trunc_page(bpa); + endpa = round_page(bpa + size); + + /* XXX use extent manager to check duplicate mapping */ + + va = uvm_km_alloc(kernel_map, endpa - startpa, 0, + UVM_KMF_VAONLY | UVM_KMF_NOWAIT | UVM_KMF_COLORMATCH); + if (!va) + return ENOMEM; + + *bshp = (bus_space_handle_t)(va + (bpa - startpa)); + + const int pmapflags = + (flag & (BUS_SPACE_MAP_CACHEABLE|BUS_SPACE_MAP_PREFETCHABLE)) + ? 0 + : PMAP_NOCACHE; + for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) { + pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE, pmapflags); + } + pmap_update(pmap_kernel()); + + return 0; +} + +void +amlogic_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size) +{ + vaddr_t va; + vsize_t sz; + + if (pmap_devmap_find_va(bsh, size) != NULL) { + /* Device was statically mapped; nothing to do. */ + return; + } + + va = trunc_page(bsh); + sz = round_page(bsh + size) - va; + + pmap_kremove(va, sz); + pmap_update(pmap_kernel()); + uvm_km_free(kernel_map, va, sz, UVM_KMF_VAONLY); +} + + +int +amlogic_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset, + bus_size_t size, bus_space_handle_t *nbshp) +{ + + *nbshp = bsh + offset; + return (0); +} + +int +amlogic_a4x_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset, + bus_size_t size, bus_space_handle_t *nbshp) +{ + + *nbshp = bsh + 4 * offset; + return (0); +} + +void +amlogic_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset, + bus_size_t len, int flags) +{ + flags &= BUS_SPACE_BARRIER_READ|BUS_SPACE_BARRIER_WRITE; + + if (flags) { + /* Issue an ARM11 Data Syncronisation Barrier (DSB) */ +#ifdef _ARM_ARCH_7 + __asm __volatile("dsb"); +#else + __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 4" : : "r" (0) + : "memory"); +#endif + return; + } + +} + +void * +amlogic_bs_vaddr(void *t, bus_space_handle_t bsh) +{ + + return (void *)bsh; +} + +paddr_t +amlogic_bs_mmap(void *t, bus_addr_t bpa, off_t offset, int prot, int flags) +{ + paddr_t bus_flags = 0; + + if (flags & BUS_SPACE_MAP_PREFETCHABLE) + bus_flags |= ARM32_MMAP_WRITECOMBINE; + + return (arm_btop(bpa + offset) | bus_flags); +} + +paddr_t +amlogic_a4x_bs_mmap(void *t, bus_addr_t bpa, off_t offset, int prot, int flags) +{ + paddr_t bus_flags = 0; + + if (flags & BUS_SPACE_MAP_PREFETCHABLE) + bus_flags |= ARM32_MMAP_WRITECOMBINE; + + return (arm_btop(bpa + 4 * offset) | bus_flags); +} + +int +amlogic_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend, + bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags, + bus_addr_t *bpap, bus_space_handle_t *bshp) +{ + + panic("%s(): not implemented\n", __func__); +} + +void +amlogic_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size) +{ + + panic("%s(): not implemented\n", __func__); +} Index: src/sys/arch/arm/amlogic/amlogic_var.h diff -u /dev/null src/sys/arch/arm/amlogic/amlogic_var.h:1.1 --- /dev/null Sat Feb 7 17:20:17 2015 +++ src/sys/arch/arm/amlogic/amlogic_var.h Sat Feb 7 17:20:17 2015 @@ -0,0 +1,59 @@ +/* $NetBSD: amlogic_var.h,v 1.1 2015/02/07 17:20:17 jmcneill Exp $ */ + +/*- + * Copyright (c) 2015 Jared D. McNeill <jmcne...@invisible.ca> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _ARM_AMLOGIC_VAR_H +#define _ARM_AMLOGIC_VAR_H + +#include <sys/types.h> +#include <sys/bus.h> + +struct amlogic_locators { + const char *loc_name; + bus_addr_t loc_offset; + bus_size_t loc_size; + int loc_port; + int loc_intr; +#define AMLOGICIO_INTR_DEFAULT 0 +}; + +struct amlogicio_attach_args { + struct amlogic_locators aio_loc; + bus_space_tag_t aio_core_bst; + bus_space_tag_t aio_core_a4x_bst; + bus_space_handle_t aio_bsh; + bus_dma_tag_t aio_dmat; +}; + +extern struct bus_space amlogic_bs_tag; +extern struct bus_space amlogic_a4x_bs_tag; +extern bus_space_handle_t amlogic_core_bsh; +extern struct arm32_bus_dma_tag amlogic_dma_tag; + +void amlogic_bootstrap(void); + +#endif /* _ARM_AMLOGIC_VAR_H */ Index: src/sys/arch/arm/amlogic/files.amlogic diff -u /dev/null src/sys/arch/arm/amlogic/files.amlogic:1.1 --- /dev/null Sat Feb 7 17:20:17 2015 +++ src/sys/arch/arm/amlogic/files.amlogic Sat Feb 7 17:20:17 2015 @@ -0,0 +1,33 @@ +# $NetBSD: files.amlogic,v 1.1 2015/02/07 17:20:17 jmcneill Exp $ +# +# Configuration info for Amlogic ARM Peripherals +# + +include "arch/arm/pic/files.pic" +include "arch/arm/cortex/files.cortex" + +file arch/arm/arm32/arm32_boot.c +file arch/arm/arm32/arm32_kvminit.c +file arch/arm/arm32/arm32_reboot.c +file arch/arm/arm32/irq_dispatch.S + +file arch/arm/amlogic/amlogic_board.c +file arch/arm/amlogic/amlogic_space.c +file arch/arm/arm/bus_space_a4x.S + +# On-board I/O +device amlogicio { [port=-1] } : bus_space_generic +attach amlogicio at mainbus with amlogic_io +file arch/arm/amlogic/amlogic_io.c amlogic_io + +# serial +attach com at amlogicio with amlogic_com +file arch/arm/amlogic/amlogic_com.c amlogic_com + +# Console parameters +defparam opt_amlogic.h CONADDR +defparam opt_amlogic.h CONSPEED +defparam opt_amlogic.h CONMODE + +# Memory parameters +defparam opt_amlogic.h MEMSIZE Index: src/sys/arch/evbarm/amlogic/amlogic_machdep.c diff -u /dev/null src/sys/arch/evbarm/amlogic/amlogic_machdep.c:1.1 --- /dev/null Sat Feb 7 17:20:17 2015 +++ src/sys/arch/evbarm/amlogic/amlogic_machdep.c Sat Feb 7 17:20:16 2015 @@ -0,0 +1,596 @@ +/* $NetBSD: amlogic_machdep.c,v 1.1 2015/02/07 17:20:16 jmcneill Exp $ */ + +/* + * Machine dependent functions for kernel setup for TI OSK5912 board. + * Based on lubbock_machdep.c which in turn was based on iq80310_machhdep.c + * + * Copyright (c) 2002, 2003, 2005 Genetec Corporation. All rights reserved. + * Written by Hiroyuki Bessho for Genetec Corporation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of Genetec Corporation may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Copyright (c) 2001 Wasabi Systems, Inc. + * All rights reserved. + * + * Written by Jason R. Thorpe for Wasabi Systems, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed for the NetBSD Project by + * Wasabi Systems, Inc. + * 4. The name of Wasabi Systems, Inc. may not be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Copyright (c) 1997,1998 Mark Brinicombe. + * Copyright (c) 1997,1998 Causality Limited. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mark Brinicombe + * for the NetBSD Project. + * 4. The name of the company nor the name of the author may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Copyright (c) 2007 Microsoft + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Microsoft + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTERS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__KERNEL_RCSID(0, "$NetBSD: amlogic_machdep.c,v 1.1 2015/02/07 17:20:16 jmcneill Exp $"); + +#include "opt_machdep.h" +#include "opt_ddb.h" +#include "opt_kgdb.h" +#include "opt_ipkdb.h" +#include "opt_md.h" +#include "opt_com.h" +#include "opt_amlogic.h" +#include "opt_arm_debug.h" + +#include "com.h" +#if 0 +#include "prcm.h" +#include "sdhc.h" +#include "ukbd.h" +#endif +#include "arml2cc.h" +#include "act8846pm.h" +#include "ether.h" + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/bus.h> +#include <sys/atomic.h> +#include <sys/cpu.h> +#include <sys/device.h> +#include <sys/exec.h> +#include <sys/kernel.h> +#include <sys/ksyms.h> +#include <sys/msgbuf.h> +#include <sys/proc.h> +#include <sys/reboot.h> +#include <sys/termios.h> +#include <sys/gpio.h> + +#include <uvm/uvm_extern.h> + +#include <sys/conf.h> +#include <dev/cons.h> +#include <dev/md.h> + +#include <machine/db_machdep.h> +#include <ddb/db_sym.h> +#include <ddb/db_extern.h> +#ifdef KGDB +#include <sys/kgdb.h> +#endif + +#include <machine/bootconfig.h> +#include <arm/armreg.h> +#include <arm/undefined.h> + +#include <arm/arm32/machdep.h> +#include <arm/mainbus/mainbus.h> + +#include <arm/amlogic/amlogic_reg.h> +#include <arm/amlogic/amlogic_var.h> +#include <arm/amlogic/amlogic_comreg.h> + +#include <arm/cortex/pl310_reg.h> +#include <arm/cortex/scu_reg.h> + +#include <arm/cortex/a9tmr_var.h> +#include <arm/cortex/pl310_var.h> + +#include <arm/cortex/gtmr_var.h> + +#include <evbarm/include/autoconf.h> +#include <evbarm/amlogic/platform.h> + +#include <dev/i2c/i2cvar.h> +#include <dev/i2c/ddcreg.h> + +#include <dev/usb/ukbdvar.h> +#include <net/if_ether.h> + +#ifndef AMLOGIC_MAX_BOOT_STRING +#define AMLOGIC_MAX_BOOT_STRING 1024 +#endif + +BootConfig bootconfig; /* Boot config storage */ +static char bootargs[AMLOGIC_MAX_BOOT_STRING]; +char *boot_args = NULL; +char *boot_file = NULL; +#if 0 +static uint8_t amlogic_edid[128]; /* EDID storage */ +#endif +u_int uboot_args[4] = { 0 }; /* filled in by amlogic_start.S (not in bss) */ + +/* Same things, but for the free (unused by the kernel) memory. */ + +extern char KERNEL_BASE_phys[]; +extern char _end[]; + +#if NCOM > 0 +int use_fb_console = false; +#else +int use_fb_console = true; +#endif + +/* + * Macros to translate between physical and virtual for a subset of the + * kernel address space. *Not* for general use. + */ +#define KERNEL_BASE_PHYS ((paddr_t)KERNEL_BASE_phys) +#define AMLOGIC_CORE_VOFFSET (AMLOGIC_CORE_VBASE - AMLOGIC_CORE_BASE) +/* Prototypes */ + +void consinit(void); +#ifdef KGDB +static void kgdb_port_init(void); +#endif + +static void init_clocks(void); +static void amlogic_device_register(device_t, void *); +static void amlogic_reset(void); + +bs_protos(bs_notimpl); + +#if NCOM > 0 +#include <dev/ic/comreg.h> +#include <dev/ic/comvar.h> +#endif + +/* + * Static device mappings. These peripheral registers are mapped at + * fixed virtual addresses very early in initarm() so that we can use + * them while booting the kernel, and stay at the same address + * throughout whole kernel's life time. + * + * We use this table twice; once with bootstrap page table, and once + * with kernel's page table which we build up in initarm(). + * + * Since we map these registers into the bootstrap page table using + * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map + * registers segment-aligned and segment-rounded in order to avoid + * using the 2nd page tables. + */ + +#define _A(a) ((a) & ~L1_S_OFFSET) +#define _S(s) (((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1)) + +static const struct pmap_devmap devmap[] = { + { + .pd_va = _A(AMLOGIC_CORE_VBASE), + .pd_pa = _A(AMLOGIC_CORE_BASE), + .pd_size = _S(AMLOGIC_CORE_SIZE), + .pd_prot = VM_PROT_READ|VM_PROT_WRITE, + .pd_cache = PTE_NOCACHE + }, + {0} +}; + +#undef _A +#undef _S + +#ifdef DDB +static void +amlogic_db_trap(int where) +{ + /* NOT YET */ +} +#endif + +void amlogic_putchar(char c); +void +amlogic_putchar(char c) +{ + volatile uint32_t *uartaddr = (volatile uint32_t *)CONSADDR_VA; + int timo = 150000; + + while ((uartaddr[UART_STATUS_REG] & UART_STATUS_TX_EMPTY) == 0) { + if (--timo == 0) + break; + } + + uartaddr[UART_WFIFO_REG] = c; + + while ((uartaddr[UART_STATUS_REG] & UART_STATUS_TX_EMPTY) == 0) { + if (--timo == 0) + break; + } +} + +/* + * u_int initarm(...) + * + * Initial entry point on startup. This gets called before main() is + * entered. + * It should be responsible for setting up everything that must be + * in place when main is called. + * This includes + * Taking a copy of the boot configuration structure. + * Initialising the physical console so characters can be printed. + * Setting up page tables for the kernel + * Relocating the kernel to the bottom of physical memory + */ +u_int +initarm(void *arg) +{ + psize_t ram_size = 0; + char *ptr; + *(volatile int *)CONSADDR_VA = 0x40; /* output '@' */ +#if 1 + amlogic_putchar('d'); +#endif + + pmap_devmap_register(devmap); + amlogic_putchar('b'); + amlogic_bootstrap(); + amlogic_putchar('!'); + +#ifdef MULTIPROCESSOR + uint32_t scu_cfg = bus_space_read_4(&amlogic_bs_tag, + amlogic_core0_bsh, ROCKCHIP_SCU_OFFSET + SCU_CFG); + arm_cpu_max = (scu_cfg & SCU_CFG_CPUMAX) + 1; + membar_producer(); +#endif + + /* Heads up ... Setup the CPU / MMU / TLB functions. */ + if (set_cpufuncs()) + panic("cpu not recognized!"); + + init_clocks(); + + consinit(); +#ifdef MULTIPROCESSOR + arm_cpu_max = 1 + __SHIFTOUT(armreg_l2ctrl_read(), L2CTRL_NUMCPU); +#endif + +#if NARML2CC > 0 + /* + * Probe the PL310 L2CC + */ + printf("probe the PL310 L2CC\n"); + const bus_space_handle_t pl310_bh = + AMLOGIC_CORE_VBASE + AMLOGIC_PL310_OFFSET; + arml2cc_init(&amlogic_bs_tag, pl310_bh, 0); + amlogic_putchar('l'); +#endif + + printf("\nuboot arg = %#x, %#x, %#x, %#x\n", + uboot_args[0], uboot_args[1], uboot_args[2], uboot_args[3]); + +#ifdef KGDB + kgdb_port_init(); +#endif + + cpu_reset_address = amlogic_reset; + +#ifdef VERBOSE_INIT_ARM + /* Talk to the user */ + printf("\nNetBSD/evbarm (amlogic) booting ...\n"); +#endif + +#ifdef BOOT_ARGS + char mi_bootargs[] = BOOT_ARGS; + parse_mi_bootargs(mi_bootargs); +#endif + +#ifdef VERBOSE_INIT_ARM + printf("initarm: Configuring system ...\n"); + + printf("initarm: cbar=%#x\n", armreg_cbar_read()); + printf("KERNEL_BASE=0x%x, KERNEL_VM_BASE=0x%x, KERNEL_VM_BASE - KERNEL_BASE=0x%x, KERNEL_BASE_VOFFSET=0x%x\n", + KERNEL_BASE, KERNEL_VM_BASE, KERNEL_VM_BASE - KERNEL_BASE, KERNEL_BASE_VOFFSET); +#endif + +#if notyet + ram_size = amlogic_get_ram_size(); +#endif + +#ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS + if (ram_size > KERNEL_VM_BASE - KERNEL_BASE) { + printf("%s: dropping RAM size from %luMB to %uMB\n", + __func__, (unsigned long) (ram_size >> 20), + (KERNEL_VM_BASE - KERNEL_BASE) >> 20); + ram_size = KERNEL_VM_BASE - KERNEL_BASE; + } +#endif + + /* + * If MEMSIZE specified less than what we really have, limit ourselves + * to that. + */ +#ifdef MEMSIZE + if (ram_size == 0 || ram_size > (unsigned)MEMSIZE * 1024 * 1024) + ram_size = (unsigned)MEMSIZE * 1024 * 1024; + printf("ram_size = 0x%x\n", (int)ram_size); +#else + KASSERTMSG(ram_size > 0, "RAM size unknown and MEMSIZE undefined"); +#endif + + /* Fake bootconfig structure for the benefit of pmap.c. */ + bootconfig.dramblocks = 1; + bootconfig.dram[0].address = 0x00000000; /* DDR PHY addr */ + bootconfig.dram[0].pages = ram_size / PAGE_SIZE; + +#ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS + const bool mapallmem_p = true; + KASSERT(ram_size <= KERNEL_VM_BASE - KERNEL_BASE); +#else + const bool mapallmem_p = false; +#endif + KASSERT((armreg_pfr1_read() & ARM_PFR1_SEC_MASK) != 0); + + arm32_bootmem_init(bootconfig.dram[0].address, ram_size, + KERNEL_BASE_PHYS); + arm32_kernel_vm_init(KERNEL_VM_BASE, ARM_VECTORS_LOW, 0, devmap, + mapallmem_p); + + printf("bootargs: %s\n", bootargs); + + boot_args = bootargs; + parse_mi_bootargs(boot_args); + + /* we've a specific device_register routine */ + evbarm_device_register = amlogic_device_register; + + db_trap_callback = amlogic_db_trap; + + if (get_bootconf_option(boot_args, "console", + BOOTOPT_TYPE_STRING, &ptr) && strncmp(ptr, "fb", 2) == 0) { + use_fb_console = true; + } + +#if notyet + curcpu()->ci_data.cpu_cc_freq = amlogic_cpu_get_rate(); +#else + curcpu()->ci_data.cpu_cc_freq = 1000000; +#endif + + return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, NULL, 0); + +} + +static void +init_clocks(void) +{ + /* NOT YET */ +} + +#if NCOM > 0 +#ifndef CONSADDR +#error Specify the address of the console UART with the CONSADDR option. +#endif +#ifndef CONSPEED +#define CONSPEED 115200 +#endif +#ifndef CONMODE +#define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */ +#endif + +static const bus_addr_t consaddr = CONSADDR; +static const int conspeed = CONSPEED; +static const int conmode = CONMODE; +#endif + +void +consinit(void) +{ +#if NCOM > 0 + bus_space_handle_t bh; +#endif + static int consinit_called = 0; + + if (consinit_called != 0) + return; + + consinit_called = 1; + + amlogic_putchar('e'); + +#if NCOM > 0 + if (bus_space_map(&amlogic_a4x_bs_tag, consaddr, AMLOGIC_UART_SIZE, 0, &bh)) + panic("Serial console can not be mapped."); + + if (comcnattach(&amlogic_a4x_bs_tag, consaddr, conspeed, + AMLOGIC_UART_FREQ, COM_TYPE_NORMAL, conmode)) + panic("Serial console can not be initialized."); + + bus_space_unmap(&amlogic_a4x_bs_tag, bh, AMLOGIC_UART_SIZE); +#endif + + +#if NUKBD > 0 + ukbd_cnattach(); /* allow USB keyboard to become console */ +#endif + + amlogic_putchar('f'); + amlogic_putchar('g'); +} + +void +amlogic_reset(void) +{ +#if notyet + bus_space_tag_t bst = &amlogic_bs_tag; + bus_space_handle_t bsh; + + bus_space_subregion(bst, amlogic_core1_bsh, + ROCKCHIP_CRU_OFFSET, ROCKCHIP_CRU_SIZE, &bsh); + + bus_space_write_4(bst, bsh, CRU_GLB_SRST_FST_REG, + CRU_GLB_SRST_FST_MAGIC); +#endif +} + +#ifdef KGDB +#ifndef KGDB_DEVADDR +#error Specify the address of the kgdb UART with the KGDB_DEVADDR option. +#endif +#ifndef KGDB_DEVRATE +#define KGDB_DEVRATE 115200 +#endif + +#ifndef KGDB_DEVMODE +#define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */ +#endif +static const vaddr_t comkgdbaddr = KGDB_DEVADDR; +static const int comkgdbspeed = KGDB_DEVRATE; +static const int comkgdbmode = KGDB_DEVMODE; + +void +static kgdb_port_init(void) +{ + static int kgdbsinit_called = 0; + + if (kgdbsinit_called != 0) + return; + + kgdbsinit_called = 1; + + bus_space_handle_t bh; + if (bus_space_map(&amlogic_a4x_bs_tag, comkgdbaddr, ROCKCHIP_COM_SIZE, 0, &bh)) + panic("kgdb port can not be mapped."); + + if (com_kgdb_attach(&amlogic_a4x_bs_tag, comkgdbaddr, comkgdbspeed, + ROCKCHIP_COM_FREQ, COM_TYPE_NORMAL, comkgdbmode)) + panic("KGDB uart can not be initialized."); + + bus_space_unmap(&amlogic_a4x_bs_tag, bh, ROCKCHIP_COM_SIZE); +} +#endif + +void +amlogic_device_register(device_t self, void *aux) +{ + prop_dictionary_t dict = device_properties(self); + + if (device_is_a(self, "armperiph") + && device_is_a(device_parent(self), "mainbus")) { + struct mainbus_attach_args * const mb = aux; + mb->mb_iot = &amlogic_bs_tag; + return; + } + + /* + * We need to tell the A9 Global/Watchdog Timer + * what frequency it runs at. + */ + if (device_is_a(self, "a9tmr") || device_is_a(self, "a9wdt")) { + prop_dictionary_set_uint32(dict, "frequency", + 1600000000 / 2); + + return; + } +} Index: src/sys/arch/evbarm/amlogic/amlogic_start.S diff -u /dev/null src/sys/arch/evbarm/amlogic/amlogic_start.S:1.1 --- /dev/null Sat Feb 7 17:20:17 2015 +++ src/sys/arch/evbarm/amlogic/amlogic_start.S Sat Feb 7 17:20:16 2015 @@ -0,0 +1,318 @@ +/*- + * Copyright (c) 2014 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas of 3am Software Foundry. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "opt_amlogic.h" +#include "opt_com.h" +#include "opt_cpuoptions.h" +#include "opt_cputypes.h" +#include "opt_multiprocessor.h" +#include "opt_arm_debug.h" + +#include <arm/asm.h> +#include <arm/armreg.h> +#include "assym.h" + +#include <arm/amlogic/amlogic_reg.h> +#include <evbarm/amlogic/platform.h> + +#include <arm/cortex/scu_reg.h> + +RCSID("$NetBSD: amlogic_start.S,v 1.1 2015/02/07 17:20:16 jmcneill Exp $") + +#if defined(VERBOSE_INIT_ARM) +#define XPUTC(n) mov r0, n; bl xputc +#if KERNEL_BASE_VOFFSET == 0 +#define XPUTC2(n) mov r0, n; bl xputc +#else +#define XPUTC2(n) mov r0, n; blx r11 +#endif +#ifdef __ARMEB__ +#define COM_BSWAP +#endif +#define COM_MULT 4 +#define XPUTC_COM 1 +#else +#define XPUTC(n) +#define XPUTC2(n) +#endif + +#define INIT_MEMSIZE 128 +#define TEMP_L1_TABLE (KERNEL_BASE - KERNEL_BASE_VOFFSET + INIT_MEMSIZE * L1_S_SIZE - L1_TABLE_SIZE) + +#define MD_CPU_HATCH _C_LABEL(a9tmr_init_cpu_clock) + +/* + * Kernel start routine for Amlogic boards. + * At this point, this code has been loaded into SDRAM + * and the MMU maybe on or maybe off. + */ +#ifdef KERNEL_BASES_EQUAL + .text +#else + .section .start,"ax",%progbits +#endif + + .global _C_LABEL(amlogic_start) +_C_LABEL(amlogic_start): +#ifdef __ARMEB__ + setend be /* force big endian */ +#endif + mov r9, #0 + + /* Move into supervisor mode and disable IRQs/FIQs. */ +// cpsid if, #PSR_SVC32_MODE + + /* + * Save any arguments passed to us. + */ + movw r4, #:lower16:uboot_args + movt r4, #:upper16:uboot_args +#if KERNEL_BASE_VOFFSET != 0 + /* + * But since .start is at 0x40000000 and .text is at 0x8000000, we + * can't directly use the address that the linker gave us directly. + * We have to adjust the address the linker gave us to get the to + * the physical address. + */ + sub r4, r4, #KERNEL_BASE_VOFFSET +#endif + + stmia r4, {r0-r3} // Save the arguments + + /* + * Turn on the SMP bit + */ + bl cortex_init + + /* + * Set up a preliminary mapping in the MMU to allow us to run + * at KERNEL_BASE with caches on. + */ + movw r0, #:lower16:TEMP_L1_TABLE + movt r0, #:upper16:TEMP_L1_TABLE + movw r1, #:lower16:mmu_init_table + movt r1, #:upper16:mmu_init_table + bl arm_boot_l1pt_init + XPUTC(#68) + + /* + * Turn on the MMU, Caches, etc. Return to new enabled address space. + */ + movw r0, #:lower16:TEMP_L1_TABLE + movt r0, #:upper16:TEMP_L1_TABLE +#if KERNEL_BASE_VOFFSET == 0 + bl arm_cpuinit +#else + /* + * After the MMU is on, we can execute in the normal .text segment + * so setup the lr to be in .text. Cache the address for xputc + * before we go. + */ +#if defined(VERBOSE_INIT_ARM) + adr r11, xputc @ for XPUTC2 +#endif + movw lr, #:lower16:1f + movt lr, #:upper16:1f + b arm_cpuinit + .pushsection .text,"ax",%progbits +1: +#endif + XPUTC2(#90) + +#if defined(MULTIPROCESSOR) + // Now spin up the second processors into the same state we are now. + XPUTC2(#77) + XPUTC2(#80) + XPUTC2(#60) + // Make sure the cache is flushed out to RAM for the other CPUs + bl _C_LABEL(armv7_dcache_wbinv_all) + bl amlogic_mpinit + XPUTC2(#62) +#endif /* MULTIPROCESSOR */ + XPUTC2(#13) + XPUTC2(#10) + + /* + * Jump to start in locore.S, which in turn will call initarm and main. + */ + b start + + /* NOTREACHED */ + +#ifndef KERNEL_BASES_EQUAL + .popsection +#endif + +#include <arm/cortex/a9_mpsubr.S> + +#define PMU_PWRDN_REG 0x0008 +#define PMU_PWRDN_SCU __BIT(4) + +#if defined(MULTIPROCESSOR) +#ifndef KERNEL_BASES_EQUAL + .pushsection .text,"ax",%progbits +#endif +amlogic_mptramp: + ldr pc, 1f +.global amlogic_mpstart_vec +amlogic_mpstart_vec: +1: .space 4 + +amlogic_mpinit: + mov r4, lr + /* r5: SCU, r6: PMU, r7: SRAM */ + movw r5, #:lower16:(ROCKCHIP_CORE0_BASE+ROCKCHIP_SCU_OFFSET) + movt r5, #:upper16:(ROCKCHIP_CORE0_BASE+ROCKCHIP_SCU_OFFSET) + movw r6, #:lower16:(ROCKCHIP_CORE1_BASE+ROCKCHIP_PMU_OFFSET) + movt r6, #:upper16:(ROCKCHIP_CORE1_BASE+ROCKCHIP_PMU_OFFSET) + movw r7, #:lower16:(ROCKCHIP_CORE0_BASE+ROCKCHIP_SRAM_OFFSET) + movt r7, #:upper16:(ROCKCHIP_CORE0_BASE+ROCKCHIP_SRAM_OFFSET) + + /* Set where the other CPU(s) are going to execute */ + XPUTC2(#118) + movw r1, #:lower16:amlogic_mpstart + movt r1, #:upper16:amlogic_mpstart + ldr r0, =amlogic_mpstart_vec + str r1, [r0] + ldr r0, =amlogic_mptramp + mov r2, #0 +1: ldr r1, [r0, r2] + str r1, [r7, r2] + add r2, r2, #4 + cmp r2, #32 + blt 1b + dsb + + /* Invalid SCU cache tags */ + XPUTC2(#45) + movw r1, #0xffff + movt r1, #0 + str r1, [r5, #SCU_INV_ALL_REG] + + /* Get CPU count */ + ldr r1, [r5, #SCU_CFG] + and r2, r1, #SCU_CFG_CPUMAX + add r2, r2, #1 + + /* Convert to CPU1..N mask */ + mov r7, #0 + lsl r7, r2, #1 + sub r7, r7, #1 + and r7, r7, #~1 + + /* Power down secondary CPUs */ + XPUTC2(#46) + ldr r1, [r6, #PMU_PWRDN_REG] + orr r1, r1, r7 + str r1, [r6, #PMU_PWRDN_REG] + dsb + + /* Power up SCU */ + XPUTC2(#46) + ldr r1, [r6, #PMU_PWRDN_REG] + and r1, r1, #~PMU_PWRDN_SCU + str r1, [r6, #PMU_PWRDN_REG] + dsb + + /* Enable SCU */ + XPUTC2(#46) + ldr r1, [r5, #SCU_CTL] + orr r1, r1, #SCU_CTL_SCU_ENA + str r1, [r5, #SCU_CTL] + dsb + + /* Power up secondary CPUs */ + XPUTC2(#33) + ldr r1, [r6, #PMU_PWRDN_REG] + and r1, r1, r7 + str r1, [r6, #PMU_PWRDN_REG] + dsb + + XPUTC2(#49) + XPUTC2(#50) + XPUTC2(#51) + + // + // Wait up a second for CPU1 to hatch. + // + movw r2, #:lower16:arm_cpu_hatched + movt r2, #:upper16:arm_cpu_hatched + mov r1, #0x10000000 +1: dmb + ldr r0, [r2] + cmp r0, r7 + beq .hatched + subs r1, r1, #1 + bne 1b + +.hatched: + bx r4 + +ASEND(amlogic_mpinit) +#ifndef KERNEL_BASES_EQUAL + .popsection +#endif + +amlogic_mpstart: + /* invalidate cache */ + movw ip, #:lower16:_C_LABEL(armv7_dcache_inv_all) + movt ip, #:upper16:_C_LABEL(armv7_dcache_inv_all) +#ifndef KERNEL_BASES_EQUAL + sub ip, ip, #KERNEL_BASE_VOFFSET +#endif + blx ip + b _C_LABEL(cortex_mpstart) + +#endif /* MULTIPROCESSOR */ + +mmu_init_table: + MMU_INIT(KERNEL_BASE, KERNEL_BASE - KERNEL_BASE_VOFFSET, INIT_MEMSIZE, + L1_S_PROTO_armv7 | L1_S_APv7_KRW | L1_S_CACHEABLE) + +#if KERNEL_BASE_VOFFSET != 0 + /* Map KERNEL_BASE VA to SDRAM PA, write-back cacheable, shareable */ + MMU_INIT(KERNEL_BASE - KERNEL_BASE_VOFFSET, + KERNEL_BASE - KERNEL_BASE_VOFFSET, INIT_MEMSIZE, + L1_S_PROTO_armv7 | L1_S_APv7_KRW | L1_S_CACHEABLE) +#endif + + /* Map CORE */ + MMU_INIT(AMLOGIC_CORE_VBASE, AMLOGIC_CORE_BASE, + (AMLOGIC_CORE_SIZE + L1_S_SIZE - 1) / L1_S_SIZE, + L1_S_PROTO_armv7 | L1_S_APv7_KRW | L1_S_V6_XN) + + /* Map CORE */ + MMU_INIT(AMLOGIC_CORE_BASE, AMLOGIC_CORE_BASE, + (AMLOGIC_CORE_SIZE + L1_S_SIZE - 1) / L1_S_SIZE, + L1_S_PROTO_armv7 | L1_S_APv7_KRW | L1_S_V6_XN) + + /* end of table */ + MMU_INIT(0, 0, 0, 0) + +END(_C_LABEL(amlogic_start)) Index: src/sys/arch/evbarm/amlogic/genassym.cf diff -u /dev/null src/sys/arch/evbarm/amlogic/genassym.cf:1.1 --- /dev/null Sat Feb 7 17:20:17 2015 +++ src/sys/arch/evbarm/amlogic/genassym.cf Sat Feb 7 17:20:16 2015 @@ -0,0 +1,37 @@ +# $NetBSD: genassym.cf,v 1.1 2015/02/07 17:20:16 jmcneill Exp $ + +#- +# Copyright (c) 2013 The NetBSD Foundation, Inc. +# All rights reserved. +# +# This code is derived from software contributed to The NetBSD Foundation +# by Matt Thomas of 3am Software Foundry. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +include <arch/arm/amlogic/amlogic_comreg.h> + +define LSR_TXRDY UART_STATUS_TX_EMPTY +define LSR_TSRE UART_STATUS_TX_EMPTY +define COM_DATA (UART_WFIFO_REG>>2) +define COM_LSR (UART_STATUS_REG>>2) Index: src/sys/arch/evbarm/amlogic/platform.h diff -u /dev/null src/sys/arch/evbarm/amlogic/platform.h:1.1 --- /dev/null Sat Feb 7 17:20:17 2015 +++ src/sys/arch/evbarm/amlogic/platform.h Sat Feb 7 17:20:16 2015 @@ -0,0 +1,39 @@ +/* $NetBSD: platform.h,v 1.1 2015/02/07 17:20:16 jmcneill Exp $ */ + +/*- + * Copyright (c) 2015 Jared D. McNeill <jmcne...@invisible.ca> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _EVBARM_AMLOGIC_PLATFORM_H +#define _EVBARM_AMLOGIC_PLATFORM_H + +#include <arm/amlogic/amlogic_reg.h> + +#define KERNEL_VM_BASE 0xc0000000 +#define KERNEL_VM_SIZE 0x20000000 /* 0x20000000 = 512MB */ + +#define CONSADDR_VA (CONSADDR - AMLOGIC_CORE_BASE + AMLOGIC_CORE_VBASE) + +#endif /* _EVBARM_AMLOGIC_PLATFORM_H */ Index: src/sys/arch/evbarm/conf/ODROID-C1 diff -u /dev/null src/sys/arch/evbarm/conf/ODROID-C1:1.1 --- /dev/null Sat Feb 7 17:20:17 2015 +++ src/sys/arch/evbarm/conf/ODROID-C1 Sat Feb 7 17:20:16 2015 @@ -0,0 +1,199 @@ +# +# $NetBSD: ODROID-C1,v 1.1 2015/02/07 17:20:16 jmcneill Exp $ +# +# Odroid-C1 (Amlogic S805) based SBC (Single Board Computer) +# + +include "arch/evbarm/conf/std.amlogic" + +# estimated number of users + +maxusers 32 + +# Standard system options + +options RTC_OFFSET=0 # hardware clock is this many mins. west of GMT +#options NTP # NTP phase/frequency locked loop + +# CPU options + +options CPU_CORTEXA5 +options PMAPCOUNTERS + +# Architecture options + +# File systems + +file-system FFS # UFS +#file-system LFS # log-structured file system +file-system MFS # memory file system +file-system NFS # Network file system +#file-system ADOSFS # AmigaDOS-compatible file system +#file-system EXT2FS # second extended file system (linux) +#file-system CD9660 # ISO 9660 + Rock Ridge file system +file-system MSDOSFS # MS-DOS file system +#file-system FDESC # /dev/fd +file-system KERNFS # /kern +#file-system NULLFS # loopback file system +file-system PROCFS # /proc +#file-system PUFFS # Userspace file systems (e.g. ntfs-3g & sshfs) +#file-system UMAPFS # NULLFS + uid and gid remapping +#file-system UNION # union file system +file-system TMPFS # memory file system +file-system PTYFS # /dev/pts/N support + +# File system options +#options QUOTA # legacy UFS quotas +#options QUOTA2 # new, in-filesystem UFS quotas +#options FFS_EI # FFS Endian Independant support +#options NFSSERVER +#options WAPBL # File system journaling support - Experimental +#options FFS_NO_SNAPSHOT # No FFS snapshot support + +# Networking options + +#options GATEWAY # packet forwarding +options INET # IP + ICMP + TCP + UDP +options INET6 # IPV6 +#options IPSEC # IP security +#options IPSEC_DEBUG # debug for IP security +#options MROUTING # IP multicast routing +#options PIM # Protocol Independent Multicast +#options NETATALK # AppleTalk networking +#options PPP_BSDCOMP # BSD-Compress compression support for PPP +#options PPP_DEFLATE # Deflate compression support for PPP +#options PPP_FILTER # Active filter support for PPP (requires bpf) +#options TCP_DEBUG # Record last TCP_NDEBUG packets with SO_DEBUG + +options NFS_BOOT_BOOTP +#options NFS_BOOT_DHCP +#options NFS_BOOT_BOOTSTATIC +#options NFS_BOOTSTATIC_MYIP="\"192.168.1.4\"" +#options NFS_BOOTSTATIC_GWIP="\"192.168.1.1\"" +#options NFS_BOOTSTATIC_MASK="\"255.255.255.0\"" +#options NFS_BOOTSTATIC_SERVADDR="\"192.168.1.1\"" +#options NFS_BOOTSTATIC_SERVER="\"192.168.1.1:/nfs/sdp2430\"" + +options NFS_BOOT_RWSIZE=1024 + +# Compatibility options + +#options COMPAT_NETBSD32 # allow running arm (e.g. non-earm) binaries +#options COMPAT_43 # 4.3BSD compatibility. +#options COMPAT_09 # NetBSD 0.9, +#options COMPAT_10 # NetBSD 1.0, +#options COMPAT_11 # NetBSD 1.1, +#options COMPAT_12 # NetBSD 1.2, +#options COMPAT_13 # NetBSD 1.3, +#options COMPAT_14 # NetBSD 1.4, +#options COMPAT_15 # NetBSD 1.5, +#options COMPAT_16 # NetBSD 1.6, +#options COMPAT_20 # NetBSD 2.0, +#options COMPAT_30 # NetBSD 3.0, +#options COMPAT_40 # NetBSD 4.0, +#options COMPAT_50 # NetBSD 5.0, +#options COMPAT_60 # NetBSD 6.0, and +options COMPAT_70 # NetBSD 7.0 binary compatibility. +#options TCP_COMPAT_42 # 4.2BSD TCP/IP bug compat. Not recommended. +#options COMPAT_BSDPTY # /dev/[pt]ty?? ptys. + +# Shared memory options + +options SYSVMSG # System V-like message queues +options SYSVSEM # System V-like semaphores +#options SEMMNI=10 # number of semaphore identifiers +#options SEMMNS=60 # number of semaphores in system +#options SEMUME=10 # max number of undo entries per process +#options SEMMNU=30 # number of undo structures in system +options SYSVSHM # System V-like memory sharing + +# Device options + +#options MEMORY_DISK_HOOKS # boottime setup of ramdisk +#options MEMORY_DISK_ROOT_SIZE=8192 # Size in blocks +#options MEMORY_DISK_DYNAMIC +#options MINIROOTSIZE=1000 # Size in blocks +#options MEMORY_DISK_IS_ROOT # use memory disk as root +#options MEMORY_DISK_FBFLAGS=RB_SINGLE + +# Miscellaneous kernel options +options KTRACE # system call tracing, a la ktrace(1) +#options KMEMSTATS # kernel memory statistics +#options SCSIVERBOSE # Verbose SCSI errors +#options MIIVERBOSE # Verbose MII autoconfuration messages +#options DDB_KEYCODE=0x40 +#options USERCONF # userconf(4) support +#options PIPE_SOCKETPAIR # smaller, but slower pipe(2) + +# Alternate buffer queue strategies for better responsiveness under high +# disk I/O load. +#options BUFQ_READPRIO +options BUFQ_PRIOCSCAN + +# Development and Debugging options + +#options PERFCTRS # performance counters +options DIAGNOSTIC # internal consistency checks +options DEBUG +options LOCKDEBUG +#options PMAP_DEBUG # Enable pmap_debug_level code +#options IPKDB # remote kernel debugging +options VERBOSE_INIT_ARM # verbose bootstraping messages +options DDB # in-kernel debugger +options DDB_ONPANIC=1 +options DDB_HISTORY_SIZE=100 # Enable history editing in DDB +options DDB_COMMANDONENTER="bt" +#options KGDB +makeoptions DEBUG="-g" # compile full symbol table +makeoptions COPY_SYMTAB=1 + +options BOOT_ARGS="\"\"" + +config netbsd root on ? type ? + +# The main bus device +mainbus0 at root + +# The boot cpu +cpu* at mainbus? +#options MULTIPROCESSOR + +# A5 core devices +armperiph0 at mainbus? +arml2cc0 at armperiph? # L2 Cache Controller +armgic0 at armperiph? # Interrupt Controller +a9tmr0 at armperiph? # Global Timer +a9wdt0 at armperiph? # Watchdog + +# Specify the memory size in megabytes. +options MEMSIZE=1024 + +# On-board I/O +amlogicio0 at mainbus? + +# On-board 16550 UARTs +com0 at amlogicio0 port 0 +options CONSADDR=0xc81004c0, CONSPEED=115200 + +# Pseudo-Devices + +# disk/mass storage pseudo-devices +pseudo-device md # memory disk device (ramdisk) +pseudo-device vnd # disk-like interface to files +#pseudo-device fss # file system snapshot device +pseudo-device drvctl # driver control +#pseudo-device putter # for puffs and pud + +# network pseudo-devices +pseudo-device bpfilter # Berkeley packet filter +pseudo-device loop # network loopback +#pseudo-device kttcp # network loopback + +# miscellaneous pseudo-devices +pseudo-device pty # pseudo-terminals +#options RND_COM +#pseudo-device clockctl # user control of clock subsystem +pseudo-device ksyms # /dev/ksyms +pseudo-device lockstat # lock profiling + +cinclude "arch/evbarm/conf/ODROID-C1.local" Index: src/sys/arch/evbarm/conf/files.amlogic diff -u /dev/null src/sys/arch/evbarm/conf/files.amlogic:1.1 --- /dev/null Sat Feb 7 17:20:17 2015 +++ src/sys/arch/evbarm/conf/files.amlogic Sat Feb 7 17:20:16 2015 @@ -0,0 +1,10 @@ +# $NetBSD: files.amlogic,v 1.1 2015/02/07 17:20:16 jmcneill Exp $ +# +# Amlogic configuration info +# + +file arch/evbarm/amlogic/amlogic_machdep.c + +defparam opt_machdep.h BOOT_ARGS + +include "arch/arm/amlogic/files.amlogic" Index: src/sys/arch/evbarm/conf/mk.amlogic diff -u /dev/null src/sys/arch/evbarm/conf/mk.amlogic:1.1 --- /dev/null Sat Feb 7 17:20:17 2015 +++ src/sys/arch/evbarm/conf/mk.amlogic Sat Feb 7 17:20:16 2015 @@ -0,0 +1,33 @@ +# $NetBSD: mk.amlogic,v 1.1 2015/02/07 17:20:16 jmcneill Exp $ +CPPFLAGS+= -mcpu=cortex-a5 -mfpu=neon + +SYSTEM_FIRST_OBJ= amlogic_start.o +SYSTEM_FIRST_SFILE= ${THISARM}/amlogic/amlogic_start.S + +GENASSYM_EXTRAS+= ${THISARM}/amlogic/genassym.cf + +_OSRELEASE!= ${HOST_SH} $S/conf/osrelease.sh + +MKUBOOTIMAGEARGS= -A arm -T kernel +MKUBOOTIMAGEARGS+= -a $(KERNEL_BASE_PHYS) -e $(KERNEL_BASE_PHYS) +MKUBOOTIMAGEARGS+= -n "NetBSD/$(BOARDTYPE) ${_OSRELEASE}" +MKUBOOTIMAGEARGS_NONE= ${MKUBOOTIMAGEARGS} -C none +MKUBOOTIMAGEARGS_GZ= ${MKUBOOTIMAGEARGS} -C gz + +KERNEL_BASE_PHYS=0x00100000 +KERNEL_BASE_VIRT=0x80100000 + +SYSTEM_LD_TAIL_EXTRA+=; \ + echo ${OBJCOPY} -S -O binary $@ $@.bin; \ + ${OBJCOPY} -S -O binary $@ $@.bin; \ + echo ${TOOL_MKUBOOTIMAGE} ${MKUBOOTIMAGEARGS_NONE} $@.bin $@.ub; \ + ${TOOL_MKUBOOTIMAGE} ${MKUBOOTIMAGEARGS_NONE} $@.bin $@.ub; \ + echo ${TOOL_GZIP} -c $@.bin > $@.bin.gz; \ + ${TOOL_GZIP} -c $@.bin > $@.bin.gz; \ + echo ${TOOL_MKUBOOTIMAGE} ${MKUBOOTIMAGEARGS_GZ} $@.bin.gz $@.gz.ub; \ + ${TOOL_MKUBOOTIMAGE} ${MKUBOOTIMAGEARGS_GZ} $@.bin.gz $@.gz.ub + +EXTRA_KERNELS+= ${KERNELS:@.KERNEL.@${.KERNEL.}.bin@} +EXTRA_KERNELS+= ${KERNELS:@.KERNEL.@${.KERNEL.}.ub@} +EXTRA_KERNELS+= ${KERNELS:@.KERNEL.@${.KERNEL.}.bin.gz@} +EXTRA_KERNELS+= ${KERNELS:@.KERNEL.@${.KERNEL.}.gz.ub@} Index: src/sys/arch/evbarm/conf/std.amlogic diff -u /dev/null src/sys/arch/evbarm/conf/std.amlogic:1.1 --- /dev/null Sat Feb 7 17:20:17 2015 +++ src/sys/arch/evbarm/conf/std.amlogic Sat Feb 7 17:20:16 2015 @@ -0,0 +1,29 @@ +# $NetBSD: std.amlogic,v 1.1 2015/02/07 17:20:16 jmcneill Exp $ +# + +machine evbarm arm +include "arch/evbarm/conf/std.evbarm" + +include "arch/evbarm/conf/files.amlogic" + +options MODULAR +options MODULAR_DEFAULT_AUTOLOAD +options __HAVE_CPU_COUNTER +options CORTEX_PMC +options __HAVE_FAST_SOFTINTS # should be in types.h +options ARM_HAS_VBAR +options __HAVE_MM_MD_DIRECT_MAPPED_PHYS +options TPIDRPRW_IS_CURCPU +options KERNEL_BASE_EXT=0x80000000 +options FPU_VFP +options ARM_CBAR=0xc4300000 + +makeoptions KERNEL_BASE_PHYS="0x00100000" +makeoptions KERNEL_BASE_VIRT="0x80100000" +makeoptions BOARDTYPE="amlogic" +makeoptions BOARDMKFRAG="${THISARM}/conf/mk.amlogic" + +options ARM_INTR_IMPL="<arch/arm/amlogic/amlogic_intr.h>" +options ARM_GENERIC_TODR + +options COM_16750