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.


lot of changes
[palacios.git] / palacios / src / devices / 8254.c
1 #include <devices/8254.h>
2 #include <palacios/vmm.h>
3 #include <palacios/vmm_time.h>
4
5 // constants
6 #define OSC_HZ 1193182
7
8
9 /* The 8254 has three counters and one control port */
10 #define CHANNEL0_PORT 0x40
11 #define CHANNEL1_PORT 0x41
12 #define CHANNEL2_PORT 0x42
13 #define COMMAND_PORT 0x43
14
15
16 #define PIT_INTR_NUM 0
17
18 /* The order of these typedefs is important because the numerical values correspond to the 
19  * values coming from the io ports
20  */
21 typedef enum {NOT_RUNNING, WAITING_LOBYTE, WAITING_HIBYTE, RUNNING} channel_access_state_t;
22 typedef enum {LATCH_COUNT, LOBYTE_ONLY, HIBYTE_ONLY, LOBYTE_HIBYTE} channel_access_mode_t;
23 typedef enum {IRQ_ON_TERM_CNT, ONE_SHOT, RATE_GEN, SQR_WAVE, SW_STROBE, HW_STROBE} channel_op_mode_t;
24
25
26 struct channel {
27   channel_access_mode_t access_mode;
28   channel_access_state_t access_state;
29
30   channel_op_mode_t op_mode;
31
32   // Time til interrupt trigger 
33   ullong_t ns;
34
35   uint_t ctr;
36   uint_t prg_ctr;
37 };
38
39
40 struct pit {
41
42   struct channel ch_0;
43   struct channel ch_1;
44   struct channel ch_2;
45 };
46
47 struct pit_cmd {
48   uint_t channel     : 2;
49   uint_t access_mode : 2;
50   uint_t op_mode     : 3;
51   uint_t bcd_mode    : 1;
52 };
53
54
55
56
57
58
59 static void pit_update_time(ullong_t cpu_cycles, ullong_t cpu_freq, void * private_data) {
60
61   return;
62 }
63
64
65
66 static int pit_read_channel(ushort_t port, void * dst, uint_t length, struct vm_device * dev) {
67   PrintDebug("8254 PIT: Read of PIT Channel %d\n", port - CHANNEL0_PORT);
68   return length;
69 }
70
71
72
73 static int pit_write_channel(ushort_t port, void * src, uint_t length, struct vm_device * dev) {
74   PrintDebug("8254 PIT: Write to PIT Channel %d\n", port - CHANNEL0_PORT);
75   return length;
76 }
77
78
79 static int pit_write_command(ushort_t port, void * src, uint_t length, struct vm_device * dev) {
80   struct pit * state = (struct pit *)dev->private_data;
81   struct pit_cmd * cmd = (struct pit_cmd *)src;
82
83   PrintDebug("8254 PIT: Write to PIT Command port\n");
84
85   if (length != 1) {
86     PrintDebug("8254 PIT: Write of Invalid length to command port\n");
87     return -1;
88   }
89
90   switch (cmd->channel) {
91   case 0:
92     state->ch_0.op_mode = cmd->op_mode;
93     break;
94   case 1:
95     break;
96   case 2:
97     break;
98   default:
99     break;
100   }
101
102
103   return length;
104 }
105
106
107
108
109 static struct vm_timer_ops timer_ops = {
110   .update_time = pit_update_time,
111 };
112
113
114 static int pit_init(struct vm_device * dev) {
115   dev_hook_io(dev, CHANNEL0_PORT, &pit_read_channel, &pit_write_channel);
116   dev_hook_io(dev, CHANNEL1_PORT, &pit_read_channel, &pit_write_channel);
117   dev_hook_io(dev, CHANNEL2_PORT, &pit_read_channel, &pit_write_channel);
118   dev_hook_io(dev, COMMAND_PORT, NULL, &pit_write_command);
119
120
121   v3_add_timer(dev->vm, &timer_ops, dev);
122
123   return 0;
124 }
125
126 static int pit_deinit(struct vm_device * dev) {
127
128   return 0;
129 }
130
131
132 static struct vm_device_ops dev_ops = {
133   .init = pit_init,
134   .deinit = pit_deinit,
135   .reset = NULL,
136   .start = NULL,
137   .stop = NULL,
138
139 };
140
141
142 struct vm_device * create_pit() {
143   struct pit * pit_state = NULL;
144   pit_state = (struct pit *)V3_Malloc(sizeof(struct pit));
145   V3_ASSERT(pit_state != NULL);
146
147   struct vm_device * dev = create_device("PIT", &dev_ops, pit_state);
148   
149   return dev;
150 }