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