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.


*** empty log 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.3 $
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 #include <geekos/debug.h>
16
17 /* ----------------------------------------------------------------------
18  * Private functions and data
19  * ---------------------------------------------------------------------- */
20
21 /*
22  * Current IRQ mask.
23  * This should be kept up to date with setup.asm
24  * (which does the initial programming of the PICs).
25  */
26 static ushort_t s_irqMask = 0xfffb;
27
28 /*
29  * Get the master and slave parts of an IRQ mask.
30  */
31 #define MASTER(mask) ((mask) & 0xff)
32 #define SLAVE(mask) (((mask)>>8) & 0xff)
33
34
35 /* ----------------------------------------------------------------------
36  * Public functions
37  * ---------------------------------------------------------------------- */
38
39 /*
40  * Install a handler for given IRQ.
41  * Note that we don't unmask the IRQ.
42  */
43 void Install_IRQ(int irq, Interrupt_Handler handler)
44 {
45     Install_Interrupt_Handler(irq + FIRST_EXTERNAL_INT, handler);
46 }
47
48 /*
49  * Get current IRQ mask.  Each bit position represents
50  * one of the 16 IRQ lines.
51  */
52 ushort_t Get_IRQ_Mask(void)
53 {
54     return s_irqMask;
55 }
56
57 /*
58  * Set the IRQ mask.
59  */
60 void Set_IRQ_Mask(ushort_t mask)
61 {
62     uchar_t oldMask, newMask;
63
64     oldMask = MASTER(s_irqMask);
65     newMask = MASTER(mask);
66     if (newMask != oldMask) {
67         Out_Byte(0x21, newMask);
68     }
69
70     oldMask = SLAVE(s_irqMask);
71     newMask = SLAVE(mask);
72     if (newMask != oldMask) {
73         Out_Byte(0xA1, newMask);
74     }
75
76     s_irqMask = mask;
77 }
78
79 /*
80  * Enable given IRQ.
81  */
82 void Enable_IRQ(int irq)
83 {
84     bool iflag = Begin_Int_Atomic();
85
86     KASSERT(irq >= 0 && irq < 16);
87     ushort_t mask = Get_IRQ_Mask();
88     mask &= ~(1 << irq);
89     Set_IRQ_Mask(mask);
90
91     End_Int_Atomic(iflag);
92 }
93
94 /*
95  * Disable given IRQ.
96  */
97 void Disable_IRQ(int irq)
98 {
99     bool iflag = Begin_Int_Atomic();
100
101     KASSERT(irq >= 0 && irq < 16);
102     ushort_t mask = Get_IRQ_Mask();
103     mask |= (1 << irq);
104     Set_IRQ_Mask(mask);
105
106     End_Int_Atomic(iflag);
107 }
108
109 /*
110  * Called by an IRQ handler to begin the interrupt.
111  * Currently a no-op.
112  */
113 void Begin_IRQ(struct Interrupt_State* state)
114 {
115   
116 }
117
118 /*
119  * Called by an IRQ handler to end the interrupt.
120  * Sends an EOI command to the appropriate PIC(s).
121  */
122 void End_IRQ(struct Interrupt_State* state)
123 {
124     int irq = state->intNum - FIRST_EXTERNAL_INT;
125     End_IRQ_num(irq);
126 }
127
128
129 void End_IRQ_num(int irq) {
130     uchar_t command = 0x60 | (irq & 0x7);
131
132     if (irq < 8) {
133         /* Specific EOI to master PIC */
134         Out_Byte(0x20, command);
135     }
136     else {
137         /* Specific EOI to slave PIC, then to master (cascade line) */
138         Out_Byte(0xA0, command);
139         Out_Byte(0x20, 0x62);
140     }
141 }