Home | History | Annotate | Line # | Download | only in apbus
apbus_subr.c revision 1.2.6.3
      1  1.2.6.3  bouyer /*	$NetBSD: apbus_subr.c,v 1.2.6.3 2000/12/08 09:28:49 bouyer Exp $	*/
      2  1.2.6.2  bouyer 
      3  1.2.6.2  bouyer /*-
      4  1.2.6.2  bouyer  * Copyright (C) 1999 SHIMIZU Ryo.  All rights reserved.
      5  1.2.6.2  bouyer  *
      6  1.2.6.2  bouyer  * Redistribution and use in source and binary forms, with or without
      7  1.2.6.2  bouyer  * modification, are permitted provided that the following conditions
      8  1.2.6.2  bouyer  * are met:
      9  1.2.6.2  bouyer  * 1. Redistributions of source code must retain the above copyright
     10  1.2.6.2  bouyer  *    notice, this list of conditions and the following disclaimer.
     11  1.2.6.2  bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.2.6.2  bouyer  *    notice, this list of conditions and the following disclaimer in the
     13  1.2.6.2  bouyer  *    documentation and/or other materials provided with the distribution.
     14  1.2.6.2  bouyer  * 3. The name of the author may not be used to endorse or promote products
     15  1.2.6.2  bouyer  *    derived from this software without specific prior written permission.
     16  1.2.6.2  bouyer  *
     17  1.2.6.2  bouyer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18  1.2.6.2  bouyer  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19  1.2.6.2  bouyer  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20  1.2.6.2  bouyer  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21  1.2.6.2  bouyer  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22  1.2.6.2  bouyer  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23  1.2.6.2  bouyer  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24  1.2.6.2  bouyer  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25  1.2.6.2  bouyer  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     26  1.2.6.2  bouyer  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  1.2.6.2  bouyer  */
     28  1.2.6.2  bouyer 
     29  1.2.6.2  bouyer #include <sys/param.h>
     30  1.2.6.2  bouyer #include <sys/systm.h>
     31  1.2.6.2  bouyer 
     32  1.2.6.2  bouyer #include <newsmips/apbus/apbusvar.h>
     33  1.2.6.2  bouyer 
     34  1.2.6.3  bouyer static void apctl_dump (struct apbus_ctl *);
     35  1.2.6.3  bouyer 
     36  1.2.6.2  bouyer void *
     37  1.2.6.2  bouyer apbus_device_to_hwaddr(apbus_dev)
     38  1.2.6.2  bouyer 	struct apbus_dev *apbus_dev;
     39  1.2.6.2  bouyer {
     40  1.2.6.2  bouyer 	struct apbus_ctl *ctl;
     41  1.2.6.2  bouyer 
     42  1.2.6.2  bouyer 	if (apbus_dev == NULL)
     43  1.2.6.2  bouyer 		return NULL;
     44  1.2.6.2  bouyer 
     45  1.2.6.2  bouyer 	ctl = apbus_dev->apbd_ctl;
     46  1.2.6.2  bouyer 	if (ctl == NULL)
     47  1.2.6.2  bouyer 		return NULL;
     48  1.2.6.2  bouyer 
     49  1.2.6.2  bouyer 	return (void *)ctl->apbc_hwbase;
     50  1.2.6.2  bouyer }
     51  1.2.6.2  bouyer 
     52  1.2.6.2  bouyer struct apbus_dev *
     53  1.2.6.2  bouyer apbus_lookupdev(devname)
     54  1.2.6.2  bouyer 	char *devname;
     55  1.2.6.2  bouyer {
     56  1.2.6.2  bouyer 	struct apbus_dev *dp;
     57  1.2.6.2  bouyer 
     58  1.2.6.2  bouyer 	dp = _sip->apbsi_dev;
     59  1.2.6.2  bouyer 	if (devname == NULL || *devname == '\0')
     60  1.2.6.2  bouyer 		return dp;
     61  1.2.6.2  bouyer 
     62  1.2.6.2  bouyer 	/* search apbus_dev named 'devname' */
     63  1.2.6.2  bouyer 	while (dp) {
     64  1.2.6.2  bouyer 		if (strcmp(devname,dp->apbd_name) == 0)
     65  1.2.6.2  bouyer 			return dp;
     66  1.2.6.2  bouyer 
     67  1.2.6.2  bouyer 		dp = dp->apbd_link;
     68  1.2.6.2  bouyer 	}
     69  1.2.6.2  bouyer 
     70  1.2.6.2  bouyer 	return NULL;
     71  1.2.6.2  bouyer }
     72  1.2.6.2  bouyer 
     73  1.2.6.3  bouyer static void
     74  1.2.6.2  bouyer apctl_dump(apctl)
     75  1.2.6.2  bouyer 	struct apbus_ctl *apctl;
     76  1.2.6.2  bouyer {
     77  1.2.6.2  bouyer 	unsigned int *p;
     78  1.2.6.2  bouyer 
     79  1.2.6.2  bouyer 	if (!apctl)
     80  1.2.6.2  bouyer 		return;
     81  1.2.6.2  bouyer 
     82  1.2.6.2  bouyer 	printf("	apbus_ctl dump (%p)\n", apctl);
     83  1.2.6.2  bouyer 
     84  1.2.6.2  bouyer 	p = (void *)apctl;
     85  1.2.6.2  bouyer 
     86  1.2.6.2  bouyer 	printf("	Num:		%d\n", apctl->apbc_ctlno);
     87  1.2.6.2  bouyer 	printf("	HWaddr:		0x%08x\n", apctl->apbc_hwbase);
     88  1.2.6.2  bouyer 	printf("	softc:		%p\n", apctl->apbc_softc);
     89  1.2.6.2  bouyer 	printf("	Slot:		%d\n", apctl->apbc_sl);
     90  1.2.6.2  bouyer 	printf("\n");
     91  1.2.6.2  bouyer 
     92  1.2.6.2  bouyer 	if (apctl->apbc_link)
     93  1.2.6.2  bouyer 		apctl_dump(apctl->apbc_link);
     94  1.2.6.2  bouyer }
     95  1.2.6.2  bouyer 
     96  1.2.6.2  bouyer void
     97  1.2.6.2  bouyer apdevice_dump(apdev)
     98  1.2.6.2  bouyer 	struct apbus_dev *apdev;
     99  1.2.6.2  bouyer {
    100  1.2.6.2  bouyer 	struct apbus_ctl *apctl;
    101  1.2.6.2  bouyer 
    102  1.2.6.2  bouyer 	if (apdev == NULL)
    103  1.2.6.2  bouyer 		return;
    104  1.2.6.2  bouyer 
    105  1.2.6.2  bouyer 	/* only no pseudo device */
    106  1.2.6.2  bouyer 	apctl = apdev->apbd_ctl;
    107  1.2.6.2  bouyer 	if (apctl == NULL || apctl->apbc_hwbase == 0)
    108  1.2.6.2  bouyer 		return;
    109  1.2.6.2  bouyer 
    110  1.2.6.2  bouyer 	printf("apbus_dev dump (%p)\n", apdev);
    111  1.2.6.2  bouyer 	printf("name:		%s\n", apdev->apbd_name);
    112  1.2.6.2  bouyer 	printf("vendor:		%s\n", apdev->apbd_vendor);
    113  1.2.6.2  bouyer 	printf("atr:		%08x\n", apdev->apbd_atr);
    114  1.2.6.2  bouyer 	printf("rev:		%d\n", apdev->apbd_rev);
    115  1.2.6.2  bouyer 	printf("driver:		0x%08x\n", (unsigned int)apdev->apbd_driver);
    116  1.2.6.2  bouyer 	printf("ctl:		0x%08x\n", (unsigned int)apdev->apbd_ctl);
    117  1.2.6.2  bouyer 	printf("link:		0x%08x\n", (unsigned int)apdev->apbd_link);
    118  1.2.6.2  bouyer 	printf("\n");
    119  1.2.6.2  bouyer 
    120  1.2.6.2  bouyer 	apctl_dump(apctl);
    121  1.2.6.2  bouyer }
    122