Home | History | Annotate | Line # | Download | only in apbus
apbus.c revision 1.2
      1  1.2  tsubai /*	$NetBSD: apbus.c,v 1.2 1999/12/23 06:52:30 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 #include <sys/device.h>
     32  1.1  tsubai 
     33  1.1  tsubai #include <machine/adrsmap.h>
     34  1.1  tsubai #include <machine/autoconf.h>
     35  1.1  tsubai #include <newsmips/apbus/apbusvar.h>
     36  1.1  tsubai 
     37  1.1  tsubai static int  apbusmatch __P((struct device *, struct cfdata *, void *));
     38  1.1  tsubai static void apbusattach __P((struct device *, struct device *, void *));
     39  1.1  tsubai static int apbusprint __P((void *, const char *));
     40  1.1  tsubai /* static void *aptokseg0 __P((void *)); */
     41  1.1  tsubai 
     42  1.1  tsubai #define	MAXAPDEVNUM	32
     43  1.1  tsubai 
     44  1.1  tsubai struct apbus_softc {
     45  1.1  tsubai 	struct device apbs_dev;
     46  1.1  tsubai };
     47  1.1  tsubai 
     48  1.1  tsubai struct cfattach ap_ca = {
     49  1.1  tsubai 	sizeof(struct apbus_softc), apbusmatch, apbusattach
     50  1.1  tsubai };
     51  1.1  tsubai 
     52  1.1  tsubai #define	APBUS_DEVNAMELEN	16
     53  1.1  tsubai 
     54  1.1  tsubai struct ap_intrhand {
     55  1.1  tsubai 	int ai_mask;
     56  1.1  tsubai 	int ai_priority;
     57  1.1  tsubai 	void (*ai_func) __P((void*));	/* function */
     58  1.1  tsubai 	void *ai_aux;			/* softc */
     59  1.1  tsubai 	char ai_name[APBUS_DEVNAMELEN];
     60  1.1  tsubai 	int ai_ctlno;
     61  1.1  tsubai };
     62  1.1  tsubai 
     63  1.1  tsubai #define	NLEVEL	2
     64  1.1  tsubai #define	NBIT	16
     65  1.2  tsubai #define	LEVELxBIT(l,b)	(((l)*NBIT)+(b))
     66  1.1  tsubai 
     67  1.2  tsubai static struct ap_intrhand apintr[NLEVEL*NBIT];
     68  1.1  tsubai 
     69  1.1  tsubai static int
     70  1.1  tsubai apbusmatch(parent, cfdata, aux)
     71  1.1  tsubai         struct device *parent;
     72  1.1  tsubai         struct cfdata *cfdata;
     73  1.1  tsubai         void *aux;
     74  1.1  tsubai {
     75  1.1  tsubai 	struct confargs *ca = aux;
     76  1.1  tsubai 
     77  1.1  tsubai 	if (strcmp(ca->ca_name, "ap") != 0)
     78  1.1  tsubai 		return 0;
     79  1.1  tsubai 
     80  1.1  tsubai 	return 1;
     81  1.1  tsubai }
     82  1.1  tsubai 
     83  1.1  tsubai 
     84  1.1  tsubai static void
     85  1.1  tsubai apbusattach(parent, self, aux)
     86  1.1  tsubai         struct device *parent;
     87  1.1  tsubai         struct device *self;
     88  1.1  tsubai         void *aux;
     89  1.1  tsubai {
     90  1.1  tsubai 	struct apbus_attach_args child;
     91  1.2  tsubai 	struct apbus_dev *apdev;
     92  1.1  tsubai 	struct apbus_ctl *apctl;
     93  1.1  tsubai 
     94  1.2  tsubai 	*(volatile u_int *)(NEWS5000_APBUS_INTST) = 0xffffffff;
     95  1.2  tsubai 	*(volatile u_int *)(NEWS5000_APBUS_INTMSK) = 0xffffffff;
     96  1.2  tsubai 	*(volatile u_int *)(NEWS5000_APBUS_CTRL) = 0x00000004;
     97  1.2  tsubai 	*(volatile u_int *)(NEWS5000_APBUS_DMA) = 0xffffffff;
     98  1.1  tsubai 
     99  1.1  tsubai 	printf("\n");
    100  1.1  tsubai 
    101  1.1  tsubai 	/*
    102  1.1  tsubai 	 * get first ap-device
    103  1.1  tsubai 	 */
    104  1.1  tsubai 	apdev = apbus_lookupdev(NULL);
    105  1.1  tsubai 
    106  1.1  tsubai 	/*
    107  1.1  tsubai 	 * trace device chain
    108  1.1  tsubai 	 */
    109  1.1  tsubai 	while (apdev) {
    110  1.1  tsubai 		apctl = apdev->apbd_ctl;
    111  1.1  tsubai 
    112  1.1  tsubai 		/*
    113  1.1  tsubai 		 * probe physical device only
    114  1.1  tsubai 		 * (no pseudo device)
    115  1.1  tsubai 		 */
    116  1.1  tsubai 		if (apctl && apctl->apbc_hwbase) {
    117  1.1  tsubai 			/*
    118  1.1  tsubai 			 * ... and, all units
    119  1.1  tsubai 			 */
    120  1.1  tsubai 			while (apctl) {
    121  1.1  tsubai 				/* make apbus_attach_args for devices */
    122  1.1  tsubai 				child.apa_name = apdev->apbd_name;
    123  1.1  tsubai 				child.apa_ctlnum = apctl->apbc_ctlno;
    124  1.1  tsubai 				child.apa_slotno = apctl->apbc_sl;
    125  1.1  tsubai 				child.apa_hwbase = apctl->apbc_hwbase;
    126  1.1  tsubai 
    127  1.1  tsubai 				config_found(self, &child, apbusprint);
    128  1.1  tsubai 
    129  1.1  tsubai 				apctl = apctl->apbc_link;
    130  1.1  tsubai 			}
    131  1.1  tsubai 		}
    132  1.1  tsubai 
    133  1.1  tsubai 		apdev = apdev->apbd_link;
    134  1.1  tsubai 	}
    135  1.1  tsubai }
    136  1.1  tsubai 
    137  1.1  tsubai int
    138  1.1  tsubai apbusprint(aux, pnp)
    139  1.1  tsubai 	void *aux;
    140  1.1  tsubai 	const char *pnp;
    141  1.1  tsubai {
    142  1.1  tsubai 	struct apbus_attach_args *a = aux;
    143  1.1  tsubai 
    144  1.1  tsubai 	if (pnp)
    145  1.1  tsubai 		printf("%s at %s slot%d addr 0x%lx",
    146  1.1  tsubai 			a->apa_name, pnp, a->apa_slotno, a->apa_hwbase);
    147  1.1  tsubai 
    148  1.1  tsubai 	return UNCONF;
    149  1.1  tsubai }
    150  1.1  tsubai 
    151  1.1  tsubai #if 0
    152  1.1  tsubai void *
    153  1.1  tsubai aptokseg0(va)
    154  1.1  tsubai 	void *va;
    155  1.1  tsubai {
    156  1.1  tsubai 	vaddr_t addr = (vaddr_t)va;
    157  1.1  tsubai 
    158  1.1  tsubai 	if (addr >= 0xfff00000) {
    159  1.1  tsubai 		addr -= 0xfff00000;
    160  1.1  tsubai 		addr += physmem << PGSHIFT;
    161  1.1  tsubai 		addr += 0x80000000;
    162  1.1  tsubai 		va = (void *)addr;
    163  1.1  tsubai 	}
    164  1.1  tsubai 	return va;
    165  1.1  tsubai }
    166  1.1  tsubai #endif
    167  1.1  tsubai 
    168  1.1  tsubai void
    169  1.1  tsubai apbus_wbflush()
    170  1.1  tsubai {
    171  1.2  tsubai 	volatile int *wbflush = (int *)NEWS5000_WBFLUSH;
    172  1.1  tsubai 
    173  1.1  tsubai 	(void)*wbflush;
    174  1.1  tsubai }
    175  1.1  tsubai 
    176  1.1  tsubai /*
    177  1.1  tsubai  * called by hardware interrupt routine
    178  1.1  tsubai  */
    179  1.1  tsubai int
    180  1.1  tsubai apbus_intr_call(level, stat)
    181  1.1  tsubai 	int level;
    182  1.1  tsubai 	int stat;
    183  1.1  tsubai {
    184  1.1  tsubai 	int i;
    185  1.1  tsubai 	int nintr = 0;
    186  1.2  tsubai 	struct ap_intrhand *aip = &apintr[LEVELxBIT(level,0)];
    187  1.1  tsubai 
    188  1.1  tsubai 	for(i = 0; i < NBIT; i++) {
    189  1.1  tsubai 		if (aip->ai_mask & stat) {
    190  1.1  tsubai 			(*aip->ai_func)(aip->ai_aux);
    191  1.1  tsubai 			nintr++;
    192  1.1  tsubai 		}
    193  1.1  tsubai 		aip++;
    194  1.1  tsubai 	}
    195  1.1  tsubai 	return nintr;
    196  1.1  tsubai }
    197  1.1  tsubai 
    198  1.1  tsubai /*
    199  1.1  tsubai  * register device interrupt routine
    200  1.1  tsubai  */
    201  1.1  tsubai void *
    202  1.1  tsubai apbus_intr_establish(level, mask, priority, func, aux, name, ctlno)
    203  1.1  tsubai 	int level;
    204  1.1  tsubai 	int mask;
    205  1.1  tsubai 	int priority;
    206  1.1  tsubai 	void (*func) __P((void *));
    207  1.1  tsubai 	void *aux;
    208  1.1  tsubai 	char *name;
    209  1.1  tsubai 	int ctlno;
    210  1.1  tsubai {
    211  1.1  tsubai 	int i;
    212  1.1  tsubai 	int nbit = -1;
    213  1.1  tsubai 	struct ap_intrhand *aip;
    214  1.1  tsubai 
    215  1.1  tsubai 	for (i = 0; i < NBIT; i++) {
    216  1.1  tsubai 		if (mask & (1 << i)) {
    217  1.1  tsubai 			nbit = i;
    218  1.1  tsubai 			break;
    219  1.1  tsubai 		}
    220  1.1  tsubai 	}
    221  1.1  tsubai 
    222  1.1  tsubai 	if (nbit == -1)
    223  1.1  tsubai 		panic("apbus_intr_establish");
    224  1.1  tsubai 
    225  1.2  tsubai 	aip = &apintr[LEVELxBIT(level,nbit)];
    226  1.1  tsubai 	aip->ai_mask = 1 << nbit;
    227  1.1  tsubai 	aip->ai_priority = priority;
    228  1.1  tsubai 	aip->ai_func = func;
    229  1.1  tsubai 	aip->ai_aux = aux;
    230  1.1  tsubai 	strncpy(aip->ai_name, name, APBUS_DEVNAMELEN-1);
    231  1.1  tsubai 	aip->ai_ctlno = ctlno;
    232  1.1  tsubai 
    233  1.1  tsubai 	return (void *)aip;
    234  1.1  tsubai }
    235