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.


e945b92a7e9eaf85aee8b67abdeb7f2d31872f72
[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("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) {
41
42     if (!vm) {
43         PrintError("Tried to get a nenregion from a NULL vm pointer\n");
44         return -1;
45     }
46
47
48     region->start = vm->mem_map.base_region.host_addr;
49     region->end = vm->mem_map.base_region.host_addr + (vm->mem_map.base_region.guest_end - vm->mem_map.base_region.guest_start);
50
51     return 0;
52 }
53
54
55 struct v3_host_pci_dev * v3_host_pci_get_dev(struct v3_vm_info * vm, 
56                                              char * url, void * priv_data) {
57
58     struct v3_host_pci_dev * host_dev = NULL;
59
60     if ((!pci_hooks) || (!pci_hooks->request_device)) {
61         PrintError("Host PCI Hooks not initialized\n");
62         return NULL;
63     }
64
65     host_dev = pci_hooks->request_device(url, vm);
66
67     if (host_dev == NULL) {
68         PrintError("Could not find host PCI device (%s)\n", url);
69         return NULL;
70     }
71
72     host_dev->guest_data = priv_data;
73     
74     return host_dev;
75     
76 }
77
78
79 int v3_host_pci_config_write(struct v3_host_pci_dev * v3_dev, 
80                              uint32_t reg_num, void * src, 
81                              uint32_t length) {
82
83     if ((!pci_hooks) || (!pci_hooks->config_write)) {
84         PrintError("Host PCI hooks not initialized\n");
85         return -1;
86     }
87
88     return pci_hooks->config_write(v3_dev, reg_num, src, length);
89 }
90
91
92 int v3_host_pci_config_read(struct v3_host_pci_dev * v3_dev, 
93                              uint32_t reg_num, void * dst, 
94                              uint32_t length) {
95
96     if ((!pci_hooks) || (!pci_hooks->config_read)) {
97         PrintError("Host PCI hooks not initialized\n");
98         return -1;
99     }
100
101     return pci_hooks->config_read(v3_dev, reg_num, dst, length);
102 }
103
104 int v3_host_pci_ack_irq(struct v3_host_pci_dev * v3_dev, uint32_t vec_index) {
105
106     if ((!pci_hooks) || (!pci_hooks->ack_irq)) {
107         PrintError("Host PCI hooks not initialized\n");
108         return -1;
109     }
110
111     return pci_hooks->ack_irq(v3_dev, vec_index);
112 }
113
114
115
116 int v3_host_pci_cmd_update(struct v3_host_pci_dev * v3_dev, pci_cmd_t cmd, uint64_t arg ) {
117
118     if ((!pci_hooks) || (!pci_hooks->pci_cmd)) {
119         PrintError("Host PCI hooks not initialized\n");
120         return -1;
121     }
122
123     return pci_hooks->pci_cmd(v3_dev, cmd, arg);
124 }
125
126
127
128
129
130 int V3_host_pci_raise_irq(struct v3_host_pci_dev * v3_dev, uint32_t vec_index) {
131     if (!v3_dev->irq_handler) {
132         PrintError("No interrupt registerd for host pci device\n");
133         return -1;
134     }
135
136     return v3_dev->irq_handler(v3_dev->guest_data, vec_index);
137 }
138