From: Jack Lange Date: Mon, 25 Oct 2010 22:38:05 +0000 (-0500) Subject: added private data pointer to per vm state... X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=commitdiff_plain;h=4731ff7dc97e42853546b38b4d441d793e7a4ec8;p=palacios.git added private data pointer to per vm state... This is going to break the host interface. --- diff --git a/palacios/include/palacios/vm_guest.h b/palacios/include/palacios/vm_guest.h index a5bb46d..7d82660 100644 --- a/palacios/include/palacios/vm_guest.h +++ b/palacios/include/palacios/vm_guest.h @@ -172,6 +172,9 @@ struct v3_vm_info { int num_cores; struct guest_info cores[0]; + + void * host_priv_data; + }; int v3_init_vm(struct v3_vm_info * vm); diff --git a/palacios/include/palacios/vmm.h b/palacios/include/palacios/vmm.h index 7a466a9..b3b56cb 100644 --- a/palacios/include/palacios/vmm.h +++ b/palacios/include/palacios/vmm.h @@ -211,7 +211,7 @@ struct guest_info; while(1); \ } \ } while(0) \ - + @@ -300,7 +300,7 @@ struct v3_interrupt { void Init_V3(struct v3_os_hooks * hooks, int num_cpus); -struct v3_vm_info * v3_create_vm(void * cfg); +struct v3_vm_info * v3_create_vm(void * cfg, void * priv_data); int v3_start_vm(struct v3_vm_info * vm, unsigned int cpu_mask); diff --git a/palacios/include/palacios/vmm_console.h b/palacios/include/palacios/vmm_console.h index 2b38c0d..52a7d5f 100644 --- a/palacios/include/palacios/vmm_console.h +++ b/palacios/include/palacios/vmm_console.h @@ -28,39 +28,39 @@ #ifdef __V3VEE__ -#define V3_TtyOpen(path, mode) \ +#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)) : NULL; \ + 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; \ + 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) ? \ + 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) ? \ + 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; \ + extern struct v3_console_hooks * console_hooks; \ + ((console_hooks) && (console_hooks)->tty_update) ? \ + (console_hooks)->tty_update((tty)) : -1; \ }) #endif @@ -70,21 +70,21 @@ 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 *(*tty_open)(const char * path, int mode, void * priv_data); /* set cursor position */ - int (*tty_cursor_set)(void *tty, int x, int y); + int (*tty_cursor_set)(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 (*tty_character_set)(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 (*tty_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 (*tty_update)(void * tty); }; diff --git a/palacios/include/palacios/vmm_file.h b/palacios/include/palacios/vmm_file.h index 20718c3..bf4a1d0 100644 --- a/palacios/include/palacios/vmm_file.h +++ b/palacios/include/palacios/vmm_file.h @@ -28,37 +28,37 @@ #define V3_FileOpen(path, mode) \ ({ \ - extern struct v3_file_hooks *file_hooks; \ - ((file_hooks) && (file_hooks)->file_open) ? \ - (file_hooks)->file_open((path), (mode)) : -1 ; \ + extern struct v3_file_hooks * file_hooks; \ + ((file_hooks) && (file_hooks)->file_open) ? \ + (file_hooks)->file_open((path), (mode)) : -1; \ }) #define V3_FileClose(fd) \ ({ \ - extern struct v3_file_hooks *file_hooks; \ - ((file_hooks) && (file_hooks)->file_close) ? \ - (file_hooks)->file_close((fd)) : -1 ; \ + extern struct v3_file_hooks * file_hooks; \ + ((file_hooks) && (file_hooks)->file_close) ? \ + (file_hooks)->file_close((fd)) : -1; \ }) -#define V3_FileSize(fd) \ +#define V3_FileSize(fd) \ ({ \ - extern struct v3_file_hooks *file_hooks; \ - ((file_hooks) && (file_hooks)->file_size) ? \ - (file_hooks)->file_size((fd)) : -1 ; \ + extern struct v3_file_hooks * file_hooks; \ + ((file_hooks) && (file_hooks)->file_size) ? \ + (file_hooks)->file_size((fd)) : -1; \ }) -#define V3_FileRead(fd,start,buf,len) \ +#define V3_FileRead(fd, start, buf, len) \ ({ \ - extern struct v3_file_hooks *file_hooks; \ - ((file_hooks) && (file_hooks)->file_read) ? \ - (file_hooks)->file_read((fd),(start),(buf),(len)) : -1 ; \ + extern struct v3_file_hooks * file_hooks; \ + ((file_hooks) && (file_hooks)->file_read) ? \ + (file_hooks)->file_read((fd), (start), (buf), (len)) : -1; \ }) #define V3_FileWrite(fd,start,buf,len) \ ({ \ - extern struct v3_file_hooks *file_hooks; \ - ((file_hooks) && (file_hooks)->file_write) ? \ - (file_hooks)->file_write((fd),(start),(buf),(len)) : -1 ; \ + extern struct v3_file_hooks * file_hooks; \ + ((file_hooks) && (file_hooks)->file_write) ? \ + (file_hooks)->file_write((fd), (start), (buf), (len)) : -1; \ }) @@ -69,14 +69,14 @@ struct v3_file_hooks { - int (*file_open)(const char *path, int mode); + int (*file_open)(const char * path, int mode); int (*file_close)(int fd); long long (*file_size)(int fd); // blocking reads and writes - long long (*file_read)(int fd, long long start, void *buffer, long long length); - long long (*file_write)(int fd, long long start, void *buffer, long long length); + long long (*file_read)(int fd, long long start, void * buffer, long long length); + long long (*file_write)(int fd, long long start, void * buffer, long long length); }; diff --git a/palacios/src/devices/curses_cons.c b/palacios/src/devices/curses_cons.c index b30ee02..528b6a0 100644 --- a/palacios/src/devices/curses_cons.c +++ b/palacios/src/devices/curses_cons.c @@ -39,8 +39,8 @@ struct cons_state { - void *tty; - struct vm_device *frontend_dev; + void * tty; + struct vm_device * frontend_dev; }; static int screen_update(uint_t x, uint_t y, uint_t length, void *private_data); @@ -49,112 +49,110 @@ static uint_t last_offset; static int cursor_update(uint_t x, uint_t y, void *private_data) { - struct vm_device *dev = (struct vm_device *) private_data; - struct cons_state *state = (struct cons_state *) dev->private_data; - uint_t offset = (x * BYTES_PER_COL) + (y * BYTES_PER_ROW); - uint_t last_x, last_y; - - /* unfortunately Palacios sometimes misses some writes, - * but if they are accompanied by a cursor move we may be able to - * detect this - */ - if (offset < last_offset) last_offset = 0; - if (offset > last_offset) { - last_x = (last_offset % BYTES_PER_ROW) / BYTES_PER_COL; - last_y = last_offset / BYTES_PER_ROW; - screen_update(last_x, last_y, offset - last_offset, private_data); - } + struct vm_device *dev = (struct vm_device *) private_data; + struct cons_state *state = (struct cons_state *) dev->private_data; + uint_t offset = (x * BYTES_PER_COL) + (y * BYTES_PER_ROW); + uint_t last_x, last_y; + + /* unfortunately Palacios sometimes misses some writes, + * but if they are accompanied by a cursor move we may be able to + * detect this + */ + if (offset < last_offset) last_offset = 0; + + if (offset > last_offset) { + last_x = (last_offset % BYTES_PER_ROW) / BYTES_PER_COL; + last_y = last_offset / BYTES_PER_ROW; + screen_update(last_x, last_y, offset - last_offset, 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); + return -1; + } + + /* done with console update */ + if (V3_TtyUpdate(state->tty) < 0) { + PrintError("V3_TtyUpdate(0x%p) failed\n", state->tty); + return -1; + } + + return 0; +} - /* adjust cursor */ - if (V3_TtyCursorSet(state->tty, x, y) < 0) { - PrintError("V3_TtyCursorSet(0x%p, %d, %d) failed\n", state->tty, x, y); - return -1; +static int screen_update(uint_t x, uint_t y, uint_t length, void * private_data) { + struct vm_device *dev = (struct vm_device *)private_data; + struct cons_state *state = (struct cons_state *)dev->private_data; + uint_t offset = (x * BYTES_PER_COL) + (y * BYTES_PER_ROW); + uint8_t fb_buf[length]; + int i; + uint_t cur_x = x; + uint_t cur_y = y; + + /* grab frame buffer */ + memset(fb_buf, 0, length); + v3_cons_get_fb(state->frontend_dev, fb_buf, offset, length); + + /* update the screen */ + for (i = 0; i < length; i += 2) { + uint_t col_index = i; + uint8_t col[2]; + + col[0] = fb_buf[col_index]; // Character + 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]); + return -1; } + + // CAUTION: the order of these statements is critical + // cur_y depends on the previous value of cur_x + cur_y = cur_y + ((cur_x + 1) / NUM_COLS); + cur_x = (cur_x + 1) % NUM_COLS; + } + + /* done with console update */ + if (V3_TtyUpdate(state->tty) < 0) { + PrintError("V3_TtyUpdate(0x%p) failed\n", state->tty); + return -1; + } + + /* store offset to catch missing notifications */ + last_offset = offset + length; + + return 0; +} - /* done with console update */ - if (V3_TtyUpdate(state->tty) < 0) { - PrintError("V3_TtyUpdate(0x%p) failed\n", state->tty); - return -1; - } +static int scroll(int rows, void * private_data) { + struct vm_device *dev = (struct vm_device *)private_data; + struct cons_state *state = (struct cons_state *)dev->private_data; - return 0; -} + if (rows < 0) { + /* simply update the screen */ + return screen_update(0, 0, SCREEN_SIZE, private_data); + } -static int screen_update(uint_t x, uint_t y, uint_t length, void *private_data) -{ - struct vm_device *dev = (struct vm_device *)private_data; - struct cons_state *state = (struct cons_state *)dev->private_data; - uint_t offset = (x * BYTES_PER_COL) + (y * BYTES_PER_ROW); - uint8_t fb_buf[length]; - int i; - uint_t cur_x = x; - uint_t cur_y = y; - - /* grab frame buffer */ - memset(fb_buf, 0, length); - v3_cons_get_fb(state->frontend_dev, fb_buf, offset, length); - - /* update the screen */ - for (i = 0; i < length; i += 2) - { - uint_t col_index = i; - uint8_t col[2]; - - col[0] = fb_buf[col_index]; // Character - 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]); - return -1; - } - - // CAUTION: the order of these statements is critical - // cur_y depends on the previous value of cur_x - cur_y = cur_y + ((cur_x + 1) / NUM_COLS); - cur_x = (cur_x + 1) % NUM_COLS; + 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); + return -1; } /* done with console update */ if (V3_TtyUpdate(state->tty) < 0) { - PrintError("V3_TtyUpdate(0x%p) failed\n", state->tty); - return -1; + PrintError("V3_TtyUpdate(0x%p) failed\n", state->tty); + return -1; } - - /* store offset to catch missing notifications */ - last_offset = offset + length; - - return 0; -} - -static int scroll(int rows, void *private_data) -{ - struct vm_device *dev = (struct vm_device *)private_data; - struct cons_state *state = (struct cons_state *)dev->private_data; - - if (rows < 0) { - /* simply update the screen */ - return screen_update(0, 0, SCREEN_SIZE, 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); - return -1; - } - - /* done with console update */ - if (V3_TtyUpdate(state->tty) < 0) { - PrintError("V3_TtyUpdate(0x%p) failed\n", state->tty); - return -1; - } - last_offset = BYTES_PER_ROW * (NUM_ROWS - 1); - } + last_offset = BYTES_PER_ROW * (NUM_ROWS - 1); + } - return 0; + return 0; } static struct v3_console_ops cons_ops = { @@ -172,48 +170,49 @@ static struct v3_device_ops dev_ops = { static int cons_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { - struct cons_state * state = NULL; - v3_cfg_tree_t * frontend_cfg = v3_cfg_subtree(cfg, "frontend"); - 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); - V3_ASSERT(frontend_tag); - V3_ASSERT(frontend); - - - /* 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(ttypath, TTY_OPEN_MODE_READ | TTY_OPEN_MODE_WRITE); - if (!state->tty) { - PrintError("Could not open tty %s\n", ttypath); - V3_Free(state); - return -1; - } - - /* allocate device */ - struct vm_device *dev = v3_allocate_device(dev_id, &dev_ops, state); - V3_ASSERT(dev); - - /* attach device to virtual machine */ - if (v3_attach_device(vm, dev) == -1) { - PrintError("Could not attach device %s\n", dev_id); - V3_Free(state); - return -1; - } - - /* attach to front-end display adapter */ - v3_console_register_cga(frontend, &cons_ops, dev); - - return 0; + struct cons_state * state = NULL; + v3_cfg_tree_t * frontend_cfg = v3_cfg_subtree(cfg, "frontend"); + 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); + V3_ASSERT(frontend_tag); + V3_ASSERT(frontend); + + + /* 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); + + if (!state->tty) { + PrintError("Could not open tty %s\n", ttypath); + V3_Free(state); + return -1; + } + + /* allocate device */ + struct vm_device * dev = v3_allocate_device(dev_id, &dev_ops, state); + V3_ASSERT(dev); + + /* attach device to virtual machine */ + if (v3_attach_device(vm, dev) == -1) { + PrintError("Could not attach device %s\n", dev_id); + V3_Free(state); + return -1; + } + + /* attach to front-end display adapter */ + v3_console_register_cga(frontend, &cons_ops, dev); + + return 0; } device_register("CURSES_CONSOLE", cons_init) diff --git a/palacios/src/palacios/vmm.c b/palacios/src/palacios/vmm.c index 2194ae5..49f30ba 100644 --- a/palacios/src/palacios/vmm.c +++ b/palacios/src/palacios/vmm.c @@ -117,7 +117,7 @@ v3_cpu_arch_t v3_get_cpu_type(int cpu_id) { } -struct v3_vm_info * v3_create_vm(void * cfg) { +struct v3_vm_info * v3_create_vm(void * cfg, void * priv_data) { struct v3_vm_info * vm = v3_config_guest(cfg); if (vm == NULL) { @@ -125,13 +125,15 @@ struct v3_vm_info * v3_create_vm(void * cfg) { return NULL; } + vm->host_priv_data = priv_data; + return vm; } static int start_core(void *p) { - struct guest_info * info = (struct guest_info*)p; + struct guest_info * info = (struct guest_info *)p; PrintDebug("core %u: in start_core\n",info->cpu_id);