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.


bug fixes for:
[palacios.git] / palacios / src / devices / apic.c
1 /* 
2  * This file is part of the Palacios Virtual Machine Monitor developed
3  * by the V3VEE Project with funding from the United States National 
4  * Science Foundation and the Department of Energy.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
10  * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu> 
11  * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author: Jack Lange <jarusl@cs.northwestern.edu>
15  *
16  * This is free software.  You are permitted to use,
17  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
18  */
19
20
21 #include <devices/apic.h>
22 #include <palacios/vmm.h>
23 #include <palacios/vmm_msr.h>
24
25 #define BASE_ADDR_MSR 0x0000001B
26 #define DEFAULT_BASE_ADDR 0xfee00000
27
28
29 struct apic_base_addr_reg {
30   uchar_t rsvd;
31   uint_t bsc           : 1;
32   uint_t rsvd2         : 2;
33   uint_t apic_enable   : 1;
34   ullong_t base_addr   : 40;
35   uint_t rsvd3         : 12;
36 } __attribute__((packed));
37
38 struct apic_state {
39   addr_t base_addr;
40
41   v3_msr_t base_addr_reg;
42
43   
44
45 };
46
47
48 static int read_apic_msr(uint_t msr, v3_msr_t * dst, void * priv_data) {
49   struct vm_device * dev = (struct vm_device *)priv_data;
50   struct apic_state * apic = (struct apic_state *)dev->private_data;
51   PrintDebug("READING APIC BASE ADDR: HI=%x LO=%x\n", apic->base_addr_reg.hi, apic->base_addr_reg.lo);
52
53   return -1;
54 }
55
56
57 static int write_apic_msr(uint_t msr, v3_msr_t src, void * priv_data) {
58   //  struct vm_device * dev = (struct vm_device *)priv_data;
59   //  struct apic_state * apic = (struct apic_state *)dev->private_data;
60
61   PrintDebug("WRITING APIC BASE ADDR: HI=%x LO=%x\n", src.hi, src.lo);
62
63   return -1;
64 }
65
66
67 static int apic_read(addr_t guest_addr, void * dst, uint_t length, void * priv_data) {
68   PrintDebug("Read from apic address space\n");
69   return -1;
70 }
71
72
73 static int apic_write(addr_t guest_addr, void * dst, uint_t length, void * priv_data) {
74   PrintDebug("Write to apic address space\n");
75   return -1;
76 }
77
78
79 static int apic_deinit(struct vm_device * dev) {
80   struct guest_info * info = dev->vm;
81
82   v3_unhook_msr(info, BASE_ADDR_MSR);
83
84   return 0;
85 }
86
87
88 static int apic_init(struct vm_device * dev) {
89   struct guest_info * info = dev->vm;
90   struct apic_state * apic = (struct apic_state *)(dev->private_data);
91
92   apic->base_addr = DEFAULT_BASE_ADDR;
93
94   v3_hook_msr(info, BASE_ADDR_MSR, read_apic_msr, write_apic_msr, dev);
95
96   v3_hook_full_mem(info, DEFAULT_BASE_ADDR, DEFAULT_BASE_ADDR + PAGE_SIZE_4KB, apic_read, apic_write, dev);
97
98   return 0;
99 }
100
101
102
103 static struct vm_device_ops dev_ops = {
104   .init = apic_init,
105   .deinit = apic_deinit,
106   .reset = NULL,
107   .start = NULL,
108   .stop = NULL,
109 };
110
111
112 struct vm_device * v3_create_apic() {
113   PrintDebug("Creating APIC\n");
114
115   struct apic_state * apic = (struct apic_state *)V3_Malloc(sizeof(struct apic_state));
116
117   struct vm_device * device = v3_create_device("APIC", &dev_ops, apic);
118   
119   return device;
120 }