crime.c revision 1.14 1 1.14 keihan /* $NetBSD: crime.c,v 1.14 2003/11/17 10:07:58 keihan 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.14 keihan * 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.12 lukem
39 1.12 lukem #include <sys/cdefs.h>
40 1.14 keihan __KERNEL_RCSID(0, "$NetBSD: crime.c,v 1.14 2003/11/17 10:07:58 keihan Exp $");
41 1.1 soren
42 1.1 soren #include <sys/param.h>
43 1.1 soren #include <sys/device.h>
44 1.1 soren #include <sys/systm.h>
45 1.1 soren
46 1.1 soren #include <machine/cpu.h>
47 1.1 soren #include <machine/locore.h>
48 1.1 soren #include <machine/autoconf.h>
49 1.1 soren #include <machine/bus.h>
50 1.2 soren #include <machine/intr.h>
51 1.4 thorpej #include <machine/machtype.h>
52 1.1 soren
53 1.13 tsutsui #include <sgimips/dev/crimevar.h>
54 1.1 soren #include <sgimips/dev/crimereg.h>
55 1.1 soren
56 1.1 soren #include "locators.h"
57 1.1 soren
58 1.1 soren static int crime_match(struct device *, struct cfdata *, void *);
59 1.1 soren static void crime_attach(struct device *, struct device *, void *);
60 1.1 soren
61 1.13 tsutsui struct crime_softc *crime_sc; /* only one per machine, okay to be global */
62 1.13 tsutsui
63 1.13 tsutsui CFATTACH_DECL(crime, sizeof(struct crime_softc),
64 1.8 thorpej crime_match, crime_attach, NULL, NULL);
65 1.1 soren
66 1.10 rafal #define CRIME_NINTR 32 /* XXX */
67 1.10 rafal
68 1.10 rafal struct {
69 1.10 rafal int (*func)(void *);
70 1.10 rafal void *arg;
71 1.10 rafal } crime[CRIME_NINTR];
72 1.10 rafal
73 1.1 soren static int
74 1.1 soren crime_match(parent, match, aux)
75 1.1 soren struct device *parent;
76 1.1 soren struct cfdata *match;
77 1.1 soren void *aux;
78 1.1 soren {
79 1.1 soren
80 1.1 soren /*
81 1.1 soren * The CRIME is in the O2.
82 1.1 soren */
83 1.4 thorpej if (mach_type == MACH_SGI_IP32)
84 1.4 thorpej return (1);
85 1.4 thorpej
86 1.4 thorpej return (0);
87 1.1 soren }
88 1.1 soren
89 1.1 soren static void
90 1.1 soren crime_attach(parent, self, aux)
91 1.1 soren struct device *parent;
92 1.1 soren struct device *self;
93 1.1 soren void *aux;
94 1.1 soren {
95 1.13 tsutsui struct crime_softc *sc = (struct crime_softc *)self;
96 1.1 soren struct mainbus_attach_args *ma = aux;
97 1.9 rafal u_int64_t crm_id;
98 1.1 soren
99 1.13 tsutsui crime_sc = sc;
100 1.13 tsutsui
101 1.13 tsutsui sc->iot = SGIMIPS_BUS_SPACE_HPC;
102 1.13 tsutsui
103 1.13 tsutsui if (bus_space_map(sc->iot, ma->ma_addr, 0 /* XXX */,
104 1.13 tsutsui BUS_SPACE_MAP_LINEAR, &sc->ioh))
105 1.13 tsutsui panic("crime_attach: can't map I/O space");
106 1.13 tsutsui
107 1.13 tsutsui crm_id = bus_space_read_8(sc->iot, sc->ioh, CRIME_REV);
108 1.1 soren
109 1.10 rafal aprint_naive(": system ASIC");
110 1.10 rafal
111 1.11 rafal switch ((crm_id & CRIME_ID_IDBITS) >> CRIME_ID_IDSHIFT) {
112 1.9 rafal case 0x0b:
113 1.9 rafal aprint_normal(": rev 1.5");
114 1.9 rafal break;
115 1.1 soren
116 1.9 rafal case 0x0a:
117 1.9 rafal if ((crm_id >> 32) == 0)
118 1.9 rafal aprint_normal(": rev 1.1");
119 1.9 rafal else if ((crm_id >> 32) == 1)
120 1.9 rafal aprint_normal(": rev 1.3");
121 1.9 rafal else
122 1.9 rafal aprint_normal(": rev 1.4");
123 1.9 rafal break;
124 1.9 rafal
125 1.9 rafal case 0x00:
126 1.9 rafal aprint_normal(": Petty CRIME");
127 1.9 rafal break;
128 1.1 soren
129 1.9 rafal default:
130 1.9 rafal aprint_normal(": Unknown CRIME");
131 1.9 rafal break;
132 1.9 rafal }
133 1.9 rafal
134 1.9 rafal aprint_normal(" (CRIME_ID: %llx)\n", crm_id);
135 1.10 rafal
136 1.13 tsutsui /* Turn on memory error and crime error interrupts.
137 1.13 tsutsui All others turned on as devices are registered. */
138 1.13 tsutsui bus_space_write_8(sc->iot, sc->ioh, CRIME_INTMASK,
139 1.13 tsutsui CRIME_INT_MEMERR |
140 1.13 tsutsui CRIME_INT_CRMERR |
141 1.13 tsutsui CRIME_INT_VICE |
142 1.13 tsutsui CRIME_INT_VID_OUT |
143 1.13 tsutsui CRIME_INT_VID_IN2 |
144 1.13 tsutsui CRIME_INT_VID_IN1);
145 1.13 tsutsui bus_space_write_8(sc->iot, sc->ioh, CRIME_INTSTAT, 0);
146 1.13 tsutsui bus_space_write_8(sc->iot, sc->ioh, CRIME_SOFTINT, 0);
147 1.13 tsutsui bus_space_write_8(sc->iot, sc->ioh, CRIME_HARDINT, 0);
148 1.2 soren }
149 1.2 soren
150 1.2 soren /*
151 1.10 rafal * XXX: sharing interrupts?
152 1.2 soren */
153 1.2 soren
154 1.5 simonb void *
155 1.2 soren crime_intr_establish(irq, type, level, func, arg)
156 1.5 simonb int irq;
157 1.5 simonb int type;
158 1.5 simonb int level;
159 1.5 simonb int (*func)(void *);
160 1.5 simonb void *arg;
161 1.2 soren {
162 1.10 rafal if (crime[irq].func != NULL)
163 1.10 rafal return NULL; /* panic("Cannot share CRIME interrupts!"); */
164 1.2 soren
165 1.10 rafal crime[irq].func = func;
166 1.10 rafal crime[irq].arg = arg;
167 1.2 soren
168 1.13 tsutsui crime_intr_mask(irq);
169 1.13 tsutsui
170 1.10 rafal return (void *)&crime[irq];
171 1.2 soren }
172 1.2 soren
173 1.9 rafal void
174 1.9 rafal crime_intr(pendmask)
175 1.9 rafal u_int pendmask;
176 1.2 soren {
177 1.2 soren int i;
178 1.2 soren
179 1.2 soren for (i = 0; i < CRIME_NINTR; i++) {
180 1.9 rafal if ((pendmask & (1 << i)) && crime[i].func != NULL)
181 1.9 rafal (*crime[i].func)(crime[i].arg);
182 1.2 soren }
183 1.9 rafal }
184 1.2 soren
185 1.13 tsutsui void
186 1.13 tsutsui crime_intr_mask(unsigned int intr)
187 1.13 tsutsui {
188 1.13 tsutsui u_int64_t mask;
189 1.13 tsutsui
190 1.13 tsutsui mask = bus_space_read_8(crime_sc->iot, crime_sc->ioh, CRIME_INTMASK);
191 1.13 tsutsui mask |= (1 << intr);
192 1.13 tsutsui bus_space_write_8(crime_sc->iot, crime_sc->ioh, CRIME_INTMASK, mask);
193 1.13 tsutsui }
194