Rev 4153 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4153 | Rev 4581 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2001-2004 Jakub Jermar |
2 | * Copyright (c) 2001-2004 Jakub Jermar |
3 | * Copyright (c) 2006 Josef Cejka |
3 | * Copyright (c) 2006 Josef Cejka |
4 | * All rights reserved. |
4 | * All rights reserved. |
5 | * |
5 | * |
6 | * Redistribution and use in source and binary forms, with or without |
6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions |
7 | * modification, are permitted provided that the following conditions |
8 | * are met: |
8 | * are met: |
9 | * |
9 | * |
10 | * - Redistributions of source code must retain the above copyright |
10 | * - Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. |
11 | * notice, this list of conditions and the following disclaimer. |
12 | * - Redistributions in binary form must reproduce the above copyright |
12 | * - Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the |
13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. |
14 | * documentation and/or other materials provided with the distribution. |
15 | * - The name of the author may not be used to endorse or promote products |
15 | * - The name of the author may not be used to endorse or promote products |
16 | * derived from this software without specific prior written permission. |
16 | * derived from this software without specific prior written permission. |
17 | * |
17 | * |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | */ |
28 | */ |
29 | 29 | ||
30 | /** @addtogroup kbd_port |
30 | /** @addtogroup kbd_port |
31 | * @ingroup kbd |
31 | * @ingroup kbd |
32 | * @{ |
32 | * @{ |
33 | */ |
33 | */ |
34 | /** @file |
34 | /** @file |
35 | * @brief i8042 port driver. |
35 | * @brief i8042 port driver. |
36 | */ |
36 | */ |
37 | 37 | ||
38 | #include <ddi.h> |
38 | #include <ddi.h> |
39 | #include <libarch/ddi.h> |
39 | #include <libarch/ddi.h> |
40 | #include <ipc/ipc.h> |
40 | #include <ipc/ipc.h> |
41 | #include <async.h> |
41 | #include <async.h> |
42 | #include <unistd.h> |
42 | #include <unistd.h> |
43 | #include <sysinfo.h> |
43 | #include <sysinfo.h> |
44 | #include <kbd_port.h> |
44 | #include <kbd_port.h> |
45 | #include <kbd.h> |
45 | #include <kbd.h> |
46 | #include <ddi.h> |
46 | #include <ddi.h> |
47 | #include "i8042.h" |
47 | #include "i8042.h" |
48 | 48 | ||
49 | /* Interesting bits for status register */ |
49 | /* Interesting bits for status register */ |
50 | #define i8042_OUTPUT_FULL 0x1 |
50 | #define i8042_OUTPUT_FULL 0x1 |
51 | #define i8042_INPUT_FULL 0x2 |
51 | #define i8042_INPUT_FULL 0x2 |
52 | #define i8042_MOUSE_DATA 0x20 |
52 | #define i8042_MOUSE_DATA 0x20 |
53 | 53 | ||
54 | /* Command constants */ |
54 | /* Command constants */ |
55 | #define i8042_CMD_KBD 0x60 |
55 | #define i8042_CMD_KBD 0x60 |
56 | #define i8042_CMD_MOUSE 0xd4 |
56 | #define i8042_CMD_MOUSE 0xd4 |
57 | 57 | ||
58 | /* Keyboard cmd byte */ |
58 | /* Keyboard cmd byte */ |
59 | #define i8042_KBD_IE 0x1 |
59 | #define i8042_KBD_IE 0x1 |
60 | #define i8042_MOUSE_IE 0x2 |
60 | #define i8042_MOUSE_IE 0x2 |
61 | #define i8042_KBD_DISABLE 0x10 |
61 | #define i8042_KBD_DISABLE 0x10 |
62 | #define i8042_MOUSE_DISABLE 0x20 |
62 | #define i8042_MOUSE_DISABLE 0x20 |
63 | #define i8042_KBD_TRANSLATE 0x40 |
63 | #define i8042_KBD_TRANSLATE 0x40 |
64 | 64 | ||
65 | /* Mouse constants */ |
65 | /* Mouse constants */ |
66 | #define MOUSE_OUT_INIT 0xf4 |
66 | #define MOUSE_OUT_INIT 0xf4 |
67 | #define MOUSE_ACK 0xfa |
67 | #define MOUSE_ACK 0xfa |
68 | 68 | ||
69 | static irq_cmd_t i8042_cmds[] = { |
69 | static irq_cmd_t i8042_cmds[] = { |
70 | { |
70 | { |
71 | .cmd = CMD_PIO_READ_8, |
71 | .cmd = CMD_PIO_READ_8, |
72 | .addr = NULL, /* will be patched in run-time */ |
72 | .addr = NULL, /* will be patched in run-time */ |
73 | .dstarg = 1 |
73 | .dstarg = 1 |
74 | }, |
74 | }, |
75 | { |
75 | { |
76 | .cmd = CMD_BTEST, |
76 | .cmd = CMD_BTEST, |
77 | .value = i8042_OUTPUT_FULL, |
77 | .value = i8042_OUTPUT_FULL, |
78 | .srcarg = 1, |
78 | .srcarg = 1, |
79 | .dstarg = 3 |
79 | .dstarg = 3 |
80 | }, |
80 | }, |
81 | { |
81 | { |
82 | .cmd = CMD_PREDICATE, |
82 | .cmd = CMD_PREDICATE, |
83 | .value = 2, |
83 | .value = 2, |
84 | .srcarg = 3 |
84 | .srcarg = 3 |
85 | }, |
85 | }, |
86 | { |
86 | { |
87 | .cmd = CMD_PIO_READ_8, |
87 | .cmd = CMD_PIO_READ_8, |
88 | .addr = NULL, /* will be patched in run-time */ |
88 | .addr = NULL, /* will be patched in run-time */ |
89 | .dstarg = 2 |
89 | .dstarg = 2 |
90 | }, |
90 | }, |
91 | { |
91 | { |
92 | .cmd = CMD_ACCEPT |
92 | .cmd = CMD_ACCEPT |
93 | } |
93 | } |
94 | }; |
94 | }; |
95 | 95 | ||
96 | static irq_code_t i8042_kbd = { |
96 | static irq_code_t i8042_kbd = { |
97 | sizeof(i8042_cmds) / sizeof(irq_cmd_t), |
97 | sizeof(i8042_cmds) / sizeof(irq_cmd_t), |
98 | i8042_cmds |
98 | i8042_cmds |
99 | }; |
99 | }; |
100 | 100 | ||
101 | static uintptr_t i8042_physical; |
101 | static uintptr_t i8042_physical; |
102 | static uintptr_t i8042_kernel; |
102 | static uintptr_t i8042_kernel; |
103 | static i8042_t * i8042; |
103 | static i8042_t * i8042; |
104 | 104 | ||
105 | static void wait_ready(void) { |
105 | static void wait_ready(void) { |
106 | while (pio_read_8(&i8042->status) & i8042_INPUT_FULL) |
106 | while (pio_read_8(&i8042->status) & i8042_INPUT_FULL) |
107 | ; |
107 | ; |
108 | } |
108 | } |
109 | 109 | ||
110 | static void i8042_irq_handler(ipc_callid_t iid, ipc_call_t *call); |
110 | static void i8042_irq_handler(ipc_callid_t iid, ipc_call_t *call); |
111 | 111 | ||
112 | int kbd_port_init(void) |
112 | int kbd_port_init(void) |
113 | { |
113 | { |
114 | int mouseenabled = 0; |
114 | int mouseenabled = 0; |
115 | void *vaddr; |
115 | void *vaddr; |
116 | 116 | ||
117 | i8042_physical = sysinfo_value("kbd.address.physical"); |
117 | i8042_physical = sysinfo_value("kbd.address.physical"); |
118 | i8042_kernel = sysinfo_value("kbd.address.kernel"); |
118 | i8042_kernel = sysinfo_value("kbd.address.kernel"); |
119 | if (pio_enable((void *) i8042_physical, sizeof(i8042_t), &vaddr) != 0) |
119 | if (pio_enable((void *) i8042_physical, sizeof(i8042_t), &vaddr) != 0) |
120 | return -1; |
120 | return -1; |
121 | i8042 = vaddr; |
121 | i8042 = vaddr; |
122 | 122 | ||
123 | async_set_interrupt_received(i8042_irq_handler); |
123 | async_set_interrupt_received(i8042_irq_handler); |
124 | 124 | ||
125 | /* Disable kbd, enable mouse */ |
125 | /* Disable kbd, enable mouse */ |
126 | pio_write_8(&i8042->status, i8042_CMD_KBD); |
126 | pio_write_8(&i8042->status, i8042_CMD_KBD); |
127 | wait_ready(); |
127 | wait_ready(); |
128 | pio_write_8(&i8042->status, i8042_CMD_KBD); |
128 | pio_write_8(&i8042->status, i8042_CMD_KBD); |
129 | wait_ready(); |
129 | wait_ready(); |
130 | pio_write_8(&i8042->data, i8042_KBD_DISABLE); |
130 | pio_write_8(&i8042->data, i8042_KBD_DISABLE); |
131 | wait_ready(); |
131 | wait_ready(); |
132 | 132 | ||
133 | /* Flush all current IO */ |
133 | /* Flush all current IO */ |
134 | while (pio_read_8(&i8042->status) & i8042_OUTPUT_FULL) |
134 | while (pio_read_8(&i8042->status) & i8042_OUTPUT_FULL) |
135 | (void) pio_read_8(&i8042->data); |
135 | (void) pio_read_8(&i8042->data); |
136 | 136 | ||
137 | /* Enable kbd */ |
137 | /* Enable kbd */ |
138 | i8042_kbd.cmds[0].addr = &((i8042_t *) i8042_kernel)->status; |
138 | i8042_kbd.cmds[0].addr = &((i8042_t *) i8042_kernel)->status; |
139 | i8042_kbd.cmds[3].addr = &((i8042_t *) i8042_kernel)->data; |
139 | i8042_kbd.cmds[3].addr = &((i8042_t *) i8042_kernel)->data; |
140 | ipc_register_irq(sysinfo_value("kbd.inr"), device_assign_devno(), 0, &i8042_kbd); |
140 | ipc_register_irq(sysinfo_value("kbd.inr"), device_assign_devno(), 0, &i8042_kbd); |
141 | 141 | ||
142 | int newcontrol = i8042_KBD_IE | i8042_KBD_TRANSLATE; |
142 | int newcontrol = i8042_KBD_IE | i8042_KBD_TRANSLATE; |
143 | if (mouseenabled) |
143 | if (mouseenabled) |
144 | newcontrol |= i8042_MOUSE_IE; |
144 | newcontrol |= i8042_MOUSE_IE; |
145 | 145 | ||
146 | pio_write_8(&i8042->status, i8042_CMD_KBD); |
146 | pio_write_8(&i8042->status, i8042_CMD_KBD); |
147 | wait_ready(); |
147 | wait_ready(); |
148 | pio_write_8(&i8042->data, newcontrol); |
148 | pio_write_8(&i8042->data, newcontrol); |
149 | wait_ready(); |
149 | wait_ready(); |
150 | 150 | ||
151 | return 0; |
151 | return 0; |
152 | } |
152 | } |
153 | 153 | ||
- | 154 | void kbd_port_yield(void) |
|
- | 155 | { |
|
- | 156 | } |
|
- | 157 | ||
- | 158 | void kbd_port_reclaim(void) |
|
- | 159 | { |
|
- | 160 | } |
|
- | 161 | ||
154 | static void i8042_irq_handler(ipc_callid_t iid, ipc_call_t *call) |
162 | static void i8042_irq_handler(ipc_callid_t iid, ipc_call_t *call) |
155 | { |
163 | { |
156 | int status = IPC_GET_ARG1(*call); |
164 | int status = IPC_GET_ARG1(*call); |
157 | 165 | ||
158 | if ((status & i8042_MOUSE_DATA)) |
166 | if ((status & i8042_MOUSE_DATA)) |
159 | return; |
167 | return; |
160 | 168 | ||
161 | int scan_code = IPC_GET_ARG2(*call); |
169 | int scan_code = IPC_GET_ARG2(*call); |
162 | 170 | ||
163 | kbd_push_scancode(scan_code); |
171 | kbd_push_scancode(scan_code); |
164 | return; |
172 | return; |
165 | } |
173 | } |
166 | 174 | ||
167 | /** |
175 | /** |
168 | * @} |
176 | * @} |
169 | */ |
177 | */ |
170 | 178 |