xref: /freebsd/sys/powerpc/mpc85xx/atpic.c (revision a05a680469a7ac77b195021fed74e3aa58152dd7)
1ac741ae5SMarcel Moolenaar /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
371e3c308SPedro F. Giffuni  *
4ac741ae5SMarcel Moolenaar  * Copyright (c) 2009 Marcel Moolenaar
5ac741ae5SMarcel Moolenaar  *
6ac741ae5SMarcel Moolenaar  * Redistribution and use in source and binary forms, with or without
7ac741ae5SMarcel Moolenaar  * modification, are permitted provided that the following conditions
8ac741ae5SMarcel Moolenaar  * are met:
9ac741ae5SMarcel Moolenaar  * 1. Redistributions of source code must retain the above copyright
10ac741ae5SMarcel Moolenaar  *    notice, this list of conditions and the following disclaimer.
11ac741ae5SMarcel Moolenaar  * 2. Redistributions in binary form must reproduce the above copyright
12ac741ae5SMarcel Moolenaar  *    notice, this list of conditions and the following disclaimer in the
13ac741ae5SMarcel Moolenaar  *    documentation and/or other materials provided with the distribution.
14ac741ae5SMarcel Moolenaar  *
15ac741ae5SMarcel Moolenaar  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16ac741ae5SMarcel Moolenaar  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17ac741ae5SMarcel Moolenaar  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18ac741ae5SMarcel Moolenaar  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19ac741ae5SMarcel Moolenaar  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20ac741ae5SMarcel Moolenaar  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21ac741ae5SMarcel Moolenaar  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
22ac741ae5SMarcel Moolenaar  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23ac741ae5SMarcel Moolenaar  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24ac741ae5SMarcel Moolenaar  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25ac741ae5SMarcel Moolenaar  * SUCH DAMAGE.
26ac741ae5SMarcel Moolenaar  */
27ac741ae5SMarcel Moolenaar 
28ac741ae5SMarcel Moolenaar #include <sys/param.h>
29ac741ae5SMarcel Moolenaar #include <sys/systm.h>
30f1a8a358SMarcel Moolenaar #include <sys/bus.h>
31f1a8a358SMarcel Moolenaar #include <sys/cpuset.h>
32ac741ae5SMarcel Moolenaar #include <sys/kernel.h>
33ac741ae5SMarcel Moolenaar #include <sys/module.h>
34ac741ae5SMarcel Moolenaar #include <sys/rman.h>
35ac741ae5SMarcel Moolenaar 
36ac741ae5SMarcel Moolenaar #include <machine/bus.h>
37ac741ae5SMarcel Moolenaar #include <machine/intr_machdep.h>
38ac741ae5SMarcel Moolenaar #include <machine/pio.h>
39ac741ae5SMarcel Moolenaar 
40d1d3233eSRafal Jaworowski #include <powerpc/mpc85xx/mpc85xx.h>
41ac741ae5SMarcel Moolenaar 
42ac741ae5SMarcel Moolenaar #include <dev/ic/i8259.h>
43ac741ae5SMarcel Moolenaar 
44ac741ae5SMarcel Moolenaar #include <isa/isareg.h>
45ac741ae5SMarcel Moolenaar #include <isa/isavar.h>
46ac741ae5SMarcel Moolenaar 
47ac741ae5SMarcel Moolenaar #include "pic_if.h"
48ac741ae5SMarcel Moolenaar 
49ac741ae5SMarcel Moolenaar #define	ATPIC_MASTER	0
50ac741ae5SMarcel Moolenaar #define	ATPIC_SLAVE	1
51ac741ae5SMarcel Moolenaar 
52ac741ae5SMarcel Moolenaar struct atpic_softc {
53ac741ae5SMarcel Moolenaar 	device_t	sc_dev;
54ac741ae5SMarcel Moolenaar 
55ac741ae5SMarcel Moolenaar 	/* I/O port resources for master & slave. */
56ac741ae5SMarcel Moolenaar 	struct resource	*sc_res[2];
57ac741ae5SMarcel Moolenaar 	int		sc_rid[2];
58ac741ae5SMarcel Moolenaar 
59ac741ae5SMarcel Moolenaar 	/* Our "routing" interrupt */
60ac741ae5SMarcel Moolenaar 	struct resource *sc_ires;
61ac741ae5SMarcel Moolenaar 	void		*sc_icookie;
62ac741ae5SMarcel Moolenaar 	int		sc_irid;
63ac741ae5SMarcel Moolenaar 
64ac741ae5SMarcel Moolenaar 	int		sc_vector[16];
65ac741ae5SMarcel Moolenaar 	uint8_t		sc_mask[2];
66ac741ae5SMarcel Moolenaar };
67ac741ae5SMarcel Moolenaar 
68ac741ae5SMarcel Moolenaar static int	atpic_isa_attach(device_t);
69ac741ae5SMarcel Moolenaar static void	atpic_isa_identify(driver_t *, device_t);
70ac741ae5SMarcel Moolenaar static int	atpic_isa_probe(device_t);
71ac741ae5SMarcel Moolenaar 
72ac741ae5SMarcel Moolenaar static void atpic_config(device_t, u_int, enum intr_trigger,
73ac741ae5SMarcel Moolenaar     enum intr_polarity);
74ac741ae5SMarcel Moolenaar static void atpic_dispatch(device_t, struct trapframe *);
75ac741ae5SMarcel Moolenaar static void atpic_enable(device_t, u_int, u_int);
76ac741ae5SMarcel Moolenaar static void atpic_eoi(device_t, u_int);
77ac741ae5SMarcel Moolenaar static void atpic_ipi(device_t, u_int);
78ac741ae5SMarcel Moolenaar static void atpic_mask(device_t, u_int);
79ac741ae5SMarcel Moolenaar static void atpic_unmask(device_t, u_int);
80eaef5f0aSNathan Whitehorn 
8154423402SNathan Whitehorn static void atpic_ofw_translate_code(device_t, u_int irq, int code,
8254423402SNathan Whitehorn     enum intr_trigger *trig, enum intr_polarity *pol);
8354423402SNathan Whitehorn 
84ac741ae5SMarcel Moolenaar static device_method_t atpic_isa_methods[] = {
85ac741ae5SMarcel Moolenaar 	/* Device interface */
86ac741ae5SMarcel Moolenaar 	DEVMETHOD(device_identify, 	atpic_isa_identify),
87ac741ae5SMarcel Moolenaar 	DEVMETHOD(device_probe,		atpic_isa_probe),
88ac741ae5SMarcel Moolenaar 	DEVMETHOD(device_attach,	atpic_isa_attach),
89ac741ae5SMarcel Moolenaar 
90ac741ae5SMarcel Moolenaar 	/* PIC interface */
91ac741ae5SMarcel Moolenaar 	DEVMETHOD(pic_config,		atpic_config),
92ac741ae5SMarcel Moolenaar 	DEVMETHOD(pic_dispatch,		atpic_dispatch),
93ac741ae5SMarcel Moolenaar 	DEVMETHOD(pic_enable,		atpic_enable),
94ac741ae5SMarcel Moolenaar 	DEVMETHOD(pic_eoi,		atpic_eoi),
95ac741ae5SMarcel Moolenaar 	DEVMETHOD(pic_ipi,		atpic_ipi),
96ac741ae5SMarcel Moolenaar 	DEVMETHOD(pic_mask,		atpic_mask),
97ac741ae5SMarcel Moolenaar 	DEVMETHOD(pic_unmask,		atpic_unmask),
98ac741ae5SMarcel Moolenaar 
9954423402SNathan Whitehorn 	DEVMETHOD(pic_translate_code,	atpic_ofw_translate_code),
10054423402SNathan Whitehorn 
101ac741ae5SMarcel Moolenaar 	{ 0, 0 },
102ac741ae5SMarcel Moolenaar };
103ac741ae5SMarcel Moolenaar 
104ac741ae5SMarcel Moolenaar static driver_t atpic_isa_driver = {
105ac741ae5SMarcel Moolenaar 	"atpic",
106ac741ae5SMarcel Moolenaar 	atpic_isa_methods,
107ac741ae5SMarcel Moolenaar 	sizeof(struct atpic_softc)
108ac741ae5SMarcel Moolenaar };
109ac741ae5SMarcel Moolenaar 
110ac741ae5SMarcel Moolenaar static struct isa_pnp_id atpic_ids[] = {
111ac741ae5SMarcel Moolenaar 	{ 0x0000d041 /* PNP0000 */, "AT interrupt controller" },
112ac741ae5SMarcel Moolenaar 	{ 0 }
113ac741ae5SMarcel Moolenaar };
114ac741ae5SMarcel Moolenaar 
1155d7d6129SJohn Baldwin DRIVER_MODULE(atpic, isa, atpic_isa_driver, 0, 0);
116d6b66397SWarner Losh ISA_PNP_INFO(atpic_ids);
117d6b66397SWarner Losh 
118ac741ae5SMarcel Moolenaar static __inline uint8_t
119ac741ae5SMarcel Moolenaar atpic_read(struct atpic_softc *sc, int icu, int ofs)
120ac741ae5SMarcel Moolenaar {
121ac741ae5SMarcel Moolenaar 	uint8_t val;
122ac741ae5SMarcel Moolenaar 
123ac741ae5SMarcel Moolenaar 	val = bus_read_1(sc->sc_res[icu], ofs);
124ac741ae5SMarcel Moolenaar 	return (val);
125ac741ae5SMarcel Moolenaar }
126ac741ae5SMarcel Moolenaar 
127ac741ae5SMarcel Moolenaar static __inline void
128ac741ae5SMarcel Moolenaar atpic_write(struct atpic_softc *sc, int icu, int ofs, uint8_t val)
129ac741ae5SMarcel Moolenaar {
130ac741ae5SMarcel Moolenaar 
131ac741ae5SMarcel Moolenaar 	bus_write_1(sc->sc_res[icu], ofs, val);
132ac741ae5SMarcel Moolenaar 	bus_barrier(sc->sc_res[icu], ofs, 2 - ofs,
133ac741ae5SMarcel Moolenaar 	    BUS_SPACE_BARRIER_READ|BUS_SPACE_BARRIER_WRITE);
134ac741ae5SMarcel Moolenaar }
135ac741ae5SMarcel Moolenaar 
136ac741ae5SMarcel Moolenaar static void
137ac741ae5SMarcel Moolenaar atpic_intr(void *arg)
138ac741ae5SMarcel Moolenaar {
139ac741ae5SMarcel Moolenaar 
140ec120b94SMarcel Moolenaar 	atpic_dispatch(arg, NULL);
141ac741ae5SMarcel Moolenaar }
142ac741ae5SMarcel Moolenaar 
143ac741ae5SMarcel Moolenaar static void
144ac741ae5SMarcel Moolenaar atpic_isa_identify(driver_t *drv, device_t parent)
145ac741ae5SMarcel Moolenaar {
146ac741ae5SMarcel Moolenaar 	device_t child;
147ac741ae5SMarcel Moolenaar 
148*a05a6804SWarner Losh 	child = BUS_ADD_CHILD(parent, ISA_ORDER_SENSITIVE, drv->name, DEVICE_UNIT_ANY);
149ac741ae5SMarcel Moolenaar 	device_set_driver(child, drv);
150ac741ae5SMarcel Moolenaar 	isa_set_logicalid(child, atpic_ids[0].ip_id);
151ac741ae5SMarcel Moolenaar 	isa_set_vendorid(child, atpic_ids[0].ip_id);
152ac741ae5SMarcel Moolenaar 
153ac741ae5SMarcel Moolenaar 	bus_set_resource(child, SYS_RES_IOPORT, ATPIC_MASTER, IO_ICU1, 2);
154ac741ae5SMarcel Moolenaar 	bus_set_resource(child, SYS_RES_IOPORT, ATPIC_SLAVE, IO_ICU2, 2);
155ac741ae5SMarcel Moolenaar 
156ac741ae5SMarcel Moolenaar 	/* ISA interrupts are routed through external interrupt 0. */
1576d2d7b8cSMarcel Moolenaar 	bus_set_resource(child, SYS_RES_IRQ, 0, 16, 1);
158ac741ae5SMarcel Moolenaar }
159ac741ae5SMarcel Moolenaar 
160ac741ae5SMarcel Moolenaar static int
161ac741ae5SMarcel Moolenaar atpic_isa_probe(device_t dev)
162ac741ae5SMarcel Moolenaar {
163ac741ae5SMarcel Moolenaar 	int res;
164ac741ae5SMarcel Moolenaar 
165ac741ae5SMarcel Moolenaar 	res = ISA_PNP_PROBE(device_get_parent(dev), dev, atpic_ids);
166ac741ae5SMarcel Moolenaar 	if (res > 0)
167ac741ae5SMarcel Moolenaar 		return (res);
168ac741ae5SMarcel Moolenaar 
169ac741ae5SMarcel Moolenaar 	device_set_desc(dev, "PC/AT compatible PIC");
170ac741ae5SMarcel Moolenaar 	return (res);
171ac741ae5SMarcel Moolenaar }
172ac741ae5SMarcel Moolenaar 
173ac741ae5SMarcel Moolenaar static void
174ac741ae5SMarcel Moolenaar atpic_init(struct atpic_softc *sc, int icu)
175ac741ae5SMarcel Moolenaar {
176ac741ae5SMarcel Moolenaar 
177ac741ae5SMarcel Moolenaar 	sc->sc_mask[icu] = 0xff - ((icu == ATPIC_MASTER) ? 4 : 0);
178ac741ae5SMarcel Moolenaar 
179ac741ae5SMarcel Moolenaar 	atpic_write(sc, icu, 0, ICW1_RESET | ICW1_IC4);
180ac741ae5SMarcel Moolenaar 	atpic_write(sc, icu, 1, (icu == ATPIC_SLAVE) ? 8 : 0);
181ac741ae5SMarcel Moolenaar 	atpic_write(sc, icu, 1, (icu == ATPIC_SLAVE) ? 2 : 4);
182ac741ae5SMarcel Moolenaar 	atpic_write(sc, icu, 1, ICW4_8086);
183ac741ae5SMarcel Moolenaar 	atpic_write(sc, icu, 1, sc->sc_mask[icu]);
184ac741ae5SMarcel Moolenaar 	atpic_write(sc, icu, 0, OCW3_SEL | OCW3_RR);
185ac741ae5SMarcel Moolenaar }
186ac741ae5SMarcel Moolenaar 
187ac741ae5SMarcel Moolenaar static int
188ac741ae5SMarcel Moolenaar atpic_isa_attach(device_t dev)
189ac741ae5SMarcel Moolenaar {
190ac741ae5SMarcel Moolenaar 	struct atpic_softc *sc;
191ac741ae5SMarcel Moolenaar 	int error;
192ac741ae5SMarcel Moolenaar 
193ac741ae5SMarcel Moolenaar 	sc = device_get_softc(dev);
194ac741ae5SMarcel Moolenaar 	sc->sc_dev = dev;
195ac741ae5SMarcel Moolenaar 
196ac741ae5SMarcel Moolenaar 	error = ENXIO;
197ac741ae5SMarcel Moolenaar 
198ac741ae5SMarcel Moolenaar 	sc->sc_rid[ATPIC_MASTER] = 0;
199ac741ae5SMarcel Moolenaar 	sc->sc_res[ATPIC_MASTER] = bus_alloc_resource_any(dev, SYS_RES_IOPORT,
200ac741ae5SMarcel Moolenaar 	    &sc->sc_rid[ATPIC_MASTER], RF_ACTIVE);
201ac741ae5SMarcel Moolenaar 	if (sc->sc_res[ATPIC_MASTER] == NULL)
202ac741ae5SMarcel Moolenaar 		goto fail;
203ac741ae5SMarcel Moolenaar 
204ac741ae5SMarcel Moolenaar 	sc->sc_rid[ATPIC_SLAVE] = 1;
205ac741ae5SMarcel Moolenaar 	sc->sc_res[ATPIC_SLAVE] = bus_alloc_resource_any(dev, SYS_RES_IOPORT,
206ac741ae5SMarcel Moolenaar 	    &sc->sc_rid[ATPIC_SLAVE], RF_ACTIVE);
207ac741ae5SMarcel Moolenaar 	if (sc->sc_res[ATPIC_SLAVE] == NULL)
208ac741ae5SMarcel Moolenaar 		goto fail;
209ac741ae5SMarcel Moolenaar 
210ac741ae5SMarcel Moolenaar 	sc->sc_irid = 0;
211ac741ae5SMarcel Moolenaar 	sc->sc_ires = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->sc_irid,
212ac741ae5SMarcel Moolenaar 	    RF_ACTIVE);
213ac741ae5SMarcel Moolenaar 	if (sc->sc_ires == NULL)
214ac741ae5SMarcel Moolenaar 		goto fail;
215ac741ae5SMarcel Moolenaar 
216591dea8cSMarcel Moolenaar 	error = bus_setup_intr(dev, sc->sc_ires, INTR_TYPE_MISC | INTR_MPSAFE,
217ec120b94SMarcel Moolenaar 	    NULL, atpic_intr, dev, &sc->sc_icookie);
218ac741ae5SMarcel Moolenaar 	if (error)
219ac741ae5SMarcel Moolenaar 		goto fail;
220ac741ae5SMarcel Moolenaar 
221ac741ae5SMarcel Moolenaar 	atpic_init(sc, ATPIC_SLAVE);
222ac741ae5SMarcel Moolenaar 	atpic_init(sc, ATPIC_MASTER);
223ac741ae5SMarcel Moolenaar 
2246d2d7b8cSMarcel Moolenaar 	powerpc_register_pic(dev, 0, 16, 0, TRUE);
225ac741ae5SMarcel Moolenaar 	return (0);
226ac741ae5SMarcel Moolenaar 
227ac741ae5SMarcel Moolenaar  fail:
228ac741ae5SMarcel Moolenaar 	if (sc->sc_ires != NULL)
229ac741ae5SMarcel Moolenaar 		bus_release_resource(dev, SYS_RES_IRQ, sc->sc_irid,
230ac741ae5SMarcel Moolenaar 		    sc->sc_ires);
231ac741ae5SMarcel Moolenaar 	if (sc->sc_res[ATPIC_SLAVE] != NULL)
232ac741ae5SMarcel Moolenaar 		bus_release_resource(dev, SYS_RES_IOPORT,
233ac741ae5SMarcel Moolenaar 		    sc->sc_rid[ATPIC_SLAVE], sc->sc_res[ATPIC_SLAVE]);
234ac741ae5SMarcel Moolenaar 	if (sc->sc_res[ATPIC_MASTER] != NULL)
235ac741ae5SMarcel Moolenaar 		bus_release_resource(dev, SYS_RES_IOPORT,
236ac741ae5SMarcel Moolenaar 		    sc->sc_rid[ATPIC_MASTER], sc->sc_res[ATPIC_MASTER]);
237ac741ae5SMarcel Moolenaar 	return (error);
238ac741ae5SMarcel Moolenaar }
239ac741ae5SMarcel Moolenaar 
240ac741ae5SMarcel Moolenaar /*
241ac741ae5SMarcel Moolenaar  * PIC interface.
242ac741ae5SMarcel Moolenaar  */
243ac741ae5SMarcel Moolenaar 
244ac741ae5SMarcel Moolenaar static void
245ac741ae5SMarcel Moolenaar atpic_config(device_t dev, u_int irq, enum intr_trigger trig,
246ac741ae5SMarcel Moolenaar     enum intr_polarity pol)
247ac741ae5SMarcel Moolenaar {
248ac741ae5SMarcel Moolenaar }
249ac741ae5SMarcel Moolenaar 
250ac741ae5SMarcel Moolenaar static void
251ac741ae5SMarcel Moolenaar atpic_dispatch(device_t dev, struct trapframe *tf)
252ac741ae5SMarcel Moolenaar {
253ac741ae5SMarcel Moolenaar 	struct atpic_softc *sc;
254ac741ae5SMarcel Moolenaar 	uint8_t irq;
255ac741ae5SMarcel Moolenaar 
256ac741ae5SMarcel Moolenaar 	sc = device_get_softc(dev);
257ac741ae5SMarcel Moolenaar 	atpic_write(sc, ATPIC_MASTER, 0, OCW3_SEL | OCW3_P);
258ac741ae5SMarcel Moolenaar 	irq = atpic_read(sc, ATPIC_MASTER, 0);
259ac741ae5SMarcel Moolenaar 	atpic_write(sc, ATPIC_MASTER, 0, OCW3_SEL | OCW3_RR);
260ac741ae5SMarcel Moolenaar 	if ((irq & 0x80) == 0)
261ac741ae5SMarcel Moolenaar 		return;
262ac741ae5SMarcel Moolenaar 
263ac741ae5SMarcel Moolenaar 	if (irq == 0x82) {
264ac741ae5SMarcel Moolenaar 		atpic_write(sc, ATPIC_SLAVE, 0, OCW3_SEL | OCW3_P);
265ac741ae5SMarcel Moolenaar 		irq = atpic_read(sc, ATPIC_SLAVE, 0) + 8;
266ac741ae5SMarcel Moolenaar 		atpic_write(sc, ATPIC_SLAVE, 0, OCW3_SEL | OCW3_RR);
267ac741ae5SMarcel Moolenaar 		if ((irq & 0x80) == 0)
268ac741ae5SMarcel Moolenaar 			return;
269ac741ae5SMarcel Moolenaar 	}
270ac741ae5SMarcel Moolenaar 
271ac741ae5SMarcel Moolenaar 	powerpc_dispatch_intr(sc->sc_vector[irq & 0x0f], tf);
272ac741ae5SMarcel Moolenaar }
273ac741ae5SMarcel Moolenaar 
274ac741ae5SMarcel Moolenaar static void
275ac741ae5SMarcel Moolenaar atpic_enable(device_t dev, u_int irq, u_int vector)
276ac741ae5SMarcel Moolenaar {
277ac741ae5SMarcel Moolenaar 	struct atpic_softc *sc;
278ac741ae5SMarcel Moolenaar 
279ac741ae5SMarcel Moolenaar 	sc = device_get_softc(dev);
280ac741ae5SMarcel Moolenaar 	sc->sc_vector[irq] = vector;
281ac741ae5SMarcel Moolenaar 	atpic_unmask(dev, irq);
282ac741ae5SMarcel Moolenaar }
283ac741ae5SMarcel Moolenaar 
284ac741ae5SMarcel Moolenaar static void
285ac741ae5SMarcel Moolenaar atpic_eoi(device_t dev, u_int irq)
286ac741ae5SMarcel Moolenaar {
287ac741ae5SMarcel Moolenaar 	struct atpic_softc *sc;
288ac741ae5SMarcel Moolenaar 
289ac741ae5SMarcel Moolenaar 	sc = device_get_softc(dev);
290ac741ae5SMarcel Moolenaar 	if (irq > 7)
291ac741ae5SMarcel Moolenaar 		atpic_write(sc, ATPIC_SLAVE, 0, OCW2_EOI);
292ac741ae5SMarcel Moolenaar 	atpic_write(sc, ATPIC_MASTER, 0, OCW2_EOI);
293ac741ae5SMarcel Moolenaar }
294ac741ae5SMarcel Moolenaar 
295ac741ae5SMarcel Moolenaar static void
296ac741ae5SMarcel Moolenaar atpic_ipi(device_t dev, u_int cpu)
297ac741ae5SMarcel Moolenaar {
298ac741ae5SMarcel Moolenaar 	/* No SMP support. */
299ac741ae5SMarcel Moolenaar }
300ac741ae5SMarcel Moolenaar 
301ac741ae5SMarcel Moolenaar static void
302ac741ae5SMarcel Moolenaar atpic_mask(device_t dev, u_int irq)
303ac741ae5SMarcel Moolenaar {
304ac741ae5SMarcel Moolenaar 	struct atpic_softc *sc;
305ac741ae5SMarcel Moolenaar 
306ac741ae5SMarcel Moolenaar 	sc = device_get_softc(dev);
307ac741ae5SMarcel Moolenaar 	if (irq > 7) {
308ac741ae5SMarcel Moolenaar 		sc->sc_mask[ATPIC_SLAVE] |= 1 << (irq - 8);
309ac741ae5SMarcel Moolenaar 		atpic_write(sc, ATPIC_SLAVE, 1, sc->sc_mask[ATPIC_SLAVE]);
310ac741ae5SMarcel Moolenaar 	} else {
311ac741ae5SMarcel Moolenaar 		sc->sc_mask[ATPIC_MASTER] |= 1 << irq;
312ac741ae5SMarcel Moolenaar 		atpic_write(sc, ATPIC_MASTER, 1, sc->sc_mask[ATPIC_MASTER]);
313ac741ae5SMarcel Moolenaar 	}
314ac741ae5SMarcel Moolenaar }
315ac741ae5SMarcel Moolenaar 
316ac741ae5SMarcel Moolenaar static void
317ac741ae5SMarcel Moolenaar atpic_unmask(device_t dev, u_int irq)
318ac741ae5SMarcel Moolenaar {
319ac741ae5SMarcel Moolenaar 	struct atpic_softc *sc;
320ac741ae5SMarcel Moolenaar 
321ac741ae5SMarcel Moolenaar 	sc = device_get_softc(dev);
322ac741ae5SMarcel Moolenaar 	if (irq > 7) {
323ac741ae5SMarcel Moolenaar 		sc->sc_mask[ATPIC_SLAVE] &= ~(1 << (irq - 8));
324ac741ae5SMarcel Moolenaar 		atpic_write(sc, ATPIC_SLAVE, 1, sc->sc_mask[ATPIC_SLAVE]);
325ac741ae5SMarcel Moolenaar 	} else {
326ac741ae5SMarcel Moolenaar 		sc->sc_mask[ATPIC_MASTER] &= ~(1 << irq);
327ac741ae5SMarcel Moolenaar 		atpic_write(sc, ATPIC_MASTER, 1, sc->sc_mask[ATPIC_MASTER]);
328ac741ae5SMarcel Moolenaar 	}
329ac741ae5SMarcel Moolenaar }
33054423402SNathan Whitehorn 
33154423402SNathan Whitehorn static void
33254423402SNathan Whitehorn atpic_ofw_translate_code(device_t dev, u_int irq, int code,
33354423402SNathan Whitehorn     enum intr_trigger *trig, enum intr_polarity *pol)
33454423402SNathan Whitehorn {
33554423402SNathan Whitehorn 	switch (code) {
33654423402SNathan Whitehorn 	case 0:
33754423402SNathan Whitehorn 		/* Active L level */
33854423402SNathan Whitehorn 		*trig = INTR_TRIGGER_LEVEL;
33954423402SNathan Whitehorn 		*pol = INTR_POLARITY_LOW;
34054423402SNathan Whitehorn 		break;
34154423402SNathan Whitehorn 	case 1:
34254423402SNathan Whitehorn 		/* Active H level */
34354423402SNathan Whitehorn 		*trig = INTR_TRIGGER_LEVEL;
34454423402SNathan Whitehorn 		*pol = INTR_POLARITY_HIGH;
34554423402SNathan Whitehorn 		break;
34654423402SNathan Whitehorn 	case 2:
34754423402SNathan Whitehorn 		/* H to L edge */
34854423402SNathan Whitehorn 		*trig = INTR_TRIGGER_EDGE;
34954423402SNathan Whitehorn 		*pol = INTR_POLARITY_LOW;
35054423402SNathan Whitehorn 		break;
35154423402SNathan Whitehorn 	case 3:
35254423402SNathan Whitehorn 		/* L to H edge */
35354423402SNathan Whitehorn 		*trig = INTR_TRIGGER_EDGE;
35454423402SNathan Whitehorn 		*pol = INTR_POLARITY_HIGH;
35554423402SNathan Whitehorn 		break;
35654423402SNathan Whitehorn 	default:
35754423402SNathan Whitehorn 		*trig = INTR_TRIGGER_CONFORM;
35854423402SNathan Whitehorn 		*pol = INTR_POLARITY_CONFORM;
35954423402SNathan Whitehorn 	}
36054423402SNathan Whitehorn }
361