From: Jack Lange Date: Wed, 10 Nov 2010 22:35:46 +0000 (-0600) Subject: reworked the console hooks X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=commitdiff_plain;h=124131ed42f201896d9b81c039ee3fffd0336e21;p=palacios.git reworked the console hooks --- diff --git a/palacios/include/palacios/vmm_console.h b/palacios/include/palacios/vmm_console.h index 52a7d5f..e49fab0 100644 --- a/palacios/include/palacios/vmm_console.h +++ b/palacios/include/palacios/vmm_console.h @@ -28,63 +28,36 @@ #ifdef __V3VEE__ -#define V3_TtyOpen(vm, path, mode) \ - ({ \ - extern struct v3_console_hooks * console_hooks; \ - ((console_hooks) && (console_hooks)->tty_open) ? \ - (console_hooks)->tty_open((path), (mode), (vm)->host_priv_data) : NULL; \ - }) - -#define V3_TtyCursorSet(tty, x, y) \ - ({ \ - extern struct v3_console_hooks * console_hooks; \ - ((console_hooks) && (console_hooks)->tty_cursor_set) ? \ - (console_hooks)->tty_cursor_set((tty), (x), (y)) : -1; \ - }) - -#define V3_TtyCharacterSet(tty, x, y, c, style) \ - ({ \ - extern struct v3_console_hooks * console_hooks; \ - ((console_hooks) && (console_hooks)->tty_character_set) ? \ - (console_hooks)->tty_character_set((tty), (x), (y), (c), (style)) : -1; \ - }) - -#define V3_TtyScroll(tty, lines) \ - ({ \ - extern struct v3_console_hooks * console_hooks; \ - ((console_hooks) && (console_hooks)->tty_scroll) ? \ - (console_hooks)->tty_scroll((tty), (lines)) : -1; \ - }) - -#define V3_TtyUpdate(tty) \ - ({ \ - extern struct v3_console_hooks * console_hooks; \ - ((console_hooks) && (console_hooks)->tty_update) ? \ - (console_hooks)->tty_update((tty)) : -1; \ - }) +typedef void * v3_console_t; + +v3_console_t v3_console_open(struct v3_vm_info * vm); + +int v3_console_set_cursor(v3_console_t cons, int x, int y); +int v3_console_set_char(v3_console_t cons, int x, int y, char c, uint8_t style); +int v3_console_scroll(v3_console_t cons, int lines); +int v3_console_update(v3_console_t cons); #endif -#define TTY_OPEN_MODE_READ (1 << 0) -#define TTY_OPEN_MODE_WRITE (1 << 1) + struct v3_console_hooks { /* open console device, mode is a combination of TTY_OPEN_MODE_* flags */ - void *(*tty_open)(const char * path, int mode, void * priv_data); + void *(*open)(void * priv_data); /* set cursor position */ - int (*tty_cursor_set)(void * tty, int x, int y); + int (*set_cursor)(void * tty, int x, int y); /* output character c with specified style at (x, y) */ - int (*tty_character_set)(void * tty, int x, int y, char c, unsigned char style); + int (*set_character)(void * tty, int x, int y, char c, unsigned char style); /* scroll the console down the specified number of lines */ - int (*tty_scroll)(void * tty, int lines); + int (*scroll)(void * tty, int lines); /* force update of console display; all updates by above functions * may be defferred until the next tty_update call */ - int (*tty_update)(void * tty); + int (*update)(void * tty); }; diff --git a/palacios/src/devices/curses_cons.c b/palacios/src/devices/curses_cons.c index d712a58..b43d69b 100644 --- a/palacios/src/devices/curses_cons.c +++ b/palacios/src/devices/curses_cons.c @@ -40,7 +40,7 @@ struct cons_state { - void * tty; + v3_console_t cons; struct vm_device * frontend_dev; }; @@ -68,14 +68,14 @@ static int cursor_update(uint_t x, uint_t y, void *private_data) } /* adjust cursor */ - if (V3_TtyCursorSet(state->tty, x, y) < 0) { - PrintError("V3_TtyCursorSet(0x%p, %d, %d) failed\n", state->tty, x, y); + if (v3_console_set_cursor(state->cons, x, y) < 0) { + PrintError("set cursor (0x%p, %d, %d) failed\n", state->cons, x, y); return -1; } /* done with console update */ - if (V3_TtyUpdate(state->tty) < 0) { - PrintError("V3_TtyUpdate(0x%p) failed\n", state->tty); + if (v3_console_update(state->cons) < 0) { + PrintError("console update (0x%p) failed\n", state->cons); return -1; } @@ -104,9 +104,9 @@ static int screen_update(uint_t x, uint_t y, uint_t length, void * private_data) col[1] = fb_buf[col_index + 1]; // Attribute /* update current character */ - if (V3_TtyCharacterSet(state->tty, cur_x, cur_y, col[0], col[1]) < 0) { - PrintError("V3_TtyCursorSet(0x%p, %d, %d, %d, %d) failed\n", - state->tty, cur_x, cur_y, col[1], col[0]); + if (v3_console_set_char(state->cons, cur_x, cur_y, col[0], col[1]) < 0) { + PrintError("set cursor (0x%p, %d, %d, %d, %d) failed\n", + state->cons, cur_x, cur_y, col[1], col[0]); return -1; } @@ -117,8 +117,8 @@ static int screen_update(uint_t x, uint_t y, uint_t length, void * private_data) } /* done with console update */ - if (V3_TtyUpdate(state->tty) < 0) { - PrintError("V3_TtyUpdate(0x%p) failed\n", state->tty); + if (v3_console_update(state->cons) < 0) { + PrintError("console update(0x%p) failed\n", state->cons); return -1; } @@ -139,14 +139,14 @@ static int scroll(int rows, void * private_data) { if (rows > 0) { /* scroll requested number of lines*/ - if (V3_TtyScroll(state->tty, rows) < 0) { - PrintError("V3_TtyScroll(0x%p, %u) failed\n", state->tty, rows); + if (v3_console_scroll(state->cons, rows) < 0) { + PrintError("console scroll (0x%p, %u) failed\n", state->cons, rows); return -1; } /* done with console update */ - if (V3_TtyUpdate(state->tty) < 0) { - PrintError("V3_TtyUpdate(0x%p) failed\n", state->tty); + if (v3_console_update(state->cons) < 0) { + PrintError("console update (0x%p) failed\n", state->cons); return -1; } @@ -176,7 +176,6 @@ static int cons_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) const char * frontend_tag = v3_cfg_val(frontend_cfg, "tag"); struct vm_device * frontend = v3_find_dev(vm, frontend_tag); char * dev_id = v3_cfg_val(cfg, "ID"); - char * ttypath = v3_cfg_val(cfg, "tty"); /* read configuration */ V3_ASSERT(frontend_cfg); @@ -187,14 +186,14 @@ static int cons_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) /* allocate state */ state = (struct cons_state *)V3_Malloc(sizeof(struct cons_state)); V3_ASSERT(state); + state->frontend_dev = frontend; - V3_ASSERT(ttypath); /* open tty for screen display */ - state->tty = V3_TtyOpen(vm, ttypath, TTY_OPEN_MODE_READ | TTY_OPEN_MODE_WRITE); + state->cons = v3_console_open(vm); - if (!state->tty) { - PrintError("Could not open tty %s\n", ttypath); + if (!state->cons) { + PrintError("Could not open console\n"); V3_Free(state); return -1; } diff --git a/palacios/src/palacios/vmm_console.c b/palacios/src/palacios/vmm_console.c index ef142b9..772b83c 100644 --- a/palacios/src/palacios/vmm_console.c +++ b/palacios/src/palacios/vmm_console.c @@ -24,10 +24,48 @@ #include #include #include - +#include struct v3_console_hooks * console_hooks = 0; +v3_console_t v3_console_open(struct v3_vm_info * vm) { + V3_ASSERT(console_hooks != NULL); + V3_ASSERT(console_hooks->open != NULL); + + return console_hooks->open(vm->host_priv_data); +} + + +int v3_console_set_cursor(v3_console_t cons, int x, int y) { + V3_ASSERT(console_hooks != NULL); + V3_ASSERT(console_hooks->set_cursor != NULL); + + return console_hooks->set_cursor(cons, x, y); +} + +int v3_console_set_char(v3_console_t cons, int x, int y, char c, uint8_t style) { + V3_ASSERT(console_hooks != NULL); + V3_ASSERT(console_hooks->set_character != NULL); + + return console_hooks->set_character(cons, x, y, c, style); +} + + +int v3_console_scroll(v3_console_t cons, int lines) { + V3_ASSERT(console_hooks != NULL); + V3_ASSERT(console_hooks->scroll != NULL); + + return console_hooks->scroll(cons, lines); +} + + +int v3_console_update(v3_console_t cons) { + V3_ASSERT(console_hooks != NULL); + V3_ASSERT(console_hooks->update != NULL); + + return console_hooks->update(cons); +} + void V3_Init_Console(struct v3_console_hooks * hooks) { console_hooks = hooks; PrintDebug("V3 console inited\n");