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.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
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.
14 * Author: Jack Lange <jacklange@cs.pitt.edu>
16 * This is free software. You are permitted to use,
17 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
21 #include <interfaces/host_pci.h>
22 #include <palacios/vmm.h>
23 #include <palacios/vm_guest.h>
24 #include <palacios/vmm_mem.h>
28 static struct v3_host_pci_hooks * pci_hooks = NULL;
32 void V3_Init_Host_PCI(struct v3_host_pci_hooks * hooks) {
34 V3_Print(VM_NONE, VCORE_NONE, "V3 host PCI interface intialized\n");
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;
43 memset(region, 0, sizeof(struct v3_guest_mem_region));
46 PrintError(vm, VCORE_NONE, "Tried to get a menregion from a NULL vm pointer\n");
51 v3_reg = v3_get_base_region(vm, gpa);
57 region->start = v3_reg->host_addr;
58 region->end = v3_reg->host_addr + (v3_reg->guest_end - v3_reg->guest_start);
64 struct v3_host_pci_dev * v3_host_pci_get_dev(struct v3_vm_info * vm,
65 char * url, void * priv_data) {
67 struct v3_host_pci_dev * host_dev = NULL;
69 if ((!pci_hooks) || (!pci_hooks->request_device)) {
70 PrintError(vm, VCORE_NONE, "Host PCI Hooks not initialized\n");
74 host_dev = pci_hooks->request_device(url, vm);
76 if (host_dev == NULL) {
77 PrintError(vm, VCORE_NONE, "Could not find host PCI device (%s)\n", url);
81 host_dev->guest_data = priv_data;
88 int v3_host_pci_config_write(struct v3_host_pci_dev * v3_dev,
89 uint32_t reg_num, void * src,
92 if ((!pci_hooks) || (!pci_hooks->config_write)) {
93 PrintError(VM_NONE, VCORE_NONE, "Host PCI hooks not initialized\n");
97 return pci_hooks->config_write(v3_dev, reg_num, src, length);
101 int v3_host_pci_config_read(struct v3_host_pci_dev * v3_dev,
102 uint32_t reg_num, void * dst,
105 if ((!pci_hooks) || (!pci_hooks->config_read)) {
106 PrintError(VM_NONE, VCORE_NONE, "Host PCI hooks not initialized\n");
110 return pci_hooks->config_read(v3_dev, reg_num, dst, length);
113 int v3_host_pci_ack_irq(struct v3_host_pci_dev * v3_dev, uint32_t vec_index) {
115 if ((!pci_hooks) || (!pci_hooks->ack_irq)) {
116 PrintError(VM_NONE, VCORE_NONE, "Host PCI hooks not initialized\n");
120 return pci_hooks->ack_irq(v3_dev, vec_index);
125 int v3_host_pci_cmd_update(struct v3_host_pci_dev * v3_dev, pci_cmd_t cmd, uint64_t arg ) {
127 if ((!pci_hooks) || (!pci_hooks->pci_cmd)) {
128 PrintError(VM_NONE, VCORE_NONE, "Host PCI hooks not initialized\n");
132 return pci_hooks->pci_cmd(v3_dev, cmd, arg);
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");
145 return v3_dev->irq_handler(v3_dev->guest_data, vec_index);