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.


updates to virtio device framework
[palacios.git] / palacios / src / devices / pci.c
index 7832a08..cce7aa8 100644 (file)
@@ -121,9 +121,11 @@ static int get_free_dev_num(struct pci_bus * bus) {
     int i, j;
 
     for (i = 0; i < sizeof(bus->dev_map); i++) {
+       PrintDebug("i=%d\n", i);
        if (bus->dev_map[i] != 0xff) {
            // availability
            for (j = 0; j < 8; j++) {
+               PrintDebug("\tj=%d\n", j);
                if (!(bus->dev_map[i] & (0x1 << j))) {
                    return ((i * 8) + j);
                }
@@ -556,7 +558,7 @@ static int pci_stop_device(struct vm_device * dev) {
 
 
 
-static int pci_deinit_device(struct vm_device * dev) {
+static int pci_free(struct vm_device * dev) {
     int i = 0;
     
     for (i = 0; i < 4; i++){
@@ -581,14 +583,30 @@ static void init_pci_busses(struct pci_internal * pci_state) {
 
 
 
-static int pci_init_device(struct vm_device * dev) {
-    struct pci_internal * pci_state = (struct pci_internal *)dev->private_data;
+
+static struct v3_device_ops dev_ops = {
+    .free = pci_free,
+    .reset = pci_reset_device,
+    .start = pci_start_device,
+    .stop = pci_stop_device,
+};
+
+
+
+
+static int pci_init(struct guest_info * vm, void * cfg_data) {
+    struct pci_internal * pci_state = V3_Malloc(sizeof(struct pci_internal));
     int i = 0;
     
-    PrintDebug("pci: init_device\n");
+    PrintDebug("PCI internal at %p\n",(void *)pci_state);
+    
+    struct vm_device * dev = v3_allocate_device("PCI", &dev_ops, pci_state);
+    
+    if (v3_attach_device(vm, dev) == -1) {
+       PrintError("Could not attach device %s\n", "PCI");
+       return -1;
+    }
 
-    // JRL: Fix this....
-    //    dev->vm->pci = dev;   //should be in vmm_config.c
     
     pci_state->addr_reg.val = 0; 
 
@@ -605,25 +623,7 @@ static int pci_init_device(struct vm_device * dev) {
 }
 
 
-static struct vm_device_ops dev_ops = {
-    .init = pci_init_device, 
-    .deinit = pci_deinit_device,
-    .reset = pci_reset_device,
-    .start = pci_start_device,
-    .stop = pci_stop_device,
-};
-
-
-struct vm_device * v3_create_pci() {
-    struct pci_internal * pci_state = V3_Malloc(sizeof(struct pci_internal));
-    
-    PrintDebug("PCI internal at %p\n",(void *)pci_state);
-    
-    struct vm_device * device = v3_create_device("PCI", &dev_ops, pci_state);
-    
-    return device;
-}
-
+device_register("PCI", pci_init)
 
 
 static inline int init_bars(struct pci_device * pci_dev) {
@@ -641,10 +641,12 @@ static inline int init_bars(struct pci_device * pci_dev) {
 
            for (j = 0; j < pci_dev->bar[i].num_ports; j++) {
                // hook IO
-               if (v3_dev_hook_io(pci_dev->vm_dev, pci_dev->bar[i].default_base_port + j,
-                                  pci_dev->bar[i].io_read, pci_dev->bar[i].io_write) == -1) {
-                   PrintError("Could not hook default io port %x\n", pci_dev->bar[i].default_base_port + j);
-                   return -1;
+               if (pci_dev->bar[i].default_base_port != 0xffff) {
+                   if (v3_dev_hook_io(pci_dev->vm_dev, pci_dev->bar[i].default_base_port + j,
+                                      pci_dev->bar[i].io_read, pci_dev->bar[i].io_write) == -1) {
+                       PrintError("Could not hook default io port %x\n", pci_dev->bar[i].default_base_port + j);
+                       return -1;
+                   }
                }
            }
 
@@ -719,13 +721,16 @@ struct pci_device * v3_pci_register_device(struct vm_device * pci,
        return NULL;
     }
 
-    if (dev_num == -1) {
+    if (dev_num == PCI_AUTO_DEV_NUM) {
+       PrintDebug("Searching for free device number\n");
        if ((dev_num = get_free_dev_num(bus)) == -1) {
            PrintError("No more available PCI slots on bus %d\n", bus->bus_num);
            return NULL;
        }
     }
     
+    PrintDebug("Checking for PCI Device\n");
+
     if (get_device(bus, dev_num, fn_num) != NULL) {
        PrintError("PCI Device already registered at slot %d on bus %d\n", 
                   dev_num, bus->bus_num);