xref: /kvmtool/x86/ioport.c (revision b0822113d5247df6cf21e8097d9b4b51a7e2a18e)
1af7b0868SMatt Evans #include "kvm/ioport.h"
2af7b0868SMatt Evans 
3af7b0868SMatt Evans #include <stdlib.h>
4ce08f2afSPekka Enberg #include <stdio.h>
5af7b0868SMatt Evans 
6af7b0868SMatt Evans static bool debug_io_out(struct ioport *ioport, struct kvm *kvm, u16 port, void *data, int size)
7af7b0868SMatt Evans {
8*b0822113SSasha Levin 	return 0;
9af7b0868SMatt Evans }
10af7b0868SMatt Evans 
11af7b0868SMatt Evans static struct ioport_operations debug_ops = {
12af7b0868SMatt Evans 	.io_out		= debug_io_out,
13af7b0868SMatt Evans };
14af7b0868SMatt Evans 
15ce08f2afSPekka Enberg static bool seabios_debug_io_out(struct ioport *ioport, struct kvm *kvm, u16 port, void *data, int size)
16ce08f2afSPekka Enberg {
17ce08f2afSPekka Enberg 	char ch;
18ce08f2afSPekka Enberg 
19ce08f2afSPekka Enberg 	ch = ioport__read8(data);
20ce08f2afSPekka Enberg 
21ce08f2afSPekka Enberg 	putchar(ch);
22ce08f2afSPekka Enberg 
23ce08f2afSPekka Enberg 	return true;
24ce08f2afSPekka Enberg }
25ce08f2afSPekka Enberg 
26ce08f2afSPekka Enberg static struct ioport_operations seabios_debug_ops = {
27ce08f2afSPekka Enberg 	.io_out		= seabios_debug_io_out,
28ce08f2afSPekka Enberg };
29ce08f2afSPekka Enberg 
30af7b0868SMatt Evans static bool dummy_io_in(struct ioport *ioport, struct kvm *kvm, u16 port, void *data, int size)
31af7b0868SMatt Evans {
32af7b0868SMatt Evans 	return true;
33af7b0868SMatt Evans }
34af7b0868SMatt Evans 
35af7b0868SMatt Evans static bool dummy_io_out(struct ioport *ioport, struct kvm *kvm, u16 port, void *data, int size)
36af7b0868SMatt Evans {
37af7b0868SMatt Evans 	return true;
38af7b0868SMatt Evans }
39af7b0868SMatt Evans 
40af7b0868SMatt Evans static struct ioport_operations dummy_read_write_ioport_ops = {
41af7b0868SMatt Evans 	.io_in		= dummy_io_in,
42af7b0868SMatt Evans 	.io_out		= dummy_io_out,
43af7b0868SMatt Evans };
44af7b0868SMatt Evans 
45af7b0868SMatt Evans static struct ioport_operations dummy_write_only_ioport_ops = {
46af7b0868SMatt Evans 	.io_out		= dummy_io_out,
47af7b0868SMatt Evans };
48af7b0868SMatt Evans 
494346fd8fSSasha Levin void ioport__setup_arch(struct kvm *kvm)
50af7b0868SMatt Evans {
51af7b0868SMatt Evans 	/* Legacy ioport setup */
52af7b0868SMatt Evans 
53af7b0868SMatt Evans 	/* 0x0020 - 0x003F - 8259A PIC 1 */
544346fd8fSSasha Levin 	ioport__register(kvm, 0x0020, &dummy_read_write_ioport_ops, 2, NULL);
55af7b0868SMatt Evans 
56af7b0868SMatt Evans 	/* PORT 0040-005F - PIT - PROGRAMMABLE INTERVAL TIMER (8253, 8254) */
574346fd8fSSasha Levin 	ioport__register(kvm, 0x0040, &dummy_read_write_ioport_ops, 4, NULL);
58af7b0868SMatt Evans 
59af7b0868SMatt Evans 	/* 0x00A0 - 0x00AF - 8259A PIC 2 */
604346fd8fSSasha Levin 	ioport__register(kvm, 0x00A0, &dummy_read_write_ioport_ops, 2, NULL);
61af7b0868SMatt Evans 
62af7b0868SMatt Evans 	/* PORT 00E0-00EF are 'motherboard specific' so we use them for our
63af7b0868SMatt Evans 	   internal debugging purposes.  */
644346fd8fSSasha Levin 	ioport__register(kvm, IOPORT_DBG, &debug_ops, 1, NULL);
65af7b0868SMatt Evans 
66af7b0868SMatt Evans 	/* PORT 00ED - DUMMY PORT FOR DELAY??? */
674346fd8fSSasha Levin 	ioport__register(kvm, 0x00ED, &dummy_write_only_ioport_ops, 1, NULL);
68af7b0868SMatt Evans 
69af7b0868SMatt Evans 	/* 0x00F0 - 0x00FF - Math co-processor */
704346fd8fSSasha Levin 	ioport__register(kvm, 0x00F0, &dummy_write_only_ioport_ops, 2, NULL);
71af7b0868SMatt Evans 
72af7b0868SMatt Evans 	/* PORT 03D4-03D5 - COLOR VIDEO - CRT CONTROL REGISTERS */
734346fd8fSSasha Levin 	ioport__register(kvm, 0x03D4, &dummy_read_write_ioport_ops, 1, NULL);
744346fd8fSSasha Levin 	ioport__register(kvm, 0x03D5, &dummy_write_only_ioport_ops, 1, NULL);
75ce08f2afSPekka Enberg 
764346fd8fSSasha Levin 	ioport__register(kvm, 0x402, &seabios_debug_ops, 1, NULL);
77af7b0868SMatt Evans }
78