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.


reformatted device source files
[palacios.git] / palacios / src / devices / generic.c
index 130c708..cc26934 100644 (file)
 
 
 struct generic_internal {
-  struct list_head port_list;
-  uint_t num_port_ranges;
-  struct list_head mem_list;
-  uint_t num_mem_ranges;
-  struct list_head irq_list;
-  uint_t num_irq_ranges;
+    struct list_head port_list;
+    uint_t num_port_ranges;
+    struct list_head mem_list;
+    uint_t num_mem_ranges;
+    struct list_head irq_list;
+    uint_t num_irq_ranges;
 };
 
 
 struct port_range {
-  uint_t start;
-  uint_t end;
-  uint_t type;
-  struct list_head range_link;
+    uint_t start;
+    uint_t end;
+    uint_t type;
+    struct list_head range_link;
 };
 
 struct mem_range {
-  void * start;
-  void * end;
-  uint_t type;
-  struct list_head range_link;
+    void * start;
+    void * end;
+    uint_t type;
+    struct list_head range_link;
 };
 
 struct irq_range {
-  uint_t start;
-  uint_t end;
-  uint_t type;
-  struct list_head range_link;
+    uint_t start;
+    uint_t end;
+    uint_t type;
+    struct list_head range_link;
 };
 
 
 
 static int generic_reset_device(struct vm_device * dev) {
-  PrintDebug("generic: reset device\n");
-  return 0;
+    PrintDebug("generic: reset device\n");
+    return 0;
 }
 
 
