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.


updated host pci interface to support non-contiguous memory regions
[palacios.git] / palacios / src / interfaces / host_pci.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) 2012, Jack Lange <jacklange@cs.pitt.edu>
11  * Copyright (c) 2012, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author: Jack Lange <jacklange@cs.pitt.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 <interfaces/host_pci.h>
22 #include <palacios/vmm.h>
23 #include <palacios/vm_guest.h>
24 #include <palacios/vmm_mem.h>
25
26
27
28 static struct v3_host_pci_hooks * pci_hooks = NULL;
29
30
31
32 void V3_Init_Host_PCI(struct v3_host_pci_hooks * hooks) {
33     pci_hooks = hooks;
34     V3_Print(VM_NONE, VCORE_NONE, "V3 host PCI interface intialized\n");
35     return;
36 }
37
38
39 /* This is ugly and should be abstracted out to a function in the memory manager */
40 int V3_get_guest_mem_region(struct v3_vm_info * vm, struct v3_guest_mem_region * region, uint64_t gpa) {
41     struct v3_mem_region * v3_reg = NULL;
42     
43     memset(region, 0, sizeof(struct v3_guest_mem_region));
44
45     if (!vm) {
46         PrintError(vm, VCORE_NONE, "Tried to get a menregion from a NULL vm pointer\n");
47         return -1;
48     }
49
50
51     v3_reg = v3_get_base_region(vm, gpa);
52
53     if (v3_reg == NULL) {
54         return 0;
55     }
56
57     region->start = v3_reg->host_addr;
58     region->end = v3_reg->host_addr + (v3_reg->guest_end - v3_reg->guest_start);
59
60     return 1;
61 }
62
63
64 struct v3_host_pci_dev * v3_host_pci_get_dev(struct v3_vm_info * vm, 
65                                              char * url, void * priv_data) {
66
67     struct v3_host_pci_dev * host_dev = NULL;
68
69     if ((!pci_hooks) || (!pci_hooks->request_device)) {
70         PrintError(vm, VCORE_NONE, "Host PCI Hooks not initialized\n");
71         return NULL;
72     }
73
74     host_dev = pci_hooks->request_device(url, vm);
75
76     if (host_dev == NULL) {
77         PrintError(vm, VCORE_NONE, "Could not find host PCI device (%s)\n", url);
78         return NULL;
79     }
80
81     host_dev->guest_data = priv_data;
82     
83     return host_dev;
84     
85 }
86
87
88 int v3_host_pci_config_write(struct v3_host_pci_dev * v3_dev, 
89                              uint32_t reg_num, void * src, 
90                              uint32_t length) {
91
92     if ((!pci_hooks) || (!pci_hooks->config_write)) {
93         PrintError(VM_NONE, VCORE_NONE, "Host PCI hooks not initialized\n");
94         return -1;
95     }
96
97     return pci_hooks->config_write(v3_dev, reg_num, src, length);
98 }
99
100
101 int v3_host_pci_config_read(struct v3_host_pci_dev * v3_dev, 
102                              uint32_t reg_num, void * dst, 
103                              uint32_t length) {
104
105     if ((!pci_hooks) || (!pci_hooks->config_read)) {
106         PrintError(VM_NONE, VCORE_NONE, "Host PCI hooks not initialized\n");
107         return -1;
108     }
109
110     return pci_hooks->config_read(v3_dev, reg_num, dst, length);
111 }
112
113 int v3_host_pci_ack_irq(struct v3_host_pci_dev * v3_dev, uint32_t vec_index) {
114
115     if ((!pci_hooks) || (!pci_hooks->ack_irq)) {
116         PrintError(VM_NONE, VCORE_NONE, "Host PCI hooks not initialized\n");
117         return -1;
118     }
119
120     return pci_hooks->ack_irq(v3_dev, vec_index);
121 }
122
123
124
125 int v3_host_pci_cmd_update(struct v3_host_pci_dev * v3_dev, pci_cmd_t cmd, uint64_t arg ) {
126
127     if ((!pci_hooks) || (!pci_hooks->pci_cmd)) {
128         PrintError(VM_NONE, VCORE_NONE, "Host PCI hooks not initialized\n");
129         return -1;
130     }
131
132     return pci_hooks->pci_cmd(v3_dev, cmd, arg);
133 }
134
135
136
137
138
139 int V3_host_pci_raise_irq(struct v3_host_pci_dev * v3_dev, uint32_t vec_index) {
140     if (!v3_dev->irq_handler) {
141         PrintError(VM_NONE, VCORE_NONE, "No interrupt registerd for host pci device\n");
142         return -1;
143     }
144
145     return v3_dev->irq_handler(v3_dev->guest_data, vec_index);
146 }
147