crime.c revision 1.2 1 1.2 soren /* $NetBSD: crime.c,v 1.2 2000/06/29 15:44:10 soren 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.1 soren *
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.1 soren *
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.1 soren
49 1.1 soren #include <dev/pci/pcivar.h>
50 1.1 soren
51 1.2 soren #if 0
52 1.1 soren #include <sgimips/dev/crimereg.h>
53 1.2 soren #endif
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.2 soren int crime_intr(void *);
61 1.1 soren
62 1.1 soren struct cfattach crime_ca = {
63 1.1 soren sizeof(struct device), crime_match, crime_attach
64 1.1 soren };
65 1.1 soren
66 1.1 soren static int
67 1.1 soren crime_match(parent, match, aux)
68 1.1 soren struct device *parent;
69 1.1 soren struct cfdata *match;
70 1.1 soren void *aux;
71 1.1 soren {
72 1.1 soren struct mainbus_attach_args *ma = aux;
73 1.1 soren
74 1.1 soren /*
75 1.1 soren * The CRIME is in the O2.
76 1.1 soren */
77 1.1 soren switch (ma->ma_arch) {
78 1.1 soren case 32:
79 1.1 soren return 1;
80 1.1 soren default:
81 1.1 soren return 0;
82 1.1 soren }
83 1.1 soren }
84 1.1 soren
85 1.1 soren static void
86 1.1 soren crime_attach(parent, self, aux)
87 1.1 soren struct device *parent;
88 1.1 soren struct device *self;
89 1.1 soren void *aux;
90 1.1 soren {
91 1.1 soren struct mainbus_attach_args *ma = aux;
92 1.1 soren u_int32_t rev; /* really u_int64_t ! */
93 1.1 soren int major, minor;
94 1.1 soren
95 1.1 soren rev = bus_space_read_4(ma->ma_iot, ma->ma_ioh, 4) & 0xff;
96 1.1 soren
97 1.1 soren major = rev > 4;
98 1.1 soren minor = rev & 0x0f;
99 1.1 soren
100 1.1 soren if (major == 0 && minor == 0)
101 1.1 soren printf(": petty\n");
102 1.1 soren else
103 1.1 soren printf(": rev %d.%d\n", major, minor);
104 1.1 soren
105 1.1 soren #if 0
106 1.1 soren *(volatile u_int64_t *)0xb4000018 = 0xffffffffffffffff;
107 1.1 soren #else
108 1.1 soren /* enable all mace interrupts, but no crime devices */
109 1.1 soren *(volatile u_int64_t *)0xb4000018 = 0x000000000000ffff;
110 1.1 soren #endif
111 1.2 soren }
112 1.2 soren
113 1.2 soren /*
114 1.2 soren * XXX
115 1.2 soren */
116 1.2 soren
117 1.2 soren #define CRIME_NINTR 32 /* XXX */
118 1.2 soren
119 1.2 soren struct {
120 1.2 soren int (*func)(void *);
121 1.2 soren void *arg;
122 1.2 soren } crime[CRIME_NINTR];
123 1.2 soren
124 1.2 soren void *
125 1.2 soren crime_intr_establish(irq, type, level, func, arg)
126 1.2 soren int irq;
127 1.2 soren int type;
128 1.2 soren int level;
129 1.2 soren int (*func)(void *);
130 1.2 soren void *arg;
131 1.2 soren {
132 1.2 soren int i;
133 1.2 soren
134 1.2 soren for (i = 0; i <= CRIME_NINTR; i++) {
135 1.2 soren if (i == CRIME_NINTR)
136 1.2 soren panic("too many IRQs");
137 1.2 soren
138 1.2 soren if (crime[i].func != NULL)
139 1.2 soren continue;
140 1.2 soren
141 1.2 soren crime[i].func = func;
142 1.2 soren crime[i].arg = arg;
143 1.2 soren break;
144 1.2 soren }
145 1.2 soren
146 1.2 soren return (void *)-1;
147 1.2 soren }
148 1.2 soren
149 1.2 soren int
150 1.2 soren crime_intr(arg)
151 1.2 soren void *arg;
152 1.2 soren {
153 1.2 soren int i;
154 1.2 soren
155 1.2 soren for (i = 0; i < CRIME_NINTR; i++) {
156 1.2 soren int s;
157 1.2 soren if (crime[i].func == NULL)
158 1.2 soren return 0;
159 1.2 soren
160 1.2 soren s = spltty();
161 1.2 soren (*crime[i].func)(crime[i].arg);
162 1.2 soren splx(s);
163 1.2 soren }
164 1.2 soren
165 1.2 soren return 0;
166 1.1 soren }
167