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) {
43 PrintError(vm, VCORE_NONE, "Tried to get a menregion from a NULL vm pointer\n");
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);
55 struct v3_host_pci_dev * v3_host_pci_get_dev(struct v3_vm_info * vm,
56 char * url, void * priv_data) {
58 struct v3_host_pci_dev * host_dev = NULL;
60 if ((!pci_hooks) || (!pci_hooks->request_device)) {
61 PrintError(vm, VCORE_NONE, "Host PCI Hooks not initialized\n");
65 host_dev = pci_hooks->request_device(url, vm);
67 if (host_dev == NULL) {
68 PrintError(vm, VCORE_NONE, "Could not find host PCI device (%s)\n", url);
72 host_dev->guest_data = priv_data;
79 int v3_host_pci_config_write(struct v3_host_pci_dev * v3_dev,
80 uint32_t reg_num, void * src,
83 if ((!pci_hooks) || (!pci_hooks->config_write)) {
84 PrintError(VM_NONE, VCORE_NONE, "Host PCI hooks not initialized\n");
88 return pci_hooks->config_write(v3_dev, reg_num, src, length);
92 int v3_host_pci_config_read(struct v3_host_pci_dev * v3_dev,
93 uint32_t reg_num, void * dst,
96 if ((!pci_hooks) || (!pci_hooks->config_read)) {
97 PrintError(VM_NONE, VCORE_NONE, "Host PCI hooks not initialized\n");
101 return pci_hooks->config_read(v3_dev, reg_num, dst, length);
104 int v3_host_pci_ack_irq(struct v3_host_pci_dev * v3_dev, uint32_t vec_index) {
106 if ((!pci_hooks) || (!pci_hooks->ack_irq)) {
107 PrintError(VM_NONE, VCORE_NONE, "Host PCI hooks not initialized\n");
111 return pci_hooks->ack_irq(v3_dev, vec_index);
116 int v3_host_pci_cmd_update(struct v3_host_pci_dev * v3_dev, pci_cmd_t cmd, uint64_t arg ) {
118 if ((!pci_hooks) || (!pci_hooks->pci_cmd)) {
119 PrintError(VM_NONE, VCORE_NONE, "Host PCI hooks not initialized\n");
123 return pci_hooks->pci_cmd(v3_dev, cmd, arg);
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(VM_NONE, VCORE_NONE, "No interrupt registerd for host pci device\n");
136 return v3_dev->irq_handler(v3_dev->guest_data, vec_index);