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) 2008, Jack Lange <jarusl@cs.northwestern.edu>
11 * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org>
12 * All rights reserved.
14 * Author: Jack Lange <jarusl@cs.northwestern.edu>
16 * This is free software. You are permitted to use,
17 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
20 #include <palacios/vmm.h>
21 #include <palacios/vm_guest.h>
22 #include <palacios/vmm_dev_mgr.h>
23 #include <devices/pci.h>
25 #include <palacios/vmm_io.h>
28 // We Have to setup some sort of PIC interrupt mapping here....
31 struct vm_device * pci;
35 static int io_read(struct guest_info * core, ushort_t port, void * dst, uint_t length, void * priv_data) {
36 PrintError(core->vm_info, core, "Unhandled read on port %x\n", port);
40 static int io_write(struct guest_info * core, ushort_t port, void * src, uint_t length, void * priv_data) {
41 PrintError(core->vm_info, core, "Unhandled write on port %x\n", port);
49 static int i440_free(struct i440_state * state) {
51 // unregister from PCI
58 static struct v3_device_ops dev_ops = {
59 .free = (int (*)(void *))i440_free,
66 static int i440_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
67 struct pci_device * pci_dev = NULL;
68 struct v3_pci_bar bars[6];
70 struct i440_state * state = NULL;
71 struct vm_device * pci = v3_find_dev(vm, v3_cfg_val(cfg, "bus"));
72 char * dev_id = v3_cfg_val(cfg, "ID");
76 PrintError(vm, VCORE_NONE, "could not find PCI Device\n");
80 state = (struct i440_state *)V3_Malloc(sizeof(struct i440_state));
83 PrintError(vm, VCORE_NONE, "Cannot allocate state\n");
89 struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, state);
92 PrintError(vm, VCORE_NONE, "Could not attach device %s\n", dev_id);
97 for (i = 0; i < 4; i++) {
98 ret |= v3_dev_hook_io(dev, 0x0cf8 + i, &io_read, &io_write);
99 ret |= v3_dev_hook_io(dev, 0x0cfc + i, &io_read, &io_write);
104 PrintError(vm, VCORE_NONE, "Error hooking i440FX io ports\n");
105 v3_remove_device(dev);
110 for (i = 0; i < 6; i++) {
111 bars[i].type = PCI_BAR_NONE;
114 pci_dev = v3_pci_register_device(state->pci, PCI_STD_DEVICE,
115 0, 0, 0, "i440FX", bars,
116 NULL, NULL, NULL, NULL, state);
119 v3_remove_device(dev);
123 pci_dev->config_header.vendor_id = 0x8086;
124 pci_dev->config_header.device_id = 0x1237;
125 pci_dev->config_header.revision = 0x02;
126 pci_dev->config_header.subclass = 0x00; // SubClass: host2pci
127 pci_dev->config_header.class = PCI_CLASS_BRIDGE; // Class: PCI bridge
129 pci_dev->config_space[0x72] = 0x02; // SMRAM (?)
134 device_register("i440FX", i440_init);