#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <mips/cpuregs.h>
#include <evbmips/loongson/autoconf.h>
#include <machine/intr.h>
#include <dev/ic/i8259reg.h>
#include <dev/pci/pcivar.h>
#include <dev/isa/isareg.h>
#include <dev/isa/isavar.h>
#include <mips/bonito/bonitoreg.h>
#include <mips/bonito/bonitovar.h>
#include <evbmips/loongson/loongson_isa.h>
uint loongson_isaimr;
void
loongson_set_isa_imr(uint newimr)
{
uint imr1, imr2;
imr1 = 0xff & ~newimr;
imr1 &= ~(1 << 2);
imr2 = 0xff & ~(newimr >> 8);
REGVAL8(BONITO_PCIIO_BASE + IO_ICU2 + 1) = imr2;
REGVAL8(BONITO_PCIIO_BASE + IO_ICU1 + 1) = imr1;
__asm__ __volatile__ ("sync" ::: "memory");
loongson_isaimr = newimr;
}
void
loongson_isa_specific_eoi(int bit)
{
KASSERT((bit < 16) && (bit >= 0));
loongson_isaimr &= ~(1 << bit);
if (bit & 8) {
(void)REGVAL8(BONITO_PCIIO_BASE + IO_ICU2 + 1);
REGVAL8(BONITO_PCIIO_BASE + IO_ICU2 + 1) =
(0xff & ~(loongson_isaimr >> 8));
__asm__ __volatile__ ("sync" ::: "memory");
REGVAL8(BONITO_PCIIO_BASE + IO_ICU2 + PIC_OCW2) =
OCW2_SELECT | OCW2_EOI | OCW2_SL | OCW2_ILS(bit & 7);
bit = 2;
__asm__ __volatile__ ("sync" ::: "memory");
}
(void)REGVAL8(BONITO_PCIIO_BASE + IO_ICU1 + 1);
REGVAL8(BONITO_PCIIO_BASE + IO_ICU1 + 1) =
(0xff & ~(loongson_isaimr));
__asm__ __volatile__ ("sync" ::: "memory");
REGVAL8(BONITO_PCIIO_BASE + IO_ICU1 + PIC_OCW2) =
OCW2_SELECT | OCW2_EOI | OCW2_SL | OCW2_ILS(bit);
__asm__ __volatile__ ("sync" ::: "memory");
}