@@ -80,14 +80,14 @@ static int generic_reset_device(struct vm_device * dev) {
 
 
 static int generic_start_device(struct vm_device * dev) {
-  PrintDebug("generic: start device\n");
-  return 0;
+    PrintDebug("generic: start device\n");
+    return 0;
 }
 
 
 static int generic_stop_device(struct vm_device * dev) {
-  PrintDebug("generic: stop device\n");
-  return 0;
+    PrintDebug("generic: stop device\n");
+    return 0;
 }
 
 
@@ -97,90 +97,90 @@ static int generic_write_port_passthrough(ushort_t port,
                                          void * src, 
                                          uint_t length,
                                          struct vm_device * dev) {
-  uint_t i;
+    uint_t i;
 
-  PrintDebug("generic: writing 0x");
+    PrintDebug("generic: writing 0x");
 
-  for (i = 0; i < length; i++) { 
-    PrintDebug("%x", ((uchar_t*)src)[i]);
-  }
-  
-  PrintDebug(" to port 0x%x ... ", port);
-
-
-  switch (length) {
-  case 1:
-    v3_outb(port,((uchar_t*)src)[0]);
-    break;
-  case 2:
-    v3_outw(port,((ushort_t*)src)[0]);
-    break;
-  case 4:
-    v3_outdw(port,((uint_t*)src)[0]);
-    break;
-  default:
     for (i = 0; i < length; i++) { 
-      v3_outb(port, ((uchar_t*)src)[i]);
+       PrintDebug("%x", ((uchar_t*)src)[i]);
     }
-  } //switch length
+  
+    PrintDebug(" to port 0x%x ... ", port);
 
 
-  PrintDebug(" done\n");
+    switch (length) {
+       case 1:
+           v3_outb(port,((uchar_t*)src)[0]);
+           break;
+       case 2:
+           v3_outw(port,((ushort_t*)src)[0]);
+           break;
+       case 4:
+           v3_outdw(port,((uint_t*)src)[0]);
+           break;
+       default:
+           for (i = 0; i < length; i++) { 
+               v3_outb(port, ((uchar_t*)src)[i]);
+           }
+    } //switch length
+
+
+    PrintDebug(" done\n");
   
-  return length;
+    return length;
 }
 
 static int generic_read_port_passthrough(ushort_t port,
                                         void * src, 
                                         uint_t length,
                                         struct vm_device * dev) {
-  uint_t i;
+    uint_t i;
 
-  PrintDebug("generic: reading 0x%x bytes from port 0x%x ...", length, port);
+    PrintDebug("generic: reading 0x%x bytes from port 0x%x ...", length, port);
 
 
     switch (length) {
-    case 1:
-      ((uchar_t*)src)[0] = v3_inb(port);
-      break;
-    case 2:
-      ((ushort_t*)src)[0] = v3_inw(port);
-      break;
-    case 4:
-      ((uint_t*)src)[0] = v3_indw(port);
-      break;
-    default:
-      for (i = 0; i < length; i++) { 
-       ((uchar_t*)src)[i] = v3_inb(port);
-      }
+       case 1:
+           ((uchar_t*)src)[0] = v3_inb(port);
+           break;
+       case 2:
+           ((ushort_t*)src)[0] = v3_inw(port);
+           break;
+       case 4:
+           ((uint_t*)src)[0] = v3_indw(port);
+           break;
+       default:
+           for (i = 0; i < length; i++) { 
+               ((uchar_t*)src)[i] = v3_inb(port);
+           }
     }//switch length
 
-  PrintDebug(" done ... read 0x");
+    PrintDebug(" done ... read 0x");
 
-  for (i = 0; i < length; i++) { 
-    PrintDebug("%x", ((uchar_t*)src)[i]);
-  }
+    for (i = 0; i < length; i++) { 
+       PrintDebug("%x", ((uchar_t*)src)[i]);
+    }
 
-  PrintDebug("\n");
+    PrintDebug("\n");
 
-  return length;
+    return length;
 }
 
 static int generic_write_port_ignore(ushort_t port,
                                     void * src, 
                                     uint_t length,
                                     struct vm_device * dev) {
-  uint_t i;
+    uint_t i;
 
-  PrintDebug("generic: writing 0x");
+    PrintDebug("generic: writing 0x");
 
-  for (i = 0; i < length; i++) { 
-    PrintDebug("%x", ((uchar_t*)src)[i]);
-  }
+    for (i = 0; i < length; i++) { 
+       PrintDebug("%x", ((uchar_t*)src)[i]);
+    }
   
-  PrintDebug(" to port 0x%x ... ignored\n", port);
+    PrintDebug(" to port 0x%x ... ignored\n", port);
  
-  return length;
+    return length;
 }
 
 static int generic_read_port_ignore(ushort_t port,
@@ -188,194 +188,194 @@ static int generic_read_port_ignore(ushort_t port,
                                    uint_t length,
                                    struct vm_device * dev) {
 
-  PrintDebug("generic: reading 0x%x bytes from port 0x%x ...", length, port);
+    PrintDebug("generic: reading 0x%x bytes from port 0x%x ...", length, port);
 
-  memset((char*)src, 0, length);
-  PrintDebug(" ignored (return zeroed buffer)\n");
+    memset((char*)src, 0, length);
+    PrintDebug(" ignored (return zeroed buffer)\n");
 
-  return length;
+    return length;
 }
 
 
 
 static int generic_interrupt(uint_t irq, struct vm_device * dev) {
-  PrintDebug("generic: interrupt 0x%x - injecting into VM\n", irq);
+    PrintDebug("generic: interrupt 0x%x - injecting into VM\n", irq);
 
-  v3_raise_irq(dev->vm, irq);
+    v3_raise_irq(dev->vm, irq);
 
-  return 0;
+    return 0;
 }
 
 
 static int generic_init_device(struct vm_device * dev) {
-  struct generic_internal * state = (struct generic_internal *)(dev->private_data);
+    struct generic_internal * state = (struct generic_internal *)(dev->private_data);
 
-  PrintDebug("generic: init_device\n");
-  generic_reset_device(dev);
+    PrintDebug("generic: init_device\n");
+    generic_reset_device(dev);
 
 
-  if (PORT_HOOKS) { // This is a runtime conditional on a #define
-    struct port_range * tmp = NULL;
+    if (PORT_HOOKS) { // This is a runtime conditional on a #define
+       struct port_range * tmp = NULL;
 
-    list_for_each_entry(tmp, &(state->port_list), range_link) {
-      uint_t i = 0;
+       list_for_each_entry(tmp, &(state->port_list), range_link) {
+           uint_t i = 0;
       
-      PrintDebug("generic: hooking ports 0x%x to 0x%x as %x\n", 
-                tmp->start, tmp->end, 
-                (tmp->type == GENERIC_PRINT_AND_PASSTHROUGH) ? "print-and-passthrough" : "print-and-ignore");
+           PrintDebug("generic: hooking ports 0x%x to 0x%x as %x\n", 
+                      tmp->start, tmp->end, 
+                      (tmp->type == GENERIC_PRINT_AND_PASSTHROUGH) ? "print-and-passthrough" : "print-and-ignore");
       
-      for (i = tmp->start; i <= tmp->end; i++) { 
-       if (tmp->type == GENERIC_PRINT_AND_PASSTHROUGH) { 
+           for (i = tmp->start; i <= tmp->end; i++) { 
+               if (tmp->type == GENERIC_PRINT_AND_PASSTHROUGH) { 
          
-         if (v3_dev_hook_io(dev, i, &generic_read_port_passthrough, &generic_write_port_passthrough)) { 
-           PrintDebug("generic: can't hook port 0x%x (already hooked?)\n", i);
-         }
+                   if (v3_dev_hook_io(dev, i, &generic_read_port_passthrough, &generic_write_port_passthrough)) { 
+                       PrintDebug("generic: can't hook port 0x%x (already hooked?)\n", i);
+                   }
          
-       } else if (tmp->type == GENERIC_PRINT_AND_IGNORE) { 
+               } else if (tmp->type == GENERIC_PRINT_AND_IGNORE) { 
          
-         if (v3_dev_hook_io(dev, i, &generic_read_port_ignore, &generic_write_port_ignore)) { 
-           PrintDebug("generic: can't hook port 0x%x (already hooked?)\n", i);
-         }
-       } 
-      }
+                   if (v3_dev_hook_io(dev, i, &generic_read_port_ignore, &generic_write_port_ignore)) { 
+                       PrintDebug("generic: can't hook port 0x%x (already hooked?)\n", i);
+                   }
+               } 
+           }
 
+       }
+    } else {
+       PrintDebug("generic: hooking ports not supported\n");
     }
-  } else {
-    PrintDebug("generic: hooking ports not supported\n");
-  }
 
 
 
-  if (MEM_HOOKS) { // This is a runtime conditional on a #define
-    struct mem_range * tmp;
+    if (MEM_HOOKS) { // This is a runtime conditional on a #define
+       struct mem_range * tmp;
 
-    list_for_each_entry(tmp, &(state->mem_list), range_link) {
+       list_for_each_entry(tmp, &(state->mem_list), range_link) {
 
-      PrintDebug("generic: hooking addresses 0x%x to 0x%x\n", 
-                tmp->start, tmp->end); 
+           PrintDebug("generic: hooking addresses 0x%x to 0x%x\n", 
+                      tmp->start, tmp->end); 
       
       
-      if (v3_dev_hook_mem(dev, tmp->start, tmp->end)) {
-       PrintDebug("generic: Can't hook addresses 0x%x to 0x%x (already hooked?)\n",
-                  tmp->start, tmp->end); 
-      }
+           if (v3_dev_hook_mem(dev, tmp->start, tmp->end)) {
+               PrintDebug("generic: Can't hook addresses 0x%x to 0x%x (already hooked?)\n",
+                          tmp->start, tmp->end); 
+           }
+       }
+    } else {
+       PrintDebug("generic: hooking addresses not supported\n");
     }
-  } else {
-    PrintDebug("generic: hooking addresses not supported\n");
-  }
 
 
 
 
-  if (IRQ_HOOKS) { // This is a runtime conditional on a #define
-    struct irq_range * tmp;
+    if (IRQ_HOOKS) { // This is a runtime conditional on a #define
+       struct irq_range * tmp;
     
-    list_for_each_entry(tmp, &(state->irq_list), range_link) {
-      uint_t i;
+       list_for_each_entry(tmp, &(state->irq_list), range_link) {
+           uint_t i;
 
-      PrintDebug("generic: hooking irqs 0x%x to 0x%x\n",
-                tmp->start, tmp->end);
+           PrintDebug("generic: hooking irqs 0x%x to 0x%x\n",
+                      tmp->start, tmp->end);
       
-      for (i = tmp->start; i <= tmp->end; i++) { 
-       if (v3_dev_hook_irq(dev, i, &generic_interrupt)) { 
-         PrintDebug("generic: can't hook irq  0x%x (already hooked?)\n", i);
-       }
-      }
+           for (i = tmp->start; i <= tmp->end; i++) { 
+               if (v3_dev_hook_irq(dev, i, &generic_interrupt)) { 
+                   PrintDebug("generic: can't hook irq  0x%x (already hooked?)\n", i);
+               }
+           }
 
+       }
+    } else {
+       PrintDebug("generic: hooking irqs not supported\n");
     }
-  } else {
-    PrintDebug("generic: hooking irqs not supported\n");
-  }
 
 
 
-  return 0;
+    return 0;
 }
 
 static int generic_deinit_device(struct vm_device * dev) {
-  struct generic_internal * state = (struct generic_internal *)(dev->private_data);
+    struct generic_internal * state = (struct generic_internal *)(dev->private_data);
 
 
-  PrintDebug("generic: deinit_device\n");
+    PrintDebug("generic: deinit_device\n");
 
 
-  if (IRQ_HOOKS) { // This is a runtime conditional on a #define
-    struct irq_range * tmp;
-    struct irq_range * cur;
+    if (IRQ_HOOKS) { // This is a runtime conditional on a #define
+       struct irq_range * tmp;
+       struct irq_range * cur;
     
-    list_for_each_entry_safe(cur, tmp, &(state->irq_list), range_link) {
-      uint_t i;
+       list_for_each_entry_safe(cur, tmp, &(state->irq_list), range_link) {
+           uint_t i;
 
-      PrintDebug("generic: unhooking irqs 0x%x to 0x%x\n", 
-                cur->start, cur->end);
+           PrintDebug("generic: unhooking irqs 0x%x to 0x%x\n", 
+                      cur->start, cur->end);
       
 
-      for (i = cur->start; i <= cur->end; i++) { 
-       if (v3_dev_unhook_irq(dev, i)) {
-         PrintDebug("generic: can't unhook irq 0x%x (already unhooked?)\n", i);
-       }
-      }
+           for (i = cur->start; i <= cur->end; i++) { 
+               if (v3_dev_unhook_irq(dev, i)) {
+                   PrintDebug("generic: can't unhook irq 0x%x (already unhooked?)\n", i);
+               }
+           }
 
-      list_del(&(cur->range_link));
-      state->num_irq_ranges--;
-      V3_Free(cur);
+           list_del(&(cur->range_link));
+           state->num_irq_ranges--;
+           V3_Free(cur);
+       }
+    } else {
+       PrintDebug("generic: unhooking irqs not supported\n");
     }
-  } else {
-    PrintDebug("generic: unhooking irqs not supported\n");
-  }
 
 
-  if (MEM_HOOKS) {
-    struct mem_range * tmp;
-    struct mem_range * cur;
+    if (MEM_HOOKS) {
+       struct mem_range * tmp;
+       struct mem_range * cur;
     
-    list_for_each_entry_safe(cur, tmp, &(state->mem_list), range_link) {
+       list_for_each_entry_safe(cur, tmp, &(state->mem_list), range_link) {
 
-      PrintDebug("generic: unhooking addresses 0x%x to 0x%x\n",
-                cur->start, cur->end); 
+           PrintDebug("generic: unhooking addresses 0x%x to 0x%x\n",
+                      cur->start, cur->end); 
 
-      if (v3_dev_unhook_mem(dev, cur->start, cur->end)) {
-       PrintDebug("generic: Can't unhook addresses 0x%x to 0x%x (already unhooked?)\n",
-                  cur->start, cur->end); 
-      }
+           if (v3_dev_unhook_mem(dev, cur->start, cur->end)) {
+               PrintDebug("generic: Can't unhook addresses 0x%x to 0x%x (already unhooked?)\n",
+                          cur->start, cur->end); 
+           }
 
-      list_del(&(cur->range_link));
-      state->num_mem_ranges--;
-      V3_Free(cur);
+           list_del(&(cur->range_link));
+           state->num_mem_ranges--;
+           V3_Free(cur);
+       }
+    } else {
+       PrintDebug("generic: unhooking addresses not supported\n");
     }
-  } else {
-    PrintDebug("generic: unhooking addresses not supported\n");
-  }
   
 
-  if (PORT_HOOKS) {
-    struct port_range * tmp;
-    struct port_range * cur;
+    if (PORT_HOOKS) {
+       struct port_range * tmp;
+       struct port_range * cur;
     
-    list_for_each_entry_safe(cur, tmp, &(state->port_list), range_link) {
-      uint_t i;
+       list_for_each_entry_safe(cur, tmp, &(state->port_list), range_link) {
+           uint_t i;
 
-      PrintDebug("generic: unhooking ports 0x%x to 0x%x\n",
-                  cur->start, cur->end);
+           PrintDebug("generic: unhooking ports 0x%x to 0x%x\n",
+                      cur->start, cur->end);
                
-      for (i = cur->start; i <= cur->end; i++) {
-       if (v3_dev_unhook_io(dev, i)) {
-         PrintDebug("generic: can't unhook port 0x%x (already unhooked?)\n", i);
+           for (i = cur->start; i <= cur->end; i++) {
+               if (v3_dev_unhook_io(dev, i)) {
+                   PrintDebug("generic: can't unhook port 0x%x (already unhooked?)\n", i);
+               }
+           }
+
+           list_del(&(cur->range_link));
+           state->num_port_ranges--;
+           V3_Free(cur);
        }
-      }
-
-      list_del(&(cur->range_link));
-      state->num_port_ranges--;
-      V3_Free(cur);
+    } else {
+       PrintDebug("generic: unhooking ports not supported\n");
     }
-  } else {
-    PrintDebug("generic: unhooking ports not supported\n");
-  }
 
 
 
-  generic_reset_device(dev);
-  return 0;
+    generic_reset_device(dev);
+    return 0;
 }
 
 
@@ -383,11 +383,11 @@ static int generic_deinit_device(struct vm_device * dev) {
 
 
 static struct vm_device_ops dev_ops = { 
-  .init = generic_init_device, 
-  .deinit = generic_deinit_device,
-  .reset = generic_reset_device,
-  .start = generic_start_device,
-  .stop = generic_stop_device,
+    .init = generic_init_device, 
+    .deinit = generic_deinit_device,
+    .reset = generic_reset_device,
+    .start = generic_start_device,
+    .stop = generic_stop_device,
 };
 
 
@@ -395,84 +395,84 @@ static struct vm_device_ops dev_ops = {
 
 int v3_generic_add_port_range(struct vm_device * dev, uint_t start, uint_t end, uint_t type) {
 
-  if (PORT_HOOKS) {
-    struct generic_internal * state = (struct generic_internal *)(dev->private_data);
+    if (PORT_HOOKS) {
+       struct generic_internal * state = (struct generic_internal *)(dev->private_data);
 
-    struct port_range * range = (struct port_range *)V3_Malloc(sizeof(struct port_range));
-    range->start = start;
-    range->end = end;
-    range->type = type;
+       struct port_range * range = (struct port_range *)V3_Malloc(sizeof(struct port_range));
+       range->start = start;
+       range->end = end;
+       range->type = type;
     
       
-    PrintDebug("generic: Adding Port Range: 0x%x to 0x%x as %x\n", 
-              range->start, range->end, 
-              (range->type == GENERIC_PRINT_AND_PASSTHROUGH) ? "print-and-passthrough" : "print-and-ignore");
+       PrintDebug("generic: Adding Port Range: 0x%x to 0x%x as %x\n", 
+                  range->start, range->end, 
+                  (range->type == GENERIC_PRINT_AND_PASSTHROUGH) ? "print-and-passthrough" : "print-and-ignore");
     
-    list_add(&(range->range_link), &(state->port_list));
-    state->num_port_ranges++;
-  } else {
-    PrintDebug("generic: hooking IO ports not supported\n");
-    return -1;
-  }
-
-  return 0;
+       list_add(&(range->range_link), &(state->port_list));
+       state->num_port_ranges++;
+    } else {
+       PrintDebug("generic: hooking IO ports not supported\n");
+       return -1;
+    }
+
+    return 0;
 }
 
 int v3_generic_add_mem_range(struct vm_device * dev, void * start, void * end, uint_t type) {
 
-  if (MEM_HOOKS) {
-    struct generic_internal * state = (struct generic_internal *)(dev->private_data);
+    if (MEM_HOOKS) {
+       struct generic_internal * state = (struct generic_internal *)(dev->private_data);
     
-    struct mem_range * range = (struct mem_range *)V3_Malloc(sizeof(struct mem_range));
-    range->start = start;
-    range->end = end;
-    range->type = type;
+       struct mem_range * range = (struct mem_range *)V3_Malloc(sizeof(struct mem_range));
+       range->start = start;
+       range->end = end;
+       range->type = type;
     
-    list_add(&(range->range_link), &(state->port_list));
-    state->num_mem_ranges++;
-  } else {
-    PrintDebug("generic: hooking memory not supported\n");
-    return -1;
-  }
-
-  return 0;
+       list_add(&(range->range_link), &(state->port_list));
+       state->num_mem_ranges++;
+    } else {
+       PrintDebug("generic: hooking memory not supported\n");
+       return -1;
+    }
+
+    return 0;
 }
 
 
 int v3_generic_add_irq_range(struct vm_device * dev, uint_t start, uint_t end, uint_t type) {
 
-  if (IRQ_HOOKS) {
-    struct generic_internal * state = (struct generic_internal *)(dev->private_data);
+    if (IRQ_HOOKS) {
+       struct generic_internal * state = (struct generic_internal *)(dev->private_data);
     
-    struct irq_range * range = (struct irq_range *)V3_Malloc(sizeof(struct irq_range));
-    range->start = start;
-    range->end = end;
-    range->type = type;
+       struct irq_range * range = (struct irq_range *)V3_Malloc(sizeof(struct irq_range));
+       range->start = start;
+       range->end = end;
+       range->type = type;
     
-    list_add(&(range->range_link), &(state->port_list));
-    state->num_irq_ranges++;
-  } else {
-    PrintDebug("generic: hooking IRQs not supported\n");
-    return -1;
-  }
-
-  return 0;
+       list_add(&(range->range_link), &(state->port_list));
+       state->num_irq_ranges++;
+    } else {
+       PrintDebug("generic: hooking IRQs not supported\n");
+       return -1;
+    }
+
+    return 0;
 }
 
 
 
 struct vm_device * v3_create_generic() {
-  struct generic_internal * generic_state = (struct generic_internal *)V3_Malloc(sizeof(struct generic_internal));
+    struct generic_internal * generic_state = (struct generic_internal *)V3_Malloc(sizeof(struct generic_internal));
   
-  generic_state->num_port_ranges = 0;
-  generic_state->num_mem_ranges = 0;
-  generic_state->num_irq_ranges = 0;
+    generic_state->num_port_ranges = 0;
+    generic_state->num_mem_ranges = 0;
+    generic_state->num_irq_ranges = 0;
 
-  INIT_LIST_HEAD(&(generic_state->port_list));
-  INIT_LIST_HEAD(&(generic_state->mem_list));
-  INIT_LIST_HEAD(&(generic_state->irq_list));
+    INIT_LIST_HEAD(&(generic_state->port_list));
+    INIT_LIST_HEAD(&(generic_state->mem_list));
+    INIT_LIST_HEAD(&(generic_state->irq_list));
     
-  struct vm_device * device = v3_create_device("GENERIC", &dev_ops, generic_state);
+    struct vm_device * device = v3_create_device("GENERIC", &dev_ops, generic_state);
 
-  return device;
+    return device;
 }