From: Jack Lange Date: Tue, 26 May 2009 23:23:11 +0000 (-0500) Subject: Merge branch 'devel' of ssh://palacios@newskysaw//home/palacios/palacios into devel X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=commitdiff_plain;h=85c736059d266eff4fc8de648c43079a29137da1;hp=1a3e584d6d3b937a5990517f4fc838ea0d12298d;p=palacios.releases.git Merge branch 'devel' of ssh://palacios@newskysaw//home/palacios/palacios into devel --- diff --git a/palacios/include/devices/net_cd.h b/palacios/include/devices/net_cd.h new file mode 100644 index 0000000..34c90c2 --- /dev/null +++ b/palacios/include/devices/net_cd.h @@ -0,0 +1,36 @@ +/* + * This file is part of the Palacios Virtual Machine Monitor developed + * by the V3VEE Project with funding from the United States National + * Science Foundation and the Department of Energy. + * + * The V3VEE Project is a joint project between Northwestern University + * and the University of New Mexico. You can find out more at + * http://www.v3vee.org + * + * Copyright (c) 2008, Jack Lange + * Copyright (c) 2008, The V3VEE Project + * All rights reserved. + * + * Author: Jack Lange + * + * This is free software. You are permitted to use, + * redistribute, and modify it as specified in the file "V3VEE_LICENSE". + */ + +#ifndef __DEVICES_RAM_CD_H__ +#define __DEVICES_RAM_CD_H__ + +#ifdef __V3VEE__ + +#include + + +struct vm_device * v3_create_ram_cd(struct vm_device * ide, + uint_t bus, uint_t drive, + addr_t ramdisk, uint32_t size); + + + +#endif + +#endif diff --git a/palacios/include/devices/net_hd.h b/palacios/include/devices/net_hd.h new file mode 100644 index 0000000..77adf3e --- /dev/null +++ b/palacios/include/devices/net_hd.h @@ -0,0 +1,36 @@ +/* + * This file is part of the Palacios Virtual Machine Monitor developed + * by the V3VEE Project with funding from the United States National + * Science Foundation and the Department of Energy. + * + * The V3VEE Project is a joint project between Northwestern University + * and the University of New Mexico. You can find out more at + * http://www.v3vee.org + * + * Copyright (c) 2008, Jack Lange + * Copyright (c) 2008, The V3VEE Project + * All rights reserved. + * + * Author: Jack Lange + * + * This is free software. You are permitted to use, + * redistribute, and modify it as specified in the file "V3VEE_LICENSE". + */ + +#ifndef __DEVICES_RAM_HD_H__ +#define __DEVICES_RAM_HD_H__ + +#ifdef __V3VEE__ + +#include + + +struct vm_device * v3_create_ram_hd(struct vm_device * ide, + uint_t bus, uint_t drive, + addr_t ramdisk, uint32_t size); + + + +#endif + +#endif diff --git a/palacios/src/devices/ide.c b/palacios/src/devices/ide.c index 80f76b2..eb07a62 100644 --- a/palacios/src/devices/ide.c +++ b/palacios/src/devices/ide.c @@ -1400,6 +1400,7 @@ static int init_ide(struct vm_device * dev) { return -1; } + PrintDebug("Connecting to IDE IO ports\n"); v3_dev_hook_io(dev, PRI_DATA_PORT, &ide_read_data_port, &write_data_port); @@ -1459,6 +1460,8 @@ static int init_ide(struct vm_device * dev) { struct pci_device * pci_dev = NULL; int i; + PrintDebug("Connecting IDE to PCI bus\n"); + for (i = 0; i < 6; i++) { bars[i].type = PCI_BAR_NONE; } @@ -1501,6 +1504,8 @@ static int init_ide(struct vm_device * dev) { } + PrintDebug("IDE Initialized\n"); + return 0; } @@ -1523,15 +1528,22 @@ static struct vm_device_ops dev_ops = { struct vm_device * v3_create_ide(struct vm_device * pci_bus, struct vm_device * southbridge_dev) { struct ide_internal * ide = (struct ide_internal *)V3_Malloc(sizeof(struct ide_internal)); + + memset(ide, 0, sizeof(struct ide_internal)); + struct vm_device * device = v3_create_device("IDE", &dev_ops, ide); - ide->pci_bus = pci_bus; - if (ide->southbridge) { - ide->southbridge = (struct v3_southbridge *)(southbridge_dev->private_data); - } else { - ide->southbridge = NULL; + if (pci_bus != NULL) { + if (southbridge_dev == NULL) { + PrintError("PCI Enabled BUT southbridge is NULL\n"); + return NULL; + } + + ide->pci_bus = pci_bus; + ide->southbridge = (struct v3_southbridge *)(southbridge_dev->private_data); } + PrintDebug("IDE: Creating IDE bus x 2\n"); return device; diff --git a/palacios/src/devices/net_cd.c b/palacios/src/devices/net_cd.c new file mode 100644 index 0000000..fb88e37 --- /dev/null +++ b/palacios/src/devices/net_cd.c @@ -0,0 +1,118 @@ +/* + * This file is part of the Palacios Virtual Machine Monitor developed + * by the V3VEE Project with funding from the United States National + * Science Foundation and the Department of Energy. + * + * The V3VEE Project is a joint project between Northwestern University + * and the University of New Mexico. You can find out more at + * http://www.v3vee.org + * + * Copyright (c) 2008, Jack Lange + * Copyright (c) 2008, The V3VEE Project + * All rights reserved. + * + * Author: Jack Lange + * + * This is free software. You are permitted to use, + * redistribute, and modify it as specified in the file "V3VEE_LICENSE". + */ + +#include +#include +#include + +#ifndef DEBUG_IDE +#undef PrintDebug +#define PrintDebug(fmt, args...) +#endif + + +struct cd_state { + addr_t disk_image; + uint32_t capacity; // in bytes + + struct vm_device * ide; + + uint_t bus; + uint_t drive; +}; + + +// CDs always read 2048 byte blocks... ? +static int cd_read(uint8_t * buf, int block_count, uint64_t lba, void * private_data) { + struct vm_device * cd_dev = (struct vm_device *)private_data; + struct cd_state * cd = (struct cd_state *)(cd_dev->private_data); + int offset = lba * ATAPI_BLOCK_SIZE; + int length = block_count * ATAPI_BLOCK_SIZE; + + PrintDebug("Reading RAM CD at (LBA=%d) offset %d (length=%d)\n", (uint32_t)lba, offset, length); + + memcpy(buf, (uint8_t *)(cd->disk_image + offset), length); + + return 0; +} + + +static uint32_t cd_get_capacity(void * private_data) { + struct vm_device * cd_dev = (struct vm_device *)private_data; + struct cd_state * cd = (struct cd_state *)(cd_dev->private_data); + PrintDebug("Querying RAM CD capacity (bytes=%d) (ret = %d)\n", + cd->capacity, cd->capacity / ATAPI_BLOCK_SIZE); + return cd->capacity / ATAPI_BLOCK_SIZE; +} + +static struct v3_ide_cd_ops cd_ops = { + .read = cd_read, + .get_capacity = cd_get_capacity, +}; + + +static int cd_init(struct vm_device * dev) { + struct cd_state * cd = (struct cd_state *)(dev->private_data); + + if (v3_ide_register_cdrom(cd->ide, cd->bus, cd->drive, "RAM-CD", &cd_ops, dev) == -1) { + return -1; + } + + return 0; +} + + +static int cd_deinit(struct vm_device * dev) { + return 0; +} + +static struct vm_device_ops dev_ops = { + .init = cd_init, + .deinit = cd_deinit, + .reset = NULL, + .start = NULL, + .stop = NULL, +}; + +struct vm_device * v3_create_ram_cd(struct vm_device * ide, + uint_t bus, uint_t drive, + addr_t ramdisk, uint32_t size) { + struct cd_state * cd = NULL; + + if (size % ATAPI_BLOCK_SIZE) { + PrintError("CD image must be an integral of block size (ATAPI_BLOCK_SIZE=%d)\n", ATAPI_BLOCK_SIZE); + return NULL; + } + + cd = (struct cd_state *)V3_Malloc(sizeof(struct cd_state)); + + PrintDebug("Registering Ram CD at %p (size=%d)\n", (void *)ramdisk, size); + + + cd->disk_image = ramdisk; + cd->capacity = size; + + cd->ide = ide; + cd->bus = bus; + cd->drive = drive; + + struct vm_device * cd_dev = v3_create_device("RAM-CD", &dev_ops, cd); + + return cd_dev; +} diff --git a/palacios/src/devices/net_hd.c b/palacios/src/devices/net_hd.c new file mode 100644 index 0000000..3bce4fc --- /dev/null +++ b/palacios/src/devices/net_hd.c @@ -0,0 +1,131 @@ +/* + * This file is part of the Palacios Virtual Machine Monitor developed + * by the V3VEE Project with funding from the United States National + * Science Foundation and the Department of Energy. + * + * The V3VEE Project is a joint project between Northwestern University + * and the University of New Mexico. You can find out more at + * http://www.v3vee.org + * + * Copyright (c) 2008, Jack Lange + * Copyright (c) 2008, The V3VEE Project + * All rights reserved. + * + * Author: Jack Lange + * + * This is free software. You are permitted to use, + * redistribute, and modify it as specified in the file "V3VEE_LICENSE". + */ + +#include +#include +#include + + + +#ifndef DEBUG_IDE +#undef PrintDebug +#define PrintDebug(fmt, args...) +#endif + +struct hd_state { + addr_t disk_image; + uint32_t capacity; // in bytes + + struct vm_device * ide; + + uint_t bus; + uint_t drive; +}; + + +// HDs always read 512 byte blocks... ? +static int hd_read(uint8_t * buf, int sector_count, uint64_t lba, void * private_data) { + struct vm_device * hd_dev = (struct vm_device *)private_data; + struct hd_state * hd = (struct hd_state *)(hd_dev->private_data); + int offset = lba * IDE_SECTOR_SIZE; + int length = sector_count * IDE_SECTOR_SIZE; + + // PrintDebug("Reading RAM HD at (LBA=%d) offset %d (length=%d)\n", (uint32_t)lba, offset, length); + + memcpy(buf, (uint8_t *)(hd->disk_image + offset), length); + + return 0; +} + + +static int hd_write(uint8_t * buf, int sector_count, uint64_t lba, void * private_data) { + struct vm_device * hd_dev = (struct vm_device *)private_data; + struct hd_state * hd = (struct hd_state *)(hd_dev->private_data); + int offset = lba * IDE_SECTOR_SIZE; + int length = sector_count * IDE_SECTOR_SIZE; + + memcpy((uint8_t *)(hd->disk_image + offset), buf, length); + + return 0; +} + + +static uint64_t hd_get_capacity(void * private_data) { + struct vm_device * hd_dev = (struct vm_device *)private_data; + struct hd_state * hd = (struct hd_state *)(hd_dev->private_data); + PrintDebug("Querying RAM HD capacity (bytes=%d) (ret = %d)\n", + hd->capacity, hd->capacity / IDE_SECTOR_SIZE); + return hd->capacity / IDE_SECTOR_SIZE; +} + +static struct v3_ide_hd_ops hd_ops = { + .read = hd_read, + .write = hd_write, + .get_capacity = hd_get_capacity, +}; + + +static int hd_init(struct vm_device * dev) { + struct hd_state * hd = (struct hd_state *)(dev->private_data); + + if (v3_ide_register_harddisk(hd->ide, hd->bus, hd->drive, "V3-RAM-HD", &hd_ops, dev) == -1) { + return -1; + } + + return 0; +} + + +static int hd_deinit(struct vm_device * dev) { + return 0; +} + +static struct vm_device_ops dev_ops = { + .init = hd_init, + .deinit = hd_deinit, + .reset = NULL, + .start = NULL, + .stop = NULL, +}; + +struct vm_device * v3_create_ram_hd(struct vm_device * ide, + uint_t bus, uint_t drive, + addr_t ramdisk, uint32_t size) { + struct hd_state * hd = NULL; + + if (size % IDE_SECTOR_SIZE) { + PrintError("HD image must be an integral of sector size (IDE_SECTOR_SIZE=%d)\n", IDE_SECTOR_SIZE); + return NULL; + } + + hd = (struct hd_state *)V3_Malloc(sizeof(struct hd_state)); + + PrintDebug("Registering Ram HDD at %p (size=%d)\n", (void *)ramdisk, size); + + hd->disk_image = ramdisk; + hd->capacity = size; + + hd->ide = ide; + hd->bus = bus; + hd->drive = drive; + + struct vm_device * hd_dev = v3_create_device("RAM-HD", &dev_ops, hd); + + return hd_dev; +}