From: Jean Guyader Date: Fri, 31 Oct 2008 12:15:55 +0000 (+0000) Subject: Fix intel driver X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=b4b416f8c39ce2c64aace6cc952d75e1572c8974;p=xenclient%2Fioemu.git Fix intel driver --- diff --git a/dom0_driver.c b/dom0_driver.c index e4897e9f..220d7571 100644 --- a/dom0_driver.c +++ b/dom0_driver.c @@ -1,8 +1,8 @@ /* * QEMU dom0 /dev/input driver - * + * * Copyright (c) 2008 Citrix Systems - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights @@ -40,9 +40,16 @@ #include #include +extern int vga_passthrough; + +void xenstore_watch_dom0_driver(const char *, const char *); + #define DEBUG_DOM0_DRIVER 1 #define EVENT_PATH "/dev/input/event" -#define XS_REFRESH_INTERVAL 100 +#define XS_REFRESH_INTERVAL 5000 + +#define DOM0_MOUSE 1 +#define DOM0_KEYBOARD 2 #if DEBUG_DOM0_DRIVER # define DEBUG(_format_, args...) \ @@ -53,7 +60,12 @@ #define NB_SLOTS 10 +#define ABS(x) ((x) > 0 ? (x) : -(x)) + +int dom0_driver_focus = 0; + static void dom0_read(void *opaque); +static void dom0_driver_reset_keyboard(void); enum dom0Direction { @@ -70,69 +82,146 @@ static const char *str2pos[] = "left", "top", "center", "bottom", "right" }; -struct dom0Driver +struct dom0Driver { - int *event_fds; - int event_nb; + int keyboard_fd; + int mouse_fd; int mouse_button_state; QEMUTimer *xs_timer; uint8_t scroll_lock_count; + int windows_down; + int key_status[256]; +}; + +struct dom0_driver_xs_info +{ + int state; + int domid; + int leaving_dir; + int new_slot; }; static struct dom0Driver driver; -static void dom0_update(DisplayState *ds, int x, int y, int w, int h) +static int dom0_driver_xs_read_dom0(const char *key) { + char *str = NULL; + int blank; + + if (!(str = xenstore_read_dom0_driver(key))) + { + fprintf(stderr, "dom0_driver: fatal the node blank don't exits\n"); + exit(2); + } + return strtol(str, NULL, 10); } -static void dom0_refresh(DisplayState *ds) +static void dom0_driver_read_xs_info(struct dom0_driver_xs_info *info, + int controller) { + char *str = NULL; + char path[128]; + int val[10]; + const char *key[] = {"state", "domid", "new-slot"}; + + memset(info, -1, sizeof (struct dom0_driver_xs_info)); + for (int i = 0; i < sizeof (key) / sizeof (key[0]); i++) + { + if (controller == DOM0_MOUSE) + sprintf(path, "mouse/%s", key[i]); + else if (controller == DOM0_KEYBOARD) + sprintf(path, "keyboard/%s", key[i]); + else + { + fprintf(stderr, "dom0_driver unknown controller type\n"); + exit(2); + } + + val[i] = -1; + if ((str = xenstore_read_dom0_driver(path))) + { + val[i] = strtol(str, NULL, 10); + free(str); + } + } + + info->state = val[0]; + info->domid = val[1]; + info->new_slot = val[2]; +} + +static void dom0_driver_xs_write(const char *key, int val, int controller) +{ + char path[128]; + + if (controller == DOM0_MOUSE) + sprintf(path, "mouse/%s", key); + if (controller == DOM0_KEYBOARD) + sprintf(path, "keyboard/%s", key); + + xenstore_write_dom0_driver(path, val); } -static int dom0_safe_switch(int keycode) +static int dom0_windows_key_switch(int code, int keycode) { - if (driver.scroll_lock_count == 3) + int new_slot = 0; + struct dom0_driver_xs_info info; + + dom0_driver_read_xs_info(&info, DOM0_MOUSE); + if (info.state == 0) + return 0; + + if (driver.windows_down && keycode != KEY_LEFTCTRL) { + driver.windows_down = 0; switch (keycode) { - case KEY_LEFT: - xenstore_write_dom0_driver("leaving-dir", DOM0_LEFT); + case KEY_1: + DEBUG("1 pressed switch to new-slot 1\n"); + new_slot = 1; break; - case KEY_RIGHT: - xenstore_write_dom0_driver("leaving-dir", DOM0_RIGHT); + case KEY_2: + DEBUG("2 pressed switch to new-slot 2\n"); + new_slot = 2; break; - case KEY_DOWN: - xenstore_write_dom0_driver("leaving-dir", DOM0_BOTTOM); + case KEY_3: + DEBUG("3 pressed switch to new-slot 3\n"); + new_slot = 3; break; - case KEY_UP: - xenstore_write_dom0_driver("leaving-dir", DOM0_TOP); + case KEY_4: + DEBUG("4 pressed switch to new-slot 4\n"); + new_slot = 4; break; default: return 0; } - xenstore_write_dom0_driver("state", 0); - driver.scroll_lock_count = 0; + + DEBUG("Write state = 0 inside xenstore\n"); + + dom0_driver_xs_write("new-slot", new_slot, DOM0_KEYBOARD); + dom0_driver_xs_write("new-slot", new_slot, DOM0_MOUSE); + + dom0_driver_xs_write("state", 0, DOM0_KEYBOARD); + dom0_driver_xs_write("state", 0, DOM0_MOUSE); + return 1; } - if (keycode == KEY_SCROLLLOCK) + if (keycode == KEY_LEFTCTRL) { - driver.scroll_lock_count++; - DEBUG("scroll count %d\n", driver.scroll_lock_count); + if (code == 1) + { + DEBUG("left ctrl key is down\n"); + driver.windows_down = 1; + } + else + driver.windows_down = 0; } - else - driver.scroll_lock_count = 0; return 0; } -static void dom0_key_event(int down, uint32_t keycode) +static void dom0_key_inject(int code, uint32_t keycode) { - int shift_keys = 0; - uint8_t esc = 0; - - if (down && dom0_safe_switch(keycode)) - return; - switch (keycode) { case KEY_F11: keycode = 0X57; break; /* F11 */ @@ -155,10 +244,32 @@ static void dom0_key_event(int down, uint32_t keycode) if (keycode & 0x80) kbd_put_keycode(0xe0); - if (down) - kbd_put_keycode(keycode | 0x80); - else + if (code == 1) kbd_put_keycode(keycode & 0x7f); + else + kbd_put_keycode(keycode | 0x80); +} + +static void dom0_key_event(int code, uint32_t keycode) +{ + int shift_keys = 0; + uint8_t esc = 0; + + driver.key_status[keycode] = code == 1; + + if (code != 2) + dom0_windows_key_switch(code, keycode); + + dom0_key_inject(code, keycode); +} + +static void dom0_driver_reset_keyboard(void) +{ + int i = 0; + + for (i = 0; i < 256; i++) + if (driver.key_status[i]) + dom0_key_inject(0, i); } static void dom0_get_positions(int *positions) @@ -168,7 +279,7 @@ static void dom0_get_positions(int *positions) char *tmp; unsigned long len; int pos = 0; - + memset(positions, 0, NB_SLOTS * 4); /* Get all the positions */ @@ -184,13 +295,11 @@ static void dom0_get_positions(int *positions) positions[pos] = domids[i]; } free(domids); - for (pos = 0; pos < NB_SLOTS; pos++) - DEBUG("pos %d -> %d\n", pos, positions[pos]); } static int dom0_get_next_domid(int dir, int id) { - int pos = 0, next_pos = 0; + int pos = 0, next_pos = -1; int positions[NB_SLOTS]; dom0_get_positions(positions); @@ -211,10 +320,9 @@ static int dom0_get_next_domid(int dir, int id) else if (pos == DOM0_CENTER && dir != DOM0_CENTER) next_pos = dir; - if (next_pos == 0) + if (next_pos == -1) next_pos = pos; - DEBUG("positions[next_pos] %d, id %d\n", positions[next_pos], id); if (!positions[next_pos]) return domid; else @@ -237,7 +345,7 @@ static void dom0_read(void *opaque) { /* Mouse Key */ int type = 0; - + switch(event[i].code) { case BTN_LEFT: type = MOUSE_EVENT_LBUTTON; break; @@ -252,19 +360,49 @@ static void dom0_read(void *opaque) kbd_mouse_event(0, 0, 0, driver.mouse_button_state); } else - dom0_key_event(event[i].value == 0, event[i].code); + dom0_key_event(event[i].value, event[i].code); } - if (event[i].type == EV_REL) + if (event[i].type == EV_REL || event[i].type == EV_ABS) { /* Mouse motion */ int x = 0, y = 0, z = 0; - switch (event[i].code) + if (event[i].type == EV_REL) + switch (event[i].code) + { + case REL_X : x = event[i].value; break; + case REL_Y : y = event[i].value; break; + case REL_WHEEL : z = -event[i].value; break; + } + if (event[i].type == EV_ABS) { - case REL_X : x = event[i].value; break; - case REL_Y : y = event[i].value; break; - case REL_WHEEL : z = -event[i].value; break; + static int last_x = 1, last_y = 1; + int px = 0, py = 0, l = 50; + char *str = xenstore_read_dom0_driver("touchpad-limit"); + + if (str) + l = strtol(str, NULL, 10); + + switch (event[i].code) + { + case ABS_X : x = event[i].value; break; + case ABS_Y : y = event[i].value; break; + } + + if (x) + { + px = x - last_x; + last_x = x; + } + if (y) + { + py = y - last_y; + last_y = y; + } + + x = ABS(px) < l ? px : 0; + y = ABS(py) < l ? py : 0; } kbd_mouse_event(x, y, z, driver.mouse_button_state); @@ -272,27 +410,47 @@ static void dom0_read(void *opaque) } } -static void dom0_gr_devices(int grab) +static void dom0_gr_devices(int grab, int controller) { char *tmp; int id; + int *fd = NULL; + + if (controller == DOM0_MOUSE) + fd = &driver.mouse_fd; + if (controller == DOM0_KEYBOARD) + fd = &driver.keyboard_fd; + assert(fd != NULL); + + if (ioctl(*fd, EVIOCGRAB, grab) == -1) + { + DEBUG("Try to %s on %d\n", 1 ? "grab" : "release", *fd); + return; + } + DEBUG("%s succed %d\n", grab ? "grab" : "release", *fd); + + if (grab) + qemu_set_fd_handler(*fd, dom0_read, NULL, fd); + else + qemu_set_fd_handler(*fd, NULL, NULL, fd); - for (int i = 0; i < driver.event_nb; i++) + if (controller == DOM0_MOUSE) { - if (ioctl(driver.event_fds[i], EVIOCGRAB, grab) == -1) + if (vga_passthrough) + xenstore_write_dom0_driver("blank", !grab); + else { - DEBUG("IOCTL failed !\n"); - return; + struct dom0_driver_xs_info info; + + dom0_driver_read_xs_info(&info, DOM0_MOUSE); + if (dom0_driver_xs_read_dom0("natif") != info.domid) + dom0_driver_focus = grab; } - if (grab) - qemu_set_fd_handler(driver.event_fds[i], dom0_read, NULL, - &driver.event_fds[i]); - else - qemu_set_fd_handler(driver.event_fds[i], NULL, NULL, - &driver.event_fds[i]); } - xenstore_write_dom0_driver("state", grab); - xenstore_write_dom0_driver("domid", domid); + + dom0_driver_reset_keyboard(); + dom0_driver_xs_write("state", grab ? 1 : 2, controller); + dom0_driver_xs_write("domid", domid, controller); } static int dom0_dom_alive(int id) @@ -310,177 +468,148 @@ static int dom0_dom_alive(int id) return (i < len); } -static void dom0_probe_xenstore_location(void *opaque) + + +static int dom0_driver_failover_switch(void *opaque) { - char *tmp = NULL; - char *dir = NULL; - int state = 0; - int cur_domid, next_domid; - - if (!(tmp = xenstore_read_dom0_driver("state"))) - { - DEBUG("No state grab the device\n"); - dom0_gr_devices(1); - goto out; - } - state = strtol(tmp, NULL, 10); - free(tmp); + struct dom0_driver_xs_info info; + int ret = 1; + + dom0_driver_read_xs_info(&info, DOM0_MOUSE); - if (!(tmp = xenstore_read_dom0_driver("domid"))) + if (info.state == -1) { - dom0_gr_devices(1); + DEBUG("No state grab the device\n"); + dom0_gr_devices(1, DOM0_KEYBOARD); + dom0_gr_devices(1, DOM0_MOUSE); goto out; } - cur_domid = strtol(tmp, NULL, 10); - free(tmp); /* The domain which has the focus crash */ - if (!dom0_dom_alive(cur_domid)) + if (!dom0_dom_alive(info.domid)) { - DEBUG("steal the focus from %d\n", cur_domid); - dom0_gr_devices(1); + DEBUG("steal the focus from %d\n", info.domid); + dom0_gr_devices(1, DOM0_KEYBOARD); + dom0_gr_devices(1, DOM0_MOUSE); goto out; } - - if (state == 0) /* loosing the focus */ - { - if (!(dir = xenstore_read_dom0_driver("leaving-dir"))) - goto out; - next_domid = dom0_get_next_domid(strtol(dir, NULL, 10), cur_domid); - DEBUG("leaving-dir %ld\n", strtol(dir, NULL, 10)); - DEBUG("next_domid is %d\n", next_domid); - DEBUG("cur_domid is %d\n", cur_domid); - - if (cur_domid != next_domid) - { - if (cur_domid == domid) - { - DEBUG("release devices\n"); - dom0_gr_devices(0); - } - if (next_domid == domid) - { - DEBUG("grab devices\n"); - dom0_gr_devices(1); - } - } - else - xenstore_write_dom0_driver("state", 1); - } - -out: - qemu_mod_timer(driver.xs_timer, qemu_get_clock(rt_clock) + XS_REFRESH_INTERVAL); -} - -static void dom0_driver_location_init(const char *arg) -{ - int pos = 0, i = 0; - int positions[NB_SLOTS]; - char str[10]; - - - /* Register the xenstore probing */ - driver.xs_timer = qemu_new_timer(rt_clock, dom0_probe_xenstore, NULL); + ret = 0; +out: qemu_mod_timer(driver.xs_timer, qemu_get_clock(rt_clock) + XS_REFRESH_INTERVAL); + return ret; } -static void dom0_driver_slot_init(int slot) -{ - -} static void dom0_driver_event_init(const char *str_arg) { char dev_name[strlen(EVENT_PATH) + 3]; + int positions[NB_SLOTS]; + char str[10]; int fd = -1; - int arg = 0; - - do - { - snprintf(dev_name, sizeof (dev_name), "%s%d", EVENT_PATH, i++); - if ((fd = open(dev_name, O_RDONLY)) == -1) - break; - - if (!(driver.event_fds = realloc(driver.event_fds, - (driver.event_nb + 1) * sizeof (int)))) - { - DEBUG("memory allocation failed\n"); - exit(1); - } + int pos = 0; + int i = 0; + struct input_id input; + char name[128]; - driver.event_fds[driver.event_nb] = fd; - driver.event_nb++; - - DEBUG("XXX Using %s\n", dev_name); - } - while (1); - - if (driver.event_nb == 0) - return; + driver.keyboard_fd = open("/dev/input/event0", O_RDONLY); + driver.mouse_fd = open("/dev/input/event2", O_RDONLY); pos = strtol(str_arg, NULL, 10); - /* Register position */ - if (errno == EINVAL) // position mode - { - DEBUG("Register the position inside xenstore\n"); - for (pos = 0; pos < DOM0_OUT; pos++) - if (strcmp(str2pos[pos], str_arg) == 0) - break; - DEBUG("Get the position %s\n", str2pos[pos]); - if (pos == DOM0_OUT) - { - DEBUG("position must be left, right, center, top or bottom\n"); - exit(1); - } - } - dom0_get_positions(positions); if (positions[pos]) { - DEBUG("There is already a vm at this position\n"); + DEBUG("There is already a vm at this slot\n"); exit(1); } else { snprintf(str, 9, "%d", pos); - DEBUG("register dom0_input %s\n", str); xenstore_dom_write(domid, "dom0_input", str); } - arg = strtol(str_arg, NULL, 10); - if (errno == EINVAL) - dom0_driver_location_init(str_arg); - else - dom0_driver_slot_init(arg); + if (vga_passthrough) + xenstore_write_dom0_driver("natif", domid); + + xenstore_watch_dom0_driver("mouse/state", "dom0_driver_keyboard_state"); + xenstore_watch_dom0_driver("keyboard/state", "dom0_driver_mouse_state"); + xenstore_watch_dom0_driver("blank", "dom0_driver_blank_done"); + + /* Register the failover switch */ + driver.xs_timer = qemu_new_timer(rt_clock, dom0_driver_failover_switch, NULL); + qemu_mod_timer(driver.xs_timer, qemu_get_clock(rt_clock) + XS_REFRESH_INTERVAL); } -static void dom0_driver_cleanup(void) +static void dom0_driver_slots(int controller) { - char *tmp; - int cur_domid, state; + struct dom0_driver_xs_info info; + int next_domid; + int positions[NB_SLOTS]; - free(driver.event_fds); - - if (!(tmp = xenstore_read_dom0_driver("domid"))) + if (dom0_driver_failover_switch(NULL)) return; - cur_domid = strtol(tmp, NULL, 10); - free(tmp); - if (!(tmp = xenstore_read_dom0_driver("state"))) - return; - state = strtol(tmp, NULL, 10); - free(tmp); - - if (cur_domid == domid && state == 1) - xenstore_write_dom0_driver("state", 0); + dom0_driver_read_xs_info(&info, controller); + + if (info.new_slot != -1) + { + dom0_get_positions(positions); + if (positions[info.new_slot] != 0) + { + /* + if (info.domid == domid && + positions[info.new_slot] == domid) + { + DEBUG("already on this slot\n"); + return; + } + */ + if (info.state == 0 && info.domid == domid) + { + DEBUG("release devices\n"); + dom0_gr_devices(0, controller); + return; + } + + if (info.state == 2 && positions[info.new_slot] == domid) + { + DEBUG("grab devices\n"); + dom0_gr_devices(1, controller); + return; + } + } + } +} + +static void dom0_driver_blank_done(void) +{ + struct dom0_driver_xs_info info; + int blank; + + dom0_driver_read_xs_info(&info, DOM0_MOUSE); + blank = dom0_driver_xs_read_dom0("blank"); + + if (info.state == 1 && blank == 2) + { + dom0_driver_focus = info.domid == domid; + xenstore_write_dom0_driver("blank", 3); + } +} + +void dom0_driver_state_change(const char *str) +{ + if (!strcmp(str, "dom0_driver_keyboard_state")) + dom0_driver_slots(DOM0_KEYBOARD); + if (!strcmp(str, "dom0_driver_mouse_state")) + dom0_driver_slots(DOM0_MOUSE); + if (!strcmp(str, "dom0_driver_blank_done")) + dom0_driver_blank_done(); } void dom0_driver_init(const char *position) { memset(&driver, 0, sizeof (driver)); dom0_driver_event_init(position); - - atexit(dom0_driver_cleanup); + dom0_driver_failover_switch(NULL); } diff --git a/hw/pass-through.h b/hw/pass-through.h index 0f3d29b3..008de51b 100644 --- a/hw/pass-through.h +++ b/hw/pass-through.h @@ -26,7 +26,7 @@ #include "audio/sys-queue.h" /* Log acesss */ -#define PT_LOGGING_ENABLED +//#define PT_LOGGING_ENABLED #ifdef PT_LOGGING_ENABLED #define PT_LOG(_f, _a...) fprintf(logfile, "%s: " _f, __func__, ##_a) diff --git a/hw/pci.c b/hw/pci.c index f635c60d..fee6067a 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -30,7 +30,7 @@ //#include "exec-all.h" #include "qemu-xen.h" -#define DEBUG_PCI +//#define DEBUG_PCI struct PCIBus { int bus_num; @@ -480,10 +480,10 @@ uint32_t pci_data_read(void *opaque, uint32_t addr, int len) if (config_addr == 0x52) // GMCH val = pt_pci_host_read_word(0, 0, 0, 0x52); - if (config_addr == 0xa0) // Top Memory addrress - val = pt_pci_host_read_byte(0, 0, 0, 0xa0); -/* if (config_addr == 0x02) // Device ID - val = pt_pci_host_read_byte(0, 0, 0, 0x02);*/ +/* if (config_addr == 0xa0) // Top Memory addrress + val = pt_pci_host_read_byte(0, 0, 0, 0xa0);*/ + if (config_addr == 0x02) // Device ID + val = pt_pci_host_read_byte(0, 0, 0, 0x02); } else val = pci_dev->config_read(pci_dev, config_addr, len); diff --git a/intel.c b/intel.c index 1e1df3d0..f3adb1a6 100644 --- a/intel.c +++ b/intel.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "qemu-common.h" #include "console.h" @@ -16,9 +17,9 @@ #define TileW 128 #define TileH 8 -#define IntelFbBase 0x80000000 -#define IntelMMIOAddr 0x90000000 -#define TilePitch 8 +//#define IntelFbBase 0x80000000 +//#define IntelMMIOAddr 0x98000000 +#define TilePitch 16 #define REG_DR_DSPASURF 0x7019C #define REG_DR_DSPACNTR 0x70180 @@ -29,6 +30,9 @@ static int fd_mem_ro = -1; static int fd_mem_rw = -1; static unsigned char *intel_mem = NULL; static unsigned char *intel_mmio = NULL; +static int intel_force_full_update = 0; + +extern int dom0_driver_focus; static inline unsigned int intel_get_reg(unsigned int reg) { @@ -47,8 +51,8 @@ static inline unsigned int intel_get_offset(DisplayState *ds, int x, int y) static inline void intel_blit_tile(DisplayState *ds, int x, int y) { - static const int solid_line[] = {0, 3, 5, 6}; - static const int dashed_line[] = {1, 2, 4, 7}; + static const int solid_line[] = {0,1,2,3,4,5,6,7}; + static const int dashed_line[] = {}; unsigned int toffset, offset, to, o; unsigned char *buff; int i, j; @@ -58,21 +62,19 @@ static inline void intel_blit_tile(DisplayState *ds, int x, int y) /* Copy the solid lines */ toffset = intel_get_tiled_offset(x, y); offset = intel_get_offset(ds, x * TileW, y * TileH); - for (i = 0; i < 4; i++) + for (i = 0; i < sizeof (solid_line) / sizeof (int); i++) { to = toffset + solid_line[i] * TileW * 4; o = offset + solid_line[i] * ds->width * 4; memcpy(&buff[to], &ds->data[o], TileW * 4); } - /* Copy the dashed lines */ toffset = to = intel_get_tiled_offset(x, y); offset = o = intel_get_offset(ds, x * TileW, y * TileH); - for (i = 0; i < 4; i++) + for (i = 0; i < sizeof (dashed_line) / sizeof (int); i++) { to = toffset + dashed_line[i] * TileW * 4; o = offset + dashed_line[i] * ds->width * 4 + 16 * 4; - /* copy the odd one */ for (j = 0; j < 4 ; j++) { memcpy(&buff[to], &ds->data[o], 16 * 4); @@ -97,14 +99,21 @@ static void intel_update_tiled(DisplayState *ds, int x, int y, int w, int h) for (i = yt; i < ht; i++) for (j = xt; j < wt; j++) - if (j >= 0 && j < 8 && i >= 0 && i < 96 && + if (j >= 0 && j < 10 && i >= 0 && i < 100 && (i * TileH) < ds->height && (j * TileW) < ds->width) intel_blit_tile(ds, j, i); } static void intel_update(DisplayState *ds, int x, int y, int w, int h) { + if (!dom0_driver_focus) + return; + + if (intel_force_full_update) + intel_update_tiled(ds, 0, 0, 1280, 800); + intel_update_tiled(ds, x, y, w, h); + intel_force_full_update = 0; } static void intel_resize(DisplayState *ds, int w, int h) @@ -112,18 +121,26 @@ static void intel_resize(DisplayState *ds, int w, int h) ds->linesize = w * 4; ds->width = w; ds->height = h; - - ds->data = realloc(ds->data, w * ds->linesize); - memset(ds->data, 0, w * ds->linesize); + ds->data = realloc(ds->data, h * ds->linesize); } static void intel_refresh(DisplayState *ds) { + if (!dom0_driver_focus) + { + intel_force_full_update = 1; + return; + } + vga_hw_update(); } static void intel_init_mapping(void) { + struct pci_access *pci_bus; + struct pci_dev *pci_dev; + uint32_t intel_fb_base, intel_mmio_base; + fd_mem_ro = open("/dev/mem", O_RDONLY); if (fd_mem_ro == -1) { @@ -136,16 +153,28 @@ static void intel_init_mapping(void) perror("open"); exit(1); } - + + pci_bus = pci_alloc(); + pci_init(pci_bus); + pci_dev = pci_get_dev(pci_bus, 0, 0, 2, 0); + pci_fill_info(pci_dev, PCI_FILL_BASES); + intel_fb_base = pci_dev->base_addr[2] & 0xfffff000; + intel_mmio_base = pci_dev->base_addr[0] & 0xfffff000; + pci_free_dev(pci_dev); + pci_cleanup(pci_bus); + + INTEL_DEBUG("Map intel main mem 0x%x\n", intel_fb_base); intel_mem = mmap(NULL, 0x10000000, PROT_READ | PROT_WRITE, MAP_SHARED, - fd_mem_rw, IntelFbBase); + fd_mem_rw, intel_fb_base); if (intel_mem == MAP_FAILED) { perror("mmap"); exit(1); } + + INTEL_DEBUG("Map intel mmio 0x%x\n", intel_mmio_base); intel_mmio = mmap(NULL, 4 * 1024 * 1024, PROT_READ, MAP_SHARED, - fd_mem_ro, IntelMMIOAddr); + fd_mem_ro, intel_mmio_base); if (intel_mem == MAP_FAILED) { perror("mmap"); @@ -155,13 +184,9 @@ static void intel_init_mapping(void) void intel_display_init(DisplayState *ds) { - INTEL_DEBUG("\n"); - intel_init_mapping(); - - ds->dpy_update = intel_update; - ds->dpy_resize = intel_resize; - ds->dpy_refresh = intel_refresh; + + INTEL_DEBUG("Frambuffer is at 0x%x\n", intel_get_reg(REG_DR_DSPASURF)); ds->shared_buf = 0; ds->data = NULL; @@ -169,4 +194,8 @@ void intel_display_init(DisplayState *ds) ds->height = 400; ds->linesize = 640 * 4; ds->depth = 32; + + ds->dpy_update = intel_update; + ds->dpy_resize = intel_resize; + ds->dpy_refresh = intel_refresh; } diff --git a/xenstore.c b/xenstore.c index fe7782a1..9915cf4b 100644 --- a/xenstore.c +++ b/xenstore.c @@ -270,7 +270,7 @@ const char *xenstore_get_guest_uuid(void) { #endif } -#define DIRECT_PCI_STR_LEN 160 +#define DIRECT_PCI_STR_LEN 260 char direct_pci_str[DIRECT_PCI_STR_LEN]; void xenstore_parse_domain_config(int hvm_domid) { @@ -785,6 +785,14 @@ void xenstore_process_event(void *opaque) xenstore_process_dm_command_event(); goto out; } + + if (!strcmp(vec[XS_WATCH_TOKEN], "dom0_driver_keyboard_state") || + !strcmp(vec[XS_WATCH_TOKEN], "dom0_driver_mouse_state") || + !strcmp(vec[XS_WATCH_TOKEN], "dom0_driver_blank_done")) + { + dom0_driver_state_change(vec[XS_WATCH_TOKEN]); + goto out; + } if (strncmp(vec[XS_WATCH_TOKEN], "hd", 2) || strlen(vec[XS_WATCH_TOKEN]) != 3) @@ -1236,6 +1244,19 @@ char *xenstore_read_dom0_driver(const char *key) return val; } +int xenstore_watch_dom0_driver(const char *key, const char *token) +{ + const char *path = "/local/domain/0/dom0_driver"; + char *buf = NULL; + int ret = 0; + + if (pasprintf(&buf, "%s/%s", path, key) == -1) + return 0; + ret = xs_watch(xsh, buf, token); + free(buf); + return ret; +} + int xenstore_write_dom0_driver(const char *key, int val) { const char *path = "/local/domain/0/dom0_driver"; @@ -1305,7 +1326,6 @@ int xenstore_dom_write(int domid, char *key, char *value) return rc; } - int *xenstore_get_domids(int *len) { int *tab = NULL;