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.


Update to the device framework.
[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 struct i440_state {
25     struct vm_device * pci;
26 };
27
28
29 static int io_read(ushort_t port, void * dst, uint_t length, struct vm_device * dev) {
30     PrintError("Unhandled read on port %x\n", port);
31     return -1;
32 }
33
34 static int io_write(ushort_t port, void * src, uint_t length, struct vm_device * dev) {
35     PrintError("Unhandled write on port %x\n", port);
36     return -1;
37 }
38
39
40
41
42
43 static int i440_free(struct vm_device * dev) {
44     return 0;
45 }
46
47 static struct v3_device_ops dev_ops = {
48     .free = i440_free,
49     .reset = NULL,
50     .start = NULL,
51     .stop = NULL,
52 };
53
54
55
56
57 static int i440_init(struct guest_info * vm, void * cfg_data) {
58     struct pci_device * pci_dev = NULL;
59     struct v3_pci_bar bars[6];
60     int i;
61     struct i440_state * state = NULL;
62     struct vm_device * pci = v3_find_dev(vm, (char *)cfg_data);
63
64     if (!pci) {
65         PrintError("could not find PCI Device\n");
66         return -1;
67     }
68
69     state = (struct i440_state *)V3_Malloc(sizeof(struct i440_state));
70
71     state->pci = pci;
72         
73     struct vm_device * dev = v3_allocate_device("i440FX", &dev_ops, state);
74
75     if (v3_attach_device(vm, dev) == -1) {
76         PrintError("Could not attach device %s\n", "i440FX");
77         return -1;
78     }
79
80
81     for (i = 0; i < 4; i++) {
82         v3_dev_hook_io(dev, 0x0cf8 + i,
83                        &io_read, &io_write);
84         v3_dev_hook_io(dev, 0x0cfc + i,
85                        &io_read, &io_write);
86     }
87
88     for (i = 0; i < 6; i++) {
89         bars[i].type = PCI_BAR_NONE;
90     }    
91
92     pci_dev = v3_pci_register_device(state->pci, PCI_STD_DEVICE, 0, 0, 0, "i440FX", bars,
93                                      NULL, NULL, NULL, dev);
94
95     if (!pci_dev) {
96         return -1;
97     }
98
99     pci_dev->config_header.vendor_id = 0x8086;
100     pci_dev->config_header.device_id = 0x1237;
101     pci_dev->config_header.revision = 0x02;
102     pci_dev->config_header.subclass = 0x00; //  SubClass: host2pci
103     pci_dev->config_header.class = PCI_CLASS_BRIDGE;    // Class: PCI bridge
104
105     pci_dev->config_space[0x72] = 0x02; // SMRAM (?)
106
107     return 0;
108 }
109
110 device_register("i440FX", i440_init)