X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Fcga.c;h=3f137e615890c5f9710a7f7dfd604b246972797e;hb=d46ec4b471af03e5e7562aeec4b26a2701671a01;hp=119709f2496170ae8b0d782c4ab77a94a546a590;hpb=ec660ce1c5410ef08a7820f7ee064a30b416a523;p=palacios.releases.git diff --git a/palacios/src/devices/cga.c b/palacios/src/devices/cga.c index 119709f..3f137e6 100644 --- a/palacios/src/devices/cga.c +++ b/palacios/src/devices/cga.c @@ -70,6 +70,8 @@ struct video_internal { // so we need a temp variable to hold the partial update uint16_t tmp_screen_offset; + struct vm_device * dev; + uint8_t passthrough; @@ -151,8 +153,7 @@ static int video_write_mem(struct guest_info * core, addr_t guest_addr, void * d } static int video_read_port(struct guest_info * core, uint16_t port, void * dest, uint_t length, void * priv_data) { - struct vm_device * dev = (struct vm_device *)priv_data; - struct video_internal * video_state = (struct video_internal *)dev->private_data; + struct video_internal * video_state = priv_data; PrintDebug("Video: Read port 0x%x\n", port); @@ -167,8 +168,7 @@ static int video_read_port(struct guest_info * core, uint16_t port, void * dest, static int video_write_port(struct guest_info * core, uint16_t port, void * src, uint_t length, void * priv_data) { - struct vm_device * dev = (struct vm_device *)priv_data; - struct video_internal * video_state = (struct video_internal *)dev->private_data; + struct video_internal * video_state = priv_data; PrintDebug("Video: write port 0x%x...\n", port); @@ -183,8 +183,7 @@ static int video_write_port(struct guest_info * core, uint16_t port, void * src, static int crtc_data_write(struct guest_info * core, uint16_t port, void * src, uint_t length, void * priv_data) { - struct vm_device * dev = (struct vm_device *)priv_data; - struct video_internal * video_state = (struct video_internal *)dev->private_data; + struct video_internal * video_state = priv_data; uint8_t val = *(uint8_t *)src; uint_t index = video_state->crtc_index_reg; @@ -263,16 +262,14 @@ static int crtc_data_write(struct guest_info * core, uint16_t port, void * src, static int crtc_index_write(struct guest_info * core, uint16_t port, void * src, uint_t length, void * priv_data) { - struct vm_device * dev = (struct vm_device *)priv_data; - struct video_internal * video_state = (struct video_internal *)dev->private_data; + struct video_internal * video_state = priv_data; if (length > 2) { PrintError("Invalid write length for crtc index register port: %d (0x%x)\n", port, port); return -1; } - - + video_state->crtc_index_reg = *(uint8_t *)src; // Only do the passthrough IO for the first byte @@ -282,7 +279,7 @@ static int crtc_index_write(struct guest_info * core, uint16_t port, void * src, } if (length == 2) { - if (crtc_data_write(core, port + 1, src + 1, length - 1, dev) != (length - 1)) { + if (crtc_data_write(core, port + 1, src + 1, length - 1, video_state) != (length - 1)) { PrintError("could not handle implicit crtc data write\n"); return -1; } @@ -300,6 +297,11 @@ int v3_cons_get_fb(struct vm_device * frontend_dev, uint8_t * dst, uint_t offset PrintDebug("Getting framebuffer for screen; framebuf=%p, screen_offset=%d, offset=%d, length=%d\n", state->framebuf, screen_byte_offset, offset, length); + V3_ASSERT(screen_byte_offset <= FRAMEBUF_SIZE - SCREEN_SIZE); + V3_ASSERT(offset < SCREEN_SIZE); + V3_ASSERT(length <= SCREEN_SIZE); + V3_ASSERT(offset + length <= SCREEN_SIZE); + memcpy(dst, state->framebuf + screen_byte_offset + offset, length); return 0; @@ -307,60 +309,14 @@ int v3_cons_get_fb(struct vm_device * frontend_dev, uint8_t * dst, uint_t offset -static int free_device(struct vm_device * dev) { - struct video_internal * video_state = (struct video_internal *)dev->private_data; - struct v3_vm_info * vm = dev->vm; +static int free_cga(struct video_internal * video_state) { if (video_state->framebuf_pa) { + PrintError("Freeing framebuffer PA %p\n", (void *)(video_state->framebuf_pa)); V3_FreePages((void *)(video_state->framebuf_pa), (FRAMEBUF_SIZE / 4096)); } - v3_unhook_mem(dev->vm, V3_MEM_CORE_ANY, START_ADDR); - - v3_unhook_io_port(vm, 0x3b0); - v3_unhook_io_port(vm, 0x3b1); - v3_unhook_io_port(vm, 0x3b2); - v3_unhook_io_port(vm, 0x3b3); - v3_unhook_io_port(vm, 0x3b4); - v3_unhook_io_port(vm, 0x3b5); - v3_unhook_io_port(vm, 0x3b6); - v3_unhook_io_port(vm, 0x3b7); - v3_unhook_io_port(vm, 0x3b8); - v3_unhook_io_port(vm, 0x3b9); - v3_unhook_io_port(vm, 0x3ba); - v3_unhook_io_port(vm, 0x3bb); - v3_unhook_io_port(vm, 0x3c0); - v3_unhook_io_port(vm, 0x3c1); - v3_unhook_io_port(vm, 0x3c2); - v3_unhook_io_port(vm, 0x3c3); - v3_unhook_io_port(vm, 0x3c4); - v3_unhook_io_port(vm, 0x3c5); - v3_unhook_io_port(vm, 0x3c6); - v3_unhook_io_port(vm, 0x3c7); - v3_unhook_io_port(vm, 0x3c8); - v3_unhook_io_port(vm, 0x3c9); - v3_unhook_io_port(vm, 0x3ca); - v3_unhook_io_port(vm, 0x3cb); - v3_unhook_io_port(vm, 0x3cc); - v3_unhook_io_port(vm, 0x3cd); - v3_unhook_io_port(vm, 0x3ce); - v3_unhook_io_port(vm, 0x3cf); - v3_unhook_io_port(vm, 0x3d0); - v3_unhook_io_port(vm, 0x3d1); - v3_unhook_io_port(vm, 0x3d2); - v3_unhook_io_port(vm, 0x3d3); - v3_unhook_io_port(vm, 0x3d4); - v3_unhook_io_port(vm, 0x3d5); - v3_unhook_io_port(vm, 0x3d6); - v3_unhook_io_port(vm, 0x3d7); - v3_unhook_io_port(vm, 0x3d8); - v3_unhook_io_port(vm, 0x3d9); - v3_unhook_io_port(vm, 0x3da); - v3_unhook_io_port(vm, 0x3db); - v3_unhook_io_port(vm, 0x3dc); - v3_unhook_io_port(vm, 0x3dd); - v3_unhook_io_port(vm, 0x3de); - v3_unhook_io_port(vm, 0x3df); + v3_unhook_mem(video_state->dev->vm, V3_MEM_CORE_ANY, START_ADDR); V3_Free(video_state); @@ -369,26 +325,29 @@ static int free_device(struct vm_device * dev) { static struct v3_device_ops dev_ops = { - .free = free_device, + .free = (int (*)(void *))free_cga, }; static int cga_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { struct video_internal * video_state = NULL; char * dev_id = v3_cfg_val(cfg, "ID"); char * passthrough_str = v3_cfg_val(cfg, "passthrough"); + int ret = 0; PrintDebug("video: init_device\n"); video_state = (struct video_internal *)V3_Malloc(sizeof(struct video_internal)); memset(video_state, 0, sizeof(struct video_internal)); - struct vm_device * dev = v3_allocate_device(dev_id, &dev_ops, video_state); + struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, video_state); - if (v3_attach_device(vm, dev) == -1) { + if (dev == NULL) { PrintError("Could not attach device %s\n", dev_id); V3_Free(video_state); return -1; } + + video_state->dev = dev; video_state->framebuf_pa = (addr_t)V3_AllocPages(FRAMEBUF_SIZE / 4096); video_state->framebuf = V3_VAddr((void *)(video_state->framebuf_pa)); @@ -416,51 +375,56 @@ static int cga_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { } - v3_hook_io_port(vm, 0x3b0, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3b1, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3b2, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3b3, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3b4, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3b5, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3b6, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3b7, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3b8, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3b9, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3ba, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3bb, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3c0, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3c1, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3c2, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3c3, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3c4, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3c5, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3c6, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3c7, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3c8, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3c9, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3ca, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3cb, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3cc, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3cd, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3ce, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3cf, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3d0, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3d1, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3d2, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3d3, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3d4, &video_read_port, &crtc_index_write, dev); - v3_hook_io_port(vm, 0x3d5, &video_read_port, &crtc_data_write, dev); - v3_hook_io_port(vm, 0x3d6, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3d7, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3d8, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3d9, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3da, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3db, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3dc, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3dd, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3de, &video_read_port, &video_write_port, dev); - v3_hook_io_port(vm, 0x3df, &video_read_port, &video_write_port, dev); - + ret |= v3_dev_hook_io(dev, 0x3b0, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3b1, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3b2, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3b3, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3b4, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3b5, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3b6, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3b7, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3b8, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3b9, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3ba, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3bb, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3c0, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3c1, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3c2, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3c3, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3c4, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3c5, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3c6, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3c7, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3c8, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3c9, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3ca, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3cb, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3cc, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3cd, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3ce, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3cf, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3d0, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3d1, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3d2, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3d3, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3d4, &video_read_port, &crtc_index_write); + ret |= v3_dev_hook_io(dev, 0x3d5, &video_read_port, &crtc_data_write); + ret |= v3_dev_hook_io(dev, 0x3d6, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3d7, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3d8, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3d9, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3da, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3db, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3dc, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3dd, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3de, &video_read_port, &video_write_port); + ret |= v3_dev_hook_io(dev, 0x3df, &video_read_port, &video_write_port); + + if (ret != 0) { + PrintError("Error allocating cga io port\n"); + v3_remove_device(dev); + return -1; + } return 0; }