crime.c revision 1.4.8.4 1 1.4.8.4 thorpej /* $NetBSD: crime.c,v 1.4.8.4 2003/01/07 21:14:32 thorpej 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.4 thorpej #include <sgimips/dev/macereg.h>
53 1.4.8.2 nathanw #include <sgimips/dev/crimereg.h>
54 1.4.8.2 nathanw
55 1.4.8.2 nathanw #include "locators.h"
56 1.4.8.2 nathanw
57 1.4.8.2 nathanw static int crime_match(struct device *, struct cfdata *, void *);
58 1.4.8.2 nathanw static void crime_attach(struct device *, struct device *, void *);
59 1.4.8.2 nathanw void * crime_intr_establish(int, int, int, int (*)(void *), void *);
60 1.4.8.4 thorpej void crime_intr(u_int);
61 1.4.8.2 nathanw
62 1.4.8.3 nathanw CFATTACH_DECL(crime, sizeof(struct device),
63 1.4.8.3 nathanw crime_match, crime_attach, NULL, NULL);
64 1.4.8.2 nathanw
65 1.4.8.4 thorpej #define CRIME_NINTR 32 /* XXX */
66 1.4.8.4 thorpej
67 1.4.8.4 thorpej struct {
68 1.4.8.4 thorpej int (*func)(void *);
69 1.4.8.4 thorpej void *arg;
70 1.4.8.4 thorpej } crime[CRIME_NINTR];
71 1.4.8.4 thorpej
72 1.4.8.2 nathanw static int
73 1.4.8.2 nathanw crime_match(parent, match, aux)
74 1.4.8.2 nathanw struct device *parent;
75 1.4.8.2 nathanw struct cfdata *match;
76 1.4.8.2 nathanw void *aux;
77 1.4.8.2 nathanw {
78 1.4.8.2 nathanw
79 1.4.8.2 nathanw /*
80 1.4.8.2 nathanw * The CRIME is in the O2.
81 1.4.8.2 nathanw */
82 1.4.8.2 nathanw if (mach_type == MACH_SGI_IP32)
83 1.4.8.2 nathanw return (1);
84 1.4.8.2 nathanw
85 1.4.8.2 nathanw return (0);
86 1.4.8.2 nathanw }
87 1.4.8.2 nathanw
88 1.4.8.2 nathanw static void
89 1.4.8.2 nathanw crime_attach(parent, self, aux)
90 1.4.8.2 nathanw struct device *parent;
91 1.4.8.2 nathanw struct device *self;
92 1.4.8.2 nathanw void *aux;
93 1.4.8.2 nathanw {
94 1.4.8.2 nathanw struct mainbus_attach_args *ma = aux;
95 1.4.8.4 thorpej u_int64_t crm_id;
96 1.4.8.4 thorpej int id, rev;
97 1.4.8.4 thorpej
98 1.4.8.4 thorpej crm_id = bus_space_read_8(ma->ma_iot, ma->ma_ioh, 0);
99 1.4.8.4 thorpej
100 1.4.8.4 thorpej id = (crm_id & 0xf0) >> 4;
101 1.4.8.4 thorpej rev = crm_id & 0x0f;
102 1.4.8.2 nathanw
103 1.4.8.4 thorpej aprint_naive(": system ASIC");
104 1.4.8.2 nathanw
105 1.4.8.4 thorpej switch (id) {
106 1.4.8.4 thorpej case 0x0b:
107 1.4.8.4 thorpej aprint_normal(": rev 1.5");
108 1.4.8.4 thorpej break;
109 1.4.8.4 thorpej
110 1.4.8.4 thorpej case 0x0a:
111 1.4.8.4 thorpej if ((crm_id >> 32) == 0)
112 1.4.8.4 thorpej aprint_normal(": rev 1.1");
113 1.4.8.4 thorpej else if ((crm_id >> 32) == 1)
114 1.4.8.4 thorpej aprint_normal(": rev 1.3");
115 1.4.8.4 thorpej else
116 1.4.8.4 thorpej aprint_normal(": rev 1.4");
117 1.4.8.4 thorpej break;
118 1.4.8.4 thorpej
119 1.4.8.4 thorpej case 0x00:
120 1.4.8.4 thorpej aprint_normal(": Petty CRIME");
121 1.4.8.4 thorpej break;
122 1.4.8.4 thorpej
123 1.4.8.4 thorpej default:
124 1.4.8.4 thorpej aprint_normal(": Unknown CRIME");
125 1.4.8.4 thorpej break;
126 1.4.8.4 thorpej }
127 1.4.8.2 nathanw
128 1.4.8.4 thorpej aprint_normal(" (CRIME_ID: %llx)\n", crm_id);
129 1.4.8.4 thorpej
130 1.4.8.4 thorpej /* All interrupts off. Turned on as we register devices */
131 1.4.8.4 thorpej *(volatile u_int64_t *)MIPS_PHYS_TO_KSEG1(CRIME_INTMASK) = 0;
132 1.4.8.4 thorpej *(volatile u_int64_t *)MIPS_PHYS_TO_KSEG1(CRIME_INTSTAT) = 0;
133 1.4.8.4 thorpej *(volatile u_int64_t *)MIPS_PHYS_TO_KSEG1(CRIME_SOFTINT) = 0;
134 1.4.8.4 thorpej *(volatile u_int64_t *)MIPS_PHYS_TO_KSEG1(CRIME_HARDINT) = 0;
135 1.4.8.4 thorpej *(volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(MACE_ISA_INT_STATUS) = 0;
136 1.4.8.4 thorpej *(volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(MACE_ISA_INT_MASK) = 0;
137 1.4.8.2 nathanw }
138 1.4.8.2 nathanw
139 1.4.8.2 nathanw /*
140 1.4.8.4 thorpej * XXX: sharing interrupts?
141 1.4.8.2 nathanw */
142 1.4.8.2 nathanw
143 1.4.8.2 nathanw void *
144 1.4.8.2 nathanw crime_intr_establish(irq, type, level, func, arg)
145 1.4.8.2 nathanw int irq;
146 1.4.8.2 nathanw int type;
147 1.4.8.2 nathanw int level;
148 1.4.8.2 nathanw int (*func)(void *);
149 1.4.8.2 nathanw void *arg;
150 1.4.8.2 nathanw {
151 1.4.8.4 thorpej if (crime[irq].func != NULL)
152 1.4.8.4 thorpej return NULL; /* panic("Cannot share CRIME interrupts!"); */
153 1.4.8.2 nathanw
154 1.4.8.4 thorpej crime[irq].func = func;
155 1.4.8.4 thorpej crime[irq].arg = arg;
156 1.4.8.2 nathanw
157 1.4.8.4 thorpej return (void *)&crime[irq];
158 1.4.8.2 nathanw }
159 1.4.8.2 nathanw
160 1.4.8.4 thorpej void
161 1.4.8.4 thorpej crime_intr(pendmask)
162 1.4.8.4 thorpej u_int pendmask;
163 1.4.8.2 nathanw {
164 1.4.8.2 nathanw int i;
165 1.4.8.2 nathanw
166 1.4.8.2 nathanw for (i = 0; i < CRIME_NINTR; i++) {
167 1.4.8.4 thorpej if ((pendmask & (1 << i)) && crime[i].func != NULL)
168 1.4.8.4 thorpej (*crime[i].func)(crime[i].arg);
169 1.4.8.2 nathanw }
170 1.4.8.2 nathanw }
171 1.4.8.4 thorpej
172