From: Lei Xia Date: Tue, 23 Nov 2010 04:00:52 +0000 (-0600) Subject: Merge branch 'devel' of palacios@newskysaw.cs.northwestern.edu:/home/palacios/palacio... X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=commitdiff_plain;h=eb5eb0f70b84003972a96060c76bd7efad340be4;hp=00460ac661afa22c2bb495eba4d4655d20a1bfdc;p=palacios.git Merge branch 'devel' of palacios@newskysaw.cs.northwestern.edu:/home/palacios/palacios into devel Conflicts: palacios/src/devices/nic_bridge.c --- diff --git a/palacios/include/devices/apic.h b/palacios/include/devices/apic.h index 40415e6..4ddfc7c 100644 --- a/palacios/include/devices/apic.h +++ b/palacios/include/devices/apic.h @@ -44,11 +44,11 @@ struct v3_gen_ipi { uint8_t dst; } __attribute__((packed)); -int v3_apic_send_ipi(struct v3_vm_info * vm, struct vm_device * dev, - struct v3_gen_ipi * ipi); +int v3_apic_send_ipi(struct v3_vm_info * vm, struct v3_gen_ipi * ipi, void * dev_data); -int v3_apic_raise_intr(struct v3_vm_info * vm, struct vm_device * apic_dev, - uint32_t irq, uint32_t dst); +int v3_apic_raise_intr(struct v3_vm_info * vm, + uint32_t irq, uint32_t dst, + void * dev_data); diff --git a/palacios/include/devices/ide.h b/palacios/include/devices/ide.h index 8f8951d..14e915f 100644 --- a/palacios/include/devices/ide.h +++ b/palacios/include/devices/ide.h @@ -24,7 +24,7 @@ -int v3_ide_get_geometry(struct vm_device * ide_dev, int channel_num, int drive_num, +int v3_ide_get_geometry(void * ide_data, int channel_num, int drive_num, uint32_t * cylinders, uint32_t * heads, uint32_t * sectors); diff --git a/palacios/include/devices/pci.h b/palacios/include/devices/pci.h index 9bf4632..46864fd 100644 --- a/palacios/include/devices/pci.h +++ b/palacios/include/devices/pci.h @@ -151,9 +151,9 @@ struct pci_device { int v3_pci_set_irq_bridge(struct vm_device * pci_bus, int bus_num, - int (*raise_pci_irq)(struct vm_device * dev, struct pci_device * pci_dev), - int (*lower_pci_irq)(struct vm_device * dev, struct pci_device * pci_dev), - struct vm_device * bridge_dev); + int (*raise_pci_irq)(struct pci_device * pci_dev, void * dev_data), + int (*lower_pci_irq)(struct pci_device * pci_dev, void * dev_data), + void * dev_data); int v3_pci_raise_irq(struct vm_device * pci_bus, int bus_num, struct pci_device * dev); diff --git a/palacios/include/devices/southbridge.h b/palacios/include/devices/southbridge.h index 966d652..c20ad74 100644 --- a/palacios/include/devices/southbridge.h +++ b/palacios/include/devices/southbridge.h @@ -28,10 +28,14 @@ typedef enum {V3_SB_INVALID, V3_SB_PIIX3, V3_SB_PIIX4, V3_SB_CMD646} v3_southbridge_type_t; +struct v3_vm_info; + struct v3_southbridge { struct vm_device * pci_bus; struct pci_device * southbridge_pci; + struct v3_vm_info * vm; + v3_southbridge_type_t type; }; diff --git a/palacios/include/palacios/vmm_dev_mgr.h b/palacios/include/palacios/vmm_dev_mgr.h index d6942c0..a952e9f 100644 --- a/palacios/include/palacios/vmm_dev_mgr.h +++ b/palacios/include/palacios/vmm_dev_mgr.h @@ -33,6 +33,9 @@ struct v3_vm_info; struct v3_device_ops; +typedef void * v3_dev_data_t; + +struct vm_device; struct vm_device { char name[32]; @@ -65,8 +68,8 @@ struct vmm_dev_mgr { struct list_head char_list; struct hashtable * char_table; - struct list_head console_list; - struct hashtable * console_table; + struct list_head cons_list; + struct hashtable * cons_table; }; @@ -100,14 +103,7 @@ int v3_init_devices(); struct v3_device_ops { - int (*free)(struct vm_device *dev); - - - int (*reset)(struct vm_device *dev); - - int (*start)(struct vm_device *dev); - int (*stop)(struct vm_device *dev); - + int (*free)(struct vm_device * dev); //int (*save)(struct vm_device *dev, struct *iostream); //int (*restore)(struct vm_device *dev, struct *iostream); @@ -118,12 +114,12 @@ struct v3_device_ops { -int v3_dev_hook_io(struct vm_device *dev, +int v3_dev_hook_io(struct vm_device * dev, ushort_t port, - int (*read)(struct guest_info * core, ushort_t port, void * dst, uint_t length, struct vm_device * dev), - int (*write)(struct guest_info * core, ushort_t port, void * src, uint_t length, struct vm_device * dev)); + int (*read)(struct guest_info * core, ushort_t port, void * dst, uint_t length, void * priv_data), + int (*write)(struct guest_info * core, ushort_t port, void * src, uint_t length, void * priv_data)); -int v3_dev_unhook_io(struct vm_device *dev, +int v3_dev_unhook_io(struct vm_device * dev, ushort_t port); @@ -162,9 +158,9 @@ struct v3_dev_blk_ops { struct v3_dev_net_ops { /* Backend implemented functions */ - int (*send)(uint8_t * buf, uint32_t count, void * private_data, struct vm_device *dest_dev); - void (*start_rx)(void *back_data); - void (*stop_rx)(void *back_data); + int (*send)(uint8_t * buf, uint32_t count, void * private_data); + void (*start_rx)(void * back_data); + void (*stop_rx)(void * back_data); /* Frontend implemented functions */ int (*recv)(uint8_t * buf, uint32_t count, void * frnt_data); @@ -177,7 +173,13 @@ struct v3_dev_net_ops { }; struct v3_dev_console_ops { + int (*update_screen)(uint_t x, uint_t y, uint_t length, uint8_t * fb_data, void * private_data); + int (*update_cursor)(uint_t x, uint_t y, void * private_data); + int (*scroll)(int rows, void * private_data); + /* frontend implemented functions */ + int (*get_screen)(uint_t x, uint_t y, uint_t length, void * frontend_data); + void * push_fn_arg; }; struct v3_dev_char_ops { @@ -221,6 +223,25 @@ int v3_dev_connect_net(struct v3_vm_info * vm, void * private_data); + + +int v3_dev_add_console_frontend(struct v3_vm_info * vm, + char * name, + int (*connect)(struct v3_vm_info * vm, + void * frontend_data, + struct v3_dev_console_ops * ops, + v3_cfg_tree_t * cfg, + void * private_data), + void * priv_data); + +int v3_dev_connect_console(struct v3_vm_info * vm, + char * frontend_name, + struct v3_dev_console_ops * ops, + v3_cfg_tree_t * cfg, + void * private_data); + + + int v3_dev_add_char_frontend(struct v3_vm_info * vm, char * name, int (*connect)(struct v3_vm_info * vm, diff --git a/palacios/src/devices/8254.c b/palacios/src/devices/8254.c index 3ac10e1..028357f 100644 --- a/palacios/src/devices/8254.c +++ b/palacios/src/devices/8254.c @@ -127,7 +127,7 @@ struct pit_rdb_status_word { * This should call out to handle_SQR_WAVE_tics, etc... */ // Returns true if the the output signal changed state -static int handle_crystal_tics(struct vm_device * dev, struct channel * ch, uint_t oscillations) { +static int handle_crystal_tics(struct pit * pit, struct channel * ch, uint_t oscillations) { uint_t channel_cycles = 0; uint_t output_changed = 0; @@ -239,8 +239,7 @@ static int handle_crystal_tics(struct vm_device * dev, struct channel * ch, uint #include static void pit_update_timer(struct guest_info * info, ullong_t cpu_cycles, ullong_t cpu_freq, void * private_data) { - struct vm_device * dev = (struct vm_device *)private_data; - struct pit * state = (struct pit *)dev->private_data; + struct pit * state = (struct pit *)private_data; // ullong_t tmp_ctr = state->pit_counter; ullong_t tmp_cycles; uint_t oscillations = 0; @@ -299,14 +298,14 @@ static void pit_update_timer(struct guest_info * info, ullong_t cpu_cycles, ullo state->pit_counter = state->pit_reload - cpu_cycles; //PrintDebug("8254 PIT: Handling %d crystal tics\n", oscillations); - if (handle_crystal_tics(dev, &(state->ch_0), oscillations) == 1) { + if (handle_crystal_tics(state, &(state->ch_0), oscillations) == 1) { // raise interrupt PrintDebug("8254 PIT: Injecting Timer interrupt to guest\n"); v3_raise_irq(info->vm_info, 0); } - //handle_crystal_tics(dev, &(state->ch_1), oscillations); - handle_crystal_tics(dev, &(state->ch_2), oscillations); + //handle_crystal_tics(state, &(state->ch_1), oscillations); + handle_crystal_tics(state, &(state->ch_2), oscillations); } @@ -478,8 +477,7 @@ static int handle_channel_cmd(struct channel * ch, struct pit_cmd_word cmd) { static int pit_read_channel(struct guest_info * core, ushort_t port, void * dst, uint_t length, void * priv_data) { - struct vm_device * dev = (struct vm_device *)priv_data; - struct pit * state = (struct pit *)dev->private_data; + struct pit * state = (struct pit *)priv_data; char * val = (char *)dst; if (length != 1) { @@ -525,8 +523,7 @@ static int pit_read_channel(struct guest_info * core, ushort_t port, void * dst, static int pit_write_channel(struct guest_info * core, ushort_t port, void * src, uint_t length, void * priv_data) { - struct vm_device * dev = (struct vm_device *)priv_data; - struct pit * state = (struct pit *)dev->private_data; + struct pit * state = (struct pit *)priv_data; char val = *(char *)src; if (length != 1) { @@ -574,8 +571,7 @@ static int pit_write_channel(struct guest_info * core, ushort_t port, void * src static int pit_write_command(struct guest_info * core, ushort_t port, void * src, uint_t length, void * priv_data) { - struct vm_device * dev = (struct vm_device *)priv_data; - struct pit * state = (struct pit *)dev->private_data; + struct pit * state = (struct pit *)priv_data; struct pit_cmd_word * cmd = (struct pit_cmd_word *)src; PrintDebug("8254 PIT: Write to PIT Command port\n"); @@ -654,13 +650,7 @@ static int pit_free(struct vm_device * dev) { if (state->timer) { v3_remove_timer(info, state->timer); } - - v3_unhook_io_port(dev->vm, CHANNEL0_PORT); - v3_unhook_io_port(dev->vm, CHANNEL1_PORT); - v3_unhook_io_port(dev->vm, CHANNEL2_PORT); - v3_unhook_io_port(dev->vm, COMMAND_PORT); - v3_unhook_io_port(dev->vm, SPEAKER_PORT); - + V3_Free(state); return 0; } @@ -668,9 +658,7 @@ static int pit_free(struct vm_device * dev) { static struct v3_device_ops dev_ops = { .free = pit_free, - .reset = NULL, - .start = NULL, - .stop = NULL, + }; @@ -701,11 +689,11 @@ static int pit_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { return -1; } - ret |= v3_hook_io_port(vm, CHANNEL0_PORT, &pit_read_channel, &pit_write_channel, dev); - ret |= v3_hook_io_port(vm, CHANNEL1_PORT, &pit_read_channel, &pit_write_channel, dev); - ret |= v3_hook_io_port(vm, CHANNEL2_PORT, &pit_read_channel, &pit_write_channel, dev); - ret |= v3_hook_io_port(vm, COMMAND_PORT, NULL, &pit_write_command, dev); - ret |= v3_hook_io_port(vm, SPEAKER_PORT, &pit_read_channel, &pit_write_channel, dev); + ret |= v3_dev_hook_io(dev, CHANNEL0_PORT, &pit_read_channel, &pit_write_channel); + ret |= v3_dev_hook_io(dev, CHANNEL1_PORT, &pit_read_channel, &pit_write_channel); + ret |= v3_dev_hook_io(dev, CHANNEL2_PORT, &pit_read_channel, &pit_write_channel); + ret |= v3_dev_hook_io(dev, COMMAND_PORT, NULL, &pit_write_command); + ret |= v3_dev_hook_io(dev, SPEAKER_PORT, &pit_read_channel, &pit_write_channel); if (ret != 0) { PrintError("8254 PIT: Failed to hook IO ports\n"); @@ -721,7 +709,7 @@ static int pit_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { - pit_state->timer = v3_add_timer(info, &timer_ops, dev); + pit_state->timer = v3_add_timer(info, &timer_ops, pit_state); if (pit_state->timer == NULL) { v3_detach_device(dev); diff --git a/palacios/src/devices/8259a.c b/palacios/src/devices/8259a.c index 6a74e8e..248fbb0 100644 --- a/palacios/src/devices/8259a.c +++ b/palacios/src/devices/8259a.c @@ -357,8 +357,8 @@ static struct intr_router_ops router_ops = { }; -static int read_master_port1(struct guest_info * core, ushort_t port, void * dst, uint_t length, struct vm_device * dev) { - struct pic_internal * state = (struct pic_internal*)dev->private_data; +static int read_master_port1(struct guest_info * core, ushort_t port, void * dst, uint_t length, void * priv_data) { + struct pic_internal * state = (struct pic_internal *)priv_data; if (length != 1) { PrintError("8259 PIC: Invalid Read length (rd_Master1)\n"); @@ -376,8 +376,8 @@ static int read_master_port1(struct guest_info * core, ushort_t port, void * dst return 1; } -static int read_master_port2(struct guest_info * core, ushort_t port, void * dst, uint_t length, struct vm_device * dev) { - struct pic_internal * state = (struct pic_internal*)dev->private_data; +static int read_master_port2(struct guest_info * core, ushort_t port, void * dst, uint_t length, void * priv_data) { + struct pic_internal * state = (struct pic_internal *)priv_data; if (length != 1) { PrintError("8259 PIC: Invalid Read length (rd_Master2)\n"); @@ -390,8 +390,8 @@ static int read_master_port2(struct guest_info * core, ushort_t port, void * dst } -static int read_slave_port1(struct guest_info * core, ushort_t port, void * dst, uint_t length, struct vm_device * dev) { - struct pic_internal * state = (struct pic_internal*)dev->private_data; +static int read_slave_port1(struct guest_info * core, ushort_t port, void * dst, uint_t length, void * priv_data) { + struct pic_internal * state = (struct pic_internal *)priv_data; if (length != 1) { PrintError("8259 PIC: Invalid Read length (rd_Slave1)\n"); @@ -409,8 +409,8 @@ static int read_slave_port1(struct guest_info * core, ushort_t port, void * dst, return 1; } -static int read_slave_port2(struct guest_info * core, ushort_t port, void * dst, uint_t length, struct vm_device * dev) { - struct pic_internal * state = (struct pic_internal*)dev->private_data; +static int read_slave_port2(struct guest_info * core, ushort_t port, void * dst, uint_t length, void * priv_data) { + struct pic_internal * state = (struct pic_internal *)priv_data; if (length != 1) { PrintError("8259 PIC: Invalid Read length (rd_Slave2)\n"); @@ -423,8 +423,8 @@ static int read_slave_port2(struct guest_info * core, ushort_t port, void * dst, } -static int write_master_port1(struct guest_info * core, ushort_t port, void * src, uint_t length, struct vm_device * dev) { - struct pic_internal * state = (struct pic_internal*)dev->private_data; +static int write_master_port1(struct guest_info * core, ushort_t port, void * src, uint_t length, void * priv_data) { + struct pic_internal * state = (struct pic_internal *)priv_data; uchar_t cw = *(uchar_t *)src; PrintDebug("8259 PIC: Write master port 1 with 0x%x\n",cw); @@ -491,8 +491,8 @@ static int write_master_port1(struct guest_info * core, ushort_t port, void * sr return 1; } -static int write_master_port2(struct guest_info * core, ushort_t port, void * src, uint_t length, struct vm_device * dev) { - struct pic_internal * state = (struct pic_internal*)dev->private_data; +static int write_master_port2(struct guest_info * core, ushort_t port, void * src, uint_t length, void * priv_data) { + struct pic_internal * state = (struct pic_internal *)priv_data; uchar_t cw = *(uchar_t *)src; PrintDebug("8259 PIC: Write master port 2 with 0x%x\n",cw); @@ -552,8 +552,8 @@ static int write_master_port2(struct guest_info * core, ushort_t port, void * sr return 1; } -static int write_slave_port1(struct guest_info * core, ushort_t port, void * src, uint_t length, struct vm_device * dev) { - struct pic_internal * state = (struct pic_internal*)dev->private_data; +static int write_slave_port1(struct guest_info * core, ushort_t port, void * src, uint_t length, void * priv_data) { + struct pic_internal * state = (struct pic_internal *)priv_data; uchar_t cw = *(uchar_t *)src; PrintDebug("8259 PIC: Write slave port 1 with 0x%x\n",cw); @@ -613,8 +613,8 @@ static int write_slave_port1(struct guest_info * core, ushort_t port, void * src return 1; } -static int write_slave_port2(struct guest_info * core, ushort_t port, void * src, uint_t length, struct vm_device * dev) { - struct pic_internal * state = (struct pic_internal*)dev->private_data; +static int write_slave_port2(struct guest_info * core, ushort_t port, void * src, uint_t length, void * priv_data) { + struct pic_internal * state = (struct pic_internal *)priv_data; uchar_t cw = *(uchar_t *)src; PrintDebug("8259 PIC: Write slave port 2 with 0x%x\n",cw); @@ -673,8 +673,8 @@ static int write_slave_port2(struct guest_info * core, ushort_t port, void * src -static int read_elcr_port(struct guest_info * core, ushort_t port, void * dst, uint_t length, struct vm_device * dev) { - struct pic_internal * state = (struct pic_internal*)dev->private_data; +static int read_elcr_port(struct guest_info * core, ushort_t port, void * dst, uint_t length, void * priv_data) { + struct pic_internal * state = (struct pic_internal *)priv_data; if (length != 1) { PrintError("ELCR read of invalid length %d\n", length); @@ -695,8 +695,8 @@ static int read_elcr_port(struct guest_info * core, ushort_t port, void * dst, u } -static int write_elcr_port(struct guest_info * core, ushort_t port, void * src, uint_t length, struct vm_device * dev) { - struct pic_internal * state = (struct pic_internal*)dev->private_data; +static int write_elcr_port(struct guest_info * core, ushort_t port, void * src, uint_t length, void * priv_data) { + struct pic_internal * state = (struct pic_internal *)priv_data; if (length != 1) { PrintError("ELCR read of invalid length %d\n", length); @@ -722,10 +722,6 @@ static int write_elcr_port(struct guest_info * core, ushort_t port, void * src, static int pic_free(struct vm_device * dev) { - v3_dev_unhook_io(dev, MASTER_PORT1); - v3_dev_unhook_io(dev, MASTER_PORT2); - v3_dev_unhook_io(dev, SLAVE_PORT1); - v3_dev_unhook_io(dev, SLAVE_PORT2); return 0; } @@ -738,9 +734,7 @@ static int pic_free(struct vm_device * dev) { static struct v3_device_ops dev_ops = { .free = pic_free, - .reset = NULL, - .start = NULL, - .stop = NULL, + }; diff --git a/palacios/src/devices/apic.c b/palacios/src/devices/apic.c index 1827366..91c6824 100644 --- a/palacios/src/devices/apic.c +++ b/palacios/src/devices/apic.c @@ -33,14 +33,14 @@ #endif #ifdef CONFIG_DEBUG_APIC -static char *shorthand_str[] = { +static char * shorthand_str[] = { "(no shorthand)", "(self)", "(all)", "(all-but-me)", }; -static char *deliverymode_str[] = { +static char * deliverymode_str[] = { "(fixed)", "(lowest priority)", "(SMI)", @@ -1290,9 +1290,8 @@ static int apic_get_intr_number(struct guest_info * core, void * private_data) { } -int v3_apic_send_ipi(struct v3_vm_info * vm, struct vm_device * dev, - struct v3_gen_ipi * ipi) { - struct apic_dev_state * apic_dev = (struct apic_dev_state *)(dev->private_data); +int v3_apic_send_ipi(struct v3_vm_info * vm, struct v3_gen_ipi * ipi, void * dev_data) { + struct apic_dev_state * apic_dev = (struct apic_dev_state *)dev_data; struct int_cmd_reg tmp_icr; // zero out all the fields @@ -1311,9 +1310,8 @@ int v3_apic_send_ipi(struct v3_vm_info * vm, struct vm_device * dev, } -int v3_apic_raise_intr(struct v3_vm_info * vm, struct vm_device * dev, - uint32_t irq, uint32_t dst) { - struct apic_dev_state * apic_dev = (struct apic_dev_state *)(dev->private_data); +int v3_apic_raise_intr(struct v3_vm_info * vm, uint32_t irq, uint32_t dst, void * dev_data) { + struct apic_dev_state * apic_dev = (struct apic_dev_state *)(dev_data); struct apic_state * apic = &(apic_dev->apics[dst]); PrintDebug("apic %u core ?: raising interrupt IRQ %u (dst = %u).\n", apic->lapic_id.val, irq, dst); @@ -1492,9 +1490,6 @@ static int apic_free(struct vm_device * dev) { static struct v3_device_ops dev_ops = { .free = apic_free, - .reset = NULL, - .start = NULL, - .stop = NULL, }; diff --git a/palacios/src/devices/ata.h b/palacios/src/devices/ata.h index cb0193e..423679e 100644 --- a/palacios/src/devices/ata.h +++ b/palacios/src/devices/ata.h @@ -106,7 +106,7 @@ static void ata_identify_device(struct ide_drive * drive) { } -static int ata_read(struct vm_device * dev, struct ide_channel * channel, uint8_t * dst, uint_t sect_cnt) { +static int ata_read(struct ide_internal * ide, struct ide_channel * channel, uint8_t * dst, uint_t sect_cnt) { struct ide_drive * drive = get_selected_drive(channel); if (drive->hd_state.accessed == 0) { @@ -130,7 +130,7 @@ static int ata_read(struct vm_device * dev, struct ide_channel * channel, uint8_ } -static int ata_write(struct vm_device * dev, struct ide_channel * channel, uint8_t * src, uint_t sect_cnt) { +static int ata_write(struct ide_internal * ide, struct ide_channel * channel, uint8_t * src, uint_t sect_cnt) { struct ide_drive * drive = get_selected_drive(channel); PrintDebug("Writing Drive LBA=%d (count=%d)\n", (uint32_t)(drive->current_lba), sect_cnt); @@ -147,7 +147,7 @@ static int ata_write(struct vm_device * dev, struct ide_channel * channel, uint8 -static int ata_get_lba(struct vm_device * dev, struct ide_channel * channel, uint64_t * lba) { +static int ata_get_lba(struct ide_internal * ide, struct ide_channel * channel, uint64_t * lba) { struct ide_drive * drive = get_selected_drive(channel); // The if the sector count == 0 then read 256 sectors (cast up to handle that value) uint32_t sect_cnt = (drive->sector_count == 0) ? 256 : drive->sector_count; @@ -185,18 +185,18 @@ static int ata_get_lba(struct vm_device * dev, struct ide_channel * channel, uin // 28 bit LBA -static int ata_read_sectors(struct vm_device * dev, struct ide_channel * channel) { +static int ata_read_sectors(struct ide_internal * ide, struct ide_channel * channel) { struct ide_drive * drive = get_selected_drive(channel); // The if the sector count == 0 then read 256 sectors (cast up to handle that value) uint32_t sect_cnt = (drive->sector_count == 0) ? 256 : drive->sector_count; - if (ata_get_lba(dev, channel, &(drive->current_lba)) == -1) { - ide_abort_command(dev, channel); + if (ata_get_lba(ide, channel, &(drive->current_lba)) == -1) { + ide_abort_command(ide, channel); return 0; } - if (ata_read(dev, channel, drive->data_buf, 1) == -1) { + if (ata_read(ide, channel, drive->data_buf, 1) == -1) { PrintError("Could not read disk sector\n"); return -1; } @@ -215,7 +215,7 @@ static int ata_read_sectors(struct vm_device * dev, struct ide_channel * channel drive->irq_flags.rel = 0; - ide_raise_irq(dev, channel); + ide_raise_irq(ide, channel); PrintDebug("Returning from read sectors\n"); @@ -224,7 +224,7 @@ static int ata_read_sectors(struct vm_device * dev, struct ide_channel * channel // 48 bit LBA -static int ata_read_sectors_ext(struct vm_device * dev, struct ide_channel * channel) { +static int ata_read_sectors_ext(struct ide_internal * ide, struct ide_channel * channel) { //struct ide_drive * drive = get_selected_drive(channel); // The if the sector count == 0 then read 256 sectors (cast up to handle that value) //uint32_t sector_count = (drive->sector_count == 0) ? 256 : drive->sector_count; diff --git a/palacios/src/devices/atapi.h b/palacios/src/devices/atapi.h index 15e8eec..c889248 100644 --- a/palacios/src/devices/atapi.h +++ b/palacios/src/devices/atapi.h @@ -27,7 +27,7 @@ * however the device can change that value * */ -static int atapi_update_req_len(struct vm_device * dev, struct ide_channel * channel, uint_t xfer_len) { +static int atapi_update_req_len(struct ide_internal * ide, struct ide_channel * channel, uint_t xfer_len) { struct ide_drive * drive = get_selected_drive(channel); // PrintDebug("Updating request length (pre=%d)\n", drive->req_len); @@ -63,7 +63,7 @@ static int atapi_update_req_len(struct vm_device * dev, struct ide_channel * cha // This is for simple commands that don't need to sanity check the req_len -static void atapi_setup_cmd_resp(struct vm_device * dev, struct ide_channel * channel, uint_t xfer_len) { +static void atapi_setup_cmd_resp(struct ide_internal * ide, struct ide_channel * channel, uint_t xfer_len) { struct ide_drive * drive = get_selected_drive(channel); drive->transfer_length = xfer_len; @@ -77,10 +77,10 @@ static void atapi_setup_cmd_resp(struct vm_device * dev, struct ide_channel * ch channel->status.data_req = 1; channel->status.error = 0; - ide_raise_irq(dev, channel); + ide_raise_irq(ide, channel); } -static void atapi_cmd_error(struct vm_device * dev, struct ide_channel * channel, +static void atapi_cmd_error(struct ide_internal * ide, struct ide_channel * channel, atapi_sense_key_t sense_key, atapi_add_sense_code_t asc) { struct ide_drive * drive = get_selected_drive(channel); @@ -104,11 +104,11 @@ static void atapi_cmd_error(struct vm_device * dev, struct ide_channel * channel drive->irq_flags.c_d = 1; drive->irq_flags.rel = 0; - ide_raise_irq(dev, channel); + ide_raise_irq(ide, channel); } -static void atapi_cmd_nop(struct vm_device * dev, struct ide_channel * channel) { +static void atapi_cmd_nop(struct ide_internal * ide, struct ide_channel * channel) { struct ide_drive * drive = get_selected_drive(channel); channel->status.busy = 0; @@ -120,12 +120,12 @@ static void atapi_cmd_nop(struct vm_device * dev, struct ide_channel * channel) drive->irq_flags.c_d = 1; drive->irq_flags.rel = 0; - ide_raise_irq(dev, channel); + ide_raise_irq(ide, channel); } -static int atapi_read_chunk(struct vm_device * dev, struct ide_channel * channel) { +static int atapi_read_chunk(struct ide_internal * ide, struct ide_channel * channel) { struct ide_drive * drive = get_selected_drive(channel); int ret = drive->ops->read(drive->data_buf, drive->current_lba * ATAPI_BLOCK_SIZE, ATAPI_BLOCK_SIZE, @@ -140,7 +140,7 @@ drive->private_data); } -static int atapi_update_data_buf(struct vm_device * dev, struct ide_channel * channel) { +static int atapi_update_data_buf(struct ide_internal * ide, struct ide_channel * channel) { struct ide_drive * drive = get_selected_drive(channel); switch (drive->cd_state.atapi_cmd) { @@ -151,7 +151,7 @@ static int atapi_update_data_buf(struct vm_device * dev, struct ide_channel * ch drive->current_lba++; // read the next block - return atapi_read_chunk(dev, channel); + return atapi_read_chunk(ide, channel); default: PrintError("Unhandled ATAPI command in update buffer %x\n", drive->cd_state.atapi_cmd); @@ -162,7 +162,7 @@ static int atapi_update_data_buf(struct vm_device * dev, struct ide_channel * ch } static int atapi_read10(struct guest_info * core, - struct vm_device * dev, + struct ide_internal * ide, struct ide_channel * channel) { struct ide_drive * drive = get_selected_drive(channel); struct atapi_read10_cmd * cmd = (struct atapi_read10_cmd *)(drive->data_buf); @@ -176,7 +176,7 @@ static int atapi_read10(struct guest_info * core, */ if (xfer_len == 0) { - atapi_cmd_nop(dev, channel); + atapi_cmd_nop(ide, channel); return 0; } @@ -184,8 +184,8 @@ static int atapi_read10(struct guest_info * core, PrintError("IDE: xfer len exceeded capacity (lba=%d) (xfer_len=%d) (ReadEnd=%d) (capacity=%d)\n", lba, xfer_len, lba + xfer_len, (uint32_t)drive->ops->get_capacity(drive->private_data)); - atapi_cmd_error(dev, channel, ATAPI_SEN_ILL_REQ, ASC_LOG_BLK_OOR); - ide_raise_irq(dev, channel); + atapi_cmd_error(ide, channel, ATAPI_SEN_ILL_REQ, ASC_LOG_BLK_OOR); + ide_raise_irq(ide, channel); return 0; } @@ -200,7 +200,7 @@ static int atapi_read10(struct guest_info * core, if (channel->features.dma) { if (channel->dma_status.active == 1) { - if (dma_read(core, dev, channel) == -1) { + if (dma_read(core, ide, channel) == -1) { PrintError("Error in DMA read for CD Read10 command\n"); return -1; } @@ -208,7 +208,7 @@ static int atapi_read10(struct guest_info * core, return 0; } - if (atapi_read_chunk(dev, channel) == -1) { + if (atapi_read_chunk(ide, channel) == -1) { PrintError("IDE: Could not read initial chunk from CD\n"); return -1; } @@ -216,29 +216,29 @@ static int atapi_read10(struct guest_info * core, // Length of ATAPI buffer sits in cylinder registers // This is weird... The host sets this value to say what it would like to transfer, // if it is larger than the correct size, the device shrinks it to the correct size - if (atapi_update_req_len(dev, channel, ATAPI_BLOCK_SIZE) == -1) { + if (atapi_update_req_len(ide, channel, ATAPI_BLOCK_SIZE) == -1) { PrintError("Could not update initial request length\n"); return -1; } - ide_raise_irq(dev, channel); + ide_raise_irq(ide, channel); return 0; } -static void atapi_req_sense(struct vm_device * dev, struct ide_channel * channel) { +static void atapi_req_sense(struct ide_internal * ide, struct ide_channel * channel) { struct ide_drive * drive = get_selected_drive(channel); memcpy(drive->data_buf, drive->cd_state.sense.buf, sizeof(drive->cd_state.sense.buf)); - atapi_setup_cmd_resp(dev, channel, 18); + atapi_setup_cmd_resp(ide, channel, 18); } -static int atapi_get_capacity(struct vm_device * dev, struct ide_channel * channel) { +static int atapi_get_capacity(struct ide_internal * ide, struct ide_channel * channel) { struct ide_drive * drive = get_selected_drive(channel); struct atapi_rd_capacity_resp * resp = (struct atapi_rd_capacity_resp *)(drive->data_buf); uint32_t capacity = drive->ops->get_capacity(drive->private_data); @@ -246,12 +246,12 @@ static int atapi_get_capacity(struct vm_device * dev, struct ide_channel * chann resp->lba = le_to_be_32(capacity); resp->block_len = le_to_be_32(ATAPI_BLOCK_SIZE); - atapi_setup_cmd_resp(dev, channel, sizeof(struct atapi_rd_capacity_resp)); + atapi_setup_cmd_resp(ide, channel, sizeof(struct atapi_rd_capacity_resp)); return 0; } -static int atapi_get_config(struct vm_device * dev, struct ide_channel * channel) { +static int atapi_get_config(struct ide_internal * ide, struct ide_channel * channel) { struct ide_drive * drive = get_selected_drive(channel); struct atapi_config_cmd * cmd = (struct atapi_config_cmd *)(drive->data_buf); uint16_t alloc_len = be_to_le_16(cmd->alloc_len); @@ -266,13 +266,13 @@ static int atapi_get_config(struct vm_device * dev, struct ide_channel * channel xfer_len = alloc_len; } - atapi_setup_cmd_resp(dev, channel, xfer_len); + atapi_setup_cmd_resp(ide, channel, xfer_len); return 0; } -static int atapi_read_toc(struct vm_device * dev, struct ide_channel * channel) { +static int atapi_read_toc(struct ide_internal * ide, struct ide_channel * channel) { struct ide_drive * drive = get_selected_drive(channel); struct atapi_rd_toc_cmd * cmd = (struct atapi_rd_toc_cmd *)(drive->data_buf); uint16_t alloc_len = be_to_le_16(cmd->alloc_len); @@ -295,7 +295,7 @@ static int atapi_read_toc(struct vm_device * dev, struct ide_channel * channel) xfer_len = alloc_len; } - atapi_setup_cmd_resp(dev, channel, xfer_len); + atapi_setup_cmd_resp(ide, channel, xfer_len); } else { PrintError("Unhandled Format (%d)\n", cmd->format); return -1; @@ -305,7 +305,7 @@ static int atapi_read_toc(struct vm_device * dev, struct ide_channel * channel) } -static int atapi_mode_sense_cur_values(struct vm_device * dev, struct ide_channel * channel, +static int atapi_mode_sense_cur_values(struct ide_internal * ide, struct ide_channel * channel, struct atapi_mode_sense_cmd * sense_cmd) { struct ide_drive * drive = get_selected_drive(channel); struct atapi_mode_sense_hdr * hdr = (struct atapi_mode_sense_hdr *)(drive->data_buf); @@ -367,8 +367,8 @@ static int atapi_mode_sense_cur_values(struct vm_device * dev, struct ide_channe case 0x3f: default: PrintError("ATAPI: Mode sense Page Code not supported (%x)\n", sense_cmd->page_code); - atapi_cmd_error(dev, channel, ATAPI_SEN_ILL_REQ, ASC_INV_CMD_FIELD); - ide_raise_irq(dev, channel); + atapi_cmd_error(ide, channel, ATAPI_SEN_ILL_REQ, ASC_INV_CMD_FIELD); + ide_raise_irq(ide, channel); return 0; } @@ -381,21 +381,21 @@ static int atapi_mode_sense_cur_values(struct vm_device * dev, struct ide_channe drive->transfer_length = (resp_len > alloc_len) ? alloc_len : resp_len; drive->transfer_index = 0; - atapi_update_req_len(dev, channel, drive->transfer_length); + atapi_update_req_len(ide, channel, drive->transfer_length); - ide_raise_irq(dev, channel); + ide_raise_irq(ide, channel); return 0; } -static int atapi_mode_sense(struct vm_device * dev, struct ide_channel * channel) { +static int atapi_mode_sense(struct ide_internal * ide, struct ide_channel * channel) { struct ide_drive * drive = get_selected_drive(channel); struct atapi_mode_sense_cmd * sense_cmd = (struct atapi_mode_sense_cmd *)(drive->data_buf); switch (sense_cmd->page_ctrl) { case 0x00: // Current values - return atapi_mode_sense_cur_values(dev, channel, sense_cmd); + return atapi_mode_sense_cur_values(ide, channel, sense_cmd); case 0x01: // Changeable values case 0x02: // default values case 0x03: // saved values @@ -407,7 +407,7 @@ static int atapi_mode_sense(struct vm_device * dev, struct ide_channel * channel } -static int atapi_inquiry(struct vm_device * dev, struct ide_channel * channel) { +static int atapi_inquiry(struct ide_internal * ide, struct ide_channel * channel) { struct ide_drive * drive = get_selected_drive(channel); struct atapi_inquiry_cmd * inquiry_cmd = (struct atapi_inquiry_cmd *)(drive->data_buf); uint16_t alloc_len = be_to_le_16(inquiry_cmd->alloc_len); @@ -433,7 +433,7 @@ static int atapi_inquiry(struct vm_device * dev, struct ide_channel * channel) { xfer_len = alloc_len; } - atapi_setup_cmd_resp(dev, channel, xfer_len); + atapi_setup_cmd_resp(ide, channel, xfer_len); return 0; } @@ -452,7 +452,7 @@ static int atapi_cmd_is_data_op(uint8_t cmd) { } -static int atapi_handle_packet(struct guest_info * core, struct vm_device * dev, struct ide_channel * channel) { +static int atapi_handle_packet(struct guest_info * core, struct ide_internal * ide, struct ide_channel * channel) { struct ide_drive * drive = get_selected_drive(channel); uint8_t cmd = drive->data_buf[0]; @@ -462,29 +462,29 @@ static int atapi_handle_packet(struct guest_info * core, struct vm_device * dev, switch (cmd) { case 0x00: // test unit ready - atapi_cmd_nop(dev, channel); + atapi_cmd_nop(ide, channel); /* if drive not ready: atapi_cmd_error(... ATAPI_SEN_NOT_RDY, ASC_MEDIA_NOT_PRESENT) */ break; case 0x03: // request sense - atapi_req_sense(dev, channel); + atapi_req_sense(ide, channel); break; case 0x1e: // lock door - atapi_cmd_nop(dev, channel); + atapi_cmd_nop(ide, channel); break; case 0x28: // read(10) - if (atapi_read10(core, dev, channel) == -1) { + if (atapi_read10(core, ide, channel) == -1) { PrintError("IDE: Error in ATAPI read (%x)\n", cmd); return -1; } break; case 0x5a: // mode sense - if (atapi_mode_sense(dev, channel) == -1) { + if (atapi_mode_sense(ide, channel) == -1) { PrintError("IDE: Error in ATAPI mode sense (%x)\n", cmd); return -1; } @@ -492,7 +492,7 @@ static int atapi_handle_packet(struct guest_info * core, struct vm_device * dev, case 0x25: // read cdrom capacity - if (atapi_get_capacity(dev, channel) == -1) { + if (atapi_get_capacity(ide, channel) == -1) { PrintError("IDE: Error getting CDROM capacity (%x)\n", cmd); return -1; } @@ -500,14 +500,14 @@ static int atapi_handle_packet(struct guest_info * core, struct vm_device * dev, case 0x43: // read TOC - if (atapi_read_toc(dev, channel) == -1) { + if (atapi_read_toc(ide, channel) == -1) { PrintError("IDE: Error getting CDROM TOC (%x)\n", cmd); return -1; } break; case 0x46: // get configuration - if (atapi_get_config(dev, channel) == -1) { + if (atapi_get_config(ide, channel) == -1) { PrintError("IDE: Error getting CDROM Configuration (%x)\n", cmd); return -1; } @@ -518,12 +518,12 @@ static int atapi_handle_packet(struct guest_info * core, struct vm_device * dev, case 0x51: // read disk info // no-op to keep the Linux CD-ROM driver happy PrintDebug("Error: Read disk info no-op to keep the Linux CD-ROM driver happy\n"); - atapi_cmd_error(dev, channel, ATAPI_SEN_ILL_REQ, ASC_INV_CMD_FIELD); - ide_raise_irq(dev, channel); + atapi_cmd_error(ide, channel, ATAPI_SEN_ILL_REQ, ASC_INV_CMD_FIELD); + ide_raise_irq(ide, channel); break; case 0x12: // inquiry - if (atapi_inquiry(dev, channel) == -1) { + if (atapi_inquiry(ide, channel) == -1) { PrintError("IDE: Error in ATAPI inquiry (%x)\n", cmd); return -1; } @@ -559,8 +559,8 @@ static int atapi_handle_packet(struct guest_info * core, struct vm_device * dev, default: PrintError("Unhandled ATAPI command %x\n", cmd); - atapi_cmd_error(dev, channel, ATAPI_SEN_ILL_REQ, ASC_INV_CMD_FIELD); - ide_raise_irq(dev, channel); + atapi_cmd_error(ide, channel, ATAPI_SEN_ILL_REQ, ASC_INV_CMD_FIELD); + ide_raise_irq(ide, channel); return -1; } diff --git a/palacios/src/devices/bochs_debug.c b/palacios/src/devices/bochs_debug.c index 42128b6..6631023 100644 --- a/palacios/src/devices/bochs_debug.c +++ b/palacios/src/devices/bochs_debug.c @@ -45,8 +45,7 @@ struct debug_state { }; static int handle_info_write(struct guest_info * core, ushort_t port, void * src, uint_t length, void * priv_data) { - struct vm_device * dev = priv_data; - struct debug_state * state = (struct debug_state *)dev->private_data; + struct debug_state * state = (struct debug_state *)priv_data; state->info_buf[state->info_offset++] = *(char*)src; @@ -61,8 +60,7 @@ static int handle_info_write(struct guest_info * core, ushort_t port, void * src static int handle_debug_write(struct guest_info * core, ushort_t port, void * src, uint_t length, void * priv_data) { - struct vm_device * dev = priv_data; - struct debug_state * state = (struct debug_state *)dev->private_data; + struct debug_state * state = (struct debug_state *)priv_data; state->debug_buf[state->debug_offset++] = *(char*)src; @@ -77,8 +75,7 @@ static int handle_debug_write(struct guest_info * core, ushort_t port, void * sr static int handle_console_write(struct guest_info * core, ushort_t port, void * src, uint_t length, void * priv_data) { - struct vm_device * dev = priv_data; - struct debug_state * state = (struct debug_state *)dev->private_data; + struct debug_state * state = (struct debug_state *)priv_data; state->cons_buf[state->cons_offset++] = *(char *)src; @@ -93,7 +90,6 @@ static int handle_console_write(struct guest_info * core, ushort_t port, void * static int handle_gen_write(struct guest_info * core, ushort_t port, void * src, uint_t length, void * priv_data) { - //struct vm_device * dev = priv_data; switch (length) { case 1: @@ -120,11 +116,6 @@ static int handle_gen_write(struct guest_info * core, ushort_t port, void * src, static int debug_free(struct vm_device * dev) { struct debug_state * state = dev->private_data; - v3_unhook_io_port(dev->vm, BOCHS_PORT1); - v3_unhook_io_port(dev->vm, BOCHS_PORT2); - v3_unhook_io_port(dev->vm, BOCHS_INFO_PORT); - v3_unhook_io_port(dev->vm, BOCHS_DEBUG_PORT); - V3_Free(state); return 0; @@ -167,11 +158,11 @@ static int debug_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { memset(state->cons_buf, 0, BUF_SIZE); - ret |= v3_hook_io_port(vm, BOCHS_PORT1, NULL, &handle_gen_write, dev); - ret |= v3_hook_io_port(vm, BOCHS_PORT2, NULL, &handle_gen_write, dev); - ret |= v3_hook_io_port(vm, BOCHS_INFO_PORT, NULL, &handle_info_write, dev); - ret |= v3_hook_io_port(vm, BOCHS_DEBUG_PORT, NULL, &handle_debug_write, dev); - ret |= v3_hook_io_port(vm, BOCHS_CONSOLE_PORT, NULL, &handle_console_write, dev); + ret |= v3_dev_hook_io(dev, BOCHS_PORT1, NULL, &handle_gen_write); + ret |= v3_dev_hook_io(dev, BOCHS_PORT2, NULL, &handle_gen_write); + ret |= v3_dev_hook_io(dev, BOCHS_INFO_PORT, NULL, &handle_info_write); + ret |= v3_dev_hook_io(dev, BOCHS_DEBUG_PORT, NULL, &handle_debug_write); + ret |= v3_dev_hook_io(dev, BOCHS_CONSOLE_PORT, NULL, &handle_console_write); if (ret != 0) { PrintError("Could not hook Bochs Debug IO Ports\n"); diff --git a/palacios/src/devices/cga.c b/palacios/src/devices/cga.c index 0e36c9c..665c455 100644 --- a/palacios/src/devices/cga.c +++ b/palacios/src/devices/cga.c @@ -151,8 +151,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 +166,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 +181,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,8 +260,7 @@ 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", @@ -282,7 +278,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; } @@ -313,7 +309,6 @@ 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; if (video_state->framebuf_pa) { V3_FreePages((void *)(video_state->framebuf_pa), (FRAMEBUF_SIZE / 4096)); @@ -321,50 +316,6 @@ static int free_device(struct vm_device * dev) { 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_Free(video_state); @@ -420,50 +371,50 @@ 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); + v3_dev_hook_io(dev, 0x3b0, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3b1, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3b2, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3b3, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3b4, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3b5, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3b6, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3b7, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3b8, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3b9, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3ba, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3bb, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3c0, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3c1, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3c2, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3c3, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3c4, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3c5, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3c6, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3c7, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3c8, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3c9, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3ca, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3cb, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3cc, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3cd, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3ce, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3cf, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3d0, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3d1, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3d2, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3d3, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3d4, &video_read_port, &crtc_index_write); + v3_dev_hook_io(dev, 0x3d5, &video_read_port, &crtc_data_write); + v3_dev_hook_io(dev, 0x3d6, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3d7, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3d8, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3d9, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3da, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3db, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3dc, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3dd, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3de, &video_read_port, &video_write_port); + v3_dev_hook_io(dev, 0x3df, &video_read_port, &video_write_port); return 0; diff --git a/palacios/src/devices/disk_model.c b/palacios/src/devices/disk_model.c index 4bc4433..49ee033 100644 --- a/palacios/src/devices/disk_model.c +++ b/palacios/src/devices/disk_model.c @@ -74,9 +74,6 @@ static struct v3_dev_blk_ops blk_ops = { static struct v3_device_ops dev_ops = { .free = model_free, - .reset = NULL, - .start = NULL, - .stop = NULL, }; diff --git a/palacios/src/devices/filedisk.c b/palacios/src/devices/filedisk.c index 928355a..c0122cd 100644 --- a/palacios/src/devices/filedisk.c +++ b/palacios/src/devices/filedisk.c @@ -122,9 +122,6 @@ static int disk_free(struct vm_device * dev) { static struct v3_device_ops dev_ops = { .free = disk_free, - .reset = NULL, - .start = NULL, - .stop = NULL, }; diff --git a/palacios/src/devices/generic.c b/palacios/src/devices/generic.c index ec78bb9..d01ce95 100644 --- a/palacios/src/devices/generic.c +++ b/palacios/src/devices/generic.c @@ -37,9 +37,6 @@ typedef enum {GENERIC_IGNORE, GENERIC_PRINT_AND_IGNORE} generic_mode_t; struct generic_internal { - struct list_head port_list; - uint_t num_port_ranges; - }; @@ -153,28 +150,9 @@ static int generic_read_port_ignore(struct guest_info * core, uint16_t port, voi static int generic_free(struct vm_device * dev) { struct generic_internal * state = (struct generic_internal *)(dev->private_data); - struct port_range * tmp; - struct port_range * cur; PrintDebug("generic: deinit_device\n"); - list_for_each_entry_safe(cur, tmp, &(state->port_list), range_link) { - uint_t i; - - PrintDebug("generic: unhooking ports 0x%x to 0x%x\n", - cur->start, cur->end); - - for (i = cur->start; i <= cur->end; i++) { - if (v3_unhook_io_port(dev->vm, i)) { - PrintDebug("generic: can't unhook port 0x%x (already unhooked?)\n", i); - } - } - - list_del(&(cur->range_link)); - state->num_port_ranges--; - V3_Free(cur); - } - V3_Free(state); return 0; } @@ -191,38 +169,29 @@ static struct v3_device_ops dev_ops = { static int add_port_range(struct vm_device * dev, uint_t start, uint_t end, generic_mode_t mode) { - struct generic_internal * state = (struct generic_internal *)(dev->private_data); - struct port_range * range = (struct port_range *)V3_Malloc(sizeof(struct port_range)); uint_t i = 0; - range->start = start; - range->end = end; - range->mode = mode; - PrintDebug("generic: Adding Port Range: 0x%x to 0x%x as %s\n", start, end, (mode == GENERIC_PRINT_AND_PASSTHROUGH) ? "print-and-passthrough" : "print-and-ignore"); for (i = start; i <= end; i++) { if (mode == GENERIC_PRINT_AND_PASSTHROUGH) { - if (v3_hook_io_port(dev->vm, i, + if (v3_dev_hook_io(dev, i, &generic_read_port_passthrough, - &generic_write_port_passthrough, dev) == -1) { + &generic_write_port_passthrough) == -1) { PrintError("generic: can't hook port 0x%x (already hooked?)\n", i); return -1; } } else if (mode == GENERIC_PRINT_AND_IGNORE) { - if (v3_hook_io_port(dev->vm, i, + if (v3_dev_hook_io(dev, i, &generic_read_port_ignore, - &generic_write_port_ignore, dev) == -1) { + &generic_write_port_ignore) == -1) { PrintError("generic: can't hook port 0x%x (already hooked?)\n", i); return -1; } } } - - list_add(&(range->range_link), &(state->port_list)); - state->num_port_ranges++; return 0; } @@ -245,9 +214,6 @@ static int generic_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { } memset(state, 0, sizeof(struct generic_internal)); - - INIT_LIST_HEAD(&(state->port_list)); - state->num_port_ranges = 0; struct vm_device * dev = v3_allocate_device(dev_id, &dev_ops, state); diff --git a/palacios/src/devices/i440fx.c b/palacios/src/devices/i440fx.c index 9b52eed..22f5c62 100644 --- a/palacios/src/devices/i440fx.c +++ b/palacios/src/devices/i440fx.c @@ -32,13 +32,11 @@ struct i440_state { static int io_read(struct guest_info * core, ushort_t port, void * dst, uint_t length, void * priv_data) { - // struct vm_device * dev = priv_data; PrintError("Unhandled read on port %x\n", port); return -1; } static int io_write(struct guest_info * core, ushort_t port, void * src, uint_t length, void * priv_data) { - // struct vm_device * dev = priv_data; PrintError("Unhandled write on port %x\n", port); return -1; } @@ -49,12 +47,6 @@ static int io_write(struct guest_info * core, ushort_t port, void * src, uint_t static int i440_free(struct vm_device * dev) { struct i440_state * state = dev->private_data; - int i; - - for (i = 0; i < 4; i++) { - v3_unhook_io_port(dev->vm, 0x0cf8 + i); - v3_unhook_io_port(dev->vm, 0x0cfc + i); - } // unregister from PCI @@ -65,9 +57,7 @@ static int i440_free(struct vm_device * dev) { static struct v3_device_ops dev_ops = { .free = i440_free, - .reset = NULL, - .start = NULL, - .stop = NULL, + }; @@ -99,8 +89,8 @@ static int i440_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { } for (i = 0; i < 4; i++) { - v3_hook_io_port(vm, 0x0cf8 + i, &io_read, &io_write, dev); - v3_hook_io_port(vm, 0x0cfc + i, &io_read, &io_write, dev); + v3_dev_hook_io(dev, 0x0cf8 + i, &io_read, &io_write); + v3_dev_hook_io(dev, 0x0cfc + i, &io_read, &io_write); } for (i = 0; i < 6; i++) { @@ -109,7 +99,7 @@ static int i440_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { pci_dev = v3_pci_register_device(state->pci, PCI_STD_DEVICE, 0, 0, 0, "i440FX", bars, - NULL, NULL, NULL, dev); + NULL, NULL, NULL, state); if (!pci_dev) { v3_detach_device(dev); diff --git a/palacios/src/devices/ide.c b/palacios/src/devices/ide.c index 8577e09..b13617d 100644 --- a/palacios/src/devices/ide.c +++ b/palacios/src/devices/ide.c @@ -221,6 +221,8 @@ struct ide_internal { struct vm_device * pci_bus; struct pci_device * ide_pci; + + struct v3_vm_info * vm; }; @@ -279,11 +281,11 @@ static inline int is_lba_enabled(struct ide_channel * channel) { /* Drive Commands */ -static void ide_raise_irq(struct vm_device * dev, struct ide_channel * channel) { +static void ide_raise_irq(struct ide_internal * ide, struct ide_channel * channel) { if (channel->ctrl_reg.irq_disable == 0) { // PrintError("Raising IDE Interrupt %d\n", channel->irq); channel->dma_status.int_gen = 1; - v3_raise_irq(dev->vm, channel->irq); + v3_raise_irq(ide->vm, channel->irq); } } @@ -335,16 +337,16 @@ static void channel_reset_complete(struct ide_channel * channel) { } -static void ide_abort_command(struct vm_device * dev, struct ide_channel * channel) { +static void ide_abort_command(struct ide_internal * ide, struct ide_channel * channel) { channel->status.val = 0x41; // Error + ready channel->error_reg.val = 0x04; // No idea... - ide_raise_irq(dev, channel); + ide_raise_irq(ide, channel); } -static int dma_read(struct guest_info * core, struct vm_device * dev, struct ide_channel * channel); -static int dma_write(struct guest_info * core, struct vm_device * dev, struct ide_channel * channel); +static int dma_read(struct guest_info * core, struct ide_internal * ide, struct ide_channel * channel); +static int dma_write(struct guest_info * core, struct ide_internal * ide, struct ide_channel * channel); /* ATAPI functions */ @@ -355,7 +357,7 @@ static int dma_write(struct guest_info * core, struct vm_device * dev, struct id #ifdef CONFIG_DEBUG_IDE -static void print_prd_table(struct vm_device * dev, struct ide_channel * channel) { +static void print_prd_table(struct ide_internal * ide, struct ide_channel * channel) { struct ide_dma_prd prd_entry; int index = 0; @@ -365,7 +367,7 @@ static void print_prd_table(struct vm_device * dev, struct ide_channel * channel uint32_t prd_entry_addr = channel->dma_prd_addr + (sizeof(struct ide_dma_prd) * index); int ret; - ret = v3_read_gpa_memory(&(dev->vm->cores[0]), prd_entry_addr, sizeof(struct ide_dma_prd), (void *)&prd_entry); + ret = v3_read_gpa_memory(&(ide->vm->cores[0]), prd_entry_addr, sizeof(struct ide_dma_prd), (void *)&prd_entry); if (ret != sizeof(struct ide_dma_prd)) { PrintError("Could not read PRD\n"); @@ -387,7 +389,7 @@ static void print_prd_table(struct vm_device * dev, struct ide_channel * channel #endif /* IO Operations */ -static int dma_read(struct guest_info * core, struct vm_device * dev, struct ide_channel * channel) { +static int dma_read(struct guest_info * core, struct ide_internal * ide, struct ide_channel * channel) { struct ide_drive * drive = get_selected_drive(channel); // This is at top level scope to do the EOT test at the end struct ide_dma_prd prd_entry = {}; @@ -397,7 +399,7 @@ static int dma_read(struct guest_info * core, struct vm_device * dev, struct ide // Read a sector/block at a time until the prd entry is full. #ifdef CONFIG_DEBUG_IDE - print_prd_table(dev, channel); + print_prd_table(ide, channel); #endif PrintDebug("DMA read for %d bytes\n", bytes_left); @@ -433,7 +435,7 @@ static int dma_read(struct guest_info * core, struct vm_device * dev, struct ide bytes_to_write = (prd_bytes_left > HD_SECTOR_SIZE) ? HD_SECTOR_SIZE : prd_bytes_left; - if (ata_read(dev, channel, drive->data_buf, 1) == -1) { + if (ata_read(ide, channel, drive->data_buf, 1) == -1) { PrintError("Failed to read next disk sector\n"); return -1; } @@ -441,7 +443,7 @@ static int dma_read(struct guest_info * core, struct vm_device * dev, struct ide if (atapi_cmd_is_data_op(drive->cd_state.atapi_cmd)) { bytes_to_write = (prd_bytes_left > ATAPI_BLOCK_SIZE) ? ATAPI_BLOCK_SIZE : prd_bytes_left; - if (atapi_read_chunk(dev, channel) == -1) { + if (atapi_read_chunk(ide, channel) == -1) { PrintError("Failed to read next disk sector\n"); return -1; } @@ -521,13 +523,13 @@ static int dma_read(struct guest_info * core, struct vm_device * dev, struct ide channel->dma_status.err = 0; } - ide_raise_irq(dev, channel); + ide_raise_irq(ide, channel); return 0; } -static int dma_write(struct guest_info * core, struct vm_device * dev, struct ide_channel * channel) { +static int dma_write(struct guest_info * core, struct ide_internal * ide, struct ide_channel * channel) { struct ide_drive * drive = get_selected_drive(channel); // This is at top level scope to do the EOT test at the end struct ide_dma_prd prd_entry = {}; @@ -574,7 +576,7 @@ static int dma_write(struct guest_info * core, struct vm_device * dev, struct id PrintDebug("\t DMA ret=%d (prd_bytes_left=%d) (bytes_left=%d)\n", ret, prd_bytes_left, bytes_left); - if (ata_write(dev, channel, drive->data_buf, 1) == -1) { + if (ata_write(ide, channel, drive->data_buf, 1) == -1) { PrintError("Failed to write data to disk\n"); return -1; } @@ -611,7 +613,7 @@ static int dma_write(struct guest_info * core, struct vm_device * dev, struct id channel->dma_status.err = 0; } - ide_raise_irq(dev, channel); + ide_raise_irq(ide, channel); return 0; } @@ -628,8 +630,7 @@ static int dma_write(struct guest_info * core, struct vm_device * dev, struct id #define DMA_CHANNEL_FLAG 0x08 static int write_dma_port(struct guest_info * core, ushort_t port, void * src, uint_t length, void * private_data) { - struct vm_device * dev = (struct vm_device *)private_data; - struct ide_internal * ide = (struct ide_internal *)(dev->private_data); + struct ide_internal * ide = (struct ide_internal *)private_data; uint16_t port_offset = port & (DMA_CHANNEL_FLAG - 1); uint_t channel_flag = (port & DMA_CHANNEL_FLAG) >> 3; struct ide_channel * channel = &(ide->channels[channel_flag]); @@ -648,13 +649,13 @@ static int write_dma_port(struct guest_info * core, ushort_t port, void * src, u if (channel->dma_cmd.read == 1) { // DMA Read - if (dma_read(core, dev, channel) == -1) { + if (dma_read(core, ide, channel) == -1) { PrintError("Failed DMA Read\n"); return -1; } } else { // DMA write - if (dma_write(core, dev, channel) == -1) { + if (dma_write(core, ide, channel) == -1) { PrintError("Failed DMA Write\n"); return -1; } @@ -711,8 +712,7 @@ static int write_dma_port(struct guest_info * core, ushort_t port, void * src, u static int read_dma_port(struct guest_info * core, ushort_t port, void * dst, uint_t length, void * private_data) { - struct vm_device * dev = (struct vm_device *)private_data; - struct ide_internal * ide = (struct ide_internal *)(dev->private_data); + struct ide_internal * ide = (struct ide_internal *)private_data; uint16_t port_offset = port & (DMA_CHANNEL_FLAG - 1); uint_t channel_flag = (port & DMA_CHANNEL_FLAG) >> 3; struct ide_channel * channel = &(ide->channels[channel_flag]); @@ -764,8 +764,8 @@ static int read_dma_port(struct guest_info * core, ushort_t port, void * dst, ui -static int write_cmd_port(struct guest_info * core, ushort_t port, void * src, uint_t length, struct vm_device * dev) { - struct ide_internal * ide = (struct ide_internal *)(dev->private_data); +static int write_cmd_port(struct guest_info * core, ushort_t port, void * src, uint_t length, void * priv_data) { + struct ide_internal * ide = priv_data; struct ide_channel * channel = get_selected_channel(ide, port); struct ide_drive * drive = get_selected_drive(channel); @@ -785,7 +785,7 @@ static int write_cmd_port(struct guest_info * core, ushort_t port, void * src, u drive_reset(drive); // JRL: Should we abort here? - ide_abort_command(dev, channel); + ide_abort_command(ide, channel); } else { atapi_identify_device(drive); @@ -793,7 +793,7 @@ static int write_cmd_port(struct guest_info * core, ushort_t port, void * src, u channel->error_reg.val = 0; channel->status.val = 0x58; // ready, data_req, seek_complete - ide_raise_irq(dev, channel); + ide_raise_irq(ide, channel); } break; case 0xec: // Identify Device @@ -801,20 +801,20 @@ static int write_cmd_port(struct guest_info * core, ushort_t port, void * src, u drive_reset(drive); // JRL: Should we abort here? - ide_abort_command(dev, channel); + ide_abort_command(ide, channel); } else { ata_identify_device(drive); channel->error_reg.val = 0; channel->status.val = 0x58; - ide_raise_irq(dev, channel); + ide_raise_irq(ide, channel); } break; case 0xa0: // ATAPI Command Packet if (drive->drive_type != BLOCK_CDROM) { - ide_abort_command(dev, channel); + ide_abort_command(ide, channel); } drive->sector_count = 1; @@ -834,7 +834,7 @@ static int write_cmd_port(struct guest_info * core, ushort_t port, void * src, u case 0x21: // Read Sectors without Retry drive->hd_state.cur_sector_num = 1; - if (ata_read_sectors(dev, channel) == -1) { + if (ata_read_sectors(ide, channel) == -1) { PrintError("Error reading sectors\n"); return -1; } @@ -843,7 +843,7 @@ static int write_cmd_port(struct guest_info * core, ushort_t port, void * src, u case 0x24: // Read Sectors Extended drive->hd_state.cur_sector_num = 1; - if (ata_read_sectors_ext(dev, channel) == -1) { + if (ata_read_sectors_ext(ide, channel) == -1) { PrintError("Error reading extended sectors\n"); return -1; } @@ -853,8 +853,8 @@ static int write_cmd_port(struct guest_info * core, ushort_t port, void * src, u case 0xc9: { // Read DMA uint32_t sect_cnt = (drive->sector_count == 0) ? 256 : drive->sector_count; - if (ata_get_lba(dev, channel, &(drive->current_lba)) == -1) { - ide_abort_command(dev, channel); + if (ata_get_lba(ide, channel, &(drive->current_lba)) == -1) { + ide_abort_command(ide, channel); return 0; } @@ -865,7 +865,7 @@ static int write_cmd_port(struct guest_info * core, ushort_t port, void * src, u if (channel->dma_status.active == 1) { // DMA Read - if (dma_read(core, dev, channel) == -1) { + if (dma_read(core, ide, channel) == -1) { PrintError("Failed DMA Read\n"); return -1; } @@ -876,8 +876,8 @@ static int write_cmd_port(struct guest_info * core, ushort_t port, void * src, u case 0xca: { // Write DMA uint32_t sect_cnt = (drive->sector_count == 0) ? 256 : drive->sector_count; - if (ata_get_lba(dev, channel, &(drive->current_lba)) == -1) { - ide_abort_command(dev, channel); + if (ata_get_lba(ide, channel, &(drive->current_lba)) == -1) { + ide_abort_command(ide, channel); return 0; } @@ -888,7 +888,7 @@ static int write_cmd_port(struct guest_info * core, ushort_t port, void * src, u if (channel->dma_status.active == 1) { // DMA Write - if (dma_write(core, dev, channel) == -1) { + if (dma_write(core, ide, channel) == -1) { PrintError("Failed DMA Write\n"); return -1; } @@ -907,7 +907,7 @@ static int write_cmd_port(struct guest_info * core, ushort_t port, void * src, u case 0x99: // Sleep Now 2 channel->status.val = 0; channel->status.ready = 1; - ide_raise_irq(dev, channel); + ide_raise_irq(ide, channel); break; case 0xef: // Set Features @@ -924,7 +924,7 @@ static int write_cmd_port(struct guest_info * core, ushort_t port, void * src, u channel->status.ready = 1; channel->status.seek_complete = 1; - ide_raise_irq(dev, channel); + ide_raise_irq(ide, channel); break; case 0x91: // Initialize Drive Parameters @@ -932,14 +932,14 @@ static int write_cmd_port(struct guest_info * core, ushort_t port, void * src, u channel->status.error = 0; channel->status.ready = 1; channel->status.seek_complete = 1; - ide_raise_irq(dev, channel); + ide_raise_irq(ide, channel); break; case 0xc6: { // Set multiple mode (IDE Block mode) // This makes the drive transfer multiple sectors before generating an interrupt uint32_t tmp_sect_num = drive->sector_num; // GCC SUCKS if (tmp_sect_num > MAX_MULT_SECTORS) { - ide_abort_command(dev, channel); + ide_abort_command(ide, channel); break; } @@ -952,7 +952,7 @@ static int write_cmd_port(struct guest_info * core, ushort_t port, void * src, u channel->status.ready = 1; channel->status.error = 0; - ide_raise_irq(dev, channel); + ide_raise_irq(ide, channel); break; } @@ -967,8 +967,8 @@ static int write_cmd_port(struct guest_info * core, ushort_t port, void * src, u } -static int write_data_port(struct guest_info * core, ushort_t port, void * src, uint_t length, struct vm_device * dev) { - struct ide_internal * ide = (struct ide_internal *)(dev->private_data); +static int write_data_port(struct guest_info * core, ushort_t port, void * src, uint_t length, void * priv_data) { + struct ide_internal * ide = priv_data; struct ide_channel * channel = get_selected_channel(ide, port); struct ide_drive * drive = get_selected_drive(channel); @@ -986,7 +986,7 @@ static int write_data_port(struct guest_info * core, ushort_t port, void * src, return -1; case 0xa0: // ATAPI packet command - if (atapi_handle_packet(core, dev, channel) == -1) { + if (atapi_handle_packet(core, ide, channel) == -1) { PrintError("Error handling ATAPI packet\n"); return -1; } @@ -1001,7 +1001,7 @@ static int write_data_port(struct guest_info * core, ushort_t port, void * src, } -static int read_hd_data(uint8_t * dst, uint_t length, struct vm_device * dev, struct ide_channel * channel) { +static int read_hd_data(uint8_t * dst, uint_t length, struct ide_internal * ide, struct ide_channel * channel) { struct ide_drive * drive = get_selected_drive(channel); int data_offset = drive->transfer_index % HD_SECTOR_SIZE; @@ -1018,7 +1018,7 @@ static int read_hd_data(uint8_t * dst, uint_t length, struct vm_device * dev, st if ((data_offset == 0) && (drive->transfer_index > 0)) { drive->current_lba++; - if (ata_read(dev, channel, drive->data_buf, 1) == -1) { + if (ata_read(ide, channel, drive->data_buf, 1) == -1) { PrintError("Could not read next disk sector\n"); return -1; } @@ -1062,7 +1062,7 @@ static int read_hd_data(uint8_t * dst, uint_t length, struct vm_device * dev, st drive->irq_flags.io_dir = 1; channel->status.busy = 0; - ide_raise_irq(dev, channel); + ide_raise_irq(ide, channel); } @@ -1071,7 +1071,7 @@ static int read_hd_data(uint8_t * dst, uint_t length, struct vm_device * dev, st -static int read_cd_data(uint8_t * dst, uint_t length, struct vm_device * dev, struct ide_channel * channel) { +static int read_cd_data(uint8_t * dst, uint_t length, struct ide_internal * ide, struct ide_channel * channel) { struct ide_drive * drive = get_selected_drive(channel); int data_offset = drive->transfer_index % ATAPI_BLOCK_SIZE; int req_offset = drive->transfer_index % drive->req_len; @@ -1089,7 +1089,7 @@ static int read_cd_data(uint8_t * dst, uint_t length, struct vm_device * dev, st if ((data_offset == 0) && (drive->transfer_index > 0)) { - if (atapi_update_data_buf(dev, channel) == -1) { + if (atapi_update_data_buf(ide, channel) == -1) { PrintError("Could not update CDROM data buffer\n"); return -1; } @@ -1110,7 +1110,7 @@ static int read_cd_data(uint8_t * dst, uint_t length, struct vm_device * dev, st drive->irq_flags.c_d = 0; // Update the request length in the cylinder regs - if (atapi_update_req_len(dev, channel, drive->transfer_length - drive->transfer_index) == -1) { + if (atapi_update_req_len(ide, channel, drive->transfer_length - drive->transfer_index) == -1) { PrintError("Could not update request length after completed increment\n"); return -1; } @@ -1126,14 +1126,14 @@ static int read_cd_data(uint8_t * dst, uint_t length, struct vm_device * dev, st drive->irq_flags.io_dir = 1; channel->status.busy = 0; - ide_raise_irq(dev, channel); + ide_raise_irq(ide, channel); } return length; } -static int read_drive_id( uint8_t * dst, uint_t length, struct vm_device * dev, struct ide_channel * channel) { +static int read_drive_id( uint8_t * dst, uint_t length, struct ide_internal * ide, struct ide_channel * channel) { struct ide_drive * drive = get_selected_drive(channel); channel->status.busy = 0; @@ -1155,8 +1155,8 @@ static int read_drive_id( uint8_t * dst, uint_t length, struct vm_device * dev, } -static int ide_read_data_port(struct guest_info * core, ushort_t port, void * dst, uint_t length, struct vm_device * dev) { - struct ide_internal * ide = (struct ide_internal *)(dev->private_data); +static int ide_read_data_port(struct guest_info * core, ushort_t port, void * dst, uint_t length, void * priv_data) { + struct ide_internal * ide = priv_data; struct ide_channel * channel = get_selected_channel(ide, port); struct ide_drive * drive = get_selected_drive(channel); @@ -1164,16 +1164,16 @@ static int ide_read_data_port(struct guest_info * core, ushort_t port, void * ds if ((channel->cmd_reg == 0xec) || (channel->cmd_reg == 0xa1)) { - return read_drive_id((uint8_t *)dst, length, dev, channel); + return read_drive_id((uint8_t *)dst, length, ide, channel); } if (drive->drive_type == BLOCK_CDROM) { - if (read_cd_data((uint8_t *)dst, length, dev, channel) == -1) { + if (read_cd_data((uint8_t *)dst, length, ide, channel) == -1) { PrintError("IDE: Could not read CD Data\n"); return -1; } } else if (drive->drive_type == BLOCK_DISK) { - if (read_hd_data((uint8_t *)dst, length, dev, channel) == -1) { + if (read_hd_data((uint8_t *)dst, length, ide, channel) == -1) { PrintError("IDE: Could not read HD Data\n"); return -1; } @@ -1184,8 +1184,8 @@ static int ide_read_data_port(struct guest_info * core, ushort_t port, void * ds return length; } -static int write_port_std(struct guest_info * core, ushort_t port, void * src, uint_t length, struct vm_device * dev) { - struct ide_internal * ide = (struct ide_internal *)(dev->private_data); +static int write_port_std(struct guest_info * core, ushort_t port, void * src, uint_t length, void * priv_data) { + struct ide_internal * ide = priv_data; struct ide_channel * channel = get_selected_channel(ide, port); struct ide_drive * drive = get_selected_drive(channel); @@ -1267,8 +1267,8 @@ static int write_port_std(struct guest_info * core, ushort_t port, void * src, u } -static int read_port_std(struct guest_info * core, ushort_t port, void * dst, uint_t length, struct vm_device * dev) { - struct ide_internal * ide = (struct ide_internal *)(dev->private_data); +static int read_port_std(struct guest_info * core, ushort_t port, void * dst, uint_t length, void * priv_data) { + struct ide_internal * ide = priv_data; struct ide_channel * channel = get_selected_channel(ide, port); struct ide_drive * drive = get_selected_drive(channel); @@ -1400,8 +1400,8 @@ static void init_channel(struct ide_channel * channel) { static int pci_config_update(uint_t reg_num, void * src, uint_t length, void * private_data) { PrintDebug("PCI Config Update\n"); - /* struct vm_device * dev = (struct vm_device *)private_data; - struct ide_internal * ide = (struct ide_internal *)(dev->private_data); + /* + struct ide_internal * ide = (struct ide_internal *)(private_data); PrintDebug("\t\tInterupt register (Dev=%s), irq=%d\n", ide->ide_pci->name, ide->ide_pci->config_header.intr_line); */ @@ -1409,8 +1409,7 @@ static int pci_config_update(uint_t reg_num, void * src, uint_t length, void * p return 0; } -static int init_ide_state(struct vm_device * dev) { - struct ide_internal * ide = (struct ide_internal *)(dev->private_data); +static int init_ide_state(struct ide_internal * ide) { int i; /* @@ -1537,6 +1536,7 @@ static int ide_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { memset(ide, 0, sizeof(struct ide_internal)); + ide->vm = vm; ide->pci_bus = v3_find_dev(vm, v3_cfg_val(cfg, "bus")); @@ -1563,7 +1563,7 @@ static int ide_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { return -1; } - if (init_ide_state(dev) == -1) { + if (init_ide_state(ide) == -1) { PrintError("Failed to initialize IDE state\n"); v3_detach_device(dev); return -1; @@ -1642,11 +1642,11 @@ static int ide_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { bars[4].io_read = read_dma_port; bars[4].io_write = write_dma_port; - bars[4].private_data = dev; + bars[4].private_data = ide; pci_dev = v3_pci_register_device(ide->pci_bus, PCI_STD_DEVICE, 0, sb_pci->dev_num, 1, "PIIX3_IDE", bars, - pci_config_update, NULL, NULL, dev); + pci_config_update, NULL, NULL, ide); if (pci_dev == NULL) { PrintError("Failed to register IDE BUS %d with PCI\n", i); @@ -1693,10 +1693,10 @@ device_register("IDE", ide_init) -int v3_ide_get_geometry(struct vm_device * ide_dev, int channel_num, int drive_num, +int v3_ide_get_geometry(void * ide_data, int channel_num, int drive_num, uint32_t * cylinders, uint32_t * heads, uint32_t * sectors) { - struct ide_internal * ide = (struct ide_internal *)(ide_dev->private_data); + struct ide_internal * ide = ide_data; struct ide_channel * channel = &(ide->channels[channel_num]); struct ide_drive * drive = &(channel->drives[drive_num]); diff --git a/palacios/src/devices/io_apic.c b/palacios/src/devices/io_apic.c index 35187af..757e96e 100644 --- a/palacios/src/devices/io_apic.c +++ b/palacios/src/devices/io_apic.c @@ -135,7 +135,7 @@ struct io_apic_state { struct redir_tbl_entry redir_tbl[24]; - struct vm_device * apic_dev; + void * apic_dev_data; }; @@ -162,8 +162,7 @@ static void init_ioapic_state(struct io_apic_state * ioapic, uint32_t id) { static int ioapic_read(struct guest_info * core, addr_t guest_addr, void * dst, uint_t length, void * priv_data) { - struct vm_device * dev = (struct vm_device *)priv_data; - struct io_apic_state * ioapic = (struct io_apic_state *)(dev->private_data); + struct io_apic_state * ioapic = (struct io_apic_state *)(priv_data); uint32_t reg_tgt = guest_addr - ioapic->base_addr; uint32_t * op_val = (uint32_t *)dst; @@ -208,8 +207,7 @@ static int ioapic_read(struct guest_info * core, addr_t guest_addr, void * dst, static int ioapic_write(struct guest_info * core, addr_t guest_addr, void * src, uint_t length, void * priv_data) { - struct vm_device * dev = (struct vm_device *)priv_data; - struct io_apic_state * ioapic = (struct io_apic_state *)(dev->private_data); + struct io_apic_state * ioapic = (struct io_apic_state *)(priv_data); uint32_t reg_tgt = guest_addr - ioapic->base_addr; uint32_t op_val = *(uint32_t *)src; @@ -262,8 +260,7 @@ static int ioapic_write(struct guest_info * core, addr_t guest_addr, void * src, static int ioapic_raise_irq(struct v3_vm_info * vm, void * private_data, int irq) { - struct vm_device * dev = (struct vm_device *)private_data; - struct io_apic_state * ioapic = (struct io_apic_state *)(dev->private_data); + struct io_apic_state * ioapic = (struct io_apic_state *)(private_data); struct redir_tbl_entry * irq_entry = NULL; if (irq > 24) { @@ -288,7 +285,7 @@ static int ioapic_raise_irq(struct v3_vm_info * vm, void * private_data, int irq ipi.dst_shorthand = 0; // Need to add destination argument here... - if (v3_apic_send_ipi(vm, ioapic->apic_dev, &ipi) == -1) { + if (v3_apic_send_ipi(vm, &ipi, ioapic->apic_dev_data) == -1) { PrintError("Error sending IPI to apic %d\n", ipi.dst); return -1; } @@ -319,9 +316,7 @@ static int io_apic_free(struct vm_device * dev) { static struct v3_device_ops dev_ops = { .free = io_apic_free, - .reset = NULL, - .start = NULL, - .stop = NULL, + }; @@ -335,7 +330,7 @@ static int ioapic_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { struct io_apic_state * ioapic = (struct io_apic_state *)V3_Malloc(sizeof(struct io_apic_state)); - ioapic->apic_dev = apic_dev; + ioapic->apic_dev_data = apic_dev; struct vm_device * dev = v3_allocate_device(dev_id, &dev_ops, ioapic); @@ -346,12 +341,12 @@ static int ioapic_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { } - v3_register_intr_router(vm, &router_ops, dev); + v3_register_intr_router(vm, &router_ops, ioapic); - init_ioapic_state(ioapic,vm->num_cores); + init_ioapic_state(ioapic, vm->num_cores); v3_hook_full_mem(vm, V3_MEM_CORE_ANY, ioapic->base_addr, ioapic->base_addr + PAGE_SIZE_4KB, - ioapic_read, ioapic_write, dev); + ioapic_read, ioapic_write, ioapic); return 0; } diff --git a/palacios/src/devices/keyboard.c b/palacios/src/devices/keyboard.c index a3fda90..0483350 100644 --- a/palacios/src/devices/keyboard.c +++ b/palacios/src/devices/keyboard.c @@ -213,12 +213,13 @@ struct keyboard_internal { struct queue kbd_queue; struct queue mouse_queue; + struct v3_vm_info * vm; + v3_lock_t kb_lock; }; -static int update_kb_irq(struct vm_device * dev) { - struct keyboard_internal *state = (struct keyboard_internal *)(dev->private_data); +static int update_kb_irq(struct keyboard_internal * state) { int irq_num = 0; @@ -241,7 +242,7 @@ static int update_kb_irq(struct vm_device * dev) { state->status.out_buf_full = 1; if (state->cmd.irq_en == 1) { - v3_raise_irq(dev->vm, irq_num); + v3_raise_irq(state->vm, irq_num); } } @@ -255,8 +256,7 @@ static int update_kb_irq(struct vm_device * dev) { * If we keep reading an empty queue we return the last queue entry */ -static int push_to_output_queue(struct vm_device * dev, uint8_t value, uint8_t cmd, uint8_t mouse) { - struct keyboard_internal * state = (struct keyboard_internal *)(dev->private_data); +static int push_to_output_queue(struct keyboard_internal * state, uint8_t value, uint8_t cmd, uint8_t mouse) { struct queue * q = NULL; @@ -287,15 +287,14 @@ static int push_to_output_queue(struct vm_device * dev, uint8_t value, uint8_t c q->count++; - update_kb_irq(dev); + update_kb_irq(state); return 0; } -static int pull_from_output_queue(struct vm_device * dev, uint8_t * value) { - struct keyboard_internal * state = (struct keyboard_internal *)(dev->private_data); +static int pull_from_output_queue(struct keyboard_internal * state, uint8_t * value) { struct queue * q = NULL; if (state->kbd_queue.count > 0) { @@ -325,7 +324,7 @@ static int pull_from_output_queue(struct vm_device * dev, uint8_t * value) { PrintDebug("Read from Queue: %x\n", *value); PrintDebug("QStart=%d, QEnd=%d\n", q->start, q->end); - update_kb_irq(dev); + update_kb_irq(state); return 0; } @@ -339,8 +338,7 @@ static int pull_from_output_queue(struct vm_device * dev, uint8_t * value) { static int key_event_handler(struct v3_vm_info * vm, struct v3_keyboard_event * evt, void * private_data) { - struct vm_device * dev = (struct vm_device *)private_data; - struct keyboard_internal *state = (struct keyboard_internal *)(dev->private_data); + struct keyboard_internal * state = (struct keyboard_internal *)private_data; PrintDebug("keyboard: injected status 0x%x, and scancode 0x%x\n", evt->status, evt->scan_code); @@ -401,7 +399,7 @@ static int key_event_handler(struct v3_vm_info * vm, if ( (state->status.enabled == 1) // onboard is enabled && (state->cmd.disable == 0) ) { // keyboard is enabled - push_to_output_queue(dev, evt->scan_code, DATA, KEYBOARD); + push_to_output_queue(state, evt->scan_code, DATA, KEYBOARD); } v3_unlock_irqrestore(state->kb_lock, irq_state); @@ -413,22 +411,21 @@ static int key_event_handler(struct v3_vm_info * vm, static int mouse_event_handler(struct v3_vm_info * vm, struct v3_mouse_event * evt, void * private_data) { - struct vm_device * dev = (struct vm_device *)private_data; - struct keyboard_internal * state = (struct keyboard_internal *)(dev->private_data); + struct keyboard_internal * kbd = (struct keyboard_internal *)private_data; int ret = 0; PrintDebug("keyboard: injected mouse packet 0x %x %x %x\n", evt->data[0], evt->data[1], evt->data[2]); - addr_t irq_state = v3_lock_irqsave(state->kb_lock); + addr_t irq_state = v3_lock_irqsave(kbd->kb_lock); - switch (state->mouse_state) { + switch (kbd->mouse_state) { case STREAM: - if (state->cmd.mouse_disable == 0) { - push_to_output_queue(dev, evt->data[0], DATA, MOUSE); - push_to_output_queue(dev, evt->data[1], DATA, MOUSE); - push_to_output_queue(dev, evt->data[2], DATA, MOUSE); + if (kbd->cmd.mouse_disable == 0) { + push_to_output_queue(kbd, evt->data[0], DATA, MOUSE); + push_to_output_queue(kbd, evt->data[1], DATA, MOUSE); + push_to_output_queue(kbd, evt->data[2], DATA, MOUSE); } break; default: @@ -438,169 +435,123 @@ static int mouse_event_handler(struct v3_vm_info * vm, } - v3_unlock_irqrestore(state->kb_lock, irq_state); + v3_unlock_irqrestore(kbd->kb_lock, irq_state); return ret; } -static int keyboard_reset_device(struct vm_device * dev) { - struct keyboard_internal * data = (struct keyboard_internal *)(dev->private_data); - - memset(data, 0, sizeof(struct keyboard_internal)); - - data->state = NORMAL; - data->mouse_state = STREAM; - - - // PS2, keyboard+mouse enabled, generic translation - data->cmd.val = 0; - - data->cmd.irq_en = 1; - data->cmd.mouse_irq_en = 1; - data->cmd.self_test_ok = 1; - /** **/ - // buffers empty, no errors - data->status.val = 0; - data->status.self_test_ok = 1; // self-tests passed - data->status.enabled = 1;// keyboard ready - /** **/ - - data->output_byte = 0; // ? - data->input_byte = INPUT_RAM; // we have some - // also display=color, jumper 0, keyboard enabled - PrintDebug("keyboard: reset device\n"); - - return 0; -} - - -static int keyboard_start_device(struct vm_device * dev) { - PrintDebug("keyboard: start device\n"); - return 0; -} - - -static int keyboard_stop_device(struct vm_device * dev) { - PrintDebug("keyboard: stop device\n"); - return 0; -} - - - -static int mouse_write_output(struct vm_device * dev, uint8_t data) { - struct keyboard_internal * state = (struct keyboard_internal *)(dev->private_data); - - switch (state->mouse_state) { +static int mouse_write_output(struct keyboard_internal * kbd, uint8_t data) { + switch (kbd->mouse_state) { case NORMAL: switch (data) { case 0xff: //reset - if (state->mouse_enabled == 0) { - push_to_output_queue(dev, 0xfe, DATA, MOUSE) ; // no mouse! + if (kbd->mouse_enabled == 0) { + push_to_output_queue(kbd, 0xfe, DATA, MOUSE) ; // no mouse! } else { - push_to_output_queue(dev, MOUSE_ACK, DATA, MOUSE) ; - push_to_output_queue(dev, 0xaa, DATA, MOUSE) ; - push_to_output_queue(dev, 0x00, DATA, MOUSE) ; + push_to_output_queue(kbd, MOUSE_ACK, DATA, MOUSE) ; + push_to_output_queue(kbd, 0xaa, DATA, MOUSE) ; + push_to_output_queue(kbd, 0x00, DATA, MOUSE) ; } break; /* case 0xfe: //resend */ -/* PushToOutputQueue(dev, 0xfa, OVERWRITE, DATA, MOUSE) ; */ +/* PushToOutputQueue(kbd, 0xfa, OVERWRITE, DATA, MOUSE) ; */ /* PrintDebug(" mouse resend begins "); */ -/* state->mouse_done_after_ack = 0; */ -/* state->mouse_needs_ack = 0; */ -/* state->mouse_state = STREAM1; */ +/* kbd->mouse_done_after_ack = 0; */ +/* kbd->mouse_needs_ack = 0; */ +/* kbd->mouse_state = STREAM1; */ /* return 0; // not done */ /* break; */ case 0xf6: // set defaults - push_to_output_queue(dev, MOUSE_ACK, DATA, MOUSE) ; + push_to_output_queue(kbd, MOUSE_ACK, DATA, MOUSE) ; PrintDebug(" mouse set defaults "); break; case 0xf5: // disable data reporting - push_to_output_queue(dev, MOUSE_ACK, DATA, MOUSE) ; + push_to_output_queue(kbd, MOUSE_ACK, DATA, MOUSE) ; PrintDebug(" mouse disable data reporting "); break; case 0xf4: // enable data reporting - push_to_output_queue(dev, MOUSE_ACK, DATA, MOUSE) ; + push_to_output_queue(kbd, MOUSE_ACK, DATA, MOUSE) ; PrintDebug(" mouse enable data reporting "); break; case 0xf3: // set sample rate - push_to_output_queue(dev, MOUSE_ACK, DATA, MOUSE) ; - state->mouse_state = SAMPLE; + push_to_output_queue(kbd, MOUSE_ACK, DATA, MOUSE) ; + kbd->mouse_state = SAMPLE; PrintDebug(" mouse set sample rate begins "); break; case 0xf2: // get device id - push_to_output_queue(dev, MOUSE_ACK, DATA, MOUSE) ; - push_to_output_queue(dev, 0x0, DATA, MOUSE); + push_to_output_queue(kbd, MOUSE_ACK, DATA, MOUSE) ; + push_to_output_queue(kbd, 0x0, DATA, MOUSE); PrintDebug(" mouse get device id begins "); break; case 0xf0: // set remote mode - push_to_output_queue(dev, MOUSE_ACK, DATA, MOUSE) ; + push_to_output_queue(kbd, MOUSE_ACK, DATA, MOUSE) ; PrintDebug(" mouse set remote mode "); break; case 0xee: // set wrap mode - push_to_output_queue(dev, MOUSE_ACK, DATA, MOUSE) ; + push_to_output_queue(kbd, MOUSE_ACK, DATA, MOUSE) ; PrintError(" mouse set wrap mode (ignored) "); break; case 0xec: // reset wrap mode - push_to_output_queue(dev, MOUSE_ACK, DATA, MOUSE) ; + push_to_output_queue(kbd, MOUSE_ACK, DATA, MOUSE) ; PrintError(" mouse reset wrap mode (ignored) "); break; case 0xeb: // read data - push_to_output_queue(dev, MOUSE_ACK, DATA, MOUSE) ; + push_to_output_queue(kbd, MOUSE_ACK, DATA, MOUSE) ; PrintError(" mouse switch to wrap mode (ignored) "); break; case 0xea: // set stream mode - push_to_output_queue(dev, MOUSE_ACK, DATA, MOUSE) ; + push_to_output_queue(kbd, MOUSE_ACK, DATA, MOUSE) ; PrintDebug(" mouse set stream mode "); break; case 0xe9: // status request - push_to_output_queue(dev, MOUSE_ACK, DATA, MOUSE) ; - push_to_output_queue(dev, 0x00, DATA, MOUSE); - push_to_output_queue(dev, 0x00, DATA, MOUSE); - push_to_output_queue(dev, 0x00, DATA, MOUSE); + push_to_output_queue(kbd, MOUSE_ACK, DATA, MOUSE) ; + push_to_output_queue(kbd, 0x00, DATA, MOUSE); + push_to_output_queue(kbd, 0x00, DATA, MOUSE); + push_to_output_queue(kbd, 0x00, DATA, MOUSE); PrintDebug(" mouse status request begins "); break; case 0xe8: // set resolution - push_to_output_queue(dev, MOUSE_ACK, DATA, MOUSE) ; + push_to_output_queue(kbd, MOUSE_ACK, DATA, MOUSE) ; PrintDebug(" mouse set resolution begins "); - state->mouse_state = SET_RES; + kbd->mouse_state = SET_RES; break; case 0xe7: // set scaling 2:1 - push_to_output_queue(dev, MOUSE_ACK, DATA, MOUSE) ; + push_to_output_queue(kbd, MOUSE_ACK, DATA, MOUSE) ; PrintDebug(" mouse set scaling 2:1 "); break; case 0xe6: // set scaling 1:1 - push_to_output_queue(dev, MOUSE_ACK, DATA, MOUSE) ; + push_to_output_queue(kbd, MOUSE_ACK, DATA, MOUSE) ; PrintDebug(" mouse set scaling 1:1 "); break; default: - PrintDebug(" receiving unknown mouse command (0x%x) in acceptable state ", data); + PrintDebug(" receiving unknown mouse command (0x%x) in acceptable kbd ", data); break; } @@ -608,7 +559,7 @@ static int mouse_write_output(struct vm_device * dev, uint8_t data) { case SAMPLE: case SET_RES: default: - PrintDebug(" receiving mouse output in unhandled state (0x%x) ", state->mouse_state); + PrintDebug(" receiving mouse output in unhandled kbd (0x%x) ", kbd->mouse_state); return -1; } @@ -618,7 +569,7 @@ static int mouse_write_output(struct vm_device * dev, uint8_t data) { #if KEYBOARD_DEBUG_80H -static int keyboard_write_delay(ushort_t port, void * src, uint_t length, struct vm_device * dev) { +static int keyboard_write_delay(ushort_t port, void * src, uint_t length, void * priv_data) { if (length == 1) { PrintDebug("keyboard: write of 0x%x to 80h\n", *((uint8_t*)src)); @@ -629,7 +580,7 @@ static int keyboard_write_delay(ushort_t port, void * src, uint_t length, struc } } -static int keyboard_read_delay(struct guest_info * core, ushort_t port, void * dest, uint_t length, struct vm_device * dev) { +static int keyboard_read_delay(struct guest_info * core, ushort_t port, void * dest, uint_t length, void * priv_data) { if (length == 1) { *(uint8_t *)dest = v3_inb(port); @@ -649,8 +600,8 @@ static int keyboard_read_delay(struct guest_info * core, ushort_t port, void * d -static int keyboard_write_command(struct guest_info * core, ushort_t port, void * src, uint_t length, struct vm_device * dev) { - struct keyboard_internal * state = (struct keyboard_internal *)(dev->private_data); +static int keyboard_write_command(struct guest_info * core, ushort_t port, void * src, uint_t length, void * priv_data) { + struct keyboard_internal * kbd = priv_data; uint8_t cmd = *(uint8_t *)src; // Should always be single byte write @@ -660,9 +611,9 @@ static int keyboard_write_command(struct guest_info * core, ushort_t port, void } - addr_t irq_state = v3_lock_irqsave(state->kb_lock); + addr_t irq_state = v3_lock_irqsave(kbd->kb_lock); - if (state->state != NORMAL) { + if (kbd->state != NORMAL) { PrintDebug("keyboard: warning - receiving command on 64h but state != NORMAL\n"); } @@ -670,30 +621,30 @@ static int keyboard_write_command(struct guest_info * core, ushort_t port, void switch (cmd) { case 0x20: // READ COMMAND BYTE (returned in 60h) - push_to_output_queue(dev, state->cmd.val, COMMAND, KEYBOARD); - PrintDebug("keyboard: command byte 0x%x returned\n", state->cmd.val); + push_to_output_queue(kbd, kbd->cmd.val, COMMAND, KEYBOARD); + PrintDebug("keyboard: command byte 0x%x returned\n", kbd->cmd.val); break; case 0x60: // WRITE COMMAND BYTE (read from 60h) - state->state = WRITING_CMD_BYTE; // we need to make sure we send the next 0x60 byte appropriately + kbd->state = WRITING_CMD_BYTE; // we need to make sure we send the next 0x60 byte appropriately PrintDebug("keyboard: prepare to write command byte\n"); break; // case 0x90-9f - write to output port (?) case 0xa1: // Get version number - push_to_output_queue(dev, 0x00, COMMAND, KEYBOARD); + push_to_output_queue(kbd, 0x00, COMMAND, KEYBOARD); PrintDebug("keyboard: version number 0x0 returned\n"); break; case 0xa4: // is password installed? send result to 0x60 // we don't support passwords - push_to_output_queue(dev, 0xf1, COMMAND, KEYBOARD); + push_to_output_queue(kbd, 0xf1, COMMAND, KEYBOARD); PrintDebug("keyboard: password not installed\n"); break; case 0xa5: // new password will arrive on 0x60 - state->state = TRANSMIT_PASSWD; + kbd->state = TRANSMIT_PASSWD; PrintDebug("keyboard: pepare to transmit password\n"); break; @@ -705,90 +656,90 @@ static int keyboard_write_command(struct guest_info * core, ushort_t port, void break; case 0xa7: // disable mouse - state->cmd.mouse_disable = 1; + kbd->cmd.mouse_disable = 1; PrintDebug("keyboard: mouse disabled\n"); break; case 0xa8: // enable mouse - state->cmd.mouse_disable = 0; + kbd->cmd.mouse_disable = 0; PrintDebug("keyboard: mouse enabled\n"); break; case 0xa9: // mouse interface test (always succeeds) - push_to_output_queue(dev, 0x00, COMMAND, KEYBOARD); + push_to_output_queue(kbd, 0x00, COMMAND, KEYBOARD); PrintDebug("keyboard: mouse interface test succeeded\n"); break; case 0xaa: // controller self test (always succeeds) - push_to_output_queue(dev, 0x55, COMMAND, KEYBOARD); + push_to_output_queue(kbd, 0x55, COMMAND, KEYBOARD); PrintDebug("keyboard: controller self test succeeded\n"); break; case 0xab: // keyboard interface test (always succeeds) - push_to_output_queue(dev, 0, COMMAND, KEYBOARD); + push_to_output_queue(kbd, 0, COMMAND, KEYBOARD); PrintDebug("keyboard: keyboard interface test succeeded\n"); break; case 0xad: // disable keyboard - state->cmd.disable = 1; + kbd->cmd.disable = 1; PrintDebug("keyboard: keyboard disabled\n"); break; case 0xae: // enable keyboard - state->cmd.disable = 0; + kbd->cmd.disable = 0; PrintDebug("keyboard: keyboard enabled\n"); break; case 0xaf: // get version - push_to_output_queue(dev, 0x00, COMMAND, KEYBOARD); + push_to_output_queue(kbd, 0x00, COMMAND, KEYBOARD); PrintDebug("keyboard: version 0 returned \n"); break; case 0xd0: // return microcontroller output on 60h - push_to_output_queue(dev, state->output_byte, COMMAND, KEYBOARD); - PrintDebug("keyboard: output byte 0x%x returned\n", state->output_byte); + push_to_output_queue(kbd, kbd->output_byte, COMMAND, KEYBOARD); + PrintDebug("keyboard: output byte 0x%x returned\n", kbd->output_byte); break; case 0xd1: // request to write next byte on 60h to the microcontroller output port - state->state = WRITING_OUTPUT_PORT; + kbd->state = WRITING_OUTPUT_PORT; PrintDebug("keyboard: prepare to write output byte\n"); break; case 0xd2: // write keyboard buffer (inject key) - state->state = INJECTING_KEY; + kbd->state = INJECTING_KEY; PrintDebug("keyboard: prepare to inject key\n"); break; case 0xd3: // write mouse buffer (inject mouse) - state->state = INJECTING_MOUSE; + kbd->state = INJECTING_MOUSE; PrintDebug("keyboard: prepare to inject mouse\n"); break; case 0xd4: // write mouse device (command to mouse?) - state->state = IN_MOUSE; + kbd->state = IN_MOUSE; PrintDebug("keyboard: prepare to inject mouse command\n"); break; case 0xc0: // read input port - push_to_output_queue(dev, state->input_byte, COMMAND, KEYBOARD); - PrintDebug("keyboard: input byte 0x%x returned\n", state->input_byte); + push_to_output_queue(kbd, kbd->input_byte, COMMAND, KEYBOARD); + PrintDebug("keyboard: input byte 0x%x returned\n", kbd->input_byte); break; case 0xc1: //copy input port lsn to status msn - state->status.val &= 0x0f; - state->status.val |= (state->input_byte & 0xf) << 4; + kbd->status.val &= 0x0f; + kbd->status.val |= (kbd->input_byte & 0xf) << 4; PrintDebug("keyboard: copied input byte low 4 bits to status reg hi 4 bits\n"); break; case 0xc2: // copy input port msn to status msn - state->status.val &= 0x0f; - state->status.val |= (state->input_byte & 0xf0); + kbd->status.val &= 0x0f; + kbd->status.val |= (kbd->input_byte & 0xf0); PrintDebug("keyboard: copied input byte hi 4 bits to status reg hi 4 bits\n"); break; case 0xe0: // read test port - push_to_output_queue(dev, state->output_byte >> 6, COMMAND, KEYBOARD); - PrintDebug("keyboard: read 0x%x from test port\n", state->output_byte >> 6); + push_to_output_queue(kbd, kbd->output_byte >> 6, COMMAND, KEYBOARD); + PrintDebug("keyboard: read 0x%x from test port\n", kbd->output_byte >> 6); break; @@ -817,13 +768,13 @@ static int keyboard_write_command(struct guest_info * core, ushort_t port, void break; } - v3_unlock_irqrestore(state->kb_lock, irq_state); + v3_unlock_irqrestore(kbd->kb_lock, irq_state); return length; } -static int keyboard_read_status(struct guest_info * core, ushort_t port, void * dest, uint_t length, struct vm_device * dev) { - struct keyboard_internal *state = (struct keyboard_internal *)(dev->private_data); +static int keyboard_read_status(struct guest_info * core, ushort_t port, void * dest, uint_t length, void * priv_data) { + struct keyboard_internal * kbd = priv_data; if (length != 1) { PrintError("keyboard: >1 byte read for status (64h)\n"); @@ -832,19 +783,19 @@ static int keyboard_read_status(struct guest_info * core, ushort_t port, void * PrintDebug("keyboard: read status (64h): "); - addr_t irq_state = v3_lock_irqsave(state->kb_lock); + addr_t irq_state = v3_lock_irqsave(kbd->kb_lock); - *(uint8_t *)dest = state->status.val; + *(uint8_t *)dest = kbd->status.val; - v3_unlock_irqrestore(state->kb_lock, irq_state); + v3_unlock_irqrestore(kbd->kb_lock, irq_state); PrintDebug("0x%x\n", *(uint8_t *)dest); return length; } -static int keyboard_write_output(struct guest_info * core, ushort_t port, void * src, uint_t length, struct vm_device * dev) { - struct keyboard_internal *state = (struct keyboard_internal *)(dev->private_data); +static int keyboard_write_output(struct guest_info * core, ushort_t port, void * src, uint_t length, void * priv_data) { + struct keyboard_internal * kbd = priv_data; int ret = length; if (length != 1) { @@ -856,38 +807,38 @@ static int keyboard_write_output(struct guest_info * core, ushort_t port, void * PrintDebug("keyboard: output 0x%x on 60h\n", data); - addr_t irq_state = v3_lock_irqsave(state->kb_lock); + addr_t irq_state = v3_lock_irqsave(kbd->kb_lock); - switch (state->state) { + switch (kbd->state) { case WRITING_CMD_BYTE: - state->cmd.val = data; - state->state = NORMAL; - PrintDebug("keyboard: wrote new command byte 0x%x\n", state->cmd.val); + kbd->cmd.val = data; + kbd->state = NORMAL; + PrintDebug("keyboard: wrote new command byte 0x%x\n", kbd->cmd.val); break; case WRITING_OUTPUT_PORT: - state->output_byte = data; - state->state = NORMAL; - PrintDebug("keyboard: wrote new output byte 0x%x\n", state->output_byte); + kbd->output_byte = data; + kbd->state = NORMAL; + PrintDebug("keyboard: wrote new output byte 0x%x\n", kbd->output_byte); break; case INJECTING_KEY: - push_to_output_queue(dev, data, COMMAND, KEYBOARD); // probably should be a call to deliver_key_to_vmm() - state->state = NORMAL; + push_to_output_queue(kbd, data, COMMAND, KEYBOARD); // probably should be a call to deliver_key_to_vmm() + kbd->state = NORMAL; PrintDebug("keyboard: injected key 0x%x\n", data); break; case INJECTING_MOUSE: - push_to_output_queue(dev, data, DATA, MOUSE); + push_to_output_queue(kbd, data, DATA, MOUSE); // PrintDebug("keyboard: ignoring injected mouse event 0x%x\n", data); PrintDebug("keyboard: injected mouse event 0x%x\n", data); - state->state = NORMAL; + kbd->state = NORMAL; break; case IN_MOUSE: PrintDebug("keyboard: mouse action: "); - if (mouse_write_output(dev, data)) { - state->state = NORMAL; + if (mouse_write_output(kbd, data)) { + kbd->state = NORMAL; } PrintDebug("\n"); break; @@ -898,21 +849,21 @@ static int keyboard_write_output(struct guest_info * core, ushort_t port, void * PrintDebug("keyboard: ignoring password character 0x%x\n",data); } else { // end of password - state->state = NORMAL; + kbd->state = NORMAL; PrintDebug("keyboard: done with password\n"); } break; case SET_LEDS: PrintDebug("Keyboard: LEDs being set...\n"); - push_to_output_queue(dev, 0xfa, COMMAND, KEYBOARD); - state->state = NORMAL; + push_to_output_queue(kbd, 0xfa, COMMAND, KEYBOARD); + kbd->state = NORMAL; break; case SET_RATE: PrintDebug("Keyboard: Rate being set...\n"); - push_to_output_queue(dev, 0xfa, COMMAND, KEYBOARD); - state->state = NORMAL; + push_to_output_queue(kbd, 0xfa, COMMAND, KEYBOARD); + kbd->state = NORMAL; break; default: @@ -920,38 +871,38 @@ static int keyboard_write_output(struct guest_info * core, ushort_t port, void * // command is being sent to keyboard controller switch (data) { case 0xff: // reset - push_to_output_queue(dev, 0xfa, COMMAND, KEYBOARD); // ack - push_to_output_queue(dev, 0xaa, COMMAND, KEYBOARD); + push_to_output_queue(kbd, 0xfa, COMMAND, KEYBOARD); // ack + push_to_output_queue(kbd, 0xaa, COMMAND, KEYBOARD); PrintDebug("keyboard: reset complete and acked\n"); break; case 0xf5: // disable scanning case 0xf4: // enable scanning // ack - push_to_output_queue(dev, 0xfa, COMMAND, KEYBOARD); + push_to_output_queue(kbd, 0xfa, COMMAND, KEYBOARD); // should do something here... PAD PrintDebug("keyboard: %s scanning done and acked\n", (data == 0xf5) ? "disable" : "enable"); break; case 0xf3: - push_to_output_queue(dev, 0xfa, COMMAND, KEYBOARD); - state->state = SET_RATE; + push_to_output_queue(kbd, 0xfa, COMMAND, KEYBOARD); + kbd->state = SET_RATE; break; case 0xf2: // get keyboard ID - push_to_output_queue(dev, 0xfa, COMMAND, KEYBOARD); - push_to_output_queue(dev, 0xab, COMMAND, KEYBOARD); - push_to_output_queue(dev, 0x83, COMMAND, KEYBOARD); + push_to_output_queue(kbd, 0xfa, COMMAND, KEYBOARD); + push_to_output_queue(kbd, 0xab, COMMAND, KEYBOARD); + push_to_output_queue(kbd, 0x83, COMMAND, KEYBOARD); PrintDebug("Keyboard: Requesting Keyboard ID\n"); break; case 0xed: // enable keyboard LEDs - push_to_output_queue(dev, 0xfa, COMMAND, KEYBOARD); - state->state = SET_LEDS; + push_to_output_queue(kbd, 0xfa, COMMAND, KEYBOARD); + kbd->state = SET_LEDS; break; case 0xee: // echo, used by FreeBSD to probe controller - push_to_output_queue(dev, 0xee, COMMAND, KEYBOARD); + push_to_output_queue(kbd, 0xee, COMMAND, KEYBOARD); break; case 0xfe: // resend @@ -969,7 +920,7 @@ static int keyboard_write_output(struct guest_info * core, ushort_t port, void * default: PrintError("keyboard: unhandled unknown command 0x%x on output buffer (60h)\n", data); - state->status.out_buf_full = 1; + kbd->status.out_buf_full = 1; ret = -1; break; } @@ -977,24 +928,24 @@ static int keyboard_write_output(struct guest_info * core, ushort_t port, void * } } - v3_unlock_irqrestore(state->kb_lock, irq_state); + v3_unlock_irqrestore(kbd->kb_lock, irq_state); return ret; } -static int keyboard_read_input(struct guest_info * core, ushort_t port, void * dest, uint_t length, struct vm_device * dev) { - struct keyboard_internal * state = (struct keyboard_internal *)(dev->private_data); +static int keyboard_read_input(struct guest_info * core, ushort_t port, void * dest, uint_t length, void * priv_data) { + struct keyboard_internal * kbd = priv_data; if (length != 1) { PrintError("keyboard: unknown size read from input (60h)\n"); return -1; } - addr_t irq_state = v3_lock_irqsave(state->kb_lock); + addr_t irq_state = v3_lock_irqsave(kbd->kb_lock); - pull_from_output_queue(dev, (uint8_t *)dest); + pull_from_output_queue(kbd, (uint8_t *)dest); - v3_unlock_irqrestore(state->kb_lock, irq_state); + v3_unlock_irqrestore(kbd->kb_lock, irq_state); PrintDebug("keyboard: read from input (60h): 0x%x\n", *(uint8_t *)dest); @@ -1007,70 +958,96 @@ static int keyboard_read_input(struct guest_info * core, ushort_t port, void * d static int keyboard_free(struct vm_device * dev) { - - v3_dev_unhook_io(dev, KEYBOARD_60H); - v3_dev_unhook_io(dev, KEYBOARD_64H); -#if KEYBOARD_DEBUG_80H - v3_dev_unhook_io(dev, KEYBOARD_DELAY_80H); -#endif - keyboard_reset_device(dev); + return 0; } +static int keyboard_reset_device(struct keyboard_internal * kbd) { + + + kbd->mouse_queue.start = 0; + kbd->mouse_queue.end = 0; + kbd->mouse_queue.count = 0; + + kbd->kbd_queue.start = 0; + kbd->kbd_queue.end = 0; + kbd->kbd_queue.count = 0; + + kbd->mouse_enabled = 0; + + kbd->state = NORMAL; + kbd->mouse_state = STREAM; + + // PS2, keyboard+mouse enabled, generic translation + kbd->cmd.val = 0; + + kbd->cmd.irq_en = 1; + kbd->cmd.mouse_irq_en = 1; + kbd->cmd.self_test_ok = 1; + /** **/ + + + // buffers empty, no errors + kbd->status.val = 0; + + kbd->status.self_test_ok = 1; // self-tests passed + kbd->status.enabled = 1;// keyboard ready + /** **/ + + + kbd->output_byte = 0; // ? + + kbd->input_byte = INPUT_RAM; // we have some + // also display=color, jumper 0, keyboard enabled + + PrintDebug("keyboard: reset device\n"); + + return 0; + +} static struct v3_device_ops dev_ops = { .free = keyboard_free, - .reset = keyboard_reset_device, - .start = keyboard_start_device, - .stop = keyboard_stop_device, + }; static int keyboard_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { - struct keyboard_internal * keyboard_state = NULL; + struct keyboard_internal * kbd = NULL; char * dev_id = v3_cfg_val(cfg, "ID"); PrintDebug("keyboard: init_device\n"); - keyboard_state = (struct keyboard_internal *)V3_Malloc(sizeof(struct keyboard_internal)); - - memset(keyboard_state, 0, sizeof(struct keyboard_internal)); + kbd = (struct keyboard_internal *)V3_Malloc(sizeof(struct keyboard_internal)); - keyboard_state->mouse_queue.start = 0; - keyboard_state->mouse_queue.end = 0; - keyboard_state->mouse_queue.count = 0; + memset(kbd, 0, sizeof(struct keyboard_internal)); - keyboard_state->kbd_queue.start = 0; - keyboard_state->kbd_queue.end = 0; - keyboard_state->kbd_queue.count = 0; + kbd->vm = vm; - keyboard_state->mouse_enabled = 0; - - struct vm_device * dev = v3_allocate_device(dev_id, &dev_ops, keyboard_state); + struct vm_device * dev = v3_allocate_device(dev_id, &dev_ops, kbd); if (v3_attach_device(vm, dev) == -1) { PrintError("Could not attach device %s\n", dev_id); return -1; } - - keyboard_reset_device(dev); + keyboard_reset_device(kbd); - v3_lock_init(&(keyboard_state->kb_lock)); + v3_lock_init(&(kbd->kb_lock)); // hook ports v3_dev_hook_io(dev, KEYBOARD_64H, &keyboard_read_status, &keyboard_write_command); v3_dev_hook_io(dev, KEYBOARD_60H, &keyboard_read_input, &keyboard_write_output); - v3_hook_host_event(vm, HOST_KEYBOARD_EVT, V3_HOST_EVENT_HANDLER(key_event_handler), dev); - v3_hook_host_event(vm, HOST_MOUSE_EVT, V3_HOST_EVENT_HANDLER(mouse_event_handler), dev); + v3_hook_host_event(vm, HOST_KEYBOARD_EVT, V3_HOST_EVENT_HANDLER(key_event_handler), kbd); + v3_hook_host_event(vm, HOST_MOUSE_EVT, V3_HOST_EVENT_HANDLER(mouse_event_handler), kbd); #if KEYBOARD_DEBUG_80H diff --git a/palacios/src/devices/lnx_virtio_balloon.c b/palacios/src/devices/lnx_virtio_balloon.c index de25807..a620308 100644 --- a/palacios/src/devices/lnx_virtio_balloon.c +++ b/palacios/src/devices/lnx_virtio_balloon.c @@ -81,8 +81,7 @@ static int virtio_free(struct vm_device * dev) { return -1; } -static int virtio_reset(struct vm_device * dev) { - struct virtio_balloon_state * virtio = (struct virtio_balloon_state *)dev->private_data; +static int virtio_reset(struct virtio_balloon_state * virtio) { memset(virtio->queue, 0, sizeof(struct virtio_queue) * 2); @@ -119,8 +118,7 @@ static int get_desc_count(struct virtio_queue * q, int index) { } -static int handle_kick(struct guest_info * core, struct vm_device * dev) { - struct virtio_balloon_state * virtio = (struct virtio_balloon_state *)dev->private_data; +static int handle_kick(struct guest_info * core, struct virtio_balloon_state * virtio) { struct virtio_queue * q = virtio->cur_queue; PrintDebug("VIRTIO BALLOON KICK: cur_index=%d (mod=%d), avail_index=%d\n", @@ -152,7 +150,7 @@ static int handle_kick(struct guest_info * core, struct vm_device * dev) { } /* - if (handle_balloon_op(dev, tmp_desc, buf_desc, status_desc) == -1) { + if (handle_balloon_op(virtio, tmp_desc, buf_desc, status_desc) == -1) { PrintError("Error handling balloon operation\n"); return -1; } @@ -184,8 +182,7 @@ static int handle_kick(struct guest_info * core, struct vm_device * dev) { } static int virtio_io_write(struct guest_info * core, uint16_t port, void * src, uint_t length, void * private_data) { - struct vm_device * dev = (struct vm_device *)private_data; - struct virtio_balloon_state * virtio = (struct virtio_balloon_state *)dev->private_data; + struct virtio_balloon_state * virtio = (struct virtio_balloon_state *)private_data; int port_idx = port % virtio->io_range_size; @@ -265,7 +262,7 @@ static int virtio_io_write(struct guest_info * core, uint16_t port, void * src, break; case VRING_Q_NOTIFY_PORT: PrintDebug("Handling Kick\n"); - if (handle_kick(core, dev) == -1) { + if (handle_kick(core, virtio) == -1) { PrintError("Could not handle Balloon Notification\n"); return -1; } @@ -275,7 +272,7 @@ static int virtio_io_write(struct guest_info * core, uint16_t port, void * src, if (virtio->virtio_cfg.status == 0) { PrintDebug("Resetting device\n"); - virtio_reset(dev); + virtio_reset(virtio); } break; @@ -293,8 +290,7 @@ static int virtio_io_write(struct guest_info * core, uint16_t port, void * src, static int virtio_io_read(struct guest_info * core, uint16_t port, void * dst, uint_t length, void * private_data) { - struct vm_device * dev = (struct vm_device *)private_data; - struct virtio_balloon_state * virtio = (struct virtio_balloon_state *)dev->private_data; + struct virtio_balloon_state * virtio = (struct virtio_balloon_state *)private_data; int port_idx = port % virtio->io_range_size; @@ -369,15 +365,11 @@ static int virtio_io_read(struct guest_info * core, uint16_t port, void * dst, u static struct v3_device_ops dev_ops = { .free = virtio_free, - .reset = NULL, - .start = NULL, - .stop = NULL, -}; +}; -static int set_size(struct vm_device * dev, addr_t size) { - struct virtio_balloon_state * virtio = (struct virtio_balloon_state *)dev->private_data; +static int set_size(struct virtio_balloon_state * virtio, addr_t size) { virtio->balloon_cfg.requested_pages = size / PAGE_SIZE; // number of pages PrintDebug("Requesting %d pages\n", virtio->balloon_cfg.requested_pages); @@ -390,18 +382,17 @@ static int set_size(struct vm_device * dev, addr_t size) { static int handle_hcall(struct guest_info * info, uint_t hcall_id, void * priv_data) { - struct vm_device * dev = (struct vm_device *)priv_data; + struct virtio_balloon_state * virtio = (struct virtio_balloon_state *)priv_data; int tgt_size = info->vm_regs.rcx; - return set_size(dev, tgt_size); + return set_size(virtio, tgt_size); } static int handle_query_hcall(struct guest_info * info, uint_t hcall_id, void * priv_data) { - struct vm_device * dev = (struct vm_device *)priv_data; - struct virtio_balloon_state * virtio = (struct virtio_balloon_state *)dev->private_data; + struct virtio_balloon_state * virtio = (struct virtio_balloon_state *)priv_data; info->vm_regs.rcx = virtio->balloon_cfg.requested_pages; info->vm_regs.rdx = virtio->balloon_cfg.allocated_pages; @@ -475,13 +466,13 @@ static int virtio_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { bars[0].io_read = virtio_io_read; bars[0].io_write = virtio_io_write; - bars[0].private_data = dev; + bars[0].private_data = virtio_state; pci_dev = v3_pci_register_device(pci_bus, PCI_STD_DEVICE, 0, PCI_AUTO_DEV_NUM, 0, "LNX_VIRTIO_BALLOON", bars, - NULL, NULL, NULL, dev); + NULL, NULL, NULL, virtio_state); if (!pci_dev) { PrintError("Could not register PCI Device\n"); @@ -508,10 +499,10 @@ static int virtio_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { virtio_state->pci_bus = pci_bus; } - virtio_reset(dev); + virtio_reset(virtio_state); - v3_register_hypercall(vm, BALLOON_START_HCALL, handle_hcall, dev); - v3_register_hypercall(vm, BALLOON_QUERY_HCALL, handle_query_hcall, dev); + v3_register_hypercall(vm, BALLOON_START_HCALL, handle_hcall, virtio_state); + v3_register_hypercall(vm, BALLOON_QUERY_HCALL, handle_query_hcall, virtio_state); return 0; } diff --git a/palacios/src/devices/lnx_virtio_blk.c b/palacios/src/devices/lnx_virtio_blk.c index ffb8c24..6cb8fa3 100644 --- a/palacios/src/devices/lnx_virtio_blk.c +++ b/palacios/src/devices/lnx_virtio_blk.c @@ -122,16 +122,7 @@ static int blk_reset(struct virtio_blk_state * virtio) { } -static int virtio_reset(struct vm_device * dev) { - struct virtio_dev_state * dev_state = (struct virtio_dev_state *)(dev->private_data); - struct virtio_blk_state * blk_state = NULL; - list_for_each_entry(blk_state, &(dev_state->dev_list), dev_link) { - blk_reset(blk_state); - } - - return 0; -} static int handle_read_op(struct virtio_blk_state * blk_state, uint8_t * buf, uint64_t * sector, uint64_t len) { int ret = -1; @@ -486,9 +477,7 @@ static int virtio_io_read(struct guest_info * core, uint16_t port, void * dst, u static struct v3_device_ops dev_ops = { .free = virtio_free, - .reset = virtio_reset, - .start = NULL, - .stop = NULL, + }; diff --git a/palacios/src/devices/lnx_virtio_nic.c b/palacios/src/devices/lnx_virtio_nic.c index a9825b9..ab9a78b 100644 --- a/palacios/src/devices/lnx_virtio_nic.c +++ b/palacios/src/devices/lnx_virtio_nic.c @@ -173,7 +173,7 @@ pkt_tx(struct guest_info * core, return -ERR_VIRTIO_OTHER; } - return virtio->net_ops->send(buf, len, virtio->backend_data, NULL); + return virtio->net_ops->send(buf, len, virtio->backend_data); } @@ -654,9 +654,6 @@ exit: static struct v3_device_ops dev_ops = { .free = virtio_free, - .reset = NULL, - .start = NULL, - .stop = NULL, }; diff --git a/palacios/src/devices/lnx_virtio_sym.c b/palacios/src/devices/lnx_virtio_sym.c index 6bd3ff4..b5ca9e8 100644 --- a/palacios/src/devices/lnx_virtio_sym.c +++ b/palacios/src/devices/lnx_virtio_sym.c @@ -342,9 +342,6 @@ static int virtio_io_read(struct guest_info * core, uint16_t port, void * dst, u static struct v3_device_ops dev_ops = { .free = NULL, - .reset = NULL, - .start = NULL, - .stop = NULL, }; @@ -409,12 +406,12 @@ static int virtio_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { bars[0].io_read = virtio_io_read; bars[0].io_write = virtio_io_write; - bars[0].private_data = dev; + bars[0].private_data = virtio_state; pci_dev = v3_pci_register_device(pci_bus, PCI_STD_DEVICE, 0, PCI_AUTO_DEV_NUM, 0, "LNX_VIRTIO_SYM", bars, - NULL, NULL, NULL, dev); + NULL, NULL, NULL, virtio_state); if (!pci_dev) { PrintError("Could not register PCI Device\n"); diff --git a/palacios/src/devices/lnx_virtio_symmod.c b/palacios/src/devices/lnx_virtio_symmod.c index 5a64335..09ec44c 100644 --- a/palacios/src/devices/lnx_virtio_symmod.c +++ b/palacios/src/devices/lnx_virtio_symmod.c @@ -588,13 +588,15 @@ static int virtio_load_capsule(struct v3_vm_info * vm, struct v3_sym_capsule * m } +static int virtio_free(struct vm_device * dev) +{ + + return 0; +} static struct v3_device_ops dev_ops = { - .free = NULL, - .reset = NULL, - .start = NULL, - .stop = NULL, + .free = virtio_free, }; diff --git a/palacios/src/devices/netdisk.c b/palacios/src/devices/netdisk.c index 479baeb..b2e76b1 100644 --- a/palacios/src/devices/netdisk.c +++ b/palacios/src/devices/netdisk.c @@ -216,9 +216,6 @@ static int disk_free(struct vm_device * dev) { static struct v3_device_ops dev_ops = { .free = disk_free, - .reset = NULL, - .start = NULL, - .stop = NULL, }; diff --git a/palacios/src/devices/nic_bridge.c b/palacios/src/devices/nic_bridge.c index eb5500b..b77e6e6 100644 --- a/palacios/src/devices/nic_bridge.c +++ b/palacios/src/devices/nic_bridge.c @@ -36,7 +36,7 @@ struct nic_bridge_state { }; static int bridge_send(uint8_t * buf, uint32_t len, - void * private_data, struct vm_device *dev){ + void * private_data) { //struct nic_bridge_state *bridge = (struct nic_bridge_state *)private_data; #ifdef CONFIG_DEBUG_NIC_BRIDGE @@ -49,17 +49,16 @@ static int bridge_send(uint8_t * buf, uint32_t len, return V3_send_raw(buf, len); } - -static int packet_input(struct v3_vm_info * vm, - struct v3_packet_event * evt, - void * private_data) { - struct nic_bridge_state *bridge = (struct nic_bridge_state *)private_data; - +static int packet_input(struct v3_vm_info * vm, + struct v3_packet_event * evt, + void * private_data) { + struct nic_bridge_state * bridge = (struct nic_bridge_state *)private_data; + PrintDebug("NIC_BRIDGE: Incoming packet size: %d\n", evt->size); return bridge->net_ops.recv(evt->pkt, - evt->size, - bridge->net_ops.frontend_data); + evt->size, + bridge->net_ops.frontend_data); } @@ -75,9 +74,7 @@ static int vnet_nic_free(struct vm_device * dev) { static struct v3_device_ops dev_ops = { .free = vnet_nic_free, - .reset = NULL, - .start = NULL, - .stop = NULL, + }; static int vnet_nic_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { @@ -109,7 +106,7 @@ static int vnet_nic_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { PrintDebug("NIC-Bridge: Connect %s to frontend %s\n", dev_id, v3_cfg_val(frontend_cfg, "tag")); - v3_hook_host_event(vm, HOST_PACKET_EVT, V3_HOST_EVENT_HANDLER(packet_input), dev); + v3_hook_host_event(vm, HOST_PACKET_EVT, V3_HOST_EVENT_HANDLER(packet_input), bridge); return 0; } diff --git a/palacios/src/devices/nvram.c b/palacios/src/devices/nvram.c index e2d1e05..e08d5d3 100644 --- a/palacios/src/devices/nvram.c +++ b/palacios/src/devices/nvram.c @@ -103,6 +103,8 @@ struct nvram_internal { struct vm_device * ide; + struct v3_vm_info * vm; + v3_lock_t nvram_lock; uint_t us; //microseconds - for clock update - zeroed every second @@ -270,8 +272,7 @@ static uchar_t days_in_month(uchar_t month, uchar_t bcd) { } -static void update_time( struct vm_device * dev, uint_t period_us) { - struct nvram_internal * data = (struct nvram_internal *) (dev->private_data); +static void update_time(struct nvram_internal * data, uint_t period_us) { struct rtc_stata * stata = (struct rtc_stata *) &((data->mem_state[NVRAM_REG_STAT_A])); struct rtc_statb * statb = (struct rtc_statb *) &((data->mem_state[NVRAM_REG_STAT_B])); struct rtc_statc * statc = (struct rtc_statc *) &((data->mem_state[NVRAM_REG_STAT_C])); @@ -452,7 +453,7 @@ static void update_time( struct vm_device * dev, uint_t period_us) { // Interrupt associated VM, if needed if (statc->irq) { PrintDebug("nvram: injecting interrupt\n"); - v3_raise_irq(dev->vm, NVRAM_RTC_IRQ); + v3_raise_irq(data->vm, NVRAM_RTC_IRQ); } } @@ -461,13 +462,12 @@ static int handle_timer_event(struct v3_vm_info * vm, struct v3_timer_event * evt, void * priv_data) { - struct vm_device * dev = (struct vm_device *)priv_data; - if (dev) { - struct nvram_internal * data = (struct nvram_internal *) (dev->private_data); - + struct nvram_internal * data = priv_data; + + if (data) { addr_t irq_state = v3_lock_irqsave(data->nvram_lock); - update_time(dev, evt->period_us); + update_time(data, evt->period_us); v3_unlock_irqrestore(data->nvram_lock, irq_state); } @@ -592,10 +592,8 @@ static void init_harddrives(struct nvram_internal * nvram) { } } -static int init_nvram_state(struct v3_vm_info * vm, struct vm_device * dev) { +static int init_nvram_state(struct v3_vm_info * vm, struct nvram_internal * nvram) { - struct nvram_internal * nvram = (struct nvram_internal *)dev->private_data; - memset(nvram->mem_state, 0, NVRAM_REG_MAX); memset(nvram->reg_map, 0, NVRAM_REG_MAX / 8); @@ -684,33 +682,12 @@ static int init_nvram_state(struct v3_vm_info * vm, struct vm_device * dev) { -static int nvram_reset_device(struct vm_device * dev) { - - return 0; -} - - - - - -static int nvram_start_device(struct vm_device * dev) { - PrintDebug("nvram: start device\n"); - return 0; -} - - -static int nvram_stop_device(struct vm_device * dev) { - PrintDebug("nvram: stop device\n"); - return 0; -} - - static int nvram_write_reg_port(struct guest_info * core, ushort_t port, - void * src, uint_t length, struct vm_device * dev) { + void * src, uint_t length, void * priv_data) { - struct nvram_internal * data = (struct nvram_internal *)dev->private_data; + struct nvram_internal * data = priv_data; memcpy(&(data->thereg), src, 1); PrintDebug("Writing To NVRAM reg: 0x%x\n", data->thereg); @@ -719,9 +696,9 @@ static int nvram_write_reg_port(struct guest_info * core, ushort_t port, } static int nvram_read_data_port(struct guest_info * core, ushort_t port, - void * dst, uint_t length, struct vm_device * dev) { + void * dst, uint_t length, void * priv_data) { - struct nvram_internal * data = (struct nvram_internal *)dev->private_data; + struct nvram_internal * data = priv_data; addr_t irq_state = v3_lock_irqsave(data->nvram_lock); @@ -747,9 +724,9 @@ static int nvram_read_data_port(struct guest_info * core, ushort_t port, static int nvram_write_data_port(struct guest_info * core, ushort_t port, - void * src, uint_t length, struct vm_device * dev) { + void * src, uint_t length, void * priv_data) { - struct nvram_internal * data = (struct nvram_internal *)dev->private_data; + struct nvram_internal * data = priv_data; addr_t irq_state = v3_lock_irqsave(data->nvram_lock); @@ -767,9 +744,6 @@ static int nvram_write_data_port(struct guest_info * core, ushort_t port, static int nvram_free(struct vm_device * dev) { - v3_dev_unhook_io(dev, NVRAM_REG_PORT); - v3_dev_unhook_io(dev, NVRAM_DATA_PORT); - return 0; } @@ -779,9 +753,6 @@ static int nvram_free(struct vm_device * dev) { static struct v3_device_ops dev_ops = { .free = nvram_free, - .reset = nvram_reset_device, - .start = nvram_start_device, - .stop = nvram_stop_device, }; @@ -804,6 +775,7 @@ static int nvram_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { PrintDebug("nvram: internal at %p\n", (void *)nvram_state); nvram_state->ide = ide; + nvram_state->vm = vm; struct vm_device * dev = v3_allocate_device(dev_id, &dev_ops, nvram_state); @@ -813,13 +785,13 @@ static int nvram_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { return -1; } - init_nvram_state(vm, dev); + init_nvram_state(vm, nvram_state); // hook ports v3_dev_hook_io(dev, NVRAM_REG_PORT, NULL, &nvram_write_reg_port); v3_dev_hook_io(dev, NVRAM_DATA_PORT, &nvram_read_data_port, &nvram_write_data_port); - v3_hook_host_event(vm, HOST_TIMER_EVT, V3_HOST_EVENT_HANDLER(handle_timer_event), dev); + v3_hook_host_event(vm, HOST_TIMER_EVT, V3_HOST_EVENT_HANDLER(handle_timer_event), nvram_state); return 0; } diff --git a/palacios/src/devices/os_debug.c b/palacios/src/devices/os_debug.c index 9e6ceba..e3fb734 100644 --- a/palacios/src/devices/os_debug.c +++ b/palacios/src/devices/os_debug.c @@ -34,8 +34,8 @@ struct debug_state { }; -static int handle_gen_write(struct guest_info * core, ushort_t port, void * src, uint_t length, struct vm_device * dev) { - struct debug_state * state = (struct debug_state *)dev->private_data; +static int handle_gen_write(struct guest_info * core, ushort_t port, void * src, uint_t length, void * priv_data) { + struct debug_state * state = priv_data; state->debug_buf[state->debug_offset++] = *(char*)src; @@ -49,8 +49,7 @@ static int handle_gen_write(struct guest_info * core, ushort_t port, void * src, } static int handle_hcall(struct guest_info * info, uint_t hcall_id, void * priv_data) { - struct vm_device * dev = (struct vm_device *)priv_data; - struct debug_state * state = (struct debug_state *)dev->private_data; + struct debug_state * state = (struct debug_state *)priv_data; int msg_len = info->vm_regs.rcx; addr_t msg_gpa = info->vm_regs.rbx; @@ -83,8 +82,6 @@ static int handle_hcall(struct guest_info * info, uint_t hcall_id, void * priv_d static int debug_free(struct vm_device * dev) { - v3_dev_unhook_io(dev, DEBUG_PORT1); - return 0; }; @@ -94,9 +91,6 @@ static int debug_free(struct vm_device * dev) { static struct v3_device_ops dev_ops = { .free = debug_free, - .reset = NULL, - .start = NULL, - .stop = NULL, }; @@ -119,7 +113,7 @@ static int debug_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { } v3_dev_hook_io(dev, DEBUG_PORT1, NULL, &handle_gen_write); - v3_register_hypercall(vm, OS_DEBUG_HCALL, handle_hcall, dev); + v3_register_hypercall(vm, OS_DEBUG_HCALL, handle_hcall, state); state->debug_offset = 0; memset(state->debug_buf, 0, BUF_SIZE); diff --git a/palacios/src/devices/pci.c b/palacios/src/devices/pci.c index 267eca1..b1f6b54 100644 --- a/palacios/src/devices/pci.c +++ b/palacios/src/devices/pci.c @@ -82,9 +82,9 @@ struct pci_bus { uint8_t dev_map[MAX_BUS_DEVICES / 8]; - int (*raise_pci_irq)(struct vm_device * dev, struct pci_device * pci_dev); - int (*lower_pci_irq)(struct vm_device * dev, struct pci_device * pci_dev); - struct vm_device * irq_bridge_dev; + int (*raise_pci_irq)(struct pci_device * pci_dev, void * dev_data); + int (*lower_pci_irq)(struct pci_device * pci_dev, void * dev_data); + void * irq_dev_data; }; @@ -228,8 +228,8 @@ static struct pci_device * get_device(struct pci_bus * bus, uint8_t dev_num, uin -static int addr_port_read(struct guest_info * core, ushort_t port, void * dst, uint_t length, struct vm_device * dev) { - struct pci_internal * pci_state = (struct pci_internal *)dev->private_data; +static int addr_port_read(struct guest_info * core, ushort_t port, void * dst, uint_t length, void * priv_data) { + struct pci_internal * pci_state = priv_data; int reg_offset = port & 0x3; uint8_t * reg_addr = ((uint8_t *)&(pci_state->addr_reg.val)) + reg_offset; @@ -259,8 +259,8 @@ static int addr_port_read(struct guest_info * core, ushort_t port, void * dst, u } -static int addr_port_write(struct guest_info * core, ushort_t port, void * src, uint_t length, struct vm_device * dev) { - struct pci_internal * pci_state = (struct pci_internal *)dev->private_data; +static int addr_port_write(struct guest_info * core, ushort_t port, void * src, uint_t length, void * priv_data) { + struct pci_internal * pci_state = priv_data; int reg_offset = port & 0x3; uint8_t * reg_addr = ((uint8_t *)&(pci_state->addr_reg.val)) + reg_offset; @@ -297,8 +297,8 @@ static int addr_port_write(struct guest_info * core, ushort_t port, void * src, } -static int data_port_read(struct guest_info * core, ushort_t port, void * dst, uint_t length, struct vm_device * vmdev) { - struct pci_internal * pci_state = (struct pci_internal *)(vmdev->private_data); +static int data_port_read(struct guest_info * core, ushort_t port, void * dst, uint_t length, void * priv_data) { + struct pci_internal * pci_state = priv_data; struct pci_device * pci_dev = NULL; uint_t reg_num = (pci_state->addr_reg.reg_num << 2) + (port & 0x3); int i; @@ -466,8 +466,8 @@ static int bar_update(struct guest_info * info, struct pci_device * pci, int bar } -static int data_port_write(struct guest_info * core, ushort_t port, void * src, uint_t length, struct vm_device * vmdev) { - struct pci_internal * pci_state = (struct pci_internal *)vmdev->private_data; +static int data_port_write(struct guest_info * core, ushort_t port, void * src, uint_t length, void * priv_data) { + struct pci_internal * pci_state = priv_data; struct pci_device * pci_dev = NULL; uint_t reg_num = (pci_state->addr_reg.reg_num << 2) + (port & 0x3); int i; @@ -597,32 +597,7 @@ static int data_port_write(struct guest_info * core, ushort_t port, void * src, -static int pci_reset_device(struct vm_device * dev) { - PrintDebug("pci: reset device\n"); - return 0; -} - - -static int pci_start_device(struct vm_device * dev) { - PrintDebug("pci: start device\n"); - return 0; -} - - -static int pci_stop_device(struct vm_device * dev) { - PrintDebug("pci: stop device\n"); - return 0; -} - - - static int pci_free(struct vm_device * dev) { - int i = 0; - - for (i = 0; i < 4; i++){ - v3_dev_unhook_io(dev, CONFIG_ADDR_PORT + i); - v3_dev_unhook_io(dev, CONFIG_DATA_PORT + i); - } return 0; } @@ -644,9 +619,7 @@ static void init_pci_busses(struct pci_internal * pci_state) { static struct v3_device_ops dev_ops = { .free = pci_free, - .reset = pci_reset_device, - .start = pci_start_device, - .stop = pci_stop_device, + }; @@ -774,15 +747,15 @@ static inline int init_bars(struct v3_vm_info * vm, struct pci_device * pci_dev) int v3_pci_set_irq_bridge(struct vm_device * pci_bus, int bus_num, - int (*raise_pci_irq)(struct vm_device * dev, struct pci_device * pci_dev), - int (*lower_pci_irq)(struct vm_device * dev, struct pci_device * pci_dev), - struct vm_device * bridge_dev) { + int (*raise_pci_irq)(struct pci_device * pci_dev, void * dev_data), + int (*lower_pci_irq)(struct pci_device * pci_dev, void * dev_data), + void * priv_data) { struct pci_internal * pci_state = (struct pci_internal *)pci_bus->private_data; pci_state->bus_list[bus_num].raise_pci_irq = raise_pci_irq; pci_state->bus_list[bus_num].lower_pci_irq = lower_pci_irq; - pci_state->bus_list[bus_num].irq_bridge_dev = bridge_dev; + pci_state->bus_list[bus_num].irq_dev_data = priv_data; return 0; } @@ -791,14 +764,14 @@ int v3_pci_raise_irq(struct vm_device * pci_bus, int bus_num, struct pci_device struct pci_internal * pci_state = (struct pci_internal *)pci_bus->private_data; struct pci_bus * bus = &(pci_state->bus_list[bus_num]); - return bus->raise_pci_irq(bus->irq_bridge_dev, dev); + return bus->raise_pci_irq(bus->irq_dev_data, dev); } int v3_pci_lower_irq(struct vm_device * pci_bus, int bus_num, struct pci_device * dev) { struct pci_internal * pci_state = (struct pci_internal *)pci_bus->private_data; struct pci_bus * bus = &(pci_state->bus_list[bus_num]); - return bus->lower_pci_irq(bus->irq_bridge_dev, dev); + return bus->lower_pci_irq(bus->irq_dev_data, dev); } // if dev_num == -1, auto assign diff --git a/palacios/src/devices/pci_passthrough.c b/palacios/src/devices/pci_passthrough.c index 8552112..2ace074 100644 --- a/palacios/src/devices/pci_passthrough.c +++ b/palacios/src/devices/pci_passthrough.c @@ -753,9 +753,6 @@ static int setup_virt_pci_dev(struct v3_vm_info * vm_info, struct vm_device * de static struct v3_device_ops dev_ops = { .free = NULL, - .reset = NULL, - .start = NULL, - .stop = NULL, }; diff --git a/palacios/src/devices/piix3.c b/palacios/src/devices/piix3.c index 89f021f..487a821 100644 --- a/palacios/src/devices/piix3.c +++ b/palacios/src/devices/piix3.c @@ -329,8 +329,7 @@ struct piix3_config_space { -static int reset_piix3(struct vm_device * dev) { - struct v3_southbridge * piix3 = (struct v3_southbridge *)(dev->private_data); +static int reset_piix3(struct v3_southbridge * piix3) { struct pci_device * pci_dev = piix3->southbridge_pci; struct piix3_config_space * piix3_cfg = (struct piix3_config_space *)(pci_dev->config_data); @@ -364,8 +363,8 @@ static int reset_piix3(struct vm_device * dev) { //irq is pirq_rc[intr_pin + pci_dev_num - 1] & 0x3 -static int raise_pci_irq(struct vm_device * dev, struct pci_device * pci_dev) { - struct v3_southbridge * piix3 = (struct v3_southbridge *)(dev->private_data); +static int raise_pci_irq(struct pci_device * pci_dev, void * dev_data) { + struct v3_southbridge * piix3 = dev_data; struct pci_device * piix3_pci = piix3->southbridge_pci; struct piix3_config_space * piix3_cfg = (struct piix3_config_space *)(piix3_pci->config_data); int intr_pin = pci_dev->config_header.intr_pin - 1; @@ -373,15 +372,15 @@ static int raise_pci_irq(struct vm_device * dev, struct pci_device * pci_dev) { // PrintError("Raising PCI IRQ %d\n", piix3_cfg->pirq_rc[irq_index]); - v3_raise_irq(dev->vm, piix3_cfg->pirq_rc[irq_index]); + v3_raise_irq(piix3->vm, piix3_cfg->pirq_rc[irq_index]); return 0; } -static int lower_pci_irq(struct vm_device * dev, struct pci_device * pci_dev) { - struct v3_southbridge * piix3 = (struct v3_southbridge *)(dev->private_data); +static int lower_pci_irq(struct pci_device * pci_dev, void * dev_data) { + struct v3_southbridge * piix3 = dev_data; struct pci_device * piix3_pci = piix3->southbridge_pci; struct piix3_config_space * piix3_cfg = (struct piix3_config_space *)(piix3_pci->config_data); int intr_pin = pci_dev->config_header.intr_pin - 1; @@ -389,7 +388,7 @@ static int lower_pci_irq(struct vm_device * dev, struct pci_device * pci_dev) { // PrintError("Lowering PCI IRQ %d\n", piix3_cfg->pirq_rc[irq_index]); - v3_lower_irq(dev->vm, piix3_cfg->pirq_rc[irq_index]); + v3_lower_irq(piix3->vm, piix3_cfg->pirq_rc[irq_index]); return 0; } @@ -403,16 +402,12 @@ static int piix_free(struct vm_device * dev) { static struct v3_device_ops dev_ops = { .free = piix_free, - .reset = reset_piix3, - .start = NULL, - .stop = NULL, }; -static int setup_pci(struct vm_device * dev) { - struct v3_southbridge * piix3 = (struct v3_southbridge *)(dev->private_data); +static int setup_pci(struct v3_southbridge * piix3) { struct pci_device * pci_dev = NULL; struct v3_pci_bar bars[6]; int i; @@ -425,7 +420,7 @@ static int setup_pci(struct vm_device * dev) { pci_dev = v3_pci_register_device(piix3->pci_bus, PCI_MULTIFUNCTION, bus_num, -1, 0, "PIIX3", bars, - NULL, NULL, NULL, dev); + NULL, NULL, NULL, piix3); if (pci_dev == NULL) { PrintError("Could not register PCI Device for PIIX3\n"); return -1; @@ -438,9 +433,9 @@ static int setup_pci(struct vm_device * dev) { piix3->southbridge_pci = pci_dev; - v3_pci_set_irq_bridge(piix3->pci_bus, bus_num, raise_pci_irq, lower_pci_irq, dev); + v3_pci_set_irq_bridge(piix3->pci_bus, bus_num, raise_pci_irq, lower_pci_irq, piix3); - reset_piix3(dev); + reset_piix3(piix3); return 0; } @@ -468,7 +463,7 @@ static int piix3_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { PrintDebug("Created PIIX3\n"); - return setup_pci(dev); + return setup_pci(piix3); } diff --git a/palacios/src/devices/ramdisk.c b/palacios/src/devices/ramdisk.c index fe45da0..e33c873 100644 --- a/palacios/src/devices/ramdisk.c +++ b/palacios/src/devices/ramdisk.c @@ -78,9 +78,6 @@ static int disk_free(struct vm_device * dev) { static struct v3_device_ops dev_ops = { .free = disk_free, - .reset = NULL, - .start = NULL, - .stop = NULL, }; diff --git a/palacios/src/devices/serial.c b/palacios/src/devices/serial.c index 5151ec2..1ca3f13 100644 --- a/palacios/src/devices/serial.c +++ b/palacios/src/devices/serial.c @@ -452,8 +452,8 @@ static int dequeue_data(struct v3_vm_info * vm, struct serial_port * com, } static int write_data_port(struct guest_info * core, uint16_t port, - void * src, uint_t length, struct vm_device * dev) { - struct serial_state * state = (struct serial_state *)dev->private_data; + void * src, uint_t length, void * priv_data) { + struct serial_state * state = priv_data; uint8_t * val = (uint8_t *)src; struct serial_port * com_port = NULL; @@ -498,8 +498,8 @@ static int write_data_port(struct guest_info * core, uint16_t port, static int read_data_port(struct guest_info * core, uint16_t port, - void * dst, uint_t length, struct vm_device * dev) { - struct serial_state * state = (struct serial_state *)dev->private_data; + void * dst, uint_t length, void * priv_data) { + struct serial_state * state = priv_data; uint8_t * val = (uint8_t *)dst; struct serial_port * com_port = NULL; @@ -581,8 +581,8 @@ static int handle_fcr_write(struct serial_port * com, uint8_t value) { static int write_ctrl_port(struct guest_info * core, uint16_t port, void * src, - uint_t length, struct vm_device * dev) { - struct serial_state * state = (struct serial_state *)dev->private_data; + uint_t length, void * priv_data) { + struct serial_state * state = priv_data; uint8_t val = *(uint8_t *)src; struct serial_port * com_port = NULL; @@ -665,8 +665,8 @@ static int write_ctrl_port(struct guest_info * core, uint16_t port, void * src, static int read_ctrl_port(struct guest_info * core, uint16_t port, void * dst, - uint_t length, struct vm_device * dev) { - struct serial_state * state = (struct serial_state *)dev->private_data; + uint_t length, void * priv_data) { + struct serial_state * state = priv_data; uint8_t * val = (uint8_t *)dst; struct serial_port * com_port = NULL; @@ -742,8 +742,8 @@ static int read_ctrl_port(struct guest_info * core, uint16_t port, void * dst, static int write_status_port(struct guest_info * core, uint16_t port, void * src, - uint_t length, struct vm_device * dev) { - struct serial_state * state = (struct serial_state *)dev->private_data; + uint_t length, void * priv_data) { + struct serial_state * state = priv_data; uint8_t val = *(uint8_t *)src; struct serial_port * com_port = NULL; @@ -787,8 +787,8 @@ static int write_status_port(struct guest_info * core, uint16_t port, void * src } static int read_status_port(struct guest_info * core, uint16_t port, void * dst, - uint_t length, struct vm_device * dev) { - struct serial_state * state = (struct serial_state *)dev->private_data; + uint_t length, void * priv_data) { + struct serial_state * state = priv_data; uint8_t * val = (uint8_t *)dst; struct serial_port * com_port = NULL; @@ -834,45 +834,7 @@ static int read_status_port(struct guest_info * core, uint16_t port, void * dst, return length; } -static int serial_deinit(struct vm_device * dev) { - - - v3_dev_unhook_io(dev, COM1_DATA_PORT); - v3_dev_unhook_io(dev, COM1_IRQ_ENABLE_PORT); - v3_dev_unhook_io(dev, COM1_FIFO_CTRL_PORT); - v3_dev_unhook_io(dev, COM1_LINE_CTRL_PORT); - v3_dev_unhook_io(dev, COM1_MODEM_CTRL_PORT); - v3_dev_unhook_io(dev, COM1_LINE_STATUS_PORT); - v3_dev_unhook_io(dev, COM1_MODEM_STATUS_PORT); - v3_dev_unhook_io(dev, COM1_SCRATCH_PORT); - - v3_dev_unhook_io(dev, COM2_DATA_PORT); - v3_dev_unhook_io(dev, COM2_IRQ_ENABLE_PORT); - v3_dev_unhook_io(dev, COM2_FIFO_CTRL_PORT); - v3_dev_unhook_io(dev, COM2_LINE_CTRL_PORT); - v3_dev_unhook_io(dev, COM2_MODEM_CTRL_PORT); - v3_dev_unhook_io(dev, COM2_LINE_STATUS_PORT); - v3_dev_unhook_io(dev, COM2_MODEM_STATUS_PORT); - v3_dev_unhook_io(dev, COM2_SCRATCH_PORT); - - v3_dev_unhook_io(dev, COM3_DATA_PORT); - v3_dev_unhook_io(dev, COM3_IRQ_ENABLE_PORT); - v3_dev_unhook_io(dev, COM3_FIFO_CTRL_PORT); - v3_dev_unhook_io(dev, COM3_LINE_CTRL_PORT); - v3_dev_unhook_io(dev, COM3_MODEM_CTRL_PORT); - v3_dev_unhook_io(dev, COM3_LINE_STATUS_PORT); - v3_dev_unhook_io(dev, COM3_MODEM_STATUS_PORT); - v3_dev_unhook_io(dev, COM3_SCRATCH_PORT); - - v3_dev_unhook_io(dev, COM4_DATA_PORT); - v3_dev_unhook_io(dev, COM4_IRQ_ENABLE_PORT); - v3_dev_unhook_io(dev, COM4_FIFO_CTRL_PORT); - v3_dev_unhook_io(dev, COM4_LINE_CTRL_PORT); - v3_dev_unhook_io(dev, COM4_MODEM_CTRL_PORT); - v3_dev_unhook_io(dev, COM4_LINE_STATUS_PORT); - v3_dev_unhook_io(dev, COM4_MODEM_STATUS_PORT); - v3_dev_unhook_io(dev, COM4_SCRATCH_PORT); - +static int serial_free(struct vm_device * dev) { return 0; } @@ -880,11 +842,7 @@ static int serial_deinit(struct vm_device * dev) { static struct v3_device_ops dev_ops = { - //.init = serial_init, - .free = serial_deinit, - .reset = NULL, - .start = NULL, - .stop = NULL, + .free = serial_free, }; diff --git a/palacios/src/devices/telnet_cons.c b/palacios/src/devices/telnet_cons.c index 00415c5..8c052b9 100644 --- a/palacios/src/devices/telnet_cons.c +++ b/palacios/src/devices/telnet_cons.c @@ -30,9 +30,7 @@ #include #include -#if 0 -#include -#endif + #define NUM_ROWS 25 #define NUM_COLS 80 @@ -59,6 +57,8 @@ struct cons_state { v3_lock_t cons_lock; + v3_vm_info * vm; + struct vm_device * frontend_dev; }; @@ -105,7 +105,7 @@ static const struct key_code ascii_to_key_code[] = { // ASCII Value -static int deliver_scan_code(struct vm_device * dev, struct key_code * key) { +static int deliver_scan_code(struct cons_state * state, struct key_code * key) { struct v3_keyboard_event key_event; struct v3_keyboard_event key_shift; uint_t cap = key->capital; @@ -120,14 +120,14 @@ static int deliver_scan_code(struct vm_device * dev, struct key_code * key) { key_shift.status = 0; key_shift.scan_code = (uint8_t)0x2A; - if (v3_deliver_keyboard_event(dev->vm, &key_shift) == -1) { + if (v3_deliver_keyboard_event(state->vm, &key_shift) == -1) { PrintError("Video: Error delivering key event\n"); return -1; } } // Press - if (v3_deliver_keyboard_event(dev->vm, &key_event) == -1) { + if (v3_deliver_keyboard_event(state->vm, &key_event) == -1) { PrintError("Video: Error delivering key event\n"); return -1; } @@ -135,7 +135,7 @@ static int deliver_scan_code(struct vm_device * dev, struct key_code * key) { // Release key_event.scan_code = key_event.scan_code | 0x80; - if (v3_deliver_keyboard_event(dev->vm, &key_event) == -1) { + if (v3_deliver_keyboard_event(state->vm, &key_event) == -1) { PrintError("Video: Error delivering key event\n"); return -1; } @@ -144,7 +144,7 @@ static int deliver_scan_code(struct vm_device * dev, struct key_code * key) { if (cap) { key_shift.scan_code = 0x2A | 0x80; - if (v3_deliver_keyboard_event(dev->vm, &key_shift) == -1) { + if (v3_deliver_keyboard_event(state->vm, &key_shift) == -1) { PrintError("Video: Error delivering key event\n"); return -1; } @@ -214,8 +214,7 @@ static const uint8_t bg_color_map[] = { } while (0) -static int send_update(struct vm_device * dev, uint8_t x, uint8_t y, uint8_t attrib, uint8_t val) { - struct cons_state * state = (struct cons_state *)dev->private_data; +static int send_update(struct cons_state * state, uint8_t x, uint8_t y, uint8_t attrib, uint8_t val) { uint8_t fg_color = fg_color_map[(attrib & 0x0f) % 16]; uint8_t bg_color = bg_color_map[(attrib & 0xf0) % 16]; uint8_t buf[32]; @@ -277,8 +276,7 @@ static int send_update(struct vm_device * dev, uint8_t x, uint8_t y, uint8_t a 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; + struct cons_state * state = (struct cons_state *)private_data; uint8_t buf[16]; int ret = 0; addr_t irq_state = 0; @@ -307,8 +305,7 @@ static int cursor_update(uint_t x, uint_t y, void * 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; + struct cons_state * state = (struct cons_state *)private_data; uint_t offset = (x * BYTES_PER_COL) + (y * BYTES_PER_ROW); uint8_t fb_buf[length]; int i = 0; @@ -337,7 +334,7 @@ static int screen_update(uint_t x, uint_t y, uint_t length, void * private_data) irq_state = v3_lock_irqsave(state->cons_lock); - if (send_update(dev, cur_x, cur_y, col[1], col[0]) == -1) { + if (send_update(state, cur_x, cur_y, col[1], col[0]) == -1) { PrintError("Could not send attribute to telnet session\n"); ret = -1; break; @@ -357,8 +354,7 @@ static int screen_update(uint_t x, uint_t y, uint_t length, void * private_data) } 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; + struct cons_state * state = (struct cons_state *)private_data; addr_t irq_state = 0; int ret = 0; @@ -396,26 +392,25 @@ static struct v3_console_ops cons_ops = { .scroll = scroll, }; +static int cons_free(struct vm_device * dev) { + return -1; +} + static struct v3_device_ops dev_ops = { - .free = NULL, - .reset = NULL, - .start = NULL, - .stop = NULL, + .free = cons_free, }; -static int key_handler(struct vm_device * dev, uint8_t ascii) { - struct cons_state * state = (struct cons_state *)dev->private_data; - +static int key_handler( struct cons_state * state, uint8_t ascii) { PrintDebug("Character recieved: 0x%x\n", ascii); // printable if (ascii < 0x80) { const struct key_code * key = &(ascii_to_key_code[ascii]); - if (deliver_scan_code(dev, (struct key_code *)key) == -1) { + if (deliver_scan_code(state, (struct key_code *)key) == -1) { PrintError("Could not deliver scan code to vm\n"); return -1; } @@ -445,16 +440,16 @@ static int key_handler(struct vm_device * dev, uint8_t ascii) { if (esc_seq[1] == 'A') { // UP ARROW struct key_code up = { 0x48, 0 }; - deliver_scan_code(dev, &up); + deliver_scan_code(state, &up); } else if (esc_seq[1] == 'B') { // DOWN ARROW struct key_code down = { 0x50, 0 }; - deliver_scan_code(dev, &down); + deliver_scan_code(state, &down); } else if (esc_seq[1] == 'C') { // RIGHT ARROW struct key_code right = { 0x4D, 0 }; - deliver_scan_code(dev, &right); + deliver_scan_code(state, &right); } else if (esc_seq[1] == 'D') { // LEFT ARROW struct key_code left = { 0x4B, 0 }; - deliver_scan_code(dev, &left); + deliver_scan_code(state, &left); } } else { PrintError("Invalid character received from network (%c) (code=%d)\n", @@ -466,8 +461,7 @@ static int key_handler(struct vm_device * dev, uint8_t ascii) { } static int cons_server(void * arg) { - struct vm_device * dev = (struct vm_device *)arg; - struct cons_state * state = (struct cons_state *)dev->private_data; + struct cons_state * state = (struct cons_state *)arg; state->server_fd = V3_Create_TCP_Socket(); @@ -494,7 +488,7 @@ static int cons_server(void * arg) { PrintDebug("Accepted Telnet Console connection\n"); state->connected = 1; - screen_update(0, 0, SCREEN_SIZE, dev); + screen_update(0, 0, SCREEN_SIZE, state); while (1) { recv = recv_all(state->client_fd, &ascii_code, sizeof(ascii_code)); @@ -509,7 +503,7 @@ static int cons_server(void * arg) { break; } - if (key_handler(dev, ascii_code) == -1) { + if (key_handler(state, ascii_code) == -1) { PrintError("Error in key handler\n"); break; } @@ -529,7 +523,7 @@ static int cons_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { struct vm_device * frontend = v3_find_dev(vm, v3_cfg_val(frontend_cfg, "tag")); char * dev_id = v3_cfg_val(cfg, "ID"); - + state->vm = vm; state->server_fd = 0; state->client_fd = 0; state->frontend_dev = frontend; @@ -545,9 +539,9 @@ static int cons_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { } - v3_console_register_cga(frontend, &cons_ops, dev); + v3_console_register_cga(frontend, &cons_ops, state); - V3_CREATE_THREAD(cons_server, dev, "Telnet Console Network Server"); + V3_CREATE_THREAD(cons_server, state, "Telnet Console Network Server"); return 0; } diff --git a/palacios/src/devices/tmpdisk.c b/palacios/src/devices/tmpdisk.c index bf582e7..450de53 100644 --- a/palacios/src/devices/tmpdisk.c +++ b/palacios/src/devices/tmpdisk.c @@ -88,9 +88,7 @@ static struct v3_dev_blk_ops blk_ops = { static struct v3_device_ops dev_ops = { .free = blk_free, - .reset = NULL, - .start = NULL, - .stop = NULL, + }; diff --git a/palacios/src/devices/vnet_nic.c b/palacios/src/devices/vnet_nic.c index 57904ba..dbebdaf 100644 --- a/palacios/src/devices/vnet_nic.c +++ b/palacios/src/devices/vnet_nic.c @@ -58,9 +58,8 @@ static void stop_rx(void * private_data){ /* called by frontend, send pkt to VNET */ static int vnet_nic_send(uint8_t * buf, uint32_t len, - void * private_data, - struct vm_device * dest_dev){ - struct vnet_nic_state *vnetnic = (struct vnet_nic_state *)private_data; + void * private_data) { + struct vnet_nic_state * vnetnic = (struct vnet_nic_state *)private_data; struct v3_vnet_pkt pkt; pkt.size = len; @@ -124,9 +123,7 @@ static int vnet_nic_free(struct vm_device * dev) { static struct v3_device_ops dev_ops = { .free = vnet_nic_free, - .reset = NULL, - .start = NULL, - .stop = NULL, + }; static struct v3_vnet_dev_ops vnet_dev_ops = { diff --git a/palacios/src/palacios/vmm_dev_mgr.c b/palacios/src/palacios/vmm_dev_mgr.c index cd6857d..5fafbdd 100644 --- a/palacios/src/palacios/vmm_dev_mgr.c +++ b/palacios/src/palacios/vmm_dev_mgr.c @@ -97,12 +97,12 @@ int v3_init_dev_mgr(struct v3_vm_info * vm) { INIT_LIST_HEAD(&(mgr->blk_list)); INIT_LIST_HEAD(&(mgr->net_list)); INIT_LIST_HEAD(&(mgr->char_list)); - INIT_LIST_HEAD(&(mgr->console_list)); + INIT_LIST_HEAD(&(mgr->cons_list)); mgr->blk_table = v3_create_htable(0, dev_hash_fn, dev_eq_fn); mgr->net_table = v3_create_htable(0, dev_hash_fn, dev_eq_fn); mgr->char_table = v3_create_htable(0, dev_hash_fn, dev_eq_fn); - mgr->console_table = v3_create_htable(0, dev_hash_fn, dev_eq_fn); + mgr->cons_table = v3_create_htable(0, dev_hash_fn, dev_eq_fn); return 0; } @@ -120,36 +120,13 @@ int v3_dev_mgr_deinit(struct v3_vm_info * vm) { v3_free_htable(mgr->blk_table, 0, 0); v3_free_htable(mgr->net_table, 0, 0); v3_free_htable(mgr->char_table, 0, 0); - v3_free_htable(mgr->console_table, 0, 0); + v3_free_htable(mgr->cons_table, 0, 0); v3_free_htable(mgr->dev_table, 0, 0); return 0; } -/* -int v3_init_core_dev_mgr(struct v3_vm_info * vm) { - struct v3_core_dev_mgr * mgr = &(vm->core_dev_mgr); - - INIT_LIST_HEAD(&(mgr->dev_list)); - mgr->dev_table = v3_create_htable(0, dev_hash_fn, dev_eq_fn); - - return 0; -} - -int v3_core_dev_mgr_deinit(struct v3_vm_info * vm) { - struct vm_device * dev; - struct v3_core_dev_mgr * mgr = &(vm->core_dev_mgr); - struct vm_device * tmp; - - list_for_each_entry_safe(dev, tmp, &(mgr->dev_list), dev_link) { - v3_detach_device(dev); - } - - // TODO: Clear hash tables - -} -*/ int v3_create_device(struct v3_vm_info * vm, const char * dev_name, v3_cfg_tree_t * cfg) { @@ -193,19 +170,58 @@ struct vm_device * v3_find_dev(struct v3_vm_info * vm, const char * dev_name) { /* The remaining functions are called by the devices themselves */ /****************************************************************/ +struct dev_io_hook { + uint16_t port; + + struct list_head node; + +}; + /* IO HOOKS */ int v3_dev_hook_io(struct vm_device * dev, uint16_t port, - int (*read)(struct guest_info * core, uint16_t port, void * dst, uint_t length, struct vm_device * dev), - int (*write)(struct guest_info * core, uint16_t port, void * src, uint_t length, struct vm_device * dev)) { - return v3_hook_io_port(dev->vm, port, - (int (*)(struct guest_info * core, ushort_t, void *, uint_t, void *))read, - (int (*)(struct guest_info * core, ushort_t, void *, uint_t, void *))write, - (void *)dev); + int (*read)(struct guest_info * core, uint16_t port, void * dst, uint_t length, void * priv_data), + int (*write)(struct guest_info * core, uint16_t port, void * src, uint_t length, void * priv_data)) { + struct dev_io_hook * io_hook = NULL; + int ret = 0; + + ret = v3_hook_io_port(dev->vm, port, + (int (*)(struct guest_info * core, ushort_t, void *, uint_t, void *))read, + (int (*)(struct guest_info * core, ushort_t, void *, uint_t, void *))write, + (void *)dev->private_data); + + if (ret == -1) { + return -1; + } + + io_hook = V3_Malloc(sizeof(struct dev_io_hook)); + + if (io_hook == NULL) { + PrintError("Could not allocate io hook dev state\n"); + return -1; + } + + io_hook->port = port; + list_add(&(io_hook->node), &(dev->io_hooks)); + + return 0; } int v3_dev_unhook_io(struct vm_device * dev, uint16_t port) { - return v3_unhook_io_port(dev->vm, port); + struct dev_io_hook * io_hook = NULL; + struct dev_io_hook * tmp; + + list_for_each_entry_safe(io_hook, tmp, &(dev->io_hooks), node) { + if (io_hook->port == port) { + + list_del(&(io_hook->node)); + V3_Free(io_hook); + + return v3_unhook_io_port(dev->vm, port); + } + } + + return -1; } @@ -236,6 +252,8 @@ struct vm_device * v3_allocate_device(char * name, dev = (struct vm_device*)V3_Malloc(sizeof(struct vm_device)); + INIT_LIST_HEAD(&(dev->io_hooks)); + strncpy(dev->name, name, 32); dev->ops = ops; dev->private_data = private_data; @@ -405,6 +423,67 @@ int v3_dev_connect_net(struct v3_vm_info * vm, } +struct cons_frontend { + int (*connect)(struct v3_vm_info * vm, + void * frontend_data, + struct v3_dev_console_ops * ops, + v3_cfg_tree_t * cfg, + void * priv_data); + + + struct list_head cons_node; + + void * priv_data; +}; + +int v3_dev_add_console_frontend(struct v3_vm_info * vm, + char * name, + int (*connect)(struct v3_vm_info * vm, + void * frontend_data, + struct v3_dev_console_ops * ops, + v3_cfg_tree_t * cfg, + void * private_data), + void * priv_data) +{ + struct cons_frontend * frontend = NULL; + + frontend = (struct cons_frontend *)V3_Malloc(sizeof(struct cons_frontend)); + memset(frontend, 0, sizeof(struct cons_frontend)); + + frontend->connect = connect; + frontend->priv_data = priv_data; + + list_add(&(frontend->cons_node), &(vm->dev_mgr.cons_list)); + v3_htable_insert(vm->dev_mgr.cons_table, (addr_t)(name), (addr_t)frontend); + + return 0; +} + + +int v3_dev_connect_console(struct v3_vm_info * vm, + char * frontend_name, + struct v3_dev_console_ops * ops, + v3_cfg_tree_t * cfg, + void * private_data) +{ + struct cons_frontend * frontend = NULL; + + frontend = (struct cons_frontend *)v3_htable_search(vm->dev_mgr.cons_table, + (addr_t)frontend_name); + + if (frontend == NULL) { + PrintError("Could not find frontend console device %s\n", frontend_name); + return 0; + } + + if (frontend->connect(vm, frontend->priv_data, ops, cfg, private_data) == -1) { + PrintError("Error connecting to console frontend %s\n", frontend_name); + return -1; + } + + return 0; +} + struct char_frontend { int (*connect)(struct v3_vm_info * vm, void * frontend_data, @@ -419,8 +498,6 @@ struct char_frontend { void * priv_data; }; - - int v3_dev_add_char_frontend(struct v3_vm_info * vm, char * name, int (*connect)(struct v3_vm_info * vm,