Now that we have a working OF_printf() since r230631 and a OF_panic()

helper since r230632, use these for output and panicing during the
early cycles and move cninit() until after the static per-CPU data
has been set up. This solves a couple of issue regarding the non-
availability of the static per-CPU data:
- panic() not working and only making things worse when called,
- having to supply a special DELAY() implementation to the low-level
  console drivers,
- curthread accesses of mutex(9) usage in low-level console drivers
  that aren't conditional due to compiler optimizations (basically,
  this is the problem described in r227537 but in this case for
  keyboards attached via uart(4)). [1]

PR:	164123 [1]
This commit is contained in:
marius 2012-01-27 23:21:54 +00:00
parent 43204e516a
commit 8ec59afebb
4 changed files with 25 additions and 90 deletions

View File

@ -1,27 +1,5 @@
/*-
* Copyright (c) 2001 Jake Burkholder.
* 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.
* This file is in the public domain.
*
* $FreeBSD$
*/
@ -29,10 +7,4 @@
#ifndef _MACHINE_CLOCK_H_
#define _MACHINE_CLOCK_H_
extern void (*delay_func)(int usec);
extern u_long clock_boot;
void delay_boot(int usec);
void delay_tick(int usec);
#endif /* !_MACHINE_CLOCK_H_ */

View File

@ -142,24 +142,24 @@ cache_init(struct pcpu *pcpu)
"l2-cache-line-size", pcpu->pc_cache.ec_linesize) == -1 ||
OF_GET(pcpu->pc_node, !use_new_prop ? "ecache-associativity" :
"l2-cache-associativity", pcpu->pc_cache.ec_assoc) == -1)
panic("cache_init: could not retrieve cache parameters");
OF_panic("%s: could not retrieve cache parameters", __func__);
set = pcpu->pc_cache.ic_size / pcpu->pc_cache.ic_assoc;
if ((set & ~(1UL << (ffs(set) - 1))) != 0)
panic("cache_init: I$ set size not a power of 2");
OF_panic("%s: I$ set size not a power of 2", __func__);
if ((pcpu->pc_cache.dc_size &
~(1UL << (ffs(pcpu->pc_cache.dc_size) - 1))) != 0)
panic("cache_init: D$ size not a power of 2");
OF_panic("%s: D$ size not a power of 2", __func__);
/*
* For CPUs which don't support unaliasing in hardware ensure that
* the data cache doesn't have too many virtual colors.
*/
if (dcache_color_ignore == 0 && ((pcpu->pc_cache.dc_size /
pcpu->pc_cache.dc_assoc) / PAGE_SIZE) != DCACHE_COLORS)
panic("cache_init: too many D$ colors");
OF_panic("%s: too many D$ colors", __func__);
set = pcpu->pc_cache.ec_size / pcpu->pc_cache.ec_assoc;
if ((set & ~(1UL << (ffs(set) - 1))) != 0)
panic("cache_init: E$ set size not a power of 2");
OF_panic("%s: E$ set size not a power of 2", __func__);
if (pcpu->pc_impl >= CPU_IMPL_ULTRASPARCIII) {
cache_enable = cheetah_cache_enable;
@ -184,5 +184,5 @@ cache_init(struct pcpu *pcpu)
tlb_flush_nonlocked = spitfire_tlb_flush_nonlocked;
tlb_flush_user = spitfire_tlb_flush_user;
} else
panic("cache_init: unknown CPU");
OF_panic("%s: unknown CPU", __func__);
}

View File

