X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Fgeneric.c;h=e397cd2fa8817b9100c7b9dd911b22a28b3201b2;hb=4f7c3b759e3889870c5b5e7d09b3ffcc168e5632;hp=35d8b9a8850cd61697e4709130253ea400ee8437;hpb=a4b341afa075a6620dd087ee3a8ed850730c05c7;p=palacios.git diff --git a/palacios/src/devices/generic.c b/palacios/src/devices/generic.c index 35d8b9a..e397cd2 100644 --- a/palacios/src/devices/generic.c +++ b/palacios/src/devices/generic.c @@ -1,15 +1,16 @@ +/* Northwestern University */ +/* (c) 2008, Peter Dinda */ + #include #include #include #include -#define GENERIC_DEBUG 1 -#if GENERIC_DEBUG -#define GENERIC_DEBUG_PRINT(first, rest...) PrintDebug(first, ##rest) -#else -#define GENERIC_DEBUG_PRINT(first, rest...) +#ifndef DEBUG_GENERIC +#undef PrintDebug +#define PrintDebug(fmt, args...) #endif @@ -28,14 +29,18 @@ struct generic_internal { - +#ifdef RAMDISK_BOOT +#include +//ramdisk_state +static struct ramdisk_t *ramdisk_state; +#endif int generic_reset_device(struct vm_device * dev) { - GENERIC_DEBUG_PRINT("generic: reset device\n"); + PrintDebug("generic: reset device\n"); return 0; @@ -47,64 +52,176 @@ int generic_reset_device(struct vm_device * dev) int generic_start_device(struct vm_device *dev) { - GENERIC_DEBUG_PRINT("generic: start device\n"); + PrintDebug("generic: start device\n"); return 0; } int generic_stop_device(struct vm_device *dev) { - GENERIC_DEBUG_PRINT("generic: stop device\n"); + PrintDebug("generic: stop device\n"); return 0; } -int generic_write_port(ushort_t port, - void * src, - uint_t length, - struct vm_device * dev) +int generic_write_port_passthrough(ushort_t port, + void * src, + uint_t length, + struct vm_device * dev) { uint_t i; - GENERIC_DEBUG_PRINT("generic: writing 0x"); + PrintDebug("generic: writing 0x"); for (i = 0; i < length; i++) { - GENERIC_DEBUG_PRINT("%x", ((uchar_t*)src)[i]); + PrintDebug("%x", ((uchar_t*)src)[i]); } + + PrintDebug(" to port 0x%x ... ", port); - GENERIC_DEBUG_PRINT(" to port 0x%x ... ", port); +#ifdef RAMDISK_BOOT - for (i = 0; i < length; i++) { - Out_Byte(port, ((uchar_t*)src)[i]); - } + uint_t err; + + if (((port >= 0x170 && port <= 0x177) || port == 0x376 || port == 0x377) + && (dev->vm->cpu_mode == REAL)) { + + + err = ramdisk_state->eops.write_port(port, src, length, dev); - GENERIC_DEBUG_PRINT(" done\n"); + }else{ +#endif + + switch (length) { + case 1: + Out_Byte(port,((uchar_t*)src)[0]); + break; + case 2: + Out_Word(port,((ushort_t*)src)[0]); + break; + case 4: + Out_DWord(port,((uint_t*)src)[0]); + break; + default: + for (i = 0; i < length; i++) { + Out_Byte(port, ((uchar_t*)src)[i]); + } + } //switch length +#ifdef RAMDISK_BOOT + }//else not ramdisk +#endif + PrintDebug(" done\n"); return length; } -int generic_read_port(ushort_t port, - void * src, - uint_t length, - struct vm_device * dev) +int generic_read_port_passthrough(ushort_t port, + void * src, + uint_t length, + struct vm_device * dev) { uint_t i; - GENERIC_DEBUG_PRINT("generic: reading 0x%x bytes from port 0x%x ...", length, port); + PrintDebug("generic: reading 0x%x bytes from port 0x%x ...", length, port); + +#ifdef RAMDISK_BOOT + + uint_t err; + + if (((port >= 0x170 && port <= 0x177) || port == 0x376 || port == 0x377) + && (dev->vm->cpu_mode == REAL)) { + + err = ramdisk_state->eops.read_port(port, src, length, dev); + + }else{ +#endif + + switch (length) { + case 1: + ((uchar_t*)src)[0] = In_Byte(port); + break; + case 2: + ((ushort_t*)src)[0] = In_Word(port); + break; + case 4: + ((uint_t*)src)[0] = In_DWord(port); + break; + default: + for (i = 0; i < length; i++) { + ((uchar_t*)src)[i] = In_Byte(port); + } + }//switch length +#ifdef RAMDISK_BOOT + }//else not ramdisk +#endif + + PrintDebug(" done ... read 0x"); for (i = 0; i < length; i++) { - ((uchar_t*)src)[i] = In_Byte(port); + PrintDebug("%x", ((uchar_t*)src)[i]); } - GENERIC_DEBUG_PRINT(" done ... read 0x"); + PrintDebug("\n"); + + return length; +} + +int generic_write_port_ignore(ushort_t port, + void * src, + uint_t length, + struct vm_device * dev) +{ + uint_t i; + + PrintDebug("generic: writing 0x"); for (i = 0; i < length; i++) { - GENERIC_DEBUG_PRINT("%x", ((uchar_t*)src)[i]); + PrintDebug("%x", ((uchar_t*)src)[i]); + } + + PrintDebug(" to port 0x%x ... ", port); + + PrintDebug(" ignored\n"); + +#ifdef RAMDISK_BOOT + + uint_t err; + + if (((port >= 0x3e8 && port <= 0x3ef) || + (port >= 0x2e8 && port <= 0x2ef)) + && (dev->vm->cpu_mode == REAL)) { + + err = ramdisk_state->eops.write_port_ignore(port, src, length, dev); } +#endif + + return length; +} + +int generic_read_port_ignore(ushort_t port, + void * src, + uint_t length, + struct vm_device * dev) +{ - GENERIC_DEBUG_PRINT("\n"); + PrintDebug("generic: reading 0x%x bytes from port 0x%x ...", length, port); + + memset((char*)src,0,length); + PrintDebug(" ignored (return zeroed buffer)\n"); + +#ifdef RAMDISK_BOOT + + uint_t err; + + if (((port >= 0x3e8 && port <= 0x3ef) || + (port >= 0x2e8 && port <= 0x2ef)) + && (dev->vm->cpu_mode == REAL)) { + + err = ramdisk_state->eops.read_port_ignore(port, src, length, dev); + } +#endif return length; } @@ -128,56 +245,68 @@ int generic_init_device(struct vm_device * dev) struct generic_internal *state = (struct generic_internal *)(dev->private_data); uint_t i, j; - GENERIC_DEBUG_PRINT("generic: init_device\n"); + PrintDebug("generic: init_device\n"); // Would read state here generic_reset_device(dev); for (i = 0; i < state->num_port_ranges; i++) { - GENERIC_DEBUG_PRINT("generic: hooking ports 0x%x to 0x%x\n", state->port_ranges[i][0], state->port_ranges[i][1]); + PrintDebug("generic: hooking ports 0x%x to 0x%x as %x\n", state->port_ranges[i][0], state->port_ranges[i][1], state->port_ranges[i][2]==GENERIC_PRINT_AND_PASSTHROUGH ? "print-and-passthrough" : "print-and-ignore"); #if PORT_HOOKS for (j = state->port_ranges[i][0]; j <= state->port_ranges[i][1]; j++) { - if (dev_hook_io(dev, j, &generic_read_port, &generic_write_port)) { - GENERIC_DEBUG_PRINT("generic: can't hook port 0x%x (already hooked?)\n", j); - } + if (state->port_ranges[i][2]==GENERIC_PRINT_AND_PASSTHROUGH) { + if (dev_hook_io(dev, j, &generic_read_port_passthrough, &generic_write_port_passthrough)) { + PrintDebug("generic: can't hook port 0x%x (already hooked?)\n", j); + } + } else if (state->port_ranges[i][2]==GENERIC_PRINT_AND_IGNORE) { + if (dev_hook_io(dev, j, &generic_read_port_ignore, &generic_write_port_ignore)) { + PrintDebug("generic: can't hook port 0x%x (already hooked?)\n", j); + } + } } #else - GENERIC_DEBUG_PRINT("generic: hooking ports not supported\n"); + PrintDebug("generic: hooking ports not supported\n"); #endif } for (i = 0; i < state->num_address_ranges; i++) { - GENERIC_DEBUG_PRINT("generic: hooking addresses 0x%x to 0x%x\n",state->address_ranges[i][0],state->address_ranges[i][1]); + PrintDebug("generic: hooking addresses 0x%x to 0x%x\n",state->address_ranges[i][0],state->address_ranges[i][1]); #if MEM_HOOKS if (dev_hook_mem(dev, state->address_ranges[i][0], state->address_ranges[i][1])) { - GENERIC_DEBUG_PRINT("generic: Can't hook addresses 0x%x to 0x%x (already hooked?)\n", + PrintDebug("generic: Can't hook addresses 0x%x to 0x%x (already hooked?)\n", state->address_ranges[i][0], state->address_ranges[i][1]); } #else - GENERIC_DEBUG_PRINT("generic: hooking addresses not supported\n"); + PrintDebug("generic: hooking addresses not supported\n"); #endif } for (i = 0; i < state->num_irq_ranges; i++) { - GENERIC_DEBUG_PRINT("generic: hooking irqs 0x%x to 0x%x\n",state->irq_ranges[i][0],state->irq_ranges[i][1]); + PrintDebug("generic: hooking irqs 0x%x to 0x%x\n",state->irq_ranges[i][0],state->irq_ranges[i][1]); #if IRQ_HOOKS for (j = state->irq_ranges[i][0]; j <= state->irq_ranges[i][1]; j++) { if (dev_hook_irq(dev, j, &generic_interrupt)) { - GENERIC_DEBUG_PRINT("generic: can't hook irq 0x%x (already hooked?)\n", j); + PrintDebug("generic: can't hook irq 0x%x (already hooked?)\n", j); } } #else - GENERIC_DEBUG_PRINT("generic: hooking irqs not supported\n"); + PrintDebug("generic: hooking irqs not supported\n"); #endif } +#ifdef RAMDISK_BOOT + + ramdisk_state->cops.init(ramdisk_state, dev); + +#endif + return 0; } @@ -186,48 +315,54 @@ int generic_deinit_device(struct vm_device *dev) struct generic_internal *state = (struct generic_internal *)(dev->private_data); uint_t i, j; - GENERIC_DEBUG_PRINT("generic: deinit_device\n"); + PrintDebug("generic: deinit_device\n"); + +#ifdef RAMDISK_BOOT + + ramdisk_state->cops.close(ramdisk_state); + +#endif for (i = 0; i < state->num_irq_ranges; i++) { - GENERIC_DEBUG_PRINT("generic: unhooking irqs 0x%x to 0x%x\n", state->irq_ranges[i][0], state->irq_ranges[i][1]); + PrintDebug("generic: unhooking irqs 0x%x to 0x%x\n", state->irq_ranges[i][0], state->irq_ranges[i][1]); #if IRQ_HOOKS for (j = state->irq_ranges[i][0]; j <= state->irq_ranges[i][1]; j++) { if (dev_unhook_irq(dev, j)) { - GENERIC_DEBUG_PRINT("generic: can't unhook irq 0x%x (already unhooked?)\n",j); + PrintDebug("generic: can't unhook irq 0x%x (already unhooked?)\n",j); } } #else - GENERIC_DEBUG_PRINT("generic: unhooking irqs not supported\n"); + PrintDebug("generic: unhooking irqs not supported\n"); #endif } for (i = 0; i < state->num_address_ranges; i++) { - GENERIC_DEBUG_PRINT("generic: unhooking addresses 0x%x to 0x%x\n",state->address_ranges[i][0],state->address_ranges[i][1]); + PrintDebug("generic: unhooking addresses 0x%x to 0x%x\n",state->address_ranges[i][0],state->address_ranges[i][1]); #if MEM_HOOKS if (dev_unhook_mem(dev, state->address_ranges[i][0], state->address_ranges[i][1])) { - GENERIC_DEBUG_PRINT("generic: Can't unhook addresses 0x%x to 0x%x (already unhooked?)\n", + PrintDebug("generic: Can't unhook addresses 0x%x to 0x%x (already unhooked?)\n", state->address_ranges[i][0], state->address_ranges[i][1]); } #else - GENERIC_DEBUG_PRINT("generic: unhooking addresses not supported\n"); + PrintDebug("generic: unhooking addresses not supported\n"); #endif } for (i = 0; i < state->num_port_ranges; i++) { - GENERIC_DEBUG_PRINT("generic: unhooking ports 0x%x to 0x%x\n",state->port_ranges[i][0],state->port_ranges[i][1]); + PrintDebug("generic: unhooking ports 0x%x to 0x%x\n",state->port_ranges[i][0],state->port_ranges[i][1]); #if PORT_HOOKS for (j = state->port_ranges[i][0]; j <= state->port_ranges[i][1]; j++) { if (dev_unhook_io(dev, j)) { - GENERIC_DEBUG_PRINT("generic: can't unhook port 0x%x (already unhooked?)\n", j); + PrintDebug("generic: can't unhook port 0x%x (already unhooked?)\n", j); } } #else - GENERIC_DEBUG_PRINT("generic: unhooking ports not supported\n"); + PrintDebug("generic: unhooking ports not supported\n"); #endif } @@ -252,14 +387,38 @@ static struct vm_device_ops dev_ops = { struct vm_device *create_generic(generic_port_range_type port_ranges[], - uint_t num_port_ranges, generic_address_range_type address_ranges[], - uint_t num_address_ranges, - generic_irq_range_type irq_ranges[], - uint_t num_irq_ranges) + generic_irq_range_type irq_ranges[]) { struct generic_internal * generic_state = (struct generic_internal *)V3_Malloc(sizeof(struct generic_internal)); + int i; + uint_t num_port_ranges, num_address_ranges, num_irq_ranges; + + num_port_ranges=0; + if (port_ranges!=NULL) { + i=0; + while (port_ranges[i]!=NULL && + !(port_ranges[i][0]==0 && port_ranges[i][1]==0 && port_ranges[i][2]==0)) + { num_port_ranges++; i++; } + } + + num_address_ranges=0; + if (address_ranges!=NULL) { + i=0; + while (address_ranges[i]!=NULL && + !(address_ranges[i][0]==0 && address_ranges[i][1]==0 && address_ranges[i][2]==0)) + { num_address_ranges++; i++; } + } + + num_irq_ranges=0; + if (irq_ranges!=NULL) { + i=0; + while (irq_ranges[i]!=NULL && + !(irq_ranges[i][0]==0 && irq_ranges[i][1]==0 && irq_ranges[i][2]==0) ) + { num_irq_ranges++; i++; } + } + generic_state->num_port_ranges = num_port_ranges; @@ -290,6 +449,12 @@ struct vm_device *create_generic(generic_port_range_type port_ranges[], generic_state->irq_ranges = NULL; } +#ifdef RAMDISK_BOOT + + ramdisk_state = create_ramdisk(); + V3_ASSERT(ramdisk_state != NULL); + +#endif struct vm_device *device = create_device("GENERIC", &dev_ops, generic_state);