]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - arch/x86/lib/pcat_interrupts.c
x86: qemu: Support operation as an EFI payload
[karo-tx-uboot.git] / arch / x86 / lib / pcat_interrupts.c
index 364c4358378cc3153777f4b2910f3a033f32bdad..a9af87e4ce418f64b26b7b20f54fd9e62fccd851 100644 (file)
@@ -3,25 +3,9 @@
  * Graeme Russ, <graeme.russ@gmail.com>
  *
  * (C) Copyright 2002
- * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
+ * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
  *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 /*
 #error "CONFIG_SYS_NUM_IRQS must equal 16 if CONFIG_SYS_NUM_IRQS is defined"
 #endif
 
-int interrupt_init(void)
+int i8259_init(void)
 {
        u8 i;
 
-       disable_interrupts();
-
        /* Mask all interrupts */
        outb(0xff, MASTER_PIC + IMR);
        outb(0xff, SLAVE_PIC + IMR);
@@ -76,9 +58,10 @@ int interrupt_init(void)
         * Enable cascaded interrupts by unmasking the cascade IRQ pin of
         * the master PIC
         */
-       unmask_irq (2);
+       unmask_irq(2);
 
-       enable_interrupts();
+       /* Interrupt 9 should be level triggered (SCI). The OS might do this */
+       configure_irq_trigger(9, true);
 
        return 0;
 }
@@ -130,3 +113,38 @@ void specific_eoi(int irq)
 
        outb(OCW2_SEOI | irq, MASTER_PIC + OCW2);
 }
+
+#define ELCR1                  0x4d0
+#define ELCR2                  0x4d1
+
+void configure_irq_trigger(int int_num, bool is_level_triggered)
+{
+       u16 int_bits = inb(ELCR1) | (((u16)inb(ELCR2)) << 8);
+
+       debug("%s: current interrupts are 0x%x\n", __func__, int_bits);
+       if (is_level_triggered)
+               int_bits |= (1 << int_num);
+       else
+               int_bits &= ~(1 << int_num);
+
+       /* Write new values */
+       debug("%s: try to set interrupts 0x%x\n", __func__, int_bits);
+       outb((u8)(int_bits & 0xff), ELCR1);
+       outb((u8)(int_bits >> 8), ELCR2);
+
+#ifdef PARANOID_IRQ_TRIGGERS
+       /*
+        * Try reading back the new values. This seems like an error but is
+        * not
+        */
+       if (inb(ELCR1) != (int_bits & 0xff)) {
+               printf("%s: lower order bits are wrong: want 0x%x, got 0x%x\n",
+                      __func__, (int_bits & 0xff), inb(ELCR1));
+       }
+
+       if (inb(ELCR2) != (int_bits >> 8)) {
+               printf("%s: higher order bits are wrong: want 0x%x, got 0x%x\n",
+                      __func__, (int_bits>>8), inb(ELCR2));
+       }
+#endif
+}