pci_kn20aa.c revision 1.56 1 /* $NetBSD: pci_kn20aa.c,v 1.56 2021/06/19 16:59:07 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.56 2021/06/19 16:59:07 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 #include <machine/rpb.h>
45
46 #include <dev/pci/pcireg.h>
47 #include <dev/pci/pcivar.h>
48
49 #include <alpha/pci/ciareg.h>
50 #include <alpha/pci/ciavar.h>
51
52 #include "sio.h"
53 #if NSIO > 0 || NPCEB > 0
54 #include <alpha/pci/siovar.h>
55 #endif
56
57 static int dec_kn20aa_intr_map(const struct pci_attach_args *,
58 pci_intr_handle_t *);
59
60 #define KN20AA_PCEB_IRQ 31
61 #define KN20AA_MAX_IRQ 32
62 #define PCI_STRAY_MAX 5
63
64 static void kn20aa_enable_intr(pci_chipset_tag_t pc, int irq);
65 static void kn20aa_disable_intr(pci_chipset_tag_t pc, int irq);
66
67 static void
68 pci_kn20aa_pickintr(void *core, bus_space_tag_t iot, bus_space_tag_t memt,
69 pci_chipset_tag_t pc)
70 {
71 int i;
72 char *cp;
73
74 pc->pc_intr_v = core;
75 pc->pc_intr_map = dec_kn20aa_intr_map;
76 pc->pc_intr_string = alpha_pci_generic_intr_string;
77 pc->pc_intr_evcnt = alpha_pci_generic_intr_evcnt;
78 pc->pc_intr_establish = alpha_pci_generic_intr_establish;
79 pc->pc_intr_disestablish = alpha_pci_generic_intr_disestablish;
80
81 /* Not supported on KN20AA. */
82 pc->pc_pciide_compat_intr_establish = NULL;
83
84 #define PCI_KN20AA_IRQ_STR 8
85 pc->pc_shared_intrs = alpha_shared_intr_alloc(KN20AA_MAX_IRQ,
86 PCI_KN20AA_IRQ_STR);
87 pc->pc_intr_desc = "kn20aa irq";
88 pc->pc_vecbase = 0x900;
89 pc->pc_nirq = KN20AA_MAX_IRQ;
90
91 pc->pc_intr_enable = kn20aa_enable_intr;
92 pc->pc_intr_disable = kn20aa_disable_intr;
93
94 for (i = 0; i < KN20AA_MAX_IRQ; i++) {
95 alpha_shared_intr_set_maxstrays(pc->pc_shared_intrs, i,
96 PCI_STRAY_MAX);
97
98 cp = alpha_shared_intr_string(pc->pc_shared_intrs, i);
99 snprintf(cp, PCI_KN20AA_IRQ_STR, "irq %d", i);
100 evcnt_attach_dynamic(alpha_shared_intr_evcnt(
101 pc->pc_shared_intrs, i), EVCNT_TYPE_INTR, NULL,
102 "kn20aa", cp);
103 }
104
105 #if NSIO > 0 || NPCEB > 0
106 sio_intr_setup(pc, iot);
107 kn20aa_enable_intr(pc, KN20AA_PCEB_IRQ);
108 #endif
109 }
110 ALPHA_PCI_INTR_INIT(ST_DEC_KN20AA, pci_kn20aa_pickintr)
111
112 static int
113 dec_kn20aa_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
114 {
115 pcitag_t bustag = pa->pa_intrtag;
116 int buspin = pa->pa_intrpin;
117 pci_chipset_tag_t pc = pa->pa_pc;
118 int device;
119 int kn20aa_irq;
120
121 if (buspin == 0) {
122 /* No IRQ used. */
123 return 1;
124 }
125 if (buspin < 0 || buspin > 4) {
126 printf("dec_kn20aa_intr_map: bad interrupt pin %d\n", buspin);
127 return 1;
128 }
129
130 /*
131 * Slot->interrupt translation. Appears to work, though it
132 * may not hold up forever.
133 *
134 * The DEC engineers who did this hardware obviously engaged
135 * in random drug testing.
136 */
137 pci_decompose_tag(pc, bustag, NULL, &device, NULL);
138 switch (device) {
139 case 11:
140 case 12:
141 kn20aa_irq = ((device - 11) + 0) * 4;
142 break;
143
144 case 7:
145 kn20aa_irq = 8;
146 break;
147
148 case 9:
149 kn20aa_irq = 12;
150 break;
151
152 case 6: /* 21040 on AlphaStation 500 */
153 kn20aa_irq = 13;
154 break;
155
156 case 8:
157 kn20aa_irq = 16;
158 break;
159
160 default:
161 printf("dec_kn20aa_intr_map: weird device number %d\n",
162 device);
163 return 1;
164 }
165
166 kn20aa_irq += buspin - 1;
167 if (kn20aa_irq > KN20AA_MAX_IRQ)
168 panic("dec_kn20aa_intr_map: kn20aa_irq too large (%d)",
169 kn20aa_irq);
170
171 alpha_pci_intr_handle_init(ihp, kn20aa_irq, 0);
172 return (0);
173 }
174
175 static void
176 kn20aa_enable_intr(pci_chipset_tag_t pc __unused, int irq)
177 {
178
179 /*
180 * From disassembling small bits of the OSF/1 kernel:
181 * the following appears to enable a given interrupt request.
182 * "blech." I'd give valuable body parts for better docs or
183 * for a good decompiler.
184 */
185 alpha_mb();
186 REGVAL(0x8780000000L + 0x40L) |= (1 << irq); /* XXX */
187 alpha_mb();
188 }
189
190 static void
191 kn20aa_disable_intr(pci_chipset_tag_t pc __unused, int irq)
192 {
193
194 alpha_mb();
195 REGVAL(0x8780000000L + 0x40L) &= ~(1 << irq); /* XXX */
196 alpha_mb();
197 }
198