Rev 1956 | Rev 2071 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1956 | Rev 1957 | ||
---|---|---|---|
Line 86... | Line 86... | ||
86 | .resume = i8042_resume, |
86 | .resume = i8042_resume, |
87 | .read = i8042_key_read |
87 | .read = i8042_key_read |
88 | }; |
88 | }; |
89 | 89 | ||
90 | /** Structure for i8042's IRQ. */ |
90 | /** Structure for i8042's IRQ. */ |
91 | static irq_t i8042_irq; |
91 | static irq_t i8042_kbd_irq; |
- | 92 | static irq_t i8042_mouse_irq; |
|
92 | 93 | ||
93 | /** Wait until the controller reads its data. */ |
94 | /** Wait until the controller reads its data. */ |
94 | static void i8042_wait(void) { |
95 | static void i8042_wait(void) { |
95 | while (i8042_status_read() & i8042_WAIT_MASK) { |
96 | while (i8042_status_read() & i8042_WAIT_MASK) { |
96 | /* wait */ |
97 | /* wait */ |
Line 105... | Line 106... | ||
105 | i8042_command_write(i8042_SET_COMMAND); |
106 | i8042_command_write(i8042_SET_COMMAND); |
106 | i8042_wait(); |
107 | i8042_wait(); |
107 | i8042_data_write(i8042_COMMAND); |
108 | i8042_data_write(i8042_COMMAND); |
108 | i8042_wait(); |
109 | i8042_wait(); |
109 | 110 | ||
110 | spinlock_lock(&i8042_irq.lock); |
111 | spinlock_lock(&i8042_kbd_irq.lock); |
111 | i8042_irq.notif_cfg.notify = false; |
112 | i8042_kbd_irq.notif_cfg.notify = false; |
112 | spinlock_unlock(&i8042_irq.lock); |
113 | spinlock_unlock(&i8042_kbd_irq.lock); |
- | 114 | ||
- | 115 | spinlock_lock(&i8042_mouse_irq.lock); |
|
- | 116 | i8042_mouse_irq.notif_cfg.notify = false; |
|
- | 117 | spinlock_unlock(&i8042_mouse_irq.lock); |
|
- | 118 | ||
113 | interrupts_restore(ipl); |
119 | interrupts_restore(ipl); |
114 | } |
120 | } |
115 | 121 | ||
116 | void i8042_release(void) |
122 | void i8042_release(void) |
117 | { |
123 | { |
118 | ipl_t ipl = interrupts_disable(); |
124 | ipl_t ipl = interrupts_disable(); |
- | 125 | ||
119 | spinlock_lock(&i8042_irq.lock); |
126 | spinlock_lock(&i8042_kbd_irq.lock); |
120 | if (i8042_irq.notif_cfg.answerbox) |
127 | if (i8042_kbd_irq.notif_cfg.answerbox) |
121 | i8042_irq.notif_cfg.notify = true; |
128 | i8042_kbd_irq.notif_cfg.notify = true; |
122 | spinlock_unlock(&i8042_irq.lock); |
129 | spinlock_unlock(&i8042_kbd_irq.lock); |
- | 130 | ||
- | 131 | spinlock_lock(&i8042_mouse_irq.lock); |
|
- | 132 | if (i8042_mouse_irq.notif_cfg.answerbox) |
|
- | 133 | i8042_mouse_irq.notif_cfg.notify = true; |
|
- | 134 | spinlock_unlock(&i8042_mouse_irq.lock); |
|
- | 135 | ||
123 | interrupts_restore(ipl); |
136 | interrupts_restore(ipl); |
124 | } |
137 | } |
125 | 138 | ||
126 | static irq_ownership_t i8042_claim(void) |
139 | static irq_ownership_t i8042_claim(void) |
127 | { |
140 | { |
128 | return IRQ_ACCEPT; |
141 | return IRQ_ACCEPT; |
129 | } |
142 | } |
130 | 143 | ||
131 | static void i8042_irq_handler(irq_t *irq, void *arg, ...) |
144 | static void i8042_kbd_irq_handler(irq_t *irq, void *arg, ...) |
132 | { |
145 | { |
133 | if (irq->notif_cfg.notify && irq->notif_cfg.answerbox) |
146 | if (irq->notif_cfg.notify && irq->notif_cfg.answerbox) |
134 | ipc_irq_send_notif(irq); |
147 | ipc_irq_send_notif(irq); |
135 | else { |
148 | else { |
136 | uint8_t x; |
149 | uint8_t x; |
Line 148... | Line 161... | ||
148 | key_pressed(x); |
161 | key_pressed(x); |
149 | } |
162 | } |
150 | } |
163 | } |
151 | } |
164 | } |
152 | 165 | ||
- | 166 | static void i8042_mouse_irq_handler(irq_t *irq, void *arg, ...) |
|
- | 167 | { |
|
- | 168 | if (irq->notif_cfg.notify && irq->notif_cfg.answerbox) |
|
- | 169 | ipc_irq_send_notif(irq); |
|
- | 170 | } |
|
- | 171 | ||
153 | /** Initialize i8042. */ |
172 | /** Initialize i8042. */ |
154 | void i8042_init(devno_t devno, inr_t inr) |
173 | void i8042_init(devno_t kbd_devno, inr_t kbd_inr, devno_t mouse_devno, inr_t mouse_inr) |
155 | { |
174 | { |
156 | chardev_initialize("i8042_kbd", &kbrd, &ops); |
175 | chardev_initialize("i8042_kbd", &kbrd, &ops); |
157 | stdin = &kbrd; |
176 | stdin = &kbrd; |
158 | 177 | ||
159 | irq_initialize(&i8042_irq); |
178 | irq_initialize(&i8042_kbd_irq); |
160 | i8042_irq.devno = devno; |
179 | i8042_kbd_irq.devno = kbd_devno; |
161 | i8042_irq.inr = inr; |
180 | i8042_kbd_irq.inr = kbd_inr; |
162 | i8042_irq.claim = i8042_claim; |
181 | i8042_kbd_irq.claim = i8042_claim; |
163 | i8042_irq.handler = i8042_irq_handler; |
182 | i8042_kbd_irq.handler = i8042_kbd_irq_handler; |
164 | irq_register(&i8042_irq); |
183 | irq_register(&i8042_kbd_irq); |
- | 184 | ||
- | 185 | irq_initialize(&i8042_mouse_irq); |
|
- | 186 | i8042_mouse_irq.devno = mouse_devno; |
|
- | 187 | i8042_mouse_irq.inr = mouse_inr; |
|
- | 188 | i8042_mouse_irq.claim = i8042_claim; |
|
- | 189 | i8042_mouse_irq.handler = i8042_mouse_irq_handler; |
|
- | 190 | irq_register(&i8042_mouse_irq); |
|
165 | 191 | ||
166 | trap_virtual_enable_irqs(1 << inr); |
192 | trap_virtual_enable_irqs(1 << kbd_inr); |
- | 193 | trap_virtual_enable_irqs(1 << mouse_inr); |
|
167 | 194 | ||
168 | /* |
195 | /* |
169 | * Clear input buffer. |
196 | * Clear input buffer. |
170 | * Number of iterations is limited to prevent infinite looping. |
197 | * Number of iterations is limited to prevent infinite looping. |
171 | */ |
198 | */ |
Line 173... | Line 200... | ||
173 | for (i = 0; (i8042_status_read() & i8042_BUFFER_FULL_MASK) && i < 100; i++) { |
200 | for (i = 0; (i8042_status_read() & i8042_BUFFER_FULL_MASK) && i < 100; i++) { |
174 | i8042_data_read(); |
201 | i8042_data_read(); |
175 | } |
202 | } |
176 | 203 | ||
177 | sysinfo_set_item_val("kbd", NULL, true); |
204 | sysinfo_set_item_val("kbd", NULL, true); |
178 | sysinfo_set_item_val("kbd.devno", NULL, devno); |
205 | sysinfo_set_item_val("kbd.devno", NULL, kbd_devno); |
179 | sysinfo_set_item_val("kbd.inr", NULL, inr); |
206 | sysinfo_set_item_val("kbd.inr", NULL, kbd_inr); |
- | 207 | ||
- | 208 | sysinfo_set_item_val("mouse", NULL, true); |
|
- | 209 | sysinfo_set_item_val("mouse.devno", NULL, mouse_devno); |
|
- | 210 | sysinfo_set_item_val("mouse.inr", NULL, mouse_inr); |
|
180 | 211 | ||
181 | i8042_grab(); |
212 | i8042_grab(); |
182 | } |
213 | } |
183 | 214 | ||
184 | /* Called from getc(). */ |
215 | /* Called from getc(). */ |