summaryrefslogtreecommitdiff
path: root/kvm_i8254.h
blob: 31da46b2009c1a16cb6cc26b948c786cd8d3e694 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef __KVM_I8254_H
#define __KVM_I8254_H

#include "kvm_iodev.h"
#include "kvm_timer.h"

typedef struct kvm_kpit_channel_state {
	uint32_t count; /* can be 65536 */
	uint16_t latched_count;
	uint8_t count_latched;
	uint8_t status_latched;
	uint8_t status;
	uint8_t read_state;
	uint8_t write_state;
	uint8_t write_latch;
	uint8_t rw_mode;
	uint8_t mode;
	uint8_t bcd; /* not supported */
	uint8_t gate; /* timer start */
	hrtime_t count_load_time;
} kvm_kpit_channel_state_t;

typedef struct kvm_kpit_state {
	struct kvm_kpit_channel_state channels[3];
	uint32_t flags;
	struct kvm_timer pit_timer;
	int is_periodic;
	uint32_t    speaker_data_on;
	kmutex_t lock;
	struct kvm_pit *pit;
	kmutex_t inject_lock;
	unsigned long irq_ack;
	struct kvm_irq_ack_notifier irq_ack_notifier;
} kvm_kpit_state_t;

typedef struct kvm_pit {
	unsigned long base_addresss;
	struct kvm_io_device dev;
	struct kvm_io_device speaker_dev;
	struct kvm *kvm;
	struct kvm_kpit_state pit_state;
	int irq_source_id;
	struct kvm_irq_mask_notifier mask_notifier;
} kvm_pit_t;

#define KVM_PIT_BASE_ADDRESS	    0x40
#define KVM_SPEAKER_BASE_ADDRESS    0x61
#define KVM_PIT_MEM_LENGTH	    4
#define KVM_PIT_FREQ		    1193181
#define KVM_MAX_PIT_INTR_INTERVAL   HZ / 100
#define KVM_PIT_CHANNEL_MASK	    0x3

extern void kvm_inject_pit_timer_irqs(struct kvm_vcpu *);
extern void kvm_pit_load_count(struct kvm *, int, uint32_t, boolean_t);
extern struct kvm_pit *kvm_create_pit(struct kvm *, uint32_t);
extern void kvm_free_pit(struct kvm *);
extern void kvm_pit_reset(struct kvm_pit *);

#endif