Home | History | Annotate | Line # | Download | only in apbus
apbus.c revision 1.1
      1  1.1  tsubai /*	$NetBSD: apbus.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 #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.1  tsubai 
     66  1.1  tsubai static struct ap_intrhand apintr[NLEVEL][NBIT];
     67  1.1  tsubai 
     68  1.1  tsubai static int
     69  1.1  tsubai apbusmatch(parent, cfdata, aux)
     70  1.1  tsubai         struct device *parent;
     71  1.1  tsubai         struct cfdata *cfdata;
     72  1.1  tsubai         void *aux;
     73  1.1  tsubai {
     74  1.1  tsubai 	struct confargs *ca = aux;
     75  1.1  tsubai 
     76  1.1  tsubai 	if (strcmp(ca->ca_name, "ap") != 0)
     77  1.1  tsubai 		return 0;
     78  1.1  tsubai 
     79  1.1  tsubai 	return 1;
     80  1.1  tsubai }
     81  1.1  tsubai 
     82  1.1  tsubai 
     83  1.1  tsubai static void
     84  1.1  tsubai apbusattach(parent, self, aux)
     85  1.1  tsubai         struct device *parent;
     86  1.1  tsubai         struct device *self;
     87  1.1  tsubai         void *aux;
     88  1.1  tsubai {
     89  1.1  tsubai 	struct apbus_attach_args child;
     90  1.1  tsubai 	struct apbus_device *apdev;
     91  1.1  tsubai 	struct apbus_ctl *apctl;
     92  1.1  tsubai 
     93  1.1  tsubai 	*(volatile u_int*)(NEWS5000_APBUS_INTSTAT) = 0xffffffff;
     94  1.1  tsubai 	*(volatile u_int*)(NEWS5000_APBUS_INTMASK) = NEWS5000_INTAPBUS_ALL;
     95  1.1  tsubai 
     96  1.1  tsubai 	*(volatile u_int*)(NEWS5000_APBUS_CONFIG) = 0x04;
     97  1.1  tsubai 	*(volatile u_int *)(NEWS5000_APBUS_DUMCOH) =
     98  1.1  tsubai 	                               NEWS5000_APBUS_DEVICE_DMAC3 |
     99  1.1  tsubai 	                               NEWS5000_APBUS_DEVICE_SONIC |
    100  1.1  tsubai 	                               NEWS5000_APBUS_DEVICE_ALLSLOT;
    101  1.1  tsubai 
    102  1.1  tsubai 	*(volatile u_int*)NEWS5000_INTMASK0 = NEWS5000_INT0_ALL;
    103  1.1  tsubai 	*(volatile u_int*)NEWS5000_INTMASK1 = NEWS5000_INT1_ALL;
    104  1.1  tsubai 
    105  1.1  tsubai 	printf("\n");
    106  1.1  tsubai 
    107  1.1  tsubai 	/*
    108  1.1  tsubai 	 * get first ap-device
    109  1.1  tsubai 	 */
    110  1.1  tsubai 	apdev = apbus_lookupdev(NULL);
    111  1.1  tsubai 
    112  1.1  tsubai 	/*
    113  1.1  tsubai 	 * trace device chain
    114  1.1  tsubai 	 */
    115  1.1  tsubai 	while (apdev) {
    116  1.1  tsubai 		apctl = apdev->apbd_ctl;
    117  1.1  tsubai 
    118  1.1  tsubai 		/*
    119  1.1  tsubai 		 * probe physical device only
    120  1.1  tsubai 		 * (no pseudo device)
    121  1.1  tsubai 		 */
    122  1.1  tsubai 		if (apctl && apctl->apbc_hwbase) {
    123  1.1  tsubai 			/*
    124  1.1  tsubai 			 * ... and, all units
    125  1.1  tsubai 			 */
    126  1.1  tsubai 			while (apctl) {
    127  1.1  tsubai 				/* make apbus_attach_args for devices */
    128  1.1  tsubai 				child.apa_name = apdev->apbd_name;
    129  1.1  tsubai 				child.apa_ctlnum = apctl->apbc_ctlno;
    130  1.1  tsubai 				child.apa_slotno = apctl->apbc_sl;
    131  1.1  tsubai 				child.apa_hwbase = apctl->apbc_hwbase;
    132  1.1  tsubai 
    133  1.1  tsubai #if 0
    134  1.1  tsubai printf("config_found: name = %s\n", child.apa_name);
    135  1.1  tsubai printf("            : unit = %d\n", child.apa_ctlnum);
    136  1.1  tsubai printf("            : slot = %d\n", child.apa_slotno);
    137  1.1  tsubai printf("            : unit = 0x%08lx\n", child.apa_hwbase);
    138  1.1  tsubai #endif
    139  1.1  tsubai 
    140  1.1  tsubai 				config_found(self, &child, apbusprint);
    141  1.1  tsubai 
    142  1.1  tsubai 				apctl = apctl->apbc_link;
    143  1.1  tsubai 			}
    144  1.1  tsubai 		}
    145  1.1  tsubai 
    146  1.1  tsubai 		apdev = apdev->apbd_link;
    147  1.1  tsubai 	}
    148  1.1  tsubai }
    149  1.1  tsubai 
    150  1.1  tsubai int
    151  1.1  tsubai apbusprint(aux, pnp)
    152  1.1  tsubai 	void *aux;
    153  1.1  tsubai 	const char *pnp;
    154  1.1  tsubai {
    155  1.1  tsubai 	struct apbus_attach_args *a = aux;
    156  1.1  tsubai 
    157  1.1  tsubai 	if (pnp)
    158  1.1  tsubai 		printf("%s at %s slot%d addr 0x%lx",
    159  1.1  tsubai 			a->apa_name, pnp, a->apa_slotno, a->apa_hwbase);
    160  1.1  tsubai 
    161  1.1  tsubai 	return UNCONF;
    162  1.1  tsubai }
    163  1.1  tsubai 
    164  1.1  tsubai #if 0
    165  1.1  tsubai void *
    166  1.1  tsubai aptokseg0(va)
    167  1.1  tsubai 	void *va;
    168  1.1  tsubai {
    169  1.1  tsubai 	vaddr_t addr = (vaddr_t)va;
    170  1.1  tsubai 
    171  1.1  tsubai 	if (addr >= 0xfff00000) {
    172  1.1  tsubai 		addr -= 0xfff00000;
    173  1.1  tsubai 		addr += physmem << PGSHIFT;
    174  1.1  tsubai 		addr += 0x80000000;
    175  1.1  tsubai 		va = (void *)addr;
    176  1.1  tsubai 	}
    177  1.1  tsubai 	return va;
    178  1.1  tsubai }
    179  1.1  tsubai #endif
    180  1.1  tsubai 
    181  1.1  tsubai void
    182  1.1  tsubai apbus_wbflush()
    183  1.1  tsubai {
    184  1.1  tsubai 	volatile int *wbflush = (int *)NEWS5000_WB;
    185  1.1  tsubai 
    186  1.1  tsubai 	(void)*wbflush;
    187  1.1  tsubai }
    188  1.1  tsubai 
    189  1.1  tsubai void
    190  1.1  tsubai apbus_intr_init()
    191  1.1  tsubai {
    192  1.1  tsubai 	bzero(&apintr[0][0],sizeof(apintr));
    193  1.1  tsubai }
    194  1.1  tsubai 
    195  1.1  tsubai /*
    196  1.1  tsubai  * called by hardware interrupt routine
    197  1.1  tsubai  */
    198  1.1  tsubai int
    199  1.1  tsubai apbus_intr_call(level, stat)
    200  1.1  tsubai 	int level;
    201  1.1  tsubai 	int stat;
    202  1.1  tsubai {
    203  1.1  tsubai 	int i;
    204  1.1  tsubai 	int nintr = 0;
    205  1.1  tsubai 	struct ap_intrhand *aip = &apintr[level][0];
    206  1.1  tsubai 
    207  1.1  tsubai 	for(i = 0; i < NBIT; i++) {
    208  1.1  tsubai 		if (aip->ai_mask & stat) {
    209  1.1  tsubai 			(*aip->ai_func)(aip->ai_aux);
    210  1.1  tsubai 			nintr++;
    211  1.1  tsubai 		}
    212  1.1  tsubai 		aip++;
    213  1.1  tsubai 	}
    214  1.1  tsubai 	return nintr;
    215  1.1  tsubai }
    216  1.1  tsubai 
    217  1.1  tsubai /*
    218  1.1  tsubai  * register device interrupt routine
    219  1.1  tsubai  */
    220  1.1  tsubai void *
    221  1.1  tsubai apbus_intr_establish(level, mask, priority, func, aux, name, ctlno)
    222  1.1  tsubai 	int level;
    223  1.1  tsubai 	int mask;
    224  1.1  tsubai 	int priority;
    225  1.1  tsubai 	void (*func) __P((void *));
    226  1.1  tsubai 	void *aux;
    227  1.1  tsubai 	char *name;
    228  1.1  tsubai 	int ctlno;
    229  1.1  tsubai {
    230  1.1  tsubai 	int i;
    231  1.1  tsubai 	int nbit = -1;
    232  1.1  tsubai 	struct ap_intrhand *aip;
    233  1.1  tsubai 
    234  1.1  tsubai 	for (i = 0; i < NBIT; i++) {
    235  1.1  tsubai 		if (mask & (1 << i)) {
    236  1.1  tsubai 			nbit = i;
    237  1.1  tsubai 			break;
    238  1.1  tsubai 		}
    239  1.1  tsubai 	}
    240  1.1  tsubai 
    241  1.1  tsubai 	if (nbit == -1)
    242  1.1  tsubai 		panic("apbus_intr_establish");
    243  1.1  tsubai 
    244  1.1  tsubai 	aip = &apintr[level][nbit];
    245  1.1  tsubai 	aip->ai_mask = 1 << nbit;
    246  1.1  tsubai 	aip->ai_priority = priority;
    247  1.1  tsubai 	aip->ai_func = func;
    248  1.1  tsubai 	aip->ai_aux = aux;
    249  1.1  tsubai 	strncpy(aip->ai_name, name, APBUS_DEVNAMELEN-1);
    250  1.1  tsubai 	aip->ai_ctlno = ctlno;
    251  1.1  tsubai 
    252  1.1  tsubai 	return (void *)aip;
    253  1.1  tsubai }
    254