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