Changeset 00aece0 in mainline for uspace/srv/hid
- Timestamp:
- 2012-02-18T16:47:38Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4449c6c
- Parents:
- bd5f3b7 (diff), f943dd3 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- uspace/srv/hid
- Files:
-
- 12 added
- 9 deleted
- 27 edited
- 14 moved
-
console/Makefile (modified) (1 diff)
-
console/console.c (modified) (10 diffs)
-
console/console.h (modified) (1 diff)
-
console/gcons.c (deleted)
-
console/gfx/anim_1.tga (modified) ( previous)
-
console/gfx/anim_2.tga (modified) ( previous)
-
console/gfx/anim_3.tga (modified) ( previous)
-
console/gfx/anim_4.tga (modified) ( previous)
-
console/gfx/cons_data.tga (moved) (moved from uspace/srv/hid/console/gfx/cons_has_data.tga )
-
console/gfx/cons_dis.tga (added)
-
console/gfx/cons_dis_sel.tga (added)
-
console/gfx/cons_kernel.tga (modified) ( previous)
-
console/gfx/cons_sel.tga (moved) (moved from uspace/srv/hid/console/gfx/cons_selected.tga )
-
console/keybuffer.c (deleted)
-
fb/Makefile (modified) (1 diff)
-
fb/ctl/serial.c (added)
-
fb/ctl/serial.h (moved) (moved from uspace/srv/hid/fb/msim.h ) (2 diffs)
-
fb/ega.c (deleted)
-
fb/fb.c (modified) (2 diffs)
-
fb/fb.h (modified) (2 diffs)
-
fb/gfx/font-8x16.c (moved) (moved from uspace/srv/hid/fb/font-8x16.c ) (1 diff)
-
fb/gfx/font-8x16.h (moved) (moved from uspace/srv/hid/fb/font-8x16.h ) (1 diff)
-
fb/main.c (deleted)
-
fb/pointer.xbm (deleted)
-
fb/pointer_mask.xbm (deleted)
-
fb/port/ega.c (added)
-
fb/port/ega.h (moved) (moved from uspace/srv/hid/fb/ega.h ) (1 diff)
-
fb/port/kchar.c (moved) (moved from uspace/srv/hid/fb/msim.c ) (1 diff)
-
fb/port/kchar.h (moved) (moved from uspace/srv/hid/fb/main.h ) (2 diffs)
-
fb/port/kfb.c (added)
-
fb/port/kfb.h (added)
-
fb/port/niagara.c (moved) (moved from uspace/srv/hid/fb/niagara.c ) (1 diff)
-
fb/port/niagara.h (moved) (moved from uspace/srv/hid/fb/niagara.h ) (1 diff)
-
fb/port/ski.c (moved) (moved from uspace/srv/hid/fb/ski.c ) (3 diffs)
-
fb/port/ski.h (moved) (moved from uspace/srv/hid/fb/ski.h ) (2 diffs)
-
fb/proto/vt100.c (added)
-
fb/proto/vt100.h (added)
-
fb/serial_console.c (deleted)
-
input/Makefile (modified) (2 diffs)
-
input/ctl/kbdev.c (modified) (2 diffs)
-
input/generic/input.c (modified) (14 diffs)
-
input/include/input.h (modified) (2 diffs)
-
input/include/mouse.h (modified) (1 diff)
-
input/include/mouse_proto.h (modified) (1 diff)
-
input/port/chardev.c (modified) (1 diff)
-
input/port/chardev_mouse.c (deleted)
-
input/port/gxemul.c (modified) (4 diffs)
-
input/port/msim.c (modified) (4 diffs)
-
input/port/niagara.c (modified) (3 diffs)
-
input/port/ns16550.c (modified) (6 diffs)
-
input/port/pl050.c (modified) (4 diffs)
-
input/proto/adb.c (modified) (1 diff)
-
input/proto/mousedev.c (modified) (7 diffs)
-
input/proto/ps2.c (deleted)
-
remcons/Makefile (added)
-
remcons/remcons.c (added)
-
remcons/remcons.h (moved) (moved from uspace/drv/bus/usb/uhci/iface.h ) (2 diffs)
-
remcons/telnet.h (moved) (moved from uspace/lib/usbdev/src/pipepriv.h ) (2 diffs)
-
remcons/user.c (added)
-
remcons/user.h (added)
-
s3c24xx_ts/s3c24xx_ts.c (modified) (9 diffs)
-
s3c24xx_ts/s3c24xx_ts.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/console/Makefile
rbd5f3b7 r00aece0 29 29 30 30 USPACE_PREFIX = ../../.. 31 LIBS = $(LIB IMGMAP_PREFIX)/libimgmap.a32 EXTRA_CFLAGS += -I$(LIB IMGMAP_PREFIX)31 LIBS = $(LIBFB_PREFIX)/libfb.a 32 EXTRA_CFLAGS += -I$(LIBFB_PREFIX) 33 33 BINARY = console 34 34 35 35 SOURCES = \ 36 36 console.c \ 37 keybuffer.c \ 38 images.c \ 39 gcons.c 37 images.c 40 38 41 39 IMAGES = \ 42 40 gfx/helenos.tga \ 43 41 gfx/nameic.tga \ 44 gfx/cons_selected.tga \ 42 gfx/cons_data.tga \ 43 gfx/cons_dis.tga \ 44 gfx/cons_dis_sel.tga \ 45 45 gfx/cons_idle.tga \ 46 gfx/cons_ has_data.tga \46 gfx/cons_sel.tga \ 47 47 gfx/cons_kernel.tga \ 48 48 gfx/anim_1.tga \ -
uspace/srv/hid/console/console.c
rbd5f3b7 r00aece0 1 1 /* 2 * Copyright (c) 2006 Josef Cejka 3 * Copyright (c) 2011 Jiri Svoboda 2 * Copyright (c) 2011 Martin Decky 4 3 * All rights reserved. 5 4 * … … 34 33 */ 35 34 36 #include <libc.h> 35 #include <async.h> 36 #include <stdio.h> 37 #include <adt/prodcons.h> 37 38 #include <ipc/input.h> 38 #include <io/keycode.h> 39 #include <ipc/fb.h> 40 #include <ipc/services.h> 41 #include <ns.h> 42 #include <ns_obsolete.h> 39 #include <ipc/console.h> 40 #include <ipc/vfs.h> 43 41 #include <errno.h> 44 42 #include <str_error.h> 45 #include <ipc/console.h> 46 #include <unistd.h> 47 #include <async.h> 48 #include <async_obsolete.h> 49 #include <adt/fifo.h> 50 #include <sys/mman.h> 51 #include <stdio.h> 52 #include <str.h> 53 #include <sysinfo.h> 43 #include <loc.h> 54 44 #include <event.h> 55 #include <loc.h> 56 #include <fcntl.h> 57 #include <vfs/vfs.h> 45 #include <io/keycode.h> 46 #include <screenbuffer.h> 47 #include <fb.h> 48 #include <imgmap.h> 49 #include <align.h> 50 #include <malloc.h> 51 #include <as.h> 58 52 #include <fibril_synch.h> 59 #include <io/style.h> 60 #include <io/screenbuffer.h> 61 53 #include "images.h" 62 54 #include "console.h" 63 #include "gcons.h"64 #include "keybuffer.h"65 55 66 56 #define NAME "console" 67 57 #define NAMESPACE "term" 68 58 69 /** Session with the input server. */ 59 #define CONSOLE_TOP 66 60 #define CONSOLE_MARGIN 12 61 62 #define STATE_START 100 63 #define STATE_TOP 8 64 #define STATE_SPACE 4 65 #define STATE_WIDTH 48 66 #define STATE_HEIGHT 48 67 68 typedef enum { 69 CONS_DISCONNECTED = 0, 70 CONS_DISCONNECTED_SELECTED, 71 CONS_SELECTED, 72 CONS_IDLE, 73 CONS_DATA, 74 CONS_KERNEL, 75 CONS_LAST 76 } console_state_t; 77 78 typedef struct { 79 atomic_t refcnt; /**< Connection reference count */ 80 prodcons_t input_pc; /**< Incoming keyboard events */ 81 82 fibril_mutex_t mtx; /**< Lock protecting mutable fields */ 83 84 size_t index; /**< Console index */ 85 console_state_t state; /**< Console state */ 86 service_id_t dsid; /**< Service handle */ 87 88 vp_handle_t state_vp; /**< State icon viewport */ 89 sysarg_t cols; /**< Number of columns */ 90 sysarg_t rows; /**< Number of rows */ 91 console_caps_t ccaps; /**< Console capabilities */ 92 93 screenbuffer_t *frontbuf; /**< Front buffer */ 94 frontbuf_handle_t fbid; /**< Front buffer handle */ 95 } console_t; 96 97 typedef enum { 98 GRAPHICS_NONE = 0, 99 GRAPHICS_BASIC = 1, 100 GRAPHICS_FULL = 2 101 } graphics_state_t; 102 103 /** Current console state */ 104 static graphics_state_t graphics_state = GRAPHICS_NONE; 105 106 /** State icons */ 107 static imagemap_handle_t state_icons[CONS_LAST]; 108 109 /** Session to the input server */ 70 110 static async_sess_t *input_sess; 71 111 72 /** Information about framebuffer */ 73 struct { 74 int phone; /**< Framebuffer phone */ 75 sysarg_t cols; /**< Framebuffer columns */ 76 sysarg_t rows; /**< Framebuffer rows */ 77 sysarg_t color_cap; /**< Color capabilities (FB_CCAP_xxx) */ 78 } fb_info; 79 80 typedef struct { 81 size_t index; /**< Console index */ 82 size_t refcount; /**< Connection reference count */ 83 service_id_t service_id; /**< Service ID */ 84 keybuffer_t keybuffer; /**< Buffer for incoming keys. */ 85 screenbuffer_t scr; /**< Screenbuffer for saving screen 86 contents and related settings. */ 87 } console_t; 112 /** Session to the framebuffer server */ 113 static async_sess_t *fb_sess; 114 115 /** Framebuffer resolution */ 116 static sysarg_t xres; 117 static sysarg_t yres; 88 118 89 119 /** Array of data for virtual consoles */ 90 120 static console_t consoles[CONSOLE_COUNT]; 91 121 122 /** Mutex for console switching */ 123 static FIBRIL_MUTEX_INITIALIZE(switch_mtx); 124 125 static console_t *prev_console = &consoles[0]; 92 126 static console_t *active_console = &consoles[0]; 93 static console_t *prev_console = &consoles[0];94 127 static console_t *kernel_console = &consoles[KERNEL_CONSOLE]; 95 128 96 /** Pointer to memory shared with framebufer used for 97 faster virtual console switching */ 98 static keyfield_t *interbuffer = NULL; 99 100 /** Information on row-span yet unsent to FB driver. */ 129 static imgmap_t *logo_img; 130 static imgmap_t *nameic_img; 131 132 static imgmap_t *anim_1_img; 133 static imgmap_t *anim_2_img; 134 static imgmap_t *anim_3_img; 135 static imgmap_t *anim_4_img; 136 137 static imagemap_handle_t anim_1; 138 static imagemap_handle_t anim_2; 139 static imagemap_handle_t anim_3; 140 static imagemap_handle_t anim_4; 141 142 static sequence_handle_t anim_seq; 143 144 static imgmap_t *cons_data_img; 145 static imgmap_t *cons_dis_img; 146 static imgmap_t *cons_dis_sel_img; 147 static imgmap_t *cons_idle_img; 148 static imgmap_t *cons_kernel_img; 149 static imgmap_t *cons_sel_img; 150 151 static vp_handle_t logo_vp; 152 static imagemap_handle_t logo_handle; 153 154 static vp_handle_t nameic_vp; 155 static imagemap_handle_t nameic_handle; 156 157 static vp_handle_t screen_vp; 158 static vp_handle_t console_vp; 159 101 160 struct { 102 sysarg_t col; /**< Leftmost column of the span. */ 103 sysarg_t row; /**< Row where the span lies. */ 104 sysarg_t cnt; /**< Width of the span. */ 105 } fb_pending; 106 107 static FIBRIL_MUTEX_INITIALIZE(input_mutex); 108 static FIBRIL_CONDVAR_INITIALIZE(input_cv); 109 110 static FIBRIL_MUTEX_INITIALIZE(big_console_lock); 111 112 static void console_serialize_start(void) 113 { 114 fibril_mutex_lock(&big_console_lock); 115 } 116 117 static void console_serialize_end(void) 118 { 119 fibril_mutex_unlock(&big_console_lock); 120 } 121 122 static void curs_visibility(bool visible) 123 { 124 async_obsolete_msg_1(fb_info.phone, FB_CURSOR_VISIBILITY, visible); 125 } 126 127 static void curs_hide_sync(void) 128 { 129 async_obsolete_req_1_0(fb_info.phone, FB_CURSOR_VISIBILITY, false); 130 } 131 132 static void curs_goto(sysarg_t x, sysarg_t y) 133 { 134 async_obsolete_msg_2(fb_info.phone, FB_CURSOR_GOTO, x, y); 135 } 136 137 static void screen_clear(void) 138 { 139 async_obsolete_msg_0(fb_info.phone, FB_CLEAR); 140 } 141 142 static void screen_yield(void) 143 { 144 async_obsolete_req_0_0(fb_info.phone, FB_SCREEN_YIELD); 145 } 146 147 static void screen_reclaim(void) 148 { 149 async_obsolete_req_0_0(fb_info.phone, FB_SCREEN_RECLAIM); 150 } 151 152 static void input_yield(void) 153 { 154 async_exch_t *exch = async_exchange_begin(input_sess); 155 if (exch == NULL) { 156 printf("%s: Failed starting exchange with input device.\n", 157 NAME); 161 sysarg_t x; 162 sysarg_t y; 163 164 sysarg_t btn_x; 165 sysarg_t btn_y; 166 167 bool pressed; 168 } mouse; 169 170 static void cons_redraw_state(console_t *cons) 171 { 172 if (graphics_state == GRAPHICS_FULL) { 173 fibril_mutex_lock(&cons->mtx); 174 175 fb_vp_imagemap_damage(fb_sess, cons->state_vp, 176 state_icons[cons->state], 0, 0, STATE_WIDTH, STATE_HEIGHT); 177 178 if ((cons->state != CONS_DISCONNECTED) && 179 (cons->state != CONS_KERNEL) && 180 (cons->state != CONS_DISCONNECTED_SELECTED)) { 181 char data[5]; 182 snprintf(data, 5, "%zu", cons->index + 1); 183 184 for (size_t i = 0; data[i] != 0; i++) 185 fb_vp_putchar(fb_sess, cons->state_vp, i + 2, 1, data[i]); 186 } 187 188 fibril_mutex_unlock(&cons->mtx); 189 } 190 } 191 192 static void cons_kernel_sequence_start(console_t *cons) 193 { 194 if (graphics_state == GRAPHICS_FULL) { 195 fibril_mutex_lock(&cons->mtx); 196 197 fb_vp_sequence_start(fb_sess, cons->state_vp, anim_seq); 198 fb_vp_imagemap_damage(fb_sess, cons->state_vp, 199 state_icons[cons->state], 0, 0, STATE_WIDTH, STATE_HEIGHT); 200 201 fibril_mutex_unlock(&cons->mtx); 202 } 203 } 204 205 static void cons_update_state(console_t *cons, console_state_t state) 206 { 207 bool update = false; 208 209 fibril_mutex_lock(&cons->mtx); 210 211 if (cons->state != state) { 212 cons->state = state; 213 update = true; 214 } 215 216 fibril_mutex_unlock(&cons->mtx); 217 218 if (update) 219 cons_redraw_state(cons); 220 } 221 222 static void cons_notify_data(console_t *cons) 223 { 224 fibril_mutex_lock(&switch_mtx); 225 226 if (cons != active_console) 227 cons_update_state(cons, CONS_DATA); 228 229 fibril_mutex_unlock(&switch_mtx); 230 } 231 232 static void cons_notify_connect(console_t *cons) 233 { 234 fibril_mutex_lock(&switch_mtx); 235 236 if (cons == active_console) 237 cons_update_state(cons, CONS_SELECTED); 238 else 239 cons_update_state(cons, CONS_IDLE); 240 241 fibril_mutex_unlock(&switch_mtx); 242 } 243 244 static void cons_notify_disconnect(console_t *cons) 245 { 246 fibril_mutex_lock(&switch_mtx); 247 248 if (cons == active_console) 249 cons_update_state(cons, CONS_DISCONNECTED_SELECTED); 250 else 251 cons_update_state(cons, CONS_DISCONNECTED); 252 253 fibril_mutex_unlock(&switch_mtx); 254 } 255 256 static void cons_update(console_t *cons) 257 { 258 fibril_mutex_lock(&switch_mtx); 259 fibril_mutex_lock(&cons->mtx); 260 261 if ((cons == active_console) && (active_console != kernel_console)) { 262 fb_vp_update(fb_sess, console_vp, cons->fbid); 263 fb_vp_cursor_update(fb_sess, console_vp, cons->fbid); 264 } 265 266 fibril_mutex_unlock(&cons->mtx); 267 fibril_mutex_unlock(&switch_mtx); 268 } 269 270 static void cons_update_cursor(console_t *cons) 271 { 272 fibril_mutex_lock(&switch_mtx); 273 fibril_mutex_lock(&cons->mtx); 274 275 if ((cons == active_console) && (active_console != kernel_console)) 276 fb_vp_cursor_update(fb_sess, console_vp, cons->fbid); 277 278 fibril_mutex_unlock(&cons->mtx); 279 fibril_mutex_unlock(&switch_mtx); 280 } 281 282 static void cons_clear(console_t *cons) 283 { 284 fibril_mutex_lock(&cons->mtx); 285 screenbuffer_clear(cons->frontbuf); 286 fibril_mutex_unlock(&cons->mtx); 287 288 cons_update(cons); 289 } 290 291 static void cons_damage_all(console_t *cons) 292 { 293 fibril_mutex_lock(&switch_mtx); 294 fibril_mutex_lock(&cons->mtx); 295 296 if ((cons == active_console) && (active_console != kernel_console)) { 297 fb_vp_damage(fb_sess, console_vp, cons->fbid, 0, 0, cons->cols, 298 cons->rows); 299 fb_vp_cursor_update(fb_sess, console_vp, cons->fbid); 300 } 301 302 fibril_mutex_unlock(&cons->mtx); 303 fibril_mutex_unlock(&switch_mtx); 304 } 305 306 static void cons_switch(console_t *cons) 307 { 308 fibril_mutex_lock(&switch_mtx); 309 310 if (cons == active_console) { 311 fibril_mutex_unlock(&switch_mtx); 158 312 return; 159 313 } 160 314 161 async_req_0_0(exch, INPUT_YIELD); 162 async_exchange_end(exch); 163 } 164 165 static void input_reclaim(void) 166 { 167 async_exch_t *exch = async_exchange_begin(input_sess); 168 if (exch == NULL) { 169 printf("%s: Failed starting exchange with input device.\n", 170 NAME); 171 return; 172 } 173 174 async_req_0_0(exch, INPUT_RECLAIM); 175 async_exchange_end(exch); 176 } 177 178 static void set_style(uint8_t style) 179 { 180 async_obsolete_msg_1(fb_info.phone, FB_SET_STYLE, style); 181 } 182 183 static void set_color(uint8_t fgcolor, uint8_t bgcolor, uint8_t flags) 184 { 185 async_obsolete_msg_3(fb_info.phone, FB_SET_COLOR, fgcolor, bgcolor, flags); 186 } 187 188 static void set_rgb_color(uint32_t fgcolor, uint32_t bgcolor) 189 { 190 async_obsolete_msg_2(fb_info.phone, FB_SET_RGB_COLOR, fgcolor, bgcolor); 191 } 192 193 static void set_attrs(attrs_t *attrs) 194 { 195 switch (attrs->t) { 196 case at_style: 197 set_style(attrs->a.s.style); 198 break; 199 case at_idx: 200 set_color(attrs->a.i.fg_color, attrs->a.i.bg_color, 201 attrs->a.i.flags); 202 break; 203 case at_rgb: 204 set_rgb_color(attrs->a.r.fg_color, attrs->a.r.bg_color); 205 break; 206 } 207 } 208 209 static int ccap_fb_to_con(sysarg_t ccap_fb, sysarg_t *ccap_con) 210 { 211 switch (ccap_fb) { 212 case FB_CCAP_NONE: 213 *ccap_con = CONSOLE_CCAP_NONE; 214 break; 215 case FB_CCAP_STYLE: 216 *ccap_con = CONSOLE_CCAP_STYLE; 217 break; 218 case FB_CCAP_INDEXED: 219 *ccap_con = CONSOLE_CCAP_INDEXED; 220 break; 221 case FB_CCAP_RGB: 222 *ccap_con = CONSOLE_CCAP_RGB; 223 break; 224 default: 225 return EINVAL; 226 } 227 228 return EOK; 229 } 230 231 /** Send an area of screenbuffer to the FB driver. */ 232 static void fb_update_area(console_t *cons, sysarg_t x0, sysarg_t y0, sysarg_t width, sysarg_t height) 233 { 234 if (interbuffer) { 235 sysarg_t x; 236 sysarg_t y; 237 238 for (y = 0; y < height; y++) { 239 for (x = 0; x < width; x++) { 240 interbuffer[y * width + x] = 241 *get_field_at(&cons->scr, x0 + x, y0 + y); 242 } 243 } 244 245 async_obsolete_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA, 246 x0, y0, width, height); 247 } 248 } 249 250 /** Flush pending cells to FB. */ 251 static void fb_pending_flush(void) 252 { 253 if (fb_pending.cnt > 0) { 254 fb_update_area(active_console, fb_pending.col, 255 fb_pending.row, fb_pending.cnt, 1); 256 fb_pending.cnt = 0; 257 } 258 } 259 260 /** Mark a character cell as changed. 315 if (cons == kernel_console) { 316 fb_yield(fb_sess); 317 if (!console_kcon()) { 318 fb_claim(fb_sess); 319 fibril_mutex_unlock(&switch_mtx); 320 return; 321 } 322 } 323 324 if (active_console == kernel_console) 325 fb_claim(fb_sess); 326 327 prev_console = active_console; 328 active_console = cons; 329 330 if (prev_console->state == CONS_DISCONNECTED_SELECTED) 331 cons_update_state(prev_console, CONS_DISCONNECTED); 332 else 333 cons_update_state(prev_console, CONS_IDLE); 334 335 if ((cons->state == CONS_DISCONNECTED) || 336 (cons->state == CONS_DISCONNECTED_SELECTED)) 337 cons_update_state(cons, CONS_DISCONNECTED_SELECTED); 338 else 339 cons_update_state(cons, CONS_SELECTED); 340 341 fibril_mutex_unlock(&switch_mtx); 342 343 cons_damage_all(cons); 344 } 345 346 static console_t *cons_get_active_uspace(void) 347 { 348 fibril_mutex_lock(&switch_mtx); 349 350 console_t *active_uspace = active_console; 351 if (active_uspace == kernel_console) { 352 active_uspace = prev_console; 353 } 354 assert(active_uspace != kernel_console); 355 356 fibril_mutex_unlock(&switch_mtx); 357 358 return active_uspace; 359 } 360 361 static ssize_t limit(ssize_t val, ssize_t lo, ssize_t hi) 362 { 363 if (val > hi) 364 return hi; 365 366 if (val < lo) 367 return lo; 368 369 return val; 370 } 371 372 static void cons_mouse_move(sysarg_t dx, sysarg_t dy) 373 { 374 ssize_t sx = (ssize_t) dx; 375 ssize_t sy = (ssize_t) dy; 376 377 mouse.x = limit(mouse.x + sx, 0, xres); 378 mouse.y = limit(mouse.y + sy, 0, yres); 379 380 fb_pointer_update(fb_sess, mouse.x, mouse.y, true); 381 } 382 383 static console_t *cons_find_icon(sysarg_t x, sysarg_t y) 384 { 385 sysarg_t status_start = 386 STATE_START + (xres - 800) / 2 + CONSOLE_MARGIN; 387 388 if ((y < STATE_TOP) || (y >= STATE_TOP + STATE_HEIGHT)) 389 return NULL; 390 391 if (x < status_start) 392 return NULL; 393 394 if (x >= status_start + (STATE_WIDTH + STATE_SPACE) * CONSOLE_COUNT) 395 return NULL; 396 397 if (((x - status_start) % (STATE_WIDTH + STATE_SPACE)) >= STATE_WIDTH) 398 return NULL; 399 400 sysarg_t btn = (x - status_start) / (STATE_WIDTH + STATE_SPACE); 401 402 if (btn < CONSOLE_COUNT) 403 return consoles + btn; 404 405 return NULL; 406 } 407 408 /** Handle mouse click 261 409 * 262 * This adds the cell to the pending rowspan if possible. Otherwise 263 * the old span is flushed first. 410 * @param state Button state (true - pressed, false - depressed) 264 411 * 265 412 */ 266 static void cell_mark_changed(sysarg_t col, sysarg_t row) 267 { 268 if (fb_pending.cnt != 0) { 269 if ((col != fb_pending.col + fb_pending.cnt) 270 || (row != fb_pending.row)) { 271 fb_pending_flush(); 272 } 273 } 274 275 if (fb_pending.cnt == 0) { 276 fb_pending.col = col; 277 fb_pending.row = row; 278 } 279 280 fb_pending.cnt++; 281 } 282 283 /** Print a character to the active VC with buffering. */ 284 static void fb_putchar(wchar_t c, sysarg_t col, sysarg_t row) 285 { 286 async_obsolete_msg_3(fb_info.phone, FB_PUTCHAR, c, col, row); 413 static console_t *cons_mouse_button(bool state) 414 { 415 if (graphics_state != GRAPHICS_FULL) 416 return NULL; 417 418 if (state) { 419 console_t *cons = cons_find_icon(mouse.x, mouse.y); 420 if (cons != NULL) { 421 mouse.btn_x = mouse.x; 422 mouse.btn_y = mouse.y; 423 mouse.pressed = true; 424 } 425 426 return NULL; 427 } 428 429 if ((!state) && (!mouse.pressed)) 430 return NULL; 431 432 console_t *cons = cons_find_icon(mouse.x, mouse.y); 433 if (cons == cons_find_icon(mouse.btn_x, mouse.btn_y)) 434 return cons; 435 436 mouse.pressed = false; 437 return NULL; 438 } 439 440 static void input_events(ipc_callid_t iid, ipc_call_t *icall, void *arg) 441 { 442 /* Ignore parameters, the connection is already opened */ 443 while (true) { 444 ipc_call_t call; 445 ipc_callid_t callid = async_get_call(&call); 446 447 if (!IPC_GET_IMETHOD(call)) { 448 /* TODO: Handle hangup */ 449 async_hangup(input_sess); 450 return; 451 } 452 453 kbd_event_type_t type; 454 keycode_t key; 455 keymod_t mods; 456 wchar_t c; 457 458 switch (IPC_GET_IMETHOD(call)) { 459 case INPUT_EVENT_KEY: 460 type = IPC_GET_ARG1(call); 461 key = IPC_GET_ARG2(call); 462 mods = IPC_GET_ARG3(call); 463 c = IPC_GET_ARG4(call); 464 465 if ((key >= KC_F1) && (key < KC_F1 + CONSOLE_COUNT) && 466 ((mods & KM_CTRL) == 0)) 467 cons_switch(&consoles[key - KC_F1]); 468 else { 469 /* Got key press/release event */ 470 kbd_event_t *event = 471 (kbd_event_t *) malloc(sizeof(kbd_event_t)); 472 if (event == NULL) { 473 async_answer_0(callid, ENOMEM); 474 break; 475 } 476 477 link_initialize(&event->link); 478 event->type = type; 479 event->key = key; 480 event->mods = mods; 481 event->c = c; 482 483 /* 484 * Kernel console does not read events 485 * from us, so we will redirect them 486 * to the (last) active userspace console 487 * if necessary. 488 */ 489 console_t *target_console = cons_get_active_uspace(); 490 491 prodcons_produce(&target_console->input_pc, 492 &event->link); 493 } 494 495 async_answer_0(callid, EOK); 496 break; 497 case INPUT_EVENT_MOVE: 498 cons_mouse_move(IPC_GET_ARG1(call), IPC_GET_ARG2(call)); 499 async_answer_0(callid, EOK); 500 break; 501 case INPUT_EVENT_BUTTON: 502 /* Got pointer button press/release event */ 503 if (IPC_GET_ARG1(call) == 1) { 504 console_t *cons = 505 cons_mouse_button((bool) IPC_GET_ARG2(call)); 506 if (cons != NULL) 507 cons_switch(cons); 508 } 509 async_answer_0(callid, EOK); 510 break; 511 default: 512 async_answer_0(callid, EINVAL); 513 } 514 } 287 515 } 288 516 289 517 /** Process a character from the client (TTY emulation). */ 290 static void write_char(console_t *cons, wchar_t ch) 291 { 292 bool flush_cursor = false; 518 static void cons_write_char(console_t *cons, wchar_t ch) 519 { 520 sysarg_t updated = 0; 521 522 fibril_mutex_lock(&cons->mtx); 293 523 294 524 switch (ch) { 295 525 case '\n': 296 fb_pending_flush(); 297 flush_cursor = true; 298 cons->scr.position_y++; 299 cons->scr.position_x = 0; 526 updated = screenbuffer_newline(cons->frontbuf); 300 527 break; 301 528 case '\r': 302 529 break; 303 530 case '\t': 304 cons->scr.position_x += 8; 305 cons->scr.position_x -= cons->scr.position_x % 8; 531 updated = screenbuffer_tabstop(cons->frontbuf, 8); 306 532 break; 307 533 case '\b': 308 if (cons->scr.position_x == 0) 309 break; 310 cons->scr.position_x--; 311 if (cons == active_console) 312 cell_mark_changed(cons->scr.position_x, cons->scr.position_y); 313 screenbuffer_putchar(&cons->scr, ' '); 534 updated = screenbuffer_backspace(cons->frontbuf); 314 535 break; 315 536 default: 316 if (cons == active_console) 317 cell_mark_changed(cons->scr.position_x, cons->scr.position_y); 318 319 screenbuffer_putchar(&cons->scr, ch); 320 cons->scr.position_x++; 321 } 322 323 if (cons->scr.position_x >= cons->scr.size_x) { 324 flush_cursor = true; 325 cons->scr.position_y++; 326 } 327 328 if (cons->scr.position_y >= cons->scr.size_y) { 329 fb_pending_flush(); 330 cons->scr.position_y = cons->scr.size_y - 1; 331 screenbuffer_clear_line(&cons->scr, cons->scr.top_line); 332 cons->scr.top_line = (cons->scr.top_line + 1) % cons->scr.size_y; 333 334 if (cons == active_console) 335 async_obsolete_msg_1(fb_info.phone, FB_SCROLL, 1); 336 } 337 338 if (cons == active_console && flush_cursor) 339 curs_goto(cons->scr.position_x, cons->scr.position_y); 340 cons->scr.position_x = cons->scr.position_x % cons->scr.size_x; 341 } 342 343 /** Switch to new console */ 344 static void change_console(console_t *cons) 345 { 346 if (cons == active_console) 347 return; 348 349 fb_pending_flush(); 350 351 if (cons == kernel_console) { 352 console_serialize_start(); 353 curs_hide_sync(); 354 gcons_in_kernel(); 355 screen_yield(); 356 input_yield(); 357 console_serialize_end(); 358 359 if (console_kcon()) { 360 prev_console = active_console; 361 active_console = kernel_console; 362 } else 363 cons = active_console; 364 } 365 366 if (cons != kernel_console) { 367 console_serialize_start(); 368 369 if (active_console == kernel_console) { 370 screen_reclaim(); 371 input_reclaim(); 372 gcons_redraw_console(); 373 } 374 375 active_console = cons; 376 gcons_change_console(cons->index); 377 378 set_attrs(&cons->scr.attrs); 379 curs_visibility(false); 380 381 sysarg_t x; 382 sysarg_t y; 383 int rc = 0; 384 385 if (interbuffer) { 386 for (y = 0; y < cons->scr.size_y; y++) { 387 for (x = 0; x < cons->scr.size_x; x++) { 388 interbuffer[y * cons->scr.size_x + x] = 389 *get_field_at(&cons->scr, x, y); 390 } 391 } 392 393 /* This call can preempt, but we are already at the end */ 394 rc = async_obsolete_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA, 395 0, 0, cons->scr.size_x, 396 cons->scr.size_y); 397 } 398 399 if ((!interbuffer) || (rc != 0)) { 400 set_attrs(&cons->scr.attrs); 401 screen_clear(); 402 403 for (y = 0; y < cons->scr.size_y; y++) 404 for (x = 0; x < cons->scr.size_x; x++) { 405 keyfield_t *field = get_field_at(&cons->scr, x, y); 406 407 if (!attrs_same(cons->scr.attrs, field->attrs)) 408 set_attrs(&field->attrs); 409 410 cons->scr.attrs = field->attrs; 411 if ((field->character == ' ') && 412 (attrs_same(field->attrs, cons->scr.attrs))) 413 continue; 414 415 fb_putchar(field->character, x, y); 416 } 417 } 418 419 curs_goto(cons->scr.position_x, cons->scr.position_y); 420 curs_visibility(cons->scr.is_cursor_visible); 421 422 console_serialize_end(); 423 } 424 } 425 426 /** Handler for input events */ 427 static void input_events(ipc_callid_t iid, ipc_call_t *icall, void *arg) 428 { 429 /* Ignore parameters, the connection is already opened */ 430 while (true) { 431 ipc_call_t call; 432 ipc_callid_t callid = async_get_call(&call); 433 434 int retval; 435 kbd_event_t ev; 436 437 if (!IPC_GET_IMETHOD(call)) { 438 /* TODO: Handle hangup */ 439 async_hangup(input_sess); 440 return; 441 } 442 443 switch (IPC_GET_IMETHOD(call)) { 444 case INPUT_EVENT_KEY: 445 /* Got key press/release event */ 446 retval = 0; 447 ev.type = IPC_GET_ARG1(call); 448 ev.key = IPC_GET_ARG2(call); 449 ev.mods = IPC_GET_ARG3(call); 450 ev.c = IPC_GET_ARG4(call); 451 452 if ((ev.key >= KC_F1) && (ev.key < KC_F1 + 453 CONSOLE_COUNT) && ((ev.mods & KM_CTRL) == 0)) { 454 if (ev.key == KC_F1 + KERNEL_CONSOLE) 455 change_console(kernel_console); 456 else 457 change_console(&consoles[ev.key - KC_F1]); 458 break; 459 } 460 461 fibril_mutex_lock(&input_mutex); 462 keybuffer_push(&active_console->keybuffer, &ev); 463 fibril_condvar_broadcast(&input_cv); 464 fibril_mutex_unlock(&input_mutex); 465 break; 466 case INPUT_EVENT_MOVE: 467 /* Got pointer move event */ 468 gcons_mouse_move((int) IPC_GET_ARG1(call), 469 (int) IPC_GET_ARG2(call)); 470 retval = 0; 471 break; 472 case INPUT_EVENT_BUTTON: 473 /* Got pointer button press/release event */ 474 if (IPC_GET_ARG1(call) == 1) { 475 int newcon = gcons_mouse_btn((bool) IPC_GET_ARG2(call)); 476 if (newcon != -1) 477 change_console(&consoles[newcon]); 478 } 479 retval = 0; 480 break; 481 default: 482 retval = ENOENT; 483 } 484 485 async_answer_0(callid, retval); 486 } 487 } 488 489 static void cons_write(console_t *cons, ipc_callid_t rid, ipc_call_t *request) 537 updated = screenbuffer_putchar(cons->frontbuf, ch, true); 538 } 539 540 fibril_mutex_unlock(&cons->mtx); 541 542 if (updated > 1) 543 cons_update(cons); 544 } 545 546 static void cons_set_cursor(console_t *cons, sysarg_t col, sysarg_t row) 547 { 548 fibril_mutex_lock(&cons->mtx); 549 screenbuffer_set_cursor(cons->frontbuf, col, row); 550 fibril_mutex_unlock(&cons->mtx); 551 552 cons_update_cursor(cons); 553 } 554 555 static void cons_set_cursor_visibility(console_t *cons, bool visible) 556 { 557 fibril_mutex_lock(&cons->mtx); 558 screenbuffer_set_cursor_visibility(cons->frontbuf, visible); 559 fibril_mutex_unlock(&cons->mtx); 560 561 cons_update_cursor(cons); 562 } 563 564 static void cons_get_cursor(console_t *cons, ipc_callid_t iid, ipc_call_t *icall) 565 { 566 sysarg_t col; 567 sysarg_t row; 568 569 fibril_mutex_lock(&cons->mtx); 570 screenbuffer_get_cursor(cons->frontbuf, &col, &row); 571 fibril_mutex_unlock(&cons->mtx); 572 573 async_answer_2(iid, EOK, col, row); 574 } 575 576 static void cons_write(console_t *cons, ipc_callid_t iid, ipc_call_t *icall) 490 577 { 491 578 void *buf; … … 494 581 495 582 if (rc != EOK) { 496 async_answer_0( rid, rc);583 async_answer_0(iid, rc); 497 584 return; 498 585 } 499 586 500 console_serialize_start();501 502 587 size_t off = 0; 503 while (off < size) { 504 wchar_t ch = str_decode(buf, &off, size); 505 write_char(cons, ch); 506 } 507 508 console_serialize_end(); 509 510 gcons_notify_char(cons->index); 511 async_answer_1(rid, EOK, size); 512 588 while (off < size) 589 cons_write_char(cons, str_decode(buf, &off, size)); 590 591 async_answer_1(iid, EOK, size); 513 592 free(buf); 514 } 515 516 static void cons_read(console_t *cons, ipc_callid_t rid, ipc_call_t *request) 593 594 cons_notify_data(cons); 595 } 596 597 static void cons_read(console_t *cons, ipc_callid_t iid, ipc_call_t *icall) 517 598 { 518 599 ipc_callid_t callid; … … 520 601 if (!async_data_read_receive(&callid, &size)) { 521 602 async_answer_0(callid, EINVAL); 522 async_answer_0( rid, EINVAL);603 async_answer_0(iid, EINVAL); 523 604 return; 524 605 } … … 527 608 if (buf == NULL) { 528 609 async_answer_0(callid, ENOMEM); 529 async_answer_0( rid, ENOMEM);610 async_answer_0(iid, ENOMEM); 530 611 return; 531 612 } 532 613 533 614 size_t pos = 0; 534 kbd_event_t ev; 535 fibril_mutex_lock(&input_mutex); 536 537 recheck: 538 while ((keybuffer_pop(&cons->keybuffer, &ev)) && (pos < size)) { 539 if (ev.type == KEY_PRESS) { 540 buf[pos] = ev.c; 615 while (pos < size) { 616 link_t *link = prodcons_consume(&cons->input_pc); 617 kbd_event_t *event = list_get_instance(link, kbd_event_t, link); 618 619 if (event->type == KEY_PRESS) { 620 buf[pos] = event->c; 541 621 pos++; 542 622 } 543 } 544 545 if (pos == size) { 546 (void) async_data_read_finalize(callid, buf, size); 547 async_answer_1(rid, EOK, size); 548 free(buf); 549 } else { 550 fibril_condvar_wait(&input_cv, &input_mutex); 551 goto recheck; 552 } 553 554 fibril_mutex_unlock(&input_mutex); 555 } 556 557 static void cons_get_event(console_t *cons, ipc_callid_t rid, ipc_call_t *request) 558 { 559 kbd_event_t ev; 560 561 fibril_mutex_lock(&input_mutex); 562 563 recheck: 564 if (keybuffer_pop(&cons->keybuffer, &ev)) { 565 async_answer_4(rid, EOK, ev.type, ev.key, ev.mods, ev.c); 566 } else { 567 fibril_condvar_wait(&input_cv, &input_mutex); 568 goto recheck; 569 } 570 571 fibril_mutex_unlock(&input_mutex); 572 } 573 574 /** Default thread for new connections */ 623 624 free(event); 625 } 626 627 (void) async_data_read_finalize(callid, buf, size); 628 async_answer_1(iid, EOK, size); 629 free(buf); 630 } 631 632 static void cons_set_style(console_t *cons, console_style_t style) 633 { 634 fibril_mutex_lock(&cons->mtx); 635 screenbuffer_set_style(cons->frontbuf, style); 636 fibril_mutex_unlock(&cons->mtx); 637 } 638 639 static void cons_set_color(console_t *cons, console_color_t bgcolor, 640 console_color_t fgcolor, console_color_attr_t attr) 641 { 642 fibril_mutex_lock(&cons->mtx); 643 screenbuffer_set_color(cons->frontbuf, bgcolor, fgcolor, attr); 644 fibril_mutex_unlock(&cons->mtx); 645 } 646 647 static void cons_set_rgb_color(console_t *cons, pixel_t bgcolor, 648 pixel_t fgcolor) 649 { 650 fibril_mutex_lock(&cons->mtx); 651 screenbuffer_set_rgb_color(cons->frontbuf, bgcolor, fgcolor); 652 fibril_mutex_unlock(&cons->mtx); 653 } 654 655 static void cons_get_event(console_t *cons, ipc_callid_t iid, ipc_call_t *icall) 656 { 657 link_t *link = prodcons_consume(&cons->input_pc); 658 kbd_event_t *event = list_get_instance(link, kbd_event_t, link); 659 660 async_answer_4(iid, EOK, event->type, event->key, event->mods, event->c); 661 free(event); 662 } 663 575 664 static void client_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 576 665 { 577 666 console_t *cons = NULL; 578 667 579 size_t i; 580 for (i = 0; i < CONSOLE_COUNT; i++) { 668 for (size_t i = 0; i < CONSOLE_COUNT; i++) { 581 669 if (i == KERNEL_CONSOLE) 582 670 continue; 583 671 584 if (consoles[i]. service_id == (service_id_t) IPC_GET_ARG1(*icall)) {672 if (consoles[i].dsid == (service_id_t) IPC_GET_ARG1(*icall)) { 585 673 cons = &consoles[i]; 586 674 break; … … 593 681 } 594 682 595 ipc_callid_t callid; 596 ipc_call_t call; 597 sysarg_t arg1; 598 sysarg_t arg2; 599 sysarg_t arg3; 600 601 int rc; 602 603 console_serialize_start(); 604 if (cons->refcount == 0) 605 gcons_notify_connect(cons->index); 606 607 cons->refcount++; 683 if (atomic_postinc(&cons->refcnt) == 0) { 684 cons_set_cursor_visibility(cons, true); 685 cons_notify_connect(cons); 686 } 608 687 609 688 /* Accept the connection */ … … 611 690 612 691 while (true) { 613 console_serialize_end(); 614 callid = async_get_call(&call); 615 console_serialize_start(); 616 617 arg1 = 0; 618 arg2 = 0; 619 arg3 = 0; 692 ipc_call_t call; 693 ipc_callid_t callid = async_get_call(&call); 620 694 621 695 if (!IPC_GET_IMETHOD(call)) { 622 cons->refcount--; 623 if (cons->refcount == 0) 624 gcons_notify_disconnect(cons->index); 625 console_serialize_end(); 696 if (atomic_postdec(&cons->refcnt) == 1) 697 cons_notify_disconnect(cons); 698 626 699 return; 627 700 } … … 629 702 switch (IPC_GET_IMETHOD(call)) { 630 703 case VFS_OUT_READ: 631 console_serialize_end();632 704 cons_read(cons, callid, &call); 633 console_serialize_start(); 634 continue; 705 break; 635 706 case VFS_OUT_WRITE: 636 console_serialize_end();637 707 cons_write(cons, callid, &call); 638 console_serialize_start(); 639 continue; 708 break; 640 709 case VFS_OUT_SYNC: 641 fb_pending_flush(); 642 if (cons == active_console) { 643 async_obsolete_req_0_0(fb_info.phone, FB_FLUSH); 644 curs_goto(cons->scr.position_x, cons->scr.position_y); 645 } 710 cons_update(cons); 711 async_answer_0(callid, EOK); 646 712 break; 647 713 case CONSOLE_CLEAR: 648 /* Send message to fb */ 649 if (cons == active_console) 650 async_obsolete_msg_0(fb_info.phone, FB_CLEAR); 651 652 screenbuffer_clear(&cons->scr); 653 714 cons_clear(cons); 715 async_answer_0(callid, EOK); 654 716 break; 655 717 case CONSOLE_GOTO: 656 screenbuffer_goto(&cons->scr, 657 IPC_GET_ARG1(call), IPC_GET_ARG2(call)); 658 if (cons == active_console) 659 curs_goto(IPC_GET_ARG1(call), 660 IPC_GET_ARG2(call)); 718 cons_set_cursor(cons, IPC_GET_ARG1(call), IPC_GET_ARG2(call)); 719 async_answer_0(callid, EOK); 661 720 break; 662 721 case CONSOLE_GET_POS: 663 arg1 = cons->scr.position_x; 664 arg2 = cons->scr.position_y; 722 cons_get_cursor(cons, callid, &call); 665 723 break; 666 724 case CONSOLE_GET_SIZE: 667 arg1 = fb_info.cols; 668 arg2 = fb_info.rows; 725 async_answer_2(callid, EOK, cons->cols, cons->rows); 669 726 break; 670 727 case CONSOLE_GET_COLOR_CAP: 671 rc = ccap_fb_to_con(fb_info.color_cap, &arg1); 672 if (rc != EOK) { 673 async_answer_0(callid, rc); 674 continue; 675 } 728 async_answer_1(callid, EOK, cons->ccaps); 676 729 break; 677 730 case CONSOLE_SET_STYLE: 678 fb_pending_flush(); 679 arg1 = IPC_GET_ARG1(call); 680 screenbuffer_set_style(&cons->scr, arg1); 681 if (cons == active_console) 682 set_style(arg1); 731 cons_set_style(cons, IPC_GET_ARG1(call)); 732 async_answer_0(callid, EOK); 683 733 break; 684 734 case CONSOLE_SET_COLOR: 685 fb_pending_flush(); 686 arg1 = IPC_GET_ARG1(call); 687 arg2 = IPC_GET_ARG2(call); 688 arg3 = IPC_GET_ARG3(call); 689 screenbuffer_set_color(&cons->scr, arg1, arg2, arg3); 690 if (cons == active_console) 691 set_color(arg1, arg2, arg3); 735 cons_set_color(cons, IPC_GET_ARG1(call), IPC_GET_ARG2(call), 736 IPC_GET_ARG3(call)); 737 async_answer_0(callid, EOK); 692 738 break; 693 739 case CONSOLE_SET_RGB_COLOR: 694 fb_pending_flush(); 695 arg1 = IPC_GET_ARG1(call); 696 arg2 = IPC_GET_ARG2(call); 697 screenbuffer_set_rgb_color(&cons->scr, arg1, arg2); 698 if (cons == active_console) 699 set_rgb_color(arg1, arg2); 740 cons_set_rgb_color(cons, IPC_GET_ARG1(call), IPC_GET_ARG2(call)); 741 async_answer_0(callid, EOK); 700 742 break; 701 743 case CONSOLE_CURSOR_VISIBILITY: 702 fb_pending_flush(); 703 arg1 = IPC_GET_ARG1(call); 704 cons->scr.is_cursor_visible = arg1; 705 if (cons == active_console) 706 curs_visibility(arg1); 744 cons_set_cursor_visibility(cons, IPC_GET_ARG1(call)); 745 async_answer_0(callid, EOK); 707 746 break; 708 747 case CONSOLE_GET_EVENT: 709 console_serialize_end();710 748 cons_get_event(cons, callid, &call); 711 console_serialize_start(); 712 continue; 713 } 714 async_answer_3(callid, EOK, arg1, arg2, arg3); 715 } 716 } 717 718 static void interrupt_received(ipc_callid_t callid, ipc_call_t *call) 719 { 720 change_console(prev_console); 721 } 722 723 static async_sess_t *connect_input(const char *svc_path) 749 break; 750 default: 751 async_answer_0(callid, EINVAL); 752 } 753 } 754 } 755 756 static async_sess_t *input_connect(const char *svc) 724 757 { 725 758 async_sess_t *sess; 726 async_exch_t *exch; 727 service_id_t service_id; 728 729 int rc = loc_service_get_id(svc_path, &service_id, 0); 759 service_id_t dsid; 760 761 int rc = loc_service_get_id(svc, &dsid, 0); 730 762 if (rc == EOK) { 731 sess = loc_service_connect(EXCHANGE_ATOMIC, service_id, 0);763 sess = loc_service_connect(EXCHANGE_ATOMIC, dsid, 0); 732 764 if (sess == NULL) { 733 printf("%s: Failed to connect to input server\n", NAME); 765 printf("%s: Unable to connect to input service %s\n", NAME, 766 svc); 734 767 return NULL; 735 768 } 736 } else {769 } else 737 770 return NULL; 738 } 739 740 exch = async_exchange_begin(sess); 741 if (exch == NULL) { 742 printf("%s: Failed to create callback from input server.\n", NAME); 743 return NULL; 744 } 745 746 /* NB: The callback connection is slotted for removal */ 771 772 async_exch_t *exch = async_exchange_begin(sess); 747 773 rc = async_connect_to_me(exch, 0, 0, 0, input_events, NULL); 748 749 774 async_exchange_end(exch); 750 775 751 776 if (rc != EOK) { 752 777 async_hangup(sess); 753 printf("%s: Failed to create callback from input server (%s).\n",754 NAME, s tr_error(rc));778 printf("%s: Unable to create callback connection to service %s (%s)\n", 779 NAME, svc, str_error(rc)); 755 780 return NULL; 756 781 } … … 759 784 } 760 785 761 static bool console_srv_init(char *input_dev) 762 { 763 /* Connect to input server */ 764 input_sess = connect_input(input_dev); 786 static void interrupt_received(ipc_callid_t callid, ipc_call_t *call) 787 { 788 cons_switch(prev_console); 789 } 790 791 static async_sess_t *fb_connect(const char *svc) 792 { 793 async_sess_t *sess; 794 service_id_t dsid; 795 796 int rc = loc_service_get_id(svc, &dsid, 0); 797 if (rc == EOK) { 798 sess = loc_service_connect(EXCHANGE_SERIALIZE, dsid, 0); 799 if (sess == NULL) { 800 printf("%s: Unable to connect to framebuffer service %s\n", 801 NAME, svc); 802 return NULL; 803 } 804 } else 805 return NULL; 806 807 return sess; 808 } 809 810 static bool console_srv_init(char *input_svc, char *fb_svc) 811 { 812 /* Avoid double initialization */ 813 if (graphics_state != GRAPHICS_NONE) 814 return false; 815 816 /* Connect to input service */ 817 input_sess = input_connect(input_svc); 765 818 if (input_sess == NULL) 766 819 return false; 767 820 768 /* Connect to framebuffer driver */ 769 fb_info.phone = service_obsolete_connect_blocking(SERVICE_VIDEO, 0, 0); 770 if (fb_info.phone < 0) { 771 printf("%s: Failed to connect to video service\n", NAME); 821 /* Connect to framebuffer service */ 822 fb_sess = fb_connect(fb_svc); 823 if (fb_sess == NULL) 772 824 return false; 773 }774 825 775 826 /* Register server */ 776 int rc = loc_server_register(NAME, client_connection); 827 async_set_client_connection(client_connection); 828 int rc = loc_server_register(NAME); 777 829 if (rc < 0) { 778 printf("%s: Unable to register server (%d)\n", NAME, rc); 830 printf("%s: Unable to register server (%s)\n", NAME, 831 str_error(rc)); 779 832 return false; 780 833 } 781 834 782 /* Initialize gcons */ 783 gcons_init(fb_info.phone); 784 785 /* Synchronize, the gcons could put something in queue */ 786 async_obsolete_req_0_0(fb_info.phone, FB_FLUSH); 787 async_obsolete_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.cols, &fb_info.rows); 788 async_obsolete_req_0_1(fb_info.phone, FB_GET_COLOR_CAP, &fb_info.color_cap); 789 790 /* Set up shared memory buffer. */ 791 size_t ib_size = sizeof(keyfield_t) * fb_info.cols * fb_info.rows; 792 interbuffer = as_get_mappable_page(ib_size); 793 794 if (as_area_create(interbuffer, ib_size, AS_AREA_READ | 795 AS_AREA_WRITE | AS_AREA_CACHEABLE) != interbuffer) 796 interbuffer = NULL; 797 798 if (interbuffer) { 799 if (async_obsolete_share_out_start(fb_info.phone, interbuffer, 800 AS_AREA_READ) != EOK) { 801 as_area_destroy(interbuffer); 802 interbuffer = NULL; 803 } 804 } 805 806 fb_pending.cnt = 0; 835 fb_get_resolution(fb_sess, &xres, &yres); 836 837 /* Initialize the screen */ 838 screen_vp = fb_vp_create(fb_sess, 0, 0, xres, yres); 839 840 if ((xres >= 800) && (yres >= 600)) { 841 logo_vp = fb_vp_create(fb_sess, xres - 66, 2, 64, 60); 842 logo_img = imgmap_decode_tga((void *) helenos_tga, 843 helenos_tga_size, IMGMAP_FLAG_SHARED); 844 logo_handle = fb_imagemap_create(fb_sess, logo_img); 845 846 nameic_vp = fb_vp_create(fb_sess, 5, 17, 100, 26); 847 nameic_img = imgmap_decode_tga((void *) nameic_tga, 848 nameic_tga_size, IMGMAP_FLAG_SHARED); 849 nameic_handle = fb_imagemap_create(fb_sess, nameic_img); 850 851 cons_data_img = imgmap_decode_tga((void *) cons_data_tga, 852 cons_data_tga_size, IMGMAP_FLAG_SHARED); 853 cons_dis_img = imgmap_decode_tga((void *) cons_dis_tga, 854 cons_dis_tga_size, IMGMAP_FLAG_SHARED); 855 cons_dis_sel_img = imgmap_decode_tga((void *) cons_dis_sel_tga, 856 cons_dis_sel_tga_size, IMGMAP_FLAG_SHARED); 857 cons_idle_img = imgmap_decode_tga((void *) cons_idle_tga, 858 cons_idle_tga_size, IMGMAP_FLAG_SHARED); 859 cons_kernel_img = imgmap_decode_tga((void *) cons_kernel_tga, 860 cons_kernel_tga_size, IMGMAP_FLAG_SHARED); 861 cons_sel_img = imgmap_decode_tga((void *) cons_sel_tga, 862 cons_sel_tga_size, IMGMAP_FLAG_SHARED); 863 864 state_icons[CONS_DISCONNECTED] = 865 fb_imagemap_create(fb_sess, cons_dis_img); 866 state_icons[CONS_DISCONNECTED_SELECTED] = 867 fb_imagemap_create(fb_sess, cons_dis_sel_img); 868 state_icons[CONS_SELECTED] = 869 fb_imagemap_create(fb_sess, cons_sel_img); 870 state_icons[CONS_IDLE] = 871 fb_imagemap_create(fb_sess, cons_idle_img); 872 state_icons[CONS_DATA] = 873 fb_imagemap_create(fb_sess, cons_data_img); 874 state_icons[CONS_KERNEL] = 875 fb_imagemap_create(fb_sess, cons_kernel_img); 876 877 anim_1_img = imgmap_decode_tga((void *) anim_1_tga, 878 anim_1_tga_size, IMGMAP_FLAG_SHARED); 879 anim_2_img = imgmap_decode_tga((void *) anim_2_tga, 880 anim_2_tga_size, IMGMAP_FLAG_SHARED); 881 anim_3_img = imgmap_decode_tga((void *) anim_3_tga, 882 anim_3_tga_size, IMGMAP_FLAG_SHARED); 883 anim_4_img = imgmap_decode_tga((void *) anim_4_tga, 884 anim_4_tga_size, IMGMAP_FLAG_SHARED); 885 886 anim_1 = fb_imagemap_create(fb_sess, anim_1_img); 887 anim_2 = fb_imagemap_create(fb_sess, anim_2_img); 888 anim_3 = fb_imagemap_create(fb_sess, anim_3_img); 889 anim_4 = fb_imagemap_create(fb_sess, anim_4_img); 890 891 anim_seq = fb_sequence_create(fb_sess); 892 fb_sequence_add_imagemap(fb_sess, anim_seq, anim_1); 893 fb_sequence_add_imagemap(fb_sess, anim_seq, anim_2); 894 fb_sequence_add_imagemap(fb_sess, anim_seq, anim_3); 895 fb_sequence_add_imagemap(fb_sess, anim_seq, anim_4); 896 897 console_vp = fb_vp_create(fb_sess, CONSOLE_MARGIN, CONSOLE_TOP, 898 xres - 2 * CONSOLE_MARGIN, yres - (CONSOLE_TOP + CONSOLE_MARGIN)); 899 900 fb_vp_clear(fb_sess, screen_vp); 901 fb_vp_imagemap_damage(fb_sess, logo_vp, logo_handle, 902 0, 0, 64, 60); 903 fb_vp_imagemap_damage(fb_sess, nameic_vp, nameic_handle, 904 0, 0, 100, 26); 905 906 graphics_state = GRAPHICS_FULL; 907 } else { 908 console_vp = screen_vp; 909 graphics_state = GRAPHICS_BASIC; 910 } 911 912 fb_vp_set_style(fb_sess, console_vp, STYLE_NORMAL); 913 fb_vp_clear(fb_sess, console_vp); 914 915 sysarg_t cols; 916 sysarg_t rows; 917 fb_vp_get_dimensions(fb_sess, console_vp, &cols, &rows); 918 919 console_caps_t ccaps; 920 fb_vp_get_caps(fb_sess, console_vp, &ccaps); 921 922 mouse.x = xres / 2; 923 mouse.y = yres / 2; 924 mouse.pressed = false; 807 925 808 926 /* Inititalize consoles */ 809 size_t i; 810 for (i = 0; i < CONSOLE_COUNT; i++) { 811 if (i != KERNEL_CONSOLE) { 812 if (screenbuffer_init(&consoles[i].scr, 813 fb_info.cols, fb_info.rows) == NULL) { 814 printf("%s: Unable to allocate screen buffer %zu\n", NAME, i); 815 return false; 816 } 817 screenbuffer_clear(&consoles[i].scr); 818 keybuffer_init(&consoles[i].keybuffer); 819 consoles[i].index = i; 820 consoles[i].refcount = 0; 821 822 char vc[LOC_NAME_MAXLEN + 1]; 823 snprintf(vc, LOC_NAME_MAXLEN, "%s/vc%zu", NAMESPACE, i); 824 825 if (loc_service_register(vc, &consoles[i].service_id) != EOK) { 826 printf("%s: Unable to register service %s\n", NAME, vc); 827 return false; 828 } 829 } 830 } 831 832 /* Initialize the screen */ 833 console_serialize_start(); 834 gcons_redraw_console(); 835 set_style(STYLE_NORMAL); 836 screen_clear(); 837 curs_goto(0, 0); 838 curs_visibility(active_console->scr.is_cursor_visible); 839 console_serialize_end(); 927 for (size_t i = 0; i < CONSOLE_COUNT; i++) { 928 consoles[i].index = i; 929 atomic_set(&consoles[i].refcnt, 0); 930 fibril_mutex_initialize(&consoles[i].mtx); 931 prodcons_initialize(&consoles[i].input_pc); 932 933 if (graphics_state == GRAPHICS_FULL) { 934 /* Create state buttons */ 935 consoles[i].state_vp = 936 fb_vp_create(fb_sess, STATE_START + (xres - 800) / 2 + 937 CONSOLE_MARGIN + i * (STATE_WIDTH + STATE_SPACE), 938 STATE_TOP, STATE_WIDTH, STATE_HEIGHT); 939 } 940 941 if (i == KERNEL_CONSOLE) { 942 consoles[i].state = CONS_KERNEL; 943 cons_redraw_state(&consoles[i]); 944 cons_kernel_sequence_start(&consoles[i]); 945 continue; 946 } 947 948 if (i == 0) 949 consoles[i].state = CONS_DISCONNECTED_SELECTED; 950 else 951 consoles[i].state = CONS_DISCONNECTED; 952 953 consoles[i].cols = cols; 954 consoles[i].rows = rows; 955 consoles[i].ccaps = ccaps; 956 consoles[i].frontbuf = 957 screenbuffer_create(cols, rows, SCREENBUFFER_FLAG_SHARED); 958 959 if (consoles[i].frontbuf == NULL) { 960 printf("%s: Unable to allocate frontbuffer %zu\n", NAME, i); 961 return false; 962 } 963 964 consoles[i].fbid = fb_frontbuf_create(fb_sess, consoles[i].frontbuf); 965 if (consoles[i].fbid == 0) { 966 printf("%s: Unable to create frontbuffer %zu\n", NAME, i); 967 return false; 968 } 969 970 cons_redraw_state(&consoles[i]); 971 972 char vc[LOC_NAME_MAXLEN + 1]; 973 snprintf(vc, LOC_NAME_MAXLEN, "%s/vc%zu", NAMESPACE, i); 974 975 if (loc_service_register(vc, &consoles[i].dsid) != EOK) { 976 printf("%s: Unable to register device %s\n", NAME, vc); 977 return false; 978 } 979 } 840 980 841 981 /* Receive kernel notifications */ 842 982 async_set_interrupt_received(interrupt_received); 843 if (event_subscribe(EVENT_KCONSOLE, 0) != EOK) 844 printf("%s: Error registering kconsole notifications\n", NAME); 983 rc = event_subscribe(EVENT_KCONSOLE, 0); 984 if (rc != EOK) 985 printf("%s: Failed to register kconsole notifications (%s)\n", 986 NAME, str_error(rc)); 845 987 846 988 return true; … … 849 991 static void usage(void) 850 992 { 851 printf("Usage: console <input_dev> \n");993 printf("Usage: console <input_dev> <framebuffer_dev>\n"); 852 994 } 853 995 854 996 int main(int argc, char *argv[]) 855 997 { 856 if (argc < 2) {998 if (argc < 3) { 857 999 usage(); 858 1000 return -1; 859 1001 } 860 1002 861 printf( NAME ": HelenOS Console service\n");862 863 if (!console_srv_init(argv[1] ))1003 printf("%s: HelenOS Console service\n", NAME); 1004 1005 if (!console_srv_init(argv[1], argv[2])) 864 1006 return -1; 865 1007 866 printf(NAME ": Accepting connections\n"); 1008 printf("%s: Accepting connections\n", NAME); 1009 task_retval(0); 867 1010 async_manager(); 868 1011 -
uspace/srv/hid/console/console.h
rbd5f3b7 r00aece0 33 33 */ 34 34 35 #ifndef __CONSOLE_H__36 #define __CONSOLE_H__35 #ifndef CONSOLE_CONSOLE_H__ 36 #define CONSOLE_CONSOLE_H__ 37 37 38 38 #define CONSOLE_COUNT 12 -
uspace/srv/hid/fb/Makefile
rbd5f3b7 r00aece0 29 29 30 30 USPACE_PREFIX = ../../.. 31 ROOT_PATH = $(USPACE_PREFIX)/.. 32 33 COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common 34 CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config 35 31 LIBS = $(LIBFB_PREFIX)/libfb.a 32 EXTRA_CFLAGS += -I$(LIBFB_PREFIX) 36 33 BINARY = fb 37 34 38 -include $(COMMON_MAKEFILE)39 -include $(CONFIG_MAKEFILE)40 41 35 SOURCES = \ 42 main.c 43 44 ifneq ($(UARCH),ia64) 45 SOURCES += \ 46 fb.c \ 47 font-8x16.c 48 EXTRA_CFLAGS += -DFB_ENABLED 49 endif 50 51 ifeq ($(UARCH),ia32) 52 SOURCES += \ 53 ega.c 54 EXTRA_CFLAGS += -DEGA_ENABLED 55 endif 56 57 ifeq ($(UARCH),ia64) 58 SOURCES += \ 59 ega.c \ 60 ski.c \ 61 serial_console.c 62 EXTRA_CFLAGS += -DSKI_ENABLED -DEGA_ENABLED 63 endif 64 65 ifeq ($(UARCH),amd64) 66 SOURCES += \ 67 ega.c 68 EXTRA_CFLAGS += -DEGA_ENABLED 69 endif 70 71 ifeq ($(UARCH),mips32) 72 SOURCES += \ 73 msim.c \ 74 serial_console.c 75 EXTRA_CFLAGS += -DMSIM_ENABLED 76 endif 77 78 ifeq ($(UARCH),sparc64) 79 ifeq ($(PROCESSOR),sun4v) 80 SOURCES += \ 81 niagara.c \ 82 serial_console.c 83 EXTRA_CFLAGS += -DNIAGARA_ENABLED 84 endif 85 endif 86 87 LIBS = $(LIBIMGMAP_PREFIX)/libimgmap.a 88 EXTRA_CFLAGS += -I$(LIBIMGMAP_PREFIX) -D$(UARCH) 36 gfx/font-8x16.c \ 37 ctl/serial.c \ 38 port/ega.c \ 39 port/kfb.c \ 40 port/kchar.c \ 41 port/niagara.c \ 42 port/ski.c \ 43 proto/vt100.c \ 44 fb.c 89 45 90 46 include $(USPACE_PREFIX)/Makefile.common -
uspace/srv/hid/fb/ctl/serial.h
rbd5f3b7 r00aece0 28 28 */ 29 29 30 /** @addtogroup msimfb31 * @brief HelenOS MSIM text console.32 * @ingroup fbs33 * @{34 */35 30 /** @file 36 31 */ 37 32 38 #ifndef FB_ MSIM_H_39 #define FB_ MSIM_H_33 #ifndef FB_CTL_SERIAL_H_ 34 #define FB_CTL_SERIAL_H_ 40 35 41 extern int msim_init(void); 36 #include "../proto/vt100.h" 37 38 extern int serial_init(vt100_putchar_t, vt100_control_puts_t); 42 39 43 40 #endif … … 45 42 /** @} 46 43 */ 47 -
uspace/srv/hid/fb/fb.c
rbd5f3b7 r00aece0 1 1 /* 2 * Copyright (c) 2008 Martin Decky 3 * Copyright (c) 2006 Jakub Vana 4 * Copyright (c) 2006 Ondrej Palkovsky 2 * Copyright (c) 2011 Martin Decky 5 3 * All rights reserved. 6 4 * … … 29 27 */ 30 28 31 /** 32 * @defgroup fb Graphical framebuffer 33 * @brief HelenOS graphical framebuffer. 34 * @ingroup fbs 35 * @{ 36 */ 37 38 /** @file 39 */ 40 41 #include <stdlib.h> 42 #include <unistd.h> 43 #include <str.h> 44 #include <ddi.h> 45 #include <sysinfo.h> 46 #include <align.h> 29 #include <sys/types.h> 30 #include <bool.h> 31 #include <loc.h> 32 #include <errno.h> 33 #include <stdio.h> 34 #include <malloc.h> 35 #include <inttypes.h> 47 36 #include <as.h> 48 #include <ipc/fb.h> 49 #include <ipc/ns.h> 50 #include <ipc/services.h> 51 #include <errno.h> 52 #include <abi/fb/visuals.h> 53 #include <io/color.h> 54 #include <io/style.h> 55 #include <async.h> 56 #include <fibril.h> 57 #include <bool.h> 58 #include <stdio.h> 59 #include <byteorder.h> 60 #include <io/screenbuffer.h> 61 #include <imgmap.h> 62 #include "font-8x16.h" 37 #include <fb.h> 38 #include <screenbuffer.h> 39 #include "port/ega.h" 40 #include "port/kchar.h" 41 #include "port/kfb.h" 42 #include "port/niagara.h" 43 #include "port/ski.h" 63 44 #include "fb.h" 64 #include "main.h" 65 #include "pointer.xbm" 66 #include "pointer_mask.xbm" 67 68 // FIXME: remove this header 69 #include <abi/ipc/methods.h> 70 71 #define DEFAULT_BGCOLOR 0xf0f0f0 72 #define DEFAULT_FGCOLOR 0x000000 73 74 #define GLYPH_UNAVAIL '?' 75 76 #define MAX_ANIM_LEN 8 77 #define MAX_ANIMATIONS 4 78 #define MAX_IMGMAPS 256 /**< Maximum number of saved image maps */ 79 #define MAX_VIEWPORTS 128 /**< Viewport is a rectangular area on the screen */ 80 81 /** Function to render a pixel from a RGB value. */ 82 typedef void (*rgb_conv_t)(void *, uint32_t); 83 84 /** Function to render a bit mask. */ 85 typedef void (*mask_conv_t)(void *, bool); 86 87 /** Function to draw a glyph. */ 88 typedef void (*dg_t)(unsigned int x, unsigned int y, bool cursor, 89 uint8_t *glyphs, uint32_t glyph, uint32_t fg_color, uint32_t bg_color); 90 91 struct { 92 uint8_t *fb_addr; 93 94 unsigned int xres; 95 unsigned int yres; 96 97 unsigned int scanline; 98 unsigned int glyphscanline; 99 100 unsigned int pixelbytes; 101 unsigned int glyphbytes; 102 103 /** Pre-rendered mask for rendering glyphs. Specific for the visual. */ 104 uint8_t *glyphs; 105 106 rgb_conv_t rgb_conv; 107 mask_conv_t mask_conv; 108 } screen; 109 110 /** Backbuffer character cell. */ 111 typedef struct { 112 uint32_t glyph; 113 uint32_t fg_color; 114 uint32_t bg_color; 115 } bb_cell_t; 116 117 typedef struct { 118 bool initialized; 119 unsigned int x; 120 unsigned int y; 121 unsigned int width; 122 unsigned int height; 123 124 /* Text support in window */ 125 unsigned int cols; 126 unsigned int rows; 45 46 #define NAME "fb" 47 #define NAMESPACE "hid" 48 49 #define TICK_INTERVAL 250000 50 51 static LIST_INITIALIZE(fbdevs); 52 53 fbdev_t *fbdev_register(fbdev_ops_t *ops, void *data) 54 { 55 sysarg_t index = 0; 56 57 if (!list_empty(&fbdevs)) { 58 list_foreach(fbdevs, link) { 59 fbdev_t *dev = list_get_instance(link, fbdev_t, link); 60 if (index <= dev->index) 61 index = dev->index + 1; 62 } 63 } 64 65 fbdev_t *dev = (fbdev_t *) malloc(sizeof(fbdev_t)); 66 if (dev == NULL) 67 return NULL; 68 69 link_initialize(&dev->link); 70 atomic_set(&dev->refcnt, 0); 71 dev->claimed = false; 72 dev->index = index; 73 list_initialize(&dev->vps); 74 list_initialize(&dev->frontbufs); 75 list_initialize(&dev->imagemaps); 76 list_initialize(&dev->sequences); 77 78 dev->ops = *ops; 79 dev->data = data; 80 81 char node[LOC_NAME_MAXLEN + 1]; 82 snprintf(node, LOC_NAME_MAXLEN, "%s/%s%" PRIun, NAMESPACE, NAME, 83 index); 84 85 if (loc_service_register(node, &dev->dsid) != EOK) { 86 printf("%s: Unable to register device %s\n", NAME, node); 87 free(dev); 88 return NULL; 89 } 90 91 list_append(&dev->link, &fbdevs); 92 return dev; 93 } 94 95 static void fbsrv_yield(fbdev_t *dev, ipc_callid_t iid, ipc_call_t *icall) 96 { 97 assert(dev->ops.yield); 98 99 if (dev->claimed) { 100 int rc = dev->ops.yield(dev); 101 if (rc == EOK) 102 dev->claimed = false; 103 104 async_answer_0(iid, rc); 105 } else 106 async_answer_0(iid, ENOENT); 107 } 108 109 static void fbsrv_claim(fbdev_t *dev, ipc_callid_t iid, ipc_call_t *icall) 110 { 111 assert(dev->ops.claim); 112 113 if (!dev->claimed) { 114 int rc = dev->ops.claim(dev); 115 if (rc == EOK) 116 dev->claimed = true; 117 118 async_answer_0(iid, rc); 119 } else 120 async_answer_0(iid, ENOENT); 121 } 122 123 static void fbsrv_get_resolution(fbdev_t *dev, ipc_callid_t iid, ipc_call_t *icall) 124 { 125 assert(dev->ops.get_resolution); 126 127 sysarg_t width; 128 sysarg_t height; 129 int rc = dev->ops.get_resolution(dev, &width, &height); 130 131 async_answer_2(iid, rc, width, height); 132 } 133 134 static void fbsrv_pointer_update(fbdev_t *dev, ipc_callid_t iid, ipc_call_t *icall) 135 { 136 if ((dev->claimed) && (dev->ops.pointer_update)) { 137 dev->ops.pointer_update(dev, IPC_GET_ARG1(*icall), 138 IPC_GET_ARG2(*icall), IPC_GET_ARG3(*icall)); 139 async_answer_0(iid, EOK); 140 } else 141 async_answer_0(iid, ENOTSUP); 142 } 143 144 static fbvp_t *resolve_vp(fbdev_t *dev, sysarg_t handle, ipc_callid_t iid) 145 { 146 fbvp_t *vp = NULL; 147 list_foreach(dev->vps, link) { 148 fbvp_t *cur = list_get_instance(link, fbvp_t, link); 149 if (cur == (fbvp_t *) handle) { 150 vp = cur; 151 break; 152 } 153 } 154 155 if (vp == NULL) { 156 async_answer_0(iid, ENOENT); 157 return NULL; 158 } 159 160 return vp; 161 } 162 163 static frontbuf_t *resolve_frontbuf(fbdev_t *dev, sysarg_t handle, ipc_callid_t iid) 164 { 165 frontbuf_t *frontbuf = NULL; 166 list_foreach(dev->frontbufs, link) { 167 frontbuf_t *cur = list_get_instance(link, frontbuf_t, link); 168 if (cur == (frontbuf_t *) handle) { 169 frontbuf = cur; 170 break; 171 } 172 } 173 174 if (frontbuf == NULL) { 175 async_answer_0(iid, ENOENT); 176 return NULL; 177 } 178 179 return frontbuf; 180 } 181 182 static imagemap_t *resolve_imagemap(fbdev_t *dev, sysarg_t handle, ipc_callid_t iid) 183 { 184 imagemap_t *imagemap = NULL; 185 list_foreach(dev->imagemaps, link) { 186 imagemap_t *cur = list_get_instance(link, imagemap_t, link); 187 if (cur == (imagemap_t *) handle) { 188 imagemap = cur; 189 break; 190 } 191 } 192 193 if (imagemap == NULL) { 194 async_answer_0(iid, ENOENT); 195 return NULL; 196 } 197 198 return imagemap; 199 } 200 201 static sequence_t *resolve_sequence(fbdev_t *dev, sysarg_t handle, ipc_callid_t iid) 202 { 203 sequence_t *sequence = NULL; 204 list_foreach(dev->sequences, link) { 205 sequence_t *cur = list_get_instance(link, sequence_t, link); 206 if (cur == (sequence_t *) handle) { 207 sequence = cur; 208 break; 209 } 210 } 211 212 if (sequence == NULL) { 213 async_answer_0(iid, ENOENT); 214 return NULL; 215 } 216 217 return sequence; 218 } 219 220 static void fbsrv_vp_create(fbdev_t *dev, ipc_callid_t iid, ipc_call_t *icall) 221 { 222 assert(dev->ops.font_metrics); 223 assert(dev->ops.vp_create); 224 225 fbvp_t *vp = (fbvp_t *) malloc(sizeof(fbvp_t)); 226 if (vp == NULL) { 227 async_answer_0(iid, ENOMEM); 228 return; 229 } 230 231 link_initialize(&vp->link); 232 233 vp->x = IPC_GET_ARG1(*icall); 234 vp->y = IPC_GET_ARG2(*icall); 235 vp->width = IPC_GET_ARG3(*icall); 236 vp->height = IPC_GET_ARG4(*icall); 237 238 dev->ops.font_metrics(dev, vp->width, vp->height, &vp->cols, &vp->rows); 239 240 vp->cursor_active = false; 241 vp->cursor_flash = false; 242 243 list_initialize(&vp->sequences); 244 245 vp->backbuf = screenbuffer_create(vp->cols, vp->rows, 246 SCREENBUFFER_FLAG_NONE); 247 if (vp->backbuf == NULL) { 248 free(vp); 249 async_answer_0(iid, ENOMEM); 250 return; 251 } 252 253 vp->top_row = 0; 254 255 int rc = dev->ops.vp_create(dev, vp); 256 if (rc != EOK) { 257 free(vp); 258 async_answer_0(iid, ENOMEM); 259 return; 260 } 261 262 list_append(&vp->link, &dev->vps); 263 async_answer_1(iid, EOK, (sysarg_t) vp); 264 } 265 266 static void fbsrv_vp_destroy(fbdev_t *dev, ipc_callid_t iid, ipc_call_t *icall) 267 { 268 assert(dev->ops.vp_destroy); 269 270 fbvp_t *vp = resolve_vp(dev, IPC_GET_ARG1(*icall), iid); 271 if (vp == NULL) 272 return; 273 274 if (dev->active_vp == vp) { 275 async_answer_0(iid, EPERM); 276 return; 277 } 278 279 dev->ops.vp_destroy(dev, vp); 280 281 list_remove(&vp->link); 282 free(vp->backbuf); 283 free(vp); 284 285 async_answer_0(iid, EOK); 286 } 287 288 static void fbsrv_frontbuf_create(fbdev_t *dev, ipc_callid_t iid, ipc_call_t *icall) 289 { 290 frontbuf_t *frontbuf = (frontbuf_t *) malloc(sizeof(frontbuf_t)); 291 if (frontbuf == NULL) { 292 async_answer_0(iid, ENOMEM); 293 return; 294 } 295 296 link_initialize(&frontbuf->link); 297 298 ipc_callid_t callid; 299 if (!async_share_out_receive(&callid, &frontbuf->size, 300 &frontbuf->flags)) { 301 free(frontbuf); 302 async_answer_0(iid, EINVAL); 303 return; 304 } 305 306 int rc = async_share_out_finalize(callid, &frontbuf->data); 307 if ((rc != EOK) || (frontbuf->data == (void *) -1)) { 308 free(frontbuf); 309 async_answer_0(iid, ENOMEM); 310 return; 311 } 312 313 list_append(&frontbuf->link, &dev->frontbufs); 314 async_answer_1(iid, EOK, (sysarg_t) frontbuf); 315 } 316 317 static void fbsrv_frontbuf_destroy(fbdev_t *dev, ipc_callid_t iid, ipc_call_t *icall) 318 { 319 frontbuf_t *frontbuf = resolve_frontbuf(dev, IPC_GET_ARG1(*icall), iid); 320 if (frontbuf == NULL) 321 return; 322 323 list_remove(&frontbuf->link); 324 as_area_destroy(frontbuf->data); 325 free(frontbuf); 326 327 async_answer_0(iid, EOK); 328 } 329 330 static void fbsrv_imagemap_create(fbdev_t *dev, ipc_callid_t iid, ipc_call_t *icall) 331 { 332 imagemap_t *imagemap = (imagemap_t *) malloc(sizeof(imagemap_t)); 333 if (imagemap == NULL) { 334 async_answer_0(iid, ENOMEM); 335 return; 336 } 337 338 link_initialize(&imagemap->link); 339 link_initialize(&imagemap->seq_link); 340 341 ipc_callid_t callid; 342 if (!async_share_out_receive(&callid, &imagemap->size, 343 &imagemap->flags)) { 344 free(imagemap); 345 async_answer_0(iid, EINVAL); 346 return; 347 } 348 349 int rc = async_share_out_finalize(callid, &imagemap->data); 350 if ((rc != EOK) || (imagemap->data == (void *) -1)) { 351 free(imagemap); 352 async_answer_0(iid, ENOMEM); 353 return; 354 } 355 356 list_append(&imagemap->link, &dev->imagemaps); 357 async_answer_1(iid, EOK, (sysarg_t) imagemap); 358 } 359 360 static void fbsrv_imagemap_destroy(fbdev_t *dev, ipc_callid_t iid, ipc_call_t *icall) 361 { 362 imagemap_t *imagemap = resolve_imagemap(dev, IPC_GET_ARG1(*icall), iid); 363 if (imagemap == NULL) 364 return; 365 366 list_remove(&imagemap->link); 367 list_remove(&imagemap->seq_link); 368 as_area_destroy(imagemap->data); 369 free(imagemap); 370 371 async_answer_0(iid, EOK); 372 } 373 374 static void fbsrv_sequence_create(fbdev_t *dev, ipc_callid_t iid, ipc_call_t *icall) 375 { 376 sequence_t *sequence = (sequence_t *) malloc(sizeof(sequence_t)); 377 if (sequence == NULL) { 378 async_answer_0(iid, ENOMEM); 379 return; 380 } 381 382 link_initialize(&sequence->link); 383 list_initialize(&sequence->imagemaps); 384 sequence->count = 0; 385 386 list_append(&sequence->link, &dev->sequences); 387 async_answer_1(iid, EOK, (sysarg_t) sequence); 388 } 389 390 static void fbsrv_sequence_destroy(fbdev_t *dev, ipc_callid_t iid, ipc_call_t *icall) 391 { 392 sequence_t *sequence = resolve_sequence(dev, IPC_GET_ARG1(*icall), iid); 393 if (sequence == NULL) 394 return; 395 396 list_remove(&sequence->link); 397 free(sequence); 398 399 async_answer_0(iid, EOK); 400 } 401 402 static void fbsrv_sequence_add_imagemap(fbdev_t *dev, ipc_callid_t iid, ipc_call_t *icall) 403 { 404 sequence_t *sequence = resolve_sequence(dev, IPC_GET_ARG1(*icall), iid); 405 if (sequence == NULL) 406 return; 407 408 imagemap_t *imagemap = resolve_imagemap(dev, IPC_GET_ARG2(*icall), iid); 409 if (imagemap == NULL) 410 return; 411 412 if (list_member(&imagemap->seq_link, &sequence->imagemaps)) { 413 async_answer_0(iid, EEXISTS); 414 return; 415 } 416 417 list_append(&imagemap->seq_link, &sequence->imagemaps); 418 sequence->count++; 419 420 async_answer_0(iid, EOK); 421 } 422 423 static void fbsrv_vp_focus(fbdev_t *dev, ipc_callid_t iid, ipc_call_t *icall) 424 { 425 fbvp_t *vp = resolve_vp(dev, IPC_GET_ARG1(*icall), iid); 426 if (vp == NULL) 427 return; 428 429 if (dev->active_vp != vp) 430 dev->active_vp = vp; 431 432 async_answer_0(iid, EOK); 433 } 434 435 static void fbsrv_vp_clear(fbdev_t *dev, ipc_callid_t iid, ipc_call_t *icall) 436 { 437 assert(dev->ops.vp_clear); 438 439 if ((dev->claimed) && (dev->active_vp)) { 440 screenbuffer_set_cursor_visibility(dev->active_vp->backbuf, false); 441 dev->ops.vp_clear(dev, dev->active_vp); 442 async_answer_0(iid, EOK); 443 } else 444 async_answer_0(iid, ENOENT); 445 } 446 447 static void fbsrv_vp_get_dimensions(fbdev_t *dev, ipc_callid_t iid, ipc_call_t *icall) 448 { 449 if (dev->active_vp) 450 async_answer_2(iid, EOK, dev->active_vp->cols, dev->active_vp->rows); 451 else 452 async_answer_0(iid, ENOENT); 453 } 454 455 static void fbsrv_vp_get_caps(fbdev_t *dev, ipc_callid_t iid, ipc_call_t *icall) 456 { 457 assert(dev->ops.vp_get_caps); 458 459 if (dev->active_vp) 460 async_answer_1(iid, EOK, 461 (sysarg_t) dev->ops.vp_get_caps(dev, dev->active_vp)); 462 else 463 async_answer_0(iid, ENOENT); 464 } 465 466 static void fbsrv_vp_cursor_update(fbdev_t *dev, ipc_callid_t iid, ipc_call_t *icall) 467 { 468 assert(dev->ops.vp_cursor_update); 469 470 frontbuf_t *frontbuf = resolve_frontbuf(dev, IPC_GET_ARG1(*icall), iid); 471 if (frontbuf == NULL) 472 return; 473 474 if ((dev->claimed) && (dev->active_vp)) { 475 screenbuffer_t *screenbuf = (screenbuffer_t *) frontbuf->data; 476 477 sysarg_t prev_col; 478 sysarg_t prev_row; 479 sysarg_t col; 480 sysarg_t row; 481 482 screenbuffer_get_cursor(dev->active_vp->backbuf, 483 &prev_col, &prev_row); 484 screenbuffer_get_cursor(screenbuf, &col, &row); 485 screenbuffer_set_cursor(dev->active_vp->backbuf, col, row); 486 487 bool visible = screenbuffer_get_cursor_visibility(screenbuf); 488 screenbuffer_set_cursor_visibility(dev->active_vp->backbuf, visible); 489 490 if (visible) 491 dev->active_vp->cursor_active = true; 492 493 dev->ops.vp_cursor_update(dev, dev->active_vp, prev_col, prev_row, 494 col, row, visible); 495 async_answer_0(iid, EOK); 496 } else 497 async_answer_0(iid, ENOENT); 498 } 499 500 static void fbsrv_vp_cursor_flash(fbdev_t *dev) 501 { 502 if ((dev->claimed) && (dev->ops.vp_cursor_flash)) { 503 list_foreach (dev->vps, link) { 504 fbvp_t *vp = list_get_instance(link, fbvp_t, link); 505 506 if (vp->cursor_active) { 507 sysarg_t col; 508 sysarg_t row; 509 510 screenbuffer_get_cursor(vp->backbuf, &col, &row); 511 vp->cursor_flash = !vp->cursor_flash; 512 dev->ops.vp_cursor_flash(dev, vp, col, row); 513 } 514 } 515 } 516 } 517 518 static void fbsrv_sequences_update(fbdev_t *dev) 519 { 520 if ((dev->claimed) && (dev->ops.vp_imgmap_damage)) { 521 list_foreach (dev->vps, vp_link) { 522 fbvp_t *vp = list_get_instance(vp_link, fbvp_t, link); 523 524 list_foreach (vp->sequences, seq_vp_link) { 525 sequence_vp_t *seq_vp = 526 list_get_instance(seq_vp_link, sequence_vp_t, link); 527 528 seq_vp->current++; 529 if (seq_vp->current >= seq_vp->seq->count) 530 seq_vp->current = 0; 531 532 link_t *link = 533 list_nth(&seq_vp->seq->imagemaps, seq_vp->current); 534 if (link != NULL) { 535 imagemap_t *imagemap = 536 list_get_instance(link, imagemap_t, seq_link); 537 538 imgmap_t *imgmap = (imgmap_t *) imagemap->data; 539 sysarg_t width; 540 sysarg_t height; 541 542 imgmap_get_resolution(imgmap, &width, &height); 543 dev->ops.vp_imgmap_damage(dev, vp, imgmap, 544 0, 0, width, height); 545 } 546 } 547 } 548 } 549 } 550 551 static void fbsrv_vp_set_style(fbdev_t *dev, ipc_callid_t iid, ipc_call_t *icall) 552 { 553 if (dev->active_vp) { 554 dev->active_vp->attrs.type = CHAR_ATTR_STYLE; 555 dev->active_vp->attrs.val.style = 556 (console_style_t) IPC_GET_ARG1(*icall); 557 async_answer_0(iid, EOK); 558 } else 559 async_answer_0(iid, ENOENT); 560 } 561 562 static void fbsrv_vp_set_color(fbdev_t *dev, ipc_callid_t iid, ipc_call_t *icall) 563 { 564 if (dev->active_vp) { 565 dev->active_vp->attrs.type = CHAR_ATTR_INDEX; 566 dev->active_vp->attrs.val.index.bgcolor = 567 (console_color_t) IPC_GET_ARG1(*icall); 568 dev->active_vp->attrs.val.index.fgcolor = 569 (console_color_t) IPC_GET_ARG2(*icall); 570 dev->active_vp->attrs.val.index.attr = 571 (console_color_attr_t) IPC_GET_ARG3(*icall); 572 async_answer_0(iid, EOK); 573 } else 574 async_answer_0(iid, ENOENT); 575 } 576 577 static void fbsrv_vp_set_rgb_color(fbdev_t *dev, ipc_callid_t iid, ipc_call_t *icall) 578 { 579 if (dev->active_vp) { 580 dev->active_vp->attrs.type = CHAR_ATTR_RGB; 581 dev->active_vp->attrs.val.rgb.bgcolor = IPC_GET_ARG1(*icall); 582 dev->active_vp->attrs.val.rgb.fgcolor = IPC_GET_ARG2(*icall); 583 async_answer_0(iid, EOK); 584 } else 585 async_answer_0(iid, ENOENT); 586 } 587 588 static void fbsrv_vp_putchar(fbdev_t *dev, ipc_callid_t iid, ipc_call_t *icall) 589 { 590 assert(dev->ops.vp_char_update); 591 592 if ((dev->claimed) && (dev->active_vp)) { 593 charfield_t *field = screenbuffer_field_at(dev->active_vp->backbuf, 594 IPC_GET_ARG1(*icall), IPC_GET_ARG2(*icall)); 595 596 field->ch = IPC_GET_ARG3(*icall); 597 598 dev->ops.vp_char_update(dev, dev->active_vp, IPC_GET_ARG1(*icall), 599 IPC_GET_ARG2(*icall)); 600 async_answer_0(iid, EOK); 601 } else 602 async_answer_0(iid, ENOENT); 603 } 604 605 static bool fbsrv_vp_update_scroll(fbdev_t *dev, fbvp_t *vp, 606 screenbuffer_t *frontbuf) 607 { 608 assert(dev->ops.vp_char_update); 609 610 sysarg_t top_row = screenbuffer_get_top_row(frontbuf); 611 612 if (vp->top_row == top_row) 613 return false; 614 615 vp->top_row = top_row; 616 617 for (sysarg_t y = 0; y < vp->rows; y++) { 618 for (sysarg_t x = 0; x < vp->cols; x++) { 619 charfield_t *front_field = 620 screenbuffer_field_at(frontbuf, x, y); 621 charfield_t *back_field = 622 screenbuffer_field_at(vp->backbuf, x, y); 623 bool update = false; 624 625 if (front_field->ch != back_field->ch) { 626 back_field->ch = front_field->ch; 627 update = true; 628 } 629 630 if (!attrs_same(front_field->attrs, back_field->attrs)) { 631 back_field->attrs = front_field->attrs; 632 update = true; 633 } 634 635 front_field->flags &= ~CHAR_FLAG_DIRTY; 636 637 if (update) 638 dev->ops.vp_char_update(dev, vp, x, y); 639 } 640 } 641 642 return true; 643 } 644 645 static void fbsrv_vp_update(fbdev_t *dev, ipc_callid_t iid, ipc_call_t *icall) 646 { 647 assert(dev->ops.vp_char_update); 648 649 frontbuf_t *frontbuf = resolve_frontbuf(dev, IPC_GET_ARG1(*icall), iid); 650 if (frontbuf == NULL) 651 return; 652 653 if ((dev->claimed) && (dev->active_vp)) { 654 fbvp_t *vp = dev->active_vp; 655 screenbuffer_t *screenbuf = (screenbuffer_t *) frontbuf->data; 656 657 if (fbsrv_vp_update_scroll(dev, vp, screenbuf)) { 658 async_answer_0(iid, EOK); 659 return; 660 } 661 662 for (sysarg_t y = 0; y < vp->rows; y++) { 663 for (sysarg_t x = 0; x < vp->cols; x++) { 664 charfield_t *front_field = 665 screenbuffer_field_at(screenbuf, x, y); 666 charfield_t *back_field = 667 screenbuffer_field_at(vp->backbuf, x, y); 668 bool update = false; 669 670 if ((front_field->flags & CHAR_FLAG_DIRTY) == CHAR_FLAG_DIRTY) { 671 if (front_field->ch != back_field->ch) { 672 back_field->ch = front_field->ch; 673 update = true; 674 } 675 676 if (!attrs_same(front_field->attrs, back_field->attrs)) { 677 back_field->attrs = front_field->attrs; 678 update = true; 679 } 680 681 front_field->flags &= ~CHAR_FLAG_DIRTY; 682 } 683 684 if (update) 685 dev->ops.vp_char_update(dev, vp, x, y); 686 } 687 } 688 689 async_answer_0(iid, EOK); 690 } else 691 async_answer_0(iid, ENOENT); 692 } 693 694 static void fbsrv_vp_damage(fbdev_t *dev, ipc_callid_t iid, ipc_call_t *icall) 695 { 696 assert(dev->ops.vp_char_update); 697 698 frontbuf_t *frontbuf = resolve_frontbuf(dev, IPC_GET_ARG1(*icall), iid); 699 if (frontbuf == NULL) 700 return; 701 702 if ((dev->claimed) && (dev->active_vp)) { 703 fbvp_t *vp = dev->active_vp; 704 screenbuffer_t *screenbuf = (screenbuffer_t *) frontbuf->data; 705 706 if (fbsrv_vp_update_scroll(dev, vp, screenbuf)) { 707 async_answer_0(iid, EOK); 708 return; 709 } 710 711 sysarg_t col = IPC_GET_ARG2(*icall); 712 sysarg_t row = IPC_GET_ARG3(*icall); 713 714 sysarg_t cols = IPC_GET_ARG4(*icall); 715 sysarg_t rows = IPC_GET_ARG5(*icall); 716 717 for (sysarg_t y = 0; y < rows; y++) { 718 for (sysarg_t x = 0; x < cols; x++) { 719 charfield_t *front_field = 720 screenbuffer_field_at(screenbuf, col + x, row + y); 721 charfield_t *back_field = 722 screenbuffer_field_at(vp->backbuf, col + x, row + y); 723 bool update = false; 724 725 if (front_field->ch != back_field->ch) { 726 back_field->ch = front_field->ch; 727 update = true; 728 } 729 730 if (!attrs_same(front_field->attrs, back_field->attrs)) { 731 back_field->attrs = front_field->attrs; 732 update = true; 733 } 734 735 front_field->flags &= ~CHAR_FLAG_DIRTY; 736 737 if (update) 738 dev->ops.vp_char_update(dev, vp, col + x, row + y); 739 } 740 } 741 742 async_answer_0(iid, EOK); 743 } else 744 async_answer_0(iid, ENOENT); 745 } 746 747 static void fbsrv_vp_imagemap_damage(fbdev_t *dev, ipc_callid_t iid, ipc_call_t *icall) 748 { 749 imagemap_t *imagemap = resolve_imagemap(dev, IPC_GET_ARG1(*icall), iid); 750 if (imagemap == NULL) 751 return; 752 753 if ((dev->claimed) && (dev->ops.vp_imgmap_damage)) { 754 if (dev->active_vp) { 755 dev->ops.vp_imgmap_damage(dev, dev->active_vp, 756 (imgmap_t *) imagemap->data, 757 IPC_GET_ARG2(*icall), IPC_GET_ARG3(*icall), 758 IPC_GET_ARG4(*icall), IPC_GET_ARG5(*icall)); 759 async_answer_0(iid, EOK); 760 } else 761 async_answer_0(iid, ENOENT); 762 } else 763 async_answer_0(iid, ENOTSUP); 764 } 765 766 static void fbsrv_vp_sequence_start(fbdev_t *dev, ipc_callid_t iid, ipc_call_t *icall) 767 { 768 sequence_t *sequence = resolve_sequence(dev, IPC_GET_ARG1(*icall), iid); 769 if (sequence == NULL) 770 return; 771 772 if (dev->active_vp) { 773 /* Check if the sequence is not already started */ 774 list_foreach(dev->active_vp->sequences, link) { 775 sequence_vp_t *seq_vp = 776 list_get_instance(link, sequence_vp_t, link); 777 778 if (seq_vp->seq == sequence) { 779 async_answer_0(iid, EEXISTS); 780 return; 781 } 782 } 783 784 sequence_vp_t *seq_vp = 785 (sequence_vp_t *) malloc(sizeof(sequence_vp_t)); 786 787 if (seq_vp != NULL) { 788 link_initialize(&seq_vp->link); 789 seq_vp->seq = sequence; 790 seq_vp->current = 0; 791 792 list_append(&seq_vp->link, &dev->active_vp->sequences); 793 async_answer_0(iid, EOK); 794 } else 795 async_answer_0(iid, ENOMEM); 796 } else 797 async_answer_0(iid, ENOENT); 798 } 799 800 static void fbsrv_vp_sequence_stop(fbdev_t *dev, ipc_callid_t iid, ipc_call_t *icall) 801 { 802 sequence_t *sequence = resolve_sequence(dev, IPC_GET_ARG1(*icall), iid); 803 if (sequence == NULL) 804 return; 805 806 if (dev->active_vp) { 807 list_foreach(dev->active_vp->sequences, link) { 808 sequence_vp_t *seq_vp = 809 list_get_instance(link, sequence_vp_t, link); 810 811 if (seq_vp->seq == sequence) { 812 list_remove(&seq_vp->link); 813 free(seq_vp); 814 815 async_answer_0(iid, EOK); 816 return; 817 } 818 } 819 820 async_answer_0(iid, ENOENT); 821 } else 822 async_answer_0(iid, ENOENT); 823 } 824 825 static void client_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 826 { 827 fbdev_t *dev = NULL; 828 service_id_t dsid = (service_id_t) IPC_GET_ARG1(*icall); 829 830 list_foreach(fbdevs, link) { 831 fbdev_t *fbdev = list_get_instance(link, fbdev_t, link); 832 if (fbdev->dsid == dsid) { 833 dev = fbdev; 834 break; 835 } 836 } 837 838 if (dev == NULL) { 839 async_answer_0(iid, ENOENT); 840 return; 841 } 842 843 if (atomic_get(&dev->refcnt) > 0) { 844 async_answer_0(iid, ELIMIT); 845 return; 846 } 127 847 128 848 /* 129 * Style and glyphs for text printing849 * Accept the connection 130 850 */ 131 851 132 /** Current attributes. */ 133 attr_rgb_t attr; 134 135 uint8_t *bgpixel; 136 137 /** 138 * Glyph drawing function for this viewport. Different viewports 139 * might use different drawing functions depending on whether their 140 * scanlines are aligned on a word boundary. 141 */ 142 dg_t dglyph; 143 144 /* Auto-cursor position */ 145 bool cursor_active; 146 unsigned int cur_col; 147 unsigned int cur_row; 148 bool cursor_shown; 149 150 /* Back buffer */ 151 bb_cell_t *backbuf; 152 unsigned int bbsize; 153 } viewport_t; 154 155 typedef struct { 156 bool initialized; 157 bool enabled; 158 unsigned int vp; 159 160 unsigned int pos; 161 unsigned int animlen; 162 unsigned int imgmaps[MAX_ANIM_LEN]; 163 } animation_t; 164 165 static animation_t animations[MAX_ANIMATIONS]; 166 static bool anims_enabled; 167 168 static imgmap_t *imgmaps[MAX_IMGMAPS]; 169 static viewport_t viewports[128]; 170 171 static bool client_connected = false; /**< Allow only 1 connection */ 172 173 static uint32_t color_table[16] = { 174 [COLOR_BLACK] = 0x000000, 175 [COLOR_BLUE] = 0x0000f0, 176 [COLOR_GREEN] = 0x00f000, 177 [COLOR_CYAN] = 0x00f0f0, 178 [COLOR_RED] = 0xf00000, 179 [COLOR_MAGENTA] = 0xf000f0, 180 [COLOR_YELLOW] = 0xf0f000, 181 [COLOR_WHITE] = 0xf0f0f0, 182 183 [8 + COLOR_BLACK] = 0x000000, 184 [8 + COLOR_BLUE] = 0x0000ff, 185 [8 + COLOR_GREEN] = 0x00ff00, 186 [8 + COLOR_CYAN] = 0x00ffff, 187 [8 + COLOR_RED] = 0xff0000, 188 [8 + COLOR_MAGENTA] = 0xff00ff, 189 [8 + COLOR_YELLOW] = 0xffff00, 190 [8 + COLOR_WHITE] = 0xffffff, 191 }; 192 193 static int rgb_from_attr(attr_rgb_t *rgb, const attrs_t *a); 194 static int rgb_from_style(attr_rgb_t *rgb, int style); 195 static int rgb_from_idx(attr_rgb_t *rgb, sysarg_t fg_color, 196 sysarg_t bg_color, sysarg_t flags); 197 198 static int fb_set_color(viewport_t *vport, sysarg_t fg_color, 199 sysarg_t bg_color, sysarg_t attr); 200 201 static void draw_glyph_aligned(unsigned int x, unsigned int y, bool cursor, 202 uint8_t *glyphs, uint32_t glyph, uint32_t fg_color, uint32_t bg_color); 203 static void draw_glyph_fallback(unsigned int x, unsigned int y, bool cursor, 204 uint8_t *glyphs, uint32_t glyph, uint32_t fg_color, uint32_t bg_color); 205 206 static void draw_vp_glyph(viewport_t *vport, bool cursor, unsigned int col, 207 unsigned int row); 208 209 #define RED(x, bits) (((x) >> (8 + 8 + 8 - (bits))) & ((1 << (bits)) - 1)) 210 #define GREEN(x, bits) (((x) >> (8 + 8 - (bits))) & ((1 << (bits)) - 1)) 211 #define BLUE(x, bits) (((x) >> (8 - (bits))) & ((1 << (bits)) - 1)) 212 213 #define COL2X(col) ((col) * FONT_WIDTH) 214 #define ROW2Y(row) ((row) * FONT_SCANLINES) 215 216 #define X2COL(x) ((x) / FONT_WIDTH) 217 #define Y2ROW(y) ((y) / FONT_SCANLINES) 218 219 #define FB_POS(x, y) ((y) * screen.scanline + (x) * screen.pixelbytes) 220 #define BB_POS(vport, col, row) ((row) * vport->cols + (col)) 221 #define GLYPH_POS(glyph, y, cursor) (((glyph) + (cursor) * FONT_GLYPHS) * screen.glyphbytes + (y) * screen.glyphscanline) 222 223 /* 224 * RGB conversion and mask functions. 225 * 226 * These functions write an RGB value to some memory in some predefined format. 227 * The naming convention corresponds to the format created by these functions. 228 * The functions use the so called network order (i.e. big endian) with respect 229 * to their names. 230 */ 231 232 static void rgb_0888(void *dst, uint32_t rgb) 233 { 234 *((uint32_t *) dst) = host2uint32_t_be((0 << 24) | 235 (RED(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | (BLUE(rgb, 8))); 236 } 237 238 static void bgr_0888(void *dst, uint32_t rgb) 239 { 240 *((uint32_t *) dst) = host2uint32_t_be((0 << 24) | 241 (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | (RED(rgb, 8))); 242 } 243 244 static void mask_0888(void *dst, bool mask) 245 { 246 bgr_0888(dst, mask ? 0xffffff : 0); 247 } 248 249 static void rgb_8880(void *dst, uint32_t rgb) 250 { 251 *((uint32_t *) dst) = host2uint32_t_be((RED(rgb, 8) << 24) | 252 (GREEN(rgb, 8) << 16) | (BLUE(rgb, 8) << 8) | 0); 253 } 254 255 static void bgr_8880(void *dst, uint32_t rgb) 256 { 257 *((uint32_t *) dst) = host2uint32_t_be((BLUE(rgb, 8) << 24) | 258 (GREEN(rgb, 8) << 16) | (RED(rgb, 8) << 8) | 0); 259 } 260 261 static void mask_8880(void *dst, bool mask) 262 { 263 bgr_8880(dst, mask ? 0xffffff : 0); 264 } 265 266 static void rgb_888(void *dst, uint32_t rgb) 267 { 268 ((uint8_t *) dst)[0] = RED(rgb, 8); 269 ((uint8_t *) dst)[1] = GREEN(rgb, 8); 270 ((uint8_t *) dst)[2] = BLUE(rgb, 8); 271 } 272 273 static void bgr_888(void *dst, uint32_t rgb) 274 { 275 ((uint8_t *) dst)[0] = BLUE(rgb, 8); 276 ((uint8_t *) dst)[1] = GREEN(rgb, 8); 277 ((uint8_t *) dst)[2] = RED(rgb, 8); 278 } 279 280 static void mask_888(void *dst, bool mask) 281 { 282 bgr_888(dst, mask ? 0xffffff : 0); 283 } 284 285 static void rgb_555_be(void *dst, uint32_t rgb) 286 { 287 *((uint16_t *) dst) = host2uint16_t_be(RED(rgb, 5) << 10 | 288 GREEN(rgb, 5) << 5 | BLUE(rgb, 5)); 289 } 290 291 static void rgb_555_le(void *dst, uint32_t rgb) 292 { 293 *((uint16_t *) dst) = host2uint16_t_le(RED(rgb, 5) << 10 | 294 GREEN(rgb, 5) << 5 | BLUE(rgb, 5)); 295 } 296 297 static void rgb_565_be(void *dst, uint32_t rgb) 298 { 299 *((uint16_t *) dst) = host2uint16_t_be(RED(rgb, 5) << 11 | 300 GREEN(rgb, 6) << 5 | BLUE(rgb, 5)); 301 } 302 303 static void rgb_565_le(void *dst, uint32_t rgb) 304 { 305 *((uint16_t *) dst) = host2uint16_t_le(RED(rgb, 5) << 11 | 306 GREEN(rgb, 6) << 5 | BLUE(rgb, 5)); 307 } 308 309 static void mask_555(void *dst, bool mask) 310 { 311 rgb_555_be(dst, mask ? 0xffffff : 0); 312 } 313 314 static void mask_565(void *dst, bool mask) 315 { 316 rgb_565_be(dst, mask ? 0xffffff : 0); 317 } 318 319 static void bgr_323(void *dst, uint32_t rgb) 320 { 321 *((uint8_t *) dst) 322 = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3)); 323 } 324 325 static void mask_323(void *dst, bool mask) 326 { 327 bgr_323(dst, mask ? 0x0 : ~0x0); 328 } 329 330 /** Draw a filled rectangle. 331 * 332 * @note Need real implementation that does not access VRAM twice. 333 * 334 */ 335 static void draw_filled_rect(unsigned int x0, unsigned int y0, unsigned int x1, 336 unsigned int y1, uint32_t color) 337 { 338 unsigned int x; 339 unsigned int y; 340 unsigned int copy_bytes; 341 342 uint8_t *sp; 343 uint8_t *dp; 344 uint8_t cbuf[4]; 345 346 if ((y0 >= y1) || (x0 >= x1)) 347 return; 348 349 screen.rgb_conv(cbuf, color); 350 351 sp = &screen.fb_addr[FB_POS(x0, y0)]; 352 dp = sp; 353 354 /* Draw the first line. */ 355 for (x = x0; x < x1; x++) { 356 memcpy(dp, cbuf, screen.pixelbytes); 357 dp += screen.pixelbytes; 358 } 359 360 dp = sp + screen.scanline; 361 copy_bytes = (x1 - x0) * screen.pixelbytes; 362 363 /* Draw the remaining lines by copying. */ 364 for (y = y0 + 1; y < y1; y++) { 365 memcpy(dp, sp, copy_bytes); 366 dp += screen.scanline; 367 } 368 } 369 370 /** Redraw viewport. 371 * 372 * @param vport Viewport to redraw 373 * 374 */ 375 static void vport_redraw(viewport_t *vport) 376 { 377 unsigned int col; 378 unsigned int row; 379 380 for (row = 0; row < vport->rows; row++) { 381 for (col = 0; col < vport->cols; col++) { 382 draw_vp_glyph(vport, false, col, row); 383 } 384 } 385 386 if (COL2X(vport->cols) < vport->width) { 387 draw_filled_rect( 388 vport->x + COL2X(vport->cols), vport->y, 389 vport->x + vport->width, vport->y + vport->height, 390 vport->attr.bg_color); 391 } 392 393 if (ROW2Y(vport->rows) < vport->height) { 394 draw_filled_rect( 395 vport->x, vport->y + ROW2Y(vport->rows), 396 vport->x + vport->width, vport->y + vport->height, 397 vport->attr.bg_color); 398 } 399 } 400 401 static void backbuf_clear(bb_cell_t *backbuf, size_t len, uint32_t fg_color, 402 uint32_t bg_color) 403 { 404 size_t i; 405 406 for (i = 0; i < len; i++) { 407 backbuf[i].glyph = 0; 408 backbuf[i].fg_color = fg_color; 409 backbuf[i].bg_color = bg_color; 410 } 411 } 412 413 /** Clear viewport. 414 * 415 * @param vport Viewport to clear 416 * 417 */ 418 static void vport_clear(viewport_t *vport) 419 { 420 backbuf_clear(vport->backbuf, vport->cols * vport->rows, 421 vport->attr.fg_color, vport->attr.bg_color); 422 vport_redraw(vport); 423 } 424 425 /** Scroll viewport by the specified number of lines. 426 * 427 * @param vport Viewport to scroll 428 * @param lines Number of lines to scroll 429 * 430 */ 431 static void vport_scroll(viewport_t *vport, int lines) 432 { 433 unsigned int col; 434 unsigned int row; 435 unsigned int x; 436 unsigned int y; 437 uint32_t glyph; 438 uint32_t fg_color; 439 uint32_t bg_color; 440 bb_cell_t *bbp; 441 bb_cell_t *xbp; 442 443 /* 444 * Redraw. 445 */ 446 447 y = vport->y; 448 for (row = 0; row < vport->rows; row++) { 449 x = vport->x; 450 for (col = 0; col < vport->cols; col++) { 451 if (((int) row + lines >= 0) && 452 ((int) row + lines < (int) vport->rows)) { 453 xbp = &vport->backbuf[BB_POS(vport, col, row + lines)]; 454 bbp = &vport->backbuf[BB_POS(vport, col, row)]; 455 456 glyph = xbp->glyph; 457 fg_color = xbp->fg_color; 458 bg_color = xbp->bg_color; 459 460 if ((bbp->glyph == glyph) 461 && (bbp->fg_color == xbp->fg_color) 462 && (bbp->bg_color == xbp->bg_color)) { 463 x += FONT_WIDTH; 464 continue; 465 } 466 } else { 467 glyph = 0; 468 fg_color = vport->attr.fg_color; 469 bg_color = vport->attr.bg_color; 470 } 471 472 (*vport->dglyph)(x, y, false, screen.glyphs, glyph, 473 fg_color, bg_color); 474 x += FONT_WIDTH; 475 } 476 y += FONT_SCANLINES; 477 } 478 479 /* 480 * Scroll backbuffer. 481 */ 482 483 if (lines > 0) { 484 memmove(vport->backbuf, vport->backbuf + vport->cols * lines, 485 vport->cols * (vport->rows - lines) * sizeof(bb_cell_t)); 486 backbuf_clear(&vport->backbuf[BB_POS(vport, 0, vport->rows - lines)], 487 vport->cols * lines, vport->attr.fg_color, vport->attr.bg_color); 488 } else { 489 memmove(vport->backbuf - vport->cols * lines, vport->backbuf, 490 vport->cols * (vport->rows + lines) * sizeof(bb_cell_t)); 491 backbuf_clear(vport->backbuf, - vport->cols * lines, 492 vport->attr.fg_color, vport->attr.bg_color); 493 } 494 } 495 496 /** Render glyphs 497 * 498 * Convert glyphs from device independent font 499 * description to current visual representation. 500 * 501 */ 502 static void render_glyphs(void) 503 { 504 unsigned int glyph; 505 506 for (glyph = 0; glyph < FONT_GLYPHS; glyph++) { 507 unsigned int y; 508 509 for (y = 0; y < FONT_SCANLINES; y++) { 510 unsigned int x; 511 512 for (x = 0; x < FONT_WIDTH; x++) { 513 screen.mask_conv(&screen.glyphs[GLYPH_POS(glyph, y, false) + x * screen.pixelbytes], 514 (fb_font[glyph][y] & (1 << (7 - x))) ? true : false); 515 516 screen.mask_conv(&screen.glyphs[GLYPH_POS(glyph, y, true) + x * screen.pixelbytes], 517 (fb_font[glyph][y] & (1 << (7 - x))) ? false : true); 518 } 519 } 520 } 521 } 522 523 /** Create new viewport 524 * 525 * @param x Origin of the viewport (x). 526 * @param y Origin of the viewport (y). 527 * @param width Width of the viewport. 528 * @param height Height of the viewport. 529 * 530 * @return New viewport number. 531 * 532 */ 533 static int vport_create(unsigned int x, unsigned int y, 534 unsigned int width, unsigned int height) 535 { 536 unsigned int i; 537 538 for (i = 0; i < MAX_VIEWPORTS; i++) { 539 if (!viewports[i].initialized) 852 atomic_inc(&dev->refcnt); 853 dev->claimed = true; 854 async_answer_0(iid, EOK); 855 856 while (true) { 857 ipc_call_t call; 858 ipc_callid_t callid = 859 async_get_call_timeout(&call, TICK_INTERVAL); 860 861 if (!callid) { 862 fbsrv_vp_cursor_flash(dev); 863 fbsrv_sequences_update(dev); 864 continue; 865 } 866 867 if (!IPC_GET_IMETHOD(call)) { 868 dev->claimed = false; 869 atomic_dec(&dev->refcnt); 870 async_answer_0(callid, EOK); 540 871 break; 541 }542 543 if (i == MAX_VIEWPORTS)544 return ELIMIT;545 546 unsigned int cols = width / FONT_WIDTH;547 unsigned int rows = height / FONT_SCANLINES;548 unsigned int bbsize = cols * rows * sizeof(bb_cell_t);549 unsigned int word_size = sizeof(unsigned long);550 551 bb_cell_t *backbuf = (bb_cell_t *) malloc(bbsize);552 if (!backbuf)553 return ENOMEM;554 555 uint8_t *bgpixel = (uint8_t *) malloc(screen.pixelbytes);556 if (!bgpixel) {557 free(backbuf);558 return ENOMEM;559 }560 561 backbuf_clear(backbuf, cols * rows, DEFAULT_FGCOLOR, DEFAULT_BGCOLOR);562 memset(bgpixel, 0, screen.pixelbytes);563 564 viewports[i].x = x;565 viewports[i].y = y;566 viewports[i].width = width;567 viewports[i].height = height;568 569 viewports[i].cols = cols;570 viewports[i].rows = rows;571 572 viewports[i].attr.bg_color = DEFAULT_BGCOLOR;573 viewports[i].attr.fg_color = DEFAULT_FGCOLOR;574 575 viewports[i].bgpixel = bgpixel;576 577 /*578 * Conditions necessary to select aligned version:579 * - word size is divisible by pixelbytes580 * - cell scanline size is divisible by word size581 * - cell scanlines are word-aligned582 *583 */584 if (((word_size % screen.pixelbytes) == 0)585 && ((FONT_WIDTH * screen.pixelbytes) % word_size == 0)586 && ((x * screen.pixelbytes) % word_size == 0)587 && (screen.scanline % word_size == 0)) {588 viewports[i].dglyph = draw_glyph_aligned;589 } else {590 viewports[i].dglyph = draw_glyph_fallback;591 }592 593 viewports[i].cur_col = 0;594 viewports[i].cur_row = 0;595 viewports[i].cursor_active = false;596 viewports[i].cursor_shown = false;597 598 viewports[i].bbsize = bbsize;599 viewports[i].backbuf = backbuf;600 601 viewports[i].initialized = true;602 603 screen.rgb_conv(viewports[i].bgpixel, viewports[i].attr.bg_color);604 605 return i;606 }607 608 609 /** Initialize framebuffer as a chardev output device610 *611 * @param addr Address of the framebuffer612 * @param xres Screen width in pixels613 * @param yres Screen height in pixels614 * @param visual Bits per pixel (8, 16, 24, 32)615 * @param scan Bytes per one scanline616 *617 */618 static bool screen_init(void *addr, unsigned int xres, unsigned int yres,619 unsigned int scan, unsigned int visual)620 {621 switch (visual) {622 case VISUAL_INDIRECT_8:623 screen.rgb_conv = bgr_323;624 screen.mask_conv = mask_323;625 screen.pixelbytes = 1;626 break;627 case VISUAL_RGB_5_5_5_LE:628 screen.rgb_conv = rgb_555_le;629 screen.mask_conv = mask_555;630 screen.pixelbytes = 2;631 break;632 case VISUAL_RGB_5_5_5_BE:633 screen.rgb_conv = rgb_555_be;634 screen.mask_conv = mask_555;635 screen.pixelbytes = 2;636 break;637 case VISUAL_RGB_5_6_5_LE:638 screen.rgb_conv = rgb_565_le;639 screen.mask_conv = mask_565;640 screen.pixelbytes = 2;641 break;642 case VISUAL_RGB_5_6_5_BE:643 screen.rgb_conv = rgb_565_be;644 screen.mask_conv = mask_565;645 screen.pixelbytes = 2;646 break;647 case VISUAL_RGB_8_8_8:648 screen.rgb_conv = rgb_888;649 screen.mask_conv = mask_888;650 screen.pixelbytes = 3;651 break;652 case VISUAL_BGR_8_8_8:653 screen.rgb_conv = bgr_888;654 screen.mask_conv = mask_888;655 screen.pixelbytes = 3;656 break;657 case VISUAL_RGB_8_8_8_0:658 screen.rgb_conv = rgb_8880;659 screen.mask_conv = mask_8880;660 screen.pixelbytes = 4;661 break;662 case VISUAL_RGB_0_8_8_8:663 screen.rgb_conv = rgb_0888;664 screen.mask_conv = mask_0888;665 screen.pixelbytes = 4;666 break;667 case VISUAL_BGR_0_8_8_8:668 screen.rgb_conv = bgr_0888;669 screen.mask_conv = mask_0888;670 screen.pixelbytes = 4;671 break;672 case VISUAL_BGR_8_8_8_0:673 screen.rgb_conv = bgr_8880;674 screen.mask_conv = mask_8880;675 screen.pixelbytes = 4;676 break;677 default:678 return false;679 }680 681 screen.fb_addr = (unsigned char *) addr;682 screen.xres = xres;683 screen.yres = yres;684 screen.scanline = scan;685 686 screen.glyphscanline = FONT_WIDTH * screen.pixelbytes;687 screen.glyphbytes = screen.glyphscanline * FONT_SCANLINES;688 689 size_t glyphsize = 2 * FONT_GLYPHS * screen.glyphbytes;690 uint8_t *glyphs = (uint8_t *) malloc(glyphsize);691 if (!glyphs)692 return false;693 694 memset(glyphs, 0, glyphsize);695 screen.glyphs = glyphs;696 697 render_glyphs();698 699 /* Create first viewport */700 vport_create(0, 0, xres, yres);701 702 return true;703 }704 705 706 /** Draw a glyph, takes advantage of alignment.707 *708 * This version can only be used if the following conditions are met:709 *710 * - word size is divisible by pixelbytes711 * - cell scanline size is divisible by word size712 * - cell scanlines are word-aligned713 *714 * It makes use of the pre-rendered mask to process (possibly) several715 * pixels at once (word size / pixelbytes pixels at a time are processed)716 * making it very fast. Most notably this version is not applicable at 24 bits717 * per pixel.718 *719 * @param x x coordinate of top-left corner on screen.720 * @param y y coordinate of top-left corner on screen.721 * @param cursor Draw glyph with cursor722 * @param glyphs Pointer to font bitmap.723 * @param glyph Code of the glyph to draw.724 * @param fg_color Foreground color.725 * @param bg_color Backgroudn color.726 *727 */728 static void draw_glyph_aligned(unsigned int x, unsigned int y, bool cursor,729 uint8_t *glyphs, uint32_t glyph, uint32_t fg_color, uint32_t bg_color)730 {731 unsigned int i;732 unsigned int yd;733 unsigned long fg_buf;734 unsigned long bg_buf;735 unsigned long mask;736 737 /*738 * Prepare a pair of words, one filled with foreground-color739 * pattern and the other filled with background-color pattern.740 */741 for (i = 0; i < sizeof(unsigned long) / screen.pixelbytes; i++) {742 screen.rgb_conv(&((uint8_t *) &fg_buf)[i * screen.pixelbytes],743 fg_color);744 screen.rgb_conv(&((uint8_t *) &bg_buf)[i * screen.pixelbytes],745 bg_color);746 }747 748 /* Pointer to the current position in the mask. */749 unsigned long *maskp = (unsigned long *) &glyphs[GLYPH_POS(glyph, 0, cursor)];750 751 /* Pointer to the current position on the screen. */752 unsigned long *dp = (unsigned long *) &screen.fb_addr[FB_POS(x, y)];753 754 /* Width of the character cell in words. */755 unsigned int ww = FONT_WIDTH * screen.pixelbytes / sizeof(unsigned long);756 757 /* Offset to add when moving to another screen scanline. */758 unsigned int d_add = screen.scanline - FONT_WIDTH * screen.pixelbytes;759 760 for (yd = 0; yd < FONT_SCANLINES; yd++) {761 /*762 * Now process the cell scanline, combining foreground763 * and background color patters using the pre-rendered mask.764 */765 for (i = 0; i < ww; i++) {766 mask = *maskp++;767 *dp++ = (fg_buf & mask) | (bg_buf & ~mask);768 }769 770 /* Move to the beginning of the next scanline of the cell. */771 dp = (unsigned long *) ((uint8_t *) dp + d_add);772 }773 }774 775 /** Draw a glyph, fallback version.776 *777 * This version does not make use of the pre-rendered mask, it uses778 * the font bitmap directly. It works always, but it is slower.779 *780 * @param x x coordinate of top-left corner on screen.781 * @param y y coordinate of top-left corner on screen.782 * @param cursor Draw glyph with cursor783 * @param glyphs Pointer to font bitmap.784 * @param glyph Code of the glyph to draw.785 * @param fg_color Foreground color.786 * @param bg_color Backgroudn color.787 *788 */789 void draw_glyph_fallback(unsigned int x, unsigned int y, bool cursor,790 uint8_t *glyphs, uint32_t glyph, uint32_t fg_color, uint32_t bg_color)791 {792 unsigned int i;793 unsigned int j;794 unsigned int yd;795 uint8_t fg_buf[4];796 uint8_t bg_buf[4];797 uint8_t *sp;798 uint8_t b;799 800 /* Pre-render 1x the foreground and background color pixels. */801 if (cursor) {802 screen.rgb_conv(fg_buf, bg_color);803 screen.rgb_conv(bg_buf, fg_color);804 } else {805 screen.rgb_conv(fg_buf, fg_color);806 screen.rgb_conv(bg_buf, bg_color);807 }808 809 /* Pointer to the current position on the screen. */810 uint8_t *dp = (uint8_t *) &screen.fb_addr[FB_POS(x, y)];811 812 /* Offset to add when moving to another screen scanline. */813 unsigned int d_add = screen.scanline - FONT_WIDTH * screen.pixelbytes;814 815 for (yd = 0; yd < FONT_SCANLINES; yd++) {816 /* Byte containing bits of the glyph scanline. */817 b = fb_font[glyph][yd];818 819 for (i = 0; i < FONT_WIDTH; i++) {820 /* Choose color based on the current bit. */821 sp = (b & 0x80) ? fg_buf : bg_buf;822 823 /* Copy the pixel. */824 for (j = 0; j < screen.pixelbytes; j++) {825 *dp++ = *sp++;826 }827 828 /* Move to the next bit. */829 b = b << 1;830 }831 832 /* Move to the beginning of the next scanline of the cell. */833 dp += d_add;834 }835 }836 837 /** Draw glyph at specified position in viewport.838 *839 * @param vport Viewport identification840 * @param cursor Draw glyph with cursor841 * @param col Screen position relative to viewport842 * @param row Screen position relative to viewport843 *844 */845 static void draw_vp_glyph(viewport_t *vport, bool cursor, unsigned int col,846 unsigned int row)847 {848 unsigned int x = vport->x + COL2X(col);849 unsigned int y = vport->y + ROW2Y(row);850 851 uint32_t glyph = vport->backbuf[BB_POS(vport, col, row)].glyph;852 uint32_t fg_color = vport->backbuf[BB_POS(vport, col, row)].fg_color;853 uint32_t bg_color = vport->backbuf[BB_POS(vport, col, row)].bg_color;854 855 (*vport->dglyph)(x, y, cursor, screen.glyphs, glyph,856 fg_color, bg_color);857 }858 859 /** Hide cursor if it is shown860 *861 */862 static void cursor_hide(viewport_t *vport)863 {864 if ((vport->cursor_active) && (vport->cursor_shown)) {865 draw_vp_glyph(vport, false, vport->cur_col, vport->cur_row);866 vport->cursor_shown = false;867 }868 }869 870 /** Show cursor if cursor showing is enabled871 *872 */873 static void cursor_show(viewport_t *vport)874 {875 /* Do not check for cursor_shown */876 if (vport->cursor_active) {877 draw_vp_glyph(vport, true, vport->cur_col, vport->cur_row);878 vport->cursor_shown = true;879 }880 }881 882 /** Invert cursor, if it is enabled883 *884 */885 static void cursor_blink(viewport_t *vport)886 {887 if (vport->cursor_shown)888 cursor_hide(vport);889 else890 cursor_show(vport);891 }892 893 /** Draw character at given position relative to viewport894 *895 * @param vport Viewport identification896 * @param c Character to draw897 * @param col Screen position relative to viewport898 * @param row Screen position relative to viewport899 *900 */901 static void draw_char(viewport_t *vport, wchar_t c, unsigned int col, unsigned int row)902 {903 bb_cell_t *bbp;904 905 /* Do not hide cursor if we are going to overwrite it */906 if ((vport->cursor_active) && (vport->cursor_shown) &&907 ((vport->cur_col != col) || (vport->cur_row != row)))908 cursor_hide(vport);909 910 bbp = &vport->backbuf[BB_POS(vport, col, row)];911 bbp->glyph = fb_font_glyph(c);912 bbp->fg_color = vport->attr.fg_color;913 bbp->bg_color = vport->attr.bg_color;914 915 draw_vp_glyph(vport, false, col, row);916 917 vport->cur_col = col;918 vport->cur_row = row;919 920 vport->cur_col++;921 if (vport->cur_col >= vport->cols) {922 vport->cur_col = 0;923 vport->cur_row++;924 if (vport->cur_row >= vport->rows)925 vport->cur_row--;926 }927 928 cursor_show(vport);929 }930 931 /** Draw text data to viewport.932 *933 * @param vport Viewport id934 * @param data Text data.935 * @param x Leftmost column of the area.936 * @param y Topmost row of the area.937 * @param w Number of rows.938 * @param h Number of columns.939 *940 */941 static void draw_text_data(viewport_t *vport, keyfield_t *data, unsigned int x,942 unsigned int y, unsigned int w, unsigned int h)943 {944 unsigned int i;945 unsigned int j;946 bb_cell_t *bbp;947 attrs_t *a;948 949 for (j = 0; j < h; j++) {950 for (i = 0; i < w; i++) {951 unsigned int col = x + i;952 unsigned int row = y + j;953 954 bbp = &vport->backbuf[BB_POS(vport, col, row)];955 956 a = &data[j * w + i].attrs;957 958 attr_rgb_t rgb;959 rgb.fg_color = 0;960 rgb.bg_color = 0;961 rgb_from_attr(&rgb, a);962 963 bbp->glyph = fb_font_glyph(data[j * w + i].character);964 bbp->fg_color = rgb.fg_color;965 bbp->bg_color = rgb.bg_color;966 967 draw_vp_glyph(vport, false, col, row);968 }969 }970 cursor_show(vport);971 }972 973 static void putpixel(viewport_t *vport, unsigned int x, unsigned int y,974 uint32_t color)975 {976 unsigned int dx = vport->x + x;977 unsigned int dy = vport->y + y;978 979 screen.rgb_conv(&screen.fb_addr[FB_POS(dx, dy)], color);980 }981 982 /** Draw image map983 *984 * @param[in] img Image map.985 * @param[in] sx Coordinate of upper left corner.986 * @param[in] sy Coordinate of upper left corner.987 * @param[in] maxwidth Maximum allowed width for picture.988 * @param[in] maxheight Maximum allowed height for picture.989 * @param[in] vport Viewport.990 *991 * @return EOK on success.992 *993 */994 static int imgmap_draw(imgmap_t *img, unsigned int sx, unsigned int sy,995 unsigned int maxwidth, unsigned int maxheight, void *vport)996 {997 if (img->visual != VISUAL_BGR_8_8_8)998 return EINVAL;999 1000 uint8_t *data = (uint8_t *) img->data;1001 1002 for (sysarg_t y = 0; y < img->height; y++) {1003 for (sysarg_t x = 0; x < img->width; x++) {1004 if ((x > maxwidth) || (y > maxheight)) {1005 data += 3;1006 continue;1007 }1008 1009 uint32_t color = (data[2] << 16) + (data[1] << 8) + data[0];1010 1011 putpixel(vport, sx + x, sy + y, color);1012 data += 3;1013 }1014 }1015 1016 return EOK;1017 }1018 1019 /** Return first free image map1020 *1021 */1022 static int find_free_imgmap(void)1023 {1024 unsigned int i;1025 1026 for (i = 0; i < MAX_IMGMAPS; i++)1027 if (!imgmaps[i])1028 return i;1029 1030 return -1;1031 }1032 1033 /** Create a new image map and return appropriate ID1034 *1035 */1036 static int shm2imgmap(imgmap_t *shm, size_t size)1037 {1038 int im = find_free_imgmap();1039 if (im == -1)1040 return ELIMIT;1041 1042 imgmap_t *imap = malloc(size);1043 if (!imap)1044 return ENOMEM;1045 1046 memcpy(imap, shm, size);1047 imgmaps[im] = imap;1048 return im;1049 }1050 1051 /** Handle shared memory communication calls1052 *1053 * Protocol for drawing image maps:1054 * - FB_PREPARE_SHM(client shm identification)1055 * - IPC_M_AS_AREA_SEND1056 * - FB_DRAW_IMGMAP(startx, starty)1057 * - FB_DROP_SHM1058 *1059 * Protocol for text drawing1060 * - IPC_M_AS_AREA_SEND1061 * - FB_DRAW_TEXT_DATA1062 *1063 * @param callid Callid of the current call1064 * @param call Current call data1065 * @param vp Active viewport1066 *1067 * @return false if the call was not handled byt this function, true otherwise1068 *1069 * Note: this function is not thread-safe, you would have1070 * to redefine static variables with fibril_local.1071 *1072 */1073 static bool shm_handle(ipc_callid_t callid, ipc_call_t *call, int vp)1074 {1075 static keyfield_t *interbuffer = NULL;1076 static size_t intersize = 0;1077 1078 static imgmap_t *shm = NULL;1079 static sysarg_t shm_id = 0;1080 static size_t shm_size;1081 1082 bool handled = true;1083 int retval = EOK;1084 viewport_t *vport = &viewports[vp];1085 unsigned int x;1086 unsigned int y;1087 unsigned int w;1088 unsigned int h;1089 1090 switch (IPC_GET_IMETHOD(*call)) {1091 case IPC_M_SHARE_OUT:1092 /* We accept one area for data interchange */1093 if (IPC_GET_ARG1(*call) == shm_id) {1094 void *dest = as_get_mappable_page(IPC_GET_ARG2(*call));1095 shm_size = IPC_GET_ARG2(*call);1096 if (async_answer_1(callid, EOK, (sysarg_t) dest)) {1097 shm_id = 0;1098 return false;1099 }1100 1101 shm = dest;1102 return true;1103 } else {1104 intersize = IPC_GET_ARG2(*call);1105 receive_comm_area(callid, call, (void *) &interbuffer);1106 }1107 return true;1108 case FB_PREPARE_SHM:1109 if (shm_id)1110 retval = EBUSY;1111 else1112 shm_id = IPC_GET_ARG1(*call);1113 break;1114 case FB_DROP_SHM:1115 if (shm) {1116 as_area_destroy(shm);1117 shm = NULL;1118 }1119 shm_id = 0;1120 break;1121 case FB_SHM2IMGMAP:1122 if (!shm) {1123 retval = EINVAL;1124 break;1125 }1126 retval = shm2imgmap(shm, shm_size);1127 break;1128 case FB_DRAW_IMGMAP:1129 if (!shm) {1130 retval = EINVAL;1131 break;1132 }1133 1134 x = IPC_GET_ARG1(*call);1135 y = IPC_GET_ARG2(*call);1136 1137 if ((x > vport->width) || (y > vport->height)) {1138 retval = EINVAL;1139 break;1140 }1141 1142 imgmap_draw(shm, IPC_GET_ARG1(*call), IPC_GET_ARG2(*call),1143 vport->width - x, vport->height - y, vport);1144 break;1145 case FB_DRAW_TEXT_DATA:1146 x = IPC_GET_ARG1(*call);1147 y = IPC_GET_ARG2(*call);1148 w = IPC_GET_ARG3(*call);1149 h = IPC_GET_ARG4(*call);1150 if (!interbuffer) {1151 retval = EINVAL;1152 break;1153 }1154 if (x + w > vport->cols || y + h > vport->rows) {1155 retval = EINVAL;1156 break;1157 }1158 if (intersize < w * h * sizeof(*interbuffer)) {1159 retval = EINVAL;1160 break;1161 }1162 draw_text_data(vport, interbuffer, x, y, w, h);1163 break;1164 default:1165 handled = false;1166 }1167 1168 if (handled)1169 async_answer_0(callid, retval);1170 1171 return handled;1172 }1173 1174 static void copy_vp_to_imgmap(viewport_t *vport, imgmap_t *imap)1175 {1176 unsigned int width = vport->width;1177 unsigned int height = vport->height;1178 1179 if (width + vport->x > screen.xres)1180 width = screen.xres - vport->x;1181 1182 if (height + vport->y > screen.yres)1183 height = screen.yres - vport->y;1184 1185 unsigned int realwidth = imap->width <= width ? imap->width : width;1186 unsigned int realheight = imap->height <= height ? imap->height : height;1187 1188 unsigned int srcrowsize = vport->width * screen.pixelbytes;1189 unsigned int realrowsize = realwidth * screen.pixelbytes;1190 1191 unsigned int y;1192 for (y = 0; y < realheight; y++) {1193 unsigned int tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes;1194 memcpy(imap->data + srcrowsize * y, screen.fb_addr + tmp, realrowsize);1195 }1196 }1197 1198 /** Save viewport to image map1199 *1200 */1201 static int save_vp_to_imgmap(viewport_t *vport)1202 {1203 int im = find_free_imgmap();1204 if (im == -1)1205 return ELIMIT;1206 1207 size_t size = screen.pixelbytes * vport->width * vport->height;1208 imgmap_t *imap = malloc(sizeof(imgmap_t) + size);1209 if (!imap)1210 return ENOMEM;1211 1212 imap->size = sizeof(imgmap_t) + size;1213 imap->width = vport->width;1214 imap->height = vport->height;1215 imap->visual = (visual_t) -1;1216 1217 copy_vp_to_imgmap(vport, imap);1218 imgmaps[im] = imap;1219 return im;1220 }1221 1222 /** Draw image map to screen1223 *1224 * @param vp Viewport to draw to1225 * @param im Image map identifier1226 *1227 */1228 static int draw_imgmap(int vp, int im)1229 {1230 imgmap_t *imap = imgmaps[im];1231 if (!imap)1232 return EINVAL;1233 1234 viewport_t *vport = &viewports[vp];1235 1236 unsigned int width = vport->width;1237 unsigned int height = vport->height;1238 1239 if (width + vport->x > screen.xres)1240 width = screen.xres - vport->x;1241 1242 if (height + vport->y > screen.yres)1243 height = screen.yres - vport->y;1244 1245 unsigned int realwidth = imap->width <= width ? imap->width : width;1246 unsigned int realheight = imap->height <= height ? imap->height : height;1247 1248 if (imap->visual == (visual_t) -1) {1249 unsigned int srcrowsize = vport->width * screen.pixelbytes;1250 unsigned int realrowsize = realwidth * screen.pixelbytes;1251 1252 unsigned int y;1253 for (y = 0; y < realheight; y++) {1254 unsigned int tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes;1255 memcpy(screen.fb_addr + tmp, imap->data + y * srcrowsize, realrowsize);1256 }1257 } else1258 imgmap_draw(imap, 0, 0, realwidth, realheight, vport);1259 1260 return EOK;1261 }1262 1263 /** Tick animation one step forward1264 *1265 */1266 static void anims_tick(void)1267 {1268 unsigned int i;1269 static int counts = 0;1270 1271 /* Limit redrawing */1272 counts = (counts + 1) % 8;1273 if (counts)1274 return;1275 1276 for (i = 0; i < MAX_ANIMATIONS; i++) {1277 if ((!animations[i].animlen) || (!animations[i].initialized) ||1278 (!animations[i].enabled))1279 continue;1280 1281 draw_imgmap(animations[i].vp, animations[i].imgmaps[animations[i].pos]);1282 animations[i].pos = (animations[i].pos + 1) % animations[i].animlen;1283 }1284 }1285 1286 1287 static unsigned int pointer_x;1288 static unsigned int pointer_y;1289 static bool pointer_shown, pointer_enabled;1290 static int pointer_vport = -1;1291 static int pointer_imgmap = -1;1292 1293 1294 static void mouse_show(void)1295 {1296 int i, j;1297 int visibility;1298 int color;1299 int bytepos;1300 1301 if ((pointer_shown) || (!pointer_enabled))1302 return;1303 1304 /* Save image under the pointer. */1305 if (pointer_vport == -1) {1306 pointer_vport = vport_create(pointer_x, pointer_y, pointer_width, pointer_height);1307 if (pointer_vport < 0)1308 return;1309 } else {1310 viewports[pointer_vport].x = pointer_x;1311 viewports[pointer_vport].y = pointer_y;1312 }1313 1314 if (pointer_imgmap == -1)1315 pointer_imgmap = save_vp_to_imgmap(&viewports[pointer_vport]);1316 else1317 copy_vp_to_imgmap(&viewports[pointer_vport], imgmaps[pointer_imgmap]);1318 1319 /* Draw mouse pointer. */1320 for (i = 0; i < pointer_height; i++)1321 for (j = 0; j < pointer_width; j++) {1322 bytepos = i * ((pointer_width - 1) / 8 + 1) + j / 8;1323 visibility = pointer_mask_bits[bytepos] &1324 (1 << (j % 8));1325 if (visibility) {1326 color = pointer_bits[bytepos] &1327 (1 << (j % 8)) ? 0 : 0xffffff;1328 if (pointer_x + j < screen.xres && pointer_y +1329 i < screen.yres)1330 putpixel(&viewports[0], pointer_x + j,1331 pointer_y + i, color);1332 }1333 }1334 pointer_shown = 1;1335 }1336 1337 1338 static void mouse_hide(void)1339 {1340 /* Restore image under the pointer. */1341 if (pointer_shown) {1342 draw_imgmap(pointer_vport, pointer_imgmap);1343 pointer_shown = 0;1344 }1345 }1346 1347 1348 static void mouse_move(unsigned int x, unsigned int y)1349 {1350 mouse_hide();1351 pointer_x = x % screen.xres;1352 pointer_y = y % screen.yres;1353 mouse_show();1354 }1355 1356 1357 static int anim_handle(ipc_callid_t callid, ipc_call_t *call, int vp)1358 {1359 bool handled = true;1360 int retval = EOK;1361 int i, nvp;1362 int newval;1363 1364 switch (IPC_GET_IMETHOD(*call)) {1365 case FB_ANIM_CREATE:1366 nvp = IPC_GET_ARG1(*call);1367 if (nvp == -1)1368 nvp = vp;1369 if (nvp >= MAX_VIEWPORTS || nvp < 0 ||1370 !viewports[nvp].initialized) {1371 retval = EINVAL;1372 break;1373 }1374 for (i = 0; i < MAX_ANIMATIONS; i++) {1375 if (!animations[i].initialized)1376 break;1377 }1378 if (i == MAX_ANIMATIONS) {1379 retval = ELIMIT;1380 break;1381 }1382 animations[i].initialized = 1;1383 animations[i].animlen = 0;1384 animations[i].pos = 0;1385 animations[i].enabled = 0;1386 animations[i].vp = nvp;1387 retval = i;1388 break;1389 case FB_ANIM_DROP:1390 i = IPC_GET_ARG1(*call);1391 if (i >= MAX_ANIMATIONS || i < 0) {1392 retval = EINVAL;1393 break;1394 }1395 animations[i].initialized = 0;1396 break;1397 case FB_ANIM_ADDIMGMAP:1398 i = IPC_GET_ARG1(*call);1399 if (i >= MAX_ANIMATIONS || i < 0 ||1400 !animations[i].initialized) {1401 retval = EINVAL;1402 break;1403 }1404 if (animations[i].animlen == MAX_ANIM_LEN) {1405 retval = ELIMIT;1406 break;1407 }1408 newval = IPC_GET_ARG2(*call);1409 if (newval < 0 || newval > MAX_IMGMAPS ||1410 !imgmaps[newval]) {1411 retval = EINVAL;1412 break;1413 }1414 animations[i].imgmaps[animations[i].animlen++] = newval;1415 break;1416 case FB_ANIM_CHGVP:1417 i = IPC_GET_ARG1(*call);1418 if (i >= MAX_ANIMATIONS || i < 0) {1419 retval = EINVAL;1420 break;1421 }1422 nvp = IPC_GET_ARG2(*call);1423 if (nvp == -1)1424 nvp = vp;1425 if (nvp >= MAX_VIEWPORTS || nvp < 0 ||1426 !viewports[nvp].initialized) {1427 retval = EINVAL;1428 break;1429 }1430 animations[i].vp = nvp;1431 break;1432 case FB_ANIM_START:1433 case FB_ANIM_STOP:1434 i = IPC_GET_ARG1(*call);1435 if (i >= MAX_ANIMATIONS || i < 0) {1436 retval = EINVAL;1437 break;1438 }1439 newval = (IPC_GET_IMETHOD(*call) == FB_ANIM_START);1440 if (newval ^ animations[i].enabled) {1441 animations[i].enabled = newval;1442 anims_enabled += newval ? 1 : -1;1443 }1444 break;1445 default:1446 handled = 0;1447 }1448 if (handled)1449 async_answer_0(callid, retval);1450 return handled;1451 }1452 1453 /** Handler for messages concerning image map handling1454 *1455 */1456 static int imgmap_handle(ipc_callid_t callid, ipc_call_t *call, int vp)1457 {1458 bool handled = true;1459 int retval = EOK;1460 int i, nvp;1461 1462 switch (IPC_GET_IMETHOD(*call)) {1463 case FB_VP_DRAW_IMGMAP:1464 nvp = IPC_GET_ARG1(*call);1465 if (nvp == -1)1466 nvp = vp;1467 1468 if (nvp < 0 || nvp >= MAX_VIEWPORTS ||1469 !viewports[nvp].initialized) {1470 retval = EINVAL;1471 break;1472 }1473 1474 i = IPC_GET_ARG2(*call);1475 retval = draw_imgmap(nvp, i);1476 break;1477 case FB_VP2IMGMAP:1478 nvp = IPC_GET_ARG1(*call);1479 if (nvp == -1)1480 nvp = vp;1481 1482 if (nvp < 0 || nvp >= MAX_VIEWPORTS ||1483 !viewports[nvp].initialized) {1484 retval = EINVAL;1485 break;1486 }1487 1488 retval = save_vp_to_imgmap(&viewports[nvp]);1489 break;1490 case FB_DROP_IMGMAP:1491 i = IPC_GET_ARG1(*call);1492 if (i >= MAX_IMGMAPS) {1493 retval = EINVAL;1494 break;1495 }1496 1497 if (imgmaps[i]) {1498 free(imgmaps[i]);1499 imgmaps[i] = NULL;1500 }1501 1502 break;1503 default:1504 handled = 0;1505 }1506 1507 if (handled)1508 async_answer_0(callid, retval);1509 return handled;1510 1511 }1512 1513 static int rgb_from_style(attr_rgb_t *rgb, int style)1514 {1515 switch (style) {1516 case STYLE_NORMAL:1517 rgb->fg_color = color_table[COLOR_BLACK];1518 rgb->bg_color = color_table[COLOR_WHITE];1519 break;1520 case STYLE_EMPHASIS:1521 rgb->fg_color = color_table[COLOR_RED];1522 rgb->bg_color = color_table[COLOR_WHITE];1523 break;1524 case STYLE_INVERTED:1525 rgb->fg_color = color_table[COLOR_WHITE];1526 rgb->bg_color = color_table[COLOR_BLACK];1527 break;1528 case STYLE_SELECTED:1529 rgb->fg_color = color_table[COLOR_WHITE];1530 rgb->bg_color = color_table[COLOR_RED];1531 break;1532 default:1533 return EINVAL;1534 }1535 1536 return EOK;1537 }1538 1539 static int rgb_from_idx(attr_rgb_t *rgb, sysarg_t fg_color,1540 sysarg_t bg_color, sysarg_t flags)1541 {1542 fg_color = (fg_color & 7) | ((flags & CATTR_BRIGHT) ? 8 : 0);1543 bg_color = (bg_color & 7) | ((flags & CATTR_BRIGHT) ? 8 : 0);1544 1545 rgb->fg_color = color_table[fg_color];1546 rgb->bg_color = color_table[bg_color];1547 1548 return EOK;1549 }1550 1551 static int rgb_from_attr(attr_rgb_t *rgb, const attrs_t *a)1552 {1553 int rc;1554 1555 switch (a->t) {1556 case at_style:1557 rc = rgb_from_style(rgb, a->a.s.style);1558 break;1559 case at_idx:1560 rc = rgb_from_idx(rgb, a->a.i.fg_color,1561 a->a.i.bg_color, a->a.i.flags);1562 break;1563 case at_rgb:1564 *rgb = a->a.r;1565 rc = EOK;1566 break;1567 }1568 1569 return rc;1570 }1571 1572 static int fb_set_style(viewport_t *vport, sysarg_t style)1573 {1574 return rgb_from_style(&vport->attr, (int) style);1575 }1576 1577 static int fb_set_color(viewport_t *vport, sysarg_t fg_color,1578 sysarg_t bg_color, sysarg_t flags)1579 {1580 return rgb_from_idx(&vport->attr, fg_color, bg_color, flags);1581 }1582 1583 /** Function for handling connections to FB1584 *1585 */1586 static void fb_client_connection(ipc_callid_t iid, ipc_call_t *icall,1587 void *arg)1588 {1589 unsigned int vp = 0;1590 viewport_t *vport = &viewports[vp];1591 1592 if (client_connected) {1593 async_answer_0(iid, ELIMIT);1594 return;1595 }1596 1597 /* Accept connection */1598 client_connected = true;1599 async_answer_0(iid, EOK);1600 1601 while (true) {1602 ipc_callid_t callid;1603 ipc_call_t call;1604 int retval;1605 unsigned int i;1606 int scroll;1607 wchar_t ch;1608 unsigned int col, row;1609 1610 if ((vport->cursor_active) || (anims_enabled))1611 callid = async_get_call_timeout(&call, 250000);1612 else1613 callid = async_get_call(&call);1614 1615 mouse_hide();1616 if (!callid) {1617 cursor_blink(vport);1618 anims_tick();1619 mouse_show();1620 continue;1621 }1622 1623 if (shm_handle(callid, &call, vp))1624 continue;1625 1626 if (imgmap_handle(callid, &call, vp))1627 continue;1628 1629 if (anim_handle(callid, &call, vp))1630 continue;1631 1632 if (!IPC_GET_IMETHOD(call)) {1633 client_connected = false;1634 1635 /* Cleanup other viewports */1636 for (i = 1; i < MAX_VIEWPORTS; i++)1637 vport->initialized = false;1638 1639 /* Exit thread */1640 return;1641 872 } 1642 873 1643 874 switch (IPC_GET_IMETHOD(call)) { 1644 case FB_PUTCHAR: 1645 ch = IPC_GET_ARG1(call); 1646 col = IPC_GET_ARG2(call); 1647 row = IPC_GET_ARG3(call); 1648 1649 if ((col >= vport->cols) || (row >= vport->rows)) { 1650 retval = EINVAL; 1651 break; 1652 } 1653 async_answer_0(callid, EOK); 1654 1655 draw_char(vport, ch, col, row); 1656 1657 /* Message already answered */ 1658 continue; 1659 case FB_CLEAR: 1660 vport_clear(vport); 1661 cursor_show(vport); 1662 retval = EOK; 1663 break; 1664 case FB_CURSOR_GOTO: 1665 col = IPC_GET_ARG1(call); 1666 row = IPC_GET_ARG2(call); 1667 1668 if ((col >= vport->cols) || (row >= vport->rows)) { 1669 retval = EINVAL; 1670 break; 1671 } 1672 retval = EOK; 1673 1674 cursor_hide(vport); 1675 vport->cur_col = col; 1676 vport->cur_row = row; 1677 cursor_show(vport); 1678 break; 1679 case FB_CURSOR_VISIBILITY: 1680 cursor_hide(vport); 1681 vport->cursor_active = IPC_GET_ARG1(call); 1682 cursor_show(vport); 1683 retval = EOK; 1684 break; 1685 case FB_GET_CSIZE: 1686 async_answer_2(callid, EOK, vport->cols, vport->rows); 1687 continue; 1688 case FB_GET_COLOR_CAP: 1689 async_answer_1(callid, EOK, FB_CCAP_RGB); 1690 continue; 1691 case FB_SCROLL: 1692 scroll = IPC_GET_ARG1(call); 1693 if ((scroll > (int) vport->rows) || (scroll < (-(int) vport->rows))) { 1694 retval = EINVAL; 1695 break; 1696 } 1697 cursor_hide(vport); 1698 vport_scroll(vport, scroll); 1699 cursor_show(vport); 1700 retval = EOK; 1701 break; 1702 case FB_VIEWPORT_SWITCH: 1703 i = IPC_GET_ARG1(call); 1704 if (i >= MAX_VIEWPORTS) { 1705 retval = EINVAL; 1706 break; 1707 } 1708 if (!viewports[i].initialized) { 1709 retval = EADDRNOTAVAIL; 1710 break; 1711 } 1712 cursor_hide(vport); 1713 vp = i; 1714 vport = &viewports[vp]; 1715 cursor_show(vport); 1716 retval = EOK; 1717 break; 1718 case FB_VIEWPORT_CREATE: 1719 retval = vport_create(IPC_GET_ARG1(call) >> 16, 1720 IPC_GET_ARG1(call) & 0xffff, 1721 IPC_GET_ARG2(call) >> 16, 1722 IPC_GET_ARG2(call) & 0xffff); 1723 break; 1724 case FB_VIEWPORT_DELETE: 1725 i = IPC_GET_ARG1(call); 1726 if (i >= MAX_VIEWPORTS) { 1727 retval = EINVAL; 1728 break; 1729 } 1730 if (!viewports[i].initialized) { 1731 retval = EADDRNOTAVAIL; 1732 break; 1733 } 1734 viewports[i].initialized = false; 1735 if (viewports[i].bgpixel) 1736 free(viewports[i].bgpixel); 1737 if (viewports[i].backbuf) 1738 free(viewports[i].backbuf); 1739 retval = EOK; 1740 break; 1741 case FB_SET_STYLE: 1742 retval = fb_set_style(vport, IPC_GET_ARG1(call)); 1743 break; 1744 case FB_SET_COLOR: 1745 retval = fb_set_color(vport, IPC_GET_ARG1(call), 1746 IPC_GET_ARG2(call), IPC_GET_ARG3(call)); 1747 break; 1748 case FB_SET_RGB_COLOR: 1749 vport->attr.fg_color = IPC_GET_ARG1(call); 1750 vport->attr.bg_color = IPC_GET_ARG2(call); 1751 retval = EOK; 1752 break; 1753 case FB_GET_RESOLUTION: 1754 async_answer_2(callid, EOK, screen.xres, screen.yres); 1755 continue; 1756 case FB_POINTER_MOVE: 1757 pointer_enabled = true; 1758 mouse_move(IPC_GET_ARG1(call), IPC_GET_ARG2(call)); 1759 retval = EOK; 1760 break; 1761 case FB_SCREEN_YIELD: 1762 case FB_SCREEN_RECLAIM: 1763 retval = EOK; 1764 break; 1765 default: 1766 retval = ENOENT; 1767 } 1768 async_answer_0(callid, retval); 1769 } 1770 } 1771 1772 /** Initialization of framebuffer 1773 * 1774 */ 1775 int fb_init(void) 1776 { 1777 async_set_client_connection(fb_client_connection); 1778 1779 sysarg_t fb_ph_addr; 1780 if (sysinfo_get_value("fb.address.physical", &fb_ph_addr) != EOK) 1781 return -1; 1782 1783 sysarg_t fb_offset; 1784 if (sysinfo_get_value("fb.offset", &fb_offset) != EOK) 1785 fb_offset = 0; 1786 1787 sysarg_t fb_width; 1788 if (sysinfo_get_value("fb.width", &fb_width) != EOK) 1789 return -1; 1790 1791 sysarg_t fb_height; 1792 if (sysinfo_get_value("fb.height", &fb_height) != EOK) 1793 return -1; 1794 1795 sysarg_t fb_scanline; 1796 if (sysinfo_get_value("fb.scanline", &fb_scanline) != EOK) 1797 return -1; 1798 1799 sysarg_t fb_visual; 1800 if (sysinfo_get_value("fb.visual", &fb_visual) != EOK) 1801 return -1; 1802 1803 sysarg_t fbsize = fb_scanline * fb_height; 1804 void *fb_addr = as_get_mappable_page(fbsize); 1805 1806 if (physmem_map((void *) fb_ph_addr + fb_offset, fb_addr, 1807 ALIGN_UP(fbsize, PAGE_SIZE) >> PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE) != 0) 1808 return -1; 1809 1810 if (screen_init(fb_addr, fb_width, fb_height, fb_scanline, fb_visual)) 1811 return 0; 1812 1813 return -1; 1814 } 1815 1816 /** 1817 * @} 1818 */ 875 876 /* Screen methods */ 877 878 case FB_GET_RESOLUTION: 879 fbsrv_get_resolution(dev, callid, &call); 880 break; 881 case FB_YIELD: 882 fbsrv_yield(dev, callid, &call); 883 break; 884 case FB_CLAIM: 885 fbsrv_claim(dev, callid, &call); 886 break; 887 case FB_POINTER_UPDATE: 888 fbsrv_pointer_update(dev, callid, &call); 889 break; 890 891 /* Object methods */ 892 893 case FB_VP_CREATE: 894 fbsrv_vp_create(dev, callid, &call); 895 break; 896 case FB_VP_DESTROY: 897 fbsrv_vp_destroy(dev, callid, &call); 898 break; 899 case FB_FRONTBUF_CREATE: 900 fbsrv_frontbuf_create(dev, callid, &call); 901 break; 902 case FB_FRONTBUF_DESTROY: 903 fbsrv_frontbuf_destroy(dev, callid, &call); 904 break; 905 case FB_IMAGEMAP_CREATE: 906 fbsrv_imagemap_create(dev, callid, &call); 907 break; 908 case FB_IMAGEMAP_DESTROY: 909 fbsrv_imagemap_destroy(dev, callid, &call); 910 break; 911 case FB_SEQUENCE_CREATE: 912 fbsrv_sequence_create(dev, callid, &call); 913 break; 914 case FB_SEQUENCE_DESTROY: 915 fbsrv_sequence_destroy(dev, callid, &call); 916 break; 917 case FB_SEQUENCE_ADD_IMAGEMAP: 918 fbsrv_sequence_add_imagemap(dev, callid, &call); 919 break; 920 921 /* Viewport stateful methods */ 922 923 case FB_VP_FOCUS: 924 fbsrv_vp_focus(dev, callid, &call); 925 break; 926 case FB_VP_CLEAR: 927 fbsrv_vp_clear(dev, callid, &call); 928 break; 929 case FB_VP_GET_DIMENSIONS: 930 fbsrv_vp_get_dimensions(dev, callid, &call); 931 break; 932 case FB_VP_GET_CAPS: 933 fbsrv_vp_get_caps(dev, callid, &call); 934 break; 935 936 /* Style methods (viewport specific) */ 937 938 case FB_VP_CURSOR_UPDATE: 939 fbsrv_vp_cursor_update(dev, callid, &call); 940 break; 941 case FB_VP_SET_STYLE: 942 fbsrv_vp_set_style(dev, callid, &call); 943 break; 944 case FB_VP_SET_COLOR: 945 fbsrv_vp_set_color(dev, callid, &call); 946 break; 947 case FB_VP_SET_RGB_COLOR: 948 fbsrv_vp_set_rgb_color(dev, callid, &call); 949 break; 950 951 /* Text output methods (viewport specific) */ 952 953 case FB_VP_PUTCHAR: 954 fbsrv_vp_putchar(dev, callid, &call); 955 break; 956 case FB_VP_UPDATE: 957 fbsrv_vp_update(dev, callid, &call); 958 break; 959 case FB_VP_DAMAGE: 960 fbsrv_vp_damage(dev, callid, &call); 961 break; 962 963 /* Image map methods (viewport specific) */ 964 965 case FB_VP_IMAGEMAP_DAMAGE: 966 fbsrv_vp_imagemap_damage(dev, callid, &call); 967 break; 968 969 /* Sequence methods (viewport specific) */ 970 971 case FB_VP_SEQUENCE_START: 972 fbsrv_vp_sequence_start(dev, callid, &call); 973 break; 974 case FB_VP_SEQUENCE_STOP: 975 fbsrv_vp_sequence_stop(dev, callid, &call); 976 break; 977 978 default: 979 async_answer_0(callid, EINVAL); 980 } 981 } 982 } 983 984 int main(int argc, char *argv[]) 985 { 986 printf("%s: HelenOS framebuffer service\n", NAME); 987 988 /* Register server */ 989 async_set_client_connection(client_connection); 990 int rc = loc_server_register(NAME); 991 if (rc != EOK) { 992 printf("%s: Unable to register driver (%d)\n", NAME, rc); 993 return 1; 994 } 995 996 ega_init(); 997 kchar_init(); 998 kfb_init(); 999 niagara_init(); 1000 ski_init(); 1001 1002 printf("%s: Accepting connections\n", NAME); 1003 task_retval(0); 1004 async_manager(); 1005 1006 /* Never reached */ 1007 return 0; 1008 } -
uspace/srv/hid/fb/fb.h
rbd5f3b7 r00aece0 1 1 /* 2 * Copyright (c) 20 06 Ondrej Palkovsky2 * Copyright (c) 2011 Martin Decky 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup fb30 * @ingroup fbs31 * @{32 */33 /** @file34 */35 36 29 #ifndef FB_FB_H_ 37 30 #define FB_FB_H_ 38 31 39 #include <stdint.h> 32 #include <sys/types.h> 33 #include <bool.h> 34 #include <loc.h> 35 #include <io/console.h> 36 #include <io/style.h> 37 #include <io/color.h> 38 #include <fb.h> 39 #include <screenbuffer.h> 40 #include <imgmap.h> 40 41 41 extern int fb_init(void); 42 struct fbdev; 43 struct fbvp; 44 45 typedef struct { 46 int (* yield)(struct fbdev *dev); 47 int (* claim)(struct fbdev *dev); 48 void (* pointer_update)(struct fbdev *dev, sysarg_t x, sysarg_t y, 49 bool visible); 50 51 int (* get_resolution)(struct fbdev *dev, sysarg_t *width, 52 sysarg_t *height); 53 void (* font_metrics)(struct fbdev *dev, sysarg_t width, 54 sysarg_t height, sysarg_t *cols, sysarg_t *rows); 55 56 int (* vp_create)(struct fbdev *dev, struct fbvp *vp); 57 void (* vp_destroy)(struct fbdev *dev, struct fbvp *vp); 58 59 void (* vp_clear)(struct fbdev *dev, struct fbvp *vp); 60 console_caps_t (* vp_get_caps)(struct fbdev *dev, struct fbvp *vp); 61 62 void (* vp_cursor_update)(struct fbdev *dev, struct fbvp *vp, 63 sysarg_t prev_col, sysarg_t prev_row, sysarg_t col, sysarg_t row, 64 bool visible); 65 void (* vp_cursor_flash)(struct fbdev *dev, struct fbvp *vp, 66 sysarg_t col, sysarg_t row); 67 68 void (* vp_char_update)(struct fbdev *dev, struct fbvp *vp, sysarg_t col, 69 sysarg_t row); 70 71 void (* vp_imgmap_damage)(struct fbdev *dev, struct fbvp *vp, 72 imgmap_t *imgmap, sysarg_t col, sysarg_t row, sysarg_t cols, 73 sysarg_t rows); 74 } fbdev_ops_t; 75 76 typedef struct fbdev { 77 link_t link; 78 79 atomic_t refcnt; 80 bool claimed; 81 82 sysarg_t index; 83 service_id_t dsid; 84 struct fbvp *active_vp; 85 86 list_t vps; 87 list_t frontbufs; 88 list_t imagemaps; 89 list_t sequences; 90 91 fbdev_ops_t ops; 92 void *data; 93 } fbdev_t; 94 95 typedef struct fbvp { 96 link_t link; 97 98 sysarg_t x; 99 sysarg_t y; 100 101 sysarg_t width; 102 sysarg_t height; 103 104 sysarg_t cols; 105 sysarg_t rows; 106 107 char_attrs_t attrs; 108 list_t sequences; 109 110 screenbuffer_t *backbuf; 111 sysarg_t top_row; 112 113 bool cursor_active; 114 bool cursor_flash; 115 116 void *data; 117 } fbvp_t; 118 119 typedef struct { 120 link_t link; 121 122 size_t size; 123 unsigned int flags; 124 void *data; 125 } frontbuf_t; 126 127 typedef struct { 128 link_t link; 129 link_t seq_link; 130 131 size_t size; 132 unsigned int flags; 133 void *data; 134 } imagemap_t; 135 136 typedef struct { 137 link_t link; 138 139 list_t imagemaps; 140 size_t count; 141 } sequence_t; 142 143 typedef struct { 144 link_t link; 145 146 sequence_t *seq; 147 size_t current; 148 } sequence_vp_t; 149 150 extern fbdev_t *fbdev_register(fbdev_ops_t *, void *); 42 151 43 152 #endif 44 45 /** @}46 */ -
uspace/srv/hid/fb/gfx/font-8x16.c
rbd5f3b7 r00aece0 43 43 * glyph in the font or returns an index to the question 44 44 * mark glyph if no specific glyph exists. 45 * 45 46 */ 46 47 uint16_t fb_font_glyph(const wchar_t ch) -
uspace/srv/hid/fb/gfx/font-8x16.h
rbd5f3b7 r00aece0 36 36 #define FONT_8X16_H_ 37 37 38 #include <sys/types.h> 39 38 40 #define FONT_GLYPHS 2899 39 41 #define FONT_WIDTH 8 40 42 #define FONT_SCANLINES 16 41 43 42 #include <sys/types.h> 43 44 extern uint16_t fb_font_glyph(const wchar_t ch); 44 extern uint16_t fb_font_glyph(const wchar_t); 45 45 extern uint8_t fb_font[FONT_GLYPHS][FONT_SCANLINES]; 46 46 -
uspace/srv/hid/fb/port/ega.h
rbd5f3b7 r00aece0 27 27 */ 28 28 29 /** @addtogroup egafb30 * @brief HelenOS EGA framebuffer.31 * @ingroup fbs32 * @{33 */34 29 /** @file 35 30 */ 36 31 37 #ifndef FB_ EGA_H_38 #define FB_ EGA_H_32 #ifndef FB_PORT_EGA_H_ 33 #define FB_PORT_EGA_H_ 39 34 40 35 extern int ega_init(void); -
uspace/srv/hid/fb/port/kchar.c
rbd5f3b7 r00aece0 28 28 */ 29 29 30 /** @defgroup msimfb MSIM text console31 * @brief HelenOS MSIM text console.32 * @ingroup fbs33 * @{34 */35 30 /** @file 36 31 */ 37 32 38 #include < async.h>39 #include < libc.h>33 #include <sys/types.h> 34 #include <errno.h> 40 35 #include <sysinfo.h> 36 #include <ddi.h> 41 37 #include <as.h> 42 #include <ddi.h> 43 #include <errno.h> 38 #include <align.h> 39 #include "../ctl/serial.h" 40 #include "kchar.h" 44 41 45 #include "serial_console.h" 46 #include "msim.h" 42 typedef struct { 43 uint8_t *addr; 44 } kchar_t; 47 45 48 #define WIDTH 80 49 #define HEIGHT 24 46 static kchar_t kchar; 50 47 51 static char *virt_addr; 52 53 static void msim_putc(const char c) 48 static void kchar_putchar(wchar_t ch) 54 49 { 55 *virt_addr = c; 50 if ((ch >= 0) && (ch < 128)) 51 *kchar.addr = ch; 52 else 53 *kchar.addr = '?'; 56 54 } 57 55 58 int msim_init(void)56 static void kchar_control_puts(const char *str) 59 57 { 60 sysarg_t phys_addr; 61 if (sysinfo_get_value("fb.address.physical", &phys_addr) != EOK) 62 return -1; 58 while (*str) 59 *kchar.addr = *(str++); 60 } 61 62 int kchar_init(void) 63 { 64 sysarg_t present; 65 int rc = sysinfo_get_value("fb", &present); 66 if (rc != EOK) 67 present = false; 63 68 64 virt_addr = (char *) as_get_mappable_page(1); 69 if (!present) 70 return ENOENT; 65 71 66 if (physmem_map((void *) phys_addr, virt_addr, 1, 67 AS_AREA_READ | AS_AREA_WRITE) != 0) 68 return -1; 72 sysarg_t kind; 73 rc = sysinfo_get_value("fb.kind", &kind); 74 if (rc != EOK) 75 kind = (sysarg_t) -1; 69 76 70 serial_console_init(msim_putc, WIDTH, HEIGHT); 77 if (kind != 3) 78 return EINVAL; 71 79 72 async_set_client_connection(serial_client_connection); 73 return 0; 80 sysarg_t paddr; 81 rc = sysinfo_get_value("fb.address.physical", &paddr); 82 if (rc != EOK) 83 return rc; 84 85 rc = physmem_map((void *) paddr, 86 ALIGN_UP(1, PAGE_SIZE) >> PAGE_WIDTH, 87 AS_AREA_READ | AS_AREA_WRITE, (void *) &kchar.addr); 88 if (rc != EOK) 89 return rc; 90 91 return serial_init(kchar_putchar, kchar_control_puts); 74 92 } 75 93 -
uspace/srv/hid/fb/port/kchar.h
rbd5f3b7 r00aece0 1 1 /* 2 2 * Copyright (c) 2006 Ondrej Palkovsky 3 * Copyright (c) 2008 Martin Decky 3 4 * All rights reserved. 4 5 * … … 27 28 */ 28 29 29 #ifndef FB_MAIN_H_ 30 #define FB_MAIN_H_ 30 /** @file 31 */ 31 32 32 extern void receive_comm_area(ipc_callid_t, ipc_call_t *, void **); 33 #ifndef FB_PORT_KCHAR_H_ 34 #define FB_PORT_KCHAR_H_ 35 36 extern int kchar_init(void); 33 37 34 38 #endif 39 40 /** @} 41 */ -
uspace/srv/hid/fb/port/niagara.c
rbd5f3b7 r00aece0 29 29 */ 30 30 31 /** @defgroup niagarafb32 * @brief userland driver of the Niagara console output33 * @{34 */35 31 /** @file 36 32 */ 37 33 38 #include <async.h> 34 #include <sys/types.h> 35 #include <errno.h> 39 36 #include <sysinfo.h> 37 #include <ddi.h> 40 38 #include <as.h> 41 #include <errno.h> 42 #include <stdio.h> 43 #include <ddi.h> 44 45 #include "serial_console.h" 39 #include <align.h> 40 #include "../ctl/serial.h" 46 41 #include "niagara.h" 47 42 48 #define WIDTH 80 49 #define HEIGHT 24 43 #define OUTPUT_FIFO_SIZE ((PAGE_SIZE) - 2 * sizeof(uint64_t)) 50 44 51 /**52 * Virtual address mapped to the buffer shared with the kernel counterpart.53 */54 static uintptr_t output_buffer_addr;55 56 /*57 * Kernel counterpart of the driver reads characters to be printed from here.58 * Keep in sync with the definition from59 * kernel/arch/sparc64/src/drivers/niagara.c.60 */61 #define OUTPUT_BUFFER_SIZE ((PAGE_SIZE) - 2 * 8)62 45 typedef volatile struct { 63 46 uint64_t read_ptr; 64 47 uint64_t write_ptr; 65 char data[OUTPUT_BUFFER_SIZE]; 66 } 67 __attribute__ ((packed)) 68 __attribute__ ((aligned(PAGE_SIZE))) 69 *output_buffer_t; 48 char data[OUTPUT_FIFO_SIZE]; 49 } __attribute__((packed)) output_fifo_t; 70 50 71 output_buffer_t output_buffer; 51 typedef struct { 52 output_fifo_t *fifo; 53 } niagara_t; 72 54 73 /** 74 * Pushes the character to the Niagara serial. 75 * @param c character to be pushed 76 */ 77 static void niagara_putc(char c) 55 static niagara_t niagara; 56 57 static void niagara_putc(const char c) 78 58 { 79 while ( output_buffer->write_ptr ==80 (output_buffer->read_ptr + OUTPUT_BUFFER_SIZE - 1)81 % OUTPUT_BUFFER_SIZE)82 ;83 output_buffer->data[output_buffer->write_ptr] = (uint64_t)c;84 output_buffer->write_ptr =85 ((output_buffer->write_ptr) + 1) % OUTPUT_BUFFER_SIZE;59 while (niagara.fifo->write_ptr == 60 (niagara.fifo->read_ptr + OUTPUT_FIFO_SIZE - 1) 61 % OUTPUT_FIFO_SIZE); 62 63 niagara.fifo->data[niagara.fifo->write_ptr] = c; 64 niagara.fifo->write_ptr = 65 ((niagara.fifo->write_ptr) + 1) % OUTPUT_FIFO_SIZE; 86 66 } 87 67 88 /** 89 * Initializes the Niagara serial driver. 90 */ 68 static void niagara_putchar(wchar_t ch) 69 { 70 if ((ch >= 0) && (ch < 128)) 71 niagara_putc(ch); 72 else 73 niagara_putc('?'); 74 } 75 76 static void niagara_control_puts(const char *str) 77 { 78 while (*str) 79 niagara_putc(*(str++)); 80 } 81 91 82 int niagara_init(void) 92 83 { 84 sysarg_t present; 85 int rc = sysinfo_get_value("fb", &present); 86 if (rc != EOK) 87 present = false; 88 89 if (!present) 90 return ENOENT; 91 92 sysarg_t kind; 93 rc = sysinfo_get_value("fb.kind", &kind); 94 if (rc != EOK) 95 kind = (sysarg_t) -1; 96 97 if (kind != 5) 98 return EINVAL; 99 93 100 sysarg_t paddr; 94 if (sysinfo_get_value("niagara.outbuf.address", &paddr) != EOK) 95 return -1; 101 rc = sysinfo_get_value("niagara.outbuf.address", &paddr); 102 if (rc != EOK) 103 return rc; 96 104 97 output_buffer_addr = (uintptr_t) as_get_mappable_page(PAGE_SIZE); 98 int result = physmem_map((void *) paddr, 99 (void *) output_buffer_addr, 1, 100 AS_AREA_READ | AS_AREA_WRITE); 101 102 if (result != 0) { 103 printf("Niagara: uspace driver couldn't map physical memory: %d\n", 104 result); 105 } 106 107 output_buffer = (output_buffer_t) output_buffer_addr; 108 109 serial_console_init(niagara_putc, WIDTH, HEIGHT); 110 async_set_client_connection(serial_client_connection); 111 return 0; 105 rc = physmem_map((void *) paddr, 1, 106 AS_AREA_READ | AS_AREA_WRITE, (void *) &niagara.fifo); 107 if (rc != EOK) 108 return rc; 109 110 return serial_init(niagara_putchar, niagara_control_puts); 112 111 } 113 112 114 /** 115 * @} 113 /** @} 116 114 */ 117 -
uspace/srv/hid/fb/port/niagara.h
rbd5f3b7 r00aece0 27 27 */ 28 28 29 /** @defgroup niagarafb30 * @brief userland driver of the Niagara console output31 * @{32 */33 34 29 /** @file 35 30 */ 36 31 37 #ifndef FB_ NIAGARA_H_38 #define FB_ NIAGARA_H_32 #ifndef FB_PORT_NIAGARA_H_ 33 #define FB_PORT_NIAGARA_H_ 39 34 40 int niagara_init(void);35 extern int niagara_init(void); 41 36 42 37 #endif 43 38 44 /** 39 /** 45 40 * @} 46 41 */ -
uspace/srv/hid/fb/port/ski.c
rbd5f3b7 r00aece0 1 1 /* 2 * Copyright (c) 200 5 Jakub Jermar3 * Copyright (c) 2008 Jiri Svoboda2 * Copyright (c) 2006 Ondrej Palkovsky 3 * Copyright (c) 2008 Martin Decky 4 4 * All rights reserved. 5 5 * … … 28 28 */ 29 29 30 /** @defgroup msimfb MSIM text console31 * @brief HelenOS MSIM text console.32 * @ingroup fbs33 * @{34 */35 30 /** @file 36 31 */ 37 32 38 #include < async.h>39 #include < libc.h>33 #include <sys/types.h> 34 #include <errno.h> 40 35 #include <sysinfo.h> 41 #include <as.h> 42 #include <ddi.h> 43 44 #include "serial_console.h" 36 #include "../ctl/serial.h" 45 37 #include "ski.h" 46 38 47 # define SKI_PUTCHAR 3139 #ifdef UARCH_ia64 48 40 49 #define WIDTH 80 50 #define HEIGHT 24 41 #define SKI_PUTCHAR 31 51 42 52 43 /** Display character on ski debug console … … 55 46 * display character on debug console. 56 47 * 57 * @param ch Character to be printed. 48 * @param c Character to be printed. 49 * 58 50 */ 59 static void ski_putc(const char c h)51 static void ski_putc(const char c) 60 52 { 61 53 asm volatile ( 62 54 "mov r15 = %0\n" 63 "mov r32 = %1\n" /* r32 is in0 */64 "break 0x80000\n" /* modifies r8 */55 "mov r32 = %1\n" /* r32 is in0 */ 56 "break 0x80000\n" /* modifies r8 */ 65 57 : 66 : "i" (SKI_PUTCHAR), "r" (c h)58 : "i" (SKI_PUTCHAR), "r" (c) 67 59 : "r15", "in0", "r8" 68 60 ); 69 61 70 if (c h== '\n')62 if (c == '\n') 71 63 ski_putc('\r'); 64 } 65 66 static void ski_putchar(wchar_t ch) 67 { 68 if ((ch >= 0) && (ch < 128)) 69 ski_putc(ch); 70 else 71 ski_putc('?'); 72 } 73 74 static void ski_control_puts(const char *str) 75 { 76 while (*str) 77 ski_putc(*(str++)); 72 78 } 73 79 74 80 int ski_init(void) 75 81 { 76 serial_console_init(ski_putc, WIDTH, HEIGHT); 82 sysarg_t present; 83 int rc = sysinfo_get_value("fb", &present); 84 if (rc != EOK) 85 present = false; 77 86 78 async_set_client_connection(serial_client_connection); 79 return 0; 87 if (!present) 88 return ENOENT; 89 90 sysarg_t kind; 91 rc = sysinfo_get_value("fb.kind", &kind); 92 if (rc != EOK) 93 kind = (sysarg_t) -1; 94 95 if (kind != 6) 96 return EINVAL; 97 98 return serial_init(ski_putchar, ski_control_puts); 80 99 } 81 100 82 /** 83 * @} 101 #else /* UARCH_ia64 */ 102 103 int ski_init(void) 104 { 105 return ENOENT; 106 } 107 108 #endif 109 110 /** @} 84 111 */ -
uspace/srv/hid/fb/port/ski.h
rbd5f3b7 r00aece0 27 27 */ 28 28 29 /** @addtogroup skifb30 * @brief HelenOS ski text console.31 * @ingroup fbs32 * @{33 */34 29 /** @file 35 30 */ 36 31 37 #ifndef FB_ SKI_H_38 #define FB_ SKI_H_32 #ifndef FB_PORT_SKI_H_ 33 #define FB_PORT_SKI_H_ 39 34 40 35 extern int ski_init(void); … … 44 39 /** @} 45 40 */ 46 -
uspace/srv/hid/input/Makefile
rbd5f3b7 r00aece0 43 43 port/adb_mouse.c \ 44 44 port/chardev.c \ 45 port/chardev_mouse.c \46 45 port/gxemul.c \ 47 46 port/msim.c \ … … 52 51 proto/adb.c \ 53 52 proto/mousedev.c \ 54 proto/ps2.c \55 53 ctl/apple.c \ 56 54 ctl/gxe_fb.c \ -
uspace/srv/hid/input/ctl/kbdev.c
rbd5f3b7 r00aece0 111 111 printf("%s: Failed allocating device structure for '%s'.\n", 112 112 NAME, kdev->svc_name); 113 async_hangup(sess); 113 114 return -1; 114 115 } … … 169 170 callid = async_get_call(&call); 170 171 if (!IPC_GET_IMETHOD(call)) { 171 /* XXX Handle hangup */172 kbdev_destroy(kbdev); 172 173 return; 173 174 } -
uspace/srv/hid/input/generic/input.c
rbd5f3b7 r00aece0 39 39 #include <adt/list.h> 40 40 #include <bool.h> 41 #include <fibril_synch.h> 41 42 #include <ipc/services.h> 42 43 #include <ipc/input.h> … … 47 48 #include <stdio.h> 48 49 #include <ns.h> 49 #include <ns_obsolete.h>50 50 #include <async.h> 51 #include <async_obsolete.h>52 51 #include <errno.h> 53 52 #include <adt/fifo.h> … … 63 62 #include <mouse.h> 64 63 65 // FIXME: remove this header66 #include <abi/ipc/methods.h>67 68 64 #define NUM_LAYOUTS 3 69 65 … … 77 73 static void kbd_devs_reclaim(void); 78 74 79 int client_phone = -1;75 async_sess_t *client_sess = NULL; 80 76 81 77 /** List of keyboard devices */ … … 86 82 87 83 bool irc_service = false; 88 int irc_phone = -1; 84 async_sess_t *irc_sess = NULL; 85 86 static FIBRIL_MUTEX_INITIALIZE(discovery_lock); 89 87 90 88 void kbd_push_data(kbd_dev_t *kdev, sysarg_t data) … … 170 168 171 169 ev.c = layout_parse_ev(kdev->active_layout, &ev); 172 async_obsolete_msg_4(client_phone, INPUT_EVENT_KEY, ev.type, ev.key, 173 ev.mods, ev.c); 170 171 async_exch_t *exch = async_exchange_begin(client_sess); 172 async_msg_4(exch, INPUT_EVENT_KEY, ev.type, ev.key, ev.mods, ev.c); 173 async_exchange_end(exch); 174 174 } 175 175 176 176 /** Mouse pointer has moved. */ 177 void mouse_push_event_move(mouse_dev_t *mdev, int dx, int dy) 178 { 179 async_obsolete_msg_2(client_phone, INPUT_EVENT_MOVE, dx, dy); 177 void mouse_push_event_move(mouse_dev_t *mdev, int dx, int dy, int dz) 178 { 179 async_exch_t *exch = async_exchange_begin(client_sess); 180 if (dx || dy) 181 async_msg_2(exch, INPUT_EVENT_MOVE, dx, dy); 182 if (dz) { 183 // TODO: Implement proper wheel support 184 keycode_t code = dz > 0 ? KC_UP : KC_DOWN; 185 for (int i = 0; i < 3; ++i) { 186 async_msg_4(exch, INPUT_EVENT_KEY, KEY_PRESS, code, 0, 0); 187 } 188 async_msg_4(exch, INPUT_EVENT_KEY, KEY_RELEASE, code, 0, 0); 189 } 190 async_exchange_end(exch); 180 191 } 181 192 … … 183 194 void mouse_push_event_button(mouse_dev_t *mdev, int bnum, int press) 184 195 { 185 async_obsolete_msg_2(client_phone, INPUT_EVENT_BUTTON, bnum, press); 196 async_exch_t *exch = async_exchange_begin(client_sess); 197 async_msg_2(exch, INPUT_EVENT_BUTTON, bnum, press); 198 async_exchange_end(exch); 186 199 } 187 200 188 201 static void client_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 189 202 { 190 ipc_callid_t callid;191 ipc_call_t call;192 int retval;193 194 203 async_answer_0(iid, EOK); 195 204 196 205 while (true) { 197 callid = async_get_call(&call); 206 ipc_call_t call; 207 ipc_callid_t callid = async_get_call(&call); 198 208 199 209 if (!IPC_GET_IMETHOD(call)) { 200 if (client_ phone != -1) {201 async_ obsolete_hangup(client_phone);202 client_ phone = -1;210 if (client_sess != NULL) { 211 async_hangup(client_sess); 212 client_sess = NULL; 203 213 } 204 214 … … 207 217 } 208 218 209 switch (IPC_GET_IMETHOD(call)) { 210 case IPC_M_CONNECT_TO_ME: 211 if (client_phone != -1) { 212 retval = ELIMIT; 219 async_sess_t *sess = 220 async_callback_receive_start(EXCHANGE_SERIALIZE, &call); 221 if (sess != NULL) { 222 if (client_sess == NULL) { 223 client_sess = sess; 224 async_answer_0(callid, EOK); 225 } else 226 async_answer_0(callid, ELIMIT); 227 } else { 228 switch (IPC_GET_IMETHOD(call)) { 229 case INPUT_YIELD: 230 kbd_devs_yield(); 231 async_answer_0(callid, EOK); 213 232 break; 233 case INPUT_RECLAIM: 234 kbd_devs_reclaim(); 235 async_answer_0(callid, EOK); 236 break; 237 default: 238 async_answer_0(callid, EINVAL); 214 239 } 215 client_phone = IPC_GET_ARG5(call); 216 retval = 0; 217 break; 218 case INPUT_YIELD: 219 kbd_devs_yield(); 220 retval = 0; 221 break; 222 case INPUT_RECLAIM: 223 kbd_devs_reclaim(); 224 retval = 0; 225 break; 226 default: 227 retval = EINVAL; 228 } 229 230 async_answer_0(callid, retval); 240 } 231 241 } 232 242 } … … 399 409 * them automatically. 400 410 */ 401 #if defined(UARCH_amd64)402 kbd_add_dev(&chardev_port, &pc_ctl);403 #endif404 411 #if defined(UARCH_arm32) && defined(MACHINE_gta02) 405 412 kbd_add_dev(&chardev_port, &stty_ctl); … … 413 420 #if defined(UARCH_arm32) && defined(MACHINE_integratorcp) 414 421 kbd_add_dev(&pl050_port, &pc_ctl); 415 #endif416 #if defined(UARCH_ia32)417 kbd_add_dev(&chardev_port, &pc_ctl);418 #endif419 #if defined(MACHINE_i460GX)420 kbd_add_dev(&chardev_port, &pc_ctl);421 422 #endif 422 423 #if defined(MACHINE_ski) … … 452 453 * them automatically. 453 454 */ 454 #if defined(UARCH_amd64)455 mouse_add_dev(&chardev_mouse_port, &ps2_proto);456 #endif457 #if defined(UARCH_ia32)458 mouse_add_dev(&chardev_mouse_port, &ps2_proto);459 #endif460 #if defined(MACHINE_i460GX)461 mouse_add_dev(&chardev_mouse_port, &ps2_proto);462 #endif463 455 #if defined(UARCH_ppc32) 464 456 mouse_add_dev(&adb_mouse_port, &adb_proto); … … 604 596 int rc; 605 597 598 fibril_mutex_lock(&discovery_lock); 599 606 600 rc = dev_check_new_kbdevs(); 607 if (rc != EOK) 601 if (rc != EOK) { 602 fibril_mutex_unlock(&discovery_lock); 608 603 return rc; 604 } 609 605 610 606 rc = dev_check_new_mousedevs(); 611 if (rc != EOK) 607 if (rc != EOK) { 608 fibril_mutex_unlock(&discovery_lock); 612 609 return rc; 613 610 } 611 612 fibril_mutex_unlock(&discovery_lock); 613 614 614 return EOK; 615 615 } … … 648 648 649 649 if (irc_service) { 650 while (irc_phone < 0) 651 irc_phone = service_obsolete_connect_blocking(SERVICE_IRC, 0, 0); 650 while (irc_sess == NULL) 651 irc_sess = service_connect_blocking(EXCHANGE_SERIALIZE, 652 SERVICE_IRC, 0, 0); 652 653 } 653 654 … … 659 660 660 661 /* Register driver */ 661 int rc = loc_server_register(NAME, client_connection); 662 async_set_client_connection(client_connection); 663 int rc = loc_server_register(NAME); 662 664 if (rc < 0) { 663 665 printf("%s: Unable to register server (%d)\n", NAME, rc); -
uspace/srv/hid/input/include/input.h
rbd5f3b7 r00aece0 40 40 41 41 #include <bool.h> 42 #include <async.h> 42 43 43 44 #define NAME "input" … … 45 46 46 47 extern bool irc_service; 47 extern int irc_phone;48 extern async_sess_t *irc_sess; 48 49 49 50 #endif -
uspace/srv/hid/input/include/mouse.h
rbd5f3b7 r00aece0 62 62 63 63 extern void mouse_push_data(mouse_dev_t *, sysarg_t); 64 extern void mouse_push_event_move(mouse_dev_t *, int, int );64 extern void mouse_push_event_move(mouse_dev_t *, int, int, int); 65 65 extern void mouse_push_event_button(mouse_dev_t *, int, int); 66 66 -
uspace/srv/hid/input/include/mouse_proto.h
rbd5f3b7 r00aece0 48 48 49 49 extern mouse_proto_ops_t adb_proto; 50 extern mouse_proto_ops_t ps2_proto;51 50 extern mouse_proto_ops_t mousedev_proto; 52 51 -
uspace/srv/hid/input/port/chardev.c
rbd5f3b7 r00aece0 63 63 /** List of devices to try connecting to. */ 64 64 static const char *in_devs[] = { 65 "char/ps2a",66 65 "char/s3c24ser" 67 66 }; -
uspace/srv/hid/input/port/gxemul.c
rbd5f3b7 r00aece0 57 57 static kbd_dev_t *kbd_dev; 58 58 59 static irq_pio_range_t gxemul_ranges[] = { 60 { 61 .base = 0, 62 .size = 1 63 } 64 }; 65 59 66 static irq_cmd_t gxemul_cmds[] = { 60 67 { … … 69 76 70 77 static irq_code_t gxemul_kbd = { 78 sizeof(gxemul_ranges) / sizeof(irq_pio_range_t), 79 gxemul_ranges, 71 80 sizeof(gxemul_cmds) / sizeof(irq_cmd_t), 72 81 gxemul_cmds … … 81 90 82 91 sysarg_t addr; 83 if (sysinfo_get_value("kbd.address. virtual", &addr) != EOK)92 if (sysinfo_get_value("kbd.address.physical", &addr) != EOK) 84 93 return -1; 85 94 … … 89 98 90 99 async_set_interrupt_received(gxemul_irq_handler); 100 gxemul_ranges[0].base = addr; 91 101 gxemul_cmds[0].addr = (void *) addr; 92 register_irq(inr, device_assign_devno(), 0, &gxemul_kbd);102 irq_register(inr, device_assign_devno(), 0, &gxemul_kbd); 93 103 return 0; 94 104 } -
uspace/srv/hid/input/port/msim.c
rbd5f3b7 r00aece0 57 57 static kbd_dev_t *kbd_dev; 58 58 59 static irq_pio_range_t msim_ranges[] = { 60 { 61 .base = 0, 62 .size = 1 63 } 64 }; 65 59 66 static irq_cmd_t msim_cmds[] = { 60 67 { … … 69 76 70 77 static irq_code_t msim_kbd = { 78 sizeof(msim_ranges) / sizeof(irq_pio_range_t), 79 msim_ranges, 71 80 sizeof(msim_cmds) / sizeof(irq_cmd_t), 72 81 msim_cmds … … 79 88 kbd_dev = kdev; 80 89 81 sysarg_t vaddr;82 if (sysinfo_get_value("kbd.address. virtual", &vaddr) != EOK)90 sysarg_t paddr; 91 if (sysinfo_get_value("kbd.address.physical", &paddr) != EOK) 83 92 return -1; 84 93 … … 87 96 return -1; 88 97 89 msim_cmds[0].addr = (void *) vaddr; 98 msim_ranges[0].base = paddr; 99 msim_cmds[0].addr = (void *) paddr; 90 100 async_set_interrupt_received(msim_irq_handler); 91 register_irq(inr, device_assign_devno(), 0, &msim_kbd);101 irq_register(inr, device_assign_devno(), 0, &msim_kbd); 92 102 93 103 return 0; -
uspace/srv/hid/input/port/niagara.c
rbd5f3b7 r00aece0 63 63 #define POLL_INTERVAL 10000 64 64 65 /**66 * Virtual address mapped to the buffer shared with the kernel counterpart.67 */68 static uintptr_t input_buffer_addr;69 70 65 /* 71 66 * Kernel counterpart of the driver pushes characters (it has read) here. … … 102 97 return -1; 103 98 104 input_buffer_addr = (uintptr_t) as_get_mappable_page(PAGE_SIZE); 105 int rc = physmem_map((void *) paddr, (void *) input_buffer_addr, 106 1, AS_AREA_READ | AS_AREA_WRITE); 107 99 int rc = physmem_map((void *) paddr, 1, 100 AS_AREA_READ | AS_AREA_WRITE, (void *) &input_buffer); 108 101 if (rc != 0) { 109 102 printf("Niagara: uspace driver couldn't map physical memory: %d\n", … … 111 104 return rc; 112 105 } 113 114 input_buffer = (input_buffer_t) input_buffer_addr;115 106 116 107 thread_id_t tid; -
uspace/srv/hid/input/port/ns16550.c
rbd5f3b7 r00aece0 38 38 #include <ipc/irc.h> 39 39 #include <async.h> 40 #include <async_obsolete.h>41 40 #include <sysinfo.h> 42 41 #include <input.h> … … 71 70 #define LSR_DATA_READY 0x01 72 71 72 static irq_pio_range_t ns16550_ranges[] = { 73 { 74 .base = 0, 75 .size = 8 76 } 77 }; 78 73 79 static irq_cmd_t ns16550_cmds[] = { 74 80 { … … 99 105 100 106 irq_code_t ns16550_kbd = { 107 sizeof(ns16550_ranges) / sizeof(irq_pio_range_t), 108 ns16550_ranges, 101 109 sizeof(ns16550_cmds) / sizeof(irq_cmd_t), 102 110 ns16550_cmds … … 106 114 107 115 static uintptr_t ns16550_physical; 108 static uintptr_t ns16550_kernel;109 116 110 117 static kbd_dev_t *kbd_dev; … … 125 132 return -1; 126 133 127 if (sysinfo_get_value("kbd.address.kernel", &ns16550_kernel) != EOK)128 return -1;129 130 134 sysarg_t inr; 131 135 if (sysinfo_get_value("kbd.inr", &inr) != EOK) 132 136 return -1; 133 137 134 ns16550_kbd.cmds[0].addr = (void *) (ns16550_kernel + LSR_REG); 135 ns16550_kbd.cmds[3].addr = (void *) (ns16550_kernel + RBR_REG); 138 ns16550_kbd.ranges[0].base = ns16550_physical; 139 ns16550_kbd.cmds[0].addr = (void *) (ns16550_physical + LSR_REG); 140 ns16550_kbd.cmds[3].addr = (void *) (ns16550_physical + RBR_REG); 136 141 137 142 async_set_interrupt_received(ns16550_irq_handler); 138 register_irq(inr, device_assign_devno(), inr, &ns16550_kbd);143 irq_register(inr, device_assign_devno(), inr, &ns16550_kbd); 139 144 140 145 return pio_enable((void *) ns16550_physical, 8, &vaddr); … … 158 163 kbd_push_data(kbd_dev, IPC_GET_ARG2(*call)); 159 164 160 if (irc_service) 161 async_obsolete_msg_1(irc_phone, IRC_CLEAR_INTERRUPT, 162 IPC_GET_IMETHOD(*call)); 165 if (irc_service) { 166 async_exch_t *exch = async_exchange_begin(irc_sess); 167 async_msg_1(exch, IRC_CLEAR_INTERRUPT, IPC_GET_IMETHOD(*call)); 168 async_exchange_end(exch); 169 } 163 170 } 164 171 -
uspace/srv/hid/input/port/pl050.c
rbd5f3b7 r00aece0 61 61 static kbd_dev_t *kbd_dev; 62 62 63 #define PL050_STAT 4 64 #define PL050_DATA 8 65 63 66 #define PL050_STAT_RXFULL (1 << 4) 67 68 static irq_pio_range_t pl050_ranges[] = { 69 { 70 .base = 0, 71 .size = 9, 72 } 73 }; 64 74 65 75 static irq_cmd_t pl050_cmds[] = { … … 91 101 92 102 static irq_code_t pl050_kbd = { 103 sizeof(pl050_ranges) / sizeof(irq_pio_range_t), 104 pl050_ranges, 93 105 sizeof(pl050_cmds) / sizeof(irq_cmd_t), 94 106 pl050_cmds … … 102 114 103 115 sysarg_t addr; 104 if (sysinfo_get_value("kbd.address. status", &addr) != EOK)116 if (sysinfo_get_value("kbd.address.physical", &addr) != EOK) 105 117 return -1; 106 118 107 pl050_kbd.cmds[0].addr = (void *) addr; 108 109 if (sysinfo_get_value("kbd.address.data", &addr) != EOK) 110 return -1; 111 112 pl050_kbd.cmds[3].addr = (void *) addr; 119 pl050_kbd.ranges[0].base = addr; 120 pl050_kbd.cmds[0].addr = (void *) addr + PL050_STAT; 121 pl050_kbd.cmds[3].addr = (void *) addr + PL050_DATA; 113 122 114 123 sysarg_t inr; … … 117 126 118 127 async_set_interrupt_received(pl050_irq_handler); 119 register_irq(inr, device_assign_devno(), 0, &pl050_kbd);128 irq_register(inr, device_assign_devno(), 0, &pl050_kbd); 120 129 121 130 return 0; -
uspace/srv/hid/input/proto/adb.c
rbd5f3b7 r00aece0 82 82 83 83 if (dx != 0 || dy != 0) 84 mouse_push_event_move(mouse_dev, dx, dy );84 mouse_push_event_move(mouse_dev, dx, dy, 0); 85 85 } 86 86 -
uspace/srv/hid/input/proto/mousedev.c
rbd5f3b7 r00aece0 54 54 /** Link to generic mouse device */ 55 55 mouse_dev_t *mouse_dev; 56 57 /** Session to mouse device */58 async_sess_t *sess;59 56 } mousedev_t; 60 57 … … 72 69 static void mousedev_destroy(mousedev_t *mousedev) 73 70 { 74 if (mousedev->sess != NULL)75 async_hangup(mousedev->sess);76 77 71 free(mousedev); 78 72 } … … 89 83 90 84 if (!IPC_GET_IMETHOD(call)) { 91 /* XXX Handle hangup */85 mousedev_destroy(mousedev); 92 86 return; 93 87 } … … 97 91 switch (IPC_GET_IMETHOD(call)) { 98 92 case MOUSEEV_MOVE_EVENT: 99 mouse_push_event_move(mousedev->mouse_dev, IPC_GET_ARG1(call), 100 IPC_GET_ARG2(call)); 93 mouse_push_event_move(mousedev->mouse_dev, 94 IPC_GET_ARG1(call), IPC_GET_ARG2(call), 95 IPC_GET_ARG3(call)); 101 96 retval = EOK; 102 97 break; 103 98 case MOUSEEV_BUTTON_EVENT: 104 mouse_push_event_button(mousedev->mouse_dev, IPC_GET_ARG1(call),105 IPC_GET_ARG 2(call));99 mouse_push_event_button(mousedev->mouse_dev, 100 IPC_GET_ARG1(call), IPC_GET_ARG2(call)); 106 101 retval = EOK; 107 102 break; … … 129 124 printf("%s: Failed allocating device structure for '%s'.\n", 130 125 NAME, mdev->svc_name); 126 async_hangup(sess); 131 127 return -1; 132 128 } 133 134 mousedev->sess = sess;135 129 136 130 async_exch_t *exch = async_exchange_begin(sess); … … 139 133 mdev->svc_name); 140 134 mousedev_destroy(mousedev); 135 async_hangup(sess); 141 136 return -1; 142 137 } … … 144 139 int rc = async_connect_to_me(exch, 0, 0, 0, mousedev_callback_conn, mousedev); 145 140 async_exchange_end(exch); 141 async_hangup(sess); 146 142 147 143 if (rc != EOK) { -
uspace/srv/hid/remcons/remcons.h
rbd5f3b7 r00aece0 1 1 /* 2 * Copyright (c) 201 0Vojtech Horky2 * Copyright (c) 2012 Vojtech Horky 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup drvusbuhcihc29 /** @addtogroup remcons 30 30 * @{ 31 31 */ 32 32 /** @file 33 * @brief UHCI driver iface34 33 */ 35 #ifndef DRV_UHCI_IFACE_H36 #define DRV_UHCI_IFACE_H37 34 38 #include <usbhc_iface.h> 35 #ifndef REMCONS_H_ 36 #define REMCONS_H_ 39 37 40 extern usbhc_iface_t hc_iface; 38 #define NAME "remcons" 39 #define NAMESPACE "term" 40 #define BACKLOG_SIZE 5 41 41 42 42 #endif 43 43 44 /** 44 45 * @} -
uspace/srv/hid/remcons/telnet.h
rbd5f3b7 r00aece0 1 1 /* 2 * Copyright (c) 201 1Vojtech Horky2 * Copyright (c) 2012 Vojtech Horky 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup libusbdev29 /** @addtogroup remcons 30 30 * @{ 31 31 */ 32 32 /** @file 33 * Library internal functions on USB pipes.34 33 */ 35 #ifndef LIBUSBDEV_PIPEPRIV_H_36 #define LIBUSBDEV_PIPEPRIV_H_37 34 38 #i nclude <usb/dev/pipes.h>39 # include <bool.h>35 #ifndef TELNET_H_ 36 #define TELNET_H_ 40 37 41 void pipe_acquire(usb_pipe_t *); 42 void pipe_release(usb_pipe_t *); 38 #include <inttypes.h> 43 39 44 void pipe_start_transaction(usb_pipe_t *); 45 void pipe_end_transaction(usb_pipe_t *); 40 typedef uint8_t telnet_cmd_t; 46 41 47 int pipe_add_ref(usb_pipe_t *, bool); 48 void pipe_drop_ref(usb_pipe_t *); 42 /* 43 * Telnet commands. 44 */ 45 46 #define TELNET_IAC 255 47 48 #define TELNET_WILL 251 49 #define TELNET_WONT 252 50 #define TELNET_DO 253 51 #define TELNET_DONT 254 52 53 #define TELNET_IS_OPTION_CODE(code) (((code) >= 251) && ((code) <= 254)) 54 55 #define TELNET_ECHO 1 56 #define TELNET_SUPPRESS_GO_AHEAD 3 57 #define TELNET_LINEMODE 34 49 58 50 59 51 60 #endif 61 52 62 /** 53 63 * @} -
uspace/srv/hid/s3c24xx_ts/s3c24xx_ts.c
rbd5f3b7 r00aece0 44 44 #include <ipc/mouseev.h> 45 45 #include <async.h> 46 #include <async_obsolete.h>47 46 #include <unistd.h> 48 47 #include <stdio.h> … … 53 52 #include "s3c24xx_ts.h" 54 53 55 // FIXME: remove this header 56 #include <abi/ipc/methods.h> 57 58 #define NAME "s3c24ser" 59 #define NAMESPACE "hid" 54 #define NAME "s3c24ser" 55 #define NAMESPACE "hid" 60 56 61 57 static irq_cmd_t ts_irq_cmds[] = { … … 66 62 67 63 static irq_code_t ts_irq_code = { 64 0, 65 NULL, 68 66 sizeof(ts_irq_cmds) / sizeof(irq_cmd_t), 69 67 ts_irq_cmds … … 89 87 90 88 printf(NAME ": S3C24xx touchscreen driver\n"); 91 92 rc = loc_server_register(NAME, s3c24xx_ts_connection); 89 90 async_set_client_connection(s3c24xx_ts_connection); 91 rc = loc_server_register(NAME); 93 92 if (rc < 0) { 94 93 printf(NAME ": Unable to register driver.\n"); … … 134 133 135 134 ts->io = vaddr; 136 ts->client_ phone = -1;135 ts->client_sess = NULL; 137 136 ts->state = ts_wait_pendown; 138 137 ts->last_x = 0; … … 143 142 144 143 async_set_interrupt_received(s3c24xx_ts_irq_handler); 145 register_irq(inr, device_assign_devno(), 0, &ts_irq_code);144 irq_register(inr, device_assign_devno(), 0, &ts_irq_code); 146 145 147 146 s3c24xx_ts_wait_for_int_mode(ts, updn_down); … … 284 283 button = 1; 285 284 press = 0; 286 async_obsolete_msg_2(ts->client_phone, MOUSEEV_BUTTON_EVENT, button, press); 285 286 async_exch_t *exch = async_exchange_begin(ts->client_sess); 287 async_msg_2(exch, MOUSEEV_BUTTON_EVENT, button, press); 288 async_exchange_end(exch); 287 289 288 290 s3c24xx_ts_wait_for_int_mode(ts, updn_down); … … 325 327 326 328 /* Send notifications to client. */ 327 async_obsolete_msg_2(ts->client_phone, MOUSEEV_MOVE_EVENT, dx, dy); 328 async_obsolete_msg_2(ts->client_phone, MOUSEEV_BUTTON_EVENT, button, press); 329 async_exch_t *exch = async_exchange_begin(ts->client_sess); 330 async_msg_2(exch, MOUSEEV_MOVE_EVENT, dx, dy); 331 async_msg_2(exch, MOUSEEV_BUTTON_EVENT, button, press); 332 async_exchange_end(exch); 329 333 330 334 ts->last_x = x_pos; … … 377 381 void *arg) 378 382 { 379 ipc_callid_t callid;380 ipc_call_t call;381 int retval;382 383 383 async_answer_0(iid, EOK); 384 385 while (1) { 386 callid = async_get_call(&call); 384 385 while (true) { 386 ipc_call_t call; 387 ipc_callid_t callid = async_get_call(&call); 387 388 388 389 if (!IPC_GET_IMETHOD(call)) { 389 if (ts->client_ phone != -1) {390 async_ obsolete_hangup(ts->client_phone);391 ts->client_ phone = -1;390 if (ts->client_sess != NULL) { 391 async_hangup(ts->client_sess); 392 ts->client_sess = NULL; 392 393 } 393 394 394 395 async_answer_0(callid, EOK); 395 396 return; 396 397 } 397 398 398 switch (IPC_GET_IMETHOD(call)) { 399 case IPC_M_CONNECT_TO_ME: 400 if (ts->client_phone != -1) { 401 retval = ELIMIT; 402 break; 403 } 404 ts->client_phone = IPC_GET_ARG5(call); 405 retval = 0; 406 break; 407 default: 408 retval = EINVAL; 409 } 410 async_answer_0(callid, retval); 399 async_sess_t *sess = 400 async_callback_receive_start(EXCHANGE_SERIALIZE, &call); 401 if (sess != NULL) { 402 if (ts->client_sess == NULL) { 403 ts->client_sess = sess; 404 async_answer_0(callid, EOK); 405 } else 406 async_answer_0(callid, ELIMIT); 407 } else 408 async_answer_0(callid, EINVAL); 411 409 } 412 410 } -
uspace/srv/hid/s3c24xx_ts/s3c24xx_ts.h
rbd5f3b7 r00aece0 39 39 40 40 #include <sys/types.h> 41 #include <async.h> 41 42 42 43 /** S3C24xx ADC and touch-screen I/O */ … … 121 122 s3c24xx_adc_io_t *io; 122 123 123 /** Callback phoneto the client */124 int client_phone;124 /** Callback session to the client */ 125 async_sess_t *client_sess; 125 126 126 127 /** Service ID */
Note:
See TracChangeset
for help on using the changeset viewer.
