diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/misc/ibmasm/remote.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'drivers/misc/ibmasm/remote.c')
-rw-r--r-- | drivers/misc/ibmasm/remote.c | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/drivers/misc/ibmasm/remote.c b/drivers/misc/ibmasm/remote.c new file mode 100644 index 000000000000..520c3f10c271 --- /dev/null +++ b/drivers/misc/ibmasm/remote.c | |||
@@ -0,0 +1,152 @@ | |||
1 | |||
2 | /* | ||
3 | * IBM ASM Service Processor Device Driver | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
18 | * | ||
19 | * Copyright (C) IBM Corporation, 2004 | ||
20 | * | ||
21 | * Author: Max Asböck <amax@us.ibm.com> | ||
22 | * | ||
23 | */ | ||
24 | |||
25 | /* Remote mouse and keyboard event handling functions */ | ||
26 | |||
27 | #include "ibmasm.h" | ||
28 | #include "remote.h" | ||
29 | |||
30 | int ibmasm_init_remote_queue(struct service_processor *sp) | ||
31 | { | ||
32 | struct remote_queue *q = &sp->remote_queue; | ||
33 | |||
34 | disable_mouse_interrupts(sp); | ||
35 | |||
36 | q->open = 0; | ||
37 | q->size = 0; | ||
38 | |||
39 | q->start = kmalloc(DRIVER_REMOTE_QUEUE_SIZE * sizeof(struct remote_event), GFP_KERNEL); | ||
40 | if (q->start == 0) | ||
41 | return -ENOMEM; | ||
42 | |||
43 | q->end = q->start + DRIVER_REMOTE_QUEUE_SIZE; | ||
44 | q->reader = q->start; | ||
45 | q->writer = q->start; | ||
46 | q->size = DRIVER_REMOTE_QUEUE_SIZE; | ||
47 | init_waitqueue_head(&q->wait); | ||
48 | |||
49 | return 0; | ||
50 | } | ||
51 | |||
52 | void ibmasm_free_remote_queue(struct service_processor *sp) | ||
53 | { | ||
54 | kfree(sp->remote_queue.start); | ||
55 | } | ||
56 | |||
57 | void ibmasm_advance_reader(struct remote_queue *q, unsigned int n) | ||
58 | { | ||
59 | q->reader += n; | ||
60 | if (q->reader >= q->end) | ||
61 | q->reader -= q->size; | ||
62 | } | ||
63 | |||
64 | size_t ibmasm_events_available(struct remote_queue *q) | ||
65 | { | ||
66 | ssize_t diff = q->writer - q->reader; | ||
67 | |||
68 | return (diff >= 0) ? diff : q->end - q->reader; | ||
69 | } | ||
70 | |||
71 | |||
72 | static int space_free(struct remote_queue *q) | ||
73 | { | ||
74 | if (q->reader == q->writer) | ||
75 | return q->size - 1; | ||
76 | |||
77 | return ( (q->reader + q->size - q->writer) % q->size ) - 1; | ||
78 | } | ||
79 | |||
80 | static void set_mouse_event(struct remote_input *input, struct mouse_event *mouse) | ||
81 | { | ||
82 | static char last_buttons = 0; | ||
83 | |||
84 | mouse->x = input->data.mouse.x; | ||
85 | mouse->y = input->data.mouse.y; | ||
86 | |||
87 | if (input->mouse_buttons == REMOTE_MOUSE_DOUBLE_CLICK) { | ||
88 | mouse->buttons = REMOTE_MOUSE_DOUBLE_CLICK; | ||
89 | last_buttons = 0; | ||
90 | return; | ||
91 | } | ||
92 | mouse->transitions = last_buttons ^ input->mouse_buttons; | ||
93 | mouse->buttons = input->mouse_buttons; | ||
94 | |||
95 | last_buttons = input->mouse_buttons; | ||
96 | } | ||
97 | |||
98 | static void set_keyboard_event(struct remote_input *input, struct keyboard_event *keyboard) | ||
99 | { | ||
100 | keyboard->key_code = input->data.keyboard.key_code; | ||
101 | keyboard->key_down = input->data.keyboard.key_down; | ||
102 | } | ||
103 | |||
104 | static int add_to_driver_queue(struct remote_queue *q, struct remote_input *input) | ||
105 | { | ||
106 | struct remote_event *event = q->writer; | ||
107 | |||
108 | if (space_free(q) < 1) { | ||
109 | return 1; | ||
110 | } | ||
111 | |||
112 | switch(input->type) { | ||
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 | |||
126 | q->writer++; | ||
127 | if (q->writer == q->end) | ||
128 | q->writer = q->start; | ||
129 | |||
130 | return 0; | ||
131 | } | ||
132 | |||
133 | |||
134 | void ibmasm_handle_mouse_interrupt(struct service_processor *sp) | ||
135 | { | ||
136 | unsigned long reader; | ||
137 | unsigned long writer; | ||
138 | struct remote_input input; | ||
139 | |||
140 | reader = get_queue_reader(sp); | ||
141 | writer = get_queue_writer(sp); | ||
142 | |||
143 | while (reader != writer) { | ||
144 | memcpy(&input, (void *)get_queue_entry(sp, reader), sizeof(struct remote_input)); | ||
145 | |||
146 | if (add_to_driver_queue(&sp->remote_queue, &input)) | ||
147 | break; | ||
148 | |||
149 | reader = advance_queue_reader(sp, reader); | ||
150 | } | ||
151 | wake_up_interruptible(&sp->remote_queue.wait); | ||
152 | } | ||