diff options
Diffstat (limited to 'drivers/misc/ibmasm/remote.c')
-rw-r--r-- | drivers/misc/ibmasm/remote.c | 304 |
1 files changed, 212 insertions, 92 deletions
diff --git a/drivers/misc/ibmasm/remote.c b/drivers/misc/ibmasm/remote.c index 520c3f10c271..d3c48d23ee51 100644 --- a/drivers/misc/ibmasm/remote.c +++ b/drivers/misc/ibmasm/remote.c | |||
@@ -1,4 +1,3 @@ | |||
1 | |||
2 | /* | 1 | /* |
3 | * IBM ASM Service Processor Device Driver | 2 | * IBM ASM Service Processor Device Driver |
4 | * | 3 | * |
@@ -18,135 +17,256 @@ | |||
18 | * | 17 | * |
19 | * Copyright (C) IBM Corporation, 2004 | 18 | * Copyright (C) IBM Corporation, 2004 |
20 | * | 19 | * |
21 | * Author: Max Asböck <amax@us.ibm.com> | 20 | * Authors: Max Asböck <amax@us.ibm.com> |
21 | * Vernon Mauery <vernux@us.ibm.com> | ||
22 | * | 22 | * |
23 | */ | 23 | */ |
24 | 24 | ||
25 | /* Remote mouse and keyboard event handling functions */ | 25 | /* Remote mouse and keyboard event handling functions */ |
26 | 26 | ||
27 | #include <linux/pci.h> | ||
27 | #include "ibmasm.h" | 28 | #include "ibmasm.h" |
28 | #include "remote.h" | 29 | #include "remote.h" |
29 | 30 | ||
30 | int ibmasm_init_remote_queue(struct service_processor *sp) | 31 | static int xmax = 1600; |
31 | { | 32 | static int ymax = 1200; |
32 | struct remote_queue *q = &sp->remote_queue; | ||
33 | |||
34 | disable_mouse_interrupts(sp); | ||
35 | 33 | ||
36 | q->open = 0; | ||
37 | q->size = 0; | ||
38 | 34 | ||
39 | q->start = kmalloc(DRIVER_REMOTE_QUEUE_SIZE * sizeof(struct remote_event), GFP_KERNEL); | 35 | static unsigned short xlate_high[XLATE_SIZE] = { |
40 | if (q->start == 0) | 36 | [KEY_SYM_ENTER & 0xff] = KEY_ENTER, |
41 | return -ENOMEM; | 37 | [KEY_SYM_KPSLASH & 0xff] = KEY_KPSLASH, |
38 | [KEY_SYM_KPSTAR & 0xff] = KEY_KPASTERISK, | ||
39 | [KEY_SYM_KPMINUS & 0xff] = KEY_KPMINUS, | ||
40 | [KEY_SYM_KPDOT & 0xff] = KEY_KPDOT, | ||
41 | [KEY_SYM_KPPLUS & 0xff] = KEY_KPPLUS, | ||
42 | [KEY_SYM_KP0 & 0xff] = KEY_KP0, | ||
43 | [KEY_SYM_KP1 & 0xff] = KEY_KP1, | ||
44 | [KEY_SYM_KP2 & 0xff] = KEY_KP2, [KEY_SYM_KPDOWN & 0xff] = KEY_KP2, | ||
45 | [KEY_SYM_KP3 & 0xff] = KEY_KP3, | ||
46 | [KEY_SYM_KP4 & 0xff] = KEY_KP4, [KEY_SYM_KPLEFT & 0xff] = KEY_KP4, | ||
47 | [KEY_SYM_KP5 & 0xff] = KEY_KP5, | ||
48 | [KEY_SYM_KP6 & 0xff] = KEY_KP6, [KEY_SYM_KPRIGHT & 0xff] = KEY_KP6, | ||
49 | [KEY_SYM_KP7 & 0xff] = KEY_KP7, | ||
50 | [KEY_SYM_KP8 & 0xff] = KEY_KP8, [KEY_SYM_KPUP & 0xff] = KEY_KP8, | ||
51 | [KEY_SYM_KP9 & 0xff] = KEY_KP9, | ||
52 | [KEY_SYM_BK_SPC & 0xff] = KEY_BACKSPACE, | ||
53 | [KEY_SYM_TAB & 0xff] = KEY_TAB, | ||
54 | [KEY_SYM_CTRL & 0xff] = KEY_LEFTCTRL, | ||
55 | [KEY_SYM_ALT & 0xff] = KEY_LEFTALT, | ||
56 | [KEY_SYM_INSERT & 0xff] = KEY_INSERT, | ||
57 | [KEY_SYM_DELETE & 0xff] = KEY_DELETE, | ||
58 | [KEY_SYM_SHIFT & 0xff] = KEY_LEFTSHIFT, | ||
59 | [KEY_SYM_UARROW & 0xff] = KEY_UP, | ||
60 | [KEY_SYM_DARROW & 0xff] = KEY_DOWN, | ||
61 | [KEY_SYM_LARROW & 0xff] = KEY_LEFT, | ||
62 | [KEY_SYM_RARROW & 0xff] = KEY_RIGHT, | ||
63 | [KEY_SYM_ESCAPE & 0xff] = KEY_ESC, | ||
64 | [KEY_SYM_PAGEUP & 0xff] = KEY_PAGEUP, | ||
65 | [KEY_SYM_PAGEDOWN & 0xff] = KEY_PAGEDOWN, | ||
66 | [KEY_SYM_HOME & 0xff] = KEY_HOME, | ||
67 | [KEY_SYM_END & 0xff] = KEY_END, | ||
68 | [KEY_SYM_F1 & 0xff] = KEY_F1, | ||
69 | [KEY_SYM_F2 & 0xff] = KEY_F2, | ||
70 | [KEY_SYM_F3 & 0xff] = KEY_F3, | ||
71 | [KEY_SYM_F4 & 0xff] = KEY_F4, | ||
72 | [KEY_SYM_F5 & 0xff] = KEY_F5, | ||
73 | [KEY_SYM_F6 & 0xff] = KEY_F6, | ||
74 | [KEY_SYM_F7 & 0xff] = KEY_F7, | ||
75 | [KEY_SYM_F8 & 0xff] = KEY_F8, | ||
76 | [KEY_SYM_F9 & 0xff] = KEY_F9, | ||
77 | [KEY_SYM_F10 & 0xff] = KEY_F10, | ||
78 | [KEY_SYM_F11 & 0xff] = KEY_F11, | ||
79 | [KEY_SYM_F12 & 0xff] = KEY_F12, | ||
80 | [KEY_SYM_CAP_LOCK & 0xff] = KEY_CAPSLOCK, | ||
81 | [KEY_SYM_NUM_LOCK & 0xff] = KEY_NUMLOCK, | ||
82 | [KEY_SYM_SCR_LOCK & 0xff] = KEY_SCROLLLOCK, | ||
83 | }; | ||
84 | static unsigned short xlate[XLATE_SIZE] = { | ||
85 | [NO_KEYCODE] = KEY_RESERVED, | ||
86 | [KEY_SYM_SPACE] = KEY_SPACE, | ||
87 | [KEY_SYM_TILDE] = KEY_GRAVE, [KEY_SYM_BKTIC] = KEY_GRAVE, | ||
88 | [KEY_SYM_ONE] = KEY_1, [KEY_SYM_BANG] = KEY_1, | ||
89 | [KEY_SYM_TWO] = KEY_2, [KEY_SYM_AT] = KEY_2, | ||
90 | [KEY_SYM_THREE] = KEY_3, [KEY_SYM_POUND] = KEY_3, | ||
91 | [KEY_SYM_FOUR] = KEY_4, [KEY_SYM_DOLLAR] = KEY_4, | ||
92 | [KEY_SYM_FIVE] = KEY_5, [KEY_SYM_PERCENT] = KEY_5, | ||
93 | [KEY_SYM_SIX] = KEY_6, [KEY_SYM_CARAT] = KEY_6, | ||
94 | [KEY_SYM_SEVEN] = KEY_7, [KEY_SYM_AMPER] = KEY_7, | ||
95 | [KEY_SYM_EIGHT] = KEY_8, [KEY_SYM_STAR] = KEY_8, | ||
96 | [KEY_SYM_NINE] = KEY_9, [KEY_SYM_LPAREN] = KEY_9, | ||
97 | [KEY_SYM_ZERO] = KEY_0, [KEY_SYM_RPAREN] = KEY_0, | ||
98 | [KEY_SYM_MINUS] = KEY_MINUS, [KEY_SYM_USCORE] = KEY_MINUS, | ||
99 | [KEY_SYM_EQUAL] = KEY_EQUAL, [KEY_SYM_PLUS] = KEY_EQUAL, | ||
100 | [KEY_SYM_LBRKT] = KEY_LEFTBRACE, [KEY_SYM_LCURLY] = KEY_LEFTBRACE, | ||
101 | [KEY_SYM_RBRKT] = KEY_RIGHTBRACE, [KEY_SYM_RCURLY] = KEY_RIGHTBRACE, | ||
102 | [KEY_SYM_SLASH] = KEY_BACKSLASH, [KEY_SYM_PIPE] = KEY_BACKSLASH, | ||
103 | [KEY_SYM_TIC] = KEY_APOSTROPHE, [KEY_SYM_QUOTE] = KEY_APOSTROPHE, | ||
104 | [KEY_SYM_SEMIC] = KEY_SEMICOLON, [KEY_SYM_COLON] = KEY_SEMICOLON, | ||
105 | [KEY_SYM_COMMA] = KEY_COMMA, [KEY_SYM_LT] = KEY_COMMA, | ||
106 | [KEY_SYM_PERIOD] = KEY_DOT, [KEY_SYM_GT] = KEY_DOT, | ||
107 | [KEY_SYM_BSLASH] = KEY_SLASH, [KEY_SYM_QMARK] = KEY_SLASH, | ||
108 | [KEY_SYM_A] = KEY_A, [KEY_SYM_a] = KEY_A, | ||
109 | [KEY_SYM_B] = KEY_B, [KEY_SYM_b] = KEY_B, | ||
110 | [KEY_SYM_C] = KEY_C, [KEY_SYM_c] = KEY_C, | ||
111 | [KEY_SYM_D] = KEY_D, [KEY_SYM_d] = KEY_D, | ||
112 | [KEY_SYM_E] = KEY_E, [KEY_SYM_e] = KEY_E, | ||
113 | [KEY_SYM_F] = KEY_F, [KEY_SYM_f] = KEY_F, | ||
114 | [KEY_SYM_G] = KEY_G, [KEY_SYM_g] = KEY_G, | ||
115 | [KEY_SYM_H] = KEY_H, [KEY_SYM_h] = KEY_H, | ||
116 | [KEY_SYM_I] = KEY_I, [KEY_SYM_i] = KEY_I, | ||
117 | [KEY_SYM_J] = KEY_J, [KEY_SYM_j] = KEY_J, | ||
118 | [KEY_SYM_K] = KEY_K, [KEY_SYM_k] = KEY_K, | ||
119 | [KEY_SYM_L] = KEY_L, [KEY_SYM_l] = KEY_L, | ||
120 | [KEY_SYM_M] = KEY_M, [KEY_SYM_m] = KEY_M, | ||
121 | [KEY_SYM_N] = KEY_N, [KEY_SYM_n] = KEY_N, | ||
122 | [KEY_SYM_O] = KEY_O, [KEY_SYM_o] = KEY_O, | ||
123 | [KEY_SYM_P] = KEY_P, [KEY_SYM_p] = KEY_P, | ||
124 | [KEY_SYM_Q] = KEY_Q, [KEY_SYM_q] = KEY_Q, | ||
125 | [KEY_SYM_R] = KEY_R, [KEY_SYM_r] = KEY_R, | ||
126 | [KEY_SYM_S] = KEY_S, [KEY_SYM_s] = KEY_S, | ||
127 | [KEY_SYM_T] = KEY_T, [KEY_SYM_t] = KEY_T, | ||
128 | [KEY_SYM_U] = KEY_U, [KEY_SYM_u] = KEY_U, | ||
129 | [KEY_SYM_V] = KEY_V, [KEY_SYM_v] = KEY_V, | ||
130 | [KEY_SYM_W] = KEY_W, [KEY_SYM_w] = KEY_W, | ||
131 | [KEY_SYM_X] = KEY_X, [KEY_SYM_x] = KEY_X, | ||
132 | [KEY_SYM_Y] = KEY_Y, [KEY_SYM_y] = KEY_Y, | ||
133 | [KEY_SYM_Z] = KEY_Z, [KEY_SYM_z] = KEY_Z, | ||
134 | }; | ||
42 | 135 | ||
43 | q->end = q->start + DRIVER_REMOTE_QUEUE_SIZE; | 136 | static char remote_mouse_name[] = "ibmasm RSA I remote mouse"; |
44 | q->reader = q->start; | 137 | static char remote_keybd_name[] = "ibmasm RSA I remote keyboard"; |
45 | q->writer = q->start; | ||
46 | q->size = DRIVER_REMOTE_QUEUE_SIZE; | ||
47 | init_waitqueue_head(&q->wait); | ||
48 | 138 | ||
49 | return 0; | 139 | static void print_input(struct remote_input *input) |
50 | } | ||
51 | |||
52 | void ibmasm_free_remote_queue(struct service_processor *sp) | ||
53 | { | 140 | { |
54 | kfree(sp->remote_queue.start); | 141 | if (input->type == INPUT_TYPE_MOUSE) { |
142 | unsigned char buttons = input->mouse_buttons; | ||
143 | dbg("remote mouse movement: (x,y)=(%d,%d)%s%s%s%s\n", | ||
144 | input->data.mouse.x, input->data.mouse.y, | ||
145 | (buttons)?" -- buttons:":"", | ||
146 | (buttons & REMOTE_BUTTON_LEFT)?"left ":"", | ||
147 | (buttons & REMOTE_BUTTON_MIDDLE)?"middle ":"", | ||
148 | (buttons & REMOTE_BUTTON_RIGHT)?"right":"" | ||
149 | ); | ||
150 | } else { | ||
151 | dbg("remote keypress (code, flag, down):" | ||
152 | "%d (0x%x) [0x%x] [0x%x]\n", | ||
153 | input->data.keyboard.key_code, | ||
154 | input->data.keyboard.key_code, | ||
155 | input->data.keyboard.key_flag, | ||
156 | input->data.keyboard.key_down | ||
157 | ); | ||
158 | } | ||
55 | } | 159 | } |
56 | 160 | ||
57 | void ibmasm_advance_reader(struct remote_queue *q, unsigned int n) | 161 | static void send_mouse_event(struct input_dev *dev, struct pt_regs *regs, |
162 | struct remote_input *input) | ||
58 | { | 163 | { |
59 | q->reader += n; | 164 | unsigned char buttons = input->mouse_buttons; |
60 | if (q->reader >= q->end) | ||
61 | q->reader -= q->size; | ||
62 | } | ||
63 | 165 | ||
64 | size_t ibmasm_events_available(struct remote_queue *q) | 166 | input_regs(dev, regs); |
65 | { | 167 | input_report_abs(dev, ABS_X, input->data.mouse.x); |
66 | ssize_t diff = q->writer - q->reader; | 168 | input_report_abs(dev, ABS_Y, input->data.mouse.y); |
67 | 169 | input_report_key(dev, BTN_LEFT, buttons & REMOTE_BUTTON_LEFT); | |
68 | return (diff >= 0) ? diff : q->end - q->reader; | 170 | input_report_key(dev, BTN_MIDDLE, buttons & REMOTE_BUTTON_MIDDLE); |
171 | input_report_key(dev, BTN_RIGHT, buttons & REMOTE_BUTTON_RIGHT); | ||
172 | input_sync(dev); | ||
69 | } | 173 | } |
70 | |||
71 | 174 | ||
72 | static int space_free(struct remote_queue *q) | 175 | static void send_keyboard_event(struct input_dev *dev, struct pt_regs *regs, |
176 | struct remote_input *input) | ||
73 | { | 177 | { |
74 | if (q->reader == q->writer) | 178 | unsigned int key; |
75 | return q->size - 1; | 179 | unsigned short code = input->data.keyboard.key_code; |
76 | 180 | ||
77 | return ( (q->reader + q->size - q->writer) % q->size ) - 1; | 181 | if (code & 0xff00) |
182 | key = xlate_high[code & 0xff]; | ||
183 | else | ||
184 | key = xlate[code]; | ||
185 | input_regs(dev, regs); | ||
186 | input_report_key(dev, key, (input->data.keyboard.key_down) ? 1 : 0); | ||
187 | input_sync(dev); | ||
78 | } | 188 | } |
79 | 189 | ||
80 | static void set_mouse_event(struct remote_input *input, struct mouse_event *mouse) | 190 | void ibmasm_handle_mouse_interrupt(struct service_processor *sp, |
191 | struct pt_regs *regs) | ||
81 | { | 192 | { |
82 | static char last_buttons = 0; | 193 | unsigned long reader; |
194 | unsigned long writer; | ||
195 | struct remote_input input; | ||
83 | 196 | ||
84 | mouse->x = input->data.mouse.x; | 197 | reader = get_queue_reader(sp); |
85 | mouse->y = input->data.mouse.y; | 198 | writer = get_queue_writer(sp); |
86 | 199 | ||
87 | if (input->mouse_buttons == REMOTE_MOUSE_DOUBLE_CLICK) { | 200 | while (reader != writer) { |
88 | mouse->buttons = REMOTE_MOUSE_DOUBLE_CLICK; | 201 | memcpy_fromio(&input, get_queue_entry(sp, reader), |
89 | last_buttons = 0; | 202 | sizeof(struct remote_input)); |
90 | return; | ||
91 | } | ||
92 | mouse->transitions = last_buttons ^ input->mouse_buttons; | ||
93 | mouse->buttons = input->mouse_buttons; | ||
94 | 203 | ||
95 | last_buttons = input->mouse_buttons; | 204 | print_input(&input); |
96 | } | 205 | if (input.type == INPUT_TYPE_MOUSE) { |
206 | send_mouse_event(&sp->remote->mouse_dev, regs, &input); | ||
207 | } else if (input.type == INPUT_TYPE_KEYBOARD) { | ||
208 | send_keyboard_event(&sp->remote->keybd_dev, regs, &input); | ||
209 | } else | ||
210 | break; | ||
97 | 211 | ||
98 | static void set_keyboard_event(struct remote_input *input, struct keyboard_event *keyboard) | 212 | reader = advance_queue_reader(sp, reader); |
99 | { | 213 | writer = get_queue_writer(sp); |
100 | keyboard->key_code = input->data.keyboard.key_code; | 214 | } |
101 | keyboard->key_down = input->data.keyboard.key_down; | ||
102 | } | 215 | } |
103 | 216 | ||
104 | static int add_to_driver_queue(struct remote_queue *q, struct remote_input *input) | 217 | int ibmasm_init_remote_input_dev(struct service_processor *sp) |
105 | { | 218 | { |
106 | struct remote_event *event = q->writer; | 219 | /* set up the mouse input device */ |
220 | struct ibmasm_remote *remote; | ||
221 | struct pci_dev *pdev = to_pci_dev(sp->dev); | ||
222 | int i; | ||
107 | 223 | ||
108 | if (space_free(q) < 1) { | 224 | sp->remote = remote = kmalloc(sizeof(*remote), GFP_KERNEL); |
109 | return 1; | 225 | if (!remote) |
110 | } | 226 | return -ENOMEM; |
111 | 227 | ||
112 | switch(input->type) { | 228 | memset(remote, 0, sizeof(*remote)); |
113 | case (INPUT_TYPE_MOUSE): | ||
114 | event->type = INPUT_TYPE_MOUSE; | ||
115 | set_mouse_event(input, &event->data.mouse); | ||
116 | break; | ||
117 | case (INPUT_TYPE_KEYBOARD): | ||
118 | event->type = INPUT_TYPE_KEYBOARD; | ||
119 | set_keyboard_event(input, &event->data.keyboard); | ||
120 | break; | ||
121 | default: | ||
122 | return 0; | ||
123 | } | ||
124 | event->type = input->type; | ||
125 | 229 | ||
126 | q->writer++; | 230 | remote->mouse_dev.private = remote; |
127 | if (q->writer == q->end) | 231 | init_input_dev(&remote->mouse_dev); |
128 | q->writer = q->start; | 232 | remote->mouse_dev.id.vendor = pdev->vendor; |
233 | remote->mouse_dev.id.product = pdev->device; | ||
234 | remote->mouse_dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); | ||
235 | remote->mouse_dev.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | | ||
236 | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE); | ||
237 | set_bit(BTN_TOUCH, remote->mouse_dev.keybit); | ||
238 | remote->mouse_dev.name = remote_mouse_name; | ||
239 | input_set_abs_params(&remote->mouse_dev, ABS_X, 0, xmax, 0, 0); | ||
240 | input_set_abs_params(&remote->mouse_dev, ABS_Y, 0, ymax, 0, 0); | ||
129 | 241 | ||
130 | return 0; | 242 | remote->keybd_dev.private = remote; |
131 | } | 243 | init_input_dev(&remote->keybd_dev); |
132 | 244 | remote->keybd_dev.id.vendor = pdev->vendor; | |
245 | remote->keybd_dev.id.product = pdev->device; | ||
246 | remote->keybd_dev.evbit[0] = BIT(EV_KEY); | ||
247 | remote->keybd_dev.name = remote_keybd_name; | ||
133 | 248 | ||
134 | void ibmasm_handle_mouse_interrupt(struct service_processor *sp) | 249 | for (i=0; i<XLATE_SIZE; i++) { |
135 | { | 250 | if (xlate_high[i]) |
136 | unsigned long reader; | 251 | set_bit(xlate_high[i], remote->keybd_dev.keybit); |
137 | unsigned long writer; | 252 | if (xlate[i]) |
138 | struct remote_input input; | 253 | set_bit(xlate[i], remote->keybd_dev.keybit); |
254 | } | ||
139 | 255 | ||
140 | reader = get_queue_reader(sp); | 256 | input_register_device(&remote->mouse_dev); |
141 | writer = get_queue_writer(sp); | 257 | input_register_device(&remote->keybd_dev); |
258 | enable_mouse_interrupts(sp); | ||
142 | 259 | ||
143 | while (reader != writer) { | 260 | printk(KERN_INFO "ibmasm remote responding to events on RSA card %d\n", sp->number); |
144 | memcpy(&input, (void *)get_queue_entry(sp, reader), sizeof(struct remote_input)); | ||
145 | 261 | ||
146 | if (add_to_driver_queue(&sp->remote_queue, &input)) | 262 | return 0; |
147 | break; | 263 | } |
148 | 264 | ||
149 | reader = advance_queue_reader(sp, reader); | 265 | void ibmasm_free_remote_input_dev(struct service_processor *sp) |
150 | } | 266 | { |
151 | wake_up_interruptible(&sp->remote_queue.wait); | 267 | disable_mouse_interrupts(sp); |
268 | input_unregister_device(&sp->remote->keybd_dev); | ||
269 | input_unregister_device(&sp->remote->mouse_dev); | ||
270 | kfree(sp->remote); | ||
152 | } | 271 | } |
272 | |||