Home | History | Annotate | Line # | Download | only in nubus
nubus.c revision 1.57
      1  1.57     lukem /*	$NetBSD: nubus.c,v 1.57 2003/07/15 02:43:24 lukem Exp $	*/
      2   1.8       cgd 
      3  1.11    briggs /*
      4  1.29    scottr  * Copyright (c) 1995, 1996 Allen Briggs.  All rights reserved.
      5   1.1    briggs  *
      6   1.1    briggs  * Redistribution and use in source and binary forms, with or without
      7   1.1    briggs  * modification, are permitted provided that the following conditions
      8   1.1    briggs  * are met:
      9   1.1    briggs  * 1. Redistributions of source code must retain the above copyright
     10   1.1    briggs  *    notice, this list of conditions and the following disclaimer.
     11   1.1    briggs  * 2. Redistributions in binary form must reproduce the above copyright
     12   1.1    briggs  *    notice, this list of conditions and the following disclaimer in the
     13   1.1    briggs  *    documentation and/or other materials provided with the distribution.
     14   1.1    briggs  * 3. All advertising materials mentioning features or use of this software
     15   1.1    briggs  *    must display the following acknowledgement:
     16  1.11    briggs  *	This product includes software developed by Allen Briggs.
     17  1.11    briggs  * 4. The name of the author may not be used to endorse or promote products
     18  1.11    briggs  *    derived from this software without specific prior written permission.
     19   1.1    briggs  *
     20  1.11    briggs  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21   1.1    briggs  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22   1.1    briggs  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  1.11    briggs  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24   1.1    briggs  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25   1.1    briggs  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26   1.1    briggs  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27   1.1    briggs  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  1.11    briggs  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  1.11    briggs  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30   1.1    briggs  */
     31  1.57     lukem 
     32  1.57     lukem #include <sys/cdefs.h>
     33  1.57     lukem __KERNEL_RCSID(0, "$NetBSD: nubus.c,v 1.57 2003/07/15 02:43:24 lukem Exp $");
     34   1.1    briggs 
     35   1.4    briggs #include <sys/param.h>
     36   1.4    briggs #include <sys/systm.h>
     37  1.53    briggs #include <sys/malloc.h>
     38  1.10    briggs #include <sys/device.h>
     39  1.29    scottr #include <sys/buf.h>
     40  1.29    scottr #include <sys/conf.h>
     41  1.29    scottr 
     42  1.49       mrg #include <uvm/uvm_extern.h>
     43  1.10    briggs 
     44  1.19    briggs #include <machine/autoconf.h>
     45  1.29    scottr #include <machine/vmparam.h>
     46  1.29    scottr #include <machine/param.h>
     47   1.4    briggs #include <machine/cpu.h>
     48  1.29    scottr #include <machine/pte.h>
     49  1.33    scottr #include <machine/viareg.h>
     50  1.12    briggs 
     51  1.44    scottr #include <mac68k/nubus/nubus.h>
     52   1.1    briggs 
     53  1.23    scottr #ifdef DEBUG
     54  1.12    briggs #define NDB_PROBE	0x1
     55  1.12    briggs #define NDB_FOLLOW	0x2
     56  1.12    briggs #define NDB_ARITH	0x4
     57  1.53    briggs static int	nubus_debug = 0 /* | NDB_PROBE | NDB_FOLLOW | NDB_ARITH */ ;
     58  1.12    briggs #endif
     59  1.12    briggs 
     60  1.28    scottr static int	nubus_print __P((void *, const char *));
     61  1.28    scottr static int	nubus_match __P((struct device *, struct cfdata *, void *));
     62  1.28    scottr static void	nubus_attach __P((struct device *, struct device *, void *));
     63  1.37    scottr static int	nubus_video_resource __P((int));
     64  1.11    briggs 
     65  1.37    scottr static int	nubus_probe_slot __P((bus_space_tag_t, bus_space_handle_t,
     66  1.37    scottr 		    int, nubus_slot *));
     67  1.37    scottr static u_int32_t nubus_calc_CRC __P((bus_space_tag_t, bus_space_handle_t,
     68  1.37    scottr 		    nubus_slot *));
     69  1.37    scottr 
     70  1.37    scottr static u_long	nubus_adjust_ptr __P((u_int8_t, u_long, long));
     71  1.37    scottr static u_int8_t	nubus_read_1 __P((bus_space_tag_t, bus_space_handle_t,
     72  1.37    scottr 		    u_int8_t, u_long));
     73  1.17    briggs #ifdef notyet
     74  1.37    scottr static u_int16_t nubus_read_2 __P((bus_space_tag_t, bus_space_handle_t,
     75  1.37    scottr 		    u_int8_t, u_long));
     76  1.17    briggs #endif
     77  1.37    scottr static u_int32_t nubus_read_4 __P((bus_space_tag_t, bus_space_handle_t,
     78  1.37    scottr 		    u_int8_t, u_long));
     79  1.29    scottr 
     80  1.55   thorpej CFATTACH_DECL(nubus, sizeof(struct nubus_softc),
     81  1.55   thorpej     nubus_match, nubus_attach, NULL, NULL);
     82   1.1    briggs 
     83  1.19    briggs static int
     84  1.28    scottr nubus_match(parent, cf, aux)
     85  1.19    briggs 	struct device *parent;
     86  1.28    scottr 	struct cfdata *cf;
     87  1.28    scottr 	void *aux;
     88  1.19    briggs {
     89  1.29    scottr 	static int nubus_matched = 0;
     90  1.19    briggs 
     91  1.29    scottr 	/* Allow only one instance. */
     92  1.29    scottr 	if (nubus_matched)
     93  1.29    scottr 		return (0);
     94  1.29    scottr 
     95  1.29    scottr 	nubus_matched = 1;
     96  1.29    scottr 	return (1);
     97  1.19    briggs }
     98  1.19    briggs 
     99  1.11    briggs static void
    100  1.28    scottr nubus_attach(parent, self, aux)
    101  1.28    scottr 	struct device *parent, *self;
    102  1.28    scottr 	void *aux;
    103  1.11    briggs {
    104  1.28    scottr 	struct nubus_attach_args na_args;
    105  1.53    briggs 	struct mainbus_attach_args *mba;
    106  1.37    scottr 	bus_space_tag_t bst;
    107  1.37    scottr 	bus_space_handle_t bsh;
    108  1.28    scottr 	nubus_slot fmtblock;
    109  1.28    scottr 	nubus_dir dir;
    110  1.28    scottr 	nubus_dirent dirent;
    111  1.28    scottr 	nubus_type slottype;
    112  1.34    briggs 	u_long entry;
    113  1.28    scottr 	int i, rsrcid;
    114  1.37    scottr 	u_int8_t lanes;
    115   1.1    briggs 
    116  1.53    briggs 	mba = aux;
    117  1.53    briggs 	KASSERT(NULL != mba->mba_dmat);
    118  1.53    briggs 
    119  1.26  christos 	printf("\n");
    120   1.1    briggs 
    121  1.19    briggs 	for (i = NUBUS_MIN_SLOT; i <= NUBUS_MAX_SLOT; i++) {
    122  1.37    scottr 		na_args.slot = i;
    123  1.52    briggs 		na_args.na_tag = bst = mba->mba_bst;
    124  1.52    briggs 		na_args.na_dmat = mba->mba_dmat;
    125  1.37    scottr 
    126  1.37    scottr 		if (bus_space_map(bst,
    127  1.37    scottr 		    NUBUS_SLOT2PA(na_args.slot), NBMEMSIZE, 0, &bsh)) {
    128  1.45    scottr #ifdef DEBUG
    129  1.45    scottr 			if (nubus_debug & NDB_PROBE)
    130  1.45    scottr 				printf("%s: failed to map slot %x, "
    131  1.45    scottr 				    "address %p (in use?)\n",
    132  1.45    scottr 				    self->dv_xname, i,
    133  1.45    scottr 				    (void *)NUBUS_SLOT2PA(i));
    134  1.37    scottr #endif
    135  1.28    scottr 			continue;
    136  1.37    scottr 		}
    137  1.28    scottr 
    138  1.37    scottr 		if (nubus_probe_slot(bst, bsh, i, &fmtblock) <= 0) {
    139  1.37    scottr notfound:
    140  1.37    scottr 			bus_space_unmap(bst, bsh, NBMEMSIZE);
    141  1.37    scottr 			continue;
    142  1.37    scottr 		}
    143  1.37    scottr 
    144  1.34    briggs 		rsrcid = 0x80;
    145  1.37    scottr 		lanes = fmtblock.bytelanes;
    146  1.28    scottr 
    147  1.28    scottr 		nubus_get_main_dir(&fmtblock, &dir);
    148  1.28    scottr 
    149  1.34    briggs 		/*
    150  1.34    briggs 		 * Get the resource for the first function on the card.
    151  1.34    briggs 		 * This is assumed to be at resource ID 0x80.  If we can
    152  1.34    briggs 		 * not find this entry (as we can not on some video cards),
    153  1.34    briggs 		 * check to see if we can get a different ID from the list
    154  1.34    briggs 		 * of video resources given to us by the booter.  If that
    155  1.34    briggs 		 * doesn't work either, take the first resource following
    156  1.34    briggs 		 * the board resource.
    157  1.53    briggs 		 * If we only find a board resource, report that.
    158  1.53    briggs 		 * There are cards that do not have anything else; their
    159  1.53    briggs 		 * driver then has to match on the board resource and
    160  1.53    briggs 		 * the card name.
    161  1.34    briggs 		 */
    162  1.37    scottr 		if (nubus_find_rsrc(bst, bsh,
    163  1.37    scottr 		    &fmtblock, &dir, rsrcid, &dirent) <= 0) {
    164  1.34    briggs 			if ((rsrcid = nubus_video_resource(i)) == -1) {
    165  1.53    briggs 				int has_board_rsrc = 0;
    166  1.53    briggs 
    167  1.34    briggs 				/*
    168  1.34    briggs 				 * Since nubus_find_rsrc failed, the directory
    169  1.34    briggs 				 * is back at its base.
    170  1.34    briggs 				 */
    171  1.34    briggs 				entry = dir.curr_ent;
    172  1.34    briggs 
    173  1.34    briggs 				/*
    174  1.34    briggs 				 * All nubus cards should have a board
    175  1.34    briggs 				 * resource, but be sure that's what it
    176  1.53    briggs 				 * is before we skip it, and note the fact.
    177  1.34    briggs 				 */
    178  1.37    scottr 				rsrcid = nubus_read_1(bst, bsh,
    179  1.37    scottr 				    lanes, entry);
    180  1.53    briggs 				if (rsrcid == 0x1) {
    181  1.53    briggs 					has_board_rsrc = 1;
    182  1.37    scottr 					entry = nubus_adjust_ptr(lanes,
    183  1.37    scottr 					    dir.curr_ent, 4);
    184  1.53    briggs 				}
    185  1.37    scottr 				rsrcid = nubus_read_1(bst, bsh, lanes, entry);
    186  1.53    briggs 				/* end of chain? */
    187  1.53    briggs 				if (rsrcid == 0xff) {
    188  1.53    briggs 					if (!has_board_rsrc)
    189  1.53    briggs 						goto notfound;
    190  1.53    briggs 					else
    191  1.53    briggs 						rsrcid = 0x01;
    192  1.53    briggs 				}
    193  1.34    briggs #ifdef DEBUG
    194  1.34    briggs 				if (nubus_debug & NDB_FOLLOW)
    195  1.34    briggs 					printf("\tUsing rsrc 0x%x.\n", rsrcid);
    196  1.34    briggs #endif
    197  1.34    briggs 			}
    198  1.34    briggs 			/*
    199  1.34    briggs 			 * Try to find the resource passed by the booter
    200  1.34    briggs 			 * or the one we just tracked down.
    201  1.34    briggs 			 */
    202  1.37    scottr 			if (nubus_find_rsrc(bst, bsh,
    203  1.37    scottr 			    &fmtblock, &dir, rsrcid, &dirent) <= 0)
    204  1.37    scottr 				goto notfound;
    205  1.34    briggs 		}
    206  1.28    scottr 
    207  1.28    scottr 		nubus_get_dir_from_rsrc(&fmtblock, &dirent, &dir);
    208  1.28    scottr 
    209  1.37    scottr 		if (nubus_find_rsrc(bst, bsh,
    210  1.37    scottr 		    &fmtblock, &dir, NUBUS_RSRC_TYPE, &dirent) <= 0)
    211  1.37    scottr 			goto notfound;
    212  1.37    scottr 
    213  1.37    scottr 		if (nubus_get_ind_data(bst, bsh, &fmtblock, &dirent,
    214  1.37    scottr 		    (caddr_t)&slottype, sizeof(nubus_type)) <= 0)
    215  1.37    scottr 			goto notfound;
    216  1.34    briggs 
    217  1.34    briggs 		/*
    218  1.34    briggs 		 * If this is a display card, try to pull out the correct
    219  1.34    briggs 		 * display mode as passed by the booter.
    220  1.34    briggs 		 */
    221  1.34    briggs 		if (slottype.category == NUBUS_CATEGORY_DISPLAY) {
    222  1.37    scottr 			int r;
    223  1.34    briggs 
    224  1.34    briggs 			if ((r = nubus_video_resource(i)) != -1) {
    225  1.34    briggs 
    226  1.34    briggs 				nubus_get_main_dir(&fmtblock, &dir);
    227  1.34    briggs 
    228  1.37    scottr 				if (nubus_find_rsrc(bst, bsh,
    229  1.37    scottr 				    &fmtblock, &dir, r, &dirent) <= 0)
    230  1.37    scottr 					goto notfound;
    231  1.34    briggs 
    232  1.34    briggs 				nubus_get_dir_from_rsrc(&fmtblock,
    233  1.37    scottr 				    &dirent, &dir);
    234  1.34    briggs 
    235  1.37    scottr 				if (nubus_find_rsrc(bst, bsh, &fmtblock, &dir,
    236  1.37    scottr 				    NUBUS_RSRC_TYPE, &dirent) <= 0)
    237  1.37    scottr 					goto notfound;
    238  1.37    scottr 
    239  1.37    scottr 				if (nubus_get_ind_data(bst, bsh,
    240  1.37    scottr 				    &fmtblock, &dirent, (caddr_t)&slottype,
    241  1.37    scottr 				    sizeof(nubus_type)) <= 0)
    242  1.37    scottr 					goto notfound;
    243  1.36    briggs 
    244  1.36    briggs 				rsrcid = r;
    245  1.34    briggs 			}
    246  1.34    briggs 		}
    247  1.28    scottr 
    248  1.28    scottr 		na_args.slot = i;
    249  1.28    scottr 		na_args.rsrcid = rsrcid;
    250  1.28    scottr 		na_args.category = slottype.category;
    251  1.28    scottr 		na_args.type = slottype.type;
    252  1.28    scottr 		na_args.drsw = slottype.drsw;
    253  1.28    scottr 		na_args.drhw = slottype.drhw;
    254  1.28    scottr 		na_args.fmt = &fmtblock;
    255  1.28    scottr 
    256  1.37    scottr 		bus_space_unmap(bst, bsh, NBMEMSIZE);
    257  1.37    scottr 
    258  1.28    scottr 		config_found(self, &na_args, nubus_print);
    259  1.12    briggs 	}
    260  1.33    scottr 
    261  1.33    scottr 	enable_nubus_intr();
    262   1.1    briggs }
    263   1.1    briggs 
    264  1.10    briggs static int
    265  1.40    scottr nubus_print(aux, pnp)
    266  1.28    scottr 	void *aux;
    267  1.40    scottr 	const char *pnp;
    268  1.11    briggs {
    269  1.37    scottr 	struct nubus_attach_args *na = (struct nubus_attach_args *)aux;
    270  1.37    scottr 	bus_space_tag_t bst = na->na_tag;
    271  1.37    scottr 	bus_space_handle_t bsh;
    272   1.1    briggs 
    273  1.40    scottr 	if (pnp) {
    274  1.56   thorpej 		aprint_normal("%s slot %x", pnp, na->slot);
    275  1.37    scottr 		if (bus_space_map(bst,
    276  1.40    scottr 		    NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh) == 0) {
    277  1.56   thorpej 			aprint_normal(": %s",
    278  1.56   thorpej 			    nubus_get_card_name(bst, bsh, na->fmt));
    279  1.56   thorpej 			aprint_normal(" (Vendor: %s,",
    280  1.56   thorpej 			    nubus_get_vendor(bst, bsh,
    281  1.37    scottr 			    na->fmt, NUBUS_RSRC_VEND_ID));
    282  1.56   thorpej 			aprint_normal(" Part: %s)", nubus_get_vendor(bst, bsh,
    283  1.37    scottr 			    na->fmt, NUBUS_RSRC_VEND_PART));
    284  1.40    scottr 			bus_space_unmap(bst, bsh, NBMEMSIZE);
    285  1.40    scottr 		}
    286  1.35    scottr #ifdef DIAGNOSTIC
    287  1.40    scottr 		else
    288  1.56   thorpej 			aprint_normal(":");
    289  1.56   thorpej 		aprint_normal(" Type: %04x %04x %04x %04x",
    290  1.40    scottr 		    na->category, na->type, na->drsw, na->drhw);
    291  1.35    scottr #endif
    292  1.40    scottr 	} else {
    293  1.56   thorpej 		aprint_normal(" slot %x", na->slot);
    294   1.1    briggs 	}
    295  1.11    briggs 	return (UNCONF);
    296  1.28    scottr }
    297  1.28    scottr 
    298  1.37    scottr static int
    299  1.28    scottr nubus_video_resource(slot)
    300  1.28    scottr 	int slot;
    301  1.28    scottr {
    302  1.28    scottr 	extern u_int16_t mac68k_vrsrc_vec[];
    303  1.28    scottr 	int i;
    304  1.28    scottr 
    305  1.28    scottr 	for (i = 0 ; i < 6 ; i++)
    306  1.28    scottr 		if ((mac68k_vrsrc_vec[i] & 0xff) == slot)
    307  1.28    scottr 			return ((mac68k_vrsrc_vec[i] >> 8) & 0xff);
    308  1.28    scottr 	return (-1);
    309   1.1    briggs }
    310   1.1    briggs 
    311  1.11    briggs /*
    312  1.11    briggs  * Probe a given nubus slot.  If a card is there and we can get the
    313  1.11    briggs  * format block from it's clutching decl. ROMs, fill the format block
    314  1.11    briggs  * and return non-zero.  If we can't find a card there with a valid
    315  1.11    briggs  * decl. ROM, return 0.
    316  1.11    briggs  *
    317  1.11    briggs  * First, we check to see if we can access the memory at the tail
    318  1.11    briggs  * end of the slot.  If so, then we check for a bytelanes byte.  We
    319  1.11    briggs  * could probably just return a failure status if we bus error on
    320  1.11    briggs  * the first try, but there really is little reason not to go ahead
    321  1.51       wiz  * and check the other three locations in case there's a weird card
    322  1.11    briggs  * out there.
    323  1.11    briggs  *
    324  1.11    briggs  * Checking for a card involves locating the "bytelanes" byte which
    325  1.11    briggs  * tells us how to interpret the declaration ROM's data.  The format
    326  1.11    briggs  * block is at the top of the card's standard memory space and the
    327  1.11    briggs  * bytelanes byte is at the end of that block.
    328  1.11    briggs  *
    329  1.11    briggs  * After some inspection of the bytelanes byte, it appears that it
    330  1.11    briggs  * takes the form 0xXY where Y is a bitmask of the bytelanes in use
    331  1.11    briggs  * and X is a bitmask of the lanes to ignore.  Hence, (X ^ Y) == 0
    332  1.11    briggs  * and (less obviously), Y will have the upper N bits clear if it is
    333  1.11    briggs  * found N bytes from the last possible location.  Both that and
    334  1.11    briggs  * the exclusive-or check are made.
    335  1.11    briggs  *
    336  1.11    briggs  * If a valid
    337  1.11    briggs  */
    338  1.37    scottr static u_int8_t	nbits[] = {0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4};
    339  1.11    briggs static int
    340  1.37    scottr nubus_probe_slot(bst, bsh, slot, fmt)
    341  1.37    scottr 	bus_space_tag_t bst;
    342  1.37    scottr 	bus_space_handle_t bsh;
    343  1.37    scottr 	int slot;
    344  1.37    scottr 	nubus_slot *fmt;
    345   1.1    briggs {
    346  1.37    scottr 	u_long ofs, hdr;
    347  1.37    scottr 	int i, j, found, hdr_size;
    348  1.37    scottr 	u_int8_t lanes;
    349  1.10    briggs 
    350  1.12    briggs #ifdef DEBUG
    351  1.37    scottr 	if (nubus_debug & NDB_PROBE)
    352  1.37    scottr 		printf("probing slot %x\n", slot);
    353  1.12    briggs #endif
    354  1.12    briggs 
    355  1.37    scottr 	/*
    356  1.37    scottr 	 * The idea behind this glorious work of art is to probe for only
    357  1.38    scottr 	 * valid bytelanes values at appropriate locations (see DC&D p. 159
    358  1.37    scottr 	 * for a list).  Note the pattern:  the first 8 values are at offset
    359  1.37    scottr 	 * 0xffffff in the slot's space; the next 4 values at 0xfffffe; the
    360  1.37    scottr 	 * next 2 values at 0xfffffd; and the last one at 0xfffffc.
    361  1.37    scottr 	 *
    362  1.37    scottr 	 * The nested loops implement an efficient search of this space,
    363  1.37    scottr 	 * probing first for a valid address, then checking for each of the
    364  1.37    scottr 	 * valid bytelanes values at that address.
    365  1.37    scottr 	 */
    366  1.37    scottr 	ofs = NBMEMSIZE;
    367  1.37    scottr 	lanes = 0xf;
    368  1.10    briggs 
    369  1.37    scottr 	for (j = 8, found = 0; j > 0 && !found; j >>= 1) {
    370  1.37    scottr 		ofs--;
    371  1.37    scottr 		for (i = j; i > 0; i--, lanes--) {
    372  1.43    scottr 			if (!mac68k_bus_space_probe(bst, bsh, ofs, 1)) {
    373  1.37    scottr 				lanes -= i;
    374  1.37    scottr 				break;
    375  1.37    scottr 			}
    376  1.37    scottr 			if (bus_space_read_1(bst, bsh, ofs) ==
    377  1.37    scottr 			    (((~lanes & 0xf) << 4) | lanes)) {
    378  1.37    scottr 				found = 1;
    379  1.37    scottr 				break;
    380  1.37    scottr 			}
    381  1.11    briggs 		}
    382   1.1    briggs 	}
    383  1.37    scottr 
    384  1.37    scottr 	if (!found) {
    385  1.11    briggs #ifdef DEBUG
    386  1.37    scottr 		if (nubus_debug & NDB_PROBE)
    387  1.37    scottr 			printf("bytelanes not found for slot %x\n", slot);
    388  1.11    briggs #endif
    389  1.37    scottr 		return 0;
    390  1.37    scottr 	}
    391  1.11    briggs 
    392  1.37    scottr 	fmt->bytelanes = lanes;
    393  1.37    scottr 	fmt->step = nbits[(lanes & 0x0f)];
    394  1.37    scottr 	fmt->slot = slot;	/* XXX redundant; get rid of this someday */
    395  1.11    briggs 
    396  1.11    briggs #ifdef DEBUG
    397  1.12    briggs 	if (nubus_debug & NDB_PROBE)
    398  1.26  christos 		printf("bytelanes of 0x%x found for slot 0x%x.\n",
    399  1.37    scottr 		    fmt->bytelanes, slot);
    400  1.11    briggs #endif
    401   1.1    briggs 
    402  1.11    briggs 	/*
    403  1.11    briggs 	 * Go ahead and attempt to load format header.
    404  1.11    briggs 	 * First, we need to find the first byte beyond memory that
    405  1.11    briggs 	 * would be valid.  This is necessary for NUBUS_ROM_offset()
    406  1.11    briggs 	 * to work.
    407  1.11    briggs 	 */
    408  1.37    scottr 	hdr = NBMEMSIZE;
    409  1.37    scottr 	hdr_size = 20;
    410  1.19    briggs 
    411  1.37    scottr 	i = 0x10 | (lanes & 0x0f);
    412  1.11    briggs 	while ((i & 1) == 0) {
    413  1.11    briggs 		hdr++;
    414  1.11    briggs 		i >>= 1;
    415  1.11    briggs 	}
    416  1.11    briggs 	fmt->top = hdr;
    417  1.37    scottr 	hdr = nubus_adjust_ptr(lanes, hdr, -hdr_size);
    418  1.11    briggs #ifdef DEBUG
    419  1.12    briggs 	if (nubus_debug & NDB_PROBE)
    420  1.27    scottr 		printf("fmt->top is 0x%lx, that minus 0x%x puts us at 0x%lx.\n",
    421  1.37    scottr 		    fmt->top, hdr_size, hdr);
    422  1.37    scottr 	if (nubus_debug & NDB_ARITH)
    423  1.37    scottr 		for (i = 1 ; i < 8 ; i++)
    424  1.37    scottr 			printf("0x%lx - 0x%x = 0x%lx, + 0x%x = 0x%lx.\n",
    425  1.37    scottr 			    hdr, i, nubus_adjust_ptr(lanes, hdr, -i),
    426  1.37    scottr 			    i, nubus_adjust_ptr(lanes, hdr,  i));
    427  1.37    scottr #endif
    428  1.37    scottr 
    429  1.37    scottr 	fmt->directory_offset =
    430  1.37    scottr 	    0xff000000 | nubus_read_4(bst, bsh, lanes, hdr);
    431  1.37    scottr 	hdr = nubus_adjust_ptr(lanes, hdr, 4);
    432  1.37    scottr 	fmt->length = nubus_read_4(bst, bsh, lanes, hdr);
    433  1.37    scottr 	hdr = nubus_adjust_ptr(lanes, hdr, 4);
    434  1.37    scottr 	fmt->crc = nubus_read_4(bst, bsh, lanes, hdr);
    435  1.37    scottr 	hdr = nubus_adjust_ptr(lanes, hdr, 4);
    436  1.37    scottr 	fmt->revision_level = nubus_read_1(bst, bsh, lanes, hdr);
    437  1.37    scottr 	hdr = nubus_adjust_ptr(lanes, hdr, 1);
    438  1.37    scottr 	fmt->format = nubus_read_1(bst, bsh, lanes, hdr);
    439  1.37    scottr 	hdr = nubus_adjust_ptr(lanes, hdr, 1);
    440  1.37    scottr 	fmt->test_pattern = nubus_read_4(bst, bsh, lanes, hdr);
    441  1.11    briggs 
    442  1.23    scottr #ifdef DEBUG
    443  1.12    briggs 	if (nubus_debug & NDB_PROBE) {
    444  1.26  christos 		printf("Directory offset 0x%x\t", fmt->directory_offset);
    445  1.26  christos 		printf("Length 0x%x\t", fmt->length);
    446  1.26  christos 		printf("CRC 0x%x\n", fmt->crc);
    447  1.26  christos 		printf("Revision level 0x%x\t", fmt->revision_level);
    448  1.26  christos 		printf("Format 0x%x\t", fmt->format);
    449  1.26  christos 		printf("Test Pattern 0x%x\n", fmt->test_pattern);
    450  1.12    briggs 	}
    451  1.11    briggs #endif
    452  1.11    briggs 
    453  1.12    briggs 	if ((fmt->directory_offset & 0x00ff0000) == 0) {
    454  1.26  christos 		printf("Invalid looking directory offset (0x%x)!\n",
    455  1.37    scottr 		    fmt->directory_offset);
    456  1.12    briggs 		return 0;
    457  1.12    briggs 	}
    458  1.11    briggs 	if (fmt->test_pattern != NUBUS_ROM_TEST_PATTERN) {
    459  1.26  christos 		printf("Nubus--test pattern invalid:\n");
    460  1.37    scottr 		printf("       slot 0x%x, bytelanes 0x%x?\n", fmt->slot, lanes);
    461  1.26  christos 		printf("       read test 0x%x, compare with 0x%x.\n",
    462  1.37    scottr 		    fmt->test_pattern, NUBUS_ROM_TEST_PATTERN);
    463  1.11    briggs 		return 0;
    464  1.11    briggs 	}
    465  1.11    briggs 
    466  1.11    briggs 	/* Perform CRC */
    467  1.37    scottr 	if (fmt->crc != nubus_calc_CRC(bst, bsh, fmt)) {
    468  1.37    scottr 		printf("Nubus--crc check failed, slot 0x%x.\n", fmt->slot);
    469  1.11    briggs 		return 0;
    470   1.1    briggs 	}
    471  1.10    briggs 
    472  1.11    briggs 	return 1;
    473   1.1    briggs }
    474   1.1    briggs 
    475  1.37    scottr static u_int32_t
    476  1.37    scottr nubus_calc_CRC(bst, bsh, fmt)
    477  1.37    scottr 	bus_space_tag_t bst;
    478  1.37    scottr 	bus_space_handle_t bsh;
    479  1.37    scottr 	nubus_slot	*fmt;
    480  1.37    scottr {
    481  1.37    scottr #if 0
    482  1.37    scottr 	u_long base, ptr, crc_loc;
    483  1.37    scottr 	u_int32_t sum;
    484  1.37    scottr 	u_int8_t lanes = fmt->bytelanes;
    485  1.37    scottr 
    486  1.37    scottr 	base = fmt->top;
    487  1.37    scottr 	crc_loc = NUBUS_ROM_offset(fmt, base, -12);
    488  1.37    scottr 	ptr = NUBUS_ROM_offset(fmt, base, -fmt->length);
    489  1.37    scottr 
    490  1.37    scottr 	sum = 0;
    491  1.37    scottr 	while (ptr < base)
    492  1.37    scottr 		roll #1, sum
    493  1.37    scottr 		if (ptr == crc_loc) {
    494  1.37    scottr 			roll #3, sum
    495  1.37    scottr 			ptr = nubus_adjust_ptr(lanes, ptr, 3);
    496  1.37    scottr 		} else {
    497  1.37    scottr 			sum += nubus_read_1(bst, bsh, lanes, ptr);
    498  1.37    scottr 		}
    499  1.37    scottr 		ptr = nubus_adjust_ptr(lanes, ptr, 1);
    500  1.37    scottr 	}
    501  1.37    scottr 
    502  1.37    scottr 	return sum;
    503  1.37    scottr #endif
    504  1.37    scottr 	return fmt->crc;
    505  1.37    scottr }
    506  1.37    scottr 
    507  1.11    briggs /*
    508  1.11    briggs  * Compute byte offset on card, taking into account bytelanes.
    509  1.11    briggs  * Base must be on a valid bytelane for this function to work.
    510  1.11    briggs  * Return the new address.
    511  1.11    briggs  *
    512  1.11    briggs  * XXX -- There has GOT to be a better way to do this.
    513  1.11    briggs  */
    514  1.11    briggs static u_long
    515  1.37    scottr nubus_adjust_ptr(lanes, base, amt)
    516  1.37    scottr 	u_int8_t lanes;
    517  1.37    scottr 	u_long base;
    518  1.37    scottr 	long amt;
    519  1.11    briggs {
    520  1.37    scottr 	u_int8_t b, t;
    521  1.11    briggs 
    522  1.11    briggs 	if (!amt)
    523  1.11    briggs 		return base;
    524  1.11    briggs 
    525  1.11    briggs 	if (amt < 0) {
    526  1.11    briggs 		amt = -amt;
    527  1.37    scottr 		b = lanes;
    528  1.11    briggs 		t = (b << 4);
    529  1.11    briggs 		b <<= (3 - (base & 0x3));
    530  1.11    briggs 		while (amt) {
    531  1.11    briggs 			b <<= 1;
    532  1.11    briggs 			if (b == t)
    533  1.37    scottr 				b = lanes;
    534  1.11    briggs 			if (b & 0x08)
    535  1.11    briggs 				amt--;
    536  1.11    briggs 			base--;
    537  1.11    briggs 		}
    538  1.11    briggs 		return base;
    539  1.11    briggs 	}
    540  1.10    briggs 
    541  1.37    scottr 	t = (lanes & 0xf) | 0x10;
    542  1.11    briggs 	b = t >> (base & 0x3);
    543  1.11    briggs 	while (amt) {
    544  1.11    briggs 		b >>= 1;
    545  1.11    briggs 		if (b == 1)
    546  1.11    briggs 			b = t;
    547  1.11    briggs 		if (b & 1)
    548  1.11    briggs 			amt--;
    549  1.11    briggs 		base++;
    550  1.11    briggs 	}
    551  1.11    briggs 
    552  1.11    briggs 	return base;
    553  1.11    briggs }
    554  1.11    briggs 
    555  1.37    scottr static u_int8_t
    556  1.37    scottr nubus_read_1(bst, bsh, lanes, ofs)
    557  1.37    scottr 	bus_space_tag_t bst;
    558  1.37    scottr 	bus_space_handle_t bsh;
    559  1.37    scottr 	u_int8_t lanes;
    560  1.37    scottr 	u_long ofs;
    561   1.1    briggs {
    562  1.37    scottr 	return bus_space_read_1(bst, bsh, ofs);
    563   1.1    briggs }
    564   1.1    briggs 
    565  1.17    briggs #ifdef notyet
    566  1.17    briggs /* Nothing uses this, yet */
    567  1.37    scottr static u_int16_t
    568  1.37    scottr nubus_read_2(bst, bsh, lanes, ofs)
    569  1.37    scottr 	bus_space_tag_t bst;
    570  1.37    scottr 	bus_space_handle_t bsh;
    571  1.37    scottr 	u_int8_t lanes;
    572  1.37    scottr 	u_long ofs;
    573  1.37    scottr {
    574  1.37    scottr 	u_int16_t s;
    575  1.37    scottr 
    576  1.37    scottr 	s = (nubus_read_1(bst, bsh, lanes, ofs) << 8);
    577  1.37    scottr 	ofs = nubus_adjust_ptr(lanes, ofs, 1);
    578  1.37    scottr 	s |= nubus_read_1(bst, bsh, lanes, ofs);
    579  1.11    briggs 	return s;
    580  1.11    briggs }
    581  1.17    briggs #endif
    582   1.1    briggs 
    583  1.37    scottr static u_int32_t
    584  1.37    scottr nubus_read_4(bst, bsh, lanes, ofs)
    585  1.37    scottr 	bus_space_tag_t bst;
    586  1.37    scottr 	bus_space_handle_t bsh;
    587  1.37    scottr 	u_int8_t lanes;
    588  1.37    scottr 	u_long ofs;
    589  1.11    briggs {
    590  1.37    scottr 	u_int32_t l;
    591  1.37    scottr 	int i;
    592  1.10    briggs 
    593  1.11    briggs 	l = 0;
    594  1.37    scottr 	for (i = 0; i < 4; i++) {
    595  1.37    scottr 		l = (l << 8) | nubus_read_1(bst, bsh, lanes, ofs);
    596  1.37    scottr 		ofs = nubus_adjust_ptr(lanes, ofs, 1);
    597  1.11    briggs 	}
    598  1.11    briggs 	return l;
    599  1.11    briggs }
    600  1.10    briggs 
    601  1.11    briggs void
    602  1.37    scottr nubus_get_main_dir(fmt, dir_return)
    603  1.37    scottr 	nubus_slot *fmt;
    604  1.37    scottr 	nubus_dir *dir_return;
    605  1.11    briggs {
    606  1.23    scottr #ifdef DEBUG
    607  1.12    briggs 	if (nubus_debug & NDB_FOLLOW)
    608  1.37    scottr 		printf("nubus_get_main_dir(%p, %p)\n",
    609  1.37    scottr 		    fmt, dir_return);
    610  1.12    briggs #endif
    611  1.37    scottr 	dir_return->dirbase = nubus_adjust_ptr(fmt->bytelanes, fmt->top,
    612  1.37    scottr 	    fmt->directory_offset - 20);
    613  1.37    scottr 	dir_return->curr_ent = dir_return->dirbase;
    614  1.37    scottr }
    615  1.37    scottr 
    616  1.37    scottr void
    617  1.37    scottr nubus_get_dir_from_rsrc(fmt, dirent, dir_return)
    618  1.37    scottr 	nubus_slot *fmt;
    619  1.37    scottr 	nubus_dirent *dirent;
    620  1.37    scottr 	nubus_dir *dir_return;
    621  1.37    scottr {
    622  1.37    scottr 	u_long loc;
    623  1.37    scottr 
    624  1.37    scottr #ifdef DEBUG
    625  1.37    scottr 	if (nubus_debug & NDB_FOLLOW)
    626  1.37    scottr 		printf("nubus_get_dir_from_rsrc(%p, %p, %p).\n",
    627  1.37    scottr 		    fmt, dirent, dir_return);
    628  1.37    scottr #endif
    629  1.37    scottr 	if ((loc = dirent->offset) & 0x800000) {
    630  1.37    scottr 		loc |= 0xff000000;
    631  1.37    scottr 	}
    632  1.37    scottr 	dir_return->dirbase =
    633  1.37    scottr 	    nubus_adjust_ptr(fmt->bytelanes, dirent->myloc, loc);
    634  1.11    briggs 	dir_return->curr_ent = dir_return->dirbase;
    635   1.1    briggs }
    636   1.1    briggs 
    637  1.11    briggs int
    638  1.37    scottr nubus_find_rsrc(bst, bsh, fmt, dir, rsrcid, dirent_return)
    639  1.37    scottr 	bus_space_tag_t bst;
    640  1.37    scottr 	bus_space_handle_t bsh;
    641  1.37    scottr 	nubus_slot *fmt;
    642  1.37    scottr 	nubus_dir *dir;
    643  1.37    scottr 	u_int8_t rsrcid;
    644  1.37    scottr 	nubus_dirent *dirent_return;
    645   1.1    briggs {
    646  1.37    scottr 	u_long entry;
    647  1.37    scottr 	u_int8_t byte, lanes = fmt->bytelanes;
    648  1.10    briggs 
    649  1.23    scottr #ifdef DEBUG
    650  1.12    briggs 	if (nubus_debug & NDB_FOLLOW)
    651  1.37    scottr 		printf("nubus_find_rsrc(%p, %p, 0x%x, %p)\n",
    652  1.37    scottr 		    fmt, dir, rsrcid, dirent_return);
    653  1.11    briggs #endif
    654  1.37    scottr 	if (fmt->test_pattern != NUBUS_ROM_TEST_PATTERN)
    655  1.12    briggs 		return -1;
    656  1.12    briggs 
    657  1.12    briggs 	entry = dir->curr_ent;
    658  1.11    briggs 	do {
    659  1.37    scottr 		byte = nubus_read_1(bst, bsh, lanes, entry);
    660  1.23    scottr #ifdef DEBUG
    661  1.12    briggs 		if (nubus_debug & NDB_FOLLOW)
    662  1.26  christos 			printf("\tFound rsrc 0x%x.\n", byte);
    663  1.11    briggs #endif
    664  1.11    briggs 		if (byte == rsrcid) {
    665  1.11    briggs 			dirent_return->myloc = entry;
    666  1.11    briggs 			dirent_return->rsrc_id = rsrcid;
    667  1.37    scottr 			entry = nubus_read_4(bst, bsh, lanes, entry);
    668  1.11    briggs 			dirent_return->offset = (entry & 0x00ffffff);
    669  1.11    briggs 			return 1;
    670  1.11    briggs 		}
    671  1.11    briggs 		if (byte == 0xff) {
    672  1.11    briggs 			entry = dir->dirbase;
    673  1.11    briggs 		} else {
    674  1.37    scottr 			entry = nubus_adjust_ptr(lanes, entry, 4);
    675  1.11    briggs 		}
    676  1.37    scottr 	} while (entry != (u_long)dir->curr_ent);
    677  1.11    briggs 	return 0;
    678   1.1    briggs }
    679   1.1    briggs 
    680  1.11    briggs int
    681  1.37    scottr nubus_get_ind_data(bst, bsh, fmt, dirent, data_return, nbytes)
    682  1.37    scottr 	bus_space_tag_t bst;
    683  1.37    scottr 	bus_space_handle_t bsh;
    684  1.37    scottr 	nubus_slot *fmt;
    685  1.11    briggs 	nubus_dirent *dirent;
    686  1.11    briggs 	caddr_t data_return;
    687  1.11    briggs 	int nbytes;
    688  1.11    briggs {
    689  1.37    scottr 	u_long loc;
    690  1.37    scottr 	u_int8_t lanes = fmt->bytelanes;
    691   1.1    briggs 
    692  1.23    scottr #ifdef DEBUG
    693  1.12    briggs 	if (nubus_debug & NDB_FOLLOW)
    694  1.37    scottr 		printf("nubus_get_ind_data(%p, %p, %p, %d).\n",
    695  1.37    scottr 		    fmt, dirent, data_return, nbytes);
    696  1.12    briggs #endif
    697  1.11    briggs 	if ((loc = dirent->offset) & 0x800000) {
    698  1.11    briggs 		loc |= 0xff000000;
    699  1.11    briggs 	}
    700  1.37    scottr 	loc = nubus_adjust_ptr(lanes, dirent->myloc, loc);
    701   1.1    briggs 
    702  1.11    briggs 	while (nbytes--) {
    703  1.37    scottr 		*data_return++ = nubus_read_1(bst, bsh, lanes, loc);
    704  1.37    scottr 		loc = nubus_adjust_ptr(lanes, loc, 1);
    705   1.1    briggs 	}
    706  1.11    briggs 	return 1;
    707   1.1    briggs }
    708   1.1    briggs 
    709  1.11    briggs int
    710  1.37    scottr nubus_get_c_string(bst, bsh, fmt, dirent, data_return, max_bytes)
    711  1.37    scottr 	bus_space_tag_t bst;
    712  1.37    scottr 	bus_space_handle_t bsh;
    713  1.37    scottr 	nubus_slot *fmt;
    714  1.11    briggs 	nubus_dirent *dirent;
    715  1.11    briggs 	caddr_t data_return;
    716  1.11    briggs 	int max_bytes;
    717   1.1    briggs {
    718  1.37    scottr 	u_long loc;
    719  1.37    scottr 	u_int8_t lanes = fmt->bytelanes;
    720  1.10    briggs 
    721  1.23    scottr #ifdef DEBUG
    722  1.12    briggs 	if (nubus_debug & NDB_FOLLOW)
    723  1.37    scottr 		printf("nubus_get_c_string(%p, %p, %p, %d).\n",
    724  1.37    scottr 		    fmt, dirent, data_return, max_bytes);
    725  1.12    briggs #endif
    726  1.37    scottr 	if ((loc = dirent->offset) & 0x800000)
    727  1.11    briggs 		loc |= 0xff000000;
    728  1.37    scottr 
    729  1.37    scottr 	loc = nubus_adjust_ptr(lanes, dirent->myloc, loc);
    730  1.10    briggs 
    731  1.11    briggs 	*data_return = '\0';
    732  1.11    briggs 	while (max_bytes--) {
    733  1.37    scottr 		if ((*data_return++ =
    734  1.37    scottr 		    nubus_read_1(bst, bsh, lanes, loc)) == 0)
    735  1.11    briggs 			return 1;
    736  1.37    scottr 		loc = nubus_adjust_ptr(lanes, loc, 1);
    737  1.11    briggs 	}
    738  1.50    briggs 	*(data_return-1) = '\0';
    739  1.11    briggs 	return 0;
    740   1.1    briggs }
    741   1.2    briggs 
    742  1.53    briggs /*
    743  1.53    briggs  * Get list of address ranges for an sMemory resource
    744  1.53    briggs  * ->  DC&D, p.171
    745  1.53    briggs  */
    746  1.53    briggs int
    747  1.53    briggs nubus_get_smem_addr_rangelist(bst, bsh, fmt, dirent, data_return)
    748  1.53    briggs 	bus_space_tag_t bst;
    749  1.53    briggs 	bus_space_handle_t bsh;
    750  1.53    briggs 	nubus_slot *fmt;
    751  1.53    briggs 	nubus_dirent *dirent;
    752  1.53    briggs 	caddr_t data_return;
    753  1.53    briggs {
    754  1.53    briggs 	u_long loc;
    755  1.53    briggs 	u_int8_t lanes = fmt->bytelanes;
    756  1.53    briggs 	long blocklen;
    757  1.53    briggs 	caddr_t blocklist;
    758  1.53    briggs 
    759  1.53    briggs #ifdef DEBUG
    760  1.53    briggs 	if (nubus_debug & NDB_FOLLOW)
    761  1.53    briggs 		printf("nubus_get_smem_addr_rangelist(%p, %p, %p).\n",
    762  1.53    briggs 		    fmt, dirent, data_return);
    763  1.53    briggs #endif
    764  1.53    briggs 	if ((loc = dirent->offset) & 0x800000) {
    765  1.53    briggs 		loc |= 0xff000000;
    766  1.53    briggs 	}
    767  1.53    briggs 	loc = nubus_adjust_ptr(lanes, dirent->myloc, loc);
    768  1.53    briggs 
    769  1.53    briggs 	/* Obtain the block length from the head of the list */
    770  1.53    briggs 	blocklen = nubus_read_4(bst, bsh, lanes, loc);
    771  1.53    briggs 
    772  1.53    briggs 	/*
    773  1.53    briggs 	 * malloc a block of (blocklen) bytes
    774  1.53    briggs 	 * caller must recycle block after use
    775  1.53    briggs 	 */
    776  1.53    briggs 	MALLOC(blocklist,caddr_t,blocklen,M_TEMP,M_WAITOK);
    777  1.53    briggs 
    778  1.53    briggs 	/* read ((blocklen - 4) / 8) (length,offset) pairs into block */
    779  1.53    briggs 	nubus_get_ind_data(bst, bsh, fmt, dirent, blocklist, blocklen);
    780  1.53    briggs #ifdef DEBUG
    781  1.53    briggs 	if (nubus_debug & NDB_FOLLOW) {
    782  1.53    briggs 		int ii;
    783  1.53    briggs 		nubus_smem_rangelist *rlist;
    784  1.53    briggs 
    785  1.53    briggs 		rlist = (nubus_smem_rangelist *)blocklist;
    786  1.53    briggs 		printf("\tblock@%p, len 0x0%X\n", rlist, rlist->length);
    787  1.53    briggs 
    788  1.53    briggs 		for (ii=0; ii < ((blocklen - 4) / 8); ii++) {
    789  1.53    briggs 			printf("\tRange %d: base addr 0x%X [0x%X]\n", ii,
    790  1.53    briggs 			    rlist->range[ii].offset, rlist->range[ii].length);
    791  1.53    briggs 		}
    792  1.53    briggs 	}
    793  1.53    briggs #endif
    794  1.53    briggs 	*(caddr_t *)data_return = blocklist;
    795  1.53    briggs 
    796  1.53    briggs 	return 1;
    797  1.53    briggs }
    798  1.53    briggs 
    799  1.11    briggs static char	*huh = "???";
    800   1.3    briggs 
    801  1.11    briggs char *
    802  1.37    scottr nubus_get_vendor(bst, bsh, fmt, rsrc)
    803  1.37    scottr 	bus_space_tag_t bst;
    804  1.37    scottr 	bus_space_handle_t bsh;
    805  1.37    scottr 	nubus_slot *fmt;
    806  1.37    scottr 	int rsrc;
    807  1.37    scottr {
    808  1.37    scottr 	static char str_ret[64];
    809  1.37    scottr 	nubus_dir dir;
    810  1.37    scottr 	nubus_dirent ent;
    811   1.3    briggs 
    812  1.23    scottr #ifdef DEBUG
    813  1.12    briggs 	if (nubus_debug & NDB_FOLLOW)
    814  1.37    scottr 		printf("nubus_get_vendor(%p, 0x%x).\n", fmt, rsrc);
    815  1.12    briggs #endif
    816  1.37    scottr 	nubus_get_main_dir(fmt, &dir);
    817  1.37    scottr 	if (nubus_find_rsrc(bst, bsh, fmt, &dir, 1, &ent) <= 0)
    818  1.11    briggs 		return huh;
    819  1.37    scottr 	nubus_get_dir_from_rsrc(fmt, &ent, &dir);
    820   1.2    briggs 
    821  1.37    scottr 	if (nubus_find_rsrc(bst, bsh, fmt, &dir, NUBUS_RSRC_VENDORINFO, &ent)
    822  1.37    scottr 	    <= 0)
    823  1.11    briggs 		return huh;
    824  1.37    scottr 	nubus_get_dir_from_rsrc(fmt, &ent, &dir);
    825  1.10    briggs 
    826  1.37    scottr 	if (nubus_find_rsrc(bst, bsh, fmt, &dir, rsrc, &ent) <= 0)
    827  1.11    briggs 		return huh;
    828  1.10    briggs 
    829  1.37    scottr 	nubus_get_c_string(bst, bsh, fmt, &ent, str_ret, 64);
    830   1.2    briggs 
    831  1.11    briggs 	return str_ret;
    832   1.2    briggs }
    833   1.2    briggs 
    834  1.11    briggs char *
    835  1.37    scottr nubus_get_card_name(bst, bsh, fmt)
    836  1.37    scottr 	bus_space_tag_t bst;
    837  1.37    scottr 	bus_space_handle_t bsh;
    838  1.37    scottr 	nubus_slot *fmt;
    839   1.2    briggs {
    840  1.37    scottr 	static char name_ret[64];
    841  1.37    scottr 	nubus_dir dir;
    842  1.37    scottr 	nubus_dirent ent;
    843   1.2    briggs 
    844  1.23    scottr #ifdef DEBUG
    845  1.12    briggs 	if (nubus_debug & NDB_FOLLOW)
    846  1.37    scottr 		printf("nubus_get_card_name(%p).\n", fmt);
    847  1.12    briggs #endif
    848  1.37    scottr 	nubus_get_main_dir(fmt, &dir);
    849   1.2    briggs 
    850  1.37    scottr 	if (nubus_find_rsrc(bst, bsh, fmt, &dir, 1, &ent) <= 0)
    851  1.11    briggs 		return huh;
    852   1.2    briggs 
    853  1.37    scottr 	nubus_get_dir_from_rsrc(fmt, &ent, &dir);
    854   1.2    briggs 
    855  1.37    scottr 	if (nubus_find_rsrc(bst, bsh, fmt, &dir, NUBUS_RSRC_NAME, &ent) <= 0)
    856  1.11    briggs 		return huh;
    857   1.2    briggs 
    858  1.37    scottr 	nubus_get_c_string(bst, bsh, fmt, &ent, name_ret, 64);
    859   1.2    briggs 
    860  1.11    briggs 	return name_ret;
    861   1.2    briggs }
    862  1.46    briggs 
    863  1.46    briggs #ifdef DEBUG
    864  1.46    briggs void
    865  1.46    briggs nubus_scan_slot(bst, slotno)
    866  1.46    briggs 	bus_space_tag_t bst;
    867  1.46    briggs 	int slotno;
    868  1.46    briggs {
    869  1.46    briggs 	int i=0, state=0;
    870  1.46    briggs 	char twirl[] = "-\\|/";
    871  1.46    briggs 	bus_space_handle_t sc_bsh;
    872  1.46    briggs 
    873  1.46    briggs 	if (bus_space_map(bst, NUBUS_SLOT2PA(slotno), NBMEMSIZE, 0, &sc_bsh)) {
    874  1.53    briggs 		printf("nubus_scan_slot: failed to map slot %x\n", slotno);
    875  1.46    briggs 		return;
    876  1.46    briggs 	}
    877  1.46    briggs 
    878  1.46    briggs 	printf("Scanning slot %c for accessible regions:\n",
    879  1.46    briggs 		slotno == 9 ? '9' : slotno - 10 + 'A');
    880  1.46    briggs 	for (i=0 ; i<NBMEMSIZE; i++) {
    881  1.46    briggs 		if (mac68k_bus_space_probe(bst, sc_bsh, i, 1)) {
    882  1.46    briggs 			if (state == 0) {
    883  1.46    briggs 				printf("\t0x%x-", i);
    884  1.46    briggs 				state = 1;
    885  1.46    briggs 			}
    886  1.46    briggs 		} else {
    887  1.46    briggs 			if (state) {
    888  1.46    briggs 				printf("0x%x\n", i);
    889  1.46    briggs 				state = 0;
    890  1.46    briggs 			}
    891  1.46    briggs 		}
    892  1.46    briggs 		if (i%100 == 0) {
    893  1.46    briggs 			printf("%c\b", twirl[(i/100)%4]);
    894  1.46    briggs 		}
    895  1.46    briggs 	}
    896  1.46    briggs 	if (state) {
    897  1.46    briggs 		printf("0x%x\n", i);
    898  1.46    briggs 	}
    899  1.46    briggs 	return;
    900  1.46    briggs }
    901  1.46    briggs #endif
    902