| 1 |
/* |
| 2 |
* Copyright (c) 1995 Shantanu Goel |
| 3 |
* All Rights Reserved. |
| 4 |
* |
| 5 |
* Permission to use, copy, modify and distribute this software and its |
| 6 |
* documentation is hereby granted, provided that both the copyright |
| 7 |
* notice and this permission notice appear in all copies of the |
| 8 |
* software, derivative works or modified versions, and any portions |
| 9 |
* thereof, and that both notices appear in supporting documentation. |
| 10 |
* |
| 11 |
* THE AUTHOR ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" |
| 12 |
* CONDITION. THE AUTHOR DISCLAIMS ANY LIABILITY OF ANY KIND FOR |
| 13 |
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. |
| 14 |
*/ |
| 15 |
|
| 16 |
#include <mach/machine/asm.h> |
| 17 |
|
| 18 |
#include <i386/ipl.h> |
| 19 |
#ifdef APIC |
| 20 |
# include <i386/apic.h> |
| 21 |
#else |
| 22 |
# include <i386/pic.h> |
| 23 |
#endif |
| 24 |
#include <i386/i386asm.h> |
| 25 |
|
| 26 |
#define READ_ISR (OCW_TEMPLATE|READ_NEXT_RD|READ_IS_ONRD) |
| 27 |
|
| 28 |
/* |
| 29 |
* Generic interrupt handler. |
| 30 |
* |
| 31 |
* On entry, %eax contains the irq number. |
| 32 |
* |
| 33 |
* Note: kdb_kintr needs to know our stack usage |
| 34 |
*/ |
| 35 |
|
| 36 |
#define S_REGS 28(%esp) |
| 37 |
#define S_RET 24(%esp) |
| 38 |
#define S_IRQ 20(%esp) |
| 39 |
#define S_IPL 16(%esp) |
| 40 |
|
| 41 |
ENTRY(interrupt) |
| 42 |
#ifdef APIC |
| 43 |
cmpl $255,%eax /* was this a spurious intr? */ |
| 44 |
jne 1f |
| 45 |
ret /* if so, just return */ |
| 46 |
1: |
| 47 |
#endif |
| 48 |
subl $24,%esp /* Two local variables + 4 parameters */ |
| 49 |
movl %eax,S_IRQ /* save irq number */ |
| 50 |
|
| 51 |
call spl7 /* set ipl */ |
| 52 |
movl %eax,S_IPL /* save previous ipl */ |
| 53 |
|
| 54 |
movl S_IRQ,%ecx /* restore irq number */ |
| 55 |
|
| 56 |
#if NCPUS > 1 |
| 57 |
cmpl $CALL_PMAP_UPDATE,%ecx /* was this a SMP pmap_update request? */ |
| 58 |
je _call_single |
| 59 |
|
| 60 |
cmpl $CALL_AST_CHECK,%ecx /* was this a SMP remote -> local ast request? */ |
| 61 |
je _call_local_ast |
| 62 |
#endif |
| 63 |
|
| 64 |
movb EXT(irqinfo)(,%ecx,2),%al /* look up irq_info[irq].trigger */ |
| 65 |
testb $1,%al /* was this a level triggered interrupt? */ |
| 66 |
jnz _call_handler /* yes: handle before eoi */ |
| 67 |
|
| 68 |
_eoi: |
| 69 |
#ifndef APIC |
| 70 |
movl $1,%eax |
| 71 |
shll %cl,%eax /* get corresponding IRQ mask */ |
| 72 |
orl EXT(curr_pic_mask),%eax /* add current mask */ |
| 73 |
|
| 74 |
cmpl $8,%ecx /* do we need to ack slave? */ |
| 75 |
jl 1f /* no, only master */ |
| 76 |
|
| 77 |
/* EOI on slave */ |
| 78 |
movb %ah,%al |
| 79 |
outb %al,$(PIC_SLAVE_OCW) /* mask slave out */ |
| 80 |
|
| 81 |
movb $(SPECIFIC_EOI),%al /* specific EOI for this irq */ |
| 82 |
andb $7,%cl /* irq number for the slave */ |
| 83 |
orb %cl,%al /* combine them */ |
| 84 |
outb %al,$(PIC_SLAVE_ICW) /* ack interrupt to slave */ |
| 85 |
|
| 86 |
movb $(SPECIFIC_EOI + I_AM_SLAVE_2),%al /* specific master EOI for cascaded slave */ |
| 87 |
outb %al,$(PIC_MASTER_ICW) /* ack interrupt to master */ |
| 88 |
|
| 89 |
movl EXT(curr_pic_mask),%eax /* restore original mask */ |
| 90 |
movb %ah,%al |
| 91 |
outb %al,$(PIC_SLAVE_OCW) /* unmask slave */ |
| 92 |
jmp 2f |
| 93 |
|
| 94 |
1: |
| 95 |
/* EOI on master */ |
| 96 |
outb %al,$(PIC_MASTER_OCW) /* mask master out */ |
| 97 |
|
| 98 |
movb $(SPECIFIC_EOI),%al /* specific EOI for this irq */ |
| 99 |
orb %cl,%al /* combine with irq number */ |
| 100 |
outb %al,$(PIC_MASTER_ICW) /* ack interrupt to master */ |
| 101 |
|
| 102 |
movl EXT(curr_pic_mask),%eax /* restore original mask */ |
| 103 |
outb %al,$(PIC_MASTER_OCW) /* unmask master */ |
| 104 |
2: |
| 105 |
#else |
| 106 |
movl %ecx,(%esp) /* load irq number as 1st arg */ |
| 107 |
call EXT(ioapic_irq_eoi) /* ioapic irq specific EOI */ |
| 108 |
#endif |
| 109 |
|
| 110 |
movl S_IRQ,%ecx /* restore irq number */ |
| 111 |
movb EXT(irqinfo)(,%ecx,2),%al /* look up irq_info[irq].trigger */ |
| 112 |
testb $1,%al /* was this a level triggered interrupt? */ |
| 113 |
jnz _completed /* yes: we are done */ |
| 114 |
|
| 115 |
_call_handler: |
| 116 |
movl S_IPL,%eax |
| 117 |
movl %eax,4(%esp) /* previous ipl as 2nd arg */ |
| 118 |
|
| 119 |
movl S_RET,%eax |
| 120 |
movl %eax,8(%esp) /* return address as 3rd arg */ |
| 121 |
|
| 122 |
movl S_REGS,%eax |
| 123 |
movl %eax,12(%esp) /* address of interrupted registers as 4th arg */ |
| 124 |
|
| 125 |
movl S_IRQ,%eax /* copy irq number */ |
| 126 |
|
| 127 |
movl EXT(iunit)(,%eax,4),%edx /* get device unit number */ |
| 128 |
movl %edx,(%esp) /* unit number as 1st arg */ |
| 129 |
|
| 130 |
call *EXT(ivect)(,%eax,4) /* call interrupt handler */ |
| 131 |
|
| 132 |
movl S_IRQ,%ecx /* restore irq number */ |
| 133 |
movb EXT(irqinfo)(,%ecx,2),%al /* look up irq_info[irq].trigger */ |
| 134 |
testb $1,%al /* was this a level triggered interrupt? */ |
| 135 |
jnz _eoi /* yes: eoi */ |
| 136 |
|
| 137 |
_completed: |
| 138 |
movl S_IPL,%eax /* restore previous ipl */ |
| 139 |
movl %eax,(%esp) |
| 140 |
call splx_cli /* restore previous ipl */ |
| 141 |
|
| 142 |
addl $24,%esp /* pop local variables */ |
| 143 |
ret |
| 144 |
|
| 145 |
#if NCPUS > 1 |
| 146 |
_call_single: |
| 147 |
call EXT(lapic_eoi) /* lapic EOI before the handler to allow extra update */ |
| 148 |
call EXT(pmap_update_interrupt) |
| 149 |
jmp _completed |
| 150 |
|
| 151 |
_call_local_ast: |
| 152 |
call EXT(lapic_eoi) /* lapic EOI */ |
| 153 |
call EXT(ast_check) /* AST check on this cpu */ |
| 154 |
jmp _completed |
| 155 |
|
| 156 |
#endif |
| 157 |
END(interrupt) |