Rev 2089 | Rev 2516 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2089 | Rev 2321 | ||
---|---|---|---|
Line 72... | Line 72... | ||
72 | 72 | ||
73 | #define i8042_SET_COMMAND 0x60 |
73 | #define i8042_SET_COMMAND 0x60 |
74 | #define i8042_COMMAND 0x69 |
74 | #define i8042_COMMAND 0x69 |
75 | 75 | ||
76 | #define i8042_BUFFER_FULL_MASK 0x01 |
76 | #define i8042_BUFFER_FULL_MASK 0x01 |
77 | #define i8042_WAIT_MASK 0x02 |
77 | #define i8042_WAIT_MASK 0x02 |
78 | #define i8042_MOUSE_DATA 0x20 |
78 | #define i8042_MOUSE_DATA 0x20 |
79 | 79 | ||
80 | static void i8042_suspend(chardev_t *); |
80 | static void i8042_suspend(chardev_t *); |
81 | static void i8042_resume(chardev_t *); |
81 | static void i8042_resume(chardev_t *); |
82 | 82 | ||
83 | static chardev_operations_t ops = { |
83 | static chardev_operations_t ops = { |
Line 88... | Line 88... | ||
88 | 88 | ||
89 | /** Structure for i8042's IRQ. */ |
89 | /** Structure for i8042's IRQ. */ |
90 | static irq_t i8042_kbd_irq; |
90 | static irq_t i8042_kbd_irq; |
91 | static irq_t i8042_mouse_irq; |
91 | static irq_t i8042_mouse_irq; |
92 | 92 | ||
93 | /** Wait until the controller reads its data. */ |
- | |
94 | static void i8042_wait(void) { |
- | |
95 | while (i8042_status_read() & i8042_WAIT_MASK) { |
- | |
96 | /* wait */ |
- | |
97 | } |
- | |
98 | } |
- | |
99 | - | ||
100 | void i8042_grab(void) |
93 | void i8042_grab(void) |
101 | { |
94 | { |
102 | ipl_t ipl = interrupts_disable(); |
95 | ipl_t ipl = interrupts_disable(); |
103 | 96 | ||
104 | i8042_wait(); |
- | |
105 | i8042_command_write(i8042_SET_COMMAND); |
- | |
106 | i8042_wait(); |
- | |
107 | i8042_data_write(i8042_COMMAND); |
- | |
108 | i8042_wait(); |
- | |
109 | - | ||
110 | spinlock_lock(&i8042_kbd_irq.lock); |
97 | spinlock_lock(&i8042_kbd_irq.lock); |
111 | i8042_kbd_irq.notif_cfg.notify = false; |
98 | i8042_kbd_irq.notif_cfg.notify = false; |
112 | spinlock_unlock(&i8042_kbd_irq.lock); |
99 | spinlock_unlock(&i8042_kbd_irq.lock); |
113 | 100 | ||
114 | spinlock_lock(&i8042_mouse_irq.lock); |
101 | spinlock_lock(&i8042_mouse_irq.lock); |
Line 138... | Line 125... | ||
138 | static irq_ownership_t i8042_claim(void) |
125 | static irq_ownership_t i8042_claim(void) |
139 | { |
126 | { |
140 | return IRQ_ACCEPT; |
127 | return IRQ_ACCEPT; |
141 | } |
128 | } |
142 | 129 | ||
143 | static void i8042_kbd_irq_handler(irq_t *irq, void *arg, ...) |
130 | static void i8042_irq_handler(irq_t *irq, void *arg, ...) |
144 | { |
131 | { |
145 | if (irq->notif_cfg.notify && irq->notif_cfg.answerbox) |
132 | if (irq->notif_cfg.notify && irq->notif_cfg.answerbox) |
146 | ipc_irq_send_notif(irq); |
133 | ipc_irq_send_notif(irq); |
147 | else { |
134 | else { |
148 | uint8_t x; |
135 | uint8_t data; |
149 | uint8_t status; |
136 | uint8_t status; |
150 | 137 | ||
151 | while (((status = i8042_status_read()) & i8042_BUFFER_FULL_MASK)) { |
138 | while (((status = i8042_status_read()) & i8042_BUFFER_FULL_MASK)) { |
152 | x = i8042_data_read(); |
139 | data = i8042_data_read(); |
153 | 140 | ||
154 | if ((status & i8042_MOUSE_DATA)) |
141 | if ((status & i8042_MOUSE_DATA)) |
155 | continue; |
142 | continue; |
156 | 143 | ||
157 | if (x & KEY_RELEASE) |
144 | if (data & KEY_RELEASE) |
158 | key_released(x ^ KEY_RELEASE); |
145 | key_released(data ^ KEY_RELEASE); |
159 | else |
146 | else |
160 | key_pressed(x); |
147 | key_pressed(data); |
161 | } |
148 | } |
162 | } |
149 | } |
163 | } |
150 | } |
164 | 151 | ||
165 | static void i8042_mouse_irq_handler(irq_t *irq, void *arg, ...) |
- | |
166 | { |
- | |
167 | if (irq->notif_cfg.notify && irq->notif_cfg.answerbox) |
- | |
168 | ipc_irq_send_notif(irq); |
- | |
169 | } |
- | |
170 | - | ||
171 | /** Initialize i8042. */ |
152 | /** Initialize i8042. */ |
172 | void i8042_init(devno_t kbd_devno, inr_t kbd_inr, devno_t mouse_devno, inr_t mouse_inr) |
153 | void i8042_init(devno_t kbd_devno, inr_t kbd_inr, devno_t mouse_devno, inr_t mouse_inr) |
173 | { |
154 | { |
174 | chardev_initialize("i8042_kbd", &kbrd, &ops); |
155 | chardev_initialize("i8042_kbd", &kbrd, &ops); |
175 | stdin = &kbrd; |
156 | stdin = &kbrd; |
176 | 157 | ||
177 | irq_initialize(&i8042_kbd_irq); |
158 | irq_initialize(&i8042_kbd_irq); |
178 | i8042_kbd_irq.devno = kbd_devno; |
159 | i8042_kbd_irq.devno = kbd_devno; |
179 | i8042_kbd_irq.inr = kbd_inr; |
160 | i8042_kbd_irq.inr = kbd_inr; |
180 | i8042_kbd_irq.claim = i8042_claim; |
161 | i8042_kbd_irq.claim = i8042_claim; |
181 | i8042_kbd_irq.handler = i8042_kbd_irq_handler; |
162 | i8042_kbd_irq.handler = i8042_irq_handler; |
182 | irq_register(&i8042_kbd_irq); |
163 | irq_register(&i8042_kbd_irq); |
183 | 164 | ||
184 | irq_initialize(&i8042_mouse_irq); |
165 | irq_initialize(&i8042_mouse_irq); |
185 | i8042_mouse_irq.devno = mouse_devno; |
166 | i8042_mouse_irq.devno = mouse_devno; |
186 | i8042_mouse_irq.inr = mouse_inr; |
167 | i8042_mouse_irq.inr = mouse_inr; |
187 | i8042_mouse_irq.claim = i8042_claim; |
168 | i8042_mouse_irq.claim = i8042_claim; |
188 | i8042_mouse_irq.handler = i8042_mouse_irq_handler; |
169 | i8042_mouse_irq.handler = i8042_irq_handler; |
189 | irq_register(&i8042_mouse_irq); |
170 | irq_register(&i8042_mouse_irq); |
190 | 171 | ||
191 | trap_virtual_enable_irqs(1 << kbd_inr); |
172 | trap_virtual_enable_irqs(1 << kbd_inr); |
192 | trap_virtual_enable_irqs(1 << mouse_inr); |
173 | trap_virtual_enable_irqs(1 << mouse_inr); |
193 | 174 |