#include <devices/ide.h>
#include <palacios/vmm_socket.h>
-#ifndef DEBUG_IDE
+#ifndef CONFIG_DEBUG_IDE
#undef PrintDebug
#define PrintDebug(fmt, args...)
#endif
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;
+ int offset = lba * HD_SECTOR_SIZE;
+ int length = sector_count * HD_SECTOR_SIZE;
uint8_t status;
uint32_t ret_len = 0;
char nbd_cmd[4] = {0,0,0,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;
+ int offset = lba * HD_SECTOR_SIZE;
+ int length = sector_count * HD_SECTOR_SIZE;
uint8_t status;
char nbd_cmd[4] = {0,0,0,0};
struct vm_device * hd_dev = (struct vm_device *)private_data;
struct hd_state * hd = (struct hd_state *)(hd_dev->private_data);
- return hd->capacity / IDE_SECTOR_SIZE;
+ return hd->capacity / HD_SECTOR_SIZE;
}
-static struct v3_ide_hd_ops hd_ops = {
+static struct v3_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);
+
+
+
+static int hd_free(struct vm_device * dev) {
+ return 0;
+}
+
+static struct v3_device_ops dev_ops = {
+ .free = hd_free,
+ .reset = NULL,
+ .start = NULL,
+ .stop = NULL,
+};
+
+
+static int socket_init(struct hd_state * hd) {
char header[64];
PrintDebug("Intializing Net HD\n");
PrintDebug("Capacity: %p\n", (void *)(hd->capacity));
}
- PrintDebug("Registering HD\n");
- if (v3_ide_register_harddisk(hd->ide, hd->bus, hd->drive, "V3-NET-HD", &hd_ops, dev) == -1) {
- return -1;
- }
-
- PrintDebug("intialization done\n");
return 0;
}
-static int hd_deinit(struct vm_device * dev) {
- return 0;
-}
+static int hd_init(struct guest_info * vm, void * cfg_data) {
+ struct hd_state * hd = (struct hd_state *)V3_Malloc(sizeof(struct hd_state));
+ struct net_hd_cfg * cfg = (struct net_hd_cfg *)cfg_data;
-static struct vm_device_ops dev_ops = {
- .init = hd_init,
- .deinit = hd_deinit,
- .reset = NULL,
- .start = NULL,
- .stop = NULL,
-};
+ PrintDebug("Registering Net HD at %s:%d disk=%s\n", cfg->ip_str, cfg->port, cfg->disk_tag);
-struct vm_device * v3_create_net_hd(struct vm_device * ide,
- uint_t bus, uint_t drive,
- const char * ip_str, uint16_t port,
- const char * disk_tag) {
- struct hd_state * hd = (struct hd_state *)V3_Malloc(sizeof(struct hd_state));
+ strncpy(hd->disk_name, cfg->disk_tag, sizeof(hd->disk_name));
+ hd->ip_addr = v3_inet_addr(cfg->ip_str);
+ hd->port = cfg->port;
- PrintDebug("Registering Net HD at %s:%d disk=%s\n", ip_str, port, disk_tag);
+ hd->ide = v3_find_dev(vm, cfg->ide);
- strncpy(hd->disk_name, disk_tag, sizeof(hd->disk_name));
- hd->ip_addr = v3_inet_addr(ip_str);
- hd->port = port;
+ if (hd->ide == 0) {
+ PrintError("Could not find backend %s\n", cfg->ide);
+ return -1;
+ }
- hd->ide = ide;
- hd->bus = bus;
- hd->drive = drive;
+ hd->bus = cfg->bus;
+ hd->drive = cfg->drive;
- struct vm_device * hd_dev = v3_create_device("NET-HD", &dev_ops, hd);
+ struct vm_device * dev = v3_allocate_device("NET-HD", &dev_ops, hd);
+
+ if (v3_attach_device(vm, dev) == -1) {
+ PrintError("Could not attach device %s\n", "NET-HD");
+ return -1;
+ }
+
+ if (socket_init(hd) == -1) {
+ PrintError("could not initialize network connection\n");
+ return -1;
+ }
+
- return hd_dev;
+ PrintDebug("Registering HD\n");
+
+ if (v3_ide_register_harddisk(hd->ide, hd->bus, hd->drive, "V3-NET-HD", &hd_ops, dev) == -1) {
+ return -1;
+ }
+
+ PrintDebug("intialization done\n");
+
+ return 0;
}
+
+
+device_register("NET-HD", hd_init)