aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sparc/prom
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 15:20:36 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 15:20:36 -0700
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/sparc/prom
downloadkernel_samsung_smdk4412-1da177e4c3f41524e886b7f1b8a0c1fc7321cac2.zip
kernel_samsung_smdk4412-1da177e4c3f41524e886b7f1b8a0c1fc7321cac2.tar.gz
kernel_samsung_smdk4412-1da177e4c3f41524e886b7f1b8a0c1fc7321cac2.tar.bz2
Linux-2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'arch/sparc/prom')
-rw-r--r--arch/sparc/prom/Makefile9
-rw-r--r--arch/sparc/prom/bootstr.c63
-rw-r--r--arch/sparc/prom/console.c220
-rw-r--r--arch/sparc/prom/devmap.c54
-rw-r--r--arch/sparc/prom/devops.c89
-rw-r--r--arch/sparc/prom/init.c95
-rw-r--r--arch/sparc/prom/memory.c216
-rw-r--r--arch/sparc/prom/misc.c139
-rw-r--r--arch/sparc/prom/mp.c121
-rw-r--r--arch/sparc/prom/palloc.c44
-rw-r--r--arch/sparc/prom/printf.c46
-rw-r--r--arch/sparc/prom/ranges.c118
-rw-r--r--arch/sparc/prom/segment.c29
-rw-r--r--arch/sparc/prom/sun4prom.c161
-rw-r--r--arch/sparc/prom/tree.c364
15 files changed, 1768 insertions, 0 deletions
diff --git a/arch/sparc/prom/Makefile b/arch/sparc/prom/Makefile
new file mode 100644
index 0000000..2b217ee
--- /dev/null
+++ b/arch/sparc/prom/Makefile
@@ -0,0 +1,9 @@
+# $Id: Makefile,v 1.8 2000/12/15 00:41:22 davem Exp $
+# Makefile for the Sun Boot PROM interface library under
+# Linux.
+#
+
+lib-y := bootstr.o devmap.o devops.o init.o memory.o misc.o mp.o \
+ palloc.o ranges.o segment.o console.o printf.o tree.o
+
+lib-$(CONFIG_SUN4) += sun4prom.o
diff --git a/arch/sparc/prom/bootstr.c b/arch/sparc/prom/bootstr.c
new file mode 100644
index 0000000..cfdeac2
--- /dev/null
+++ b/arch/sparc/prom/bootstr.c
@@ -0,0 +1,63 @@
+/* $Id: bootstr.c,v 1.20 2000/02/08 20:24:23 davem Exp $
+ * bootstr.c: Boot string/argument acquisition from the PROM.
+ *
+ * Copyright(C) 1995 David S. Miller (davem@caip.rutgers.edu)
+ */
+
+#include <linux/string.h>
+#include <asm/oplib.h>
+#include <asm/sun4prom.h>
+#include <linux/init.h>
+
+#define BARG_LEN 256
+static char barg_buf[BARG_LEN] = { 0 };
+static char fetched __initdata = 0;
+
+extern linux_sun4_romvec *sun4_romvec;
+
+char * __init
+prom_getbootargs(void)
+{
+ int iter;
+ char *cp, *arg;
+
+ /* This check saves us from a panic when bootfd patches args. */
+ if (fetched) {
+ return barg_buf;
+ }
+
+ switch(prom_vers) {
+ case PROM_V0:
+ case PROM_SUN4:
+ cp = barg_buf;
+ /* Start from 1 and go over fd(0,0,0)kernel */
+ for(iter = 1; iter < 8; iter++) {
+ arg = (*(romvec->pv_v0bootargs))->argv[iter];
+ if(arg == 0) break;
+ while(*arg != 0) {
+ /* Leave place for space and null. */
+ if(cp >= barg_buf + BARG_LEN-2){
+ /* We might issue a warning here. */
+ break;
+ }
+ *cp++ = *arg++;
+ }
+ *cp++ = ' ';
+ }
+ *cp = 0;
+ break;
+ case PROM_V2:
+ case PROM_V3:
+ /*
+ * V3 PROM cannot supply as with more than 128 bytes
+ * of an argument. But a smart bootstrap loader can.
+ */
+ strlcpy(barg_buf, *romvec->pv_v2bootargs.bootargs, sizeof(barg_buf));
+ break;
+ default:
+ break;
+ }
+
+ fetched = 1;
+ return barg_buf;
+}
diff --git a/arch/sparc/prom/console.c b/arch/sparc/prom/console.c
new file mode 100644
index 0000000..4e6e41d
--- /dev/null
+++ b/arch/sparc/prom/console.c
@@ -0,0 +1,220 @@
+/* $Id: console.c,v 1.25 2001/10/30 04:54:22 davem Exp $
+ * console.c: Routines that deal with sending and receiving IO
+ * to/from the current console device using the PROM.
+ *
+ * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
+ * Copyright (C) 1998 Pete Zaitcev <zaitcev@yahoo.com>
+ */
+
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <asm/openprom.h>
+#include <asm/sun4prom.h>
+#include <asm/oplib.h>
+#include <asm/system.h>
+#include <linux/string.h>
+
+extern void restore_current(void);
+
+static char con_name_jmc[] = "/obio/su@"; /* "/obio/su@0,3002f8"; */
+#define CON_SIZE_JMC (sizeof(con_name_jmc))
+
+/* Non blocking get character from console input device, returns -1
+ * if no input was taken. This can be used for polling.
+ */
+int
+prom_nbgetchar(void)
+{
+ static char inc;
+ int i = -1;
+ unsigned long flags;
+
+ spin_lock_irqsave(&prom_lock, flags);
+ switch(prom_vers) {
+ case PROM_V0:
+ case PROM_SUN4:
+ i = (*(romvec->pv_nbgetchar))();
+ break;
+ case PROM_V2:
+ case PROM_V3:
+ if( (*(romvec->pv_v2devops).v2_dev_read)(*romvec->pv_v2bootargs.fd_stdin , &inc, 0x1) == 1) {
+ i = inc;
+ } else {
+ i = -1;
+ }
+ break;
+ default:
+ i = -1;
+ break;
+ };
+ restore_current();
+ spin_unlock_irqrestore(&prom_lock, flags);
+ return i; /* Ugh, we could spin forever on unsupported proms ;( */
+}
+
+/* Non blocking put character to console device, returns -1 if
+ * unsuccessful.
+ */
+int
+prom_nbputchar(char c)
+{
+ static char outc;
+ unsigned long flags;
+ int i = -1;
+
+ spin_lock_irqsave(&prom_lock, flags);
+ switch(prom_vers) {
+ case PROM_V0:
+ case PROM_SUN4:
+ i = (*(romvec->pv_nbputchar))(c);
+ break;
+ case PROM_V2:
+ case PROM_V3:
+ outc = c;
+ if( (*(romvec->pv_v2devops).v2_dev_write)(*romvec->pv_v2bootargs.fd_stdout, &outc, 0x1) == 1)
+ i = 0;
+ else
+ i = -1;
+ break;
+ default:
+ i = -1;
+ break;
+ };
+ restore_current();
+ spin_unlock_irqrestore(&prom_lock, flags);
+ return i; /* Ugh, we could spin forever on unsupported proms ;( */
+}
+
+/* Blocking version of get character routine above. */
+char
+prom_getchar(void)
+{
+ int character;
+ while((character = prom_nbgetchar()) == -1) ;
+ return (char) character;
+}
+
+/* Blocking version of put character routine above. */
+void
+prom_putchar(char c)
+{
+ while(prom_nbputchar(c) == -1) ;
+ return;
+}
+
+/* Query for input device type */
+enum prom_input_device
+prom_query_input_device(void)
+{
+ unsigned long flags;
+ int st_p;
+ char propb[64];
+ char *p;
+ int propl;
+
+ switch(prom_vers) {
+ case PROM_V0:
+ case PROM_V2:
+ case PROM_SUN4:
+ default:
+ switch(*romvec->pv_stdin) {
+ case PROMDEV_KBD: return PROMDEV_IKBD;
+ case PROMDEV_TTYA: return PROMDEV_ITTYA;
+ case PROMDEV_TTYB: return PROMDEV_ITTYB;
+ default:
+ return PROMDEV_I_UNK;
+ };
+ case PROM_V3:
+ spin_lock_irqsave(&prom_lock, flags);
+ st_p = (*romvec->pv_v2devops.v2_inst2pkg)(*romvec->pv_v2bootargs.fd_stdin);
+ restore_current();
+ spin_unlock_irqrestore(&prom_lock, flags);
+ if(prom_node_has_property(st_p, "keyboard"))
+ return PROMDEV_IKBD;
+ if (prom_getproperty(st_p, "name", propb, sizeof(propb)) != -1) {
+ if(strncmp(propb, "keyboard", sizeof("serial")) == 0)
+ return PROMDEV_IKBD;
+ }
+ if (prom_getproperty(st_p, "device_type", propb, sizeof(propb)) != -1) {
+ if(strncmp(propb, "serial", sizeof("serial")))
+ return PROMDEV_I_UNK;
+ }
+ propl = prom_getproperty(prom_root_node, "stdin-path", propb, sizeof(propb));
+ if(propl > 2) {
+ p = propb;
+ while(*p) p++; p -= 2;
+ if(p[0] == ':') {
+ if(p[1] == 'a')
+ return PROMDEV_ITTYA;
+ else if(p[1] == 'b')
+ return PROMDEV_ITTYB;
+ }
+ }
+ return PROMDEV_I_UNK;
+ }
+}
+
+/* Query for output device type */
+
+enum prom_output_device
+prom_query_output_device(void)
+{
+ unsigned long flags;
+ int st_p;
+ char propb[64];
+ char *p;
+ int propl;
+
+ switch(prom_vers) {
+ case PROM_V0:
+ case PROM_SUN4:
+ switch(*romvec->pv_stdin) {
+ case PROMDEV_SCREEN: return PROMDEV_OSCREEN;
+ case PROMDEV_TTYA: return PROMDEV_OTTYA;
+ case PROMDEV_TTYB: return PROMDEV_OTTYB;
+ };
+ break;
+ case PROM_V2:
+ case PROM_V3:
+ spin_lock_irqsave(&prom_lock, flags);
+ st_p = (*romvec->pv_v2devops.v2_inst2pkg)(*romvec->pv_v2bootargs.fd_stdout);
+ restore_current();
+ spin_unlock_irqrestore(&prom_lock, flags);
+ propl = prom_getproperty(st_p, "device_type", propb, sizeof(propb));
+ if (propl == sizeof("display") &&
+ strncmp("display", propb, sizeof("display")) == 0)
+ {
+ return PROMDEV_OSCREEN;
+ }
+ if(prom_vers == PROM_V3) {
+ if(propl >= 0 &&
+ strncmp("serial", propb, sizeof("serial")) != 0)
+ return PROMDEV_O_UNK;
+ propl = prom_getproperty(prom_root_node, "stdout-path",
+ propb, sizeof(propb));
+ if(propl == CON_SIZE_JMC &&
+ strncmp(propb, con_name_jmc, CON_SIZE_JMC) == 0)
+ return PROMDEV_OTTYA;
+ if(propl > 2) {
+ p = propb;
+ while(*p) p++; p-= 2;
+ if(p[0]==':') {
+ if(p[1] == 'a')
+ return PROMDEV_OTTYA;
+ else if(p[1] == 'b')
+ return PROMDEV_OTTYB;
+ }
+ }
+ } else {
+ switch(*romvec->pv_stdin) {
+ case PROMDEV_TTYA: return PROMDEV_OTTYA;
+ case PROMDEV_TTYB: return PROMDEV_OTTYB;
+ };
+ }
+ break;
+ default:
+ ;
+ };
+ return PROMDEV_O_UNK;
+}
diff --git a/arch/sparc/prom/devmap.c b/arch/sparc/prom/devmap.c
new file mode 100644
index 0000000..eb12073
--- /dev/null
+++ b/arch/sparc/prom/devmap.c
@@ -0,0 +1,54 @@
+/* $Id: devmap.c,v 1.7 2000/08/26 02:38:03 anton Exp $
+ * promdevmap.c: Map device/IO areas to virtual addresses.
+ *
+ * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
+ */
+
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+
+#include <asm/openprom.h>
+#include <asm/oplib.h>
+
+extern void restore_current(void);
+
+/* Just like the routines in palloc.c, these should not be used
+ * by the kernel at all. Bootloader facility mainly. And again,
+ * this is only available on V2 proms and above.
+ */
+
+/* Map physical device address 'paddr' in IO space 'ios' of size
+ * 'num_bytes' to a virtual address, with 'vhint' being a hint to
+ * the prom as to where you would prefer the mapping. We return
+ * where the prom actually mapped it.
+ */
+char *
+prom_mapio(char *vhint, int ios, unsigned int paddr, unsigned int num_bytes)
+{
+ unsigned long flags;
+ char *ret;
+
+ spin_lock_irqsave(&prom_lock, flags);
+ if((num_bytes == 0) || (paddr == 0)) ret = (char *) 0x0;
+ else
+ ret = (*(romvec->pv_v2devops.v2_dumb_mmap))(vhint, ios, paddr,
+ num_bytes);
+ restore_current();
+ spin_unlock_irqrestore(&prom_lock, flags);
+ return ret;
+}
+
+/* Unmap an IO/device area that was mapped using the above routine. */
+void
+prom_unmapio(char *vaddr, unsigned int num_bytes)
+{
+ unsigned long flags;
+
+ if(num_bytes == 0x0) return;
+ spin_lock_irqsave(&prom_lock, flags);
+ (*(romvec->pv_v2devops.v2_dumb_munmap))(vaddr, num_bytes);
+ restore_current();
+ spin_unlock_irqrestore(&prom_lock, flags);
+ return;
+}
diff --git a/arch/sparc/prom/devops.c b/arch/sparc/prom/devops.c
new file mode 100644
index 0000000..61919b5
--- /dev/null
+++ b/arch/sparc/prom/devops.c
@@ -0,0 +1,89 @@
+/* $Id: devops.c,v 1.13 2000/08/26 02:38:03 anton Exp $
+ * devops.c: Device operations using the PROM.
+ *
+ * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
+ */
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+
+#include <asm/openprom.h>
+#include <asm/oplib.h>
+
+extern void restore_current(void);
+
+/* Open the device described by the string 'dstr'. Returns the handle
+ * to that device used for subsequent operations on that device.
+ * Returns -1 on failure.
+ */
+int
+prom_devopen(char *dstr)
+{
+ int handle;
+ unsigned long flags;
+ spin_lock_irqsave(&prom_lock, flags);
+ switch(prom_vers) {
+ case PROM_V0:
+ handle = (*(romvec->pv_v0devops.v0_devopen))(dstr);
+ if(handle == 0) handle = -1;
+ break;
+ case PROM_V2:
+ case PROM_V3:
+ handle = (*(romvec->pv_v2devops.v2_dev_open))(dstr);
+ break;
+ default:
+ handle = -1;
+ break;
+ };
+ restore_current();
+ spin_unlock_irqrestore(&prom_lock, flags);
+
+ return handle;
+}
+
+/* Close the device described by device handle 'dhandle'. */
+int
+prom_devclose(int dhandle)
+{
+ unsigned long flags;
+ spin_lock_irqsave(&prom_lock, flags);
+ switch(prom_vers) {
+ case PROM_V0:
+ (*(romvec->pv_v0devops.v0_devclose))(dhandle);
+ break;
+ case PROM_V2:
+ case PROM_V3:
+ (*(romvec->pv_v2devops.v2_dev_close))(dhandle);
+ break;
+ default:
+ break;
+ };
+ restore_current();
+ spin_unlock_irqrestore(&prom_lock, flags);
+ return 0;
+}
+
+/* Seek to specified location described by 'seekhi' and 'seeklo'
+ * for device 'dhandle'.
+ */
+void
+prom_seek(int dhandle, unsigned int seekhi, unsigned int seeklo)
+{
+ unsigned long flags;
+ spin_lock_irqsave(&prom_lock, flags);
+ switch(prom_vers) {
+ case PROM_V0:
+ (*(romvec->pv_v0devops.v0_seekdev))(dhandle, seekhi, seeklo);
+ break;
+ case PROM_V2:
+ case PROM_V3:
+ (*(romvec->pv_v2devops.v2_dev_seek))(dhandle, seekhi, seeklo);
+ break;
+ default:
+ break;
+ };
+ restore_current();
+ spin_unlock_irqrestore(&prom_lock, flags);
+
+ return;
+}
diff --git a/arch/sparc/prom/init.c b/arch/sparc/prom/init.c
new file mode 100644
index 0000000..b83409c
--- /dev/null
+++ b/arch/sparc/prom/init.c
@@ -0,0 +1,95 @@
+/* $Id: init.c,v 1.14 2000/01/29 01:09:12 anton Exp $
+ * init.c: Initialize internal variables used by the PROM
+ * library functions.
+ *
+ * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
+ * Copyright (C) 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
+ */
+
+#include <linux/config.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+
+#include <asm/openprom.h>
+#include <asm/oplib.h>
+#include <asm/sun4prom.h>
+
+struct linux_romvec *romvec;
+enum prom_major_version prom_vers;
+unsigned int prom_rev, prom_prev;
+linux_sun4_romvec *sun4_romvec;
+
+/* The root node of the prom device tree. */
+int prom_root_node;
+
+int prom_stdin, prom_stdout;
+
+/* Pointer to the device tree operations structure. */
+struct linux_nodeops *prom_nodeops;
+
+/* You must call prom_init() before you attempt to use any of the
+ * routines in the prom library. It returns 0 on success, 1 on
+ * failure. It gets passed the pointer to the PROM vector.
+ */
+
+extern void prom_meminit(void);
+extern void prom_ranges_init(void);
+
+void __init prom_init(struct linux_romvec *rp)
+{
+#ifdef CONFIG_SUN4
+ extern struct linux_romvec *sun4_prom_init(void);
+ rp = sun4_prom_init();
+#endif
+ romvec = rp;
+
+ switch(romvec->pv_romvers) {
+ case 0:
+ prom_vers = PROM_V0;
+ break;
+ case 2:
+ prom_vers = PROM_V2;
+ break;
+ case 3:
+ prom_vers = PROM_V3;
+ break;
+ case 40:
+ prom_vers = PROM_SUN4;
+ break;
+ default:
+ prom_printf("PROMLIB: Bad PROM version %d\n",
+ romvec->pv_romvers);
+ prom_halt();
+ break;
+ };
+
+ prom_rev = romvec->pv_plugin_revision;
+ prom_prev = romvec->pv_printrev;
+ prom_nodeops = romvec->pv_nodeops;
+
+ prom_root_node = prom_getsibling(0);
+ if((prom_root_node == 0) || (prom_root_node == -1))
+ prom_halt();
+
+ if((((unsigned long) prom_nodeops) == 0) ||
+ (((unsigned long) prom_nodeops) == -1))
+ prom_halt();
+
+ if(prom_vers == PROM_V2 || prom_vers == PROM_V3) {
+ prom_stdout = *romvec->pv_v2bootargs.fd_stdout;
+ prom_stdin = *romvec->pv_v2bootargs.fd_stdin;
+ }
+
+ prom_meminit();
+
+ prom_ranges_init();
+
+#ifndef CONFIG_SUN4
+ /* SUN4 prints this in sun4_prom_init */
+ printk("PROMLIB: Sun Boot Prom Version %d Revision %d\n",
+ romvec->pv_romvers, prom_rev);
+#endif
+
+ /* Initialization successful. */
+ return;
+}
diff --git a/arch/sparc/prom/memory.c b/arch/sparc/prom/memory.c
new file mode 100644
index 0000000..46aa51a
--- /dev/null
+++ b/arch/sparc/prom/memory.c
@@ -0,0 +1,216 @@
+/* $Id: memory.c,v 1.15 2000/01/29 01:09:12 anton Exp $
+ * memory.c: Prom routine for acquiring various bits of information
+ * about RAM on the machine, both virtual and physical.
+ *
+ * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
+ * Copyright (C) 1997 Michael A. Griffith (grif@acm.org)
+ */
+
+#include <linux/config.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+
+#include <asm/openprom.h>
+#include <asm/sun4prom.h>
+#include <asm/oplib.h>
+
+/* This routine, for consistency, returns the ram parameters in the
+ * V0 prom memory descriptor format. I choose this format because I
+ * think it was the easiest to work with. I feel the religious
+ * arguments now... ;) Also, I return the linked lists sorted to
+ * prevent paging_init() upset stomach as I have not yet written
+ * the pepto-bismol kernel module yet.
+ */
+
+struct linux_prom_registers prom_reg_memlist[64];
+struct linux_prom_registers prom_reg_tmp[64];
+
+struct linux_mlist_v0 prom_phys_total[64];
+struct linux_mlist_v0 prom_prom_taken[64];
+struct linux_mlist_v0 prom_phys_avail[64];
+
+struct linux_mlist_v0 *prom_ptot_ptr = prom_phys_total;
+struct linux_mlist_v0 *prom_ptak_ptr = prom_prom_taken;
+struct linux_mlist_v0 *prom_pavl_ptr = prom_phys_avail;
+
+struct linux_mem_v0 prom_memlist;
+
+
+/* Internal Prom library routine to sort a linux_mlist_v0 memory
+ * list. Used below in initialization.
+ */
+static void __init
+prom_sortmemlist(struct linux_mlist_v0 *thislist)
+{
+ int swapi = 0;
+ int i, mitr, tmpsize;
+ char *tmpaddr;
+ char *lowest;
+
+ for(i=0; thislist[i].theres_more != 0; i++) {
+ lowest = thislist[i].start_adr;
+ for(mitr = i+1; thislist[mitr-1].theres_more != 0; mitr++)
+ if(thislist[mitr].start_adr < lowest) {
+ lowest = thislist[mitr].start_adr;
+ swapi = mitr;
+ }
+ if(lowest == thislist[i].start_adr) continue;
+ tmpaddr = thislist[swapi].start_adr;
+ tmpsize = thislist[swapi].num_bytes;
+ for(mitr = swapi; mitr > i; mitr--) {
+ thislist[mitr].start_adr = thislist[mitr-1].start_adr;
+ thislist[mitr].num_bytes = thislist[mitr-1].num_bytes;
+ }
+ thislist[i].start_adr = tmpaddr;
+ thislist[i].num_bytes = tmpsize;
+ }
+
+ return;
+}
+
+/* Initialize the memory lists based upon the prom version. */
+void __init prom_meminit(void)
+{
+ int node = 0;
+ unsigned int iter, num_regs;
+ struct linux_mlist_v0 *mptr; /* ptr for traversal */
+
+ switch(prom_vers) {
+ case PROM_V0:
+ /* Nice, kind of easier to do in this case. */
+ /* First, the total physical descriptors. */
+ for(mptr = (*(romvec->pv_v0mem.v0_totphys)), iter=0;
+ mptr; mptr=mptr->theres_more, iter++) {
+ prom_phys_total[iter].start_adr = mptr->start_adr;
+ prom_phys_total[iter].num_bytes = mptr->num_bytes;
+ prom_phys_total[iter].theres_more = &prom_phys_total[iter+1];
+ }
+ prom_phys_total[iter-1].theres_more = 0x0;
+ /* Second, the total prom taken descriptors. */
+ for(mptr = (*(romvec->pv_v0mem.v0_prommap)), iter=0;
+ mptr; mptr=mptr->theres_more, iter++) {
+ prom_prom_taken[iter].start_adr = mptr->start_adr;
+ prom_prom_taken[iter].num_bytes = mptr->num_bytes;
+ prom_prom_taken[iter].theres_more = &prom_prom_taken[iter+1];
+ }
+ prom_prom_taken[iter-1].theres_more = 0x0;
+ /* Last, the available physical descriptors. */
+ for(mptr = (*(romvec->pv_v0mem.v0_available)), iter=0;
+ mptr; mptr=mptr->theres_more, iter++) {
+ prom_phys_avail[iter].start_adr = mptr->start_adr;
+ prom_phys_avail[iter].num_bytes = mptr->num_bytes;
+ prom_phys_avail[iter].theres_more = &prom_phys_avail[iter+1];
+ }
+ prom_phys_avail[iter-1].theres_more = 0x0;
+ /* Sort all the lists. */
+ prom_sortmemlist(prom_phys_total);
+ prom_sortmemlist(prom_prom_taken);
+ prom_sortmemlist(prom_phys_avail);
+ break;
+ case PROM_V2:
+ case PROM_V3:
+ /* Grrr, have to traverse the prom device tree ;( */
+ node = prom_getchild(prom_root_node);
+ node = prom_searchsiblings(node, "memory");
+ num_regs = prom_getproperty(node, "available",
+ (char *) prom_reg_memlist,
+ sizeof(prom_reg_memlist));
+ num_regs = (num_regs/sizeof(struct linux_prom_registers));
+ for(iter=0; iter<num_regs; iter++) {
+ prom_phys_avail[iter].start_adr =
+ (char *) prom_reg_memlist[iter].phys_addr;
+ prom_phys_avail[iter].num_bytes =
+ (unsigned long) prom_reg_memlist[iter].reg_size;
+ prom_phys_avail[iter].theres_more =
+ &prom_phys_avail[iter+1];
+ }
+ prom_phys_avail[iter-1].theres_more = 0x0;
+
+ num_regs = prom_getproperty(node, "reg",
+ (char *) prom_reg_memlist,
+ sizeof(prom_reg_memlist));
+ num_regs = (num_regs/sizeof(struct linux_prom_registers));
+ for(iter=0; iter<num_regs; iter++) {
+ prom_phys_total[iter].start_adr =
+ (char *) prom_reg_memlist[iter].phys_addr;
+ prom_phys_total[iter].num_bytes =
+ (unsigned long) prom_reg_memlist[iter].reg_size;
+ prom_phys_total[iter].theres_more =
+ &prom_phys_total[iter+1];
+ }
+ prom_phys_total[iter-1].theres_more = 0x0;
+
+ node = prom_getchild(prom_root_node);
+ node = prom_searchsiblings(node, "virtual-memory");
+ num_regs = prom_getproperty(node, "available",
+ (char *) prom_reg_memlist,
+ sizeof(prom_reg_memlist));
+ num_regs = (num_regs/sizeof(struct linux_prom_registers));
+
+ /* Convert available virtual areas to taken virtual
+ * areas. First sort, then convert.
+ */
+ for(iter=0; iter<num_regs; iter++) {
+ prom_prom_taken[iter].start_adr =
+ (char *) prom_reg_memlist[iter].phys_addr;
+ prom_prom_taken[iter].num_bytes =
+ (unsigned long) prom_reg_memlist[iter].reg_size;
+ prom_prom_taken[iter].theres_more =
+ &prom_prom_taken[iter+1];
+ }
+ prom_prom_taken[iter-1].theres_more = 0x0;
+
+ prom_sortmemlist(prom_prom_taken);
+
+ /* Finally, convert. */
+ for(iter=0; iter<num_regs; iter++) {
+ prom_prom_taken[iter].start_adr =
+ prom_prom_taken[iter].start_adr +
+ prom_prom_taken[iter].num_bytes;
+ prom_prom_taken[iter].num_bytes =
+ prom_prom_taken[iter+1].start_adr -
+ prom_prom_taken[iter].start_adr;
+ }
+ prom_prom_taken[iter-1].num_bytes =
+ 0xffffffff - (unsigned long) prom_prom_taken[iter-1].start_adr;
+
+ /* Sort the other two lists. */
+ prom_sortmemlist(prom_phys_total);
+ prom_sortmemlist(prom_phys_avail);
+ break;
+
+ case PROM_SUN4:
+#ifdef CONFIG_SUN4
+ /* how simple :) */
+ prom_phys_total[0].start_adr = 0x0;
+ prom_phys_total[0].num_bytes = *(sun4_romvec->memorysize);
+ prom_phys_total[0].theres_more = 0x0;
+ prom_prom_taken[0].start_adr = 0x0;
+ prom_prom_taken[0].num_bytes = 0x0;
+ prom_prom_taken[0].theres_more = 0x0;
+ prom_phys_avail[0].start_adr = 0x0;
+ prom_phys_avail[0].num_bytes = *(sun4_romvec->memoryavail);
+ prom_phys_avail[0].theres_more = 0x0;
+#endif
+ break;
+
+ default:
+ break;
+ };
+
+ /* Link all the lists into the top-level descriptor. */
+ prom_memlist.v0_totphys=&prom_ptot_ptr;
+ prom_memlist.v0_prommap=&prom_ptak_ptr;
+ prom_memlist.v0_available=&prom_pavl_ptr;
+
+ return;
+}
+
+/* This returns a pointer to our libraries internal v0 format
+ * memory descriptor.
+ */
+struct linux_mem_v0 *
+prom_meminfo(void)
+{
+ return &prom_memlist;
+}
diff --git a/arch/sparc/prom/misc.c b/arch/sparc/prom/misc.c
new file mode 100644
index 0000000..c840c20
--- /dev/null
+++ b/arch/sparc/prom/misc.c
@@ -0,0 +1,139 @@
+/* $Id: misc.c,v 1.18 2000/08/26 02:38:03 anton Exp $
+ * misc.c: Miscellaneous prom functions that don't belong
+ * anywhere else.
+ *
+ * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
+ */
+
+#include <linux/config.h>
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <asm/openprom.h>
+#include <asm/oplib.h>
+#include <asm/auxio.h>
+#include <asm/system.h>
+
+extern void restore_current(void);
+
+DEFINE_SPINLOCK(prom_lock);
+
+/* Reset and reboot the machine with the command 'bcommand'. */
+void
+prom_reboot(char *bcommand)
+{
+ unsigned long flags;
+ spin_lock_irqsave(&prom_lock, flags);
+ (*(romvec->pv_reboot))(bcommand);
+ /* Never get here. */
+ restore_current();
+ spin_unlock_irqrestore(&prom_lock, flags);
+}
+
+/* Forth evaluate the expression contained in 'fstring'. */
+void
+prom_feval(char *fstring)
+{
+ unsigned long flags;
+ if(!fstring || fstring[0] == 0)
+ return;
+ spin_lock_irqsave(&prom_lock, flags);
+ if(prom_vers == PROM_V0)
+ (*(romvec->pv_fortheval.v0_eval))(strlen(fstring), fstring);
+ else
+ (*(romvec->pv_fortheval.v2_eval))(fstring);
+ restore_current();
+ spin_unlock_irqrestore(&prom_lock, flags);
+}
+
+/* We want to do this more nicely some day. */
+extern void (*prom_palette)(int);
+
+/* Drop into the prom, with the chance to continue with the 'go'
+ * prom command.
+ */
+void
+prom_cmdline(void)
+{
+ extern void install_obp_ticker(void);
+ extern void install_linux_ticker(void);
+ unsigned long flags;
+
+ if(!serial_console && prom_palette)
+ prom_palette (1);
+ spin_lock_irqsave(&prom_lock, flags);
+ install_obp_ticker();
+ (*(romvec->pv_abort))();
+ restore_current();
+ install_linux_ticker();
+ spin_unlock_irqrestore(&prom_lock, flags);
+#ifdef CONFIG_SUN_AUXIO
+ set_auxio(AUXIO_LED, 0);
+#endif
+ if(!serial_console && prom_palette)
+ prom_palette (0);
+}
+
+/* Drop into the prom, but completely terminate the program.
+ * No chance of continuing.
+ */
+void
+prom_halt(void)
+{
+ unsigned long flags;
+again:
+ spin_lock_irqsave(&prom_lock, flags);
+ (*(romvec->pv_halt))();
+ /* Never get here. */
+ restore_current();
+ spin_unlock_irqrestore(&prom_lock, flags);
+ goto again; /* PROM is out to get me -DaveM */
+}
+
+typedef void (*sfunc_t)(void);
+
+/* Set prom sync handler to call function 'funcp'. */
+void
+prom_setsync(sfunc_t funcp)
+{
+ if(!funcp) return;
+ *romvec->pv_synchook = funcp;
+}
+
+/* Get the idprom and stuff it into buffer 'idbuf'. Returns the
+ * format type. 'num_bytes' is the number of bytes that your idbuf
+ * has space for. Returns 0xff on error.
+ */
+unsigned char
+prom_get_idprom(char *idbuf, int num_bytes)
+{
+ int len;
+
+ len = prom_getproplen(prom_root_node, "idprom");
+ if((len>num_bytes) || (len==-1)) return 0xff;
+ if(!prom_getproperty(prom_root_node, "idprom", idbuf, num_bytes))
+ return idbuf[0];
+
+ return 0xff;
+}
+
+/* Get the major prom version number. */
+int
+prom_version(void)
+{
+ return romvec->pv_romvers;
+}
+
+/* Get the prom plugin-revision. */
+int
+prom_getrev(void)
+{
+ return prom_rev;
+}
+
+/* Get the prom firmware print revision. */
+int
+prom_getprev(void)
+{
+ return prom_prev;
+}
diff --git a/arch/sparc/prom/mp.c b/arch/sparc/prom/mp.c
new file mode 100644
index 0000000..92fe373
--- /dev/null
+++ b/arch/sparc/prom/mp.c
@@ -0,0 +1,121 @@
+/* $Id: mp.c,v 1.12 2000/08/26 02:38:03 anton Exp $
+ * mp.c: OpenBoot Prom Multiprocessor support routines. Don't call
+ * these on a UP or else you will halt and catch fire. ;)
+ *
+ * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
+ */
+
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+
+#include <asm/openprom.h>
+#include <asm/oplib.h>
+
+extern void restore_current(void);
+
+/* Start cpu with prom-tree node 'cpunode' using context described
+ * by 'ctable_reg' in context 'ctx' at program counter 'pc'.
+ *
+ * XXX Have to look into what the return values mean. XXX
+ */
+int
+prom_startcpu(int cpunode, struct linux_prom_registers *ctable_reg, int ctx, char *pc)
+{
+ int ret;
+ unsigned long flags;
+
+ spin_lock_irqsave(&prom_lock, flags);
+ switch(prom_vers) {
+ case PROM_V0:
+ case PROM_V2:
+ default:
+ ret = -1;
+ break;
+ case PROM_V3:
+ ret = (*(romvec->v3_cpustart))(cpunode, (int) ctable_reg, ctx, pc);
+ break;
+ };
+ restore_current();
+ spin_unlock_irqrestore(&prom_lock, flags);
+
+ return ret;
+}
+
+/* Stop CPU with device prom-tree node 'cpunode'.
+ * XXX Again, what does the return value really mean? XXX
+ */
+int
+prom_stopcpu(int cpunode)
+{
+ int ret;
+ unsigned long flags;
+
+ spin_lock_irqsave(&prom_lock, flags);
+ switch(prom_vers) {
+ case PROM_V0:
+ case PROM_V2:
+ default:
+ ret = -1;
+ break;
+ case PROM_V3:
+ ret = (*(romvec->v3_cpustop))(cpunode);
+ break;
+ };
+ restore_current();
+ spin_unlock_irqrestore(&prom_lock, flags);
+
+ return ret;
+}
+
+/* Make CPU with device prom-tree node 'cpunode' idle.
+ * XXX Return value, anyone? XXX
+ */
+int
+prom_idlecpu(int cpunode)
+{
+ int ret;
+ unsigned long flags;
+
+ spin_lock_irqsave(&prom_lock, flags);
+ switch(prom_vers) {
+ case PROM_V0:
+ case PROM_V2:
+ default:
+ ret = -1;
+ break;
+ case PROM_V3:
+ ret = (*(romvec->v3_cpuidle))(cpunode);
+ break;
+ };
+ restore_current();
+ spin_unlock_irqrestore(&prom_lock, flags);
+
+ return ret;
+}
+
+/* Resume the execution of CPU with nodeid 'cpunode'.
+ * XXX Come on, somebody has to know... XXX
+ */
+int
+prom_restartcpu(int cpunode)
+{
+ int ret;
+ unsigned long flags;
+
+ spin_lock_irqsave(&prom_lock, flags);
+ switch(prom_vers) {
+ case PROM_V0:
+ case PROM_V2:
+ default:
+ ret = -1;
+ break;
+ case PROM_V3:
+ ret = (*(romvec->v3_cpuresume))(cpunode);
+ break;
+ };
+ restore_current();
+ spin_unlock_irqrestore(&prom_lock, flags);
+
+ return ret;
+}
diff --git a/arch/sparc/prom/palloc.c b/arch/sparc/prom/palloc.c
new file mode 100644
index 0000000..84ce8bc
--- /dev/null
+++ b/arch/sparc/prom/palloc.c
@@ -0,0 +1,44 @@
+/* $Id: palloc.c,v 1.4 1996/04/25 06:09:48 davem Exp $
+ * palloc.c: Memory allocation from the Sun PROM.
+ *
+ * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
+ */
+
+#include <asm/openprom.h>
+#include <asm/oplib.h>
+
+/* You should not call these routines after memory management
+ * has been initialized in the kernel, if fact you should not
+ * use these if at all possible in the kernel. They are mainly
+ * to be used for a bootloader for temporary allocations which
+ * it will free before jumping into the kernel it has loaded.
+ *
+ * Also, these routines don't work on V0 proms, only V2 and later.
+ */
+
+/* Allocate a chunk of memory of size 'num_bytes' giving a suggestion
+ * of virtual_hint as the preferred virtual base address of this chunk.
+ * There are no guarantees that you will get the allocation, or that
+ * the prom will abide by your "hint". So check your return value.
+ */
+char *
+prom_alloc(char *virtual_hint, unsigned int num_bytes)
+{
+ if(prom_vers == PROM_V0) return (char *) 0x0;
+ if(num_bytes == 0x0) return (char *) 0x0;
+ return (*(romvec->pv_v2devops.v2_dumb_mem_alloc))(virtual_hint, num_bytes);
+}
+
+/* Free a previously allocated chunk back to the prom at virtual address
+ * 'vaddr' of size 'num_bytes'. NOTE: This vaddr is not the hint you
+ * used for the allocation, but the virtual address the prom actually
+ * returned to you. They may be have been the same, they may have not,
+ * doesn't matter.
+ */
+void
+prom_free(char *vaddr, unsigned int num_bytes)
+{
+ if((prom_vers == PROM_V0) || (num_bytes == 0x0)) return;
+ (*(romvec->pv_v2devops.v2_dumb_mem_free))(vaddr, num_bytes);
+ return;
+}
diff --git a/arch/sparc/prom/printf.c b/arch/sparc/prom/printf.c
new file mode 100644
index 0000000..dc8b598
--- /dev/null
+++ b/arch/sparc/prom/printf.c
@@ -0,0 +1,46 @@
+/*
+ * printf.c: Internal prom library printf facility.
+ *
+ * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
+ * Copyright (c) 2002 Pete Zaitcev (zaitcev@yahoo.com)
+ *
+ * We used to warn all over the code: DO NOT USE prom_printf(),
+ * and yet people do. Anton's banking code was outputing banks
+ * with prom_printf for most of the 2.4 lifetime. Since an effective
+ * stick is not available, we deployed a carrot: an early printk
+ * through PROM by means of -p boot option. This ought to fix it.
+ * USE printk; if you need, deploy -p.
+ */
+
+#include <linux/kernel.h>
+
+#include <asm/openprom.h>
+#include <asm/oplib.h>
+
+static char ppbuf[1024];
+
+void
+prom_write(const char *buf, unsigned int n)
+{
+ char ch;
+
+ while (n != 0) {
+ --n;
+ if ((ch = *buf++) == '\n')
+ prom_putchar('\r');
+ prom_putchar(ch);
+ }
+}
+
+void
+prom_printf(char *fmt, ...)
+{
+ va_list args;
+ int i;
+
+ va_start(args, fmt);
+ i = vscnprintf(ppbuf, sizeof(ppbuf), fmt, args);
+ va_end(args);
+
+ prom_write(ppbuf, i);
+}
diff --git a/arch/sparc/prom/ranges.c b/arch/sparc/prom/ranges.c
new file mode 100644
index 0000000..a292032
--- /dev/null
+++ b/arch/sparc/prom/ranges.c
@@ -0,0 +1,118 @@
+/* $Id: ranges.c,v 1.15 2001/12/19 00:29:51 davem Exp $
+ * ranges.c: Handle ranges in newer proms for obio/sbus.
+ *
+ * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
+ * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
+ */
+
+#include <linux/init.h>
+#include <asm/openprom.h>
+#include <asm/oplib.h>
+#include <asm/types.h>
+#include <asm/sbus.h>
+#include <asm/system.h>
+
+struct linux_prom_ranges promlib_obio_ranges[PROMREG_MAX];
+int num_obio_ranges;
+
+/* Adjust register values based upon the ranges parameters. */
+static void
+prom_adjust_regs(struct linux_prom_registers *regp, int nregs,
+ struct linux_prom_ranges *rangep, int nranges)
+{
+ int regc, rngc;
+
+ for (regc = 0; regc < nregs; regc++) {
+ for (rngc = 0; rngc < nranges; rngc++)
+ if (regp[regc].which_io == rangep[rngc].ot_child_space)
+ break; /* Fount it */
+ if (rngc == nranges) /* oops */
+ prom_printf("adjust_regs: Could not find range with matching bus type...\n");
+ regp[regc].which_io = rangep[rngc].ot_parent_space;
+ regp[regc].phys_addr -= rangep[rngc].ot_child_base;
+ regp[regc].phys_addr += rangep[rngc].ot_parent_base;
+ }
+}
+
+void
+prom_adjust_ranges(struct linux_prom_ranges *ranges1, int nranges1,
+ struct linux_prom_ranges *ranges2, int nranges2)
+{
+ int rng1c, rng2c;
+
+ for(rng1c=0; rng1c < nranges1; rng1c++) {
+ for(rng2c=0; rng2c < nranges2; rng2c++)
+ if(ranges1[rng1c].ot_parent_space == ranges2[rng2c].ot_child_space &&
+ ranges1[rng1c].ot_parent_base >= ranges2[rng2c].ot_child_base &&
+ ranges2[rng2c].ot_child_base + ranges2[rng2c].or_size - ranges1[rng1c].ot_parent_base > 0U)
+ break;
+ if(rng2c == nranges2) /* oops */
+ prom_printf("adjust_ranges: Could not find matching bus type...\n");
+ else if (ranges1[rng1c].ot_parent_base + ranges1[rng1c].or_size > ranges2[rng2c].ot_child_base + ranges2[rng2c].or_size)
+ ranges1[rng1c].or_size =
+ ranges2[rng2c].ot_child_base + ranges2[rng2c].or_size - ranges1[rng1c].ot_parent_base;
+ ranges1[rng1c].ot_parent_space = ranges2[rng2c].ot_parent_space;
+ ranges1[rng1c].ot_parent_base += ranges2[rng2c].ot_parent_base;
+ }
+}
+
+/* Apply probed obio ranges to registers passed, if no ranges return. */
+void
+prom_apply_obio_ranges(struct linux_prom_registers *regs, int nregs)
+{
+ if(num_obio_ranges)
+ prom_adjust_regs(regs, nregs, promlib_obio_ranges, num_obio_ranges);
+}
+
+void __init prom_ranges_init(void)
+{
+ int node, obio_node;
+ int success;
+
+ num_obio_ranges = 0;
+
+ /* Check for obio and sbus ranges. */
+ node = prom_getchild(prom_root_node);
+ obio_node = prom_searchsiblings(node, "obio");
+
+ if(obio_node) {
+ success = prom_getproperty(obio_node, "ranges",
+ (char *) promlib_obio_ranges,
+ sizeof(promlib_obio_ranges));
+ if(success != -1)
+ num_obio_ranges = (success/sizeof(struct linux_prom_ranges));
+ }
+
+ if(num_obio_ranges)
+ prom_printf("PROMLIB: obio_ranges %d\n", num_obio_ranges);
+
+ return;
+}
+
+void
+prom_apply_generic_ranges (int node, int parent, struct linux_prom_registers *regs, int nregs)
+{
+ int success;
+ int num_ranges;
+ struct linux_prom_ranges ranges[PROMREG_MAX];
+
+ success = prom_getproperty(node, "ranges",
+ (char *) ranges,
+ sizeof (ranges));
+ if (success != -1) {
+ num_ranges = (success/sizeof(struct linux_prom_ranges));
+ if (parent) {
+ struct linux_prom_ranges parent_ranges[PROMREG_MAX];
+ int num_parent_ranges;
+
+ success = prom_getproperty(parent, "ranges",
+ (char *) parent_ranges,
+ sizeof (parent_ranges));
+ if (success != -1) {
+ num_parent_ranges = (success/sizeof(struct linux_prom_ranges));
+ prom_adjust_ranges (ranges, num_ranges, parent_ranges, num_parent_ranges);
+ }
+ }
+ prom_adjust_regs(regs, nregs, ranges, num_ranges);
+ }
+}
diff --git a/arch/sparc/prom/segment.c b/arch/sparc/prom/segment.c
new file mode 100644
index 0000000..09d6460
--- /dev/null
+++ b/arch/sparc/prom/segment.c
@@ -0,0 +1,29 @@
+/* $Id: segment.c,v 1.7 2000/08/26 02:38:03 anton Exp $
+ * segment.c: Prom routine to map segments in other contexts before
+ * a standalone is completely mapped. This is for sun4 and
+ * sun4c architectures only.
+ *
+ * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
+ */
+
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <asm/openprom.h>
+#include <asm/oplib.h>
+
+extern void restore_current(void);
+
+/* Set physical segment 'segment' at virtual address 'vaddr' in
+ * context 'ctx'.
+ */
+void
+prom_putsegment(int ctx, unsigned long vaddr, int segment)
+{
+ unsigned long flags;
+ spin_lock_irqsave(&prom_lock, flags);
+ (*(romvec->pv_setctxt))(ctx, (char *) vaddr, segment);
+ restore_current();
+ spin_unlock_irqrestore(&prom_lock, flags);
+ return;
+}
diff --git a/arch/sparc/prom/sun4prom.c b/arch/sparc/prom/sun4prom.c
new file mode 100644
index 0000000..69ca735
--- /dev/null
+++ b/arch/sparc/prom/sun4prom.c
@@ -0,0 +1,161 @@
+/*
+ * Copyright (C) 1996 The Australian National University.
+ * Copyright (C) 1996 Fujitsu Laboratories Limited
+ * Copyright (C) 1997 Michael A. Griffith (grif@acm.org)
+ * Copyright (C) 1997 Sun Weenie (ko@ko.reno.nv.us)
+ * Copyright (C) 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
+ *
+ * This software may be distributed under the terms of the Gnu
+ * Public License version 2 or later
+ *
+ * fake a really simple Sun prom for the SUN4
+ */
+
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include <asm/oplib.h>
+#include <asm/idprom.h>
+#include <asm/machines.h>
+#include <asm/sun4prom.h>
+#include <asm/asi.h>
+#include <asm/contregs.h>
+#include <linux/init.h>
+
+static struct linux_romvec sun4romvec;
+static struct idprom sun4_idprom;
+
+struct property {
+ char *name;
+ char *value;
+ int length;
+};
+
+struct node {
+ int level;
+ struct property *properties;
+};
+
+struct property null_properties = { NULL, NULL, -1 };
+
+struct property root_properties[] = {
+ {"device_type", "cpu", 4},
+ {"idprom", (char *)&sun4_idprom, sizeof(struct idprom)},
+ {NULL, NULL, -1}
+};
+
+struct node nodes[] = {
+ { 0, &null_properties },
+ { 0, root_properties },
+ { -1,&null_properties }
+};
+
+
+static int no_nextnode(int node)
+{
+ if (nodes[node].level == nodes[node+1].level)
+ return node+1;
+ return -1;
+}
+
+static int no_child(int node)
+{
+ if (nodes[node].level == nodes[node+1].level-1)
+ return node+1;
+ return -1;
+}
+
+static struct property *find_property(int node,char *name)
+{
+ struct property *prop = &nodes[node].properties[0];
+ while (prop && prop->name) {
+ if (strcmp(prop->name,name) == 0) return prop;
+ prop++;
+ }
+ return NULL;
+}
+
+static int no_proplen(int node,char *name)
+{
+ struct property *prop = find_property(node,name);
+ if (prop) return prop->length;
+ return -1;
+}
+
+static int no_getprop(int node,char *name,char *value)
+{
+ struct property *prop = find_property(node,name);
+ if (prop) {
+ memcpy(value,prop->value,prop->length);
+ return 1;
+ }
+ return -1;
+}
+
+static int no_setprop(int node,char *name,char *value,int len)
+{
+ return -1;
+}
+
+static char *no_nextprop(int node,char *name)
+{
+ struct property *prop = find_property(node,name);
+ if (prop) return prop[1].name;
+ return NULL;
+}
+
+static struct linux_nodeops sun4_nodeops = {
+ no_nextnode,
+ no_child,
+ no_proplen,
+ no_getprop,
+ no_setprop,
+ no_nextprop
+};
+
+static int synch_hook;
+
+struct linux_romvec * __init sun4_prom_init(void)
+{
+ int i;
+ unsigned char x;
+ char *p;
+
+ p = (char *)&sun4_idprom;
+ for (i = 0; i < sizeof(sun4_idprom); i++) {
+ __asm__ __volatile__ ("lduba [%1] %2, %0" : "=r" (x) :
+ "r" (AC_IDPROM + i), "i" (ASI_CONTROL));
+ *p++ = x;
+ }
+
+ memset(&sun4romvec,0,sizeof(sun4romvec));
+
+ sun4_romvec = (linux_sun4_romvec *) SUN4_PROM_VECTOR;
+
+ sun4romvec.pv_romvers = 40;
+ sun4romvec.pv_nodeops = &sun4_nodeops;
+ sun4romvec.pv_reboot = sun4_romvec->reboot;
+ sun4romvec.pv_abort = sun4_romvec->abortentry;
+ sun4romvec.pv_halt = sun4_romvec->exittomon;
+ sun4romvec.pv_synchook = (void (**)(void))&synch_hook;
+ sun4romvec.pv_setctxt = sun4_romvec->setcxsegmap;
+ sun4romvec.pv_v0bootargs = sun4_romvec->bootParam;
+ sun4romvec.pv_nbgetchar = sun4_romvec->mayget;
+ sun4romvec.pv_nbputchar = sun4_romvec->mayput;
+ sun4romvec.pv_stdin = sun4_romvec->insource;
+ sun4romvec.pv_stdout = sun4_romvec->outsink;
+
+ /*
+ * We turn on the LEDs to let folks without monitors or
+ * terminals know we booted. Nothing too fancy now. They
+ * are all on, except for LED 5, which blinks. When we
+ * have more time, we can teach the penguin to say "By your
+ * command" or "Activating turbo boost, Michael". :-)
+ */
+ sun4_romvec->setLEDs(0x0);
+
+ printk("PROMLIB: Old Sun4 boot PROM monitor %s, romvec version %d\n",
+ sun4_romvec->monid,
+ sun4_romvec->romvecversion);
+
+ return &sun4romvec;
+}
diff --git a/arch/sparc/prom/tree.c b/arch/sparc/prom/tree.c
new file mode 100644
index 0000000..2bf03ee
--- /dev/null
+++ b/arch/sparc/prom/tree.c
@@ -0,0 +1,364 @@
+/* $Id: tree.c,v 1.26 2000/08/26 02:38:03 anton Exp $
+ * tree.c: Basic device tree traversal/scanning for the Linux
+ * prom library.
+ *
+ * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
+ */
+
+#define PROMLIB_INTERNAL
+
+#include <linux/string.h>
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/ctype.h>
+
+#include <asm/openprom.h>
+#include <asm/oplib.h>
+
+extern void restore_current(void);
+
+static char promlib_buf[128];
+
+/* Internal version of prom_getchild that does not alter return values. */
+int __prom_getchild(int node)
+{
+ unsigned long flags;
+ int cnode;
+
+ spin_lock_irqsave(&prom_lock, flags);
+ cnode = prom_nodeops->no_child(node);
+ restore_current();
+ spin_unlock_irqrestore(&prom_lock, flags);
+
+ return cnode;
+}
+
+/* Return the child of node 'node' or zero if no this node has no
+ * direct descendent.
+ */
+int prom_getchild(int node)
+{
+ int cnode;
+
+ if (node == -1)
+ return 0;
+
+ cnode = __prom_getchild(node);
+ if (cnode == 0 || cnode == -1)
+ return 0;
+
+ return cnode;
+}
+
+/* Internal version of prom_getsibling that does not alter return values. */
+int __prom_getsibling(int node)
+{
+ unsigned long flags;
+ int cnode;
+
+ spin_lock_irqsave(&prom_lock, flags);
+ cnode = prom_nodeops->no_nextnode(node);
+ restore_current();
+ spin_unlock_irqrestore(&prom_lock, flags);
+
+ return cnode;
+}
+
+/* Return the next sibling of node 'node' or zero if no more siblings
+ * at this level of depth in the tree.
+ */
+int prom_getsibling(int node)
+{
+ int sibnode;
+
+ if (node == -1)
+ return 0;
+
+ sibnode = __prom_getsibling(node);
+ if (sibnode == 0 || sibnode == -1)
+ return 0;
+
+ return sibnode;
+}
+
+/* Return the length in bytes of property 'prop' at node 'node'.
+ * Return -1 on error.
+ */
+int prom_getproplen(int node, char *prop)
+{
+ int ret;
+ unsigned long flags;
+
+ if((!node) || (!prop))
+ return -1;
+
+ spin_lock_irqsave(&prom_lock, flags);
+ ret = prom_nodeops->no_proplen(node, prop);
+ restore_current();
+ spin_unlock_irqrestore(&prom_lock, flags);
+ return ret;
+}
+
+/* Acquire a property 'prop' at node 'node' and place it in
+ * 'buffer' which has a size of 'bufsize'. If the acquisition
+ * was successful the length will be returned, else -1 is returned.
+ */
+int prom_getproperty(int node, char *prop, char *buffer, int bufsize)
+{
+ int plen, ret;
+ unsigned long flags;
+
+ plen = prom_getproplen(node, prop);
+ if((plen > bufsize) || (plen == 0) || (plen == -1))
+ return -1;
+ /* Ok, things seem all right. */
+ spin_lock_irqsave(&prom_lock, flags);
+ ret = prom_nodeops->no_getprop(node, prop, buffer);
+ restore_current();
+ spin_unlock_irqrestore(&prom_lock, flags);
+ return ret;
+}
+
+/* Acquire an integer property and return its value. Returns -1
+ * on failure.
+ */
+int prom_getint(int node, char *prop)
+{
+ static int intprop;
+
+ if(prom_getproperty(node, prop, (char *) &intprop, sizeof(int)) != -1)
+ return intprop;
+
+ return -1;
+}
+
+/* Acquire an integer property, upon error return the passed default
+ * integer.
+ */
+int prom_getintdefault(int node, char *property, int deflt)
+{
+ int retval;
+
+ retval = prom_getint(node, property);
+ if(retval == -1) return deflt;
+
+ return retval;
+}
+
+/* Acquire a boolean property, 1=TRUE 0=FALSE. */
+int prom_getbool(int node, char *prop)
+{
+ int retval;
+
+ retval = prom_getproplen(node, prop);
+ if(retval == -1) return 0;
+ return 1;
+}
+
+/* Acquire a property whose value is a string, returns a null
+ * string on error. The char pointer is the user supplied string
+ * buffer.
+ */
+void prom_getstring(int node, char *prop, char *user_buf, int ubuf_size)
+{
+ int len;
+
+ len = prom_getproperty(node, prop, user_buf, ubuf_size);
+ if(len != -1) return;
+ user_buf[0] = 0;
+ return;
+}
+
+
+/* Does the device at node 'node' have name 'name'?
+ * YES = 1 NO = 0
+ */
+int prom_nodematch(int node, char *name)
+{
+ int error;
+
+ static char namebuf[128];
+ error = prom_getproperty(node, "name", namebuf, sizeof(namebuf));
+ if (error == -1) return 0;
+ if(strcmp(namebuf, name) == 0) return 1;
+ return 0;
+}
+
+/* Search siblings at 'node_start' for a node with name
+ * 'nodename'. Return node if successful, zero if not.
+ */
+int prom_searchsiblings(int node_start, char *nodename)
+{
+
+ int thisnode, error;
+
+ for(thisnode = node_start; thisnode;
+ thisnode=prom_getsibling(thisnode)) {
+ error = prom_getproperty(thisnode, "name", promlib_buf,
+ sizeof(promlib_buf));
+ /* Should this ever happen? */
+ if(error == -1) continue;
+ if(strcmp(nodename, promlib_buf)==0) return thisnode;
+ }
+
+ return 0;
+}
+
+/* Gets name in the form prom v2+ uses it (name@x,yyyyy or name (if no reg)) */
+int prom_getname (int node, char *buffer, int len)
+{
+ int i;
+ struct linux_prom_registers reg[PROMREG_MAX];
+
+ i = prom_getproperty (node, "name", buffer, len);
+ if (i <= 0) return -1;
+ buffer [i] = 0;
+ len -= i;
+ i = prom_getproperty (node, "reg", (char *)reg, sizeof (reg));
+ if (i <= 0) return 0;
+ if (len < 11) return -1;
+ buffer = strchr (buffer, 0);
+ sprintf (buffer, "@%x,%x", reg[0].which_io, (uint)reg[0].phys_addr);
+ return 0;
+}
+
+/* Interal version of nextprop that does not alter return values. */
+char * __prom_nextprop(int node, char * oprop)
+{
+ unsigned long flags;
+ char *prop;
+
+ spin_lock_irqsave(&prom_lock, flags);
+ prop = prom_nodeops->no_nextprop(node, oprop);
+ restore_current();
+ spin_unlock_irqrestore(&prom_lock, flags);
+
+ return prop;
+}
+
+/* Return the first property name for node 'node'. */
+/* buffer is unused argument, but as v9 uses it, we need to have the same interface */
+char * prom_firstprop(int node, char *bufer)
+{
+ if (node == 0 || node == -1)
+ return "";
+
+ return __prom_nextprop(node, "");
+}
+
+/* Return the property type string after property type 'oprop'
+ * at node 'node' . Returns empty string if no more
+ * property types for this node.
+ */
+char * prom_nextprop(int node, char *oprop, char *buffer)
+{
+ if (node == 0 || node == -1)
+ return "";
+
+ return __prom_nextprop(node, oprop);
+}
+
+int prom_finddevice(char *name)
+{
+ char nbuf[128];
+ char *s = name, *d;
+ int node = prom_root_node, node2;
+ unsigned int which_io, phys_addr;
+ struct linux_prom_registers reg[PROMREG_MAX];
+
+ while (*s++) {
+ if (!*s) return node; /* path '.../' is legal */
+ node = prom_getchild(node);
+
+ for (d = nbuf; *s != 0 && *s != '@' && *s != '/';)
+ *d++ = *s++;
+ *d = 0;
+
+ node = prom_searchsiblings(node, nbuf);
+ if (!node)
+ return 0;
+
+ if (*s == '@') {
+ if (isxdigit(s[1]) && s[2] == ',') {
+ which_io = simple_strtoul(s+1, NULL, 16);
+ phys_addr = simple_strtoul(s+3, &d, 16);
+ if (d != s + 3 && (!*d || *d == '/')
+ && d <= s + 3 + 8) {
+ node2 = node;
+ while (node2 && node2 != -1) {
+ if (prom_getproperty (node2, "reg", (char *)reg, sizeof (reg)) > 0) {
+ if (which_io == reg[0].which_io && phys_addr == reg[0].phys_addr) {
+ node = node2;
+ break;
+ }
+ }
+ node2 = prom_getsibling(node2);
+ if (!node2 || node2 == -1)
+ break;
+ node2 = prom_searchsiblings(prom_getsibling(node2), nbuf);
+ }
+ }
+ }
+ while (*s != 0 && *s != '/') s++;
+ }
+ }
+ return node;
+}
+
+int prom_node_has_property(int node, char *prop)
+{
+ char *current_property = "";
+
+ do {
+ current_property = prom_nextprop(node, current_property, NULL);
+ if(!strcmp(current_property, prop))
+ return 1;
+ } while (*current_property);
+ return 0;
+}
+
+/* Set property 'pname' at node 'node' to value 'value' which has a length
+ * of 'size' bytes. Return the number of bytes the prom accepted.
+ */
+int prom_setprop(int node, char *pname, char *value, int size)
+{
+ unsigned long flags;
+ int ret;
+
+ if(size == 0) return 0;
+ if((pname == 0) || (value == 0)) return 0;
+ spin_lock_irqsave(&prom_lock, flags);
+ ret = prom_nodeops->no_setprop(node, pname, value, size);
+ restore_current();
+ spin_unlock_irqrestore(&prom_lock, flags);
+ return ret;
+}
+
+int prom_inst2pkg(int inst)
+{
+ int node;
+ unsigned long flags;
+
+ spin_lock_irqsave(&prom_lock, flags);
+ node = (*romvec->pv_v2devops.v2_inst2pkg)(inst);
+ restore_current();
+ spin_unlock_irqrestore(&prom_lock, flags);
+ if (node == -1) return 0;
+ return node;
+}
+
+/* Return 'node' assigned to a particular prom 'path'
+ * FIXME: Should work for v0 as well
+ */
+int prom_pathtoinode(char *path)
+{
+ int node, inst;
+
+ inst = prom_devopen (path);
+ if (inst == -1) return 0;
+ node = prom_inst2pkg (inst);
+ prom_devclose (inst);
+ if (node == -1) return 0;
+ return node;
+}