vga.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. /*
  2. * linux/include/video/vga.h -- standard VGA chipset interaction
  3. *
  4. * Copyright 1999 Jeff Garzik <jgarzik@pobox.com>
  5. *
  6. * Copyright history from vga16fb.c:
  7. * Copyright 1999 Ben Pfaff and Petr Vandrovec
  8. * Based on VGA info at http://www.osdever.net/FreeVGA/home.htm
  9. * Based on VESA framebuffer (c) 1998 Gerd Knorr
  10. *
  11. * This file is subject to the terms and conditions of the GNU General
  12. * Public License. See the file COPYING in the main directory of this
  13. * archive for more details.
  14. *
  15. */
  16. #ifndef __linux_video_vga_h__
  17. #define __linux_video_vga_h__
  18. #include <linux/types.h>
  19. #include <linux/io.h>
  20. #include <asm/vga.h>
  21. #include <asm/byteorder.h>
  22. #define VGA_FB_PHYS_BASE 0xA0000 /* VGA framebuffer I/O base */
  23. #define VGA_FB_PHYS_SIZE 65536 /* VGA framebuffer I/O size */
  24. /* Some of the code below is taken from SVGAlib. The original,
  25. unmodified copyright notice for that code is below. */
  26. /* VGAlib version 1.2 - (c) 1993 Tommy Frandsen */
  27. /* */
  28. /* This library is free software; you can redistribute it and/or */
  29. /* modify it without any restrictions. This library is distributed */
  30. /* in the hope that it will be useful, but without any warranty. */
  31. /* Multi-chipset support Copyright 1993 Harm Hanemaayer */
  32. /* partially copyrighted (C) 1993 by Hartmut Schirmer */
  33. /* VGA data register ports */
  34. #define VGA_CRT_DC 0x3D5 /* CRT Controller Data Register - color emulation */
  35. #define VGA_CRT_DM 0x3B5 /* CRT Controller Data Register - mono emulation */
  36. #define VGA_ATT_R 0x3C1 /* Attribute Controller Data Read Register */
  37. #define VGA_ATT_W 0x3C0 /* Attribute Controller Data Write Register */
  38. #define VGA_GFX_D 0x3CF /* Graphics Controller Data Register */
  39. #define VGA_SEQ_D 0x3C5 /* Sequencer Data Register */
  40. #define VGA_MIS_R 0x3CC /* Misc Output Read Register */
  41. #define VGA_MIS_W 0x3C2 /* Misc Output Write Register */
  42. #define VGA_FTC_R 0x3CA /* Feature Control Read Register */
  43. #define VGA_IS1_RC 0x3DA /* Input Status Register 1 - color emulation */
  44. #define VGA_IS1_RM 0x3BA /* Input Status Register 1 - mono emulation */
  45. #define VGA_PEL_D 0x3C9 /* PEL Data Register */
  46. #define VGA_PEL_MSK 0x3C6 /* PEL mask register */
  47. /* EGA-specific registers */
  48. #define EGA_GFX_E0 0x3CC /* Graphics enable processor 0 */
  49. #define EGA_GFX_E1 0x3CA /* Graphics enable processor 1 */
  50. /* VGA index register ports */
  51. #define VGA_CRT_IC 0x3D4 /* CRT Controller Index - color emulation */
  52. #define VGA_CRT_IM 0x3B4 /* CRT Controller Index - mono emulation */
  53. #define VGA_ATT_IW 0x3C0 /* Attribute Controller Index & Data Write Register */
  54. #define VGA_GFX_I 0x3CE /* Graphics Controller Index */
  55. #define VGA_SEQ_I 0x3C4 /* Sequencer Index */
  56. #define VGA_PEL_IW 0x3C8 /* PEL Write Index */
  57. #define VGA_PEL_IR 0x3C7 /* PEL Read Index */
  58. /* standard VGA indexes max counts */
  59. #define VGA_CRT_C 0x19 /* Number of CRT Controller Registers */
  60. #define VGA_ATT_C 0x15 /* Number of Attribute Controller Registers */
  61. #define VGA_GFX_C 0x09 /* Number of Graphics Controller Registers */
  62. #define VGA_SEQ_C 0x05 /* Number of Sequencer Registers */
  63. #define VGA_MIS_C 0x01 /* Number of Misc Output Register */
  64. /* VGA misc register bit masks */
  65. #define VGA_MIS_COLOR 0x01
  66. #define VGA_MIS_ENB_MEM_ACCESS 0x02
  67. #define VGA_MIS_DCLK_28322_720 0x04
  68. #define VGA_MIS_ENB_PLL_LOAD (0x04 | 0x08)
  69. #define VGA_MIS_SEL_HIGH_PAGE 0x20
  70. /* VGA CRT controller register indices */
  71. #define VGA_CRTC_H_TOTAL 0
  72. #define VGA_CRTC_H_DISP 1
  73. #define VGA_CRTC_H_BLANK_START 2
  74. #define VGA_CRTC_H_BLANK_END 3
  75. #define VGA_CRTC_H_SYNC_START 4
  76. #define VGA_CRTC_H_SYNC_END 5
  77. #define VGA_CRTC_V_TOTAL 6
  78. #define VGA_CRTC_OVERFLOW 7
  79. #define VGA_CRTC_PRESET_ROW 8
  80. #define VGA_CRTC_MAX_SCAN 9
  81. #define VGA_CRTC_CURSOR_START 0x0A
  82. #define VGA_CRTC_CURSOR_END 0x0B
  83. #define VGA_CRTC_START_HI 0x0C
  84. #define VGA_CRTC_START_LO 0x0D
  85. #define VGA_CRTC_CURSOR_HI 0x0E
  86. #define VGA_CRTC_CURSOR_LO 0x0F
  87. #define VGA_CRTC_V_SYNC_START 0x10
  88. #define VGA_CRTC_V_SYNC_END 0x11
  89. #define VGA_CRTC_V_DISP_END 0x12
  90. #define VGA_CRTC_OFFSET 0x13
  91. #define VGA_CRTC_UNDERLINE 0x14
  92. #define VGA_CRTC_V_BLANK_START 0x15
  93. #define VGA_CRTC_V_BLANK_END 0x16
  94. #define VGA_CRTC_MODE 0x17
  95. #define VGA_CRTC_LINE_COMPARE 0x18
  96. #define VGA_CRTC_REGS VGA_CRT_C
  97. /* VGA CRT controller bit masks */
  98. #define VGA_CR11_LOCK_CR0_CR7 0x80 /* lock writes to CR0 - CR7 */
  99. #define VGA_CR17_H_V_SIGNALS_ENABLED 0x80
  100. /* VGA attribute controller register indices */
  101. #define VGA_ATC_PALETTE0 0x00
  102. #define VGA_ATC_PALETTE1 0x01
  103. #define VGA_ATC_PALETTE2 0x02
  104. #define VGA_ATC_PALETTE3 0x03
  105. #define VGA_ATC_PALETTE4 0x04
  106. #define VGA_ATC_PALETTE5 0x05
  107. #define VGA_ATC_PALETTE6 0x06
  108. #define VGA_ATC_PALETTE7 0x07
  109. #define VGA_ATC_PALETTE8 0x08
  110. #define VGA_ATC_PALETTE9 0x09
  111. #define VGA_ATC_PALETTEA 0x0A
  112. #define VGA_ATC_PALETTEB 0x0B
  113. #define VGA_ATC_PALETTEC 0x0C
  114. #define VGA_ATC_PALETTED 0x0D
  115. #define VGA_ATC_PALETTEE 0x0E
  116. #define VGA_ATC_PALETTEF 0x0F
  117. #define VGA_ATC_MODE 0x10
  118. #define VGA_ATC_OVERSCAN 0x11
  119. #define VGA_ATC_PLANE_ENABLE 0x12
  120. #define VGA_ATC_PEL 0x13
  121. #define VGA_ATC_COLOR_PAGE 0x14
  122. #define VGA_AR_ENABLE_DISPLAY 0x20
  123. /* VGA sequencer register indices */
  124. #define VGA_SEQ_RESET 0x00
  125. #define VGA_SEQ_CLOCK_MODE 0x01
  126. #define VGA_SEQ_PLANE_WRITE 0x02
  127. #define VGA_SEQ_CHARACTER_MAP 0x03
  128. #define VGA_SEQ_MEMORY_MODE 0x04
  129. /* VGA sequencer register bit masks */
  130. #define VGA_SR01_CHAR_CLK_8DOTS 0x01 /* bit 0: character clocks 8 dots wide are generated */
  131. #define VGA_SR01_SCREEN_OFF 0x20 /* bit 5: Screen is off */
  132. #define VGA_SR02_ALL_PLANES 0x0F /* bits 3-0: enable access to all planes */
  133. #define VGA_SR04_EXT_MEM 0x02 /* bit 1: allows complete mem access to 256K */
  134. #define VGA_SR04_SEQ_MODE 0x04 /* bit 2: directs system to use a sequential addressing mode */
  135. #define VGA_SR04_CHN_4M 0x08 /* bit 3: selects modulo 4 addressing for CPU access to display memory */
  136. /* VGA graphics controller register indices */
  137. #define VGA_GFX_SR_VALUE 0x00
  138. #define VGA_GFX_SR_ENABLE 0x01
  139. #define VGA_GFX_COMPARE_VALUE 0x02
  140. #define VGA_GFX_DATA_ROTATE 0x03
  141. #define VGA_GFX_PLANE_READ 0x04
  142. #define VGA_GFX_MODE 0x05
  143. #define VGA_GFX_MISC 0x06
  144. #define VGA_GFX_COMPARE_MASK 0x07
  145. #define VGA_GFX_BIT_MASK 0x08
  146. /* VGA graphics controller bit masks */
  147. #define VGA_GR06_GRAPHICS_MODE 0x01
  148. /* macro for composing an 8-bit VGA register index and value
  149. * into a single 16-bit quantity */
  150. #define VGA_OUT16VAL(v, r) (((v) << 8) | (r))
  151. /* decide whether we should enable the faster 16-bit VGA register writes */
  152. #ifdef __LITTLE_ENDIAN
  153. #define VGA_OUTW_WRITE
  154. #endif
  155. /* VGA State Save and Restore */
  156. #define VGA_SAVE_FONT0 1 /* save/restore plane 2 fonts */
  157. #define VGA_SAVE_FONT1 2 /* save/restore plane 3 fonts */
  158. #define VGA_SAVE_TEXT 4 /* save/restore plane 0/1 fonts */
  159. #define VGA_SAVE_FONTS 7 /* save/restore all fonts */
  160. #define VGA_SAVE_MODE 8 /* save/restore video mode */
  161. #define VGA_SAVE_CMAP 16 /* save/restore color map/DAC */
  162. struct vgastate {
  163. void __iomem *vgabase; /* mmio base, if supported */
  164. unsigned long membase; /* VGA window base, 0 for default - 0xA000 */
  165. __u32 memsize; /* VGA window size, 0 for default 64K */
  166. __u32 flags; /* what state[s] to save (see VGA_SAVE_*) */
  167. __u32 depth; /* current fb depth, not important */
  168. __u32 num_attr; /* number of att registers, 0 for default */
  169. __u32 num_crtc; /* number of crt registers, 0 for default */
  170. __u32 num_gfx; /* number of gfx registers, 0 for default */
  171. __u32 num_seq; /* number of seq registers, 0 for default */
  172. void *vidstate;
  173. };
  174. extern int save_vga(struct vgastate *state);
  175. extern int restore_vga(struct vgastate *state);
  176. static inline unsigned char vga_mm_r (void __iomem *regbase, unsigned short port)
  177. {
  178. return readb (regbase + port);
  179. }
  180. static inline void vga_mm_w (void __iomem *regbase, unsigned short port, unsigned char val)
  181. {
  182. writeb (val, regbase + port);
  183. }
  184. static inline void vga_mm_w_fast (void __iomem *regbase, unsigned short port,
  185. unsigned char reg, unsigned char val)
  186. {
  187. writew (VGA_OUT16VAL (val, reg), regbase + port);
  188. }
  189. /*
  190. * generic VGA port read/write
  191. */
  192. #ifdef CONFIG_HAS_IOPORT
  193. static inline unsigned char vga_io_r (unsigned short port)
  194. {
  195. return inb_p(port);
  196. }
  197. static inline void vga_io_w (unsigned short port, unsigned char val)
  198. {
  199. outb_p(val, port);
  200. }
  201. static inline void vga_io_w_fast (unsigned short port, unsigned char reg,
  202. unsigned char val)
  203. {
  204. outw(VGA_OUT16VAL (val, reg), port);
  205. }
  206. static inline unsigned char vga_r (void __iomem *regbase, unsigned short port)
  207. {
  208. if (regbase)
  209. return vga_mm_r (regbase, port);
  210. else
  211. return vga_io_r (port);
  212. }
  213. static inline void vga_w (void __iomem *regbase, unsigned short port, unsigned char val)
  214. {
  215. if (regbase)
  216. vga_mm_w (regbase, port, val);
  217. else
  218. vga_io_w (port, val);
  219. }
  220. static inline void vga_w_fast (void __iomem *regbase, unsigned short port,
  221. unsigned char reg, unsigned char val)
  222. {
  223. if (regbase)
  224. vga_mm_w_fast (regbase, port, reg, val);
  225. else
  226. vga_io_w_fast (port, reg, val);
  227. }
  228. #else /* CONFIG_HAS_IOPORT */
  229. static inline unsigned char vga_r (void __iomem *regbase, unsigned short port)
  230. {
  231. return vga_mm_r (regbase, port);
  232. }
  233. static inline void vga_w (void __iomem *regbase, unsigned short port, unsigned char val)
  234. {
  235. vga_mm_w (regbase, port, val);
  236. }
  237. static inline void vga_w_fast (void __iomem *regbase, unsigned short port,
  238. unsigned char reg, unsigned char val)
  239. {
  240. vga_mm_w_fast (regbase, port, reg, val);
  241. }
  242. #endif /* CONFIG_HAS_IOPORT */
  243. /*
  244. * VGA CRTC register read/write
  245. */
  246. static inline unsigned char vga_rcrt (void __iomem *regbase, unsigned char reg)
  247. {
  248. vga_w (regbase, VGA_CRT_IC, reg);
  249. return vga_r (regbase, VGA_CRT_DC);
  250. }
  251. static inline void vga_wcrt (void __iomem *regbase, unsigned char reg, unsigned char val)
  252. {
  253. #ifdef VGA_OUTW_WRITE
  254. vga_w_fast (regbase, VGA_CRT_IC, reg, val);
  255. #else
  256. vga_w (regbase, VGA_CRT_IC, reg);
  257. vga_w (regbase, VGA_CRT_DC, val);
  258. #endif /* VGA_OUTW_WRITE */
  259. }
  260. #ifdef CONFIG_HAS_IOPORT
  261. static inline unsigned char vga_io_rcrt (unsigned char reg)
  262. {
  263. vga_io_w (VGA_CRT_IC, reg);
  264. return vga_io_r (VGA_CRT_DC);
  265. }
  266. static inline void vga_io_wcrt (unsigned char reg, unsigned char val)
  267. {
  268. #ifdef VGA_OUTW_WRITE
  269. vga_io_w_fast (VGA_CRT_IC, reg, val);
  270. #else
  271. vga_io_w (VGA_CRT_IC, reg);
  272. vga_io_w (VGA_CRT_DC, val);
  273. #endif /* VGA_OUTW_WRITE */
  274. }
  275. #endif /* CONFIG_HAS_IOPORT */
  276. static inline unsigned char vga_mm_rcrt (void __iomem *regbase, unsigned char reg)
  277. {
  278. vga_mm_w (regbase, VGA_CRT_IC, reg);
  279. return vga_mm_r (regbase, VGA_CRT_DC);
  280. }
  281. static inline void vga_mm_wcrt (void __iomem *regbase, unsigned char reg, unsigned char val)
  282. {
  283. #ifdef VGA_OUTW_WRITE
  284. vga_mm_w_fast (regbase, VGA_CRT_IC, reg, val);
  285. #else
  286. vga_mm_w (regbase, VGA_CRT_IC, reg);
  287. vga_mm_w (regbase, VGA_CRT_DC, val);
  288. #endif /* VGA_OUTW_WRITE */
  289. }
  290. /*
  291. * VGA sequencer register read/write
  292. */
  293. static inline unsigned char vga_rseq (void __iomem *regbase, unsigned char reg)
  294. {
  295. vga_w (regbase, VGA_SEQ_I, reg);
  296. return vga_r (regbase, VGA_SEQ_D);
  297. }
  298. static inline void vga_wseq (void __iomem *regbase, unsigned char reg, unsigned char val)
  299. {
  300. #ifdef VGA_OUTW_WRITE
  301. vga_w_fast (regbase, VGA_SEQ_I, reg, val);
  302. #else
  303. vga_w (regbase, VGA_SEQ_I, reg);
  304. vga_w (regbase, VGA_SEQ_D, val);
  305. #endif /* VGA_OUTW_WRITE */
  306. }
  307. #ifdef CONFIG_HAS_IOPORT
  308. static inline unsigned char vga_io_rseq (unsigned char reg)
  309. {
  310. vga_io_w (VGA_SEQ_I, reg);
  311. return vga_io_r (VGA_SEQ_D);
  312. }
  313. static inline void vga_io_wseq (unsigned char reg, unsigned char val)
  314. {
  315. #ifdef VGA_OUTW_WRITE
  316. vga_io_w_fast (VGA_SEQ_I, reg, val);
  317. #else
  318. vga_io_w (VGA_SEQ_I, reg);
  319. vga_io_w (VGA_SEQ_D, val);
  320. #endif /* VGA_OUTW_WRITE */
  321. }
  322. #endif /* CONFIG_HAS_IOPORT */
  323. static inline unsigned char vga_mm_rseq (void __iomem *regbase, unsigned char reg)
  324. {
  325. vga_mm_w (regbase, VGA_SEQ_I, reg);
  326. return vga_mm_r (regbase, VGA_SEQ_D);
  327. }
  328. static inline void vga_mm_wseq (void __iomem *regbase, unsigned char reg, unsigned char val)
  329. {
  330. #ifdef VGA_OUTW_WRITE
  331. vga_mm_w_fast (regbase, VGA_SEQ_I, reg, val);
  332. #else
  333. vga_mm_w (regbase, VGA_SEQ_I, reg);
  334. vga_mm_w (regbase, VGA_SEQ_D, val);
  335. #endif /* VGA_OUTW_WRITE */
  336. }
  337. /*
  338. * VGA graphics controller register read/write
  339. */
  340. static inline unsigned char vga_rgfx (void __iomem *regbase, unsigned char reg)
  341. {
  342. vga_w (regbase, VGA_GFX_I, reg);
  343. return vga_r (regbase, VGA_GFX_D);
  344. }
  345. static inline void vga_wgfx (void __iomem *regbase, unsigned char reg, unsigned char val)
  346. {
  347. #ifdef VGA_OUTW_WRITE
  348. vga_w_fast (regbase, VGA_GFX_I, reg, val);
  349. #else
  350. vga_w (regbase, VGA_GFX_I, reg);
  351. vga_w (regbase, VGA_GFX_D, val);
  352. #endif /* VGA_OUTW_WRITE */
  353. }
  354. #ifdef CONFIG_HAS_IOPORT
  355. static inline unsigned char vga_io_rgfx (unsigned char reg)
  356. {
  357. vga_io_w (VGA_GFX_I, reg);
  358. return vga_io_r (VGA_GFX_D);
  359. }
  360. static inline void vga_io_wgfx (unsigned char reg, unsigned char val)
  361. {
  362. #ifdef VGA_OUTW_WRITE
  363. vga_io_w_fast (VGA_GFX_I, reg, val);
  364. #else
  365. vga_io_w (VGA_GFX_I, reg);
  366. vga_io_w (VGA_GFX_D, val);
  367. #endif /* VGA_OUTW_WRITE */
  368. }
  369. #endif /* CONFIG_HAS_IOPORT */
  370. static inline unsigned char vga_mm_rgfx (void __iomem *regbase, unsigned char reg)
  371. {
  372. vga_mm_w (regbase, VGA_GFX_I, reg);
  373. return vga_mm_r (regbase, VGA_GFX_D);
  374. }
  375. static inline void vga_mm_wgfx (void __iomem *regbase, unsigned char reg, unsigned char val)
  376. {
  377. #ifdef VGA_OUTW_WRITE
  378. vga_mm_w_fast (regbase, VGA_GFX_I, reg, val);
  379. #else
  380. vga_mm_w (regbase, VGA_GFX_I, reg);
  381. vga_mm_w (regbase, VGA_GFX_D, val);
  382. #endif /* VGA_OUTW_WRITE */
  383. }
  384. /*
  385. * VGA attribute controller register read/write
  386. */
  387. static inline unsigned char vga_rattr (void __iomem *regbase, unsigned char reg)
  388. {
  389. vga_w (regbase, VGA_ATT_IW, reg);
  390. return vga_r (regbase, VGA_ATT_R);
  391. }
  392. static inline void vga_wattr (void __iomem *regbase, unsigned char reg, unsigned char val)
  393. {
  394. vga_w (regbase, VGA_ATT_IW, reg);
  395. vga_w (regbase, VGA_ATT_W, val);
  396. }
  397. #ifdef CONFIG_HAS_IOPORT
  398. static inline unsigned char vga_io_rattr (unsigned char reg)
  399. {
  400. vga_io_w (VGA_ATT_IW, reg);
  401. return vga_io_r (VGA_ATT_R);
  402. }
  403. static inline void vga_io_wattr (unsigned char reg, unsigned char val)
  404. {
  405. vga_io_w (VGA_ATT_IW, reg);
  406. vga_io_w (VGA_ATT_W, val);
  407. }
  408. #endif /* CONFIG_HAS_IOPORT */
  409. static inline unsigned char vga_mm_rattr (void __iomem *regbase, unsigned char reg)
  410. {
  411. vga_mm_w (regbase, VGA_ATT_IW, reg);
  412. return vga_mm_r (regbase, VGA_ATT_R);
  413. }
  414. static inline void vga_mm_wattr (void __iomem *regbase, unsigned char reg, unsigned char val)
  415. {
  416. vga_mm_w (regbase, VGA_ATT_IW, reg);
  417. vga_mm_w (regbase, VGA_ATT_W, val);
  418. }
  419. #endif /* __linux_video_vga_h__ */