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.


*** empty log message ***
[palacios.git] / palacios / src / palacios / vmm_intr.c
1 #include <palacios/vmm_intr.h>
2 #include <palacios/vmm.h>
3
4 #include <palacios/vm_guest.h>
5
6
7 void init_interrupt_state(struct guest_info * info) {
8   info->intr_state.excp_pending = 0;
9   info->intr_state.excp_num = 0;
10   info->intr_state.excp_error_code = 0;
11
12   info->vm_ops.raise_irq = &v3_raise_irq;
13 }
14
15 void set_intr_controller(struct guest_info * info, struct intr_ctrl_ops * ops, void * state) {
16   info->intr_state.controller = ops;
17   info->intr_state.controller_state = state;
18 }
19
20
21
22
23
24
25
26
27
28 int hook_irq(struct guest_info * info, int irq) {
29   extern struct vmm_os_hooks * os_hooks;
30
31   return os_hooks->hook_interrupt(info, irq);
32 }
33
34 int raise_exception_with_error(struct guest_info * info, uint_t excp, uint_t error_code) {
35   struct vm_intr * intr_state = &(info->intr_state);
36
37   if (intr_state->excp_pending == 0) {
38     intr_state->excp_pending = 1;
39     intr_state->excp_num = excp;
40     intr_state->excp_error_code = error_code;
41     intr_state->excp_error_code_valid = 1;
42     PrintDebug("Raising exception with error code: %x\n", error_code);
43   } else {
44     PrintDebug("exception already pending, currently not implemented\n");
45     return -1;
46   }
47
48   return 0;
49 }
50
51 int raise_exception(struct guest_info * info, uint_t excp) {
52   struct vm_intr * intr_state = &(info->intr_state);
53
54   if (intr_state->excp_pending == 0) {
55     intr_state->excp_pending = 1;
56     intr_state->excp_num = excp;
57     intr_state->excp_error_code = 0;
58     intr_state->excp_error_code_valid = 0;
59   } else {
60     PrintDebug("exception already pending, currently not implemented\n");
61     return -1;
62   }
63
64   return 0;
65 }
66
67
68 int v3_raise_irq(struct guest_info * info, int irq) {
69   // Look up PIC and resend
70   V3_ASSERT(info);
71   V3_ASSERT(info->intr_state.controller);
72   V3_ASSERT(info->intr_state.controller->raise_intr);
73
74   //  if ((info->intr_state.controller) && 
75   //  (info->intr_state.controller->raise_intr)) {
76     info->intr_state.controller->raise_intr(info->intr_state.controller_state, irq);
77     //} else {
78     // PrintDebug("There is no registered Interrupt Controller... (NULL POINTER)\n");
79     // return -1;
80     //}
81   return 0;
82 }
83
84
85
86
87
88
89
90
91
92
93
94 int intr_pending(struct guest_info * info) {
95   struct vm_intr * intr_state = &(info->intr_state);
96
97   if (intr_state->excp_pending == 1) {
98     return 1;
99   } else if (intr_state->controller->intr_pending(intr_state->controller_state) == 1) {
100     return 1;
101   }
102
103   /* Check [A]PIC */
104
105   return 0;
106 }
107
108
109 uint_t get_intr_number(struct guest_info * info) {
110   struct vm_intr * intr_state = &(info->intr_state);
111
112   if (intr_state->excp_pending == 1) {
113     return intr_state->excp_num;
114   } else if (intr_state->controller->intr_pending(intr_state->controller_state)) {
115     return intr_state->controller->get_intr_number(intr_state->controller_state);
116   }
117
118   /* someway to get the [A]PIC intr */
119
120   return 0;
121 }
122
123
124 intr_type_t get_intr_type(struct guest_info * info) {
125  struct vm_intr * intr_state = &(info->intr_state);
126
127   if (intr_state->excp_pending) {
128     return EXCEPTION;
129   } else if (intr_state->controller->intr_pending(intr_state->controller_state)) {
130     return EXTERNAL_IRQ;
131   }
132
133   return INVALID_INTR;
134 }
135
136
137
138
139
140
141 int injecting_intr(struct guest_info * info, uint_t intr_num, intr_type_t type) {
142   struct vm_intr * intr_state = &(info->intr_state);
143
144   if (type == EXCEPTION) {
145
146     intr_state->excp_pending = 0;
147     intr_state->excp_num = 0;
148     intr_state->excp_error_code = 0;
149     intr_state->excp_error_code_valid = 0;
150     
151   } else if (type == EXTERNAL_IRQ) {
152     return intr_state->controller->begin_irq(intr_state->controller_state, intr_num);
153   }
154
155   return 0;
156 }