@ -33,35 +33,11 @@ __FBSDID("$FreeBSD$");
#include <sys/proc.h>
#include <sys/sched.h>
#include <machine/clock.h>
#include <machine/cpu.h>
#include <machine/cpufunc.h>
void (*delay_func)(int usec);
u_long clock_boot;
void
DELAY(int usec)
{
(*delay_func)(usec);
}
void
delay_boot(int usec)
{
u_long end;
if (usec < 0)
return;
end = rd(tick) + (u_long)usec * clock_boot / 1000000;
while (rd(tick) < end)
cpu_spinwait();
}
void
delay_tick(int usec)
{
u_long end;

View File

@ -88,7 +88,6 @@ __FBSDID("$FreeBSD$");
#include <machine/bus.h>
#include <machine/cache.h>
#include <machine/clock.h>
#include <machine/cmt.h>
#include <machine/cpu.h>
#include <machine/fireplane.h>
@ -376,7 +375,7 @@ sparc64_init(caddr_t mdp, u_long o1, u_long o2, u_long o3, ofw_vec_t *vec)
/*
* Parse metadata if present and fetch parameters. Must be before the
* console is inited so cninit gets the right value of boothowto.
* console is inited so cninit() gets the right value of boothowto.
*/
if (mdp != NULL) {
preload_metadata = mdp;
@ -421,37 +420,19 @@ sparc64_init(caddr_t mdp, u_long o1, u_long o2, u_long o3, ofw_vec_t *vec)
root = OF_peer(0);
pc->pc_node = find_bsp(root, pc->pc_mid, cpu_impl);
if (pc->pc_node == 0)
OF_exit();
OF_panic("%s: cannot find boot CPU node", __func__);
if (OF_getprop(pc->pc_node, "clock-frequency", &pc->pc_clock,
sizeof(pc->pc_clock)) <= 0)
OF_exit();
/*
* Provide a DELAY() that works before PCPU_REG is set. We can't
* set PCPU_REG without also taking over the trap table or the
* firmware will overwrite it. Unfortunately, it's way to early
* to also take over the trap table at this point.
*/
clock_boot = pc->pc_clock;
delay_func = delay_boot;
/*
* Initialize the console before printing anything.
* NB: the low-level console drivers require a working DELAY() at
* this point.
*/
cninit();
OF_panic("%s: cannot determine boot CPU clock", __func__);
/*
* Panic if there is no metadata. Most likely the kernel was booted
* directly, instead of through loader(8).
*/
if (mdp == NULL || kmdp == NULL || end == 0 ||
kernel_tlb_slots == 0 || kernel_tlbs == NULL) {
printf("sparc64_init: missing loader metadata.\n"
"This probably means you are not using loader(8).\n");
panic("sparc64_init");
}
kernel_tlb_slots == 0 || kernel_tlbs == NULL)
OF_panic("%s: missing loader metadata.\nThis probably means "
"you are not using loader(8).", __func__);
/*
* Work around the broken loader behavior of not demapping no
@ -461,7 +442,7 @@ sparc64_init(caddr_t mdp, u_long o1, u_long o2, u_long o3, ofw_vec_t *vec)
for (va = KERNBASE + (kernel_tlb_slots - 1) * PAGE_SIZE_4M;
va >= roundup2(end, PAGE_SIZE_4M); va -= PAGE_SIZE_4M) {
if (bootverbose)
printf("demapping unused kernel TLB slot "
OF_printf("demapping unused kernel TLB slot "
"(va %#lx - %#lx)\n", va, va + PAGE_SIZE_4M - 1);
stxa(TLB_DEMAP_VA(va) | TLB_DEMAP_PRIMARY | TLB_DEMAP_PAGE,
ASI_DMMU_DEMAP, 0);
@ -479,13 +460,15 @@ sparc64_init(caddr_t mdp, u_long o1, u_long o2, u_long o3, ofw_vec_t *vec)
*/
if (OF_getprop(pc->pc_node, "#dtlb-entries", &dtlb_slots,
sizeof(dtlb_slots)) == -1)
panic("sparc64_init: cannot determine number of dTLB slots");
OF_panic("%s: cannot determine number of dTLB slots",
__func__);
if (OF_getprop(pc->pc_node, "#itlb-entries", &itlb_slots,
sizeof(itlb_slots)) == -1)
panic("sparc64_init: cannot determine number of iTLB slots");
OF_panic("%s: cannot determine number of iTLB slots",
__func__);
/*
* Initialize and enable the caches. Note that his may include
* Initialize and enable the caches. Note that this may include
* applying workarounds.
*/
cache_init(pc);
@ -573,9 +556,13 @@ sparc64_init(caddr_t mdp, u_long o1, u_long o2, u_long o3, ofw_vec_t *vec)
sun4u_set_traptable(tl0_base);
/*
* It's now safe to use the real DELAY().
* Initialize the console.
* NB: the low-level console drivers require a working DELAY() and
* some compiler optimizations may cause the curthread accesses of
* mutex(9) to be factored out even if the latter aren't actually
* called, both requiring PCPU_REG to be set.
*/
delay_func = delay_tick;
cninit();
/*
* Initialize the dynamic per-CPU area for the BSP and the message