Path: blob/main/sys/powerpc/booke/platform_bare.c
104874 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2008-2012 Semihalf.4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9*10* 1. Redistributions of source code must retain the above copyright11* notice, this list of conditions and the following disclaimer.12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15*16* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR17* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES18* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.19* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,20* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT21* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,22* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY23* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF25* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.26*/2728#include <sys/param.h>29#include <sys/systm.h>30#include <sys/kernel.h>31#include <sys/bus.h>32#include <sys/pcpu.h>33#include <sys/proc.h>34#include <sys/smp.h>3536#include <dev/ofw/openfirm.h>3738#include <machine/platform.h>39#include <machine/platformvar.h>4041#include "platform_if.h"4243extern uint32_t *bootinfo;4445static int bare_probe(platform_t);46static void bare_mem_regions(platform_t, struct mem_region *phys, int *physsz,47struct mem_region *avail, int *availsz);48static u_long bare_timebase_freq(platform_t, struct cpuref *cpuref);4950static void bare_reset(platform_t);5152static platform_method_t bare_methods[] = {53PLATFORMMETHOD(platform_probe, bare_probe),54PLATFORMMETHOD(platform_mem_regions, bare_mem_regions),55PLATFORMMETHOD(platform_timebase_freq, bare_timebase_freq),5657PLATFORMMETHOD(platform_reset, bare_reset),5859PLATFORMMETHOD_END60};6162static platform_def_t bare_platform = {63"bare",64bare_methods,65066};6768PLATFORM_DEF(bare_platform);6970static int71bare_probe(platform_t plat)72{7374if (OF_peer(0) == -1) /* Needs device tree to work */75return (ENXIO);7677return (BUS_PROBE_GENERIC);78}7980void81bare_mem_regions(platform_t plat, struct mem_region *phys, int *physsz,82struct mem_region *avail, int *availsz)83{8485ofw_mem_regions(phys, physsz, avail, availsz);86}8788static u_long89bare_timebase_freq(platform_t plat, struct cpuref *cpuref)90{91u_long ticks;92phandle_t cpus, child;93pcell_t freq;9495if (bootinfo != NULL) {96if (bootinfo[0] == 1) {97/* Backward compatibility. See 8-STABLE. */98ticks = bootinfo[3] >> 3;99} else {100/* Compatibility with Juniper's loader. */101ticks = bootinfo[5] >> 3;102}103} else104ticks = 0;105106if ((cpus = OF_finddevice("/cpus")) == -1)107goto out;108109if ((child = OF_child(cpus)) == 0)110goto out;111112switch (OF_getproplen(child, "timebase-frequency")) {113case 4:114{115uint32_t tbase;116OF_getprop(child, "timebase-frequency", &tbase, sizeof(tbase));117ticks = tbase;118return (ticks);119}120case 8:121{122uint64_t tbase;123OF_getprop(child, "timebase-frequency", &tbase, sizeof(tbase));124ticks = tbase;125return (ticks);126}127default:128break;129}130131freq = 0;132if (OF_getprop(child, "bus-frequency", (void *)&freq,133sizeof(freq)) <= 0)134goto out;135136/*137* Time Base and Decrementer are updated every 8 CCB bus clocks.138* HID0[SEL_TBCLK] = 0139*/140if (freq != 0)141ticks = freq / 8;142143out:144if (ticks <= 0)145panic("Unable to determine timebase frequency!");146147return (ticks);148}149150static void151bare_reset(platform_t plat)152{153154printf("Reset failed...\n");155while (1)156;157}158159160