1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 #include <linux/io.h>
4 #include <linux/console.h>
5 
6 #include <drm/drm_crtc.h>
7 #include <drm/drm_crtc_helper.h>
8 #include <drm/drm_encoder.h>
9 #include <drm/drm_fb_helper.h>
10 #include <drm/drm_gem.h>
11 #include <drm/drm_gem_vram_helper.h>
12 #include <drm/drm_simple_kms_helper.h>
13 #include <drm/drm_vram_mm_helper.h>
14 
15 /* ---------------------------------------------------------------------- */
16 
17 #define VBE_DISPI_IOPORT_INDEX           0x01CE
18 #define VBE_DISPI_IOPORT_DATA            0x01CF
19 
20 #define VBE_DISPI_INDEX_ID               0x0
21 #define VBE_DISPI_INDEX_XRES             0x1
22 #define VBE_DISPI_INDEX_YRES             0x2
23 #define VBE_DISPI_INDEX_BPP              0x3
24 #define VBE_DISPI_INDEX_ENABLE           0x4
25 #define VBE_DISPI_INDEX_BANK             0x5
26 #define VBE_DISPI_INDEX_VIRT_WIDTH       0x6
27 #define VBE_DISPI_INDEX_VIRT_HEIGHT      0x7
28 #define VBE_DISPI_INDEX_X_OFFSET         0x8
29 #define VBE_DISPI_INDEX_Y_OFFSET         0x9
30 #define VBE_DISPI_INDEX_VIDEO_MEMORY_64K 0xa
31 
32 #define VBE_DISPI_ID0                    0xB0C0
33 #define VBE_DISPI_ID1                    0xB0C1
34 #define VBE_DISPI_ID2                    0xB0C2
35 #define VBE_DISPI_ID3                    0xB0C3
36 #define VBE_DISPI_ID4                    0xB0C4
37 #define VBE_DISPI_ID5                    0xB0C5
38 
39 #define VBE_DISPI_DISABLED               0x00
40 #define VBE_DISPI_ENABLED                0x01
41 #define VBE_DISPI_GETCAPS                0x02
42 #define VBE_DISPI_8BIT_DAC               0x20
43 #define VBE_DISPI_LFB_ENABLED            0x40
44 #define VBE_DISPI_NOCLEARMEM             0x80
45 
46 /* ---------------------------------------------------------------------- */
47 
48 enum bochs_types {
49 	BOCHS_QEMU_STDVGA,
50 	BOCHS_UNKNOWN,
51 };
52 
53 struct bochs_device {
54 	/* hw */
55 	void __iomem   *mmio;
56 	int            ioports;
57 	void __iomem   *fb_map;
58 	unsigned long  fb_base;
59 	unsigned long  fb_size;
60 	unsigned long  qext_size;
61 
62 	/* mode */
63 	u16 xres;
64 	u16 yres;
65 	u16 yres_virtual;
66 	u32 stride;
67 	u32 bpp;
68 	struct edid *edid;
69 
70 	/* drm */
71 	struct drm_device *dev;
72 	struct drm_simple_display_pipe pipe;
73 	struct drm_connector connector;
74 };
75 
76 /* ---------------------------------------------------------------------- */
77 
78 /* bochs_hw.c */
79 int bochs_hw_init(struct drm_device *dev);
80 void bochs_hw_fini(struct drm_device *dev);
81 
82 void bochs_hw_setmode(struct bochs_device *bochs,
83 		      struct drm_display_mode *mode);
84 void bochs_hw_setformat(struct bochs_device *bochs,
85 			const struct drm_format_info *format);
86 void bochs_hw_setbase(struct bochs_device *bochs,
87 		      int x, int y, int stride, u64 addr);
88 int bochs_hw_load_edid(struct bochs_device *bochs);
89 
90 /* bochs_mm.c */
91 int bochs_mm_init(struct bochs_device *bochs);
92 void bochs_mm_fini(struct bochs_device *bochs);
93 
94 /* bochs_kms.c */
95 int bochs_kms_init(struct bochs_device *bochs);
96 void bochs_kms_fini(struct bochs_device *bochs);
97 
98 /* bochs_fbdev.c */
99 extern const struct drm_mode_config_funcs bochs_mode_funcs;
100