From owner-svn-src-all@freebsd.org Tue Jul 4 12:26:49 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5A1DCD9079A; Tue, 4 Jul 2017 12:26:49 +0000 (UTC) (envelope-from andrew@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 35DC9799BB; Tue, 4 Jul 2017 12:26:49 +0000 (UTC) (envelope-from andrew@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v64CQmBs096062; Tue, 4 Jul 2017 12:26:48 GMT (envelope-from andrew@FreeBSD.org) Received: (from andrew@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v64CQmT9096057; Tue, 4 Jul 2017 12:26:48 GMT (envelope-from andrew@FreeBSD.org) Message-Id: <201707041226.v64CQmT9096057@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: andrew set sender to andrew@FreeBSD.org using -f From: Andrew Turner Date: Tue, 4 Jul 2017 12:26:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r320643 - in head/sys/arm: annapurna/alpine conf X-SVN-Group: head X-SVN-Commit-Author: andrew X-SVN-Commit-Paths: in head/sys/arm: annapurna/alpine conf X-SVN-Commit-Revision: 320643 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Jul 2017 12:26:49 -0000 Author: andrew Date: Tue Jul 4 12:26:47 2017 New Revision: 320643 URL: https://svnweb.freebsd.org/changeset/base/320643 Log: Add PLATFORM and PLATFORM_SMP support to the ALPINE kernel configuration. This will help move it to be part of GENERIC. Added: head/sys/arm/annapurna/alpine/alpine_mp.h (contents, props changed) Modified: head/sys/arm/annapurna/alpine/alpine_common.c head/sys/arm/annapurna/alpine/alpine_machdep.c head/sys/arm/annapurna/alpine/alpine_machdep_mp.c head/sys/arm/conf/ALPINE Modified: head/sys/arm/annapurna/alpine/alpine_common.c ============================================================================== --- head/sys/arm/annapurna/alpine/alpine_common.c Tue Jul 4 12:17:49 2017 (r320642) +++ head/sys/arm/annapurna/alpine/alpine_common.c Tue Jul 4 12:26:47 2017 (r320643) @@ -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) Modified: head/sys/arm/annapurna/alpine/alpine_machdep.c ============================================================================== --- head/sys/arm/annapurna/alpine/alpine_machdep.c Tue Jul 4 12:17:49 2017 (r320642) +++ head/sys/arm/annapurna/alpine/alpine_machdep.c Tue Jul 4 12:26:47 2017 (r320643) @@ -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 -#define DEVMAP_MAX_VA_ADDRESS 0xF0000000 +#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 + 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); -void -platform_probe_and_attach(void) -{ + if ((node = fdt_find_compatible(node, "simple-bus", 1)) == 0) + return (ENXIO); + return fdt_get_range(node, 0, pa, size); } -void -platform_gpio_init(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_late_init(void) -{ + 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); } /* * 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); Modified: head/sys/arm/annapurna/alpine/alpine_machdep_mp.c ============================================================================== --- head/sys/arm/annapurna/alpine/alpine_machdep_mp.c Tue Jul 4 12:17:49 2017 (r320642) +++ head/sys/arm/annapurna/alpine/alpine_machdep_mp.c Tue Jul 4 12:26:47 2017 (r320643) @@ -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; Added: head/sys/arm/annapurna/alpine/alpine_mp.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/arm/annapurna/alpine/alpine_mp.h Tue Jul 4 12:26:47 2017 (r320643) @@ -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_ */ Modified: head/sys/arm/conf/ALPINE ============================================================================== --- head/sys/arm/conf/ALPINE Tue Jul 4 12:17:49 2017 (r320642) +++ head/sys/arm/conf/ALPINE Tue Jul 4 12:26:47 2017 (r320643) @@ -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