pic_mpcsoc.c revision 1.1.2.2 1 1.1.2.2 yamt /* $NetBSD: pic_mpcsoc.c,v 1.1.2.2 2009/08/19 18:46:41 yamt Exp $ */
2 1.1.2.2 yamt
3 1.1.2.2 yamt /*-
4 1.1.2.2 yamt * Copyright (c) 2007 Michael Lorenz
5 1.1.2.2 yamt * All rights reserved.
6 1.1.2.2 yamt *
7 1.1.2.2 yamt * Redistribution and use in source and binary forms, with or without
8 1.1.2.2 yamt * modification, are permitted provided that the following conditions
9 1.1.2.2 yamt * are met:
10 1.1.2.2 yamt * 1. Redistributions of source code must retain the above copyright
11 1.1.2.2 yamt * notice, this list of conditions and the following disclaimer.
12 1.1.2.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
13 1.1.2.2 yamt * notice, this list of conditions and the following disclaimer in the
14 1.1.2.2 yamt * documentation and/or other materials provided with the distribution.
15 1.1.2.2 yamt *
16 1.1.2.2 yamt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 1.1.2.2 yamt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 1.1.2.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 1.1.2.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 1.1.2.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.1.2.2 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.1.2.2 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.1.2.2 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.1.2.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.1.2.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.1.2.2 yamt * POSSIBILITY OF SUCH DAMAGE.
27 1.1.2.2 yamt */
28 1.1.2.2 yamt
29 1.1.2.2 yamt #include <sys/cdefs.h>
30 1.1.2.2 yamt __KERNEL_RCSID(0, "$NetBSD: pic_mpcsoc.c,v 1.1.2.2 2009/08/19 18:46:41 yamt Exp $");
31 1.1.2.2 yamt
32 1.1.2.2 yamt #include <sys/param.h>
33 1.1.2.2 yamt #include <sys/malloc.h>
34 1.1.2.2 yamt #include <sys/kernel.h>
35 1.1.2.2 yamt
36 1.1.2.2 yamt #include <uvm/uvm_extern.h>
37 1.1.2.2 yamt
38 1.1.2.2 yamt #include <machine/pio.h>
39 1.1.2.2 yamt #include <powerpc/openpic.h>
40 1.1.2.2 yamt
41 1.1.2.2 yamt #include <arch/powerpc/pic/picvar.h>
42 1.1.2.2 yamt
43 1.1.2.2 yamt #include "opt_interrupt.h"
44 1.1.2.2 yamt
45 1.1.2.2 yamt static void mpcpic_enable_irq(struct pic_ops *, int, int);
46 1.1.2.2 yamt static void mpcpic_disable_irq(struct pic_ops *, int);
47 1.1.2.2 yamt static void mpcpic_establish_irq(struct pic_ops *, int, int, int);
48 1.1.2.2 yamt static void mpcpic_finish_setup(struct pic_ops *);
49 1.1.2.2 yamt
50 1.1.2.2 yamt static u_int steer8245[] = {
51 1.1.2.2 yamt 0x10200, /* external irq 0 direct/serial */
52 1.1.2.2 yamt 0x10220, /* external irq 1 direct/serial */
53 1.1.2.2 yamt 0x10240, /* external irq 2 direct/serial */
54 1.1.2.2 yamt 0x10260, /* external irq 3 direct/serial */
55 1.1.2.2 yamt 0x10280, /* external irq 4 direct/serial */
56 1.1.2.2 yamt 0x102a0, /* external irq 5 serial mode */
57 1.1.2.2 yamt 0x102c0, /* external irq 6 serial mode */
58 1.1.2.2 yamt 0x102e0, /* external irq 7 serial mode */
59 1.1.2.2 yamt 0x10300, /* external irq 8 serial mode */
60 1.1.2.2 yamt 0x10320, /* external irq 9 serial mode */
61 1.1.2.2 yamt 0x10340, /* external irq 10 serial mode */
62 1.1.2.2 yamt 0x10360, /* external irq 11 serial mode */
63 1.1.2.2 yamt 0x10380, /* external irq 12 serial mode */
64 1.1.2.2 yamt 0x103a0, /* external irq 13 serial mode */
65 1.1.2.2 yamt 0x103c0, /* external irq 14 serial mode */
66 1.1.2.2 yamt 0x103e0, /* external irq 15 serial mode */
67 1.1.2.2 yamt 0x11020, /* I2C */
68 1.1.2.2 yamt 0x11040, /* DMA 0 */
69 1.1.2.2 yamt 0x11060, /* DMA 1 */
70 1.1.2.2 yamt 0x110c0, /* MU/I2O */
71 1.1.2.2 yamt 0x01120, /* Timer 0 */
72 1.1.2.2 yamt 0x01160, /* Timer 1 */
73 1.1.2.2 yamt 0x011a0, /* Timer 2 */
74 1.1.2.2 yamt 0x011e0, /* Timer 3 */
75 1.1.2.2 yamt 0x11120, /* DUART 0, MPC8245 */
76 1.1.2.2 yamt 0x11140, /* DUART 1, MPC8245 */
77 1.1.2.2 yamt };
78 1.1.2.2 yamt #define MPCPIC_IVEC(n) (steer8245[(n)])
79 1.1.2.2 yamt #define MPCPIC_IDST(n) (steer8245[(n)] + 0x10)
80 1.1.2.2 yamt
81 1.1.2.2 yamt static int i8259iswired = 0;
82 1.1.2.2 yamt
83 1.1.2.2 yamt struct pic_ops *
84 1.1.2.2 yamt setup_mpcpic(void *addr)
85 1.1.2.2 yamt {
86 1.1.2.2 yamt struct openpic_ops *ops;
87 1.1.2.2 yamt struct pic_ops *self;
88 1.1.2.2 yamt int irq;
89 1.1.2.2 yamt u_int x;
90 1.1.2.2 yamt
91 1.1.2.2 yamt openpic_base = addr;
92 1.1.2.2 yamt ops = malloc(sizeof(struct openpic_ops), M_DEVBUF, M_NOWAIT);
93 1.1.2.2 yamt KASSERT(ops != NULL);
94 1.1.2.2 yamt self = &ops->pic;
95 1.1.2.2 yamt
96 1.1.2.2 yamt x = openpic_read(OPENPIC_FEATURE);
97 1.1.2.2 yamt if (((x & 0x07ff0000) >> 16) == 0)
98 1.1.2.2 yamt panic("setup_mpcpic() called on distributed openpic");
99 1.1.2.2 yamt
100 1.1.2.2 yamt aprint_normal("OpenPIC Version 1.%d: "
101 1.1.2.2 yamt "Supports %d CPUs and %d interrupt sources.\n",
102 1.1.2.2 yamt x & 0xff, ((x & 0x1f00) >> 8) + 1, ((x & 0x07ff0000) >> 16) + 1);
103 1.1.2.2 yamt
104 1.1.2.2 yamt #ifdef PIC_I8259
105 1.1.2.2 yamt i8259iswired = 1;
106 1.1.2.2 yamt #endif
107 1.1.2.2 yamt self->pic_numintrs = ((x & 0x07ff0000) >> 16) + 1;
108 1.1.2.2 yamt self->pic_cookie = addr;
109 1.1.2.2 yamt self->pic_enable_irq = mpcpic_enable_irq;
110 1.1.2.2 yamt self->pic_reenable_irq = mpcpic_enable_irq;
111 1.1.2.2 yamt self->pic_disable_irq = mpcpic_disable_irq;
112 1.1.2.2 yamt self->pic_get_irq = opic_get_irq;
113 1.1.2.2 yamt self->pic_ack_irq = opic_ack_irq;
114 1.1.2.2 yamt self->pic_establish_irq = mpcpic_establish_irq;
115 1.1.2.2 yamt self->pic_finish_setup = mpcpic_finish_setup;
116 1.1.2.2 yamt ops->isu = NULL;
117 1.1.2.2 yamt ops->nrofisus = 0; /* internal only */
118 1.1.2.2 yamt ops->flags = 0; /* no flags (yet) */
119 1.1.2.2 yamt ops->irq_per = NULL; /* internal ISU only */
120 1.1.2.2 yamt strcpy(self->pic_name, "mpcpic");
121 1.1.2.2 yamt pic_add(self);
122 1.1.2.2 yamt
123 1.1.2.2 yamt openpic_set_priority(0, 15);
124 1.1.2.2 yamt for (irq = 0; irq < self->pic_numintrs; irq++) {
125 1.1.2.2 yamt /* make sure to keep disabled */
126 1.1.2.2 yamt openpic_write(MPCPIC_IVEC(irq), OPENPIC_IMASK);
127 1.1.2.2 yamt /* send all interrupts to CPU 0 */
128 1.1.2.2 yamt openpic_write(MPCPIC_IDST(irq), 1 << 0);
129 1.1.2.2 yamt }
130 1.1.2.2 yamt openpic_write(OPENPIC_SPURIOUS_VECTOR, 0xff);
131 1.1.2.2 yamt openpic_set_priority(0, 0);
132 1.1.2.2 yamt
133 1.1.2.2 yamt /* clear all pending interrunts */
134 1.1.2.2 yamt for (irq = 0; irq < self->pic_numintrs; irq++) {
135 1.1.2.2 yamt openpic_read_irq(0);
136 1.1.2.2 yamt openpic_eoi(0);
137 1.1.2.2 yamt }
138 1.1.2.2 yamt
139 1.1.2.2 yamt #if 0
140 1.1.2.2 yamt printf("timebase freq=%d\n", openpic_read(0x10f0));
141 1.1.2.2 yamt #endif
142 1.1.2.2 yamt return self;
143 1.1.2.2 yamt }
144 1.1.2.2 yamt
145 1.1.2.2 yamt void
146 1.1.2.2 yamt mpcpic_reserv16()
147 1.1.2.2 yamt {
148 1.1.2.2 yamt extern int max_base; /* intr.c */
149 1.1.2.2 yamt
150 1.1.2.2 yamt /*
151 1.1.2.2 yamt * reserve 16 irq slot for the case when no i8259 exists to use.
152 1.1.2.2 yamt */
153 1.1.2.2 yamt max_base += 16;
154 1.1.2.2 yamt }
155 1.1.2.2 yamt
156 1.1.2.2 yamt static void
157 1.1.2.2 yamt mpcpic_establish_irq(struct pic_ops *pic, int irq, int type, int pri)
158 1.1.2.2 yamt {
159 1.1.2.2 yamt int realpri = max(1, min(15, pri));
160 1.1.2.2 yamt u_int x;
161 1.1.2.2 yamt
162 1.1.2.2 yamt x = irq;
163 1.1.2.2 yamt x |= OPENPIC_IMASK;
164 1.1.2.2 yamt x |= (i8259iswired && irq == 0) ?
165 1.1.2.2 yamt OPENPIC_POLARITY_POSITIVE : OPENPIC_POLARITY_NEGATIVE;
166 1.1.2.2 yamt x |= (type == IST_EDGE) ? OPENPIC_SENSE_EDGE : OPENPIC_SENSE_LEVEL;
167 1.1.2.2 yamt x |= realpri << OPENPIC_PRIORITY_SHIFT;
168 1.1.2.2 yamt openpic_write(MPCPIC_IVEC(irq), x);
169 1.1.2.2 yamt
170 1.1.2.2 yamt aprint_debug("%s: setting IRQ %d to priority %d\n", __func__, irq,
171 1.1.2.2 yamt realpri);
172 1.1.2.2 yamt }
173 1.1.2.2 yamt
174 1.1.2.2 yamt static void
175 1.1.2.2 yamt mpcpic_enable_irq(struct pic_ops *pic, int irq, int type)
176 1.1.2.2 yamt {
177 1.1.2.2 yamt u_int x;
178 1.1.2.2 yamt
179 1.1.2.2 yamt x = openpic_read(MPCPIC_IVEC(irq));
180 1.1.2.2 yamt x &= ~OPENPIC_IMASK;
181 1.1.2.2 yamt openpic_write(MPCPIC_IVEC(irq), x);
182 1.1.2.2 yamt }
183 1.1.2.2 yamt
184 1.1.2.2 yamt static void
185 1.1.2.2 yamt mpcpic_disable_irq(struct pic_ops *pic, int irq)
186 1.1.2.2 yamt {
187 1.1.2.2 yamt u_int x;
188 1.1.2.2 yamt
189 1.1.2.2 yamt x = openpic_read(MPCPIC_IVEC(irq));
190 1.1.2.2 yamt x |= OPENPIC_IMASK;
191 1.1.2.2 yamt openpic_write(MPCPIC_IVEC(irq), x);
192 1.1.2.2 yamt }
193 1.1.2.2 yamt
194 1.1.2.2 yamt static void
195 1.1.2.2 yamt mpcpic_finish_setup(struct pic_ops *pic)
196 1.1.2.2 yamt {
197 1.1.2.2 yamt uint32_t cpumask = 1;
198 1.1.2.2 yamt int i;
199 1.1.2.2 yamt
200 1.1.2.2 yamt for (i = 0; i < pic->pic_numintrs; i++) {
201 1.1.2.2 yamt /* send all interrupts to all active CPUs */
202 1.1.2.2 yamt openpic_write(MPCPIC_IDST(i), cpumask);
203 1.1.2.2 yamt }
204 1.1.2.2 yamt }
205