diff --git a/sys/arm/annapurna/alpine/alpine_common.c b/sys/arm/annapurna/alpine/alpine_common.c index b03c3a487552..ce84b39b867b 100644 --- a/sys/arm/annapurna/alpine/alpine_common.c +++ b/sys/arm/annapurna/alpine/alpine_common.c @@ -43,97 +43,10 @@ __FBSDID("$FreeBSD$"); #include #include -#define WDTLOAD 0x000 -#define LOAD_MIN 0x00000001 -#define LOAD_MAX 0xFFFFFFFF -#define WDTVALUE 0x004 -#define WDTCONTROL 0x008 -/* control register masks */ -#define INT_ENABLE (1 << 0) -#define RESET_ENABLE (1 << 1) -#define WDTLOCK 0xC00 -#define UNLOCK 0x1ACCE551 -#define LOCK 0x00000001 - -extern bus_addr_t al_devmap_pa; - -static int alpine_get_wdt_base(uint32_t *pbase, uint32_t *psize); +#ifndef INTRNG static int alpine_pic_decode_fdt(uint32_t iparent, uint32_t *intr, int *interrupt, int *trig, int *pol); -int alpine_get_devmap_base(bus_addr_t *pa, bus_addr_t *size); - -int alpine_get_devmap_base(bus_addr_t *pa, bus_addr_t *size) -{ - phandle_t node; - - if ((node = OF_finddevice("/")) == 0) - return (ENXIO); - - if ((node = fdt_find_compatible(node, "simple-bus", 1)) == 0) - return (ENXIO); - - return fdt_get_range(node, 0, pa, size); -} - -static int -alpine_get_wdt_base(uint32_t *pbase, uint32_t *psize) -{ - phandle_t node; - u_long base = 0; - u_long size = 0; - - if (pbase == NULL || psize == NULL) - return (EINVAL); - - if ((node = OF_finddevice("/")) == -1) - return (EFAULT); - - if ((node = fdt_find_compatible(node, "simple-bus", 1)) == 0) - return (EFAULT); - - if ((node = - fdt_find_compatible(node, "arm,sp805", 1)) == 0) - return (EFAULT); - - if (fdt_regsize(node, &base, &size)) - return (EFAULT); - - *pbase = base; - *psize = size; - - return (0); -} - -void -cpu_reset(void) -{ - uint32_t wdbase, wdsize; - bus_addr_t wdbaddr; - int ret; - - ret = alpine_get_wdt_base(&wdbase, &wdsize); - if (ret) { - printf("Unable to get WDT base, do power down manually..."); - goto infinite; - } - - ret = bus_space_map(fdtbus_bs_tag, al_devmap_pa + wdbase, - wdsize, 0, &wdbaddr); - if (ret) { - printf("Unable to map WDT base, do power down manually..."); - goto infinite; - } - - bus_space_write_4(fdtbus_bs_tag, wdbaddr, WDTLOCK, UNLOCK); - bus_space_write_4(fdtbus_bs_tag, wdbaddr, WDTLOAD, LOAD_MIN); - bus_space_write_4(fdtbus_bs_tag, wdbaddr, WDTCONTROL, INT_ENABLE | RESET_ENABLE); - -infinite: - while (1) {} -} - -#ifndef INTRNG static int alpine_pic_decode_fdt(uint32_t iparent, uint32_t *intr, int *interrupt, int *trig, int *pol) diff --git a/sys/arm/annapurna/alpine/alpine_machdep.c b/sys/arm/annapurna/alpine/alpine_machdep.c index 7f87c7d68984..e57b360140eb 100644 --- a/sys/arm/annapurna/alpine/alpine_machdep.c +++ b/sys/arm/annapurna/alpine/alpine_machdep.c @@ -26,66 +26,137 @@ * */ +#include "opt_ddb.h" +#include "opt_platform.h" + #include __FBSDID("$FreeBSD$"); #include #include #include -#include -#include #include #include #include #include -#include /* For trapframe_t, used in */ -#include -#include #include +#include -#include "opt_ddb.h" -#include "opt_platform.h" +#include +#include + +#include + +#include "platform_if.h" + +#define WDTLOAD 0x000 +#define LOAD_MIN 0x00000001 +#define LOAD_MAX 0xFFFFFFFF +#define WDTVALUE 0x004 +#define WDTCONTROL 0x008 +/* control register masks */ +#define INT_ENABLE (1 << 0) +#define RESET_ENABLE (1 << 1) +#define WDTLOCK 0xC00 +#define UNLOCK 0x1ACCE551 +#define LOCK 0x00000001 -#define DEVMAP_MAX_VA_ADDRESS 0xF0000000 bus_addr_t al_devmap_pa; bus_addr_t al_devmap_size; -int alpine_get_devmap_base(bus_addr_t *pa, bus_addr_t *size); - -vm_offset_t -platform_lastaddr(void) +static int +alpine_get_devmap_base(bus_addr_t *pa, bus_addr_t *size) { + phandle_t node; - return (DEVMAP_MAX_VA_ADDRESS); + if ((node = OF_finddevice("/")) == 0) + return (ENXIO); + + if ((node = fdt_find_compatible(node, "simple-bus", 1)) == 0) + return (ENXIO); + + return fdt_get_range(node, 0, pa, size); } -void -platform_probe_and_attach(void) +static int +alpine_get_wdt_base(uint32_t *pbase, uint32_t *psize) { + phandle_t node; + u_long base = 0; + u_long size = 0; -} + if (pbase == NULL || psize == NULL) + return (EINVAL); -void -platform_gpio_init(void) -{ + if ((node = OF_finddevice("/")) == -1) + return (EFAULT); -} + if ((node = fdt_find_compatible(node, "simple-bus", 1)) == 0) + return (EFAULT); -void -platform_late_init(void) -{ + if ((node = + fdt_find_compatible(node, "arm,sp805", 1)) == 0) + return (EFAULT); + if (fdt_regsize(node, &base, &size)) + return (EFAULT); + + *pbase = base; + *psize = size; + + return (0); } /* * Construct devmap table with DT-derived config data. */ -int -platform_devmap_init(void) +static int +alpine_devmap_init(platform_t plat) { alpine_get_devmap_base(&al_devmap_pa, &al_devmap_size); devmap_add_entry(al_devmap_pa, al_devmap_size); return (0); } + +static void +alpine_cpu_reset(platform_t plat) +{ + uint32_t wdbase, wdsize; + bus_addr_t wdbaddr; + int ret; + + ret = alpine_get_wdt_base(&wdbase, &wdsize); + if (ret) { + printf("Unable to get WDT base, do power down manually..."); + goto infinite; + } + + ret = bus_space_map(fdtbus_bs_tag, al_devmap_pa + wdbase, + wdsize, 0, &wdbaddr); + if (ret) { + printf("Unable to map WDT base, do power down manually..."); + goto infinite; + } + + bus_space_write_4(fdtbus_bs_tag, wdbaddr, WDTLOCK, UNLOCK); + bus_space_write_4(fdtbus_bs_tag, wdbaddr, WDTLOAD, LOAD_MIN); + bus_space_write_4(fdtbus_bs_tag, wdbaddr, WDTCONTROL, + INT_ENABLE | RESET_ENABLE); + +infinite: + while (1) {} +} + +static platform_method_t alpine_methods[] = { + PLATFORMMETHOD(platform_devmap_init, alpine_devmap_init), + PLATFORMMETHOD(platform_cpu_reset, alpine_cpu_reset), + +#ifdef SMP + PLATFORMMETHOD(platform_mp_start_ap, alpine_mp_start_ap), + PLATFORMMETHOD(platform_mp_setmaxid, alpine_mp_setmaxid), +#endif + PLATFORMMETHOD_END, +}; +FDT_PLATFORM_DEF(alpine, "alpine", 0, "annapurna,alpine", 200); diff --git a/sys/arm/annapurna/alpine/alpine_machdep_mp.c b/sys/arm/annapurna/alpine/alpine_machdep_mp.c index 4ef2db1ba0f3..7e6ea3479570 100644 --- a/sys/arm/annapurna/alpine/alpine_machdep_mp.c +++ b/sys/arm/annapurna/alpine/alpine_machdep_mp.c @@ -43,12 +43,15 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include #include +#include + #define AL_CPU_RESUME_WATERMARK_REG 0x00 #define AL_CPU_RESUME_FLAGS_REG 0x04 #define AL_CPU_RESUME_PCPU_RADDR_REG(cpu) (0x08 + 0x04 + 8*(cpu)) @@ -112,7 +115,7 @@ platform_mp_get_core_cnt(void) } void -platform_mp_setmaxid(void) +alpine_mp_setmaxid(platform_t plat) { mp_ncpus = platform_mp_get_core_cnt(); @@ -172,7 +175,7 @@ alpine_get_nb_base(u_long *pbase, u_long *psize) } void -platform_mp_start_ap(void) +alpine_mp_start_ap(platform_t plat) { uint32_t physaddr; vm_offset_t vaddr; diff --git a/sys/arm/annapurna/alpine/alpine_mp.h b/sys/arm/annapurna/alpine/alpine_mp.h new file mode 100644 index 000000000000..736b6cd36b89 --- /dev/null +++ b/sys/arm/annapurna/alpine/alpine_mp.h @@ -0,0 +1,35 @@ +/*- + * Copyright (c) 2017 Andrew Turner + * 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 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 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. + * + * $FreeBSD$ + */ + +#ifndef _ANNAPURNA_ALPINE_MP_H_ +#define _ANNAPURNA_ALPINE_MP_H_ + +void alpine_mp_start_ap(platform_t plat); +void alpine_mp_setmaxid(platform_t plat); + +#endif /* _ANNAPURNA_ALPINE_MP_H_ */ diff --git a/sys/arm/conf/ALPINE b/sys/arm/conf/ALPINE index 7ef285bf82f9..259fc5290e6d 100644 --- a/sys/arm/conf/ALPINE +++ b/sys/arm/conf/ALPINE @@ -27,6 +27,8 @@ makeoptions WERROR="-Werror" options SCHED_4BSD # 4BSD scheduler options SMP # Enable multiple cores +options PLATFORM +options PLATFORM_SMP # Interrupt controller device gic