Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

715 lines
12 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. fsvga.h
  5. Abstract:
  6. This is the console fullscreen driver for the VGA card.
  7. Environment:
  8. kernel mode only
  9. Notes:
  10. Revision History:
  11. --*/
  12. #ifndef _FSVGA_
  13. #define _FSVGA_
  14. #include "stdarg.h"
  15. #include "stdio.h"
  16. #include "ntddk.h"
  17. #include "ntddvdeo.h"
  18. #include "vga.h"
  19. #include "fsvgalog.h"
  20. #define FSVGA_POOL_TAG 'gVsF'
  21. #undef ExAllocatePool
  22. #define ExAllocatePool(Type, Bytes) ExAllocatePoolWithTag(Type, Bytes, FSVGA_POOL_TAG)
  23. //
  24. // Define the default number of elements in the class input data queue.
  25. //
  26. #define DUMP_COUNT 4
  27. #define DEFAULT_DEBUG_LEVEL 0
  28. //
  29. // Define the i8042 controller input/output ports.
  30. //
  31. typedef enum _VGA_IO_PORT_TYPE {
  32. CRTCAddressPortColor = 0,
  33. CRTCDataPortColor,
  34. GRAPHAddressPort,
  35. SEQAddressPort,
  36. MaximumPortCount
  37. } VGA_IO_PORT_TYPE;
  38. typedef struct _PORT_LIST {
  39. PVOID Port;
  40. ULONG Length;
  41. BOOLEAN MapRegistersRequired;
  42. } PORT_LIST, *PPORT_LIST;
  43. //
  44. // FSVGA configuration information.
  45. //
  46. typedef struct _FSVGA_CONFIGURATION_INFORMATION {
  47. USHORT EmulationMode;
  48. #define ENABLE_WORD_WRITE_VRAM 0x01
  49. USHORT HardwareCursor;
  50. #define NO_HARDWARE_CURSOR 0
  51. #define HARDWARE_CURSOR 0x01
  52. USHORT HardwareScroll;
  53. #define NO_HARDWARE_SCROLL 0
  54. #define HARDWARE_SCROLL 0x01
  55. #define USE_LINE_COMPARE 0x02
  56. #define OFFSET_128_TO_NEXT_SLICE 0x04
  57. USHORT IOPort;
  58. } FSVGA_CONFIGURATION_INFORMATION, *PFSVGA_CONFIGURATION_INFORMATION;
  59. //
  60. // FSVGA resource information.
  61. //
  62. typedef struct _FSVGA_RESOURCE_INFORMATION {
  63. //
  64. // Indicate which hardware is actually present (display).
  65. //
  66. ULONG HardwarePresent;
  67. #ifdef RESOURCE_REQUIREMENTS
  68. //
  69. // Bus interface type.
  70. //
  71. INTERFACE_TYPE InterfaceType;
  72. //
  73. // Bus Number.
  74. //
  75. ULONG BusNumber;
  76. #endif
  77. //
  78. // The mapped addresses for this device's registers.
  79. //
  80. PORT_LIST PortList[MaximumPortCount];
  81. } FSVGA_RESOURCE_INFORMATION, *PFSVGA_RESOURCE_INFORMATION;
  82. //
  83. // EMULATE_BUFFER_INFORMATION structure
  84. //
  85. typedef struct _EMULATE_BUFFER_INFORMATION {
  86. //
  87. // Hardware scroll
  88. //
  89. USHORT StartAddress;
  90. USHORT LineCompare;
  91. USHORT PrevLineCompare;
  92. USHORT BytePerLine;
  93. USHORT MaxScanLine;
  94. ULONG LimitGRAM;
  95. #define LIMIT_64K 0x10000L
  96. USHORT DeltaNextFontRow;
  97. //
  98. // Color Attributes for last access.
  99. //
  100. UCHAR ColorFg;
  101. UCHAR ColorBg;
  102. //
  103. // Cursor position and attributes for last access.
  104. VIDEO_CURSOR_ATTRIBUTES CursorAttributes;
  105. FSVIDEO_CURSOR_POSITION CursorPosition;
  106. BOOLEAN ShowCursor;
  107. } EMULATE_BUFFER_INFORMATION, *PEMULATE_BUFFER_INFORMATION;
  108. //
  109. // Port device extension.
  110. //
  111. typedef struct _DEVICE_EXTENSION {
  112. //
  113. // Pointer to the device object.
  114. //
  115. PDEVICE_OBJECT DeviceObject;
  116. //
  117. // Next lower driver in same stack.
  118. //
  119. PDEVICE_OBJECT LowerDeviceObject;
  120. //
  121. // Use count on this device.
  122. //
  123. LONG usage;
  124. //
  125. // Set when okay to remove this device.
  126. //
  127. KEVENT evRemove;
  128. //
  129. // TRUE if we're trying to remove this device.
  130. //
  131. BOOLEAN removing;
  132. //
  133. // TRUE if device has been started.
  134. //
  135. BOOLEAN started;
  136. //
  137. // Port resource information.
  138. //
  139. FSVGA_RESOURCE_INFORMATION Resource;
  140. //
  141. // FSVIDEO_MODE_INFORMATION structure for the current mode
  142. //
  143. FSVIDEO_MODE_INFORMATION CurrentMode;
  144. //
  145. // FSVIDEO_SCREEN_INFORMATION structure
  146. //
  147. FSVIDEO_SCREEN_INFORMATION ScreenAndFont;
  148. //
  149. // EMULATE_BUFFER_INFORMATION structure
  150. //
  151. EMULATE_BUFFER_INFORMATION EmulateInfo;
  152. } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
  153. //
  154. // Global shared data
  155. //
  156. typedef struct _GLOBALS {
  157. //
  158. // Declare the global debug flag for this driver.
  159. //
  160. ULONG FsVgaDebug;
  161. //
  162. // A list of the registry path to the service parameters.
  163. //
  164. UNICODE_STRING RegistryPath;
  165. //
  166. // Port configuration information.
  167. //
  168. FSVGA_CONFIGURATION_INFORMATION Configuration;
  169. //
  170. // Resource list and size
  171. //
  172. FSVGA_RESOURCE_INFORMATION Resource;
  173. } GLOBALS, *PGLOBALS;
  174. extern GLOBALS Globals;
  175. //
  176. // Define the base values for the error log packet's UniqueErrorValue field.
  177. //
  178. #define FSVGA_ERROR_VALUE_BASE 1000
  179. //
  180. // Defines for DeviceExtension->HardwarePresent.
  181. //
  182. #define FSVGA_HARDWARE_PRESENT 1
  183. //
  184. // Function prototypes.
  185. //
  186. //
  187. // fsvga.c
  188. //
  189. NTSTATUS
  190. DriverEntry(
  191. IN PDRIVER_OBJECT DriverObject,
  192. IN PUNICODE_STRING RegistryPath
  193. );
  194. VOID
  195. FsVgaQueryDevice(
  196. IN PFSVGA_RESOURCE_INFORMATION Resource
  197. );
  198. NTSTATUS
  199. FsVgaPeripheralCallout(
  200. IN PVOID Context,
  201. IN PUNICODE_STRING PathName,
  202. IN INTERFACE_TYPE BusType,
  203. IN ULONG BusNumber,
  204. IN PKEY_VALUE_FULL_INFORMATION *BusInformation,
  205. IN CONFIGURATION_TYPE ControllerType,
  206. IN ULONG ControllerNumber,
  207. IN PKEY_VALUE_FULL_INFORMATION *ControllerInformation,
  208. IN CONFIGURATION_TYPE PeripheralType,
  209. IN ULONG PeripheralNumber,
  210. IN PKEY_VALUE_FULL_INFORMATION *PeripheralInformation
  211. );
  212. #ifdef RESOURCE_REQUIREMENTS
  213. NTSTATUS
  214. FsVgaQueryAperture(
  215. OUT PIO_RESOURCE_LIST *pApertureRequirements
  216. );
  217. #endif
  218. NTSTATUS
  219. FsVgaCreateResource(
  220. IN PFSVGA_CONFIGURATION_INFORMATION configuration,
  221. OUT PCM_PARTIAL_RESOURCE_LIST *pResourceList
  222. );
  223. VOID
  224. FsVgaServiceParameters(
  225. IN PFSVGA_CONFIGURATION_INFORMATION configuration,
  226. IN PUNICODE_STRING RegistryPath
  227. );
  228. NTSTATUS
  229. FsVgaOpenCloseDispatch(
  230. IN PDEVICE_OBJECT DeviceObject,
  231. IN PIRP Irp
  232. );
  233. NTSTATUS
  234. FsVgaDeviceControl(
  235. IN PDEVICE_OBJECT DeviceObject,
  236. IN PIRP Irp
  237. );
  238. NTSTATUS
  239. FsVgaCopyFrameBuffer(
  240. PDEVICE_EXTENSION DeviceExtension,
  241. PFSVIDEO_COPY_FRAME_BUFFER CopyFrameBuffer,
  242. ULONG inputBufferLength
  243. );
  244. NTSTATUS
  245. FsVgaWriteToFrameBuffer(
  246. PDEVICE_EXTENSION DeviceExtension,
  247. PFSVIDEO_WRITE_TO_FRAME_BUFFER WriteFrameBuffer,
  248. ULONG inputBufferLength
  249. );
  250. NTSTATUS
  251. FsVgaReverseMousePointer(
  252. PDEVICE_EXTENSION DeviceExtension,
  253. PFSVIDEO_REVERSE_MOUSE_POINTER MouseBuffer,
  254. ULONG inputBufferLength
  255. );
  256. NTSTATUS
  257. FsVgaSetMode(
  258. PDEVICE_EXTENSION DeviceExtension,
  259. PFSVIDEO_MODE_INFORMATION ModeInformation,
  260. ULONG inputBufferLength
  261. );
  262. NTSTATUS
  263. FsVgaSetScreenInformation(
  264. PDEVICE_EXTENSION DeviceExtension,
  265. PFSVIDEO_SCREEN_INFORMATION ScreenInformation,
  266. ULONG inputBufferLength
  267. );
  268. NTSTATUS
  269. FsVgaSetCursorPosition(
  270. PDEVICE_EXTENSION DeviceExtension,
  271. PFSVIDEO_CURSOR_POSITION CursorPosition,
  272. ULONG inputBufferLength
  273. );
  274. NTSTATUS
  275. FsVgaSetCursorAttribute(
  276. PDEVICE_EXTENSION DeviceExtension,
  277. PVIDEO_CURSOR_ATTRIBUTES CursorAttributes,
  278. ULONG inputBufferLength
  279. );
  280. VOID
  281. FsVgaLogError(
  282. IN PVOID Object,
  283. IN NTSTATUS ErrorCode,
  284. IN ULONG UniqueErrorValue,
  285. IN NTSTATUS FinalStatus,
  286. IN PULONG DumpData,
  287. IN ULONG DumpCount
  288. );
  289. #if DBG
  290. VOID
  291. FsVgaDebugPrint(
  292. ULONG DebugPrintLevel,
  293. PCCHAR DebugMessage,
  294. ...
  295. );
  296. extern ULONG FsVgaDebug;
  297. #define FsVgaPrint(x) FsVgaDebugPrint x
  298. #else
  299. #define FsVgaPrint(x)
  300. #endif
  301. //
  302. // drawscrn.c
  303. //
  304. ULONG
  305. CalcGRAMSize(
  306. IN COORD WindowSize,
  307. IN PFSVIDEO_SCREEN_INFORMATION ScreenInfo,
  308. IN PEMULATE_BUFFER_INFORMATION EmulateInfo
  309. );
  310. PUCHAR
  311. CalcGRAMAddress(
  312. IN COORD WindowSize,
  313. IN PFSVIDEO_MODE_INFORMATION VideoModeInfo,
  314. IN PFSVIDEO_SCREEN_INFORMATION ScreenInfo,
  315. IN PEMULATE_BUFFER_INFORMATION EmulateInfo
  316. );
  317. #ifdef LATER_HIGH_SPPED_VRAM_ACCESS // kazum
  318. BOOLEAN
  319. IsGRAMRowOver(
  320. PUCHAR BufPtr,
  321. BOOLEAN fDbcs,
  322. IN PFSVIDEO_MODE_INFORMATION VideoModeInfo,
  323. IN PEMULATE_BUFFER_INFORMATION EmulateInfo
  324. );
  325. #endif // LATER_HIGH_SPPED_VRAM_ACCESS // kazum
  326. PUCHAR
  327. NextGRAMRow(
  328. PUCHAR BufPtr,
  329. IN PFSVIDEO_MODE_INFORMATION VideoModeInfo,
  330. IN PEMULATE_BUFFER_INFORMATION EmulateInfo
  331. );
  332. VOID
  333. memcpyGRAM(
  334. IN PCHAR TargetPtr,
  335. IN PCHAR SourcePtr,
  336. IN ULONG Length
  337. );
  338. VOID
  339. memcpyGRAMOver(
  340. IN PCHAR TargetPtr,
  341. IN PCHAR SourcePtr,
  342. IN ULONG Length,
  343. IN PUCHAR FrameBufPtr,
  344. IN PEMULATE_BUFFER_INFORMATION EmulateInfo
  345. );
  346. VOID
  347. MoveGRAM(
  348. IN PCHAR TargetPtr,
  349. IN PCHAR SourcePtr,
  350. IN ULONG Length,
  351. IN PUCHAR FrameBufPtr,
  352. IN PFSVGA_RESOURCE_INFORMATION ResourceInfo,
  353. IN PEMULATE_BUFFER_INFORMATION EmulateInfo
  354. );
  355. NTSTATUS
  356. FsgVgaInitializeHWFlags(
  357. PDEVICE_EXTENSION DeviceExtension
  358. );
  359. NTSTATUS
  360. FsgCopyFrameBuffer(
  361. PDEVICE_EXTENSION DeviceExtension,
  362. PFSVIDEO_COPY_FRAME_BUFFER CopyFrameBuffer,
  363. ULONG inputBufferLength
  364. );
  365. NTSTATUS
  366. FsgWriteToFrameBuffer(
  367. PDEVICE_EXTENSION DeviceExtension,
  368. PFSVIDEO_WRITE_TO_FRAME_BUFFER WriteFrameBuffer,
  369. ULONG inputBufferLength
  370. );
  371. NTSTATUS
  372. FsgReverseMousePointer(
  373. PDEVICE_EXTENSION DeviceExtension,
  374. PFSVIDEO_REVERSE_MOUSE_POINTER MouseBuffer,
  375. ULONG inputBufferLength
  376. );
  377. NTSTATUS
  378. FsgInvertCursor(
  379. PDEVICE_EXTENSION DeviceExtension,
  380. BOOLEAN Invert
  381. );
  382. NTSTATUS
  383. FsgWriteToScreen(
  384. PUCHAR FrameBuffer,
  385. PUCHAR BitmapBuffer,
  386. ULONG cjBytes,
  387. BOOLEAN fDbcs,
  388. USHORT Attributes1,
  389. USHORT Attributes2,
  390. PDEVICE_EXTENSION DeviceExtension
  391. );
  392. NTSTATUS
  393. FsgWriteToScreenCommonLVB(
  394. PUCHAR FrameBuffer,
  395. USHORT Attributes,
  396. PDEVICE_EXTENSION DeviceExtension
  397. );
  398. UCHAR
  399. AccessGRAM_WR(
  400. PUCHAR FrameBuffer,
  401. UCHAR write
  402. );
  403. UCHAR
  404. AccessGRAM_RW(
  405. PUCHAR FrameBuffer,
  406. UCHAR write
  407. );
  408. UCHAR
  409. AccessGRAM_AND(
  410. PUCHAR FrameBuffer,
  411. UCHAR write
  412. );
  413. //
  414. // foncache.c
  415. //
  416. ULONG
  417. CalcBitmapBufferSize(
  418. IN COORD FontSize,
  419. IN ULONG dwAlign
  420. );
  421. VOID
  422. AlignCopyMemory(
  423. OUT PUCHAR pDestBits,
  424. IN ULONG dwDestAlign,
  425. IN PUCHAR pSrcBits,
  426. IN ULONG dwSrcAlign,
  427. IN COORD FontSize
  428. );
  429. //
  430. // misc.c
  431. //
  432. int
  433. ConvertOutputToOem(
  434. IN LPWSTR Source,
  435. IN int SourceLength, // in chars
  436. OUT LPSTR Target,
  437. IN int TargetLength // in chars
  438. );
  439. NTSTATUS
  440. TranslateOutputToOem(
  441. OUT PCHAR_IMAGE_INFO OutputBuffer,
  442. IN PCHAR_IMAGE_INFO InputBuffer,
  443. IN ULONG Length
  444. );
  445. //
  446. // port.c
  447. //
  448. VOID
  449. GetHardwareScrollReg(
  450. PPORT_LIST PortList,
  451. PEMULATE_BUFFER_INFORMATION EmulateInfo
  452. );
  453. VOID
  454. SetGRAMWriteMode(
  455. PPORT_LIST PortList
  456. );
  457. VOID
  458. SetGRAMCopyMode(
  459. PPORT_LIST PortList
  460. );
  461. VOID
  462. SetGRAMInvertMode(
  463. PPORT_LIST PortList
  464. );
  465. VOID
  466. set_opaque_bkgnd_proc(
  467. PPORT_LIST PortList,
  468. PEMULATE_BUFFER_INFORMATION EmulateInfo,
  469. PUCHAR FrameBuffer,
  470. USHORT Attributes
  471. );
  472. VOID
  473. ColorSetGridMask(
  474. PPORT_LIST PortList,
  475. UCHAR BitMask
  476. );
  477. VOID
  478. ColorSetDirect(
  479. PPORT_LIST PortList,
  480. PUCHAR FrameBuffer,
  481. UCHAR ColorFg,
  482. UCHAR ColorBg
  483. );
  484. //
  485. // pnp.c
  486. //
  487. VOID
  488. FsVgaDriverUnload(
  489. IN PDRIVER_OBJECT DriverObject
  490. );
  491. NTSTATUS
  492. FsVgaAddDevice(
  493. IN PDRIVER_OBJECT DriverObject,
  494. IN PDEVICE_OBJECT pdo
  495. );
  496. NTSTATUS
  497. FsVgaDevicePnp(
  498. IN PDEVICE_OBJECT fdo,
  499. IN PIRP Irp
  500. );
  501. NTSTATUS
  502. FsVgaDefaultPnpHandler(
  503. IN PDEVICE_OBJECT fdo,
  504. IN PIRP Irp
  505. );
  506. NTSTATUS
  507. FsVgaPnpRemoveDevice(
  508. IN PDEVICE_OBJECT fdo,
  509. IN PIRP Irp
  510. );
  511. NTSTATUS
  512. FsVgaPnpStartDevice(
  513. IN PDEVICE_OBJECT fdo,
  514. IN PIRP Irp
  515. );
  516. NTSTATUS
  517. FsVgaPnpStopDevice(
  518. IN PDEVICE_OBJECT fdo,
  519. IN PIRP Irp
  520. );
  521. #ifdef RESOURCE_REQUIREMENTS
  522. NTSTATUS
  523. FsVgaFilterResourceRequirements(
  524. IN PDEVICE_OBJECT fdo,
  525. IN PIRP Irp
  526. );
  527. #endif
  528. NTSTATUS
  529. FsVgaDevicePower(
  530. IN PDEVICE_OBJECT fdo,
  531. IN PIRP Irp
  532. );
  533. NTSTATUS
  534. FsVgaDefaultPowerHandler(
  535. IN PDEVICE_OBJECT fdo,
  536. IN PIRP Irp
  537. );
  538. NTSTATUS
  539. CompleteRequest(
  540. IN PIRP Irp,
  541. IN NTSTATUS status,
  542. IN ULONG info
  543. );
  544. NTSTATUS
  545. ForwardAndWait(
  546. IN PDEVICE_OBJECT fdo,
  547. IN PIRP Irp
  548. );
  549. NTSTATUS
  550. OnRequestComplete(
  551. IN PDEVICE_OBJECT fdo,
  552. IN PIRP Irp,
  553. IN PKEVENT pev
  554. );
  555. VOID
  556. RemoveDevice(
  557. IN PDEVICE_OBJECT fdo
  558. );
  559. BOOLEAN
  560. LockDevice(
  561. IN PDEVICE_EXTENSION pdx
  562. );
  563. VOID
  564. UnlockDevice(
  565. IN PDEVICE_EXTENSION pdx
  566. );
  567. NTSTATUS
  568. StartDevice(
  569. IN PDEVICE_OBJECT fdo,
  570. IN PCM_PARTIAL_RESOURCE_LIST list
  571. );
  572. VOID
  573. StopDevice(
  574. IN PDEVICE_OBJECT fdo
  575. );
  576. #endif // _FSVGA_