source: rtems/c/src/lib/libbsp/i386/shared/irq/elcr.c @ 93fb8797

Last change on this file since 93fb8797 was 93fb8797, checked in by Chris Johns <chrisj@…>, on May 6, 2016 at 7:55:29 AM

i386/pc386: Fix interrupt support.

Fix the interrupt and stop the spurious interrupt from happening.

The fix moves the EOI to C code and cleans that functionality out
of the asm part of the ISR handler.

The code checks the ISR and IRR registers on the enable.

Only ack the master for a slave IRQ if the slave has no other pending
requests.

  • Property mode set to 100644
File size: 4.9 KB
Line 
1/*-
2 * Copyright (c) 2004 John Baldwin <jhb@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28#ifndef __rtems__
29__FBSDID("$FreeBSD$");
30#endif /* __rtems__ */
31
32/*
33 * The ELCR is a register that controls the trigger mode and polarity of
34 * EISA and ISA interrupts.  In FreeBSD 3.x and 4.x, the ELCR was only
35 * consulted for determining the appropriate trigger mode of EISA
36 * interrupts when using an APIC.  However, it seems that almost all
37 * systems that include PCI also include an ELCR that manages the ISA
38 * IRQs 0 through 15.  Thus, we check for the presence of an ELCR on
39 * every machine by checking to see if the values found at bootup are
40 * sane.  Note that the polarity of ISA and EISA IRQs are linked to the
41 * trigger mode.  All edge triggered IRQs use active-hi polarity, and
42 * all level triggered interrupts use active-lo polarity.
43 *
44 * The format of the ELCR is simple: it is a 16-bit bitmap where bit 0
45 * controls IRQ 0, bit 1 controls IRQ 1, etc.  If the bit is zero, the
46 * associated IRQ is edge triggered.  If the bit is one, the IRQ is
47 * level triggered.
48 */
49
50#ifndef __rtems__
51#include <sys/param.h>
52#include <sys/bus.h>
53#include <sys/systm.h>
54#include <machine/intr_machdep.h>
55#endif /* __rtems__ */
56
57#ifdef __rtems__
58#include <bsp.h>
59#include "i386_io.h"
60#include <errno.h>
61#include "elcr.h"
62#endif /* __rtems__ */
63
64#define ELCR_PORT       0x4d0
65#define ELCR_MASK(irq)  (1 << (irq))
66
67static int elcr_status;
68#ifdef __rtems__
69static
70#endif /* __rtems__ */
71int elcr_found;
72
73#ifdef __rtems__
74#undef printf
75#define printf printk
76#define bootverbose 1
77#define KASSERT(...)
78#endif /* __rtems__ */
79
80/*
81 * Check to see if we have what looks like a valid ELCR.  We do this by
82 * verifying that IRQs 0, 1, 2, and 13 are all edge triggered.
83 */
84int
85elcr_probe(void)
86{
87        int i;
88
89        elcr_status = inb(ELCR_PORT) | inb(ELCR_PORT + 1) << 8;
90        if ((elcr_status & (ELCR_MASK(0) | ELCR_MASK(1) | ELCR_MASK(2) |
91            ELCR_MASK(8) | ELCR_MASK(13))) != 0)
92                return (ENXIO);
93        if (bootverbose) {
94                printf("ELCR Found.  ISA IRQs programmed as:\n");
95                for (i = 0; i < 16; i++)
96                        printf(" %2d", i);
97                printf("\n");
98                for (i = 0; i < 16; i++)
99                        if (elcr_status & ELCR_MASK(i))
100                                printf("  L");
101                        else
102                                printf("  E");
103                printf("\n");
104        }
105#ifndef __rtems__
106        if (resource_disabled("elcr", 0))
107                return (ENXIO);
108#endif /* __rtems__ */
109        elcr_found = 1;
110        return (0);
111}
112
113/*
114 * Returns 1 for level trigger, 0 for edge.
115 */
116enum intr_trigger
117elcr_read_trigger(u_int irq)
118{
119#ifdef __rtems__
120        if (!elcr_found)
121                return INTR_TRIGGER_EDGE;
122#endif /* __rtems__ */
123        KASSERT(elcr_found, ("%s: no ELCR was found!", __func__));
124        KASSERT(irq <= 15, ("%s: invalid IRQ %u", __func__, irq));
125        if (elcr_status & ELCR_MASK(irq))
126                return (INTR_TRIGGER_LEVEL);
127        else
128                return (INTR_TRIGGER_EDGE);
129}
130
131/*
132 * Set the trigger mode for a specified IRQ.  Mode of 0 means edge triggered,
133 * and a mode of 1 means level triggered.
134 */
135void
136elcr_write_trigger(u_int irq, enum intr_trigger trigger)
137{
138        int new_status;
139
140#ifdef __rtems__
141        if (!elcr_found)
142                return;
143#endif /* __rtems__ */
144        KASSERT(elcr_found, ("%s: no ELCR was found!", __func__));
145        KASSERT(irq <= 15, ("%s: invalid IRQ %u", __func__, irq));
146        if (trigger == INTR_TRIGGER_LEVEL)
147                new_status = elcr_status | ELCR_MASK(irq);
148        else
149                new_status = elcr_status & ~ELCR_MASK(irq);
150        if (new_status == elcr_status)
151                return;
152        elcr_status = new_status;
153        if (irq >= 8)
154                outb(ELCR_PORT + 1, elcr_status >> 8);
155        else
156                outb(ELCR_PORT, elcr_status & 0xff);
157}
158
159void
160elcr_resume(void)
161{
162#ifdef __rtems__
163        if (!elcr_found)
164                return;
165#endif /* __rtems__ */
166
167        KASSERT(elcr_found, ("%s: no ELCR was found!", __func__));
168        outb(ELCR_PORT, elcr_status & 0xff);
169        outb(ELCR_PORT + 1, elcr_status >> 8);
170}
Note: See TracBrowser for help on using the repository browser.