2005-04-16 22:20:36 +00:00
|
|
|
/* $Id: p1275.c,v 1.22 2001/10/18 09:40:00 davem Exp $
|
|
|
|
* p1275.c: Sun IEEE 1275 PROM low level interface routines
|
|
|
|
*
|
|
|
|
* Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/smp.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
|
|
|
|
#include <asm/openprom.h>
|
|
|
|
#include <asm/oplib.h>
|
|
|
|
#include <asm/system.h>
|
|
|
|
#include <asm/spitfire.h>
|
|
|
|
#include <asm/pstate.h>
|
|
|
|
|
|
|
|
struct {
|
|
|
|
long prom_callback; /* 0x00 */
|
|
|
|
void (*prom_cif_handler)(long *); /* 0x08 */
|
|
|
|
unsigned long prom_cif_stack; /* 0x10 */
|
|
|
|
unsigned long prom_args [23]; /* 0x18 */
|
|
|
|
char prom_buffer [3000];
|
|
|
|
} p1275buf;
|
|
|
|
|
|
|
|
extern void prom_world(int);
|
|
|
|
|
|
|
|
extern void prom_cif_interface(void);
|
|
|
|
extern void prom_cif_callback(void);
|
|
|
|
|
|
|
|
static inline unsigned long spitfire_get_primary_context(void)
|
|
|
|
{
|
|
|
|
unsigned long ctx;
|
|
|
|
|
|
|
|
__asm__ __volatile__("ldxa [%1] %2, %0"
|
|
|
|
: "=r" (ctx)
|
|
|
|
: "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU));
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This provides SMP safety on the p1275buf. prom_callback() drops this lock
|
|
|
|
* to allow recursuve acquisition.
|
|
|
|
*/
|
|
|
|
DEFINE_SPINLOCK(prom_entry_lock);
|
|
|
|
|
[SPARC64]: Rewrite bootup sequence.
Instead of all of this cpu-specific code to remap the kernel
to the correct location, use portable firmware calls to do
this instead.
What we do now is the following in position independant
assembler:
chosen_node = prom_finddevice("/chosen");
prom_mmu_ihandle_cache = prom_getint(chosen_node, "mmu");
vaddr = 4MB_ALIGN(current_text_addr());
prom_translate(vaddr, &paddr_high, &paddr_low, &mode);
prom_boot_mapping_mode = mode;
prom_boot_mapping_phys_high = paddr_high;
prom_boot_mapping_phys_low = paddr_low;
prom_map(-1, 8 * 1024 * 1024, KERNBASE, paddr_low);
and that replaces the massive amount of by-hand TLB probing and
programming we used to do here.
The new code should also handle properly the case where the kernel
is mapped at the correct address already (think: future kexec
support).
Consequently, the bulk of remap_kernel() dies as does the entirety
of arch/sparc64/prom/map.S
We try to share some strings in the PROM library with the ones used
at bootup, and while we're here mark input strings to oplib.h routines
with "const" when appropriate.
There are many more simplifications now possible. For one thing, we
can consolidate the two copies we now have of a lot of cpu setup code
sitting in head.S and trampoline.S.
This is a significant step towards CONFIG_DEBUG_PAGEALLOC support.
Signed-off-by: David S. Miller <davem@davemloft.net>
2005-09-23 03:11:33 +00:00
|
|
|
long p1275_cmd(const char *service, long fmt, ...)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
char *p, *q;
|
|
|
|
unsigned long flags;
|
|
|
|
int nargs, nrets, i;
|
|
|
|
va_list list;
|
|
|
|
long attrs, x;
|
|
|
|
|
|
|
|
p = p1275buf.prom_buffer;
|
|
|
|
BUG_ON((spitfire_get_primary_context() & CTX_NR_MASK) != 0);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&prom_entry_lock, flags);
|
|
|
|
|
|
|
|
p1275buf.prom_args[0] = (unsigned long)p; /* service */
|
|
|
|
strcpy (p, service);
|
|
|
|
p = (char *)(((long)(strchr (p, 0) + 8)) & ~7);
|
|
|
|
p1275buf.prom_args[1] = nargs = (fmt & 0x0f); /* nargs */
|
|
|
|
p1275buf.prom_args[2] = nrets = ((fmt & 0xf0) >> 4); /* nrets */
|
|
|
|
attrs = fmt >> 8;
|
|
|
|
va_start(list, fmt);
|
|
|
|
for (i = 0; i < nargs; i++, attrs >>= 3) {
|
|
|
|
switch (attrs & 0x7) {
|
|
|
|
case P1275_ARG_NUMBER:
|
|
|
|
p1275buf.prom_args[i + 3] =
|
|
|
|
(unsigned)va_arg(list, long);
|
|
|
|
break;
|
|
|
|
case P1275_ARG_IN_64B:
|
|
|
|
p1275buf.prom_args[i + 3] =
|
|
|
|
va_arg(list, unsigned long);
|
|
|
|
break;
|
|
|
|
case P1275_ARG_IN_STRING:
|
|
|
|
strcpy (p, va_arg(list, char *));
|
|
|
|
p1275buf.prom_args[i + 3] = (unsigned long)p;
|
|
|
|
p = (char *)(((long)(strchr (p, 0) + 8)) & ~7);
|
|
|
|
break;
|
|
|
|
case P1275_ARG_OUT_BUF:
|
|
|
|
(void) va_arg(list, char *);
|
|
|
|
p1275buf.prom_args[i + 3] = (unsigned long)p;
|
|
|
|
x = va_arg(list, long);
|
|
|
|
i++; attrs >>= 3;
|
|
|
|
p = (char *)(((long)(p + (int)x + 7)) & ~7);
|
|
|
|
p1275buf.prom_args[i + 3] = x;
|
|
|
|
break;
|
|
|
|
case P1275_ARG_IN_BUF:
|
|
|
|
q = va_arg(list, char *);
|
|
|
|
p1275buf.prom_args[i + 3] = (unsigned long)p;
|
|
|
|
x = va_arg(list, long);
|
|
|
|
i++; attrs >>= 3;
|
|
|
|
memcpy (p, q, (int)x);
|
|
|
|
p = (char *)(((long)(p + (int)x + 7)) & ~7);
|
|
|
|
p1275buf.prom_args[i + 3] = x;
|
|
|
|
break;
|
|
|
|
case P1275_ARG_OUT_32B:
|
|
|
|
(void) va_arg(list, char *);
|
|
|
|
p1275buf.prom_args[i + 3] = (unsigned long)p;
|
|
|
|
p += 32;
|
|
|
|
break;
|
|
|
|
case P1275_ARG_IN_FUNCTION:
|
|
|
|
p1275buf.prom_args[i + 3] =
|
|
|
|
(unsigned long)prom_cif_callback;
|
|
|
|
p1275buf.prom_callback = va_arg(list, long);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
va_end(list);
|
|
|
|
|
|
|
|
prom_world(1);
|
|
|
|
prom_cif_interface();
|
|
|
|
prom_world(0);
|
|
|
|
|
|
|
|
attrs = fmt >> 8;
|
|
|
|
va_start(list, fmt);
|
|
|
|
for (i = 0; i < nargs; i++, attrs >>= 3) {
|
|
|
|
switch (attrs & 0x7) {
|
|
|
|
case P1275_ARG_NUMBER:
|
|
|
|
(void) va_arg(list, long);
|
|
|
|
break;
|
|
|
|
case P1275_ARG_IN_STRING:
|
|
|
|
(void) va_arg(list, char *);
|
|
|
|
break;
|
|
|
|
case P1275_ARG_IN_FUNCTION:
|
|
|
|
(void) va_arg(list, long);
|
|
|
|
break;
|
|
|
|
case P1275_ARG_IN_BUF:
|
|
|
|
(void) va_arg(list, char *);
|
|
|
|
(void) va_arg(list, long);
|
|
|
|
i++; attrs >>= 3;
|
|
|
|
break;
|
|
|
|
case P1275_ARG_OUT_BUF:
|
|
|
|
p = va_arg(list, char *);
|
|
|
|
x = va_arg(list, long);
|
|
|
|
memcpy (p, (char *)(p1275buf.prom_args[i + 3]), (int)x);
|
|
|
|
i++; attrs >>= 3;
|
|
|
|
break;
|
|
|
|
case P1275_ARG_OUT_32B:
|
|
|
|
p = va_arg(list, char *);
|
|
|
|
memcpy (p, (char *)(p1275buf.prom_args[i + 3]), 32);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
va_end(list);
|
|
|
|
x = p1275buf.prom_args [nargs + 3];
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&prom_entry_lock, flags);
|
|
|
|
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
void prom_cif_init(void *cif_handler, void *cif_stack)
|
|
|
|
{
|
|
|
|
p1275buf.prom_cif_handler = (void (*)(long *))cif_handler;
|
|
|
|
p1275buf.prom_cif_stack = (unsigned long)cif_stack;
|
|
|
|
}
|