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