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.


more device free updates
[palacios.git] / palacios / src / devices / i440fx.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) 2008, Jack Lange <jarusl@cs.northwestern.edu> 
11  * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author: Jack Lange <jarusl@cs.northwestern.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 #include <palacios/vmm.h>
21 #include <palacios/vmm_dev_mgr.h>
22 #include <devices/pci.h>
23
24 #include <palacios/vmm_io.h>
25
26
27 // We Have to setup some sort of PIC interrupt mapping here....
28
29 struct i440_state {
30     struct vm_device * pci;
31 };
32
33
34 static int io_read(struct guest_info * core, ushort_t port, void * dst, uint_t length, void * priv_data) {
35     //    struct vm_device * dev = priv_data;
36     PrintError("Unhandled read on port %x\n", port);
37     return -1;
38 }
39
40 static int io_write(struct guest_info * core, ushort_t port, void * src, uint_t length, void * priv_data) {
41     //    struct vm_device * dev = priv_data;
42     PrintError("Unhandled write on port %x\n", port);
43     return -1;
44 }
45
46
47
48
49
50 static int i440_free(struct vm_device * dev) {
51     struct i440_state * state = dev->private_data;
52     int i;
53
54     for (i = 0; i < 4; i++) {
55         v3_unhook_io_port(dev->vm, 0x0cf8 + i);
56         v3_unhook_io_port(dev->vm, 0x0cfc + i);
57     }
58
59     // unregister from PCI
60
61     V3_Free(state);
62
63     return 0;
64 }
65
66 static struct v3_device_ops dev_ops = {
67     .free = i440_free,
68     .reset = NULL,
69     .start = NULL,
70     .stop = NULL,
71 };
72
73
74
75
76 static int i440_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
77     struct pci_device * pci_dev = NULL;
78     struct v3_pci_bar bars[6];
79     int i;
80     struct i440_state * state = NULL;
81     struct vm_device * pci = v3_find_dev(vm, v3_cfg_val(cfg, "bus"));
82     char * dev_id = v3_cfg_val(cfg, "ID");
83
84     if (!pci) {
85         PrintError("could not find PCI Device\n");
86         return -1;
87     }
88
89     state = (struct i440_state *)V3_Malloc(sizeof(struct i440_state));
90
91     state->pci = pci;
92         
93     struct vm_device * dev = v3_allocate_device(dev_id, &dev_ops, state);
94
95     if (v3_attach_device(vm, dev) == -1) {
96         PrintError("Could not attach device %s\n", dev_id);
97         V3_Free(state);
98         return -1;
99     }
100
101     for (i = 0; i < 4; i++) {
102         v3_hook_io_port(vm, 0x0cf8 + i, &io_read, &io_write, dev);
103         v3_hook_io_port(vm, 0x0cfc + i, &io_read, &io_write, dev);
104     }
105
106     for (i = 0; i < 6; i++) {
107         bars[i].type = PCI_BAR_NONE;
108     }    
109
110     pci_dev = v3_pci_register_device(state->pci, PCI_STD_DEVICE, 
111                                      0, 0, 0, "i440FX", bars,
112                                      NULL, NULL, NULL, dev);
113
114     if (!pci_dev) {
115         v3_detach_device(dev);
116         return -1;
117     }
118
119     pci_dev->config_header.vendor_id = 0x8086;
120     pci_dev->config_header.device_id = 0x1237;
121     pci_dev->config_header.revision = 0x02;
122     pci_dev->config_header.subclass = 0x00; //  SubClass: host2pci
123     pci_dev->config_header.class = PCI_CLASS_BRIDGE;    // Class: PCI bridge
124
125     pci_dev->config_space[0x72] = 0x02; // SMRAM (?)
126
127     return 0;
128 }
129
130 device_register("i440FX", i440_init);