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.


Added devices, device manager, and nvram device
[palacios.git] / palacios / src / devices / nvram.c
1 #include <devices/nvram.h>
2 #include <palacios/vmm.h>
3 #include <palacios/vmm_types.h>
4
5 extern struct vmm_os_hooks *os_hooks;
6
7
8 #define NVRAM_REG_PORT  0x70
9 #define NVRAM_DATA_PORT 0x71
10
11
12
13 typedef enum {NVRAM_READY,NVRAM_REG_POSTED} nvram_state_t;
14
15
16 #define NVRAM_REG_MAX   256
17
18
19 // These are borrowed from Bochs, which borrowed from
20 // Ralf Brown's interupt list
21 #define NVRAM_REG_SEC                     0x00
22 #define NVRAM_REG_SEC_ALARM               0x01
23 #define NVRAM_REG_MIN                     0x02
24 #define NVRAM_REG_MIN_ALARM               0x03
25 #define NVRAM_REG_HOUR                    0x04
26 #define NVRAM_REG_HOUR_ALARM              0x05
27 #define NVRAM_REG_WEEK_DAY                0x06
28 #define NVRAM_REG_MONTH_DAY               0x07
29 #define NVRAM_REG_MONTH                   0x08
30 #define NVRAM_REG_YEAR                    0x09
31 #define NVRAM_REG_STAT_A                  0x0a
32 #define NVRAM_REG_STAT_B                  0x0b
33 #define NVRAM_REG_STAT_C                  0x0c
34 #define NVRAM_REG_STAT_D                  0x0d
35 #define NVRAM_REG_DIAGNOSTIC_STATUS       0x0e  
36 #define NVRAM_REG_SHUTDOWN_STATUS         0x0f
37 #define NVRAM_REG_EQUIPMENT_BYTE          0x14
38 #define NVRAM_REG_CSUM_HIGH               0x2e
39 #define NVRAM_REG_CSUM_LOW                0x2f
40 #define NVRAM_REG_IBM_CENTURY_BYTE        0x32  
41 #define NVRAM_REG_IBM_PS2_CENTURY_BYTE    0x37  
42
43
44
45 struct nvram_internal {
46   nvram_state_t dev_state;
47   uchar_t       thereg;
48   uchar_t       mem_state[NVRAM_REG_MAX];
49 };
50
51
52
53
54
55 int nvram_reset_device(struct vm_device *dev)
56 {
57   struct nvram_internal *data = (struct nvram_internal *) dev->private_data;
58   
59   data->dev_state = NVRAM_READY;
60   data->thereg=0;
61   
62   return 0;
63
64 }
65
66 int nvram_init_device(struct vm_device *dev, struct vm_guest *vm)
67 {
68   struct nvram_internal *data = (struct nvram_internal *) dev->private_data;
69  
70   memset(data->mem_state,0,NVRAM_REG_MAX);
71
72   nvram_reset_device(dev);
73
74   // hook ports
75   dev_mgr_hook_io(dev->vm, 
76                   dev,
77                   NVRAM_REG_PORT,
78                   DEVICE_EMULATED,
79                   DEVICE_WRITE);
80
81   dev_mgr_hook_io(dev->vm, 
82                   dev,
83                   NVRAM_DATA_PORT,
84                   DEVICE_EMULATED,
85                   DEVICE_READWRITE);
86
87   return 0;
88 }
89
90 int nvram_deinit_device(struct vm_device *dev)
91 {
92
93   nvram_reset_device(dev);
94   
95   dev_mgr_unhook_device(dev->vm,dev);
96
97   return 0;
98 }
99
100
101
102
103
104
105 int nvram_start_device(struct vm_device *dev)
106 {
107   return 0;
108 }
109
110
111 int nvram_stop_device(struct vm_device *dev)
112 {
113   return 0;
114 }
115
116
117
118 int nvram_read_io_port(ushort_t port_read,
119                        void   *address, 
120                        uint_t length,
121                        struct vm_device *dev)
122 {
123   struct nvram_internal *data = (struct nvram_internal *) dev->private_data;
124
125   switch (port_read) { 
126   case NVRAM_REG_PORT:
127     // nonsense
128     memset(address,0,length);
129     break;
130   case NVRAM_DATA_PORT:
131     memcpy(address,&(data->mem_state[data->thereg]),1);
132     break;
133   default:
134     //bad
135     return -1;
136   }
137   return 0;
138 }
139
140 int nvram_write_io_port(ushort_t port_written,
141                         void   *address, 
142                         uint_t length,
143                         struct vm_device *dev)
144 {
145   struct nvram_internal *data = (struct nvram_internal *) dev->private_data;
146
147   switch (port_written) { 
148   case NVRAM_REG_PORT:
149     memcpy(&(data->thereg),address,1);
150     break;
151   case NVRAM_DATA_PORT:
152     memcpy(&(data->mem_state[data->thereg]),address,1);
153     break;
154   default:
155     //bad
156     return -1;
157   }
158   return 0;
159 }
160
161 int nvram_read_mapped_memory(void   *address_read,
162                              void   *address, 
163                              uint_t length,
164                              struct vm_device *dev)
165 {
166   return -1;
167
168 }
169
170 int nvram_write_mapped_memory(void   *address_written,
171                               void   *address, 
172                               uint_t length,
173                               struct vm_device *dev)
174 {
175   return -1;
176 }
177
178
179 static struct vm_device nvram_template = 
180   { .init_device = nvram_init_device, 
181     .deinit_device = nvram_deinit_device,
182     .reset_device = nvram_reset_device,
183     .start_device = nvram_start_device,
184     .stop_device = nvram_stop_device,
185     .read_io_port = nvram_read_io_port,
186     .write_io_port = nvram_write_io_port,
187     .read_mapped_memory = nvram_read_mapped_memory,
188     .write_mapped_memory= nvram_write_mapped_memory,
189   };
190
191
192
193 struct vm_device *nvram_create()
194 {
195   struct vm_device *device = os_hooks->malloc(sizeof(struct vm_device));
196
197   *device = nvram_template;
198
199   device->private_data = os_hooks->malloc(sizeof(struct nvram_internal));
200
201   return device;
202 }