Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


changed device registration interface
[palacios.git] / palacios / src / devices / pci.c
index 267eca1..5a12909 100644 (file)
@@ -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,
+
 };
 
 
@@ -656,13 +629,15 @@ static int pci_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
     struct pci_internal * pci_state = V3_Malloc(sizeof(struct pci_internal));
     int i = 0;
     char * dev_id = v3_cfg_val(cfg, "ID");
+    int ret = 0;
     
     PrintDebug("PCI internal at %p\n",(void *)pci_state);
     
-    struct vm_device * dev = v3_allocate_device(dev_id, &dev_ops, pci_state);
+    struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, pci_state);
     
-    if (v3_attach_device(vm, dev) == -1) {
+    if (dev == NULL) {
        PrintError("Could not attach device %s\n", dev_id);
+       V3_Free(pci_state);
        return -1;
     }
 
@@ -675,8 +650,14 @@ static int pci_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
     PrintDebug("Sizeof config header=%d\n", (int)sizeof(struct pci_config_header));
     
     for (i = 0; i < 4; i++) {
-       v3_dev_hook_io(dev, CONFIG_ADDR_PORT + i, &addr_port_read, &addr_port_write);
-       v3_dev_hook_io(dev, CONFIG_DATA_PORT + i, &data_port_read, &data_port_write);
+       ret |= v3_dev_hook_io(dev, CONFIG_ADDR_PORT + i, &addr_port_read, &addr_port_write);
+       ret |= v3_dev_hook_io(dev, CONFIG_DATA_PORT + i, &data_port_read, &data_port_write);
+    }
+    
+    if (ret != 0) {
+       PrintError("Error hooking PCI IO ports\n");
+       v3_remove_device(dev);
+       return -1;
     }
 
     return 0;
@@ -774,15 +755,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 +772,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(dev, bus->irq_dev_data);
 }
 
 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(dev, bus->irq_dev_data);
 }
 
 // if dev_num == -1, auto assign