Home | History | Annotate | Line # | Download | only in dev
crime.c revision 1.4.8.3
      1  1.4.8.3  nathanw /*	$NetBSD: crime.c,v 1.4.8.3 2002/10/18 02:39:38 nathanw Exp $	*/
      2  1.4.8.2  nathanw 
      3  1.4.8.2  nathanw /*
      4  1.4.8.2  nathanw  * Copyright (c) 2000 Soren S. Jorvang
      5  1.4.8.2  nathanw  * All rights reserved.
      6  1.4.8.2  nathanw  *
      7  1.4.8.2  nathanw  * Redistribution and use in source and binary forms, with or without
      8  1.4.8.2  nathanw  * modification, are permitted provided that the following conditions
      9  1.4.8.2  nathanw  * are met:
     10  1.4.8.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     11  1.4.8.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     12  1.4.8.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.4.8.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     14  1.4.8.2  nathanw  *    documentation and/or other materials provided with the distribution.
     15  1.4.8.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     16  1.4.8.2  nathanw  *    must display the following acknowledgement:
     17  1.4.8.2  nathanw  *          This product includes software developed for the
     18  1.4.8.2  nathanw  *          NetBSD Project.  See http://www.netbsd.org/ for
     19  1.4.8.2  nathanw  *          information about NetBSD.
     20  1.4.8.2  nathanw  * 4. The name of the author may not be used to endorse or promote products
     21  1.4.8.2  nathanw  *    derived from this software without specific prior written permission.
     22  1.4.8.2  nathanw  *
     23  1.4.8.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     24  1.4.8.2  nathanw  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25  1.4.8.2  nathanw  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26  1.4.8.2  nathanw  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     27  1.4.8.2  nathanw  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     28  1.4.8.2  nathanw  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     29  1.4.8.2  nathanw  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     30  1.4.8.2  nathanw  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     31  1.4.8.2  nathanw  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     32  1.4.8.2  nathanw  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33  1.4.8.2  nathanw  */
     34  1.4.8.2  nathanw 
     35  1.4.8.2  nathanw /*
     36  1.4.8.2  nathanw  * O2 CRIME
     37  1.4.8.2  nathanw  */
     38  1.4.8.2  nathanw 
     39  1.4.8.2  nathanw #include <sys/param.h>
     40  1.4.8.2  nathanw #include <sys/device.h>
     41  1.4.8.2  nathanw #include <sys/systm.h>
     42  1.4.8.2  nathanw 
     43  1.4.8.2  nathanw #include <machine/cpu.h>
     44  1.4.8.2  nathanw #include <machine/locore.h>
     45  1.4.8.2  nathanw #include <machine/autoconf.h>
     46  1.4.8.2  nathanw #include <machine/bus.h>
     47  1.4.8.2  nathanw #include <machine/intr.h>
     48  1.4.8.2  nathanw #include <machine/machtype.h>
     49  1.4.8.2  nathanw 
     50  1.4.8.2  nathanw #include <dev/pci/pcivar.h>
     51  1.4.8.2  nathanw 
     52  1.4.8.2  nathanw #if 0
     53  1.4.8.2  nathanw #include <sgimips/dev/crimereg.h>
     54  1.4.8.2  nathanw #endif
     55  1.4.8.2  nathanw 
     56  1.4.8.2  nathanw #include "locators.h"
     57  1.4.8.2  nathanw 
     58  1.4.8.2  nathanw static int	crime_match(struct device *, struct cfdata *, void *);
     59  1.4.8.2  nathanw static void	crime_attach(struct device *, struct device *, void *);
     60  1.4.8.2  nathanw void *		crime_intr_establish(int, int, int, int (*)(void *), void *);
     61  1.4.8.2  nathanw int		crime_intr(void *);
     62  1.4.8.2  nathanw 
     63  1.4.8.3  nathanw CFATTACH_DECL(crime, sizeof(struct device),
     64  1.4.8.3  nathanw     crime_match, crime_attach, NULL, NULL);
     65  1.4.8.2  nathanw 
     66  1.4.8.2  nathanw static int
     67  1.4.8.2  nathanw crime_match(parent, match, aux)
     68  1.4.8.2  nathanw 	struct device *parent;
     69  1.4.8.2  nathanw 	struct cfdata *match;
     70  1.4.8.2  nathanw 	void *aux;
     71  1.4.8.2  nathanw {
     72  1.4.8.2  nathanw 
     73  1.4.8.2  nathanw 	/*
     74  1.4.8.2  nathanw 	 * The CRIME is in the O2.
     75  1.4.8.2  nathanw 	 */
     76  1.4.8.2  nathanw 	if (mach_type == MACH_SGI_IP32)
     77  1.4.8.2  nathanw 		return (1);
     78  1.4.8.2  nathanw 
     79  1.4.8.2  nathanw 	return (0);
     80  1.4.8.2  nathanw }
     81  1.4.8.2  nathanw 
     82  1.4.8.2  nathanw static void
     83  1.4.8.2  nathanw crime_attach(parent, self, aux)
     84  1.4.8.2  nathanw 	struct device *parent;
     85  1.4.8.2  nathanw 	struct device *self;
     86  1.4.8.2  nathanw 	void *aux;
     87  1.4.8.2  nathanw {
     88  1.4.8.2  nathanw 	struct mainbus_attach_args *ma = aux;
     89  1.4.8.2  nathanw 	u_int32_t rev; /* really u_int64_t ! */
     90  1.4.8.2  nathanw 	int major, minor;
     91  1.4.8.2  nathanw 
     92  1.4.8.2  nathanw 	rev = bus_space_read_4(ma->ma_iot, ma->ma_ioh, 4) & 0xff;
     93  1.4.8.2  nathanw 
     94  1.4.8.2  nathanw 	major = rev >> 4;
     95  1.4.8.2  nathanw 	minor = rev & 0x0f;
     96  1.4.8.2  nathanw 
     97  1.4.8.2  nathanw 	if (major == 0 && minor == 0)
     98  1.4.8.2  nathanw 		printf(": petty\n");
     99  1.4.8.2  nathanw 	else
    100  1.4.8.2  nathanw 		printf(": rev %d.%d\n", major, minor);
    101  1.4.8.2  nathanw 
    102  1.4.8.2  nathanw #if 0
    103  1.4.8.2  nathanw 	*(volatile u_int64_t *)0xb4000018 = 0xffffffffffffffff;
    104  1.4.8.2  nathanw #else
    105  1.4.8.2  nathanw 	/* enable all mace interrupts, but no crime devices */
    106  1.4.8.2  nathanw 	*(volatile u_int64_t *)0xb4000018 = 0x000000000000ffff;
    107  1.4.8.2  nathanw #endif
    108  1.4.8.2  nathanw }
    109  1.4.8.2  nathanw 
    110  1.4.8.2  nathanw /*
    111  1.4.8.2  nathanw  * XXX
    112  1.4.8.2  nathanw  */
    113  1.4.8.2  nathanw 
    114  1.4.8.2  nathanw #define CRIME_NINTR 32 	/* XXX */
    115  1.4.8.2  nathanw 
    116  1.4.8.2  nathanw struct {
    117  1.4.8.2  nathanw 	int	(*func)(void *);
    118  1.4.8.2  nathanw 	void	*arg;
    119  1.4.8.2  nathanw } crime[CRIME_NINTR];
    120  1.4.8.2  nathanw 
    121  1.4.8.2  nathanw void *
    122  1.4.8.2  nathanw crime_intr_establish(irq, type, level, func, arg)
    123  1.4.8.2  nathanw 	int irq;
    124  1.4.8.2  nathanw 	int type;
    125  1.4.8.2  nathanw 	int level;
    126  1.4.8.2  nathanw 	int (*func)(void *);
    127  1.4.8.2  nathanw 	void *arg;
    128  1.4.8.2  nathanw {
    129  1.4.8.2  nathanw 	int i;
    130  1.4.8.2  nathanw 
    131  1.4.8.2  nathanw 	for (i = 0; i <= CRIME_NINTR; i++) {
    132  1.4.8.2  nathanw 		if (i == CRIME_NINTR)
    133  1.4.8.2  nathanw 			panic("too many IRQs");
    134  1.4.8.2  nathanw 
    135  1.4.8.2  nathanw 		if (crime[i].func != NULL)
    136  1.4.8.2  nathanw 			continue;
    137  1.4.8.2  nathanw 
    138  1.4.8.2  nathanw 		crime[i].func = func;
    139  1.4.8.2  nathanw 		crime[i].arg = arg;
    140  1.4.8.2  nathanw 		break;
    141  1.4.8.2  nathanw 	}
    142  1.4.8.2  nathanw 
    143  1.4.8.2  nathanw 	return (void *)-1;
    144  1.4.8.2  nathanw }
    145  1.4.8.2  nathanw 
    146  1.4.8.2  nathanw int
    147  1.4.8.2  nathanw crime_intr(arg)
    148  1.4.8.2  nathanw 	void *arg;
    149  1.4.8.2  nathanw {
    150  1.4.8.2  nathanw 	int i;
    151  1.4.8.2  nathanw 
    152  1.4.8.2  nathanw 	for (i = 0; i < CRIME_NINTR; i++) {
    153  1.4.8.2  nathanw int s;
    154  1.4.8.2  nathanw 		if (crime[i].func == NULL)
    155  1.4.8.2  nathanw 			return 0;
    156  1.4.8.2  nathanw 
    157  1.4.8.2  nathanw s = spltty();
    158  1.4.8.2  nathanw 		(*crime[i].func)(crime[i].arg);
    159  1.4.8.2  nathanw splx(s);
    160  1.4.8.2  nathanw 	}
    161  1.4.8.2  nathanw 
    162  1.4.8.2  nathanw 	return 0;
    163  1.4.8.2  nathanw }
    164