Move makememarr() into promlib.c.
This commit is contained in:
parent
e0ef9a798d
commit
2b390d41d0
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: autoconf.h,v 1.35 2002/08/25 16:05:42 thorpej Exp $ */
|
||||
/* $NetBSD: autoconf.h,v 1.36 2003/02/18 13:36:51 pk Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
|
||||
|
@ -171,19 +171,6 @@ int matchbyname __P((struct device *, struct cfdata *cf, void *aux));
|
|||
*/
|
||||
char *clockfreq __P((int freq));
|
||||
|
||||
/*
|
||||
* Memory description arrays. Shared between pmap.c and autoconf.c; no
|
||||
* one else should use this (except maybe mem.c, e.g., if we fix the VM to
|
||||
* handle discontiguous physical memory).
|
||||
*/
|
||||
struct memarr {
|
||||
paddr_t addr;
|
||||
psize_t len;
|
||||
};
|
||||
int makememarr(struct memarr *, int max, int which);
|
||||
#define MEMARR_AVAILPHYS 0
|
||||
#define MEMARR_TOTALPHYS 1
|
||||
|
||||
/* Openprom V2 style boot path */
|
||||
struct bootpath {
|
||||
char name[16]; /* name of this node */
|
||||
|
@ -191,11 +178,6 @@ struct bootpath {
|
|||
struct device *dev; /* device that recognised this component */
|
||||
};
|
||||
|
||||
#if 0
|
||||
struct bootpath *bootpath_store __P((int, struct bootpath *));
|
||||
#endif
|
||||
int sd_crazymap __P((int));
|
||||
|
||||
/* Parse a disk string into a dev_t, return device struct pointer */
|
||||
struct device *parsedisk __P((char *, int, int, dev_t *));
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: promlib.h,v 1.5 2003/01/16 16:58:52 pk Exp $ */
|
||||
/* $NetBSD: promlib.h,v 1.6 2003/02/18 13:36:51 pk Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999 The NetBSD Foundation, Inc.
|
||||
|
@ -115,6 +115,18 @@ struct promops {
|
|||
|
||||
extern struct promops promops;
|
||||
|
||||
/*
|
||||
* Memory description array.
|
||||
*/
|
||||
struct memarr {
|
||||
paddr_t addr;
|
||||
psize_t len;
|
||||
};
|
||||
int prom_makememarr(struct memarr *, int max, int which);
|
||||
#define MEMARR_AVAILPHYS 0
|
||||
#define MEMARR_TOTALPHYS 1
|
||||
|
||||
|
||||
void prom_init __P((void)); /* To setup promops */
|
||||
|
||||
/* Utility routines */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: autoconf.c,v 1.189 2003/01/20 20:51:34 pk Exp $ */
|
||||
/* $NetBSD: autoconf.c,v 1.190 2003/02/18 13:36:52 pk Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996
|
||||
|
@ -125,6 +125,7 @@ static char *str2hex __P((char *, int *));
|
|||
static int mbprint __P((void *, const char *));
|
||||
static void crazymap __P((char *, int *));
|
||||
int st_crazymap __P((int));
|
||||
int sd_crazymap __P((int));
|
||||
void sync_crash __P((void));
|
||||
int mainbus_match __P((struct device *, struct cfdata *, void *));
|
||||
static void mainbus_attach __P((struct device *, struct device *, void *));
|
||||
|
@ -1067,7 +1068,7 @@ mainbus_match(parent, cf, aux)
|
|||
* only get the first item in case the property value is an array.
|
||||
* Drivers that "need to know it all" can call PROM_getprop() directly.
|
||||
*/
|
||||
#if defined(SUN4C) || defined(SUN4M)
|
||||
#if defined(SUN4C) || defined(SUN4M) || defined(SUN4D)
|
||||
static int PROM_getprop_reg1 __P((int, struct openprom_addr *));
|
||||
static int PROM_getprop_intr1 __P((int, int *));
|
||||
static int PROM_getprop_address1 __P((int, void **));
|
||||
|
@ -1390,145 +1391,8 @@ extern struct sparc_bus_space_tag mainbus_space_tag;
|
|||
CFATTACH_DECL(mainbus, sizeof(struct device),
|
||||
mainbus_match, mainbus_attach, NULL, NULL);
|
||||
|
||||
int
|
||||
makememarr(ap, max, which)
|
||||
struct memarr *ap;
|
||||
int max, which;
|
||||
{
|
||||
struct v2rmi {
|
||||
int zero;
|
||||
int addr;
|
||||
int len;
|
||||
} v2rmi[200]; /* version 2 rom meminfo layout */
|
||||
#define MAXMEMINFO ((int)sizeof(v2rmi) / (int)sizeof(*v2rmi))
|
||||
void *p;
|
||||
|
||||
struct v0mlist *mp;
|
||||
int i, node, len;
|
||||
char *prop;
|
||||
|
||||
switch (prom_version()) {
|
||||
struct promvec *promvec;
|
||||
struct om_vector *oldpvec;
|
||||
case PROM_OLDMON:
|
||||
oldpvec = (struct om_vector *)PROM_BASE;
|
||||
switch (which) {
|
||||
case MEMARR_AVAILPHYS:
|
||||
ap[0].addr = 0;
|
||||
ap[0].len = *oldpvec->memoryAvail;
|
||||
break;
|
||||
case MEMARR_TOTALPHYS:
|
||||
ap[0].addr = 0;
|
||||
ap[0].len = *oldpvec->memorySize;
|
||||
break;
|
||||
default:
|
||||
printf("pre_panic: makememarr");
|
||||
break;
|
||||
}
|
||||
i = (1);
|
||||
break;
|
||||
|
||||
case PROM_OBP_V0:
|
||||
/*
|
||||
* Version 0 PROMs use a linked list to describe these
|
||||
* guys.
|
||||
*/
|
||||
promvec = romp;
|
||||
switch (which) {
|
||||
case MEMARR_AVAILPHYS:
|
||||
mp = *promvec->pv_v0mem.v0_physavail;
|
||||
break;
|
||||
|
||||
case MEMARR_TOTALPHYS:
|
||||
mp = *promvec->pv_v0mem.v0_phystot;
|
||||
break;
|
||||
|
||||
default:
|
||||
panic("makememarr");
|
||||
}
|
||||
for (i = 0; mp != NULL; mp = mp->next, i++) {
|
||||
if (i >= max)
|
||||
goto overflow;
|
||||
ap->addr = (u_int)mp->addr;
|
||||
ap->len = mp->nbytes;
|
||||
ap++;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("makememarr: hope version %d PROM is like version 2\n",
|
||||
prom_version());
|
||||
/* FALLTHROUGH */
|
||||
|
||||
case PROM_OBP_V3:
|
||||
case PROM_OBP_V2:
|
||||
/*
|
||||
* Version 2 PROMs use a property array to describe them.
|
||||
*/
|
||||
|
||||
/* Consider emulating `OF_finddevice' */
|
||||
node = findnode(firstchild(findroot()), "memory");
|
||||
goto case_common;
|
||||
|
||||
case PROM_OPENFIRM:
|
||||
node = OF_finddevice("/memory");
|
||||
if (node == -1)
|
||||
node = 0;
|
||||
|
||||
case_common:
|
||||
if (node == 0)
|
||||
panic("makememarr: cannot find \"memory\" node");
|
||||
|
||||
if (max > MAXMEMINFO) {
|
||||
printf("makememarr: limited to %d\n", MAXMEMINFO);
|
||||
max = MAXMEMINFO;
|
||||
}
|
||||
|
||||
switch (which) {
|
||||
case MEMARR_AVAILPHYS:
|
||||
prop = "available";
|
||||
break;
|
||||
|
||||
case MEMARR_TOTALPHYS:
|
||||
prop = "reg";
|
||||
break;
|
||||
|
||||
default:
|
||||
panic("makememarr");
|
||||
}
|
||||
|
||||
len = MAXMEMINFO;
|
||||
p = v2rmi;
|
||||
if (PROM_getprop(node, prop, sizeof(struct v2rmi), &len, &p) != 0)
|
||||
panic("makememarr: cannot get property");
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
if (i >= max)
|
||||
goto overflow;
|
||||
ap->addr = v2rmi[i].addr;
|
||||
ap->len = v2rmi[i].len;
|
||||
ap++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Success! (Hooray)
|
||||
*/
|
||||
if (i == 0)
|
||||
panic("makememarr: no memory found");
|
||||
return (i);
|
||||
|
||||
overflow:
|
||||
/*
|
||||
* Oops, there are more things in the PROM than our caller
|
||||
* provided space for. Truncate any extras.
|
||||
*/
|
||||
printf("makememarr: WARNING: lost some memory\n");
|
||||
return (i);
|
||||
}
|
||||
|
||||
#if defined(SUN4C) || defined(SUN4M)
|
||||
#if defined(SUN4C) || defined(SUN4M) || defined(SUN4D)
|
||||
int
|
||||
PROM_getprop_reg1(node, rrp)
|
||||
int node;
|
||||
|
@ -1599,7 +1463,7 @@ PROM_getprop_address1(node, vpp)
|
|||
free(vp, M_DEVBUF);
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
#endif /* SUN4C || SUN4M || SUN4D */
|
||||
|
||||
#ifdef RASTERCONSOLE
|
||||
/*
|
||||
|
@ -1629,7 +1493,7 @@ romgetcursoraddr(rowp, colp)
|
|||
prom_interpret(buf);
|
||||
return (*rowp == NULL || *colp == NULL);
|
||||
}
|
||||
#endif
|
||||
#endif /* RASTERCONSOLE */
|
||||
|
||||
/*
|
||||
* find a device matching "name" and unit number
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: pmap.c,v 1.239 2003/02/15 13:30:11 pk Exp $ */
|
||||
/* $NetBSD: pmap.c,v 1.240 2003/02/18 13:36:52 pk Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996
|
||||
|
@ -935,7 +935,7 @@ get_phys_mem()
|
|||
struct memarr *mp;
|
||||
int i;
|
||||
|
||||
npmemarr = makememarr(pmemarr, MA_SIZE, MEMARR_AVAILPHYS);
|
||||
npmemarr = prom_makememarr(pmemarr, MA_SIZE, MEMARR_AVAILPHYS);
|
||||
|
||||
for (physmem = 0, mp = pmemarr, i = npmemarr; --i >= 0; mp++)
|
||||
physmem += btoc(mp->len);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: promlib.c,v 1.13 2001/12/07 11:00:39 hannken Exp $ */
|
||||
/* $NetBSD: promlib.c,v 1.14 2003/02/18 13:36:52 pk Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
||||
|
@ -795,6 +795,144 @@ opf_nextprop(node, prop)
|
|||
return (buf);
|
||||
}
|
||||
|
||||
int
|
||||
prom_makememarr(ap, max, which)
|
||||
struct memarr *ap;
|
||||
int max, which;
|
||||
{
|
||||
struct v2rmi {
|
||||
int zero;
|
||||
int addr;
|
||||
int len;
|
||||
} v2rmi[200]; /* version 2 rom meminfo layout */
|
||||
#define MAXMEMINFO ((int)sizeof(v2rmi) / (int)sizeof(*v2rmi))
|
||||
void *p;
|
||||
|
||||
struct v0mlist *mp;
|
||||
int i, node, len;
|
||||
char *prop;
|
||||
|
||||
switch (prom_version()) {
|
||||
struct promvec *promvec;
|
||||
struct om_vector *oldpvec;
|
||||
case PROM_OLDMON:
|
||||
oldpvec = (struct om_vector *)PROM_BASE;
|
||||
switch (which) {
|
||||
case MEMARR_AVAILPHYS:
|
||||
ap[0].addr = 0;
|
||||
ap[0].len = *oldpvec->memoryAvail;
|
||||
break;
|
||||
case MEMARR_TOTALPHYS:
|
||||
ap[0].addr = 0;
|
||||
ap[0].len = *oldpvec->memorySize;
|
||||
break;
|
||||
default:
|
||||
printf("pre_panic: makememarr");
|
||||
break;
|
||||
}
|
||||
i = (1);
|
||||
break;
|
||||
|
||||
case PROM_OBP_V0:
|
||||
/*
|
||||
* Version 0 PROMs use a linked list to describe these
|
||||
* guys.
|
||||
*/
|
||||
promvec = romp;
|
||||
switch (which) {
|
||||
case MEMARR_AVAILPHYS:
|
||||
mp = *promvec->pv_v0mem.v0_physavail;
|
||||
break;
|
||||
|
||||
case MEMARR_TOTALPHYS:
|
||||
mp = *promvec->pv_v0mem.v0_phystot;
|
||||
break;
|
||||
|
||||
default:
|
||||
panic("makememarr");
|
||||
}
|
||||
for (i = 0; mp != NULL; mp = mp->next, i++) {
|
||||
if (i >= max)
|
||||
goto overflow;
|
||||
ap->addr = (u_int)mp->addr;
|
||||
ap->len = mp->nbytes;
|
||||
ap++;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("makememarr: hope version %d PROM is like version 2\n",
|
||||
prom_version());
|
||||
/* FALLTHROUGH */
|
||||
|
||||
case PROM_OBP_V3:
|
||||
case PROM_OBP_V2:
|
||||
/*
|
||||
* Version 2 PROMs use a property array to describe them.
|
||||
*/
|
||||
|
||||
/* Consider emulating `OF_finddevice' */
|
||||
node = findnode(firstchild(findroot()), "memory");
|
||||
goto case_common;
|
||||
|
||||
case PROM_OPENFIRM:
|
||||
node = OF_finddevice("/memory");
|
||||
if (node == -1)
|
||||
node = 0;
|
||||
|
||||
case_common:
|
||||
if (node == 0)
|
||||
panic("makememarr: cannot find \"memory\" node");
|
||||
|
||||
if (max > MAXMEMINFO) {
|
||||
printf("makememarr: limited to %d\n", MAXMEMINFO);
|
||||
max = MAXMEMINFO;
|
||||
}
|
||||
|
||||
switch (which) {
|
||||
case MEMARR_AVAILPHYS:
|
||||
prop = "available";
|
||||
break;
|
||||
|
||||
case MEMARR_TOTALPHYS:
|
||||
prop = "reg";
|
||||
break;
|
||||
|
||||
default:
|
||||
panic("makememarr");
|
||||
}
|
||||
|
||||
len = MAXMEMINFO;
|
||||
p = v2rmi;
|
||||
if (PROM_getprop(node, prop, sizeof(struct v2rmi), &len, &p) != 0)
|
||||
panic("makememarr: cannot get property");
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
if (i >= max)
|
||||
goto overflow;
|
||||
ap->addr = v2rmi[i].addr;
|
||||
ap->len = v2rmi[i].len;
|
||||
ap++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Success! (Hooray)
|
||||
*/
|
||||
if (i == 0)
|
||||
panic("makememarr: no memory found");
|
||||
return (i);
|
||||
|
||||
overflow:
|
||||
/*
|
||||
* Oops, there are more things in the PROM than our caller
|
||||
* provided space for. Truncate any extras.
|
||||
*/
|
||||
printf("makememarr: WARNING: lost some memory\n");
|
||||
return (i);
|
||||
}
|
||||
|
||||
static void prom_init_oldmon __P((void));
|
||||
static void prom_init_obp __P((void));
|
||||
static void prom_init_opf __P((void));
|
||||
|
|
Loading…
Reference in New Issue