Home | History | Annotate | Line # | Download | only in common
promdev.c revision 1.12.4.2
      1  1.12.4.2  nathanw /*	$NetBSD: promdev.c,v 1.12.4.2 2002/10/18 02:40:01 nathanw Exp $ */
      2  1.12.4.2  nathanw 
      3  1.12.4.2  nathanw /*
      4  1.12.4.2  nathanw  * Copyright (c) 1993 Paul Kranenburg
      5  1.12.4.2  nathanw  * Copyright (c) 1995 Gordon W. Ross
      6  1.12.4.2  nathanw  * All rights reserved.
      7  1.12.4.2  nathanw  *
      8  1.12.4.2  nathanw  * Redistribution and use in source and binary forms, with or without
      9  1.12.4.2  nathanw  * modification, are permitted provided that the following conditions
     10  1.12.4.2  nathanw  * are met:
     11  1.12.4.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     12  1.12.4.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     13  1.12.4.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.12.4.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     15  1.12.4.2  nathanw  *    documentation and/or other materials provided with the distribution.
     16  1.12.4.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     17  1.12.4.2  nathanw  *    must display the following acknowledgement:
     18  1.12.4.2  nathanw  *      This product includes software developed by Paul Kranenburg.
     19  1.12.4.2  nathanw  * 4. The name of the author may not be used to endorse or promote products
     20  1.12.4.2  nathanw  *    derived from this software without specific prior written permission
     21  1.12.4.2  nathanw  *
     22  1.12.4.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  1.12.4.2  nathanw  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  1.12.4.2  nathanw  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  1.12.4.2  nathanw  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  1.12.4.2  nathanw  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  1.12.4.2  nathanw  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  1.12.4.2  nathanw  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  1.12.4.2  nathanw  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  1.12.4.2  nathanw  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  1.12.4.2  nathanw  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  1.12.4.2  nathanw  */
     33  1.12.4.2  nathanw 
     34  1.12.4.2  nathanw /*
     35  1.12.4.2  nathanw  * Note: the `#ifndef BOOTXX' in here serve to queeze the code size
     36  1.12.4.2  nathanw  * of the 1st-stage boot program.
     37  1.12.4.2  nathanw  */
     38  1.12.4.2  nathanw #include <sys/param.h>
     39  1.12.4.2  nathanw #include <sys/reboot.h>
     40  1.12.4.2  nathanw #include <sys/systm.h>
     41  1.12.4.2  nathanw #include <machine/idprom.h>
     42  1.12.4.2  nathanw #include <machine/oldmon.h>
     43  1.12.4.2  nathanw #include <machine/promlib.h>
     44  1.12.4.2  nathanw #include <machine/ctlreg.h>
     45  1.12.4.2  nathanw #include <sparc/sparc/asm.h>
     46  1.12.4.2  nathanw #include <machine/pte.h>
     47  1.12.4.2  nathanw 
     48  1.12.4.2  nathanw #include <lib/libsa/stand.h>
     49  1.12.4.2  nathanw 
     50  1.12.4.2  nathanw #include <sparc/stand/common/promdev.h>
     51  1.12.4.2  nathanw 
     52  1.12.4.2  nathanw /* OBP V0-3 PROM vector */
     53  1.12.4.2  nathanw #define obpvec	((struct promvec *)romp)
     54  1.12.4.2  nathanw 
     55  1.12.4.2  nathanw int	obp_close __P((struct open_file *));
     56  1.12.4.2  nathanw int	obp_strategy __P((void *, int, daddr_t, size_t, void *, size_t *));
     57  1.12.4.2  nathanw int	obp_v0_strategy __P((void *, int, daddr_t, size_t, void *, size_t *));
     58  1.12.4.2  nathanw ssize_t	obp_v0_xmit __P((struct promdata *, void *, size_t));
     59  1.12.4.2  nathanw ssize_t	obp_v0_recv __P((struct promdata *, void *, size_t));
     60  1.12.4.2  nathanw int	obp_v2_strategy __P((void *, int, daddr_t, size_t, void *, size_t *));
     61  1.12.4.2  nathanw ssize_t	obp_v2_xmit __P((struct promdata *, void *, size_t));
     62  1.12.4.2  nathanw ssize_t	obp_v2_recv __P((struct promdata *, void *, size_t));
     63  1.12.4.2  nathanw int	oldmon_close __P((struct open_file *));
     64  1.12.4.2  nathanw int	oldmon_strategy __P((void *, int, daddr_t, size_t, void *, size_t *));
     65  1.12.4.2  nathanw void	oldmon_iclose __P((struct saioreq *));
     66  1.12.4.2  nathanw int	oldmon_iopen __P((struct promdata *));
     67  1.12.4.2  nathanw ssize_t	oldmon_xmit __P((struct promdata *, void *, size_t));
     68  1.12.4.2  nathanw ssize_t	oldmon_recv __P((struct promdata *, void *, size_t));
     69  1.12.4.2  nathanw 
     70  1.12.4.2  nathanw static char	*oldmon_mapin __P((u_long, int, int));
     71  1.12.4.2  nathanw #ifndef BOOTXX
     72  1.12.4.2  nathanw static char	*mygetpropstring __P((int, char *));
     73  1.12.4.2  nathanw static int	getdevtype __P((int, char *));
     74  1.12.4.2  nathanw #endif
     75  1.12.4.2  nathanw 
     76  1.12.4.2  nathanw extern struct filesystem file_system_nfs[];
     77  1.12.4.2  nathanw extern struct filesystem file_system_ufs[];
     78  1.12.4.2  nathanw 
     79  1.12.4.2  nathanw #define null_devopen	(void *)sparc_noop
     80  1.12.4.2  nathanw #define null_devioctl	(void *)sparc_noop
     81  1.12.4.2  nathanw 
     82  1.12.4.2  nathanw #if 0
     83  1.12.4.2  nathanw struct devsw devsw[];
     84  1.12.4.2  nathanw int	ndevs = (sizeof(devsw)/sizeof(devsw[0]));
     85  1.12.4.2  nathanw #endif
     86  1.12.4.2  nathanw 
     87  1.12.4.2  nathanw struct devsw oldmon_devsw =
     88  1.12.4.2  nathanw 	{ "oldmon", oldmon_strategy, null_devopen, oldmon_close, null_devioctl };
     89  1.12.4.2  nathanw struct devsw obp_v0_devsw =
     90  1.12.4.2  nathanw 	{ "obp v0", obp_v0_strategy, null_devopen, obp_close, null_devioctl };
     91  1.12.4.2  nathanw struct devsw obp_v2_devsw =
     92  1.12.4.2  nathanw 	{ "obp v2", obp_v2_strategy, null_devopen, obp_close, null_devioctl };
     93  1.12.4.2  nathanw 
     94  1.12.4.2  nathanw 
     95  1.12.4.2  nathanw char	*prom_bootdevice;
     96  1.12.4.2  nathanw static int	saveecho;
     97  1.12.4.2  nathanw 
     98  1.12.4.2  nathanw 
     99  1.12.4.2  nathanw void
    100  1.12.4.2  nathanw putchar(c)
    101  1.12.4.2  nathanw 	int c;
    102  1.12.4.2  nathanw {
    103  1.12.4.2  nathanw 
    104  1.12.4.2  nathanw 	if (c == '\n')
    105  1.12.4.2  nathanw 		prom_putchar('\r');
    106  1.12.4.2  nathanw 	prom_putchar(c);
    107  1.12.4.2  nathanw }
    108  1.12.4.2  nathanw 
    109  1.12.4.2  nathanw void
    110  1.12.4.2  nathanw _rtt()
    111  1.12.4.2  nathanw {
    112  1.12.4.2  nathanw 	prom_halt();
    113  1.12.4.2  nathanw }
    114  1.12.4.2  nathanw 
    115  1.12.4.2  nathanw int
    116  1.12.4.2  nathanw devopen(f, fname, file)
    117  1.12.4.2  nathanw 	struct open_file *f;
    118  1.12.4.2  nathanw 	const char *fname;
    119  1.12.4.2  nathanw 	char **file;
    120  1.12.4.2  nathanw {
    121  1.12.4.2  nathanw 	int	error = 0, fd = 0;
    122  1.12.4.2  nathanw 	struct	promdata *pd;
    123  1.12.4.2  nathanw 
    124  1.12.4.2  nathanw 	pd = (struct promdata *)alloc(sizeof *pd);
    125  1.12.4.2  nathanw 	f->f_devdata = (void *)pd;
    126  1.12.4.2  nathanw 
    127  1.12.4.2  nathanw 	switch (prom_version()) {
    128  1.12.4.2  nathanw 	case PROM_OLDMON:
    129  1.12.4.2  nathanw 		error = oldmon_iopen(pd);
    130  1.12.4.2  nathanw #ifndef BOOTXX
    131  1.12.4.2  nathanw 		pd->xmit = oldmon_xmit;
    132  1.12.4.2  nathanw 		pd->recv = oldmon_recv;
    133  1.12.4.2  nathanw #endif
    134  1.12.4.2  nathanw 		f->f_dev = &oldmon_devsw;
    135  1.12.4.2  nathanw 		saveecho = *romVectorPtr->echo;
    136  1.12.4.2  nathanw 		*romVectorPtr->echo = 0;
    137  1.12.4.2  nathanw 		break;
    138  1.12.4.2  nathanw 
    139  1.12.4.2  nathanw 	case PROM_OBP_V0:
    140  1.12.4.2  nathanw 	case PROM_OBP_V2:
    141  1.12.4.2  nathanw 	case PROM_OBP_V3:
    142  1.12.4.2  nathanw 	case PROM_OPENFIRM:
    143  1.12.4.2  nathanw 		if (prom_bootdevice == NULL) {
    144  1.12.4.2  nathanw 			error = ENXIO;
    145  1.12.4.2  nathanw 			break;
    146  1.12.4.2  nathanw 		}
    147  1.12.4.2  nathanw 		fd = prom_open(prom_bootdevice);
    148  1.12.4.2  nathanw 		if (fd == 0) {
    149  1.12.4.2  nathanw 			error = ENXIO;
    150  1.12.4.2  nathanw 			break;
    151  1.12.4.2  nathanw 		}
    152  1.12.4.2  nathanw 		pd->fd = fd;
    153  1.12.4.2  nathanw 		switch (prom_version()) {
    154  1.12.4.2  nathanw 		case PROM_OBP_V0:
    155  1.12.4.2  nathanw #ifndef BOOTXX
    156  1.12.4.2  nathanw 			pd->xmit = obp_v0_xmit;
    157  1.12.4.2  nathanw 			pd->recv = obp_v0_recv;
    158  1.12.4.2  nathanw #endif
    159  1.12.4.2  nathanw 			f->f_dev = &obp_v0_devsw;
    160  1.12.4.2  nathanw 			break;
    161  1.12.4.2  nathanw 		case PROM_OBP_V2:
    162  1.12.4.2  nathanw 		case PROM_OBP_V3:
    163  1.12.4.2  nathanw 		case PROM_OPENFIRM:
    164  1.12.4.2  nathanw #ifndef BOOTXX
    165  1.12.4.2  nathanw 			pd->xmit = obp_v2_xmit;
    166  1.12.4.2  nathanw 			pd->recv = obp_v2_recv;
    167  1.12.4.2  nathanw #endif
    168  1.12.4.2  nathanw 			f->f_dev = &obp_v2_devsw;
    169  1.12.4.2  nathanw 		}
    170  1.12.4.2  nathanw 	}
    171  1.12.4.2  nathanw 
    172  1.12.4.2  nathanw 	if (error) {
    173  1.12.4.2  nathanw 		printf("Can't open device `%s'\n", prom_bootdevice);
    174  1.12.4.2  nathanw 		return (error);
    175  1.12.4.2  nathanw 	}
    176  1.12.4.2  nathanw 
    177  1.12.4.2  nathanw #ifdef BOOTXX
    178  1.12.4.2  nathanw 	pd->devtype = DT_BLOCK;
    179  1.12.4.2  nathanw #else /* BOOTXX */
    180  1.12.4.2  nathanw 	pd->devtype = getdevtype(fd, prom_bootdevice);
    181  1.12.4.2  nathanw 	/* Assume type BYTE is a raw device */
    182  1.12.4.2  nathanw 	if (pd->devtype != DT_BYTE)
    183  1.12.4.2  nathanw 		*file = (char *)fname;
    184  1.12.4.2  nathanw 
    185  1.12.4.2  nathanw 	if (pd->devtype == DT_NET) {
    186  1.12.4.2  nathanw 		bcopy(file_system_nfs, file_system, sizeof(struct fs_ops));
    187  1.12.4.2  nathanw 		if ((error = net_open(pd)) != 0) {
    188  1.12.4.2  nathanw 			printf("Can't open NFS network connection on `%s'\n",
    189  1.12.4.2  nathanw 				prom_bootdevice);
    190  1.12.4.2  nathanw 			return (error);
    191  1.12.4.2  nathanw 		}
    192  1.12.4.2  nathanw 	} else
    193  1.12.4.2  nathanw 		bcopy(file_system_ufs, file_system, sizeof(struct fs_ops));
    194  1.12.4.2  nathanw #endif /* BOOTXX */
    195  1.12.4.2  nathanw 	return (0);
    196  1.12.4.2  nathanw }
    197  1.12.4.2  nathanw 
    198  1.12.4.2  nathanw 
    199  1.12.4.2  nathanw int
    200  1.12.4.2  nathanw obp_v0_strategy(devdata, flag, dblk, size, buf, rsize)
    201  1.12.4.2  nathanw 	void	*devdata;
    202  1.12.4.2  nathanw 	int	flag;
    203  1.12.4.2  nathanw 	daddr_t	dblk;
    204  1.12.4.2  nathanw 	size_t	size;
    205  1.12.4.2  nathanw 	void	*buf;
    206  1.12.4.2  nathanw 	size_t	*rsize;
    207  1.12.4.2  nathanw {
    208  1.12.4.2  nathanw 	int	n, error = 0;
    209  1.12.4.2  nathanw 	struct	promdata *pd = (struct promdata *)devdata;
    210  1.12.4.2  nathanw 	int	fd = pd->fd;
    211  1.12.4.2  nathanw 
    212  1.12.4.2  nathanw #ifdef DEBUG_PROM
    213  1.12.4.2  nathanw 	printf("promstrategy: size=%d dblk=%d\n", size, dblk);
    214  1.12.4.2  nathanw #endif
    215  1.12.4.2  nathanw 
    216  1.12.4.2  nathanw #define prom_bread(fd, nblk, dblk, buf) \
    217  1.12.4.2  nathanw 		(*obpvec->pv_v0devops.v0_rbdev)(fd, nblk, dblk, buf)
    218  1.12.4.2  nathanw #define prom_bwrite(fd, nblk, dblk, buf) \
    219  1.12.4.2  nathanw 		(*obpvec->pv_v0devops.v0_wbdev)(fd, nblk, dblk, buf)
    220  1.12.4.2  nathanw 
    221  1.12.4.2  nathanw #ifndef BOOTXX	/* We know it's a block device, so save some space */
    222  1.12.4.2  nathanw 	if (pd->devtype != DT_BLOCK) {
    223  1.12.4.2  nathanw 		printf("promstrategy: non-block device not supported\n");
    224  1.12.4.2  nathanw 		error = EINVAL;
    225  1.12.4.2  nathanw 	}
    226  1.12.4.2  nathanw #endif
    227  1.12.4.2  nathanw 
    228  1.12.4.2  nathanw 	n = (flag == F_READ)
    229  1.12.4.2  nathanw 		? prom_bread(fd, btodb(size), dblk, buf)
    230  1.12.4.2  nathanw 		: prom_bwrite(fd, btodb(size), dblk, buf);
    231  1.12.4.2  nathanw 
    232  1.12.4.2  nathanw 	*rsize = dbtob(n);
    233  1.12.4.2  nathanw 
    234  1.12.4.2  nathanw #ifdef DEBUG_PROM
    235  1.12.4.2  nathanw 	printf("rsize = %x\n", *rsize);
    236  1.12.4.2  nathanw #endif
    237  1.12.4.2  nathanw 	return (error);
    238  1.12.4.2  nathanw }
    239  1.12.4.2  nathanw 
    240  1.12.4.2  nathanw int
    241  1.12.4.2  nathanw obp_v2_strategy(devdata, flag, dblk, size, buf, rsize)
    242  1.12.4.2  nathanw 	void	*devdata;
    243  1.12.4.2  nathanw 	int	flag;
    244  1.12.4.2  nathanw 	daddr_t	dblk;
    245  1.12.4.2  nathanw 	size_t	size;
    246  1.12.4.2  nathanw 	void	*buf;
    247  1.12.4.2  nathanw 	size_t	*rsize;
    248  1.12.4.2  nathanw {
    249  1.12.4.2  nathanw 	int	error = 0;
    250  1.12.4.2  nathanw 	struct	promdata *pd = (struct promdata *)devdata;
    251  1.12.4.2  nathanw 	int	fd = pd->fd;
    252  1.12.4.2  nathanw 
    253  1.12.4.2  nathanw #ifdef DEBUG_PROM
    254  1.12.4.2  nathanw 	printf("promstrategy: size=%d dblk=%d\n", size, dblk);
    255  1.12.4.2  nathanw #endif
    256  1.12.4.2  nathanw 
    257  1.12.4.2  nathanw #ifndef BOOTXX	/* We know it's a block device, so save some space */
    258  1.12.4.2  nathanw 	if (pd->devtype == DT_BLOCK)
    259  1.12.4.2  nathanw #endif
    260  1.12.4.2  nathanw 		prom_seek(fd, dbtob(dblk));
    261  1.12.4.2  nathanw 
    262  1.12.4.2  nathanw 	*rsize = (flag == F_READ)
    263  1.12.4.2  nathanw 		? prom_read(fd, buf, size)
    264  1.12.4.2  nathanw 		: prom_write(fd, buf, size);
    265  1.12.4.2  nathanw 
    266  1.12.4.2  nathanw #ifdef DEBUG_PROM
    267  1.12.4.2  nathanw 	printf("rsize = %x\n", *rsize);
    268  1.12.4.2  nathanw #endif
    269  1.12.4.2  nathanw 	return (error);
    270  1.12.4.2  nathanw }
    271  1.12.4.2  nathanw 
    272  1.12.4.2  nathanw /*
    273  1.12.4.2  nathanw  * On old-monitor machines, things work differently.
    274  1.12.4.2  nathanw  */
    275  1.12.4.2  nathanw int
    276  1.12.4.2  nathanw oldmon_strategy(devdata, flag, dblk, size, buf, rsize)
    277  1.12.4.2  nathanw 	void	*devdata;
    278  1.12.4.2  nathanw 	int	flag;
    279  1.12.4.2  nathanw 	daddr_t	dblk;
    280  1.12.4.2  nathanw 	size_t	size;
    281  1.12.4.2  nathanw 	void	*buf;
    282  1.12.4.2  nathanw 	size_t	*rsize;
    283  1.12.4.2  nathanw {
    284  1.12.4.2  nathanw 	struct promdata	*pd = devdata;
    285  1.12.4.2  nathanw 	struct saioreq	*si;
    286  1.12.4.2  nathanw 	struct om_boottable *ops;
    287  1.12.4.2  nathanw 	char	*dmabuf;
    288  1.12.4.2  nathanw 	int	si_flag;
    289  1.12.4.2  nathanw 	size_t	xcnt;
    290  1.12.4.2  nathanw 
    291  1.12.4.2  nathanw 	si = pd->si;
    292  1.12.4.2  nathanw 	ops = si->si_boottab;
    293  1.12.4.2  nathanw 
    294  1.12.4.2  nathanw #ifdef DEBUG_PROM
    295  1.12.4.2  nathanw 	printf("prom_strategy: size=%d dblk=%d\n", size, dblk);
    296  1.12.4.2  nathanw #endif
    297  1.12.4.2  nathanw 
    298  1.12.4.2  nathanw 	dmabuf = dvma_mapin(buf, size);
    299  1.12.4.2  nathanw 
    300  1.12.4.2  nathanw 	si->si_bn = dblk;
    301  1.12.4.2  nathanw 	si->si_ma = dmabuf;
    302  1.12.4.2  nathanw 	si->si_cc = size;
    303  1.12.4.2  nathanw 
    304  1.12.4.2  nathanw 	si_flag = (flag == F_READ) ? SAIO_F_READ : SAIO_F_WRITE;
    305  1.12.4.2  nathanw 	xcnt = (*ops->b_strategy)(si, si_flag);
    306  1.12.4.2  nathanw 	dvma_mapout(dmabuf, size);
    307  1.12.4.2  nathanw 
    308  1.12.4.2  nathanw #ifdef DEBUG_PROM
    309  1.12.4.2  nathanw 	printf("disk_strategy: xcnt = %x\n", xcnt);
    310  1.12.4.2  nathanw #endif
    311  1.12.4.2  nathanw 
    312  1.12.4.2  nathanw 	if (xcnt <= 0)
    313  1.12.4.2  nathanw 		return (EIO);
    314  1.12.4.2  nathanw 
    315  1.12.4.2  nathanw 	*rsize = xcnt;
    316  1.12.4.2  nathanw 	return (0);
    317  1.12.4.2  nathanw }
    318  1.12.4.2  nathanw 
    319  1.12.4.2  nathanw int
    320  1.12.4.2  nathanw obp_close(f)
    321  1.12.4.2  nathanw 	struct open_file *f;
    322  1.12.4.2  nathanw {
    323  1.12.4.2  nathanw 	struct promdata *pd = f->f_devdata;
    324  1.12.4.2  nathanw 	register int fd = pd->fd;
    325  1.12.4.2  nathanw 
    326  1.12.4.2  nathanw #ifndef BOOTXX
    327  1.12.4.2  nathanw 	if (pd->devtype == DT_NET)
    328  1.12.4.2  nathanw 		net_close(pd);
    329  1.12.4.2  nathanw #endif
    330  1.12.4.2  nathanw 	prom_close(fd);
    331  1.12.4.2  nathanw 	return 0;
    332  1.12.4.2  nathanw }
    333  1.12.4.2  nathanw 
    334  1.12.4.2  nathanw int
    335  1.12.4.2  nathanw oldmon_close(f)
    336  1.12.4.2  nathanw 	struct open_file *f;
    337  1.12.4.2  nathanw {
    338  1.12.4.2  nathanw 	struct promdata *pd = f->f_devdata;
    339  1.12.4.2  nathanw 
    340  1.12.4.2  nathanw #ifndef BOOTXX
    341  1.12.4.2  nathanw 	if (pd->devtype == DT_NET)
    342  1.12.4.2  nathanw 		net_close(pd);
    343  1.12.4.2  nathanw #endif
    344  1.12.4.2  nathanw 	oldmon_iclose(pd->si);
    345  1.12.4.2  nathanw 	pd->si = NULL;
    346  1.12.4.2  nathanw 	*romVectorPtr->echo = saveecho; /* Hmm, probably must go somewhere else */
    347  1.12.4.2  nathanw 	return 0;
    348  1.12.4.2  nathanw }
    349  1.12.4.2  nathanw 
    350  1.12.4.2  nathanw #ifndef BOOTXX
    351  1.12.4.2  nathanw ssize_t
    352  1.12.4.2  nathanw obp_v0_xmit(pd, buf, len)
    353  1.12.4.2  nathanw 	struct	promdata *pd;
    354  1.12.4.2  nathanw 	void	*buf;
    355  1.12.4.2  nathanw 	size_t	len;
    356  1.12.4.2  nathanw {
    357  1.12.4.2  nathanw 
    358  1.12.4.2  nathanw 	return ((*obpvec->pv_v0devops.v0_wnet)(pd->fd, len, buf));
    359  1.12.4.2  nathanw }
    360  1.12.4.2  nathanw 
    361  1.12.4.2  nathanw ssize_t
    362  1.12.4.2  nathanw obp_v2_xmit(pd, buf, len)
    363  1.12.4.2  nathanw 	struct	promdata *pd;
    364  1.12.4.2  nathanw 	void	*buf;
    365  1.12.4.2  nathanw 	size_t	len;
    366  1.12.4.2  nathanw {
    367  1.12.4.2  nathanw 
    368  1.12.4.2  nathanw 	return (prom_write(pd->fd, buf, len));
    369  1.12.4.2  nathanw }
    370  1.12.4.2  nathanw 
    371  1.12.4.2  nathanw ssize_t
    372  1.12.4.2  nathanw obp_v0_recv(pd, buf, len)
    373  1.12.4.2  nathanw 	struct	promdata *pd;
    374  1.12.4.2  nathanw 	void	*buf;
    375  1.12.4.2  nathanw 	size_t	len;
    376  1.12.4.2  nathanw {
    377  1.12.4.2  nathanw 
    378  1.12.4.2  nathanw 	return ((*obpvec->pv_v0devops.v0_rnet)(pd->fd, len, buf));
    379  1.12.4.2  nathanw }
    380  1.12.4.2  nathanw 
    381  1.12.4.2  nathanw ssize_t
    382  1.12.4.2  nathanw obp_v2_recv(pd, buf, len)
    383  1.12.4.2  nathanw 	struct	promdata *pd;
    384  1.12.4.2  nathanw 	void	*buf;
    385  1.12.4.2  nathanw 	size_t	len;
    386  1.12.4.2  nathanw {
    387  1.12.4.2  nathanw 	int	n;
    388  1.12.4.2  nathanw 
    389  1.12.4.2  nathanw 	n = prom_read(pd->fd, buf, len);
    390  1.12.4.2  nathanw 
    391  1.12.4.2  nathanw 	/* OBP V2 & V3 may return -2 */
    392  1.12.4.2  nathanw 	return (n == -2 ? 0 : n);
    393  1.12.4.2  nathanw }
    394  1.12.4.2  nathanw 
    395  1.12.4.2  nathanw ssize_t
    396  1.12.4.2  nathanw oldmon_xmit(pd, buf, len)
    397  1.12.4.2  nathanw 	struct	promdata *pd;
    398  1.12.4.2  nathanw 	void	*buf;
    399  1.12.4.2  nathanw 	size_t	len;
    400  1.12.4.2  nathanw {
    401  1.12.4.2  nathanw 	struct saioreq	*si;
    402  1.12.4.2  nathanw 	struct saif	*sif;
    403  1.12.4.2  nathanw 	char		*dmabuf;
    404  1.12.4.2  nathanw 	int		rv;
    405  1.12.4.2  nathanw 
    406  1.12.4.2  nathanw 	si = pd->si;
    407  1.12.4.2  nathanw 	sif = si->si_sif;
    408  1.12.4.2  nathanw 	if (sif == NULL) {
    409  1.12.4.2  nathanw 		printf("xmit: not a network device\n");
    410  1.12.4.2  nathanw 		return (-1);
    411  1.12.4.2  nathanw 	}
    412  1.12.4.2  nathanw 	dmabuf = dvma_mapin(buf, len);
    413  1.12.4.2  nathanw 	rv = sif->sif_xmit(si->si_devdata, dmabuf, len);
    414  1.12.4.2  nathanw 	dvma_mapout(dmabuf, len);
    415  1.12.4.2  nathanw 
    416  1.12.4.2  nathanw 	return (ssize_t)(rv ? -1 : len);
    417  1.12.4.2  nathanw }
    418  1.12.4.2  nathanw 
    419  1.12.4.2  nathanw ssize_t
    420  1.12.4.2  nathanw oldmon_recv(pd, buf, len)
    421  1.12.4.2  nathanw 	struct	promdata *pd;
    422  1.12.4.2  nathanw 	void	*buf;
    423  1.12.4.2  nathanw 	size_t	len;
    424  1.12.4.2  nathanw {
    425  1.12.4.2  nathanw 	struct saioreq	*si;
    426  1.12.4.2  nathanw 	struct saif	*sif;
    427  1.12.4.2  nathanw 	char		*dmabuf;
    428  1.12.4.2  nathanw 	int		rv;
    429  1.12.4.2  nathanw 
    430  1.12.4.2  nathanw 	si = pd->si;
    431  1.12.4.2  nathanw 	sif = si->si_sif;
    432  1.12.4.2  nathanw 	dmabuf = dvma_mapin(buf, len);
    433  1.12.4.2  nathanw 	rv = sif->sif_poll(si->si_devdata, dmabuf);
    434  1.12.4.2  nathanw 	dvma_mapout(dmabuf, len);
    435  1.12.4.2  nathanw 
    436  1.12.4.2  nathanw 	return (ssize_t)rv;
    437  1.12.4.2  nathanw }
    438  1.12.4.2  nathanw 
    439  1.12.4.2  nathanw int
    440  1.12.4.2  nathanw getchar()
    441  1.12.4.2  nathanw {
    442  1.12.4.2  nathanw 	return (prom_getchar());
    443  1.12.4.2  nathanw }
    444  1.12.4.2  nathanw 
    445  1.12.4.2  nathanw time_t
    446  1.12.4.2  nathanw getsecs()
    447  1.12.4.2  nathanw {
    448  1.12.4.2  nathanw 	(void)prom_peekchar();
    449  1.12.4.2  nathanw 	return (prom_ticks() / 1000);
    450  1.12.4.2  nathanw }
    451  1.12.4.2  nathanw 
    452  1.12.4.2  nathanw 
    453  1.12.4.2  nathanw 
    454  1.12.4.2  nathanw void
    455  1.12.4.2  nathanw prom_getether(fd, ea)
    456  1.12.4.2  nathanw 	int fd;
    457  1.12.4.2  nathanw 	u_char *ea;
    458  1.12.4.2  nathanw {
    459  1.12.4.2  nathanw static	struct idprom idprom;
    460  1.12.4.2  nathanw 
    461  1.12.4.2  nathanw 	switch (prom_version()) {
    462  1.12.4.2  nathanw 	case PROM_OLDMON:
    463  1.12.4.2  nathanw 		if (idprom.id_format == 0) {
    464  1.12.4.2  nathanw 			int len = sizeof(struct idprom);
    465  1.12.4.2  nathanw 			u_char *src = (char *)AC_IDPROM;
    466  1.12.4.2  nathanw 			u_char *dst = (char *)&idprom;
    467  1.12.4.2  nathanw 			do {
    468  1.12.4.2  nathanw 				*dst++ = lduba(src++, ASI_CONTROL);
    469  1.12.4.2  nathanw 			} while (--len > 0);
    470  1.12.4.2  nathanw 		}
    471  1.12.4.2  nathanw 		bcopy(idprom.id_ether, ea, 6);
    472  1.12.4.2  nathanw 		break;
    473  1.12.4.2  nathanw 
    474  1.12.4.2  nathanw 	/*
    475  1.12.4.2  nathanw 	 * XXX - maybe we should simply always look at the `idprom' property
    476  1.12.4.2  nathanw 	 *	 and not bother with `pv_enaddr' or `prom_interpret()' at all.
    477  1.12.4.2  nathanw 	 */
    478  1.12.4.2  nathanw 	case PROM_OBP_V0:
    479  1.12.4.2  nathanw 		if (idprom.id_format == 0) {
    480  1.12.4.2  nathanw 			void *buf = &idprom;
    481  1.12.4.2  nathanw 			int len = sizeof(struct idprom);
    482  1.12.4.2  nathanw 			int node = prom_findroot();
    483  1.12.4.2  nathanw 			if (PROM_getprop(node, "idprom", 1, &len, &buf) != 0) {
    484  1.12.4.2  nathanw 				printf("`idprom' property cannot be read: "
    485  1.12.4.2  nathanw 					"cannot get ethernet address");
    486  1.12.4.2  nathanw 				/*
    487  1.12.4.2  nathanw 				 * Copy ethernet address into `ea' anyway,
    488  1.12.4.2  nathanw 				 * so that it will be zeroed.
    489  1.12.4.2  nathanw 				 */
    490  1.12.4.2  nathanw 			}
    491  1.12.4.2  nathanw 		}
    492  1.12.4.2  nathanw 		bcopy(idprom.id_ether, ea, 6);
    493  1.12.4.2  nathanw 		break;
    494  1.12.4.2  nathanw 
    495  1.12.4.2  nathanw 	case PROM_OBP_V2:
    496  1.12.4.2  nathanw 		(void)(*obpvec->pv_enaddr)(fd, (char *)ea);
    497  1.12.4.2  nathanw 		break;
    498  1.12.4.2  nathanw 
    499  1.12.4.2  nathanw 	case PROM_OPENFIRM:
    500  1.12.4.2  nathanw 	case PROM_OBP_V3:
    501  1.12.4.2  nathanw 		{
    502  1.12.4.2  nathanw 		char buf[64];
    503  1.12.4.2  nathanw 		sprintf(buf, "%lx mac-address drop swap 6 cmove", (u_long)ea);
    504  1.12.4.2  nathanw 		prom_interpret(buf);
    505  1.12.4.2  nathanw 		}
    506  1.12.4.2  nathanw 		break;
    507  1.12.4.2  nathanw 	}
    508  1.12.4.2  nathanw }
    509  1.12.4.2  nathanw 
    510  1.12.4.2  nathanw 
    511  1.12.4.2  nathanw /*
    512  1.12.4.2  nathanw  * A number of well-known devices on sun4s.
    513  1.12.4.2  nathanw  */
    514  1.12.4.2  nathanw static struct dtab {
    515  1.12.4.2  nathanw 	char	*name;
    516  1.12.4.2  nathanw 	int	type;
    517  1.12.4.2  nathanw } dtab[] = {
    518  1.12.4.2  nathanw 	{ "sd",	DT_BLOCK },
    519  1.12.4.2  nathanw 	{ "st",	DT_BLOCK },
    520  1.12.4.2  nathanw 	{ "xd",	DT_BLOCK },
    521  1.12.4.2  nathanw 	{ "xy",	DT_BLOCK },
    522  1.12.4.2  nathanw 	{ "fd",	DT_BLOCK },
    523  1.12.4.2  nathanw 	{ "le",	DT_NET },
    524  1.12.4.2  nathanw 	{ "ie",	DT_NET },
    525  1.12.4.2  nathanw 	{ NULL, 0 }
    526  1.12.4.2  nathanw };
    527  1.12.4.2  nathanw 
    528  1.12.4.2  nathanw int
    529  1.12.4.2  nathanw getdevtype(fd, name)
    530  1.12.4.2  nathanw 	int	fd;
    531  1.12.4.2  nathanw 	char	*name;
    532  1.12.4.2  nathanw {
    533  1.12.4.2  nathanw 	struct dtab *dp;
    534  1.12.4.2  nathanw 	int node;
    535  1.12.4.2  nathanw 	char *cp;
    536  1.12.4.2  nathanw 
    537  1.12.4.2  nathanw 	switch (prom_version()) {
    538  1.12.4.2  nathanw 	case PROM_OLDMON:
    539  1.12.4.2  nathanw 	case PROM_OBP_V0:
    540  1.12.4.2  nathanw 		for (dp = dtab; dp->name; dp++) {
    541  1.12.4.2  nathanw 			if (name[0] == dp->name[0] &&
    542  1.12.4.2  nathanw 			    name[1] == dp->name[1])
    543  1.12.4.2  nathanw 				return (dp->type);
    544  1.12.4.2  nathanw 		}
    545  1.12.4.2  nathanw 		break;
    546  1.12.4.2  nathanw 
    547  1.12.4.2  nathanw 	case PROM_OBP_V2:
    548  1.12.4.2  nathanw 	case PROM_OBP_V3:
    549  1.12.4.2  nathanw 	case PROM_OPENFIRM:
    550  1.12.4.2  nathanw 		node = prom_instance_to_package(fd);
    551  1.12.4.2  nathanw 		cp = mygetpropstring(node, "device_type");
    552  1.12.4.2  nathanw 		if (strcmp(cp, "block") == 0)
    553  1.12.4.2  nathanw 			return (DT_BLOCK);
    554  1.12.4.2  nathanw 		else if (strcmp(cp, "network") == 0)
    555  1.12.4.2  nathanw 			return (DT_NET);
    556  1.12.4.2  nathanw 		else if (strcmp(cp, "byte") == 0)
    557  1.12.4.2  nathanw 			return (DT_BYTE);
    558  1.12.4.2  nathanw 		break;
    559  1.12.4.2  nathanw 	}
    560  1.12.4.2  nathanw 	return (0);
    561  1.12.4.2  nathanw }
    562  1.12.4.2  nathanw 
    563  1.12.4.2  nathanw /*
    564  1.12.4.2  nathanw  * Return a string property.  There is a (small) limit on the length;
    565  1.12.4.2  nathanw  * the string is fetched into a static buffer which is overwritten on
    566  1.12.4.2  nathanw  * subsequent calls.
    567  1.12.4.2  nathanw  */
    568  1.12.4.2  nathanw char *
    569  1.12.4.2  nathanw mygetpropstring(node, name)
    570  1.12.4.2  nathanw 	int node;
    571  1.12.4.2  nathanw 	char *name;
    572  1.12.4.2  nathanw {
    573  1.12.4.2  nathanw 	int len;
    574  1.12.4.2  nathanw static	char buf[64];
    575  1.12.4.2  nathanw 
    576  1.12.4.2  nathanw 	len = prom_proplen(node, name);
    577  1.12.4.2  nathanw 	if (len > 0)
    578  1.12.4.2  nathanw 		_prom_getprop(node, name, buf, len);
    579  1.12.4.2  nathanw 	else
    580  1.12.4.2  nathanw 		len = 0;
    581  1.12.4.2  nathanw 
    582  1.12.4.2  nathanw 	buf[len] = '\0';	/* usually unnecessary */
    583  1.12.4.2  nathanw 	return (buf);
    584  1.12.4.2  nathanw }
    585  1.12.4.2  nathanw #endif /* BOOTXX */
    586  1.12.4.2  nathanw 
    587  1.12.4.2  nathanw /*
    588  1.12.4.2  nathanw  * Old monitor routines
    589  1.12.4.2  nathanw  */
    590  1.12.4.2  nathanw 
    591  1.12.4.2  nathanw struct saioreq prom_si;
    592  1.12.4.2  nathanw static int promdev_inuse;
    593  1.12.4.2  nathanw 
    594  1.12.4.2  nathanw int
    595  1.12.4.2  nathanw oldmon_iopen(pd)
    596  1.12.4.2  nathanw 	struct promdata	*pd;
    597  1.12.4.2  nathanw {
    598  1.12.4.2  nathanw 	struct om_bootparam *bp;
    599  1.12.4.2  nathanw 	struct om_boottable *ops;
    600  1.12.4.2  nathanw 	struct devinfo *dip;
    601  1.12.4.2  nathanw 	struct saioreq *si;
    602  1.12.4.2  nathanw 	int	error;
    603  1.12.4.2  nathanw 
    604  1.12.4.2  nathanw 	if (promdev_inuse)
    605  1.12.4.2  nathanw 		return (EMFILE);
    606  1.12.4.2  nathanw 
    607  1.12.4.2  nathanw 	bp = *romVectorPtr->bootParam;
    608  1.12.4.2  nathanw 	ops = bp->bootTable;
    609  1.12.4.2  nathanw 	dip = ops->b_devinfo;
    610  1.12.4.2  nathanw 
    611  1.12.4.2  nathanw #ifdef DEBUG_PROM
    612  1.12.4.2  nathanw 	printf("Boot device type: %s\n", ops->b_desc);
    613  1.12.4.2  nathanw 	printf("d_devbytes=%d\n", dip->d_devbytes);
    614  1.12.4.2  nathanw 	printf("d_dmabytes=%d\n", dip->d_dmabytes);
    615  1.12.4.2  nathanw 	printf("d_localbytes=%d\n", dip->d_localbytes);
    616  1.12.4.2  nathanw 	printf("d_stdcount=%d\n", dip->d_stdcount);
    617  1.12.4.2  nathanw 	printf("d_stdaddrs[%d]=%x\n", bp->ctlrNum, dip->d_stdaddrs[bp->ctlrNum]);
    618  1.12.4.2  nathanw 	printf("d_devtype=%d\n", dip->d_devtype);
    619  1.12.4.2  nathanw 	printf("d_maxiobytes=%d\n", dip->d_maxiobytes);
    620  1.12.4.2  nathanw #endif
    621  1.12.4.2  nathanw 
    622  1.12.4.2  nathanw 	dvma_init();
    623  1.12.4.2  nathanw 
    624  1.12.4.2  nathanw 	si = &prom_si;
    625  1.12.4.2  nathanw 	memset(si, 0, sizeof(*si));
    626  1.12.4.2  nathanw 	si->si_boottab = ops;
    627  1.12.4.2  nathanw 	si->si_ctlr = bp->ctlrNum;
    628  1.12.4.2  nathanw 	si->si_unit = bp->unitNum;
    629  1.12.4.2  nathanw 	si->si_boff = bp->partNum;
    630  1.12.4.2  nathanw 
    631  1.12.4.2  nathanw 	if (si->si_ctlr > dip->d_stdcount)
    632  1.12.4.2  nathanw 		return (ECTLR);
    633  1.12.4.2  nathanw 
    634  1.12.4.2  nathanw 	if (dip->d_devbytes) {
    635  1.12.4.2  nathanw 		si->si_devaddr = oldmon_mapin(dip->d_stdaddrs[si->si_ctlr],
    636  1.12.4.2  nathanw 			dip->d_devbytes, dip->d_devtype);
    637  1.12.4.2  nathanw #ifdef	DEBUG_PROM
    638  1.12.4.2  nathanw 		printf("prom_iopen: devaddr=0x%x pte=0x%x\n",
    639  1.12.4.2  nathanw 			si->si_devaddr,
    640  1.12.4.2  nathanw 			getpte4((u_long)si->si_devaddr & ~PGOFSET));
    641  1.12.4.2  nathanw #endif
    642  1.12.4.2  nathanw 	}
    643  1.12.4.2  nathanw 
    644  1.12.4.2  nathanw 	if (dip->d_dmabytes) {
    645  1.12.4.2  nathanw 		si->si_dmaaddr = dvma_alloc(dip->d_dmabytes);
    646  1.12.4.2  nathanw #ifdef	DEBUG_PROM
    647  1.12.4.2  nathanw 		printf("prom_iopen: dmaaddr=0x%x\n", si->si_dmaaddr);
    648  1.12.4.2  nathanw #endif
    649  1.12.4.2  nathanw 	}
    650  1.12.4.2  nathanw 
    651  1.12.4.2  nathanw 	if (dip->d_localbytes) {
    652  1.12.4.2  nathanw 		si->si_devdata = alloc(dip->d_localbytes);
    653  1.12.4.2  nathanw #ifdef	DEBUG_PROM
    654  1.12.4.2  nathanw 		printf("prom_iopen: devdata=0x%x\n", si->si_devdata);
    655  1.12.4.2  nathanw #endif
    656  1.12.4.2  nathanw 	}
    657  1.12.4.2  nathanw 
    658  1.12.4.2  nathanw 	/* OK, call the PROM device open routine. */
    659  1.12.4.2  nathanw 	error = (*ops->b_open)(si);
    660  1.12.4.2  nathanw 	if (error != 0) {
    661  1.12.4.2  nathanw 		printf("prom_iopen: \"%s\" error=%d\n", ops->b_desc, error);
    662  1.12.4.2  nathanw 		return (ENXIO);
    663  1.12.4.2  nathanw 	}
    664  1.12.4.2  nathanw #ifdef	DEBUG_PROM
    665  1.12.4.2  nathanw 	printf("prom_iopen: succeeded, error=%d\n", error);
    666  1.12.4.2  nathanw #endif
    667  1.12.4.2  nathanw 
    668  1.12.4.2  nathanw 	pd->si = si;
    669  1.12.4.2  nathanw 	promdev_inuse++;
    670  1.12.4.2  nathanw 	return (0);
    671  1.12.4.2  nathanw }
    672  1.12.4.2  nathanw 
    673  1.12.4.2  nathanw void
    674  1.12.4.2  nathanw oldmon_iclose(si)
    675  1.12.4.2  nathanw 	struct saioreq *si;
    676  1.12.4.2  nathanw {
    677  1.12.4.2  nathanw 	struct om_boottable *ops;
    678  1.12.4.2  nathanw 	struct devinfo *dip;
    679  1.12.4.2  nathanw 
    680  1.12.4.2  nathanw 	if (promdev_inuse == 0)
    681  1.12.4.2  nathanw 		return;
    682  1.12.4.2  nathanw 
    683  1.12.4.2  nathanw 	ops = si->si_boottab;
    684  1.12.4.2  nathanw 	dip = ops->b_devinfo;
    685  1.12.4.2  nathanw 
    686  1.12.4.2  nathanw 	(*ops->b_close)(si);
    687  1.12.4.2  nathanw 
    688  1.12.4.2  nathanw 	if (si->si_dmaaddr) {
    689  1.12.4.2  nathanw 		dvma_free(si->si_dmaaddr, dip->d_dmabytes);
    690  1.12.4.2  nathanw 		si->si_dmaaddr = NULL;
    691  1.12.4.2  nathanw 	}
    692  1.12.4.2  nathanw 
    693  1.12.4.2  nathanw 	promdev_inuse = 0;
    694  1.12.4.2  nathanw }
    695  1.12.4.2  nathanw 
    696  1.12.4.2  nathanw static struct mapinfo {
    697  1.12.4.2  nathanw 	int maptype;
    698  1.12.4.2  nathanw 	int pgtype;
    699  1.12.4.2  nathanw 	int base;
    700  1.12.4.2  nathanw } oldmon_mapinfo[] = {
    701  1.12.4.2  nathanw #define PG_COMMON	(PG_V|PG_W|PG_S|PG_NC)
    702  1.12.4.2  nathanw 	{ MAP_MAINMEM,   PG_OBMEM | PG_COMMON, 0 },
    703  1.12.4.2  nathanw 	{ MAP_OBIO,      PG_OBIO  | PG_COMMON, 0 },
    704  1.12.4.2  nathanw 	{ MAP_MBMEM,     PG_VME16 | PG_COMMON, 0xFF000000 },
    705  1.12.4.2  nathanw 	{ MAP_MBIO,      PG_VME16 | PG_COMMON, 0xFFFF0000 },
    706  1.12.4.2  nathanw 	{ MAP_VME16A16D, PG_VME16 | PG_COMMON, 0xFFFF0000 },
    707  1.12.4.2  nathanw 	{ MAP_VME16A32D, PG_VME32 | PG_COMMON, 0xFFFF0000 },
    708  1.12.4.2  nathanw 	{ MAP_VME24A16D, PG_VME16 | PG_COMMON, 0xFF000000 },
    709  1.12.4.2  nathanw 	{ MAP_VME24A32D, PG_VME32 | PG_COMMON, 0xFF000000 },
    710  1.12.4.2  nathanw 	{ MAP_VME32A16D, PG_VME16 | PG_COMMON, 0 },
    711  1.12.4.2  nathanw 	{ MAP_VME32A32D, PG_VME32 | PG_COMMON, 0 },
    712  1.12.4.2  nathanw };
    713  1.12.4.2  nathanw static int oldmon_mapinfo_cnt =
    714  1.12.4.2  nathanw 	sizeof(oldmon_mapinfo) / sizeof(oldmon_mapinfo[0]);
    715  1.12.4.2  nathanw 
    716  1.12.4.2  nathanw /* The virtual address we will use for PROM device mappings. */
    717  1.12.4.2  nathanw static u_long prom_devmap = MONSHORTSEG;
    718  1.12.4.2  nathanw 
    719  1.12.4.2  nathanw static char *
    720  1.12.4.2  nathanw oldmon_mapin(physaddr, length, maptype)
    721  1.12.4.2  nathanw 	u_long physaddr;
    722  1.12.4.2  nathanw 	int length, maptype;
    723  1.12.4.2  nathanw {
    724  1.12.4.2  nathanw 	int i, pa, pte, va;
    725  1.12.4.2  nathanw 
    726  1.12.4.2  nathanw 	if (length > (4*NBPG))
    727  1.12.4.2  nathanw 		panic("oldmon_mapin: length=%d", length);
    728  1.12.4.2  nathanw 
    729  1.12.4.2  nathanw 	for (i = 0; i < oldmon_mapinfo_cnt; i++)
    730  1.12.4.2  nathanw 		if (oldmon_mapinfo[i].maptype == maptype)
    731  1.12.4.2  nathanw 			goto found;
    732  1.12.4.2  nathanw 	panic("oldmon_mapin: invalid maptype %d", maptype);
    733  1.12.4.2  nathanw 
    734  1.12.4.2  nathanw found:
    735  1.12.4.2  nathanw 	pte = oldmon_mapinfo[i].pgtype;
    736  1.12.4.2  nathanw 	pa = oldmon_mapinfo[i].base;
    737  1.12.4.2  nathanw 	pa += physaddr;
    738  1.12.4.2  nathanw 	pte |= ((pa >> SUN4_PGSHIFT) & PG_PFNUM);
    739  1.12.4.2  nathanw 
    740  1.12.4.2  nathanw 	va = prom_devmap;
    741  1.12.4.2  nathanw 	do {
    742  1.12.4.2  nathanw 		setpte4(va, pte);
    743  1.12.4.2  nathanw 		va += NBPG;
    744  1.12.4.2  nathanw 		pte += 1;
    745  1.12.4.2  nathanw 		length -= NBPG;
    746  1.12.4.2  nathanw 	} while (length > 0);
    747  1.12.4.2  nathanw 	return ((char*)(prom_devmap | (pa & PGOFSET)));
    748  1.12.4.2  nathanw }
    749