From 65216210367b35f7ba410a3a4d380c1ee6af7b90 Mon Sep 17 00:00:00 2001 From: pk Date: Sun, 21 Mar 2004 14:10:08 +0000 Subject: [PATCH] Switch to the sparc prom library. --- sys/arch/sparc64/include/autoconf.h | 29 +-- sys/arch/sparc64/include/sparc64.h | 7 +- sys/arch/sparc64/sparc64/autoconf.c | 285 +--------------------------- 3 files changed, 10 insertions(+), 311 deletions(-) diff --git a/sys/arch/sparc64/include/autoconf.h b/sys/arch/sparc64/include/autoconf.h index 1e7b24383e7a..22140d9bda81 100644 --- a/sys/arch/sparc64/include/autoconf.h +++ b/sys/arch/sparc64/include/autoconf.h @@ -1,4 +1,4 @@ -/* $NetBSD: autoconf.h,v 1.20 2004/03/19 15:22:43 pk Exp $ */ +/* $NetBSD: autoconf.h,v 1.21 2004/03/21 14:10:08 pk Exp $ */ /*- * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. @@ -81,7 +81,7 @@ */ #include -/*notyet:#include */ +#include #include /* This is used to map device classes to IPLs */ @@ -125,20 +125,6 @@ struct mainbus_attach_args { int ma_pri; /* priority (IPL) */ }; -/* - * length; the others convert or make some other guarantee. - */ -long prom_getproplen __P((int node, char *name)); -int prom_getprop __P((int, char *, size_t, int *, void *)); -char *prom_getpropstring __P((int node, char *name)); -int prom_getpropint __P((int node, char *name, int deflt)); - - /* new interfaces: */ -char *prom_getpropstringA __P((int, char *, char *, size_t)); - -struct idprom *prom_getidprom(void); -void prom_getether(int, u_char *); - /* * The matchbyname function is useful in drivers that are matched * by romaux name, i.e., all `mainbus attached' devices. It expects @@ -172,16 +158,5 @@ void mountroot_hook_establish __P((void (*) __P((struct device *)), struct device *)); void bootstrap __P((int)); -int firstchild __P((int)); -int nextsibling __P((int)); -void callrom __P((void)); struct device *getdevunit __P((char *, int)); -void *findzs __P((int)); -void rominterpret __P((char *)); int romgetcursoraddr __P((int **, int **)); -int findroot __P((void)); -int findnode __P((int, const char *)); -int node_has_property __P((int, const char *)); -int prom_getoptionsnode __P((void)); -int prom_getoption __P((const char *name, char *buf, int buflen)); - diff --git a/sys/arch/sparc64/include/sparc64.h b/sys/arch/sparc64/include/sparc64.h index 5739cc711b1c..2d9cae306ed6 100644 --- a/sys/arch/sparc64/include/sparc64.h +++ b/sys/arch/sparc64/include/sparc64.h @@ -1,4 +1,4 @@ -/* $NetBSD: sparc64.h,v 1.6 2004/03/14 18:18:54 chs Exp $ */ +/* $NetBSD: sparc64.h,v 1.7 2004/03/21 14:10:08 pk Exp $ */ /* * Copyright (C) 1996 Wolfgang Solfrank. @@ -53,9 +53,4 @@ u_int64_t prom_get_msgbuf (int, int); void prom_stopself(void); void prom_startcpu(u_int, void *, u_long); -/* - * Debug - */ -void prom_printf (const char *, ...); - #endif /* _MACHINE_SPARC64_H_ */ diff --git a/sys/arch/sparc64/sparc64/autoconf.c b/sys/arch/sparc64/sparc64/autoconf.c index 5d2241e388f5..1a4d3b56e065 100644 --- a/sys/arch/sparc64/sparc64/autoconf.c +++ b/sys/arch/sparc64/sparc64/autoconf.c @@ -1,4 +1,4 @@ -/* $NetBSD: autoconf.c,v 1.94 2004/03/19 15:22:43 pk Exp $ */ +/* $NetBSD: autoconf.c,v 1.95 2004/03/21 14:10:08 pk Exp $ */ /* * Copyright (c) 1996 @@ -48,7 +48,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.94 2004/03/19 15:22:43 pk Exp $"); +__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.95 2004/03/21 14:10:08 pk Exp $"); #include "opt_ddb.h" #include "opt_kgdb.h" @@ -78,7 +78,6 @@ __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.94 2004/03/19 15:22:43 pk Exp $"); #include #include #include -#include #include #include #include @@ -102,7 +101,6 @@ int printspl = 0; extern int kgdb_debug_panic; #endif -static int rootnode; char machine_model[100]; static char *str2hex __P((char *, int *)); @@ -235,6 +233,8 @@ bootstrap(nctx) extern void OF_val2sym32 __P((void *)); #endif + prom_init(); + /* Initialize the PROM console so printf will not panic */ (*cn_tab->cn_init)(cn_tab); #if NKSYMS || defined(DDB) || defined(LKM) @@ -552,37 +552,6 @@ mbprint(aux, name) return (UNCONF); } -int -findroot() -{ - register int node; - - if ((node = rootnode) == 0 && (node = OF_peer(0)) == 0) - panic("no PROM root device"); - rootnode = node; - return (node); -} - -/* - * Given a `first child' node number, locate the node with the given name. - * Return the node number, or 0 if not found. - */ -int -findnode(first, name) - int first; - register const char *name; -{ - int node; - char buf[32]; - - for (node = first; node; node = OF_peer(node)) { - if ((OF_getprop(node, "name", buf, sizeof(buf)) > 0) && - (strcmp(buf, name) == 0)) - return (node); - } - return (0); -} - int mainbus_match(parent, cf, aux) struct device *parent; @@ -755,247 +724,6 @@ extern struct sparc_bus_space_tag mainbus_space_tag; CFATTACH_DECL(mainbus, sizeof(struct device), mainbus_match, mainbus_attach, NULL, NULL); -int -prom_getprop(node, name, size, nitem, bufp) - int node; - char *name; - size_t size; - int *nitem; - void *bufp; -{ - void *buf; - long len; - - len = prom_getproplen(node, name); - if (len <= 0) - return (ENOENT); - - if ((len % size) != 0) - return (EINVAL); - - buf = *(void **)bufp; - if (buf == NULL) { - /* No storage provided, so we allocate some */ - buf = malloc(len, M_DEVBUF, M_NOWAIT); - if (buf == NULL) - return (ENOMEM); - } else { - if (size * (*nitem) < len) - return (ENOMEM); - } - - OF_getprop(node, name, buf, len); - *(void **)bufp = buf; - *nitem = len / size; - return (0); -} - - -/* - * Internal form of proplen(). Returns the property length. - */ -long -prom_getproplen(node, name) - int node; - char *name; -{ - return (OF_getproplen(node, name)); -} - -/* - * Return a string property. There is a (small) limit on the length; - * the string is fetched into a static buffer which is overwritten on - * subsequent calls. - */ -char * -prom_getpropstring(node, name) - int node; - char *name; -{ - static char stringbuf[32]; - - return (prom_getpropstringA(node, name, stringbuf, sizeof stringbuf)); -} - -/* Alternative prom_getpropstring(), where caller provides the buffer */ -char * -prom_getpropstringA(node, name, buffer, bufsize) - int node; - char *name; - char *buffer; - size_t bufsize; -{ - int blen = bufsize - 1; - - if (prom_getprop(node, name, 1, &blen, &buffer) != 0) - blen = 0; - - buffer[blen] = '\0'; /* usually unnecessary */ - return (buffer); -} - -/* - * Fetch an integer (or pointer) property. - * The return value is the property, or the default if there was none. - */ -int -prom_getpropint(node, name, deflt) - int node; - char *name; - int deflt; -{ - int intbuf; - - if (OF_getprop(node, name, &intbuf, sizeof(intbuf)) != sizeof(intbuf)) - return (deflt); - - return (intbuf); -} - -/* - * OPENPROM functions. These are here mainly to hide the OPENPROM interface - * from the rest of the kernel. - */ -int -firstchild(node) - int node; -{ - - return OF_child(node); -} - -int -nextsibling(node) - int node; -{ - - return OF_peer(node); -} - -/* The following are used primarily in consinit() */ - -int -node_has_property(node, prop) /* returns 1 if node has given property */ - register int node; - register const char *prop; -{ - return (OF_getproplen(node, (caddr_t)prop) != -1); -} - -/* - * Get the global "options" node Id. - */ -int prom_getoptionsnode() -{ -static int optionsnode; - - if (optionsnode == 0) { - optionsnode = findnode(firstchild(findroot()), "options"); - } - return optionsnode; -} - -/* - * Return a property string value from the global "options" node. - */ -int prom_getoption(const char *name, char *buf, int buflen) -{ - int node = prom_getoptionsnode(); - int error, len; - - if (buflen == 0) - return (EINVAL); - - if (node == 0) - return (ENOENT); - - len = buflen - 1; - if ((error = prom_getprop(node, (char *)name, 1, &len, &buf)) != 0) - return error; - - buf[len] = '\0'; - return (0); -} - -struct idprom * -prom_getidprom(void) -{ -static struct idprom idprom; - int node, len; - u_long h; - u_char *dst; - - if (idprom.id_format != 0) - /* Already got it */ - return (&idprom); - - /* - * Fetch the `idprom' property at the root node. - */ - dst = (char *)&idprom; - len = sizeof(struct idprom); - node = findroot(); - if (prom_getprop(node, "idprom", 1, &len, &dst) != 0) { - printf("`idprom' property cannot be read: " - "cannot get ethernet address"); - } - - /* Establish hostid */ - h = idprom.id_machine << 24; - h |= idprom.id_hostid[0] << 16; - h |= idprom.id_hostid[1] << 8; - h |= idprom.id_hostid[2]; - hostid = h; - - return (&idprom); -} - -void prom_getether(node, cp) - int node; - u_char *cp; -{ - struct idprom *idp = prom_getidprom(); - char buf[6+1], *bp; - int nitem; - - if (node == 0) - goto read_idprom; - - /* - * First, try the node's "mac-address" property. - * This property is set by the adapter's firmware if the - * device has already been opened for traffic, e.g. for - * net booting. Its value might be `0-terminated', probably - * because the Forth ROMs uses `xdrstring' instead of `xdrbytes' - * to construct the property. - */ - nitem = 6+1; - bp = buf; - if (prom_getprop(node, "mac-address", 1, &nitem, &bp) == 0 && - nitem >= 6) { - memcpy(cp, bp, 6); - return; - } - - /* - * Next, check the global "local-mac-address?" switch to see - * if we should try to extract the node's "local-mac-address" - * property. - */ - if (prom_getoption("local-mac-address?", buf, sizeof buf) != 0 || - strcmp(buf, "true") != 0) - goto read_idprom; - - /* Retrieve the node's "local-mac-address" property, if any */ - nitem = 6; - if (prom_getprop(node, "local-mac-address", 1, &nitem, &cp) == 0 && - nitem == 6) - return; - - /* Fall back on the machine's global ethernet address */ -read_idprom: - memcpy(cp, idp->id_ether, 6); -} #ifdef RASTERCONSOLE /* @@ -1021,13 +749,14 @@ romgetcursoraddr(rowp, colp) } #endif /* RASTERCONSOLE */ -void -callrom() +#if 0 +void callrom() { __asm __volatile("wrpr %%g0, 0, %%tl" : ); OF_enter(); } +#endif /* * find a device matching "name" and unit number