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