The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/i386/isa/elcr.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    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  * 3. Neither the name of the author nor the names of any co-contributors
   14  *    may be used to endorse or promote products derived from this software
   15  *    without specific prior written permission.
   16  *
   17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   27  * SUCH DAMAGE.
   28  */
   29 
   30 #include <sys/cdefs.h>
   31 __FBSDID("$FreeBSD: releng/5.3/sys/i386/isa/elcr.c 128928 2004-05-04 20:07:46Z jhb $");
   32 
   33 /*
   34  * The ELCR is a register that controls the trigger mode and polarity of
   35  * EISA and ISA interrupts.  In FreeBSD 3.x and 4.x, the ELCR was only
   36  * consulted for determining the appropriate trigger mode of EISA
   37  * interrupts when using an APIC.  However, it seems that almost all
   38  * systems that include PCI also include an ELCR that manages the ISA
   39  * IRQs 0 through 15.  Thus, we check for the presence of an ELCR on
   40  * every machine by checking to see if the values found at bootup are
   41  * sane.  Note that the polarity of ISA and EISA IRQs are linked to the
   42  * trigger mode.  All edge triggered IRQs use active-hi polarity, and
   43  * all level triggered interrupts use active-lo polarity.
   44  *
   45  * The format of the ELCR is simple: it is a 16-bit bitmap where bit 0
   46  * controls IRQ 0, bit 1 controls IRQ 1, etc.  If the bit is zero, the
   47  * associated IRQ is edge triggered.  If the bit is one, the IRQ is
   48  * level triggered.
   49  */
   50 
   51 #include <sys/param.h>
   52 #include <sys/bus.h>
   53 #include <sys/systm.h>
   54 #include <machine/intr_machdep.h>
   55 
   56 #define ELCR_PORT       0x4d0
   57 #define ELCR_MASK(irq)  (1 << (irq))
   58 
   59 static int elcr_status;
   60 #ifdef INVARIANTS
   61 static int elcr_found;
   62 #endif
   63 
   64 /*
   65  * Check to see if we have what looks like a valid ELCR.  We do this by
   66  * verifying that IRQs 0, 1, 2, and 13 are all edge triggered.
   67  */
   68 int
   69 elcr_probe(void)
   70 {
   71         int i;
   72 
   73         elcr_status = inb(ELCR_PORT) | inb(ELCR_PORT + 1) << 8;
   74         if ((elcr_status & (ELCR_MASK(0) | ELCR_MASK(1) | ELCR_MASK(2) |
   75             ELCR_MASK(8) | ELCR_MASK(13))) != 0)
   76                 return (ENXIO);
   77         if (bootverbose) {
   78                 printf("ELCR Found.  ISA IRQs programmed as:\n");
   79                 for (i = 0; i < 16; i++)
   80                         printf(" %2d", i);
   81                 printf("\n");
   82                 for (i = 0; i < 16; i++)
   83                         if (elcr_status & ELCR_MASK(i))
   84                                 printf("  L");
   85                         else
   86                                 printf("  E");
   87                 printf("\n");
   88         }
   89         if (resource_disabled("elcr", 0))
   90                 return (ENXIO);
   91 #ifdef INVARIANTS
   92         elcr_found = 1;
   93 #endif
   94         return (0);
   95 }
   96 
   97 /*
   98  * Returns 1 for level trigger, 0 for edge.
   99  */
  100 enum intr_trigger
  101 elcr_read_trigger(u_int irq)
  102 {
  103 
  104         KASSERT(elcr_found, ("%s: no ELCR was found!", __func__));
  105         KASSERT(irq <= 15, ("%s: invalid IRQ %u", __func__, irq));
  106         if (elcr_status & ELCR_MASK(irq))
  107                 return (INTR_TRIGGER_LEVEL);
  108         else
  109                 return (INTR_TRIGGER_EDGE);
  110 }
  111 
  112 /*
  113  * Set the trigger mode for a specified IRQ.  Mode of 0 means edge triggered,
  114  * and a mode of 1 means level triggered.
  115  */
  116 void
  117 elcr_write_trigger(u_int irq, enum intr_trigger trigger)
  118 {
  119         int new_status;
  120 
  121         KASSERT(elcr_found, ("%s: no ELCR was found!", __func__));
  122         KASSERT(irq <= 15, ("%s: invalid IRQ %u", __func__, irq));
  123         if (trigger == INTR_TRIGGER_LEVEL)
  124                 new_status = elcr_status | ELCR_MASK(irq);
  125         else
  126                 new_status = elcr_status & ~ELCR_MASK(irq);
  127         if (new_status == elcr_status)
  128                 return;
  129         elcr_status = new_status;
  130         if (irq >= 8)
  131                 outb(ELCR_PORT + 1, elcr_status >> 8);
  132         else
  133                 outb(ELCR_PORT, elcr_status & 0xff);
  134 }
  135 
  136 void
  137 elcr_resume(void)
  138 {
  139 
  140         KASSERT(elcr_found, ("%s: no ELCR was found!", __func__));
  141         outb(ELCR_PORT, elcr_status & 0xff);
  142         outb(ELCR_PORT + 1, elcr_status >> 8);
  143 }

Cache object: 5ad362a4a372737282a4f5640b05f389


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.