Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


(no commit message)
[palacios.git] / palacios / src / geekos / irq.c
1 /*
2  * This is the device-driver interface to the interrupt system.
3  * Copyright (c) 2001,2003 David H. Hovemeyer <daveho@cs.umd.edu>
4  * $Revision: 1.1.1.1 $
5  * 
6  * This is free software.  You are permitted to use,
7  * redistribute, and modify it as specified in the file "COPYING".
8  */
9
10 #include <geekos/kassert.h>
11 #include <geekos/idt.h>
12 #include <geekos/io.h>
13 #include <geekos/irq.h>
14
15 /* ----------------------------------------------------------------------
16  * Private functions and data
17  * ---------------------------------------------------------------------- */
18
19 /*
20  * Current IRQ mask.
21  * This should be kept up to date with setup.asm
22  * (which does the initial programming of the PICs).
23  */
24 static ushort_t s_irqMask = 0xfffb;
25
26 /*
27  * Get the master and slave parts of an IRQ mask.
28  */
29 #define MASTER(mask) ((mask) & 0xff)
30 #define SLAVE(mask) (((mask)>>8) & 0xff)
31
32
33 /* ----------------------------------------------------------------------
34  * Public functions
35  * ---------------------------------------------------------------------- */
36
37 /*
38  * Install a handler for given IRQ.
39  * Note that we don't unmask the IRQ.
40  */
41 void Install_IRQ(int irq, Interrupt_Handler handler)
42 {
43     Install_Interrupt_Handler(irq + FIRST_EXTERNAL_INT, handler);
44 }
45
46 /*
47  * Get current IRQ mask.  Each bit position represents
48  * one of the 16 IRQ lines.
49  */
50 ushort_t Get_IRQ_Mask(void)
51 {
52     return s_irqMask;
53 }
54
55 /*
56  * Set the IRQ mask.
57  */
58 void Set_IRQ_Mask(ushort_t mask)
59 {
60     uchar_t oldMask, newMask;
61
62     oldMask = MASTER(s_irqMask);
63     newMask = MASTER(mask);
64     if (newMask != oldMask) {
65         Out_Byte(0x21, newMask);
66     }
67
68     oldMask = SLAVE(s_irqMask);
69     newMask = SLAVE(mask);
70     if (newMask != oldMask) {
71         Out_Byte(0xA1, newMask);
72     }
73
74     s_irqMask = mask;
75 }
76
77 /*
78  * Enable given IRQ.
79  */
80 void Enable_IRQ(int irq)
81 {
82     bool iflag = Begin_Int_Atomic();
83
84     KASSERT(irq >= 0 && irq < 16);
85     ushort_t mask = Get_IRQ_Mask();
86     mask &= ~(1 << irq);
87     Set_IRQ_Mask(mask);
88
89     End_Int_Atomic(iflag);
90 }
91
92 /*
93  * Disable given IRQ.
94  */
95 void Disable_IRQ(int irq)
96 {
97     bool iflag = Begin_Int_Atomic();
98
99     KASSERT(irq >= 0 && irq < 16);
100     ushort_t mask = Get_IRQ_Mask();
101     mask |= (1 << irq);
102     Set_IRQ_Mask(mask);
103
104     End_Int_Atomic(iflag);
105 }
106
107 /*
108  * Called by an IRQ handler to begin the interrupt.
109  * Currently a no-op.
110  */
111 void Begin_IRQ(struct Interrupt_State* state)
112 {
113 }
114
115 /*
116  * Called by an IRQ handler to end the interrupt.
117  * Sends an EOI command to the appropriate PIC(s).
118  */
119 void End_IRQ(struct Interrupt_State* state)
120 {
121     int irq = state->intNum - FIRST_EXTERNAL_INT;
122     uchar_t command = 0x60 | (irq & 0x7);
123
124     if (irq < 8) {
125         /* Specific EOI to master PIC */
126         Out_Byte(0x20, command);
127     }
128     else {
129         /* Specific EOI to slave PIC, then to master (cascade line) */
130         Out_Byte(0xA0, command);
131         Out_Byte(0x20, 0x62);
132     }
133 }