pci_kn20aa.c revision 1.55 1 /* $NetBSD: pci_kn20aa.c,v 1.55 2020/09/22 15:24:02 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
5 * All rights reserved.
6 *
7 * Author: Chris G. Demetriou
8 *
9 * Permission to use, copy, modify and distribute this software and
10 * its documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation.
14 *
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 *
19 * Carnegie Mellon requests users of this software to return to
20 *
21 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
25 *
26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes.
28 */
29
30 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
31
32 __KERNEL_RCSID(0, "$NetBSD: pci_kn20aa.c,v 1.55 2020/09/22 15:24:02 thorpej Exp $");
33
34 #include <sys/types.h>
35 #include <sys/param.h>
36 #include <sys/time.h>
37 #include <sys/systm.h>
38 #include <sys/errno.h>
39 #include <sys/malloc.h>
40 #include <sys/device.h>
41 #include <sys/syslog.h>
42
43 #include <machine/autoconf.h>
44
45 #include <dev/pci/pcireg.h>
46 #include <dev/pci/pcivar.h>
47
48 #include <alpha/pci/ciareg.h>
49 #include <alpha/pci/ciavar.h>
50
51 #include <alpha/pci/pci_kn20aa.h>
52
53 #include "sio.h"
54 #if NSIO > 0 || NPCEB > 0
55 #include <alpha/pci/siovar.h>
56 #endif
57
58 static int dec_kn20aa_intr_map(const struct pci_attach_args *,
59 pci_intr_handle_t *);
60
61 #define KN20AA_PCEB_IRQ 31
62 #define KN20AA_MAX_IRQ 32
63 #define PCI_STRAY_MAX 5
64
65 static void kn20aa_enable_intr(pci_chipset_tag_t pc, int irq);
66 static void kn20aa_disable_intr(pci_chipset_tag_t pc, int irq);
67
68 void
69 pci_kn20aa_pickintr(struct cia_config *ccp)
70 {
71 int i;
72 #if NSIO > 0 || NPCEB > 0
73 bus_space_tag_t iot = &ccp->cc_iot;
74 #endif
75 pci_chipset_tag_t pc = &ccp->cc_pc;
76 char *cp;
77
78 pc->pc_intr_v = ccp;
79 pc->pc_intr_map = dec_kn20aa_intr_map;
80 pc->pc_intr_string = alpha_pci_generic_intr_string;
81 pc->pc_intr_evcnt = alpha_pci_generic_intr_evcnt;
82 pc->pc_intr_establish = alpha_pci_generic_intr_establish;
83 pc->pc_intr_disestablish = alpha_pci_generic_intr_disestablish;
84
85 /* Not supported on KN20AA. */
86 pc->pc_pciide_compat_intr_establish = NULL;
87
88 #define PCI_KN20AA_IRQ_STR 8
89 pc->pc_shared_intrs = alpha_shared_intr_alloc(KN20AA_MAX_IRQ,
90 PCI_KN20AA_IRQ_STR);
91 pc->pc_intr_desc = "kn20aa irq";
92 pc->pc_vecbase = 0x900;
93 pc->pc_nirq = KN20AA_MAX_IRQ;
94
95 pc->pc_intr_enable = kn20aa_enable_intr;
96 pc->pc_intr_disable = kn20aa_disable_intr;
97
98 for (i = 0; i < KN20AA_MAX_IRQ; i++) {
99 alpha_shared_intr_set_maxstrays(pc->pc_shared_intrs, i,
100 PCI_STRAY_MAX);
101
102 cp = alpha_shared_intr_string(pc->pc_shared_intrs, i);
103 snprintf(cp, PCI_KN20AA_IRQ_STR, "irq %d", i);
104 evcnt_attach_dynamic(alpha_shared_intr_evcnt(
105 pc->pc_shared_intrs, i), EVCNT_TYPE_INTR, NULL,
106 "kn20aa", cp);
107 }
108
109 #if NSIO > 0 || NPCEB > 0
110 sio_intr_setup(pc, iot);
111 kn20aa_enable_intr(pc, KN20AA_PCEB_IRQ);
112 #endif
113 }
114
115 static int
116 dec_kn20aa_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
117 {
118 pcitag_t bustag = pa->pa_intrtag;
119 int buspin = pa->pa_intrpin;
120 pci_chipset_tag_t pc = pa->pa_pc;
121 int device;
122 int kn20aa_irq;
123
124 if (buspin == 0) {
125 /* No IRQ used. */
126 return 1;
127 }
128 if (buspin < 0 || buspin > 4) {
129 printf("dec_kn20aa_intr_map: bad interrupt pin %d\n", buspin);
130 return 1;
131 }
132
133 /*
134 * Slot->interrupt translation. Appears to work, though it
135 * may not hold up forever.
136 *
137 * The DEC engineers who did this hardware obviously engaged
138 * in random drug testing.
139 */
140 pci_decompose_tag(pc, bustag, NULL, &device, NULL);
141 switch (device) {
142 case 11:
143 case 12:
144 kn20aa_irq = ((device - 11) + 0) * 4;
145 break;
146
147 case 7:
148 kn20aa_irq = 8;
149 break;
150
151 case 9:
152 kn20aa_irq = 12;
153 break;
154
155 case 6: /* 21040 on AlphaStation 500 */
156 kn20aa_irq = 13;
157 break;
158
159 case 8:
160 kn20aa_irq = 16;
161 break;
162
163 default:
164 printf("dec_kn20aa_intr_map: weird device number %d\n",
165 device);
166 return 1;
167 }
168
169 kn20aa_irq += buspin - 1;
170 if (kn20aa_irq > KN20AA_MAX_IRQ)
171 panic("dec_kn20aa_intr_map: kn20aa_irq too large (%d)",
172 kn20aa_irq);
173
174 alpha_pci_intr_handle_init(ihp, kn20aa_irq, 0);
175 return (0);
176 }
177
178 static void
179 kn20aa_enable_intr(pci_chipset_tag_t pc __unused, int irq)
180 {
181
182 /*
183 * From disassembling small bits of the OSF/1 kernel:
184 * the following appears to enable a given interrupt request.
185 * "blech." I'd give valuable body parts for better docs or
186 * for a good decompiler.
187 */
188 alpha_mb();
189 REGVAL(0x8780000000L + 0x40L) |= (1 << irq); /* XXX */
190 alpha_mb();
191 }
192
193 static void
194 kn20aa_disable_intr(pci_chipset_tag_t pc __unused, int irq)
195 {
196
197 alpha_mb();
198 REGVAL(0x8780000000L + 0x40L) &= ~(1 << irq); /* XXX */
199 alpha_mb();
200 }
201