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.


Semi-functional SMP (boots Kitten guest with two cores)
[palacios.git] / palacios / src / devices / 8254.c
index c205752..a7c7398 100644 (file)
@@ -23,7 +23,7 @@
 #include <palacios/vmm_time.h>
 #include <palacios/vmm_util.h>
 #include <palacios/vmm_intr.h>
-
+#include <palacios/vmm_config.h>
 
 
 #ifndef CONFIG_DEBUG_PIT
@@ -231,8 +231,9 @@ static int handle_crystal_tics(struct vm_device * dev, struct channel * ch, uint
 }
                                
 
+#include <palacios/vm_guest.h>
 
-static void pit_update_time(ullong_t cpu_cycles, ullong_t cpu_freq, void * private_data) {
+static void pit_update_time(struct guest_info * info, ullong_t cpu_cycles, ullong_t cpu_freq, void * private_data) {
     struct vm_device * dev = (struct vm_device *)private_data;
     struct pit * state = (struct pit *)dev->private_data;
     //  ullong_t tmp_ctr = state->pit_counter;
@@ -296,7 +297,7 @@ static void pit_update_time(ullong_t cpu_cycles, ullong_t cpu_freq, void * priva
        if (handle_crystal_tics(dev, &(state->ch_0), oscillations) == 1) {
            // raise interrupt
            PrintDebug("8254 PIT: Injecting Timer interrupt to guest\n");
-           v3_raise_irq(dev->vm, 0);
+           v3_raise_irq(info->vm_info, 0);
        }
 
        //handle_crystal_tics(dev, &(state->ch_1), oscillations);
@@ -310,6 +311,12 @@ static void pit_update_time(ullong_t cpu_cycles, ullong_t cpu_freq, void * priva
 }
 
 
+static void pit_advance_time(struct guest_info * core, void * private_data) {
+
+    v3_raise_irq(core->vm_info, 0);
+}
+
+
 
 /* This should call out to handle_SQR_WAVE_write, etc...
  */
@@ -462,7 +469,7 @@ static int handle_channel_cmd(struct channel * ch, struct pit_cmd_word cmd) {
 
 
 
-static int pit_read_channel(ushort_t port, void * dst, uint_t length, struct vm_device * dev) {
+static int pit_read_channel(struct guest_info * core, ushort_t port, void * dst, uint_t length, struct vm_device * dev) {
     struct pit * state = (struct pit *)dev->private_data;
     char * val = (char *)dst;
 
@@ -502,7 +509,7 @@ static int pit_read_channel(ushort_t port, void * dst, uint_t length, struct vm_
 
 
 
-static int pit_write_channel(ushort_t port, void * src, uint_t length, struct vm_device * dev) {
+static int pit_write_channel(struct guest_info * core, ushort_t port, void * src, uint_t length, struct vm_device * dev) {
     struct pit * state = (struct pit *)dev->private_data;
     char val = *(char *)src;
 
@@ -544,7 +551,7 @@ static int pit_write_channel(ushort_t port, void * src, uint_t length, struct vm
 
 
 
-static int pit_write_command(ushort_t port, void * src, uint_t length, struct vm_device * dev) {
+static int pit_write_command(struct guest_info * core, ushort_t port, void * src, uint_t length, struct vm_device * dev) {
     struct pit * state = (struct pit *)dev->private_data;
     struct pit_cmd_word * cmd = (struct pit_cmd_word *)src;
 
@@ -592,6 +599,7 @@ static int pit_write_command(ushort_t port, void * src, uint_t length, struct vm
 
 static struct vm_timer_ops timer_ops = {
     .update_time = pit_update_time,
+    .advance_timer = pit_advance_time,
 };
 
 
@@ -630,10 +638,16 @@ static struct v3_device_ops dev_ops = {
 
 };
 
+#include <palacios/vm_guest.h>
 
-static int pit_init(struct guest_info * info, void * cfg_data) {
+static int pit_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
     struct pit * pit_state = NULL;
     struct vm_device * dev = NULL;
+    char * name = v3_cfg_val(cfg, "name");
+    
+    // PIT is only usable in non-multicore environments
+    // just hardcode the core context
+    struct guest_info * info = &(vm->cores[0]);
 
     uint_t cpu_khz = V3_CPU_KHZ();
     ullong_t reload_val = (ullong_t)cpu_khz * 1000;
@@ -641,10 +655,10 @@ static int pit_init(struct guest_info * info, void * cfg_data) {
     pit_state = (struct pit *)V3_Malloc(sizeof(struct pit));
     V3_ASSERT(pit_state != NULL);
 
-    dev = v3_allocate_device("PIT", &dev_ops, pit_state);
+    dev = v3_allocate_device(name, &dev_ops, pit_state);
 
-    if (v3_attach_device(info, dev) == -1) {
-       PrintError("Could not attach device %s\n", "PIT");
+    if (v3_attach_device(vm, dev) == -1) {
+       PrintError("Could not attach device %s\n", name);
        return -1;
     }
 
@@ -655,10 +669,11 @@ static int pit_init(struct guest_info * info, void * cfg_data) {
 
 #ifdef CONFIG_DEBUG_PIT
     PrintDebug("8254 PIT: OSC_HZ=%d, reload_val=", OSC_HZ);
-    PrintTraceLL(reload_val);
+    //PrintTrace(reload_val);
     PrintDebug("\n");
 #endif
 
+    
     v3_add_timer(info, &timer_ops, dev);
 
     // Get cpu frequency and calculate the global pit oscilattor counter/cycle
@@ -675,7 +690,7 @@ static int pit_init(struct guest_info * info, void * cfg_data) {
 
 #ifdef CONFIG_DEBUG_PIT
     PrintDebug("8254 PIT: CPU MHZ=%d -- pit count=", cpu_khz / 1000);
-    PrintTraceLL(pit_state->pit_counter);
+    //PrintTraceLL(pit_state->pit_counter);
     PrintDebug("\n");
 #endif