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.

8788 lines
267 KiB

  1. //---------------------------------------------------------------------------
  2. /*++
  3. Copyright (c) 1992-1997 Microsoft Corporation.
  4. Copyright (c) 1996-1997 Cirrus Logic, Inc.,
  5. Module Name:
  6. C I R R U S . C
  7. Abstract:
  8. This is the miniport driver for the Cirrus Logic
  9. 6410/6420/542x/543x/544x/548x/754x/755x VGA's.
  10. Environment:
  11. Kernel mode only
  12. Notes:
  13. Revision History:
  14. * $Log: S:/projects/drivers/ntsrc/miniport/cirrus.c_v $
  15. *
  16. * Rev 1.16 Apr 03 1997 15:44:40 unknown
  17. *
  18. *
  19. * Rev 1.10 Jan 08 1997 14:25:40 unknown
  20. * Fix the 440FX and 5446AC coexist problem.
  21. *
  22. * Rev 1.9 18 Dec 1996 14:03:48 PLCHU
  23. *
  24. *
  25. * Rev 1.7 Dec 06 1996 11:14:16 unknown
  26. *
  27. *
  28. * Rev 1.6 Nov 26 1996 16:29:02 unknown
  29. *
  30. *
  31. * Rev 1.8 Nov 26 1996 16:02:20 unknown
  32. * Add conditional compile for P6Cache
  33. *
  34. * Rev 1.7 Nov 26 1996 14:32:42 unknown
  35. * turn on PCI14 and second aperture for 5480
  36. *
  37. * Rev 1.6 Nov 18 1996 16:23:32 unknown
  38. * Add P6 Cache flag and fix 5436BG hung bug for HCT
  39. *
  40. * Rev 1.5 Nov 05 1996 14:49:56 unknown
  41. * turn off PCI14 for 5480 temporaryly
  42. *
  43. * Rev 1.4 Nov 01 1996 16:44:54 unknown
  44. *
  45. * Rev 1.3 Oct 14 1996 10:49:36 unknown
  46. * Add 100Hz monitor support and Detailed timnig calculation
  47. *
  48. * Rev 1.4 07 Aug 1996 14:43:02 frido
  49. * Added better support for monochrome text modes.
  50. *
  51. * Rev 1.3 06 Aug 1996 18:35:54 frido
  52. * Changed the way the video memory is shared in linear mode.
  53. *
  54. * Rev 1.2 06 Aug 1996 17:19:20 frido
  55. * Removed banking in linear mode.
  56. *
  57. * chu01 08-26-96 Distinguish CL-5480 and CL-5436/46 because the former
  58. * has new fratures such as XY-clipping, XY-position and
  59. * BLT command list that the others do not have.
  60. * jl01 09-24-96 Fix Alt+Tab switching between "Introducing Windows NT"
  61. * and "Main". Refer to PDR#5409.
  62. * jl02 10-21-96 Add CL-5446BE support.
  63. * sge01 10-14-96 VGA register and MMIO register can be relocatable.
  64. * sge02 10-22-96 VideoMemoryAddress use linear address instead of A0000.
  65. * sge03 10-23-96 Add second aperture maping
  66. * chu02 10-31-96 DDC2B enabling / disabling
  67. * sge04 11-04-96 Disable PCI14 for 5480 temporaryly
  68. * sge05 11-07-96 Add P6Cache support
  69. * sge06 11-26-96 Add conditional compile for P6Cache support
  70. * jl03 12-05-96 Set CL-5446BE flag "CL5446BE"
  71. * chu03 12-16-96 Enable color correction
  72. * sge07 12-16-96 Check mono or color mode before reading input status
  73. * sge08 01-08-97 Fix the 440FX and 5446AC coexist problem.
  74. * myf0 08-19-96 added 85hz supported
  75. * myf1 08-20-96 supported panning scrolling
  76. * myf2 08-20-96 fixed hardware save/restore state bug for matterhorn
  77. * myf3 09-01-96 Added IOCTL_CIRRUS_PRIVATE_BIOS_CALL for TV supported
  78. * myf4 09-01-96 patch Viking BIOS bug, PDR #4287, begin
  79. * myf5 09-01-96 Fixed PDR #4365 keep all default refresh rate
  80. * myf6 09-17-96 Merged Desktop SRC1001 & MINI102
  81. * myf7 09-19-96 Fixed exclude 60Hz refresh rate select
  82. * myf8 *09-21-96* May be need change CheckandUpdateDDC2BMonitor --keystring[]
  83. * myf9 09-21-96 8x6 panel in 6x4x256 mode, cursor can't move to bottom scrn
  84. * ms0809 09-25-96 fixed dstn panel icon corrupted
  85. * ms923 09-25-96 merge MS-923 Disp.zip code
  86. * myf10 09-26-96 Fixed DSTN reserved half-frame buffer bug.
  87. * myf11 09-26-96 Fixed 755x CE chip HW bug, access ramdac before disable HW
  88. * icons and cursor
  89. * myf12 10-01-96 Supported Hot Key switch display
  90. * myf13 10-05-96 Fixed /w panning scrolling, vertical expension on bug
  91. * myf14 10-15-96 Fixed PDR#6917, 6x4 panel can't panning scrolling for 754x
  92. * myf15 10-16-96 Fixed disable memory mapped IO for 754x, 755x
  93. * myf16 10-22-96 Fixed PDR #6933,panel type set different demo board setting
  94. * smith 10-22-96 Disable Timer event, because sometimes creat PAGE_FAULT or
  95. * IRQ level can't handle
  96. * myf17 11-04-96 Added special escape code must be use 11/5/96 later NTCTRL,
  97. * and added Matterhorn LF Device ID==0x4C
  98. * myf18 11-04-96 Fixed PDR #7075,
  99. * myf19 11-06-96 Fixed Vinking can't work problem, because DEVICEID = 0x30
  100. * is different from data book (CR27=0x2C)
  101. * myf20 11-12-96 Fixed DSTN panel initial reserved 128K memoru
  102. * myf21 11-15-96 fixed #7495 during change resolution, screen appear garbage
  103. * image, because not clear video memory.
  104. * myf22 11-19-96 Added 640x480x256/640x480x64K -85Hz refresh rate for 7548
  105. * myf23 11-21-96 Added fixed NT 3.51 S/W cursor panning problem
  106. * myf24 11-22-96 Added fixed NT 4.0 Japanese dos full screen problem
  107. * myf25 12-03-96 Fixed 8x6x16M 2560byte/line patch H/W bug PDR#7843, and
  108. * fixed pre-install microsoft requested
  109. * myf26 12-11-96 Fixed Japanese NT 4.0 Dos-full screen bug for LCD enable
  110. * myf27 01-09-96 Fixed NT3.51 PDR#7986, horizontal lines appears at logon
  111. * windows, set 8x6x64K mode boot up CRT, jumper set 8x6 DSTN
  112. * Fixed NT3.51 PDR#7987, set 64K color modes, garbage on
  113. * screen when boot up XGA panel.
  114. * myf28 02-03-97 Fixed NT3.51 PDR#8357, mode 3, 12, panning scrolling bug
  115. * myf29 02-12-97 Support Gamma correction graphic/video LUT for 755x
  116. * myf30 02-10-97 Fixed NT3.51, 6x4 LCD boot set 256 coloe, test 64K mode
  117. * jl04 02-11-97 Fix 542x VLB banking issue.
  118. * myf31 02-25-97 Fixed RadiSys system, set MCLK to 66MHz
  119. * myf32 03-02-97 Display each chip information
  120. * sge09 03-10-97 Add P6CACHE condition compile.
  121. * chu04 03-10-97 Chip type "5430/40", instead of "5430" requested by Intel.
  122. * chu05 03-13-97 For 5436 checked build NT, read 4-byte PCI
  123. * configuration register to access index 0x53 instead of
  124. * the whole 256 bytes.
  125. * chu06 03-26-97 Common routine to get Cirrus chip and revision IDs.
  126. * jl05 03-28-97 Fix for NT3.51
  127. --*/
  128. //---------------------------------------------------------------------------
  129. #include <dderror.h>
  130. #include <devioctl.h>
  131. #include <miniport.h>
  132. #include <ntddvdeo.h>
  133. #include <video.h>
  134. #include "cirrus.h"
  135. #include "clioctl.h"
  136. #include "sr754x.h"
  137. #include "cmdcnst.h"
  138. #define DDC2B 1
  139. #define QUERY_MONITOR_ID 0x22446688
  140. #define QUERY_NONDDC_MONITOR_ID 0x11223344
  141. #define LCD_type 1
  142. #define CRT_type 2
  143. #define SIM_type 3
  144. //---------------------------------------------------------------------------
  145. //
  146. // Function declarations
  147. //
  148. // Functions that start with 'VGA' are entry points for the OS port driver.
  149. //
  150. VP_STATUS
  151. VgaFindAdapter(
  152. PVOID HwDeviceExtension,
  153. PVOID HwContext,
  154. PWSTR ArgumentString,
  155. PVIDEO_PORT_CONFIG_INFO ConfigInfo,
  156. PUCHAR Again
  157. );
  158. BOOLEAN
  159. VgaInitialize(
  160. PVOID HwDeviceExtension
  161. );
  162. BOOLEAN
  163. VgaStartIO(
  164. PVOID HwDeviceExtension,
  165. PVIDEO_REQUEST_PACKET RequestPacket
  166. );
  167. //crus, smith
  168. VOID
  169. CirrusHwTimer(
  170. PVOID HwDeviceExtension
  171. );
  172. //
  173. // Private function prototypes.
  174. //
  175. VP_STATUS
  176. VgaQueryAvailableModes(
  177. PHW_DEVICE_EXTENSION HwDeviceExtension,
  178. PVIDEO_MODE_INFORMATION ModeInformation,
  179. ULONG ModeInformationSize,
  180. PULONG OutputSize
  181. );
  182. VP_STATUS
  183. VgaQueryNumberOfAvailableModes(
  184. PHW_DEVICE_EXTENSION HwDeviceExtension,
  185. PVIDEO_NUM_MODES NumModes,
  186. ULONG NumModesSize,
  187. PULONG OutputSize
  188. );
  189. VP_STATUS
  190. VgaQueryCurrentMode(
  191. PHW_DEVICE_EXTENSION HwDeviceExtension,
  192. PVIDEO_MODE_INFORMATION ModeInformation,
  193. ULONG ModeInformationSize,
  194. PULONG OutputSize
  195. );
  196. VP_STATUS
  197. VgaSetMode(
  198. PHW_DEVICE_EXTENSION HwDeviceExtension,
  199. PVIDEO_MODE Mode,
  200. ULONG ModeSize
  201. );
  202. VP_STATUS
  203. VgaLoadAndSetFont(
  204. PHW_DEVICE_EXTENSION HwDeviceExtension,
  205. PVIDEO_LOAD_FONT_INFORMATION FontInformation,
  206. ULONG FontInformationSize
  207. );
  208. #ifdef PANNING_SCROLL
  209. VP_STATUS
  210. CirrusSetDisplayPitch (
  211. PHW_DEVICE_EXTENSION HwDeviceExtension,
  212. PANNMODE PanningMode
  213. );
  214. #endif
  215. VP_STATUS
  216. VgaQueryCursorPosition(
  217. PHW_DEVICE_EXTENSION HwDeviceExtension,
  218. PVIDEO_CURSOR_POSITION CursorPosition,
  219. ULONG CursorPositionSize,
  220. PULONG OutputSize
  221. );
  222. VP_STATUS
  223. VgaSetCursorPosition(
  224. PHW_DEVICE_EXTENSION HwDeviceExtension,
  225. PVIDEO_CURSOR_POSITION CursorPosition,
  226. ULONG CursorPositionSize
  227. );
  228. VP_STATUS
  229. VgaQueryCursorAttributes(
  230. PHW_DEVICE_EXTENSION HwDeviceExtension,
  231. PVIDEO_CURSOR_ATTRIBUTES CursorAttributes,
  232. ULONG CursorAttributesSize,
  233. PULONG OutputSize
  234. );
  235. VP_STATUS
  236. VgaSetCursorAttributes(
  237. PHW_DEVICE_EXTENSION HwDeviceExtension,
  238. PVIDEO_CURSOR_ATTRIBUTES CursorAttributes,
  239. ULONG CursorAttributesSize
  240. );
  241. BOOLEAN
  242. VgaIsPresent(
  243. PHW_DEVICE_EXTENSION HwDeviceExtension
  244. );
  245. BOOLEAN
  246. CirrusLogicIsPresent(
  247. PHW_DEVICE_EXTENSION HwDeviceExtension
  248. );
  249. ULONG
  250. CirrusFindVmemSize(
  251. PHW_DEVICE_EXTENSION HwDeviceExtension
  252. );
  253. VOID
  254. CirrusValidateModes(
  255. PHW_DEVICE_EXTENSION HwDeviceExtension
  256. );
  257. VOID
  258. SetCirrusBanking(
  259. PHW_DEVICE_EXTENSION HwDeviceExtension,
  260. USHORT BankNumber
  261. );
  262. VOID
  263. vBankMap_CL64xx(
  264. ULONG iBankRead,
  265. ULONG iBankWrite,
  266. PVOID pvContext
  267. );
  268. VOID
  269. vBankMap_CL543x(
  270. ULONG iBankRead,
  271. ULONG iBankWrite,
  272. PVOID pvContext
  273. );
  274. VOID
  275. vBankMap_CL542x(
  276. ULONG iBankRead,
  277. ULONG iBankWrite,
  278. PVOID pvContext
  279. );
  280. USHORT
  281. CirrusFind6410DisplayType(
  282. PHW_DEVICE_EXTENSION HwDeviceExtension
  283. );
  284. USHORT
  285. CirrusFind6245DisplayType(
  286. PHW_DEVICE_EXTENSION HwDeviceExtension,
  287. PUCHAR CRTCAddrPort,
  288. PUCHAR CRTCDataPort
  289. );
  290. USHORT
  291. CirrusFind754xDisplayType(
  292. PHW_DEVICE_EXTENSION HwDeviceExtension,
  293. PUCHAR CRTCAddrPort,
  294. PUCHAR CRTCDataPort
  295. );
  296. USHORT
  297. CirrusFind755xDisplayType(
  298. PHW_DEVICE_EXTENSION HwDeviceExtension,
  299. PUCHAR CRTCAddrPort,
  300. PUCHAR CRTCDataPort
  301. );
  302. BOOLEAN
  303. CirrusFind6340(
  304. PHW_DEVICE_EXTENSION HwDeviceExtension
  305. );
  306. VOID
  307. AccessHWiconcursor(
  308. PHW_DEVICE_EXTENSION HwDeviceExtension,
  309. SHORT Access_flag
  310. );
  311. VOID
  312. VgaInterpretCmdStream(
  313. PVOID HwDeviceExtension,
  314. PUSHORT pusCmdStream
  315. );
  316. VP_STATUS
  317. VgaSetPaletteReg(
  318. PHW_DEVICE_EXTENSION HwDeviceExtension,
  319. PVIDEO_PALETTE_DATA PaletteBuffer,
  320. ULONG PaletteBufferSize
  321. );
  322. VP_STATUS
  323. VgaSetColorLookup(
  324. PHW_DEVICE_EXTENSION HwDeviceExtension,
  325. PVIDEO_CLUT ClutBuffer,
  326. ULONG ClutBufferSize
  327. );
  328. VP_STATUS
  329. VgaRestoreHardwareState(
  330. PHW_DEVICE_EXTENSION HwDeviceExtension,
  331. PVIDEO_HARDWARE_STATE HardwareState,
  332. ULONG HardwareStateSize
  333. );
  334. VP_STATUS
  335. VgaSaveHardwareState(
  336. PHW_DEVICE_EXTENSION HwDeviceExtension,
  337. PVIDEO_HARDWARE_STATE HardwareState,
  338. ULONG HardwareStateSize,
  339. PULONG OutputSize
  340. );
  341. VP_STATUS
  342. VgaGetBankSelectCode(
  343. PHW_DEVICE_EXTENSION HwDeviceExtension,
  344. PVIDEO_BANK_SELECT BankSelect,
  345. ULONG BankSelectSize,
  346. PULONG OutputSize
  347. );
  348. BOOLEAN
  349. CirrusConfigurePCI(
  350. PHW_DEVICE_EXTENSION HwDeviceExtension,
  351. PULONG NumPCIAccessRanges,
  352. PVIDEO_ACCESS_RANGE PCIAccessRanges
  353. );
  354. VOID
  355. WriteRegistryInfo(
  356. PHW_DEVICE_EXTENSION hwDeviceExtension
  357. );
  358. VP_STATUS
  359. CirrusGetDeviceDataCallback(
  360. PVOID HwDeviceExtension,
  361. PVOID Context,
  362. VIDEO_DEVICE_DATA_TYPE DeviceDataType,
  363. PVOID Identifier,
  364. ULONG IdentifierLength,
  365. PVOID ConfigurationData,
  366. ULONG ConfigurationDataLength,
  367. PVOID ComponentInformation,
  368. ULONG ComponentInformationLength
  369. );
  370. VOID
  371. IOWaitDisplEnableThenWrite(
  372. PHW_DEVICE_EXTENSION hwDeviceExtension,
  373. ULONG port,
  374. UCHAR value
  375. );
  376. VOID
  377. ReadVESATiming(
  378. PHW_DEVICE_EXTENSION hwDeviceExtension
  379. );
  380. #if (_WIN32_WINNT <= 0x0400)
  381. VOID
  382. CheckAndUpdateDDC2BMonitor(
  383. PHW_DEVICE_EXTENSION HwDeviceExtension
  384. );
  385. #endif // (_WIN32_WINNT <= 0x0400)
  386. VOID
  387. CirrusUpdate440FX(
  388. PHW_DEVICE_EXTENSION HwDeviceExtension
  389. );
  390. //
  391. // NOTE:
  392. //
  393. // This is a High Priority system callback. DO NOT mark this
  394. // routine as pageable!
  395. //
  396. BOOLEAN
  397. IOCallback(
  398. PHW_DEVICE_EXTENSION HwDeviceExtension
  399. );
  400. VP_STATUS
  401. VgaGetGammaFactor(
  402. PHW_DEVICE_EXTENSION HwDeviceExtension,
  403. PGAMMA_VALUE value,
  404. ULONG ValueLength,
  405. PULONG OutputSize
  406. );
  407. VP_STATUS
  408. VgaGetContrastFactor(
  409. PHW_DEVICE_EXTENSION HwDeviceExtension,
  410. PCONTRAST_VALUE value,
  411. ULONG ValueLength,
  412. PULONG OutputSize
  413. );
  414. UCHAR
  415. GetCirrusChipId(
  416. PHW_DEVICE_EXTENSION HwDeviceExtension
  417. );
  418. USHORT
  419. GetCirrusChipRevisionId(
  420. PHW_DEVICE_EXTENSION HwDeviceExtension
  421. );
  422. #if defined(ALLOC_PRAGMA)
  423. #pragma alloc_text(PAGE,DriverEntry)
  424. #pragma alloc_text(PAGE,VgaFindAdapter)
  425. #pragma alloc_text(PAGE,VgaInitialize)
  426. #pragma alloc_text(PAGE,VgaStartIO)
  427. #pragma alloc_text(PAGE,CirrusHwTimer)
  428. #pragma alloc_text(PAGE,VgaLoadAndSetFont)
  429. #pragma alloc_text(PAGE,VgaQueryCursorPosition)
  430. #pragma alloc_text(PAGE,VgaSetCursorPosition)
  431. #pragma alloc_text(PAGE,VgaQueryCursorAttributes)
  432. #pragma alloc_text(PAGE,VgaSetCursorAttributes)
  433. #pragma alloc_text(PAGE,VgaIsPresent)
  434. #pragma alloc_text(PAGE,CirrusLogicIsPresent)
  435. #pragma alloc_text(PAGE,CirrusFindVmemSize)
  436. #pragma alloc_text(PAGE,SetCirrusBanking)
  437. #ifdef PANNING_SCROLL
  438. #pragma alloc_text(PAGE,CirrusSetDisplayPitch)
  439. #endif
  440. #pragma alloc_text(PAGE,CirrusFind6245DisplayType)
  441. #pragma alloc_text(PAGE,CirrusFind754xDisplayType)
  442. #pragma alloc_text(PAGE,CirrusFind755xDisplayType)
  443. #pragma alloc_text(PAGE,CirrusFind6410DisplayType)
  444. #pragma alloc_text(PAGE,CirrusFind6340)
  445. #pragma alloc_text(PAGE,AccessHWiconcursor)
  446. #pragma alloc_text(PAGE,CirrusConfigurePCI)
  447. #pragma alloc_text(PAGE,VgaSetPaletteReg)
  448. #pragma alloc_text(PAGE,VgaSetColorLookup)
  449. #pragma alloc_text(PAGE,VgaRestoreHardwareState)
  450. #pragma alloc_text(PAGE,VgaSaveHardwareState)
  451. #pragma alloc_text(PAGE,VgaGetBankSelectCode)
  452. #pragma alloc_text(PAGE,VgaValidatorUcharEntry)
  453. #pragma alloc_text(PAGE,VgaValidatorUshortEntry)
  454. #pragma alloc_text(PAGE,VgaValidatorUlongEntry)
  455. #pragma alloc_text(PAGE,WriteRegistryInfo)
  456. #pragma alloc_text(PAGE,CirrusGetDeviceDataCallback)
  457. #pragma alloc_text(PAGE,CirrusUpdate440FX)
  458. #pragma alloc_text(PAGE,VgaGetGammaFactor)
  459. #pragma alloc_text(PAGE,VgaGetContrastFactor)
  460. #if (_WIN32_WINNT >= 0x0500)
  461. #pragma alloc_text(PAGE,CirrusGetChildDescriptor)
  462. #pragma alloc_text(PAGE,CirrusGetPowerState)
  463. #pragma alloc_text(PAGE,CirrusSetPowerState)
  464. #endif
  465. #endif
  466. BOOLEAN
  467. GetDdcInformation(
  468. PHW_DEVICE_EXTENSION HwDeviceExtension,
  469. PUCHAR QueryBuffer,
  470. ULONG BufferSize);
  471. ULONG
  472. CirrusGetChildDescriptor(
  473. PVOID pHwDeviceExtension,
  474. PVIDEO_CHILD_ENUM_INFO ChildEnumInfo,
  475. PVIDEO_CHILD_TYPE pChildType,
  476. PVOID pChildDescriptor,
  477. PULONG pHwId,
  478. PULONG pUnused
  479. )
  480. /*++
  481. Routine Description:
  482. Enumerate all devices controlled by the ATI graphics chip.
  483. This includes DDC monitors attached to the board, as well as other devices
  484. which may be connected to a proprietary bus.
  485. Arguments:
  486. HwDeviceExtension - Pointer to our hardware device extension structure.
  487. ChildIndex - Index of the child the system wants informaion for.
  488. pChildType - Type of child we are enumerating - monitor, I2C ...
  489. pChildDescriptor - Identification structure of the device (EDID, string)
  490. ppHwId - Private unique 32 bit ID to passed back to the miniport
  491. pMoreChildren - Should the miniport be called
  492. Return Value:
  493. Status from VideoPortInitialize()
  494. Note:
  495. In the event of a failure return, none of the fields are valid except for
  496. the return value and the pMoreChildren field.
  497. --*/
  498. {
  499. PHW_DEVICE_EXTENSION hwDeviceExtension = pHwDeviceExtension;
  500. ULONG Status;
  501. switch (ChildEnumInfo->ChildIndex) {
  502. case 0:
  503. //
  504. // Case 0 is used to enumerate devices found by the ACPI firmware.
  505. //
  506. // Since we do not support ACPI devices yet, we must return failure.
  507. //
  508. Status = ERROR_NO_MORE_DEVICES;
  509. break;
  510. case 1:
  511. //
  512. // This is the last device we enumerate. Tell the system we don't
  513. // have any more.
  514. //
  515. *pChildType = Monitor;
  516. //
  517. // Obtain the EDID structure via DDC.
  518. //
  519. if (GetDdcInformation(hwDeviceExtension,
  520. pChildDescriptor,
  521. ChildEnumInfo->ChildDescriptorSize))
  522. {
  523. *pHwId = QUERY_MONITOR_ID;
  524. VideoDebugPrint((1, "CirrusGetChildDescriptor - successfully read EDID structure\n"));
  525. } else {
  526. //
  527. // Alway return TRUE, since we always have a monitor output
  528. // on the card and it just may not be a detectable device.
  529. //
  530. *pHwId = QUERY_NONDDC_MONITOR_ID;
  531. VideoDebugPrint((1, "CirrusGetChildDescriptor - DDC not supported\n"));
  532. }
  533. Status = ERROR_MORE_DATA;
  534. break;
  535. case DISPLAY_ADAPTER_HW_ID:
  536. //
  537. // Special ID to handle return legacy PnP IDs for root enumerated
  538. // devices.
  539. //
  540. *pChildType = VideoChip;
  541. *pHwId = DISPLAY_ADAPTER_HW_ID;
  542. memcpy(pChildDescriptor, hwDeviceExtension->LegacyPnPId, 8*sizeof(WCHAR));
  543. Status = ERROR_MORE_DATA;
  544. break;
  545. default:
  546. Status = ERROR_NO_MORE_DEVICES;
  547. break;
  548. }
  549. return Status;
  550. }
  551. VP_STATUS
  552. CirrusGetPowerState(
  553. PHW_DEVICE_EXTENSION HwDeviceExtension,
  554. ULONG HwDeviceId,
  555. PVIDEO_POWER_MANAGEMENT VideoPowerManagement
  556. )
  557. /*++
  558. Routine Description:
  559. Returns power state information.
  560. Arguments:
  561. HwDeviceExtension - Pointer to our hardware device extension structure.
  562. HwDeviceId - Private unique 32 bit ID identifing the device.
  563. VideoPowerManagement - Power state information.
  564. Return Value:
  565. TRUE if power state can be set,
  566. FALSE otherwise.
  567. --*/
  568. {
  569. //
  570. // We only support power setting for the monitor. Make sure the
  571. // HwDeviceId matches one the the monitors we could report.
  572. //
  573. if ((HwDeviceId == QUERY_NONDDC_MONITOR_ID) ||
  574. (HwDeviceId == QUERY_MONITOR_ID)) {
  575. //
  576. // We are querying the power support for the monitor.
  577. //
  578. if ((VideoPowerManagement->PowerState == VideoPowerOn) ||
  579. (VideoPowerManagement->PowerState == VideoPowerHibernate)) {
  580. return NO_ERROR;
  581. }
  582. switch (VideoPowerManagement->PowerState) {
  583. case VideoPowerStandBy:
  584. return (HwDeviceExtension->PMCapability & VESA_POWER_STANDBY) ?
  585. NO_ERROR : ERROR_INVALID_FUNCTION;
  586. case VideoPowerSuspend:
  587. return (HwDeviceExtension->PMCapability & VESA_POWER_SUSPEND) ?
  588. NO_ERROR : ERROR_INVALID_FUNCTION;
  589. case VideoPowerOff:
  590. return (HwDeviceExtension->PMCapability & VESA_POWER_OFF) ?
  591. NO_ERROR : ERROR_INVALID_FUNCTION;
  592. default:
  593. break;
  594. }
  595. VideoDebugPrint((1, "This device does not support Power Management.\n"));
  596. return ERROR_INVALID_FUNCTION;
  597. } else if (HwDeviceId == DISPLAY_ADAPTER_HW_ID) {
  598. //
  599. // We are querying power support for the graphics card.
  600. //
  601. switch (VideoPowerManagement->PowerState) {
  602. case VideoPowerOn:
  603. case VideoPowerHibernate:
  604. case VideoPowerStandBy:
  605. return NO_ERROR;
  606. case VideoPowerOff:
  607. case VideoPowerSuspend:
  608. if ((HwDeviceExtension->ChipType & CL754x) ||
  609. (HwDeviceExtension->ChipType & CL755x) ||
  610. (HwDeviceExtension->ChipType & CL756x)) {
  611. //
  612. // We will allow the system to go into S3 sleep state
  613. // for machines with laptop chipsets. The system
  614. // bios will be responsible for re-posting on wake up.
  615. //
  616. return NO_ERROR;
  617. } else {
  618. //
  619. // Indicate that we can't do VideoPowerOff, because
  620. // we have no way of coming back when power is re-applied
  621. // to the card.
  622. //
  623. return ERROR_INVALID_FUNCTION;
  624. }
  625. default:
  626. ASSERT(FALSE);
  627. return ERROR_INVALID_FUNCTION;
  628. }
  629. } else {
  630. VideoDebugPrint((1, "Unknown HwDeviceId"));
  631. ASSERT(FALSE);
  632. return ERROR_INVALID_PARAMETER;
  633. }
  634. }
  635. VP_STATUS
  636. CirrusSetPowerState(
  637. PHW_DEVICE_EXTENSION HwDeviceExtension,
  638. ULONG HwDeviceId,
  639. PVIDEO_POWER_MANAGEMENT VideoPowerManagement
  640. )
  641. /*++
  642. Routine Description:
  643. Set the power state for a given device.
  644. Arguments:
  645. HwDeviceExtension - Pointer to our hardware device extension structure.
  646. HwDeviceId - Private unique 32 bit ID identifing the device.
  647. VideoPowerManagement - Power state information.
  648. Return Value:
  649. TRUE if power state can be set,
  650. FALSE otherwise.
  651. --*/
  652. {
  653. //
  654. // Make sure we recognize the device.
  655. //
  656. if ((HwDeviceId == QUERY_NONDDC_MONITOR_ID) ||
  657. (HwDeviceId == QUERY_MONITOR_ID)) {
  658. VIDEO_X86_BIOS_ARGUMENTS biosArguments;
  659. VideoPortZeroMemory(&biosArguments, sizeof(VIDEO_X86_BIOS_ARGUMENTS));
  660. biosArguments.Eax = VESA_POWER_FUNCTION;
  661. biosArguments.Ebx = VESA_SET_POWER_FUNC;
  662. switch (VideoPowerManagement->PowerState) {
  663. case VideoPowerOn:
  664. case VideoPowerHibernate:
  665. biosArguments.Ebx |= VESA_POWER_ON;
  666. break;
  667. case VideoPowerStandBy:
  668. biosArguments.Ebx |= VESA_POWER_STANDBY;
  669. break;
  670. case VideoPowerSuspend:
  671. biosArguments.Ebx |= VESA_POWER_SUSPEND;
  672. break;
  673. case VideoPowerOff:
  674. biosArguments.Ebx |= VESA_POWER_OFF;
  675. break;
  676. default:
  677. VideoDebugPrint((1, "Unknown power state.\n"));
  678. ASSERT(FALSE);
  679. return ERROR_INVALID_PARAMETER;
  680. }
  681. VideoPortInt10(HwDeviceExtension, &biosArguments);
  682. //
  683. // I have no idea why, but on some machines after a while
  684. // the Pixel Mask Register gets set to zero. Then when
  685. // we power back up, we can no longer see the screen. It is
  686. // black.
  687. //
  688. // By setting the register here, we can prevent this
  689. // problem. There should be no harmful side effects to
  690. // this.
  691. //
  692. if (VideoPowerManagement->PowerState == VideoPowerOn) {
  693. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  694. DAC_PIXEL_MASK_PORT, 0xff);
  695. }
  696. return NO_ERROR;
  697. } else if (HwDeviceId == DISPLAY_ADAPTER_HW_ID) {
  698. switch (VideoPowerManagement->PowerState) {
  699. case VideoPowerOn:
  700. case VideoPowerStandBy:
  701. case VideoPowerSuspend:
  702. case VideoPowerOff:
  703. case VideoPowerHibernate:
  704. return NO_ERROR;
  705. default:
  706. ASSERT(FALSE);
  707. return ERROR_INVALID_PARAMETER;
  708. }
  709. } else {
  710. VideoDebugPrint((1, "Unknown HwDeviceId"));
  711. ASSERT(FALSE);
  712. return ERROR_INVALID_PARAMETER;
  713. }
  714. }
  715. //---------------------------------------------------------------------------
  716. ULONG
  717. DriverEntry(
  718. PVOID Context1,
  719. PVOID Context2
  720. )
  721. /*++
  722. Routine Description:
  723. Installable driver initialization entry point.
  724. This entry point is called directly by the I/O system.
  725. Arguments:
  726. Context1 - First context value passed by the operating system. This is
  727. the value with which the miniport driver calls VideoPortInitialize().
  728. Context2 - Second context value passed by the operating system. This is
  729. the value with which the miniport driver calls 3VideoPortInitialize().
  730. Return Value:
  731. Status from VideoPortInitialize()
  732. --*/
  733. {
  734. VIDEO_HW_INITIALIZATION_DATA hwInitData;
  735. ULONG status;
  736. ULONG initializationStatus = (ULONG) -1;
  737. //
  738. // Zero out structure.
  739. //
  740. VideoPortZeroMemory(&hwInitData, sizeof(VIDEO_HW_INITIALIZATION_DATA));
  741. //
  742. // Specify sizes of structure and extension.
  743. //
  744. hwInitData.HwInitDataSize = sizeof(VIDEO_HW_INITIALIZATION_DATA);
  745. //
  746. // Set entry points.
  747. //
  748. hwInitData.HwFindAdapter = VgaFindAdapter;
  749. hwInitData.HwInitialize = VgaInitialize;
  750. hwInitData.HwInterrupt = NULL;
  751. hwInitData.HwStartIO = VgaStartIO;
  752. #if (_WIN32_WINNT>= 0x0500)
  753. hwInitData.HwGetVideoChildDescriptor = CirrusGetChildDescriptor;
  754. hwInitData.HwGetPowerState = CirrusGetPowerState;
  755. hwInitData.HwSetPowerState = CirrusSetPowerState;
  756. hwInitData.HwLegacyResourceList = VgaAccessRange;
  757. hwInitData.HwLegacyResourceCount = 3;
  758. #endif
  759. //
  760. // Determine the size we require for the device extension.
  761. //
  762. hwInitData.HwDeviceExtensionSize = sizeof(HW_DEVICE_EXTENSION);
  763. //
  764. // Always start with parameters for device0 in this case.
  765. // We can leave it like this since we know we will only ever find one
  766. // VGA type adapter in a machine.
  767. //
  768. // hwInitData.StartingDeviceNumber = 0;
  769. //
  770. // Once all the relevant information has been stored, call the video
  771. // port driver to do the initialization.
  772. // For this device we will repeat this call three times, for ISA, EISA
  773. // and PCI.
  774. // We will return the minimum of all return values.
  775. //
  776. //
  777. // We will try the PCI bus first so that our ISA detection does'nt claim
  778. // PCI cards (since it is impossible to differentiate between the two
  779. // by looking at the registers).
  780. //
  781. //
  782. // NOTE: since this driver only supports one adapter, we will return
  783. // as soon as we find a device, without going on to the following buses.
  784. // Normally one would call for each bus type and return the smallest
  785. // value.
  786. //
  787. hwInitData.AdapterInterfaceType = PCIBus;
  788. initializationStatus = VideoPortInitialize(Context1,
  789. Context2,
  790. &hwInitData,
  791. NULL);
  792. if (initializationStatus == NO_ERROR)
  793. {
  794. return initializationStatus;
  795. }
  796. hwInitData.AdapterInterfaceType = MicroChannel;
  797. initializationStatus = VideoPortInitialize(Context1,
  798. Context2,
  799. &hwInitData,
  800. NULL);
  801. //
  802. // Return immediately instead of checkin for smallest return code.
  803. //
  804. if (initializationStatus == NO_ERROR)
  805. {
  806. return initializationStatus;
  807. }
  808. hwInitData.AdapterInterfaceType = Isa;
  809. initializationStatus = VideoPortInitialize(Context1,
  810. Context2,
  811. &hwInitData,
  812. NULL);
  813. if (initializationStatus == NO_ERROR)
  814. {
  815. return initializationStatus;
  816. }
  817. hwInitData.AdapterInterfaceType = Eisa;
  818. initializationStatus = VideoPortInitialize(Context1,
  819. Context2,
  820. &hwInitData,
  821. NULL);
  822. if (initializationStatus == NO_ERROR)
  823. {
  824. return initializationStatus;
  825. }
  826. hwInitData.AdapterInterfaceType = Internal;
  827. status = VideoPortInitialize(Context1,
  828. Context2,
  829. &hwInitData,
  830. NULL);
  831. if (initializationStatus > status) {
  832. initializationStatus = status;
  833. }
  834. return initializationStatus;
  835. } // end DriverEntry()
  836. //---------------------------------------------------------------------------
  837. VP_STATUS
  838. VgaFindAdapter(
  839. PVOID HwDeviceExtension,
  840. PVOID HwContext,
  841. PWSTR ArgumentString,
  842. PVIDEO_PORT_CONFIG_INFO ConfigInfo,
  843. PUCHAR Again
  844. )
  845. /*++
  846. Routine Description:
  847. This routine is called to determine if the adapter for this driver
  848. is present in the system.
  849. If it is present, the function fills out some information describing
  850. the adapter.
  851. Arguments:
  852. HwDeviceExtension - Supplies the miniport driver's adapter storage. This
  853. storage is initialized to zero before this call.
  854. HwContext - Supplies the context value which was passed to
  855. VideoPortInitialize(). Must be NULL for PnP drivers.
  856. ArgumentString - Supplies a NULL terminated ASCII string. This string
  857. originates from the user.
  858. ConfigInfo - Returns the configuration information structure which is
  859. filled by the miniport driver. This structure is initialized with
  860. any known configuration information (such as SystemIoBusNumber) by
  861. the port driver. Where possible, drivers should have one set of
  862. defaults which do not require any supplied configuration information.
  863. Again - Indicates if the miniport driver wants the port driver to call
  864. its VIDEO_HW_FIND_ADAPTER function again with a new device extension
  865. and the same config info. This is used by the miniport drivers which
  866. can search for several adapters on a bus.
  867. Return Value:
  868. This routine must return:
  869. NO_ERROR - Indicates a host adapter was found and the
  870. configuration information was successfully determined.
  871. ERROR_INVALID_PARAMETER - Indicates an adapter was found but there was an
  872. error obtaining the configuration information. If possible an error
  873. should be logged.
  874. ERROR_DEV_NOT_EXIST - Indicates no host adapter was found for the
  875. supplied configuration information.
  876. --*/
  877. {
  878. PHW_DEVICE_EXTENSION hwDeviceExtension = HwDeviceExtension;
  879. VP_STATUS status;
  880. ULONG NumAccessRanges = NUM_VGA_ACCESS_RANGES;
  881. ULONG VESATimingBits ;
  882. VIDEO_ACCESS_RANGE AccessRangesTemp[5];
  883. //
  884. // if there are two cirrus cards and the one that is disabled is the second
  885. // one FindAdapter is called for, then we need to avoid writing to the global
  886. // VgaAccessRange. So make local copy of it
  887. //
  888. VideoPortMoveMemory((PUCHAR) AccessRangesTemp,
  889. (PUCHAR) VgaAccessRange,
  890. 5*sizeof(VIDEO_ACCESS_RANGE));
  891. //
  892. // Make sure the size of the structure is at least as large as what we
  893. // are expecting (check version of the config info structure).
  894. //
  895. if (ConfigInfo->Length < sizeof(VIDEO_PORT_CONFIG_INFO)) {
  896. return ERROR_INVALID_PARAMETER;
  897. }
  898. //
  899. // Store the bus type
  900. //
  901. hwDeviceExtension->BusType = ConfigInfo->AdapterInterfaceType;
  902. //
  903. // Assign pfnVideoPortReadXxx and pfnVideoPortWriteXxx
  904. //
  905. hwDeviceExtension->gPortRWfn.pfnVideoPortReadPortUchar = VideoPortReadPortUchar ;
  906. hwDeviceExtension->gPortRWfn.pfnVideoPortReadPortUshort = VideoPortReadPortUshort ;
  907. hwDeviceExtension->gPortRWfn.pfnVideoPortReadPortUlong = VideoPortReadPortUlong ;
  908. hwDeviceExtension->gPortRWfn.pfnVideoPortWritePortUchar = VideoPortWritePortUchar ;
  909. hwDeviceExtension->gPortRWfn.pfnVideoPortWritePortUshort = VideoPortWritePortUshort ;
  910. hwDeviceExtension->gPortRWfn.pfnVideoPortWritePortUlong = VideoPortWritePortUlong ;
  911. //
  912. // Detect the PCI card.
  913. //
  914. if (ConfigInfo->AdapterInterfaceType == PCIBus)
  915. {
  916. VideoDebugPrint((1, "Cirrus!VgaFindAdapter: "
  917. "ConfigInfo->AdapterInterfaceType == PCIBus\n"));//1
  918. if (!CirrusConfigurePCI(HwDeviceExtension,
  919. &NumAccessRanges,
  920. AccessRangesTemp))
  921. {
  922. VideoDebugPrint((1, "Failure Returned From CirrusConfigurePCI\n"));//1
  923. return ERROR_DEV_NOT_EXIST;
  924. }
  925. }
  926. else
  927. {
  928. VideoDebugPrint((1, "Cirrus!VgaFindAdapter: "
  929. "ConfigInfo->AdapterInterfaceType != PCIBus\n"));//1
  930. }
  931. //
  932. // No interrupt information is necessary.
  933. //
  934. if (AccessRangesTemp[3].RangeLength == 0)
  935. {
  936. //
  937. // The last access range (range[3]) is the access range for
  938. // the linear frame buffer. If this access range has a
  939. // range length of 0, then some HAL's will fail the request.
  940. // Therefore, if we are not using the last access range,
  941. // I'll not try to reserve it.
  942. //
  943. NumAccessRanges--;
  944. }
  945. //
  946. // Check to see if there is a hardware resource conflict.
  947. // (or if card is disabled)
  948. //
  949. status = VideoPortVerifyAccessRanges(HwDeviceExtension,
  950. NumAccessRanges,
  951. AccessRangesTemp);
  952. if (status != NO_ERROR) {
  953. VideoDebugPrint((1, "ERROR: VPVerifyAccessRanges failed!\n"));
  954. return status;
  955. }
  956. //
  957. // VideoPortVerifyAccessRanges will fail for a card that is disabled.
  958. // This card is not disabled. We can write to the global VgaAccessRange
  959. //
  960. VideoPortMoveMemory((PUCHAR) VgaAccessRange,
  961. (PUCHAR) AccessRangesTemp,
  962. NumAccessRanges*sizeof(VIDEO_ACCESS_RANGE));
  963. //
  964. // Get logical IO port addresses.
  965. //
  966. if (hwDeviceExtension->bMMAddress)
  967. {
  968. if ((hwDeviceExtension->IOAddress =
  969. VideoPortGetDeviceBase(hwDeviceExtension,
  970. VgaAccessRange[4].RangeStart,
  971. VGA_MAX_IO_PORT - VGA_END_BREAK_PORT + 1,
  972. VgaAccessRange[4].RangeInIoSpace)) == NULL)
  973. {
  974. VideoDebugPrint((2, "VgaFindAdapter - Fail to get io address\n"));
  975. return ERROR_INVALID_PARAMETER;
  976. }
  977. hwDeviceExtension->IOAddress -= VGA_END_BREAK_PORT;
  978. }
  979. else
  980. {
  981. if ((hwDeviceExtension->IOAddress =
  982. VideoPortGetDeviceBase(hwDeviceExtension,
  983. VgaAccessRange->RangeStart,
  984. VGA_MAX_IO_PORT - VGA_BASE_IO_PORT + 1,
  985. VgaAccessRange->RangeInIoSpace)) == NULL)
  986. {
  987. VideoDebugPrint((2, "VgaFindAdapter - Fail to get io address\n"));
  988. return ERROR_INVALID_PARAMETER;
  989. }
  990. hwDeviceExtension->IOAddress -= VGA_BASE_IO_PORT;
  991. }
  992. //
  993. // Determine whether a VGA is present.
  994. //
  995. if (!VgaIsPresent(hwDeviceExtension)) {
  996. VideoDebugPrint((1, "CirrusFindAdapter - VGA Failed\n"));
  997. return ERROR_DEV_NOT_EXIST;
  998. }
  999. //
  1000. // Minimum size of the buffer required to store the hardware state
  1001. // information returned by IOCTL_VIDEO_SAVE_HARDWARE_STATE.
  1002. //
  1003. ConfigInfo->HardwareStateSize = VGA_TOTAL_STATE_SIZE;
  1004. //
  1005. // now that we have the video memory address in protected mode, lets do
  1006. // the required video card initialization. We will try to detect a Cirrus
  1007. // Logic chipset...
  1008. //
  1009. //
  1010. // Determine whether an CL6410/6420/542x/543x is present.
  1011. //
  1012. //
  1013. // CirrusLogicIsPresent may set up the
  1014. // hwDeviceExtesion->AdapterMemorySize field. Set it
  1015. // to 0 now, so I can compare against this later to
  1016. // see if CirrusLogicIsPresent assigned a value.
  1017. //
  1018. hwDeviceExtension->AdapterMemorySize = 0;
  1019. if (!CirrusLogicIsPresent(hwDeviceExtension))
  1020. {
  1021. VideoDebugPrint((1, "CirrusFindAdapter - Failed\n"));
  1022. return ERROR_DEV_NOT_EXIST;
  1023. }
  1024. //
  1025. // Pass a pointer to the emulator range we are using.
  1026. //
  1027. ConfigInfo->NumEmulatorAccessEntries = VGA_NUM_EMULATOR_ACCESS_ENTRIES;
  1028. ConfigInfo->EmulatorAccessEntries = VgaEmulatorAccessEntries;
  1029. ConfigInfo->EmulatorAccessEntriesContext = (ULONG_PTR) hwDeviceExtension;
  1030. //
  1031. // There is really no reason to have the frame buffer mapped. On an
  1032. // x86 we use if for save/restore (supposedly) but even then we
  1033. // would only need to map a 64K window, not all 16 Meg!
  1034. //
  1035. #ifdef _X86_
  1036. //
  1037. // Map the video memory into the system virtual address space so we can
  1038. // clear it out and use it for save and restore.
  1039. //
  1040. if ( (hwDeviceExtension->VideoMemoryAddress =
  1041. VideoPortGetDeviceBase(hwDeviceExtension,
  1042. VgaAccessRange[2].RangeStart,
  1043. VgaAccessRange[2].RangeLength,
  1044. FALSE)) == NULL)
  1045. {
  1046. VideoDebugPrint((1, "VgaFindAdapter - Fail to get memory address\n"));
  1047. return ERROR_INVALID_PARAMETER;
  1048. }
  1049. #endif
  1050. //
  1051. // Size the memory
  1052. //
  1053. //
  1054. // The size may have been set up in detection code, so
  1055. // don't destroy if already set.
  1056. //
  1057. if( hwDeviceExtension->AdapterMemorySize == 0 )
  1058. {
  1059. hwDeviceExtension->AdapterMemorySize =
  1060. CirrusFindVmemSize(hwDeviceExtension);
  1061. }
  1062. //
  1063. // Write hardware info into registry
  1064. //
  1065. WriteRegistryInfo(hwDeviceExtension);
  1066. ConfigInfo->VdmPhysicalVideoMemoryAddress.LowPart = MEM_VGA;
  1067. ConfigInfo->VdmPhysicalVideoMemoryLength = MEM_VGA_SIZE;
  1068. ConfigInfo->VdmPhysicalVideoMemoryAddress.HighPart = 0x00000000;
  1069. #if 0
  1070. // removed the following call. This fixes MS bug #163251
  1071. //#if DDC2B
  1072. //
  1073. // Check DDC2B monitor, get EDID table.
  1074. // Turn on/off extended modes according the properties of the monitor.
  1075. //
  1076. // The miniport takes forever to load doing DDC on an
  1077. // ISA 5434 in a DELL XPS P120c.
  1078. // (IDEKIyama Vision Master 17 Monitor).
  1079. //
  1080. // Let only try to get DDC info on PCI cards for now.
  1081. // CIRRUS - Can you fix this?
  1082. if (ConfigInfo->AdapterInterfaceType == PCIBus) {
  1083. ReadVESATiming ( hwDeviceExtension ) ;
  1084. }
  1085. #endif
  1086. //
  1087. // Determines which modes are valid.
  1088. //
  1089. #if DDC2B
  1090. CirrusValidateModes(hwDeviceExtension);
  1091. #endif
  1092. #if (_WIN32_WINNT <= 0x0400)
  1093. CheckAndUpdateDDC2BMonitor(hwDeviceExtension);
  1094. #endif (_WIN32_WINNT <= 0x0400)
  1095. if (hwDeviceExtension->NumAvailableModes == 0)
  1096. {
  1097. VideoDebugPrint((1, "FindAdapter failed because there are no"
  1098. "available modes.\n"));
  1099. return ERROR_INVALID_PARAMETER;
  1100. }
  1101. //
  1102. // Fix the 5446Ac and 440FX core logic coexist bug.
  1103. //
  1104. if (hwDeviceExtension->ChipType == CL5446)
  1105. {
  1106. CirrusUpdate440FX(hwDeviceExtension);
  1107. }
  1108. //
  1109. // Once modes are validated, all 543x's are the same (the number
  1110. // of modes available is the only difference).
  1111. //
  1112. #if 0
  1113. //myf31: for RadiSYS special driver, change MCLK to 66MHz
  1114. if (hwDeviceExtension->ChipType == CL7555)
  1115. {
  1116. VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
  1117. SEQ_ADDRESS_PORT, 0x1F);
  1118. SR1F = VideoPortReadPortUchar(hwDeviceExtension->IOAddress +
  1119. SEQ_DATA_PORT) & 0xC0;
  1120. VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
  1121. SEQ_DATA_PORT, (SR1F | 0x25));
  1122. }
  1123. //myf31 end
  1124. #endif
  1125. if ((hwDeviceExtension->ChipType == CL5434) ||
  1126. (hwDeviceExtension->ChipType == CL5434_6) ||
  1127. (hwDeviceExtension->ChipType == CL5436) ||
  1128. (hwDeviceExtension->ChipType == CL5446) ||
  1129. (hwDeviceExtension->ChipType == CL5446BE) ||
  1130. (hwDeviceExtension->ChipType == CL5480))
  1131. {
  1132. hwDeviceExtension->ChipType = CL543x;
  1133. }
  1134. //
  1135. // Indicate we do not wish to be called again for another initialization.
  1136. //
  1137. *Again = 0;
  1138. //
  1139. // Indicate a successful completion status.
  1140. //
  1141. return NO_ERROR;
  1142. }
  1143. //---------------------------------------------------------------------------
  1144. BOOLEAN
  1145. VgaInitialize(
  1146. PVOID HwDeviceExtension
  1147. )
  1148. /*++
  1149. Routine Description:
  1150. This routine does one time initialization of the device.
  1151. Arguments:
  1152. HwDeviceExtension - Pointer to the miniport driver's adapter information.
  1153. Return Value:
  1154. None.
  1155. --*/
  1156. {
  1157. VP_STATUS status;
  1158. VIDEO_X86_BIOS_ARGUMENTS biosArguments;
  1159. PHW_DEVICE_EXTENSION hwDeviceExtension = HwDeviceExtension;
  1160. //
  1161. // Get the BIOS version number.
  1162. //
  1163. VideoPortZeroMemory(&biosArguments, sizeof(VIDEO_X86_BIOS_ARGUMENTS));
  1164. biosArguments.Eax = 0x1200;
  1165. biosArguments.Ebx = 0x81;
  1166. status = VideoPortInt10(HwDeviceExtension, &biosArguments);
  1167. if (status == NO_ERROR)
  1168. {
  1169. hwDeviceExtension->ulBIOSVersionNumber = biosArguments.Eax;
  1170. }
  1171. else
  1172. hwDeviceExtension->ulBIOSVersionNumber = 0;
  1173. hwDeviceExtension->bBlockSwitch = 0;
  1174. biosArguments.Eax = 0x1200;
  1175. biosArguments.Ebx = 0x9A;
  1176. status = VideoPortInt10(HwDeviceExtension, &biosArguments);
  1177. hwDeviceExtension->bDisplaytype = CRT_type;
  1178. if (status == NO_ERROR)
  1179. {
  1180. if (!(biosArguments.Eax & 0x0100))
  1181. hwDeviceExtension->bDisplaytype = LCD_type;
  1182. else if (!(biosArguments.Ebx & 0x0200))
  1183. hwDeviceExtension->bDisplaytype = SIM_type;
  1184. }
  1185. VideoPortZeroMemory(&biosArguments, sizeof(VIDEO_X86_BIOS_ARGUMENTS));
  1186. biosArguments.Eax = VESA_POWER_FUNCTION;
  1187. biosArguments.Ebx = VESA_GET_POWER_FUNC;
  1188. status = VideoPortInt10(HwDeviceExtension, &biosArguments);
  1189. if ((status == NO_ERROR) &&
  1190. ((biosArguments.Eax & 0xffff) == VESA_STATUS_SUCCESS))
  1191. {
  1192. hwDeviceExtension->PMCapability = biosArguments.Ebx;
  1193. }
  1194. else
  1195. {
  1196. hwDeviceExtension->PMCapability = 0;
  1197. }
  1198. //
  1199. // set up the default cursor position and type.
  1200. //
  1201. hwDeviceExtension->CursorPosition.Column = 0;
  1202. hwDeviceExtension->CursorPosition.Row = 0;
  1203. hwDeviceExtension->CursorTopScanLine = 0;
  1204. hwDeviceExtension->CursorBottomScanLine = 31;
  1205. hwDeviceExtension->CursorEnable = TRUE;
  1206. return TRUE;
  1207. }
  1208. //---------------------------------------------------------------------------
  1209. BOOLEAN
  1210. VgaStartIO(
  1211. PVOID pHwDeviceExtension,
  1212. PVIDEO_REQUEST_PACKET RequestPacket
  1213. )
  1214. /*++
  1215. Routine Description:
  1216. This routine is the main execution routine for the miniport driver. It
  1217. accepts a Video Request Packet, performs the request, and then returns
  1218. with the appropriate status.
  1219. Arguments:
  1220. HwDeviceExtension - Pointer to the miniport driver's adapter information.
  1221. RequestPacket - Pointer to the video request packet. This structure
  1222. contains all the parameters passed to the VideoIoControl function.
  1223. Return Value:
  1224. This routine will return error codes from the various support routines
  1225. and will also return ERROR_INSUFFICIENT_BUFFER for incorrectly sized
  1226. buffers and ERROR_INVALID_FUNCTION for unsupported functions.
  1227. --*/
  1228. {
  1229. PHW_DEVICE_EXTENSION hwDeviceExtension = pHwDeviceExtension;
  1230. PHW_DEVICE_EXTENSION HwDeviceExtension = pHwDeviceExtension;
  1231. VP_STATUS status;
  1232. VIDEO_MODE videoMode;
  1233. PVIDEO_MEMORY_INFORMATION memoryInformation;
  1234. ULONG inIoSpace;
  1235. ULONG physicalFrameLength;
  1236. PVIDEO_SHARE_MEMORY pShareMemory;
  1237. PVIDEO_SHARE_MEMORY_INFORMATION pShareMemoryInformation;
  1238. PHYSICAL_ADDRESS shareAddress;
  1239. PVOID virtualAddress;
  1240. ULONG sharedViewSize;
  1241. UCHAR SR0A;
  1242. //
  1243. // Switch on the IoContolCode in the RequestPacket. It indicates which
  1244. // function must be performed by the driver.
  1245. //
  1246. switch (RequestPacket->IoControlCode)
  1247. {
  1248. case IOCTL_VIDEO_SHARE_VIDEO_MEMORY:
  1249. VideoDebugPrint((2, "VgaStartIO - ShareVideoMemory\n"));
  1250. if ((RequestPacket->OutputBufferLength < sizeof(VIDEO_SHARE_MEMORY_INFORMATION)) ||
  1251. (RequestPacket->InputBufferLength < sizeof(VIDEO_MEMORY)) )
  1252. {
  1253. VideoDebugPrint((1, "VgaStartIO - ShareVideoMemory - ERROR_INSUFFICIENT_BUFFER\n"));
  1254. status = ERROR_INSUFFICIENT_BUFFER;
  1255. break;
  1256. }
  1257. pShareMemory = RequestPacket->InputBuffer;
  1258. RequestPacket->StatusBlock->Information =
  1259. sizeof(VIDEO_SHARE_MEMORY_INFORMATION);
  1260. //
  1261. // Beware: the input buffer and the output buffer are the same
  1262. // buffer, and therefore data should not be copied from one to the
  1263. // other
  1264. //
  1265. virtualAddress = pShareMemory->ProcessHandle;
  1266. sharedViewSize = pShareMemory->ViewSize;
  1267. //
  1268. // If you change to using a dense space frame buffer, make this
  1269. // value a 4 for the ALPHA.
  1270. //
  1271. inIoSpace = 0;
  1272. //
  1273. // NOTE: we are ignoring ViewOffset
  1274. //
  1275. shareAddress.QuadPart =
  1276. hwDeviceExtension->PhysicalFrameOffset.QuadPart +
  1277. hwDeviceExtension->PhysicalVideoMemoryBase.QuadPart;
  1278. if (hwDeviceExtension->LinearMode)
  1279. {
  1280. //
  1281. // Add P6CACHE support
  1282. //
  1283. #if P6CACHE
  1284. #if (_WIN32_WINNT >= 0x0400)
  1285. inIoSpace |= VIDEO_MEMORY_SPACE_P6CACHE;
  1286. #endif
  1287. #endif
  1288. status = VideoPortMapMemory(hwDeviceExtension,
  1289. shareAddress,
  1290. &sharedViewSize,
  1291. &inIoSpace,
  1292. &virtualAddress);
  1293. }
  1294. else
  1295. {
  1296. ULONG ulBankSize;
  1297. VOID (*pfnBank)(ULONG,ULONG,PVOID);
  1298. switch (hwDeviceExtension->ChipType) {
  1299. case CL542x: pfnBank = vBankMap_CL542x;
  1300. break;
  1301. case CL543x: pfnBank = vBankMap_CL543x;
  1302. break;
  1303. default: pfnBank = vBankMap_CL64xx;
  1304. break;
  1305. };
  1306. #if ONE_64K_BANK
  1307. //
  1308. // The Cirrus Logic VGA's support one 64K read/write bank.
  1309. //
  1310. ulBankSize = 0x10000; // 64K bank start adjustment
  1311. #endif
  1312. #if TWO_32K_BANKS
  1313. //
  1314. // The Cirrus Logic VGA's support two 32K read/write banks.
  1315. //
  1316. ulBankSize = 0x8000; // 32K bank start adjustment
  1317. #endif
  1318. status = VideoPortMapBankedMemory(hwDeviceExtension,
  1319. shareAddress,
  1320. &sharedViewSize,
  1321. &inIoSpace,
  1322. &virtualAddress,
  1323. ulBankSize,
  1324. FALSE,
  1325. pfnBank,
  1326. (PVOID)hwDeviceExtension);
  1327. }
  1328. pShareMemoryInformation = RequestPacket->OutputBuffer;
  1329. pShareMemoryInformation->SharedViewOffset = pShareMemory->ViewOffset;
  1330. pShareMemoryInformation->VirtualAddress = virtualAddress;
  1331. pShareMemoryInformation->SharedViewSize = sharedViewSize;
  1332. break;
  1333. case IOCTL_VIDEO_UNSHARE_VIDEO_MEMORY:
  1334. VideoDebugPrint((2, "VgaStartIO - UnshareVideoMemory\n"));
  1335. if (RequestPacket->InputBufferLength < sizeof(VIDEO_SHARE_MEMORY)) {
  1336. status = ERROR_INSUFFICIENT_BUFFER;
  1337. break;
  1338. }
  1339. pShareMemory = RequestPacket->InputBuffer;
  1340. status = VideoPortUnmapMemory(hwDeviceExtension,
  1341. pShareMemory->RequestedVirtualAddress,
  1342. pShareMemory->ProcessHandle);
  1343. break;
  1344. case IOCTL_VIDEO_MAP_VIDEO_MEMORY:
  1345. VideoDebugPrint((2, "VgaStartIO - MapVideoMemory\n"));
  1346. if ((RequestPacket->OutputBufferLength <
  1347. (RequestPacket->StatusBlock->Information =
  1348. sizeof(VIDEO_MEMORY_INFORMATION))) ||
  1349. (RequestPacket->InputBufferLength < sizeof(VIDEO_MEMORY)) )
  1350. {
  1351. status = ERROR_INSUFFICIENT_BUFFER;
  1352. }
  1353. memoryInformation = RequestPacket->OutputBuffer;
  1354. memoryInformation->VideoRamBase = ((PVIDEO_MEMORY)
  1355. (RequestPacket->InputBuffer))->RequestedVirtualAddress;
  1356. //
  1357. // We reserved 16 meg for the frame buffer, however, it makes
  1358. // no sense to map more memory than there is on the card. So
  1359. // only map the amount of memory we have on the card.
  1360. //
  1361. memoryInformation->VideoRamLength =
  1362. hwDeviceExtension->AdapterMemorySize;
  1363. //
  1364. // If you change to using a dense space frame buffer, make this
  1365. // value a 4 for the ALPHA.
  1366. //
  1367. inIoSpace = 0;
  1368. //
  1369. // Add P6CACHE support
  1370. //
  1371. physicalFrameLength = hwDeviceExtension->PhysicalVideoMemoryLength;
  1372. #if P6CACHE
  1373. #if (_WIN32_WINNT >= 0x0400)
  1374. //
  1375. // We saw corrupted screen in 16 color mode on 54M40 if P6CAHCHE
  1376. // is enabled. We only turn on P6CACHE when we see two access
  1377. // ranges (so that we know this request is from cirrus.dll but
  1378. // not from vga.dll)
  1379. //
  1380. if (RequestPacket->OutputBufferLength >= // if we have room for
  1381. sizeof(VIDEO_MEMORY_INFORMATION) * 2) // another access range
  1382. {
  1383. inIoSpace |= VIDEO_MEMORY_SPACE_P6CACHE;
  1384. if ( physicalFrameLength < 0x00400000)
  1385. {
  1386. physicalFrameLength = 0x00400000;
  1387. }
  1388. }
  1389. #endif
  1390. #endif
  1391. status = VideoPortMapMemory(hwDeviceExtension,
  1392. hwDeviceExtension->PhysicalVideoMemoryBase,
  1393. &physicalFrameLength,
  1394. &inIoSpace,
  1395. &(memoryInformation->VideoRamBase));
  1396. if (status != NO_ERROR) {
  1397. VideoDebugPrint((1, "VgaStartIO - IOCTL_VIDEO_MAP_VIDEO_MEMORY failed VideoPortMapMemory (%x)\n", status));
  1398. break;
  1399. }
  1400. memoryInformation->FrameBufferBase =
  1401. ((PUCHAR) (memoryInformation->VideoRamBase)) +
  1402. hwDeviceExtension->PhysicalFrameOffset.LowPart;
  1403. memoryInformation->FrameBufferLength =
  1404. hwDeviceExtension->PhysicalFrameLength ?
  1405. hwDeviceExtension->PhysicalFrameLength :
  1406. memoryInformation->VideoRamLength;
  1407. VideoDebugPrint((2, "physical VideoMemoryBase %08lx\n", hwDeviceExtension->PhysicalVideoMemoryBase));
  1408. VideoDebugPrint((2, "physical VideoMemoryLength %08lx\n", hwDeviceExtension->PhysicalVideoMemoryLength));
  1409. VideoDebugPrint((2, "VideoMemoryBase %08lx\n", memoryInformation->VideoRamBase));
  1410. VideoDebugPrint((2, "VideoMemoryLength %08lx\n", memoryInformation->VideoRamLength));
  1411. VideoDebugPrint((2, "physical framebuf offset %08lx\n", hwDeviceExtension->PhysicalFrameOffset.LowPart));
  1412. VideoDebugPrint((2, "framebuf base %08lx\n", memoryInformation->FrameBufferBase));
  1413. VideoDebugPrint((2, "physical framebuf len %08lx\n", hwDeviceExtension->PhysicalFrameLength));
  1414. VideoDebugPrint((2, "framebuf length %08lx\n", memoryInformation->FrameBufferLength));
  1415. //
  1416. // add address mapping for system to screen blt
  1417. //
  1418. if (RequestPacket->OutputBufferLength >= // if we have room for
  1419. sizeof(VIDEO_MEMORY_INFORMATION) * 2) // another access range
  1420. {
  1421. RequestPacket->StatusBlock->Information =
  1422. sizeof(VIDEO_MEMORY_INFORMATION) * 2;
  1423. memoryInformation++;
  1424. memoryInformation->VideoRamBase = (PVOID)NULL;
  1425. if (hwDeviceExtension->bSecondAperture)
  1426. {
  1427. //
  1428. // We reserved 16 meg for the frame buffer, however, it makes
  1429. // no sense to map more memory than there is on the card. So
  1430. // only map the amount of memory we have on the card.
  1431. //
  1432. memoryInformation->VideoRamLength =
  1433. hwDeviceExtension->AdapterMemorySize;
  1434. //
  1435. // If you change to using a dense space frame buffer, make this
  1436. // value a 4 for the ALPHA.
  1437. //
  1438. inIoSpace = 0;
  1439. //
  1440. // Add P6CACHE support
  1441. //
  1442. #if P6CACHE
  1443. #if (_WIN32_WINNT >= 0x0400)
  1444. inIoSpace |= VIDEO_MEMORY_SPACE_P6CACHE;
  1445. #endif
  1446. #endif
  1447. shareAddress.QuadPart =
  1448. hwDeviceExtension->PhysicalVideoMemoryBase.QuadPart +
  1449. 0x1000000; // add 16M offset
  1450. status = VideoPortMapMemory(hwDeviceExtension,
  1451. shareAddress,
  1452. &physicalFrameLength,
  1453. &inIoSpace,
  1454. &(memoryInformation->VideoRamBase));
  1455. if (status != NO_ERROR)
  1456. {
  1457. VideoDebugPrint((1, "VgaStartIO - IOCTL_VIDEO_MAP_VIDEO_MEMORY failed for system to screen blt mapping (%x)\n", status));
  1458. }
  1459. }
  1460. }
  1461. break;
  1462. case IOCTL_VIDEO_UNMAP_VIDEO_MEMORY:
  1463. VideoDebugPrint((2, "VgaStartIO - UnMapVideoMemory\n"));
  1464. if (RequestPacket->InputBufferLength < sizeof(VIDEO_MEMORY))
  1465. {
  1466. status = ERROR_INSUFFICIENT_BUFFER;
  1467. }
  1468. status = VideoPortUnmapMemory(hwDeviceExtension,
  1469. ((PVIDEO_MEMORY)
  1470. (RequestPacket->InputBuffer))->
  1471. RequestedVirtualAddress,
  1472. 0);
  1473. break;
  1474. case IOCTL_VIDEO_QUERY_AVAIL_MODES:
  1475. VideoDebugPrint((2, "VgaStartIO - QueryAvailableModes\n"));
  1476. RequestPacket->StatusBlock->Information = 0;
  1477. status = VgaQueryAvailableModes(HwDeviceExtension,
  1478. (PVIDEO_MODE_INFORMATION)
  1479. RequestPacket->OutputBuffer,
  1480. RequestPacket->OutputBufferLength,
  1481. (PULONG)&RequestPacket->StatusBlock->Information);
  1482. break;
  1483. case IOCTL_VIDEO_QUERY_NUM_AVAIL_MODES:
  1484. VideoDebugPrint((2, "VgaStartIO - QueryNumAvailableModes\n"));
  1485. RequestPacket->StatusBlock->Information = 0;
  1486. status = VgaQueryNumberOfAvailableModes(HwDeviceExtension,
  1487. (PVIDEO_NUM_MODES)
  1488. RequestPacket->OutputBuffer,
  1489. RequestPacket->OutputBufferLength,
  1490. (PULONG)&RequestPacket->StatusBlock->Information);
  1491. break;
  1492. case IOCTL_VIDEO_QUERY_CURRENT_MODE:
  1493. VideoDebugPrint((2, "VgaStartIO - QueryCurrentMode\n"));
  1494. RequestPacket->StatusBlock->Information = 0;
  1495. status = VgaQueryCurrentMode(HwDeviceExtension,
  1496. (PVIDEO_MODE_INFORMATION) RequestPacket->OutputBuffer,
  1497. RequestPacket->OutputBufferLength,
  1498. (PULONG)&RequestPacket->StatusBlock->Information);
  1499. break;
  1500. case IOCTL_VIDEO_SET_CURRENT_MODE:
  1501. VideoDebugPrint((2, "VgaStartIO - SetCurrentModes\n"));
  1502. status = VgaSetMode(HwDeviceExtension,
  1503. (PVIDEO_MODE) RequestPacket->InputBuffer,
  1504. RequestPacket->InputBufferLength);
  1505. break;
  1506. case IOCTL_VIDEO_RESET_DEVICE:
  1507. VideoDebugPrint((2, "VgaStartIO - Reset Device\n"));
  1508. videoMode.RequestedMode = DEFAULT_MODE;
  1509. VgaSetMode(HwDeviceExtension,
  1510. (PVIDEO_MODE) &videoMode,
  1511. sizeof(videoMode));
  1512. //
  1513. // Always return succcess since settings the text mode will fail on
  1514. // non-x86.
  1515. //
  1516. // Also, failiure to set the text mode is not fatal in any way, since
  1517. // this operation must be followed by another set mode operation.
  1518. //
  1519. status = NO_ERROR;
  1520. break;
  1521. case IOCTL_VIDEO_LOAD_AND_SET_FONT:
  1522. VideoDebugPrint((2, "VgaStartIO - LoadAndSetFont\n"));
  1523. status = VgaLoadAndSetFont(HwDeviceExtension,
  1524. (PVIDEO_LOAD_FONT_INFORMATION) RequestPacket->InputBuffer,
  1525. RequestPacket->InputBufferLength);
  1526. break;
  1527. case IOCTL_VIDEO_QUERY_CURSOR_POSITION:
  1528. VideoDebugPrint((2, "VgaStartIO - QueryCursorPosition\n"));
  1529. RequestPacket->StatusBlock->Information = 0;
  1530. status = VgaQueryCursorPosition(HwDeviceExtension,
  1531. (PVIDEO_CURSOR_POSITION) RequestPacket->OutputBuffer,
  1532. RequestPacket->OutputBufferLength,
  1533. (PULONG)&RequestPacket->StatusBlock->Information);
  1534. break;
  1535. case IOCTL_VIDEO_SET_CURSOR_POSITION:
  1536. VideoDebugPrint((2, "VgaStartIO - SetCursorPosition\n"));
  1537. status = VgaSetCursorPosition(HwDeviceExtension,
  1538. (PVIDEO_CURSOR_POSITION)
  1539. RequestPacket->InputBuffer,
  1540. RequestPacket->InputBufferLength);
  1541. break;
  1542. case IOCTL_VIDEO_QUERY_CURSOR_ATTR:
  1543. VideoDebugPrint((2, "VgaStartIO - QueryCursorAttributes\n"));
  1544. RequestPacket->StatusBlock->Information = 0;
  1545. status = VgaQueryCursorAttributes(HwDeviceExtension,
  1546. (PVIDEO_CURSOR_ATTRIBUTES) RequestPacket->OutputBuffer,
  1547. RequestPacket->OutputBufferLength,
  1548. (PULONG)&RequestPacket->StatusBlock->Information);
  1549. break;
  1550. case IOCTL_VIDEO_SET_CURSOR_ATTR:
  1551. VideoDebugPrint((2, "VgaStartIO - SetCursorAttributes\n"));
  1552. status = VgaSetCursorAttributes(HwDeviceExtension,
  1553. (PVIDEO_CURSOR_ATTRIBUTES) RequestPacket->InputBuffer,
  1554. RequestPacket->InputBufferLength);
  1555. break;
  1556. case IOCTL_VIDEO_SET_PALETTE_REGISTERS:
  1557. VideoDebugPrint((2, "VgaStartIO - SetPaletteRegs\n"));
  1558. status = VgaSetPaletteReg(HwDeviceExtension,
  1559. (PVIDEO_PALETTE_DATA) RequestPacket->InputBuffer,
  1560. RequestPacket->InputBufferLength);
  1561. break;
  1562. case IOCTL_VIDEO_SET_COLOR_REGISTERS:
  1563. VideoDebugPrint((2, "VgaStartIO - SetColorRegs\n"));
  1564. status = VgaSetColorLookup(HwDeviceExtension,
  1565. (PVIDEO_CLUT) RequestPacket->InputBuffer,
  1566. RequestPacket->InputBufferLength);
  1567. break;
  1568. case IOCTL_VIDEO_ENABLE_VDM:
  1569. VideoDebugPrint((2, "VgaStartIO - EnableVDM\n"));
  1570. hwDeviceExtension->TrappedValidatorCount = 0;
  1571. hwDeviceExtension->SequencerAddressValue = 0;
  1572. hwDeviceExtension->CurrentNumVdmAccessRanges =
  1573. NUM_MINIMAL_VGA_VALIDATOR_ACCESS_RANGE;
  1574. hwDeviceExtension->CurrentVdmAccessRange =
  1575. MinimalVgaValidatorAccessRange;
  1576. VideoPortSetTrappedEmulatorPorts(hwDeviceExtension,
  1577. hwDeviceExtension->CurrentNumVdmAccessRanges,
  1578. hwDeviceExtension->CurrentVdmAccessRange);
  1579. status = NO_ERROR;
  1580. break;
  1581. case IOCTL_VIDEO_RESTORE_HARDWARE_STATE:
  1582. VideoDebugPrint((2, "VgaStartIO - RestoreHardwareState\n"));
  1583. status = VgaRestoreHardwareState(HwDeviceExtension,
  1584. (PVIDEO_HARDWARE_STATE) RequestPacket->InputBuffer,
  1585. RequestPacket->InputBufferLength);
  1586. break;
  1587. case IOCTL_VIDEO_SAVE_HARDWARE_STATE:
  1588. VideoDebugPrint((2, "VgaStartIO - SaveHardwareState\n"));
  1589. RequestPacket->StatusBlock->Information = 0;
  1590. status = VgaSaveHardwareState(HwDeviceExtension,
  1591. (PVIDEO_HARDWARE_STATE) RequestPacket->OutputBuffer,
  1592. RequestPacket->OutputBufferLength,
  1593. (PULONG)&RequestPacket->StatusBlock->Information);
  1594. break;
  1595. case IOCTL_VIDEO_GET_BANK_SELECT_CODE:
  1596. VideoDebugPrint((2, "VgaStartIO - GetBankSelectCode\n"));
  1597. RequestPacket->StatusBlock->Information = 0;
  1598. status = VgaGetBankSelectCode(HwDeviceExtension,
  1599. (PVIDEO_BANK_SELECT) RequestPacket->OutputBuffer,
  1600. RequestPacket->OutputBufferLength,
  1601. (PULONG)&RequestPacket->StatusBlock->Information);
  1602. VideoDebugPrint((2, "VgaStartIO - END GetBankSelectCode\n"));
  1603. break;
  1604. case IOCTL_VIDEO_QUERY_PUBLIC_ACCESS_RANGES:
  1605. {
  1606. PVIDEO_PUBLIC_ACCESS_RANGES portAccess;
  1607. PHYSICAL_ADDRESS physicalPortAddress;
  1608. ULONG physicalPortLength;
  1609. if (RequestPacket->OutputBufferLength <
  1610. sizeof(VIDEO_PUBLIC_ACCESS_RANGES))
  1611. {
  1612. status = ERROR_INSUFFICIENT_BUFFER;
  1613. break;
  1614. }
  1615. RequestPacket->StatusBlock->Information =
  1616. sizeof(VIDEO_PUBLIC_ACCESS_RANGES);
  1617. portAccess = RequestPacket->OutputBuffer;
  1618. //
  1619. // The first public access range is the IO ports.
  1620. //
  1621. //
  1622. // On the alpha, VGA.DLL will call into the cirrus miniport
  1623. // trying to get a pointer to the IO ports. So, we can never
  1624. // return MMIO to the VGA driver. We'll assume that if the
  1625. // size of the OutputBuffer is only big enough for one access
  1626. // range then the VGA driver is asking for the ranges, and
  1627. // thus we should map them as IO space.
  1628. //
  1629. if ((hwDeviceExtension->bMMAddress) &&
  1630. (RequestPacket->OutputBufferLength >=
  1631. sizeof(VIDEO_PUBLIC_ACCESS_RANGES) * 2))
  1632. {
  1633. // PC97 Compliant
  1634. portAccess->VirtualAddress = (PVOID) NULL;
  1635. portAccess->InIoSpace = FALSE;
  1636. portAccess->MappedInIoSpace = portAccess->InIoSpace;
  1637. // for VGA register
  1638. physicalPortLength = VGA_MAX_IO_PORT - VGA_END_BREAK_PORT + 1;
  1639. status = VideoPortMapMemory(hwDeviceExtension,
  1640. VgaAccessRange[4].RangeStart,
  1641. &physicalPortLength,
  1642. &(portAccess->MappedInIoSpace),
  1643. &(portAccess->VirtualAddress));
  1644. (PUCHAR)portAccess->VirtualAddress -= VGA_END_BREAK_PORT;
  1645. VideoDebugPrint((1, "VgaStartIO - memory mapping to (%x)\n", portAccess->VirtualAddress));
  1646. if (status == NO_ERROR)
  1647. {
  1648. RequestPacket->StatusBlock->Information =
  1649. sizeof(VIDEO_PUBLIC_ACCESS_RANGES) * 2;
  1650. portAccess++;
  1651. //
  1652. // map a region for memory mapped IO
  1653. //
  1654. portAccess->VirtualAddress = (PVOID) NULL; // Requested VA
  1655. portAccess->InIoSpace = FALSE;
  1656. portAccess->MappedInIoSpace = portAccess->InIoSpace;
  1657. // MMIO register
  1658. physicalPortAddress = VgaAccessRange[4].RangeStart;
  1659. physicalPortAddress.QuadPart += RELOCATABLE_MEMORY_MAPPED_IO_OFFSET;
  1660. physicalPortLength = 0x100;
  1661. status = VideoPortMapMemory(hwDeviceExtension,
  1662. physicalPortAddress,
  1663. &physicalPortLength,
  1664. &(portAccess->MappedInIoSpace),
  1665. &(portAccess->VirtualAddress));
  1666. VideoDebugPrint((1, "The base MMIO address is: %x\n",
  1667. portAccess->VirtualAddress));
  1668. }
  1669. }
  1670. else
  1671. {
  1672. portAccess->VirtualAddress = (PVOID) NULL;
  1673. portAccess->InIoSpace = TRUE;
  1674. portAccess->MappedInIoSpace = portAccess->InIoSpace;
  1675. physicalPortLength = VGA_MAX_IO_PORT - VGA_BASE_IO_PORT + 1;
  1676. status = VideoPortMapMemory(hwDeviceExtension,
  1677. VgaAccessRange->RangeStart,
  1678. &physicalPortLength,
  1679. &(portAccess->MappedInIoSpace),
  1680. &(portAccess->VirtualAddress));
  1681. (PUCHAR)portAccess->VirtualAddress -= VGA_BASE_IO_PORT;
  1682. VideoDebugPrint((1, "VgaStartIO - mapping ports to (%x)\n", portAccess->VirtualAddress));
  1683. if ((status == NO_ERROR) &&
  1684. (RequestPacket->OutputBufferLength >= // if we have room for
  1685. sizeof(VIDEO_PUBLIC_ACCESS_RANGES) * 2)) // another access range
  1686. {
  1687. RequestPacket->StatusBlock->Information =
  1688. sizeof(VIDEO_PUBLIC_ACCESS_RANGES) * 2;
  1689. portAccess++;
  1690. //
  1691. // If we are running on a chip which supports Memory Mapped
  1692. // IO, then return a pointer to the MMIO Ports. Otherwise,
  1693. // return zero to indicate we do not support memory mapped IO.
  1694. //
  1695. if (((hwDeviceExtension->ChipType == CL543x) ||
  1696. (hwDeviceExtension->ChipType & CL755x)) && //myf15
  1697. (hwDeviceExtension->BusType != Isa) &&
  1698. (VideoPortGetDeviceData(hwDeviceExtension,
  1699. VpMachineData,
  1700. &CirrusGetDeviceDataCallback,
  1701. NULL) != NO_ERROR))
  1702. {
  1703. //
  1704. // map a region for memory mapped IO
  1705. //
  1706. // memory mapped IO is located in physical addresses B8000
  1707. // to BFFFF, but we will only touch the first 256 bytes.
  1708. //
  1709. portAccess->VirtualAddress = (PVOID) NULL; // Requested VA
  1710. portAccess->InIoSpace = FALSE;
  1711. portAccess->MappedInIoSpace = portAccess->InIoSpace;
  1712. physicalPortAddress = VgaAccessRange[2].RangeStart;
  1713. physicalPortAddress.QuadPart += MEMORY_MAPPED_IO_OFFSET;
  1714. physicalPortLength = 0x100;
  1715. status = VideoPortMapMemory(hwDeviceExtension,
  1716. physicalPortAddress,
  1717. &physicalPortLength,
  1718. &(portAccess->MappedInIoSpace),
  1719. &(portAccess->VirtualAddress));
  1720. VideoDebugPrint((1, "The base MMIO address is: %x\n",
  1721. portAccess->VirtualAddress));
  1722. }
  1723. else
  1724. {
  1725. portAccess->VirtualAddress = 0;
  1726. }
  1727. }
  1728. }
  1729. }
  1730. break;
  1731. case IOCTL_VIDEO_FREE_PUBLIC_ACCESS_RANGES:
  1732. if (RequestPacket->InputBufferLength < sizeof(VIDEO_MEMORY))
  1733. {
  1734. status = ERROR_INSUFFICIENT_BUFFER;
  1735. break;
  1736. }
  1737. //
  1738. // We decrement VGA_BASE_IO_PORT before we hand this out,
  1739. // so we should increment before we try to free it.
  1740. //
  1741. (PUCHAR)((PVIDEO_MEMORY)RequestPacket->InputBuffer)->
  1742. RequestedVirtualAddress += VGA_BASE_IO_PORT;
  1743. status = VideoPortUnmapMemory(hwDeviceExtension,
  1744. ((PVIDEO_MEMORY)
  1745. (RequestPacket->InputBuffer))->
  1746. RequestedVirtualAddress,
  1747. 0);
  1748. break;
  1749. case IOCTL_CIRRUS_GET_GAMMA_FACTOR:
  1750. VideoDebugPrint((2, "VgaStartIO - GetGammaFactor\n"));
  1751. RequestPacket->StatusBlock->Information = 0;
  1752. status = VgaGetGammaFactor(hwDeviceExtension,
  1753. (PGAMMA_VALUE) RequestPacket->OutputBuffer,
  1754. RequestPacket->OutputBufferLength,
  1755. (PULONG)&RequestPacket->StatusBlock->Information);
  1756. break ;
  1757. case IOCTL_CIRRUS_GET_CONTRAST_FACTOR:
  1758. VideoDebugPrint((2, "VgaStartIO - GetContrastFactor\n"));
  1759. RequestPacket->StatusBlock->Information = 0;
  1760. status = VgaGetContrastFactor(hwDeviceExtension,
  1761. (PCONTRAST_VALUE) RequestPacket->OutputBuffer,
  1762. RequestPacket->OutputBufferLength,
  1763. (PULONG)&RequestPacket->StatusBlock->Information);
  1764. break ;
  1765. case IOCTL_CIRRUS_GET_CAPABILITIES:
  1766. VideoDebugPrint((2, "VgaStartIO - CirrusGetCapabilities\n"));
  1767. RequestPacket->StatusBlock->Information = 0;
  1768. status = VgaQueryAvailableModes(HwDeviceExtension,
  1769. (PVIDEO_MODE_INFORMATION)
  1770. RequestPacket->OutputBuffer,
  1771. RequestPacket->OutputBufferLength,
  1772. (PULONG)&RequestPacket->StatusBlock->Information);
  1773. break;
  1774. case IOCTL_CIRRUS_SET_DISPLAY_PITCH:
  1775. VideoDebugPrint((2, "VgaStartIO - CirrusSetDisplayPitch\n"));
  1776. status = VgaSetMode(HwDeviceExtension,
  1777. (PVIDEO_MODE) RequestPacket->InputBuffer,
  1778. RequestPacket->InputBufferLength);
  1779. break;
  1780. //
  1781. // if we get here, an invalid IoControlCode was specified.
  1782. //
  1783. default:
  1784. VideoDebugPrint((1, "Fell through vga startIO routine - invalid command\n"));
  1785. status = ERROR_INVALID_FUNCTION;
  1786. break;
  1787. }
  1788. RequestPacket->StatusBlock->Status = status;
  1789. return TRUE;
  1790. }
  1791. //---------------------------------------------------------------------------
  1792. VOID
  1793. CirrusHwTimer(
  1794. PVOID pHwDeviceExtension
  1795. )
  1796. /*++
  1797. Routine Description:
  1798. This routine is the main execution routine for the miniport driver. It
  1799. accepts a Video Request Packet, performs the request, and then returns
  1800. with the appropriate status.
  1801. Arguments:
  1802. HwDeviceExtension - Pointer to the miniport driver's HwVidTimer
  1803. information.
  1804. Return Value:
  1805. This routine will return error codes from the various support routines
  1806. and will also return ERROR_INSUFFICIENT_BUFFER for incorrectly sized
  1807. buffers and ERROR_INVALID_FUNCTION for unsupported functions.
  1808. --*/
  1809. {
  1810. PHW_DEVICE_EXTENSION hwDeviceExtension = pHwDeviceExtension;
  1811. PHW_DEVICE_EXTENSION HwDeviceExtension = pHwDeviceExtension;
  1812. VIDEO_MODE videoMode;
  1813. UCHAR SR0A, SR14, savSEQidx, savCRTidx, lcd;
  1814. SHORT Displaytype;
  1815. ULONG ulCRTCAddress, ulCRTCData;
  1816. if (VideoPortReadPortUchar(hwDeviceExtension->IOAddress +
  1817. MISC_OUTPUT_REG_READ_PORT) & 0x01)
  1818. {
  1819. ulCRTCAddress = CRTC_ADDRESS_PORT_COLOR;
  1820. ulCRTCData = CRTC_DATA_PORT_COLOR;
  1821. }
  1822. else
  1823. {
  1824. ulCRTCAddress = CRTC_ADDRESS_PORT_MONO;
  1825. ulCRTCData = CRTC_DATA_PORT_MONO;
  1826. }
  1827. if (!(hwDeviceExtension->bBlockSwitch)) //not block switch
  1828. {
  1829. savSEQidx = VideoPortReadPortUchar(hwDeviceExtension->IOAddress +
  1830. SEQ_ADDRESS_PORT);
  1831. VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
  1832. SEQ_ADDRESS_PORT, 0x14);
  1833. SR14 = VideoPortReadPortUchar(hwDeviceExtension->IOAddress +
  1834. SEQ_DATA_PORT);
  1835. VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
  1836. SEQ_DATA_PORT, (UCHAR)(SR14 | 0x04));
  1837. VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
  1838. SEQ_ADDRESS_PORT, 0x0A);
  1839. SR0A = VideoPortReadPortUchar(hwDeviceExtension->IOAddress +
  1840. SEQ_DATA_PORT);
  1841. Displaytype = ((SR14 & 0x02) | (SR0A & 0x01));
  1842. if (Displaytype == 0)
  1843. Displaytype = LCD_type;
  1844. else if (Displaytype == 1)
  1845. Displaytype = CRT_type;
  1846. else if (Displaytype == 3)
  1847. Displaytype = SIM_type;
  1848. VideoDebugPrint((1, "CirrusHwTimer :\n"
  1849. "\tPreDisplaytype: %d, Currenttype :%d\n",
  1850. hwDeviceExtension->bDisplaytype,
  1851. Displaytype));
  1852. VideoDebugPrint((1, "CirrusHwTimer :\n"
  1853. "\tCurrentMode: %x\n",
  1854. hwDeviceExtension->bCurrentMode));
  1855. if (hwDeviceExtension->bDisplaytype != Displaytype)
  1856. {
  1857. hwDeviceExtension->bDisplaytype = Displaytype;
  1858. savCRTidx = VideoPortReadPortUchar(hwDeviceExtension->IOAddress +
  1859. ulCRTCAddress);
  1860. if (hwDeviceExtension->ChipType & CL754x)
  1861. {
  1862. VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
  1863. ulCRTCAddress, 0x20);
  1864. lcd = VideoPortReadPortUchar(hwDeviceExtension->IOAddress +
  1865. ulCRTCData);
  1866. if (Displaytype == LCD_type)
  1867. {
  1868. VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
  1869. ulCRTCData, (UCHAR)((lcd & 0x9F) | 0x20));
  1870. }
  1871. else if (Displaytype == CRT_type)
  1872. {
  1873. VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
  1874. ulCRTCData, (UCHAR)((lcd & 0x9F)| 0x40));
  1875. }
  1876. else if (Displaytype == SIM_type)
  1877. {
  1878. VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
  1879. ulCRTCData, (UCHAR)((lcd & 0x9F)| 0x60));
  1880. }
  1881. }
  1882. else if (hwDeviceExtension->ChipType & CL755x)
  1883. {
  1884. VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
  1885. ulCRTCAddress, 0x80);
  1886. lcd = VideoPortReadPortUchar(hwDeviceExtension->IOAddress +
  1887. ulCRTCData);
  1888. if (Displaytype == LCD_type)
  1889. {
  1890. VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
  1891. ulCRTCData, (UCHAR)((lcd & 0xFC) | 0x01));
  1892. }
  1893. else if (Displaytype == CRT_type)
  1894. {
  1895. VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
  1896. ulCRTCData, (UCHAR)((lcd & 0xFC)| 0x02));
  1897. }
  1898. else if (Displaytype == SIM_type)
  1899. {
  1900. VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
  1901. ulCRTCData, (UCHAR)((lcd & 0xFC)| 0x03));
  1902. }
  1903. }
  1904. VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
  1905. ulCRTCAddress, savCRTidx);
  1906. }
  1907. VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
  1908. SEQ_ADDRESS_PORT, 0x14);
  1909. VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
  1910. SEQ_DATA_PORT, (UCHAR)(SR14 & 0xFB));
  1911. VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
  1912. SEQ_ADDRESS_PORT, savSEQidx);
  1913. }
  1914. }
  1915. //---------------------------------------------------------------------------
  1916. //
  1917. // private routines
  1918. //
  1919. VP_STATUS
  1920. VgaLoadAndSetFont(
  1921. PHW_DEVICE_EXTENSION HwDeviceExtension,
  1922. PVIDEO_LOAD_FONT_INFORMATION FontInformation,
  1923. ULONG FontInformationSize
  1924. )
  1925. /*++
  1926. Routine Description:
  1927. Takes a buffer containing a user-defined font and loads it into the
  1928. VGA soft font memory and programs the VGA to the appropriate character
  1929. cell size.
  1930. Arguments:
  1931. HwDeviceExtension - Pointer to the miniport driver's device extension.
  1932. FontInformation - Pointer to the structure containing the information
  1933. about the loadable ROM font to be set.
  1934. FontInformationSize - Length of the input buffer supplied by the user.
  1935. Return Value:
  1936. NO_ERROR - information returned successfully
  1937. ERROR_INSUFFICIENT_BUFFER - input buffer not large enough for input data.
  1938. ERROR_INVALID_PARAMETER - invalid video mode
  1939. --*/
  1940. {
  1941. PUCHAR destination;
  1942. PUCHAR source;
  1943. USHORT width;
  1944. ULONG i;
  1945. ULONG ulCRTCAddress, ulCRTCData;
  1946. //
  1947. // check if a mode has been set
  1948. //
  1949. if (HwDeviceExtension->CurrentMode == NULL) {
  1950. return ERROR_INVALID_FUNCTION;
  1951. }
  1952. //
  1953. // Text mode only; If we are in a graphics mode, return an error
  1954. //
  1955. if (HwDeviceExtension->CurrentMode->fbType & VIDEO_MODE_GRAPHICS) {
  1956. return ERROR_INVALID_PARAMETER;
  1957. }
  1958. //
  1959. // Check if the size of the data in the input buffer is large enough
  1960. // and that it contains all the data.
  1961. //
  1962. if ( (FontInformationSize < sizeof(VIDEO_LOAD_FONT_INFORMATION)) ||
  1963. (FontInformationSize < sizeof(VIDEO_LOAD_FONT_INFORMATION) +
  1964. sizeof(UCHAR) * (FontInformation->FontSize - 1)) )
  1965. {
  1966. return ERROR_INSUFFICIENT_BUFFER;
  1967. }
  1968. //
  1969. // Check for the width and height of the font
  1970. //
  1971. if ( ((FontInformation->WidthInPixels != 8) &&
  1972. (FontInformation->WidthInPixels != 9)) ||
  1973. (FontInformation->HeightInPixels > 32) ) {
  1974. return ERROR_INVALID_PARAMETER;
  1975. }
  1976. //
  1977. // Check the size of the font buffer is the right size for the size
  1978. // font being passed down.
  1979. //
  1980. if (FontInformation->FontSize < FontInformation->HeightInPixels * 256 *
  1981. sizeof(UCHAR) ) {
  1982. return ERROR_INSUFFICIENT_BUFFER;
  1983. }
  1984. //
  1985. // Since the font parameters are valid, store the parameters in the
  1986. // device extension and load the font.
  1987. //
  1988. HwDeviceExtension->FontPelRows = FontInformation->HeightInPixels;
  1989. HwDeviceExtension->FontPelColumns = FontInformation->WidthInPixels;
  1990. HwDeviceExtension->CurrentMode->row =
  1991. HwDeviceExtension->CurrentMode->vres / HwDeviceExtension->FontPelRows;
  1992. width =
  1993. HwDeviceExtension->CurrentMode->hres / HwDeviceExtension->FontPelColumns;
  1994. if (width < (USHORT)HwDeviceExtension->CurrentMode->col) {
  1995. HwDeviceExtension->CurrentMode->col = width;
  1996. }
  1997. source = &(FontInformation->Font[0]);
  1998. //
  1999. // Set up the destination and source pointers for the font
  2000. //
  2001. destination = (PUCHAR)HwDeviceExtension->VideoMemoryAddress;
  2002. //
  2003. // Map font buffer at A0000
  2004. //
  2005. VgaInterpretCmdStream(HwDeviceExtension, EnableA000Data);
  2006. //
  2007. // Move the font to its destination
  2008. //
  2009. for (i = 1; i <= 256; i++) {
  2010. VideoPortWriteRegisterBufferUchar(destination,
  2011. source,
  2012. FontInformation->HeightInPixels);
  2013. destination += 32;
  2014. source += FontInformation->HeightInPixels;
  2015. }
  2016. VgaInterpretCmdStream(HwDeviceExtension, DisableA000Color);
  2017. //
  2018. // Restore to a text mode.
  2019. //
  2020. if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  2021. MISC_OUTPUT_REG_READ_PORT) & 0x01)
  2022. {
  2023. ulCRTCAddress = CRTC_ADDRESS_PORT_COLOR;
  2024. ulCRTCData = CRTC_DATA_PORT_COLOR;
  2025. }
  2026. else
  2027. {
  2028. ulCRTCAddress = CRTC_ADDRESS_PORT_MONO;
  2029. ulCRTCData = CRTC_DATA_PORT_MONO;
  2030. }
  2031. //
  2032. // Set Height of font.
  2033. //
  2034. VideoPortWritePortUchar(HwDeviceExtension->IOAddress + ulCRTCAddress, 0x09);
  2035. VideoPortWritePortUchar(HwDeviceExtension->IOAddress + ulCRTCData,
  2036. (UCHAR)(FontInformation->HeightInPixels - 1));
  2037. //
  2038. // Set Width of font.
  2039. //
  2040. VideoPortWritePortUchar(HwDeviceExtension->IOAddress + ulCRTCAddress, 0x12);
  2041. VideoPortWritePortUchar(HwDeviceExtension->IOAddress + ulCRTCData,
  2042. (UCHAR)(((USHORT)FontInformation->HeightInPixels *
  2043. (USHORT)HwDeviceExtension->CurrentMode->row) - 1));
  2044. i = HwDeviceExtension->CurrentMode->vres /
  2045. HwDeviceExtension->CurrentMode->row;
  2046. //
  2047. // Set Cursor End
  2048. //
  2049. VideoPortWritePortUchar(HwDeviceExtension->IOAddress + ulCRTCAddress, 0x0B);
  2050. VideoPortWritePortUchar(HwDeviceExtension->IOAddress + ulCRTCData,
  2051. (UCHAR)--i);
  2052. //
  2053. // Set Cursor Start
  2054. //
  2055. VideoPortWritePortUchar(HwDeviceExtension->IOAddress + ulCRTCAddress, 0x0A);
  2056. VideoPortWritePortUchar(HwDeviceExtension->IOAddress + ulCRTCData,
  2057. (UCHAR)--i);
  2058. return NO_ERROR;
  2059. } //end VgaLoadAndSetFont()
  2060. //---------------------------------------------------------------------------
  2061. VP_STATUS
  2062. VgaQueryCursorPosition(
  2063. PHW_DEVICE_EXTENSION HwDeviceExtension,
  2064. PVIDEO_CURSOR_POSITION CursorPosition,
  2065. ULONG CursorPositionSize,
  2066. PULONG OutputSize
  2067. )
  2068. /*++
  2069. Routine Description:
  2070. This routine returns the row and column of the cursor.
  2071. Arguments:
  2072. HwDeviceExtension - Pointer to the miniport driver's device extension.
  2073. CursorPosition - Pointer to the output buffer supplied by the user. This
  2074. is where the cursor position is stored.
  2075. CursorPositionSize - Length of the output buffer supplied by the user.
  2076. OutputSize - Pointer to a buffer in which to return the actual size of
  2077. the data in the buffer. If the buffer was not large enough, this
  2078. contains the minimum required buffer size.
  2079. Return Value:
  2080. NO_ERROR - information returned successfully
  2081. ERROR_INSUFFICIENT_BUFFER - output buffer not large enough to return
  2082. any useful data
  2083. ERROR_INVALID_PARAMETER - invalid video mode
  2084. --*/
  2085. {
  2086. //
  2087. // check if a mode has been set
  2088. //
  2089. if (HwDeviceExtension->CurrentMode == NULL) {
  2090. return ERROR_INVALID_FUNCTION;
  2091. }
  2092. //
  2093. // Text mode only; If we are in a graphics mode, return an error
  2094. //
  2095. if (HwDeviceExtension->CurrentMode->fbType & VIDEO_MODE_GRAPHICS) {
  2096. *OutputSize = 0;
  2097. return ERROR_INVALID_PARAMETER;
  2098. }
  2099. //
  2100. // If the buffer passed in is not large enough return an
  2101. // appropriate error code.
  2102. //
  2103. if (CursorPositionSize < (*OutputSize = sizeof(VIDEO_CURSOR_POSITION)) ) {
  2104. *OutputSize = 0;
  2105. return ERROR_INSUFFICIENT_BUFFER;
  2106. }
  2107. //
  2108. // Store the postition of the cursor into the buffer.
  2109. //
  2110. CursorPosition->Column = HwDeviceExtension->CursorPosition.Column;
  2111. CursorPosition->Row = HwDeviceExtension->CursorPosition.Row;
  2112. return NO_ERROR;
  2113. } // end VgaQueryCursorPosition()
  2114. //---------------------------------------------------------------------------
  2115. VP_STATUS
  2116. VgaSetCursorPosition(
  2117. PHW_DEVICE_EXTENSION HwDeviceExtension,
  2118. PVIDEO_CURSOR_POSITION CursorPosition,
  2119. ULONG CursorPositionSize
  2120. )
  2121. /*++
  2122. Routine Description:
  2123. This routine verifies that the requested cursor position is within
  2124. the row and column bounds of the current mode and font. If valid, then
  2125. it sets the row and column of the cursor.
  2126. Arguments:
  2127. HwDeviceExtension - Pointer to the miniport driver's device extension.
  2128. CursorPosition - Pointer to the structure containing the cursor position.
  2129. CursorPositionSize - Length of the input buffer supplied by the user.
  2130. Return Value:
  2131. NO_ERROR - information returned successfully
  2132. ERROR_INSUFFICIENT_BUFFER - input buffer not large enough for input data
  2133. ERROR_INVALID_PARAMETER - invalid video mode
  2134. --*/
  2135. {
  2136. USHORT position;
  2137. ULONG ulCRTCAddress, ulCRTCData;
  2138. //
  2139. // check if a mode has been set
  2140. //
  2141. if (HwDeviceExtension->CurrentMode == NULL) {
  2142. return ERROR_INVALID_FUNCTION;
  2143. }
  2144. //
  2145. // Text mode only; If we are in a graphics mode, return an error
  2146. //
  2147. if (HwDeviceExtension->CurrentMode->fbType & VIDEO_MODE_GRAPHICS) {
  2148. return ERROR_INVALID_PARAMETER;
  2149. }
  2150. //
  2151. // Check if the size of the data in the input buffer is large enough.
  2152. //
  2153. if (CursorPositionSize < sizeof(VIDEO_CURSOR_POSITION)) {
  2154. return ERROR_INSUFFICIENT_BUFFER;
  2155. }
  2156. //
  2157. // Check if the new values for the cursor positions are in the valid
  2158. // bounds for the screen.
  2159. //
  2160. if ((CursorPosition->Column >= HwDeviceExtension->CurrentMode->col) ||
  2161. (CursorPosition->Row >= HwDeviceExtension->CurrentMode->row)) {
  2162. return ERROR_INVALID_PARAMETER;
  2163. }
  2164. //
  2165. // Store these new values in the device extension so we can use them in
  2166. // a QUERY.
  2167. //
  2168. HwDeviceExtension->CursorPosition.Column = CursorPosition->Column;
  2169. HwDeviceExtension->CursorPosition.Row = CursorPosition->Row;
  2170. //
  2171. // Calculate the position on the screen at which the cursor must be
  2172. // be displayed
  2173. //
  2174. position = (USHORT) (HwDeviceExtension->CurrentMode->col *
  2175. CursorPosition->Row + CursorPosition->Column);
  2176. if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  2177. MISC_OUTPUT_REG_READ_PORT) & 0x01)
  2178. {
  2179. ulCRTCAddress = CRTC_ADDRESS_PORT_COLOR;
  2180. ulCRTCData = CRTC_DATA_PORT_COLOR;
  2181. }
  2182. else
  2183. {
  2184. ulCRTCAddress = CRTC_ADDRESS_PORT_MONO;
  2185. ulCRTCData = CRTC_DATA_PORT_MONO;
  2186. }
  2187. //
  2188. // Address Cursor Location Low Register in CRT Controller Registers
  2189. //
  2190. VideoPortWritePortUchar(HwDeviceExtension->IOAddress + ulCRTCAddress,
  2191. IND_CURSOR_LOW_LOC);
  2192. //
  2193. // Set Cursor Location Low Register
  2194. //
  2195. VideoPortWritePortUchar(HwDeviceExtension->IOAddress + ulCRTCData,
  2196. (UCHAR) (position & 0x00FF));
  2197. //
  2198. // Address Cursor Location High Register in CRT Controller Registers
  2199. //
  2200. VideoPortWritePortUchar(HwDeviceExtension->IOAddress + ulCRTCAddress,
  2201. IND_CURSOR_HIGH_LOC);
  2202. //
  2203. // Set Cursor Location High Register
  2204. //
  2205. VideoPortWritePortUchar(HwDeviceExtension->IOAddress + ulCRTCData,
  2206. (UCHAR) (position >> 8));
  2207. return NO_ERROR;
  2208. } // end VgaSetCursorPosition()
  2209. //---------------------------------------------------------------------------
  2210. VP_STATUS
  2211. VgaQueryCursorAttributes(
  2212. PHW_DEVICE_EXTENSION HwDeviceExtension,
  2213. PVIDEO_CURSOR_ATTRIBUTES CursorAttributes,
  2214. ULONG CursorAttributesSize,
  2215. PULONG OutputSize
  2216. )
  2217. /*++
  2218. Routine Description:
  2219. This routine returns information about the height and visibility of the
  2220. cursor.
  2221. Arguments:
  2222. HwDeviceExtension - Pointer to the miniport driver's device extension.
  2223. CursorAttributes - Pointer to the output buffer supplied by the user.
  2224. This is where the cursor type is stored.
  2225. CursorAttributesSize - Length of the output buffer supplied by the user.
  2226. OutputSize - Pointer to a buffer in which to return the actual size of
  2227. the data in the buffer. If the buffer was not large enough, this
  2228. contains the minimum required buffer size.
  2229. Return Value:
  2230. NO_ERROR - information returned successfully
  2231. ERROR_INSUFFICIENT_BUFFER - output buffer not large enough to return
  2232. any useful data
  2233. ERROR_INVALID_PARAMETER - invalid video mode
  2234. --*/
  2235. {
  2236. //
  2237. // check if a mode has been set
  2238. //
  2239. if (HwDeviceExtension->CurrentMode == NULL) {
  2240. return ERROR_INVALID_FUNCTION;
  2241. }
  2242. //
  2243. // Text mode only; If we are in a graphics mode, return an error
  2244. //
  2245. if (HwDeviceExtension->CurrentMode->fbType & VIDEO_MODE_GRAPHICS) {
  2246. *OutputSize = 0;
  2247. return ERROR_INVALID_PARAMETER;
  2248. }
  2249. //
  2250. // Find out the size of the data to be put in the the buffer and return
  2251. // that in the status information (whether or not the information is
  2252. // there). If the buffer passed in is not large enough return an
  2253. // appropriate error code.
  2254. //
  2255. if (CursorAttributesSize < (*OutputSize =
  2256. sizeof(VIDEO_CURSOR_ATTRIBUTES)) ) {
  2257. *OutputSize = 0;
  2258. return ERROR_INSUFFICIENT_BUFFER;
  2259. }
  2260. //
  2261. // Store the cursor information into the buffer.
  2262. //
  2263. CursorAttributes->Height = (USHORT) HwDeviceExtension->CursorTopScanLine;
  2264. CursorAttributes->Width = (USHORT) HwDeviceExtension->CursorBottomScanLine;
  2265. if (HwDeviceExtension->cursor_vert_exp_flag)
  2266. CursorAttributes->Enable = FALSE;
  2267. else
  2268. CursorAttributes->Enable = TRUE;
  2269. CursorAttributes->Enable = HwDeviceExtension->CursorEnable;
  2270. return NO_ERROR;
  2271. } // end VgaQueryCursorAttributes()
  2272. //---------------------------------------------------------------------------
  2273. VP_STATUS
  2274. VgaSetCursorAttributes(
  2275. PHW_DEVICE_EXTENSION HwDeviceExtension,
  2276. PVIDEO_CURSOR_ATTRIBUTES CursorAttributes,
  2277. ULONG CursorAttributesSize
  2278. )
  2279. /*++
  2280. Routine Description:
  2281. This routine verifies that the requested cursor height is within the
  2282. bounds of the character cell. If valid, then it sets the new
  2283. visibility and height of the cursor.
  2284. Arguments:
  2285. HwDeviceExtension - Pointer to the miniport driver's device extension.
  2286. CursorType - Pointer to the structure containing the cursor information.
  2287. CursorTypeSize - Length of the input buffer supplied by the user.
  2288. Return Value:
  2289. NO_ERROR - information returned successfully
  2290. ERROR_INSUFFICIENT_BUFFER - input buffer not large enough for input data
  2291. ERROR_INVALID_PARAMETER - invalid video mode
  2292. --*/
  2293. {
  2294. UCHAR cursorLine;
  2295. ULONG ulCRTCAddress, ulCRTCData;
  2296. //
  2297. // check if a mode has been set
  2298. //
  2299. if (HwDeviceExtension->CurrentMode == NULL) {
  2300. return ERROR_INVALID_FUNCTION;
  2301. }
  2302. //
  2303. // Text mode only; If we are in a graphics mode, return an error
  2304. //
  2305. if (HwDeviceExtension->CurrentMode->fbType & VIDEO_MODE_GRAPHICS) {
  2306. return ERROR_INVALID_PARAMETER;
  2307. }
  2308. //
  2309. // Check if the size of the data in the input buffer is large enough.
  2310. //
  2311. if (CursorAttributesSize < sizeof(VIDEO_CURSOR_ATTRIBUTES)) {
  2312. return ERROR_INSUFFICIENT_BUFFER;
  2313. }
  2314. //
  2315. // Check if the new values for the cursor type are in the valid range.
  2316. //
  2317. if ((CursorAttributes->Height >= HwDeviceExtension->FontPelRows) ||
  2318. (CursorAttributes->Width > 31)) {
  2319. return ERROR_INVALID_PARAMETER;
  2320. }
  2321. //
  2322. // Store the cursor information in the device extension so we can use
  2323. // them in a QUERY.
  2324. //
  2325. HwDeviceExtension->CursorTopScanLine = (UCHAR) CursorAttributes->Height;
  2326. HwDeviceExtension->CursorBottomScanLine = (UCHAR) CursorAttributes->Width;
  2327. HwDeviceExtension->CursorEnable = CursorAttributes->Enable;
  2328. if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  2329. MISC_OUTPUT_REG_READ_PORT) & 0x01)
  2330. {
  2331. ulCRTCAddress = CRTC_ADDRESS_PORT_COLOR;
  2332. ulCRTCData = CRTC_DATA_PORT_COLOR;
  2333. }
  2334. else
  2335. {
  2336. ulCRTCAddress = CRTC_ADDRESS_PORT_MONO;
  2337. ulCRTCData = CRTC_DATA_PORT_MONO;
  2338. }
  2339. //
  2340. // Address Cursor Start Register in CRT Controller Registers
  2341. //
  2342. VideoPortWritePortUchar(HwDeviceExtension->IOAddress + ulCRTCAddress,
  2343. IND_CURSOR_START);
  2344. //
  2345. // Set Cursor Start Register by writting to CRTCtl Data Register
  2346. // Preserve the high three bits of this register.
  2347. //
  2348. // Only the Five low bits are used for the cursor height.
  2349. // Bit 5 is cursor enable, bit 6 and 7 preserved.
  2350. //
  2351. cursorLine = (UCHAR) CursorAttributes->Height & 0x1F;
  2352. cursorLine |= VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  2353. ulCRTCData) & 0xC0;
  2354. if (!CursorAttributes->Enable) {
  2355. cursorLine |= 0x20; // Flip cursor off bit
  2356. }
  2357. VideoPortWritePortUchar(HwDeviceExtension->IOAddress + ulCRTCData,
  2358. cursorLine);
  2359. //
  2360. // Address Cursor End Register in CRT Controller Registers
  2361. //
  2362. VideoPortWritePortUchar(HwDeviceExtension->IOAddress + ulCRTCAddress,
  2363. IND_CURSOR_END);
  2364. //
  2365. // Set Cursor End Register. Preserve the high three bits of this
  2366. // register.
  2367. //
  2368. cursorLine =
  2369. (CursorAttributes->Width < (USHORT)(HwDeviceExtension->FontPelRows - 1)) ?
  2370. CursorAttributes->Width : (HwDeviceExtension->FontPelRows - 1);
  2371. cursorLine &= 0x1f;
  2372. cursorLine |= VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  2373. ulCRTCData) & 0xE0;
  2374. VideoPortWritePortUchar(HwDeviceExtension->IOAddress + ulCRTCData,
  2375. cursorLine);
  2376. return NO_ERROR;
  2377. } // end VgaSetCursorAttributes()
  2378. //---------------------------------------------------------------------------
  2379. BOOLEAN
  2380. VgaIsPresent(
  2381. PHW_DEVICE_EXTENSION HwDeviceExtension
  2382. )
  2383. /*++
  2384. Routine Description:
  2385. This routine returns TRUE if a VGA is present. Determining whether a VGA
  2386. is present is a two-step process. First, this routine walks bits through
  2387. the Bit Mask register, to establish that there are readable indexed
  2388. registers (EGAs normally don't have readable registers, and other adapters
  2389. are unlikely to have indexed registers). This test is done first because
  2390. it's a non-destructive EGA rejection test (correctly rejects EGAs, but
  2391. doesn't potentially mess up the screen or the accessibility of display
  2392. memory). Normally, this would be an adequate test, but some EGAs have
  2393. readable registers, so next, we check for the existence of the Chain4 bit
  2394. in the Memory Mode register; this bit doesn't exist in EGAs. It's
  2395. conceivable that there are EGAs with readable registers and a register bit
  2396. where Chain4 is stored, although I don't know of any; if a better test yet
  2397. is needed, memory could be written to in Chain4 mode, and then examined
  2398. plane by plane in non-Chain4 mode to make sure the Chain4 bit did what it's
  2399. supposed to do. However, the current test should be adequate to eliminate
  2400. just about all EGAs, and 100% of everything else.
  2401. If this function fails to find a VGA, it attempts to undo any damage it
  2402. may have inadvertently done while testing. The underlying assumption for
  2403. the damage control is that if there's any non-VGA adapter at the tested
  2404. ports, it's an EGA or an enhanced EGA, because: a) I don't know of any
  2405. other adapters that use 3C4/5 or 3CE/F, and b), if there are other
  2406. adapters, I certainly don't know how to restore their original states. So
  2407. all error recovery is oriented toward putting an EGA back in a writable
  2408. state, so that error messages are visible. The EGA's state on entry is
  2409. assumed to be text mode, so the Memory Mode register is restored to the
  2410. default state for text mode.
  2411. If a VGA is found, the VGA is returned to its original state after
  2412. testing is finished.
  2413. Arguments:
  2414. None.
  2415. Return Value:
  2416. TRUE if a VGA is present, FALSE if not.
  2417. --*/
  2418. {
  2419. UCHAR originalGCAddr;
  2420. UCHAR originalSCAddr;
  2421. UCHAR originalBitMask;
  2422. UCHAR originalReadMap;
  2423. UCHAR originalMemoryMode;
  2424. UCHAR testMask;
  2425. BOOLEAN returnStatus;
  2426. //
  2427. // Remember the original state of the Graphics Controller Address register.
  2428. //
  2429. originalGCAddr = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  2430. GRAPH_ADDRESS_PORT);
  2431. //
  2432. // Write the Read Map register with a known state so we can verify
  2433. // that it isn't changed after we fool with the Bit Mask. This ensures
  2434. // that we're dealing with indexed registers, since both the Read Map and
  2435. // the Bit Mask are addressed at GRAPH_DATA_PORT.
  2436. //
  2437. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2438. GRAPH_ADDRESS_PORT, IND_READ_MAP);
  2439. //
  2440. // If we can't read back the Graphics Address register setting we just
  2441. // performed, it's not readable and this isn't a VGA.
  2442. //
  2443. if ((VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  2444. GRAPH_ADDRESS_PORT) & GRAPH_ADDR_MASK) != IND_READ_MAP) {
  2445. return FALSE;
  2446. }
  2447. //
  2448. // Set the Read Map register to a known state.
  2449. //
  2450. originalReadMap = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  2451. GRAPH_DATA_PORT);
  2452. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2453. GRAPH_DATA_PORT, READ_MAP_TEST_SETTING);
  2454. if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  2455. GRAPH_DATA_PORT) != READ_MAP_TEST_SETTING) {
  2456. //
  2457. // The Read Map setting we just performed can't be read back; not a
  2458. // VGA. Restore the default Read Map state.
  2459. //
  2460. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2461. GRAPH_DATA_PORT, READ_MAP_DEFAULT);
  2462. return FALSE;
  2463. }
  2464. //
  2465. // Remember the original setting of the Bit Mask register.
  2466. //
  2467. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2468. GRAPH_ADDRESS_PORT, IND_BIT_MASK);
  2469. if ((VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  2470. GRAPH_ADDRESS_PORT) & GRAPH_ADDR_MASK) != IND_BIT_MASK) {
  2471. //
  2472. // The Graphics Address register setting we just made can't be read
  2473. // back; not a VGA. Restore the default Read Map state.
  2474. //
  2475. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2476. GRAPH_ADDRESS_PORT, IND_READ_MAP);
  2477. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2478. GRAPH_DATA_PORT, READ_MAP_DEFAULT);
  2479. return FALSE;
  2480. }
  2481. originalBitMask = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  2482. GRAPH_DATA_PORT);
  2483. //
  2484. // Set up the initial test mask we'll write to and read from the Bit Mask.
  2485. //
  2486. testMask = 0xBB;
  2487. do {
  2488. //
  2489. // Write the test mask to the Bit Mask.
  2490. //
  2491. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2492. GRAPH_DATA_PORT, testMask);
  2493. //
  2494. // Make sure the Bit Mask remembered the value.
  2495. //
  2496. if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  2497. GRAPH_DATA_PORT) != testMask) {
  2498. //
  2499. // The Bit Mask is not properly writable and readable; not a VGA.
  2500. // Restore the Bit Mask and Read Map to their default states.
  2501. //
  2502. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2503. GRAPH_DATA_PORT, BIT_MASK_DEFAULT);
  2504. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2505. GRAPH_ADDRESS_PORT, IND_READ_MAP);
  2506. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2507. GRAPH_DATA_PORT, READ_MAP_DEFAULT);
  2508. return FALSE;
  2509. }
  2510. //
  2511. // Cycle the mask for next time.
  2512. //
  2513. testMask >>= 1;
  2514. } while (testMask != 0);
  2515. //
  2516. // There's something readable at GRAPH_DATA_PORT; now switch back and
  2517. // make sure that the Read Map register hasn't changed, to verify that
  2518. // we're dealing with indexed registers.
  2519. //
  2520. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2521. GRAPH_ADDRESS_PORT, IND_READ_MAP);
  2522. if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  2523. GRAPH_DATA_PORT) != READ_MAP_TEST_SETTING) {
  2524. //
  2525. // The Read Map is not properly writable and readable; not a VGA.
  2526. // Restore the Bit Mask and Read Map to their default states, in case
  2527. // this is an EGA, so subsequent writes to the screen aren't garbled.
  2528. //
  2529. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2530. GRAPH_DATA_PORT, READ_MAP_DEFAULT);
  2531. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2532. GRAPH_ADDRESS_PORT, IND_BIT_MASK);
  2533. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2534. GRAPH_DATA_PORT, BIT_MASK_DEFAULT);
  2535. return FALSE;
  2536. }
  2537. //
  2538. // We've pretty surely verified the existence of the Bit Mask register.
  2539. // Put the Graphics Controller back to the original state.
  2540. //
  2541. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2542. GRAPH_DATA_PORT, originalReadMap);
  2543. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2544. GRAPH_ADDRESS_PORT, IND_BIT_MASK);
  2545. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2546. GRAPH_DATA_PORT, originalBitMask);
  2547. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2548. GRAPH_ADDRESS_PORT, originalGCAddr);
  2549. //
  2550. // Now, check for the existence of the Chain4 bit.
  2551. //
  2552. //
  2553. // Remember the original states of the Sequencer Address and Memory Mode
  2554. // registers.
  2555. //
  2556. originalSCAddr = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  2557. SEQ_ADDRESS_PORT);
  2558. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2559. SEQ_ADDRESS_PORT, IND_MEMORY_MODE);
  2560. if ((VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  2561. SEQ_ADDRESS_PORT) & SEQ_ADDR_MASK) != IND_MEMORY_MODE) {
  2562. //
  2563. // Couldn't read back the Sequencer Address register setting we just
  2564. // performed.
  2565. //
  2566. return FALSE;
  2567. }
  2568. originalMemoryMode = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  2569. SEQ_DATA_PORT);
  2570. //
  2571. // Toggle the Chain4 bit and read back the result. This must be done during
  2572. // sync reset, since we're changing the chaining state.
  2573. //
  2574. //
  2575. // Begin sync reset.
  2576. //
  2577. VideoPortWritePortUshort((PUSHORT)(HwDeviceExtension->IOAddress +
  2578. SEQ_ADDRESS_PORT),
  2579. (IND_SYNC_RESET + (START_SYNC_RESET_VALUE << 8)));
  2580. //
  2581. // Toggle the Chain4 bit.
  2582. //
  2583. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2584. SEQ_ADDRESS_PORT, IND_MEMORY_MODE);
  2585. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2586. SEQ_DATA_PORT, (UCHAR)(originalMemoryMode ^ CHAIN4_MASK));
  2587. if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  2588. SEQ_DATA_PORT) != (UCHAR) (originalMemoryMode ^ CHAIN4_MASK)) {
  2589. //
  2590. // Chain4 bit not there; not a VGA.
  2591. // Set text mode default for Memory Mode register.
  2592. //
  2593. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2594. SEQ_DATA_PORT, MEMORY_MODE_TEXT_DEFAULT);
  2595. //
  2596. // End sync reset.
  2597. //
  2598. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  2599. SEQ_ADDRESS_PORT),
  2600. (IND_SYNC_RESET + (END_SYNC_RESET_VALUE << 8)));
  2601. returnStatus = FALSE;
  2602. } else {
  2603. //
  2604. // It's a VGA.
  2605. //
  2606. //
  2607. // Restore the original Memory Mode setting.
  2608. //
  2609. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2610. SEQ_DATA_PORT, originalMemoryMode);
  2611. //
  2612. // End sync reset.
  2613. //
  2614. VideoPortWritePortUshort((PUSHORT)(HwDeviceExtension->IOAddress +
  2615. SEQ_ADDRESS_PORT),
  2616. (USHORT)(IND_SYNC_RESET + (END_SYNC_RESET_VALUE << 8)));
  2617. //
  2618. // Restore the original Sequencer Address setting.
  2619. //
  2620. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2621. SEQ_ADDRESS_PORT, originalSCAddr);
  2622. returnStatus = TRUE;
  2623. }
  2624. return returnStatus;
  2625. } // VgaIsPresent()
  2626. //---------------------------------------------------------------------------
  2627. VP_STATUS
  2628. VgaSetPaletteReg(
  2629. PHW_DEVICE_EXTENSION HwDeviceExtension,
  2630. PVIDEO_PALETTE_DATA PaletteBuffer,
  2631. ULONG PaletteBufferSize
  2632. )
  2633. /*++
  2634. Routine Description:
  2635. This routine sets a specified portion of the EGA (not DAC) palette
  2636. registers.
  2637. Arguments:
  2638. HwDeviceExtension - Pointer to the miniport driver's device extension.
  2639. PaletteBuffer - Pointer to the structure containing the palette data.
  2640. PaletteBufferSize - Length of the input buffer supplied by the user.
  2641. Return Value:
  2642. NO_ERROR - information returned successfully
  2643. ERROR_INSUFFICIENT_BUFFER - input buffer not large enough for input data.
  2644. ERROR_INVALID_PARAMETER - invalid palette size.
  2645. --*/
  2646. {
  2647. USHORT i;
  2648. //
  2649. // Check if the size of the data in the input buffer is large enough.
  2650. //
  2651. if ((PaletteBufferSize) < (sizeof(VIDEO_PALETTE_DATA)) ||
  2652. (PaletteBufferSize < (sizeof(VIDEO_PALETTE_DATA) +
  2653. (sizeof(USHORT) * (PaletteBuffer->NumEntries -1)) ))) {
  2654. return ERROR_INSUFFICIENT_BUFFER;
  2655. }
  2656. //
  2657. // Check to see if the parameters are valid.
  2658. //
  2659. if ( (PaletteBuffer->FirstEntry > VIDEO_MAX_COLOR_REGISTER ) ||
  2660. (PaletteBuffer->NumEntries == 0) ||
  2661. (PaletteBuffer->FirstEntry + PaletteBuffer->NumEntries >
  2662. VIDEO_MAX_PALETTE_REGISTER + 1 ) ) {
  2663. return ERROR_INVALID_PARAMETER;
  2664. }
  2665. //
  2666. // Reset ATC to index mode
  2667. //
  2668. //
  2669. // check to see mono or color first
  2670. //
  2671. if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  2672. MISC_OUTPUT_REG_READ_PORT) & 0x01) {
  2673. VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  2674. ATT_INITIALIZE_PORT_COLOR);
  2675. } else {
  2676. VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  2677. ATT_INITIALIZE_PORT_MONO); //frido 07-Aug-96
  2678. }
  2679. //
  2680. // Blast out our palette values.
  2681. //
  2682. for (i = 0; i < PaletteBuffer->NumEntries; i++) {
  2683. VideoPortWritePortUchar(HwDeviceExtension->IOAddress + ATT_ADDRESS_PORT,
  2684. (UCHAR)(i+PaletteBuffer->FirstEntry));
  2685. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2686. ATT_DATA_WRITE_PORT,
  2687. (UCHAR)PaletteBuffer->Colors[i]);
  2688. }
  2689. VideoPortWritePortUchar(HwDeviceExtension->IOAddress + ATT_ADDRESS_PORT,
  2690. VIDEO_ENABLE);
  2691. return NO_ERROR;
  2692. } // end VgaSetPaletteReg()
  2693. //---------------------------------------------------------------------------
  2694. VP_STATUS
  2695. VgaSetColorLookup(
  2696. PHW_DEVICE_EXTENSION HwDeviceExtension,
  2697. PVIDEO_CLUT ClutBuffer,
  2698. ULONG ClutBufferSize
  2699. )
  2700. /*++
  2701. Routine Description:
  2702. This routine sets a specified portion of the DAC color lookup table
  2703. settings.
  2704. Arguments:
  2705. HwDeviceExtension - Pointer to the miniport driver's device extension.
  2706. ClutBufferSize - Length of the input buffer supplied by the user.
  2707. ClutBuffer - Pointer to the structure containing the color lookup table.
  2708. Return Value:
  2709. NO_ERROR - information returned successfully
  2710. ERROR_INSUFFICIENT_BUFFER - input buffer not large enough for input data.
  2711. ERROR_INVALID_PARAMETER - invalid clut size.
  2712. --*/
  2713. {
  2714. ULONG i;
  2715. //
  2716. // Check if the size of the data in the input buffer is large enough.
  2717. //
  2718. if ( (ClutBufferSize < sizeof(VIDEO_CLUT) - sizeof(ULONG)) ||
  2719. (ClutBufferSize < sizeof(VIDEO_CLUT) +
  2720. (sizeof(ULONG) * (ClutBuffer->NumEntries - 1)) ) ) {
  2721. return ERROR_INSUFFICIENT_BUFFER;
  2722. }
  2723. //
  2724. // Check to see if the parameters are valid.
  2725. //
  2726. if ( (ClutBuffer->NumEntries == 0) ||
  2727. (ClutBuffer->FirstEntry > VIDEO_MAX_COLOR_REGISTER) ||
  2728. (ClutBuffer->FirstEntry + ClutBuffer->NumEntries >
  2729. VIDEO_MAX_COLOR_REGISTER + 1) ) {
  2730. return ERROR_INVALID_PARAMETER;
  2731. }
  2732. //
  2733. // Set CLUT registers directly on the hardware
  2734. //
  2735. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2736. DAC_ADDRESS_WRITE_PORT, (UCHAR) ClutBuffer->FirstEntry);
  2737. for (i = 0; i < ClutBuffer->NumEntries; i++) {
  2738. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2739. DAC_ADDRESS_WRITE_PORT,
  2740. (UCHAR)(i + ClutBuffer->FirstEntry));
  2741. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2742. DAC_DATA_REG_PORT,
  2743. ClutBuffer->LookupTable[i].RgbArray.Red);
  2744. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2745. DAC_DATA_REG_PORT,
  2746. ClutBuffer->LookupTable[i].RgbArray.Green);
  2747. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2748. DAC_DATA_REG_PORT,
  2749. ClutBuffer->LookupTable[i].RgbArray.Blue);
  2750. }
  2751. return NO_ERROR;
  2752. } // end VgaSetColorLookup()
  2753. //---------------------------------------------------------------------------
  2754. VP_STATUS
  2755. VgaRestoreHardwareState(
  2756. PHW_DEVICE_EXTENSION HwDeviceExtension,
  2757. PVIDEO_HARDWARE_STATE HardwareState,
  2758. ULONG HardwareStateSize
  2759. )
  2760. /*++
  2761. Routine Description:
  2762. Restores all registers and memory of the VGA.
  2763. Note: HardwareState points to the actual buffer from which the state
  2764. is to be restored. This buffer will always be big enough (we specified
  2765. the required size at DriverEntry).
  2766. Note: The offset in the hardware state header from which each general
  2767. register is restored is the offset of the write address of that register
  2768. from the base I/O address of the VGA.
  2769. Arguments:
  2770. HwDeviceExtension - Pointer to the miniport driver's device extension.
  2771. HardwareState - Pointer to a structure from which the saved state is to be
  2772. restored (actually only info about and a pointer to the actual save
  2773. buffer).
  2774. HardwareStateSize - Length of the input buffer supplied by the user.
  2775. (Actually only the size of the HardwareState structure, not the
  2776. buffer it points to from which the state is actually restored. The
  2777. pointed-to buffer is assumed to be big enough.)
  2778. Return Value:
  2779. NO_ERROR - restore performed successfully
  2780. ERROR_INSUFFICIENT_BUFFER - input buffer not large enough to provide data
  2781. --*/
  2782. {
  2783. PVIDEO_HARDWARE_STATE_HEADER hardwareStateHeader;
  2784. ULONG i;
  2785. UCHAR dummy;
  2786. PUCHAR pScreen;
  2787. PUCHAR pucLatch;
  2788. PULONG pulBuffer;
  2789. PUCHAR port;
  2790. PUCHAR portValue;
  2791. PUCHAR portValueDAC;
  2792. ULONG bIsColor;
  2793. ULONG portIO ;
  2794. UCHAR value ;
  2795. //
  2796. // Check if the size of the data in the input buffer is large enough.
  2797. //
  2798. if ((HardwareStateSize < sizeof(VIDEO_HARDWARE_STATE)) ||
  2799. (HardwareState->StateLength < VGA_TOTAL_STATE_SIZE)) {
  2800. return ERROR_INSUFFICIENT_BUFFER;
  2801. }
  2802. //
  2803. // Point to the buffer where the restore data is actually stored.
  2804. //
  2805. hardwareStateHeader = HardwareState->StateHeader;
  2806. //
  2807. // Make sure the offset are in the structure ...
  2808. //
  2809. if ((hardwareStateHeader->BasicSequencerOffset + VGA_NUM_SEQUENCER_PORTS >
  2810. HardwareState->StateLength) ||
  2811. (hardwareStateHeader->BasicCrtContOffset + VGA_NUM_CRTC_PORTS >
  2812. HardwareState->StateLength) ||
  2813. (hardwareStateHeader->BasicGraphContOffset + VGA_NUM_GRAPH_CONT_PORTS >
  2814. HardwareState->StateLength) ||
  2815. (hardwareStateHeader->BasicAttribContOffset + VGA_NUM_ATTRIB_CONT_PORTS >
  2816. HardwareState->StateLength) ||
  2817. (hardwareStateHeader->BasicDacOffset + (3 * VGA_NUM_DAC_ENTRIES) >
  2818. HardwareState->StateLength) ||
  2819. (hardwareStateHeader->BasicLatchesOffset + 4 >
  2820. HardwareState->StateLength) ||
  2821. (hardwareStateHeader->ExtendedSequencerOffset + EXT_NUM_SEQUENCER_PORTS >
  2822. HardwareState->StateLength) ||
  2823. (hardwareStateHeader->ExtendedCrtContOffset + EXT_NUM_CRTC_PORTS >
  2824. HardwareState->StateLength) ||
  2825. (hardwareStateHeader->ExtendedGraphContOffset + EXT_NUM_GRAPH_CONT_PORTS >
  2826. HardwareState->StateLength) ||
  2827. (hardwareStateHeader->ExtendedAttribContOffset + EXT_NUM_ATTRIB_CONT_PORTS >
  2828. HardwareState->StateLength) ||
  2829. (hardwareStateHeader->ExtendedDacOffset + (4 * EXT_NUM_DAC_ENTRIES) >
  2830. HardwareState->StateLength) ||
  2831. //
  2832. // Only check the validator state offset if there is unemulated data.
  2833. //
  2834. ((hardwareStateHeader->VGAStateFlags & VIDEO_STATE_UNEMULATED_VGA_STATE) &&
  2835. (hardwareStateHeader->ExtendedValidatorStateOffset + VGA_VALIDATOR_AREA_SIZE >
  2836. HardwareState->StateLength)) ||
  2837. (hardwareStateHeader->ExtendedMiscDataOffset + VGA_MISC_DATA_AREA_OFFSET >
  2838. HardwareState->StateLength) ||
  2839. (hardwareStateHeader->Plane1Offset + hardwareStateHeader->PlaneLength >
  2840. HardwareState->StateLength) ||
  2841. (hardwareStateHeader->Plane2Offset + hardwareStateHeader->PlaneLength >
  2842. HardwareState->StateLength) ||
  2843. (hardwareStateHeader->Plane3Offset + hardwareStateHeader->PlaneLength >
  2844. HardwareState->StateLength) ||
  2845. (hardwareStateHeader->Plane4Offset + hardwareStateHeader->PlaneLength >
  2846. HardwareState->StateLength) ||
  2847. (hardwareStateHeader->DIBOffset +
  2848. hardwareStateHeader->DIBBitsPerPixel / 8 *
  2849. hardwareStateHeader->DIBXResolution *
  2850. hardwareStateHeader->DIBYResolution > HardwareState->StateLength) ||
  2851. (hardwareStateHeader->DIBXlatOffset + hardwareStateHeader->DIBXlatLength >
  2852. HardwareState->StateLength)) {
  2853. return ERROR_INVALID_PARAMETER;
  2854. }
  2855. //
  2856. // Turn off the screen to avoid flickering. The screen will turn back on
  2857. // when we restore the DAC state at the end of this routine.
  2858. //
  2859. if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  2860. MISC_OUTPUT_REG_READ_PORT) & 0x01) {
  2861. port = INPUT_STATUS_1_COLOR + HwDeviceExtension->IOAddress;
  2862. } else {
  2863. port = INPUT_STATUS_1_MONO + HwDeviceExtension->IOAddress;
  2864. }
  2865. //
  2866. // Set DAC register 0 to display black.
  2867. //
  2868. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2869. DAC_ADDRESS_WRITE_PORT, 0);
  2870. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2871. DAC_DATA_REG_PORT, 0);
  2872. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2873. DAC_DATA_REG_PORT, 0);
  2874. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2875. DAC_DATA_REG_PORT, 0);
  2876. //
  2877. // Set the DAC mask register to force DAC register 0 to display all the
  2878. // time (this is the register we just set to display black). From now on,
  2879. // nothing but black will show up on the screen.
  2880. //
  2881. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2882. DAC_PIXEL_MASK_PORT, 0);
  2883. //
  2884. // Restore the latches and the contents of display memory.
  2885. //
  2886. // Set up the VGA's hardware to allow us to copy to each plane in turn.
  2887. //
  2888. // Begin sync reset.
  2889. //
  2890. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  2891. SEQ_ADDRESS_PORT),
  2892. (USHORT) (IND_SYNC_RESET + (START_SYNC_RESET_VALUE << 8)));
  2893. //
  2894. // Turn off Chain mode and map display memory at A0000 for 64K.
  2895. //
  2896. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2897. GRAPH_ADDRESS_PORT, IND_GRAPH_MISC);
  2898. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2899. GRAPH_DATA_PORT, (UCHAR) ((VideoPortReadPortUchar(
  2900. HwDeviceExtension->IOAddress + GRAPH_DATA_PORT) & 0xF1) | 0x04));
  2901. //
  2902. // Turn off Chain4 mode and odd/even.
  2903. //
  2904. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2905. SEQ_ADDRESS_PORT, IND_MEMORY_MODE);
  2906. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2907. SEQ_DATA_PORT,
  2908. (UCHAR) ((VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  2909. SEQ_DATA_PORT) & 0xF3) | 0x04));
  2910. //
  2911. // End sync reset.
  2912. //
  2913. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  2914. SEQ_ADDRESS_PORT), (USHORT) (IND_SYNC_RESET +
  2915. (END_SYNC_RESET_VALUE << 8)));
  2916. //
  2917. // Set the write mode to 0, the read mode to 0, and turn off odd/even.
  2918. //
  2919. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2920. GRAPH_ADDRESS_PORT, IND_GRAPH_MODE);
  2921. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2922. GRAPH_DATA_PORT,
  2923. (UCHAR) ((VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  2924. GRAPH_DATA_PORT) & 0xE4) | 0x00));
  2925. //
  2926. // Set the Bit Mask to 0xFF to allow all CPU bits through.
  2927. //
  2928. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  2929. GRAPH_ADDRESS_PORT), (USHORT) (IND_BIT_MASK + (0xFF << 8)));
  2930. //
  2931. // Set the Data Rotation and Logical Function fields to 0 to allow CPU
  2932. // data through unmodified.
  2933. //
  2934. VideoPortWritePortUshort((PUSHORT)(HwDeviceExtension->IOAddress +
  2935. GRAPH_ADDRESS_PORT), (USHORT) (IND_DATA_ROTATE + (0 << 8)));
  2936. //
  2937. // Set Set/Reset Enable to 0 to select CPU data for all planes.
  2938. //
  2939. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  2940. GRAPH_ADDRESS_PORT), (USHORT) (IND_SET_RESET_ENABLE + (0 << 8)));
  2941. //
  2942. // Point the Sequencer Index to the Map Mask register.
  2943. //
  2944. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2945. SEQ_ADDRESS_PORT, IND_MAP_MASK);
  2946. //
  2947. // Restore the latches.
  2948. //
  2949. // Point to the saved data for the first latch.
  2950. //
  2951. pucLatch = ((PUCHAR) (hardwareStateHeader)) +
  2952. hardwareStateHeader->BasicLatchesOffset;
  2953. //
  2954. // Point to first byte of display memory.
  2955. //
  2956. pScreen = (PUCHAR) HwDeviceExtension->VideoMemoryAddress;
  2957. //
  2958. // Write the contents to be restored to each of the four latches in turn.
  2959. //
  2960. for (i = 0; i < 4; i++) {
  2961. //
  2962. // Set the Map Mask to select the plane we want to restore next.
  2963. //
  2964. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2965. SEQ_DATA_PORT, (UCHAR)(1<<i));
  2966. //
  2967. // Write this plane's latch.
  2968. //
  2969. VideoPortWriteRegisterUchar(pScreen, *pucLatch++);
  2970. }
  2971. //
  2972. // Read the latched data into the latches, and the latches are set.
  2973. //
  2974. dummy = VideoPortReadRegisterUchar(pScreen);
  2975. //
  2976. // Point to the offset of the saved data for the first plane.
  2977. //
  2978. pulBuffer = &(hardwareStateHeader->Plane1Offset);
  2979. //
  2980. // Restore each of the four planes in turn.
  2981. //
  2982. for (i = 0; i < 4; i++) {
  2983. //
  2984. // Set the Map Mask to select the plane we want to restore next.
  2985. //
  2986. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  2987. SEQ_DATA_PORT, (UCHAR)(1<<i));
  2988. //
  2989. // Restore this plane from the buffer.
  2990. //
  2991. VideoPortMoveMemory((PUCHAR) HwDeviceExtension->VideoMemoryAddress,
  2992. ((PUCHAR) (hardwareStateHeader)) + *pulBuffer,
  2993. hardwareStateHeader->PlaneLength);
  2994. pulBuffer++;
  2995. }
  2996. //
  2997. // If we have some unemulated data, put it back into the buffer
  2998. //
  2999. if (hardwareStateHeader->VGAStateFlags & VIDEO_STATE_UNEMULATED_VGA_STATE) {
  3000. if (!hardwareStateHeader->ExtendedValidatorStateOffset) {
  3001. return ERROR_INVALID_PARAMETER;
  3002. }
  3003. //
  3004. // Get the right offset in the struct and save all the data associated
  3005. // with the trapped validator data.
  3006. //
  3007. VideoPortMoveMemory(&(HwDeviceExtension->TrappedValidatorCount),
  3008. ((PUCHAR) (hardwareStateHeader)) +
  3009. hardwareStateHeader->ExtendedValidatorStateOffset,
  3010. VGA_VALIDATOR_AREA_SIZE);
  3011. //
  3012. // Check to see if this is an appropriate access range.
  3013. // We are trapping - so we must have the trapping access range enabled.
  3014. //
  3015. if (((HwDeviceExtension->CurrentVdmAccessRange != FullVgaValidatorAccessRange) ||
  3016. (HwDeviceExtension->CurrentNumVdmAccessRanges != NUM_FULL_VGA_VALIDATOR_ACCESS_RANGE)) &&
  3017. ((HwDeviceExtension->CurrentVdmAccessRange != MinimalVgaValidatorAccessRange) ||
  3018. (HwDeviceExtension->CurrentNumVdmAccessRanges != NUM_MINIMAL_VGA_VALIDATOR_ACCESS_RANGE))) {
  3019. return ERROR_INVALID_PARAMETER;
  3020. }
  3021. VideoPortSetTrappedEmulatorPorts(HwDeviceExtension,
  3022. HwDeviceExtension->CurrentNumVdmAccessRanges,
  3023. HwDeviceExtension->CurrentVdmAccessRange);
  3024. }
  3025. //
  3026. // Set the critical registers (clock and timing states) during sync reset.
  3027. //
  3028. // Begin sync reset.
  3029. //
  3030. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  3031. SEQ_ADDRESS_PORT), (USHORT) (IND_SYNC_RESET +
  3032. (START_SYNC_RESET_VALUE << 8)));
  3033. //
  3034. // Restore the Miscellaneous Output register.
  3035. //
  3036. portIO = MISC_OUTPUT_REG_WRITE_PORT ;
  3037. value = (UCHAR) (hardwareStateHeader->PortValue[MISC_OUTPUT_REG_WRITE_PORT-VGA_BASE_IO_PORT] & 0xF7) ;
  3038. IOWaitDisplEnableThenWrite ( HwDeviceExtension,
  3039. portIO,
  3040. value ) ;
  3041. //
  3042. // Restore all Sequencer registers except the Sync Reset register, which
  3043. // is always not in reset (except when we send out a batched sync reset
  3044. // register set, but that can't be interrupted, so we know we're never in
  3045. // sync reset at save/restore time).
  3046. //
  3047. portValue = ((PUCHAR) hardwareStateHeader) +
  3048. hardwareStateHeader->BasicSequencerOffset + 1;
  3049. for (i = 1; i < VGA_NUM_SEQUENCER_PORTS; i++) {
  3050. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  3051. SEQ_ADDRESS_PORT), (USHORT) (i + ((*portValue++) << 8)) );
  3052. }
  3053. //
  3054. // Restore extended sequencer registers
  3055. //
  3056. #ifdef EXTENDED_REGISTER_SAVE_RESTORE
  3057. if (hardwareStateHeader->ExtendedSequencerOffset) {
  3058. portValue = ((PUCHAR) hardwareStateHeader) +
  3059. hardwareStateHeader->ExtendedSequencerOffset;
  3060. if ((HwDeviceExtension->ChipType != CL6410) &&
  3061. (HwDeviceExtension->ChipType != CL6420))
  3062. {
  3063. //
  3064. // No extended sequencer registers for the CL64xx
  3065. //
  3066. //
  3067. // The first section in restore must open the extension registers
  3068. //
  3069. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  3070. SEQ_ADDRESS_PORT),
  3071. IND_CL_EXTS_ENB + (0x0012 << 8) );
  3072. for (i = CL542x_SEQUENCER_EXT_START;
  3073. i <= CL542x_SEQUENCER_EXT_END;
  3074. i++) {
  3075. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  3076. SEQ_ADDRESS_PORT),
  3077. (USHORT) (i + ((*portValue++) << 8)) );
  3078. }
  3079. }
  3080. }
  3081. #endif
  3082. //
  3083. // Restore the Graphics Controller Miscellaneous register, which contains
  3084. // the Chain bit.
  3085. //
  3086. portValue = ((PUCHAR) hardwareStateHeader) +
  3087. hardwareStateHeader->BasicGraphContOffset + IND_GRAPH_MISC;
  3088. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  3089. GRAPH_ADDRESS_PORT), (USHORT)(IND_GRAPH_MISC + (*portValue << 8)));
  3090. //
  3091. // End sync reset.
  3092. //
  3093. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  3094. SEQ_ADDRESS_PORT), (USHORT) (IND_SYNC_RESET +
  3095. (END_SYNC_RESET_VALUE << 8)));
  3096. //
  3097. // Figure out if color/mono switchable registers are at 3BX or 3DX.
  3098. // At the same time, save the state of the Miscellaneous Output register
  3099. // which is read from 3CC but written at 3C2.
  3100. //
  3101. if (hardwareStateHeader->PortValue[MISC_OUTPUT_REG_WRITE_PORT-VGA_BASE_IO_PORT] & 0x01) {
  3102. bIsColor = TRUE;
  3103. } else {
  3104. bIsColor = FALSE;
  3105. }
  3106. //
  3107. // Restore the CRT Controller indexed registers.
  3108. //
  3109. // Unlock CRTC registers 0-7.
  3110. //
  3111. portValue = (PUCHAR) hardwareStateHeader +
  3112. hardwareStateHeader->BasicCrtContOffset;
  3113. if (bIsColor) {
  3114. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  3115. CRTC_ADDRESS_PORT_COLOR), (USHORT) (IND_CRTC_PROTECT +
  3116. (((*(portValue + IND_CRTC_PROTECT)) & 0x7F) << 8)));
  3117. } else {
  3118. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  3119. CRTC_ADDRESS_PORT_MONO), (USHORT) (IND_CRTC_PROTECT +
  3120. (((*(portValue + IND_CRTC_PROTECT)) & 0x7F) << 8)));
  3121. }
  3122. //
  3123. // Restore extended crtc registers.
  3124. //
  3125. #ifdef EXTENDED_REGISTER_SAVE_RESTORE
  3126. if (hardwareStateHeader->ExtendedCrtContOffset) {
  3127. portValue = (PUCHAR) hardwareStateHeader +
  3128. hardwareStateHeader->ExtendedCrtContOffset;
  3129. if ((HwDeviceExtension->ChipType != CL6410) &&
  3130. (HwDeviceExtension->ChipType != CL6420))
  3131. {
  3132. //
  3133. // No CRTC Extensions in CL64xx chipset
  3134. //
  3135. for (i = CL542x_CRTC_EXT_START; i <= CL542x_CRTC_EXT_END; i++) {
  3136. if (bIsColor) {
  3137. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  3138. CRTC_ADDRESS_PORT_COLOR),
  3139. (USHORT) (i + ((*portValue++) << 8)));
  3140. } else {
  3141. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  3142. CRTC_ADDRESS_PORT_MONO),
  3143. (USHORT) (i + ((*portValue++) << 8)));
  3144. }
  3145. }
  3146. }
  3147. /* myf2, crus
  3148. if (HwDeviceExtension->ChipType & CL755x)
  3149. {
  3150. for (i = 0x81; i <= 0x91; i++)
  3151. {
  3152. if (bIsColor)
  3153. {
  3154. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  3155. CRTC_ADDRESS_PORT_COLOR),
  3156. (USHORT) (i + ((*portValue++) << 8)));
  3157. } else {
  3158. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  3159. CRTC_ADDRESS_PORT_MONO),
  3160. (USHORT) (i + ((*portValue++) << 8)));
  3161. }
  3162. }
  3163. }
  3164. crus, myf2 */
  3165. }
  3166. #endif
  3167. //
  3168. // Now restore the CRTC registers.
  3169. //
  3170. portValue = (PUCHAR) hardwareStateHeader +
  3171. hardwareStateHeader->BasicCrtContOffset;
  3172. for (i = 0; i < VGA_NUM_CRTC_PORTS; i++) {
  3173. if (bIsColor) {
  3174. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  3175. CRTC_ADDRESS_PORT_COLOR),
  3176. (USHORT) (i + ((*portValue++) << 8)));
  3177. } else {
  3178. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  3179. CRTC_ADDRESS_PORT_MONO),
  3180. (USHORT) (i + ((*portValue++) << 8)));
  3181. }
  3182. }
  3183. //
  3184. // Restore the Graphics Controller indexed registers.
  3185. //
  3186. portValue = (PUCHAR) hardwareStateHeader +
  3187. hardwareStateHeader->BasicGraphContOffset;
  3188. for (i = 0; i < VGA_NUM_GRAPH_CONT_PORTS; i++) {
  3189. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  3190. GRAPH_ADDRESS_PORT), (USHORT) (i + ((*portValue++) << 8)));
  3191. }
  3192. //
  3193. // Restore extended graphics controller registers.
  3194. //
  3195. #ifdef EXTENDED_REGISTER_SAVE_RESTORE
  3196. if (hardwareStateHeader->ExtendedGraphContOffset) {
  3197. portValue = (PUCHAR) hardwareStateHeader +
  3198. hardwareStateHeader->ExtendedGraphContOffset;
  3199. if ((HwDeviceExtension->ChipType != CL6410) &&
  3200. (HwDeviceExtension->ChipType != CL6420))
  3201. {
  3202. for (i = CL542x_GRAPH_EXT_START; i <= CL542x_GRAPH_EXT_END; i++) {
  3203. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  3204. GRAPH_ADDRESS_PORT),
  3205. (USHORT) (i + ((*portValue++) << 8)));
  3206. }
  3207. } else { // must be a CL64xx
  3208. VideoPortWritePortUshort((PUSHORT)(HwDeviceExtension->IOAddress +
  3209. GRAPH_ADDRESS_PORT),
  3210. CL64xx_EXTENSION_ENABLE_INDEX +
  3211. (CL64xx_EXTENSION_ENABLE_VALUE << 8));
  3212. for (i = CL64xx_GRAPH_EXT_START; i <= CL64xx_GRAPH_EXT_END; i++) {
  3213. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  3214. GRAPH_ADDRESS_PORT),
  3215. (USHORT) (i + ((*portValue++) << 8)));
  3216. }
  3217. }
  3218. }
  3219. #endif
  3220. //
  3221. // Restore the Attribute Controller indexed registers.
  3222. //
  3223. portValue = (PUCHAR) hardwareStateHeader +
  3224. hardwareStateHeader->BasicAttribContOffset;
  3225. //
  3226. // Reset the AC index/data toggle, then blast out all the register
  3227. // settings.
  3228. //
  3229. if (bIsColor) {
  3230. dummy = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3231. INPUT_STATUS_1_COLOR);
  3232. } else {
  3233. dummy = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3234. INPUT_STATUS_1_MONO);
  3235. }
  3236. for (i = 0; i < VGA_NUM_ATTRIB_CONT_PORTS; i++) {
  3237. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3238. ATT_ADDRESS_PORT, (UCHAR)i);
  3239. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3240. ATT_DATA_WRITE_PORT, *portValue++);
  3241. }
  3242. //
  3243. // Restore DAC registers 1 through 255. We'll do register 0, the DAC Mask,
  3244. // and the index registers later.
  3245. // Set the DAC address port Index, then write out the DAC Data registers.
  3246. // Each three reads get Red, Green, and Blue components for that register.
  3247. //
  3248. // Write them one at a time due to problems on local bus machines.
  3249. //
  3250. portValueDAC = (PUCHAR) hardwareStateHeader +
  3251. hardwareStateHeader->BasicDacOffset + 3;
  3252. for (i = 1; i < VGA_NUM_DAC_ENTRIES; i++) {
  3253. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3254. DAC_ADDRESS_WRITE_PORT, (UCHAR)i);
  3255. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3256. DAC_DATA_REG_PORT, *portValueDAC++);
  3257. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3258. DAC_DATA_REG_PORT, *portValueDAC++);
  3259. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3260. DAC_DATA_REG_PORT, *portValueDAC++);
  3261. }
  3262. //
  3263. // Is this color or mono ?
  3264. //
  3265. if (bIsColor) {
  3266. port = HwDeviceExtension->IOAddress + INPUT_STATUS_1_COLOR;
  3267. } else {
  3268. port = HwDeviceExtension->IOAddress + INPUT_STATUS_1_MONO;
  3269. }
  3270. //
  3271. // Restore the Feature Control register.
  3272. //
  3273. if (bIsColor) {
  3274. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3275. FEAT_CTRL_WRITE_PORT_COLOR,
  3276. hardwareStateHeader->PortValue[FEAT_CTRL_WRITE_PORT_COLOR-VGA_BASE_IO_PORT]);
  3277. } else {
  3278. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3279. FEAT_CTRL_WRITE_PORT_MONO,
  3280. hardwareStateHeader->PortValue[FEAT_CTRL_WRITE_PORT_MONO-VGA_BASE_IO_PORT]);
  3281. }
  3282. //
  3283. // Restore the Sequencer Index.
  3284. //
  3285. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3286. SEQ_ADDRESS_PORT,
  3287. hardwareStateHeader->PortValue[SEQ_ADDRESS_PORT-VGA_BASE_IO_PORT]);
  3288. //
  3289. // Restore the CRT Controller Index.
  3290. //
  3291. if (bIsColor) {
  3292. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3293. CRTC_ADDRESS_PORT_COLOR,
  3294. hardwareStateHeader->PortValue[CRTC_ADDRESS_PORT_COLOR-VGA_BASE_IO_PORT]);
  3295. } else {
  3296. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3297. CRTC_ADDRESS_PORT_MONO,
  3298. hardwareStateHeader->PortValue[CRTC_ADDRESS_PORT_MONO-VGA_BASE_IO_PORT]);
  3299. }
  3300. //
  3301. // Restore the Graphics Controller Index.
  3302. //
  3303. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3304. GRAPH_ADDRESS_PORT,
  3305. hardwareStateHeader->PortValue[GRAPH_ADDRESS_PORT-VGA_BASE_IO_PORT]);
  3306. //
  3307. // Restore the Attribute Controller Index and index/data toggle state.
  3308. //
  3309. if (bIsColor) {
  3310. port = HwDeviceExtension->IOAddress + INPUT_STATUS_1_COLOR;
  3311. } else {
  3312. port = HwDeviceExtension->IOAddress + INPUT_STATUS_1_MONO;
  3313. }
  3314. VideoPortReadPortUchar(port); // reset the toggle to Index state
  3315. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3316. ATT_ADDRESS_PORT, // restore the AC Index
  3317. hardwareStateHeader->PortValue[ATT_ADDRESS_PORT-VGA_BASE_IO_PORT]);
  3318. //
  3319. // If the toggle should be in Data state, we're all set. If it should be in
  3320. // Index state, reset it to that condition.
  3321. //
  3322. if (hardwareStateHeader->AttribIndexDataState == 0) {
  3323. //
  3324. // Reset the toggle to Index state.
  3325. //
  3326. VideoPortReadPortUchar(port);
  3327. }
  3328. //
  3329. // Restore DAC register 0 and the DAC Mask, to unblank the screen.
  3330. //
  3331. portValueDAC = (PUCHAR) hardwareStateHeader +
  3332. hardwareStateHeader->BasicDacOffset;
  3333. //
  3334. // Restore the DAC Mask register.
  3335. //
  3336. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3337. DAC_PIXEL_MASK_PORT,
  3338. hardwareStateHeader->PortValue[DAC_PIXEL_MASK_PORT-VGA_BASE_IO_PORT]);
  3339. //
  3340. // Restore DAC register 0.
  3341. //
  3342. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3343. DAC_ADDRESS_WRITE_PORT, 0);
  3344. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3345. DAC_DATA_REG_PORT, *portValueDAC++);
  3346. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3347. DAC_DATA_REG_PORT, *portValueDAC++);
  3348. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3349. DAC_DATA_REG_PORT, *portValueDAC++);
  3350. //
  3351. // Restore the read/write state and the current index of the DAC.
  3352. //
  3353. // See whether the Read or Write Index was written to most recently.
  3354. // (The upper nibble stored at DAC_STATE_PORT is the # of reads/writes
  3355. // for the current index.)
  3356. //
  3357. if ((hardwareStateHeader->PortValue[DAC_STATE_PORT-VGA_BASE_IO_PORT] & 0x0F) == 3) {
  3358. //
  3359. // The DAC Read Index was written to last. Restore the DAC by setting
  3360. // up to read from the saved index - 1, because the way the Read
  3361. // Index works is that it autoincrements after reading, so you actually
  3362. // end up reading the data for the index you read at the DAC Write
  3363. // Mask register - 1.
  3364. //
  3365. // Set the Read Index to the index we read, minus 1, accounting for
  3366. // wrap from 255 back to 0. The DAC hardware immediately reads this
  3367. // register into a temporary buffer, then adds 1 to the index.
  3368. //
  3369. if (hardwareStateHeader->PortValue[DAC_ADDRESS_WRITE_PORT-VGA_BASE_IO_PORT] == 0) {
  3370. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3371. DAC_ADDRESS_READ_PORT, 255);
  3372. } else {
  3373. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3374. DAC_ADDRESS_READ_PORT, (UCHAR)
  3375. (hardwareStateHeader->PortValue[DAC_ADDRESS_WRITE_PORT-VGA_BASE_IO_PORT] -
  3376. 1));
  3377. }
  3378. //
  3379. // Now read the hardware however many times are required to get to
  3380. // the partial read state we saved.
  3381. //
  3382. for (i = hardwareStateHeader->PortValue[DAC_STATE_PORT-VGA_BASE_IO_PORT] >> 4;
  3383. i > 0; i--) {
  3384. dummy = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3385. DAC_DATA_REG_PORT);
  3386. }
  3387. } else {
  3388. //
  3389. // The DAC Write Index was written to last. Set the Write Index to the
  3390. // index value we read out of the DAC. Then, if a partial write
  3391. // (partway through an RGB triplet) was in place, write the partial
  3392. // values, which we obtained by writing them to the current DAC
  3393. // register. This DAC register will be wrong until the write is
  3394. // completed, but at least the values will be right once the write is
  3395. // finished, and most importantly we won't have messed up the sequence
  3396. // of RGB writes (which can be as long as 768 in a row).
  3397. //
  3398. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3399. DAC_ADDRESS_WRITE_PORT,
  3400. hardwareStateHeader->PortValue[DAC_ADDRESS_WRITE_PORT-VGA_BASE_IO_PORT]);
  3401. //
  3402. // Now write to the hardware however many times are required to get to
  3403. // the partial write state we saved (if any).
  3404. //
  3405. // Point to the saved value for the DAC register that was in the
  3406. // process of being written to; we wrote the partial value out, so now
  3407. // we can restore it.
  3408. //
  3409. portValueDAC = (PUCHAR) hardwareStateHeader +
  3410. hardwareStateHeader->BasicDacOffset +
  3411. (hardwareStateHeader->PortValue[DAC_ADDRESS_WRITE_PORT-VGA_BASE_IO_PORT] * 3);
  3412. for (i = hardwareStateHeader->PortValue[DAC_STATE_PORT-VGA_BASE_IO_PORT] >> 4;
  3413. i > 0; i--) {
  3414. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3415. DAC_DATA_REG_PORT, *portValueDAC++);
  3416. }
  3417. }
  3418. return NO_ERROR;
  3419. } // end VgaRestoreHardwareState()
  3420. //---------------------------------------------------------------------------
  3421. VP_STATUS
  3422. VgaSaveHardwareState(
  3423. PHW_DEVICE_EXTENSION HwDeviceExtension,
  3424. PVIDEO_HARDWARE_STATE HardwareState,
  3425. ULONG HardwareStateSize,
  3426. PULONG OutputSize
  3427. )
  3428. /*++
  3429. Routine Description:
  3430. Saves all registers and memory of the VGA.
  3431. Note: HardwareState points to the actual buffer in which the state
  3432. is saved. This buffer will always be big enough (we specified
  3433. the required size at DriverEntry).
  3434. Note: This routine leaves registers in any state it cares to, except
  3435. that it will not mess with any of the CRT or Sequencer parameters that
  3436. might make the monitor unhappy. It leaves the screen blanked by setting
  3437. the DAC Mask and DAC register 0 to all zero values. The next video
  3438. operation we expect after this is a mode set to take us back to Win32.
  3439. Note: The offset in the hardware state header in which each general
  3440. register is saved is the offset of the write address of that register from
  3441. the base I/O address of the VGA.
  3442. Arguments:
  3443. HwDeviceExtension - Pointer to the miniport driver's device extension.
  3444. HardwareState - Pointer to a structure in which the saved state will be
  3445. returned (actually only info about and a pointer to the actual save
  3446. buffer).
  3447. HardwareStateSize - Length of the output buffer supplied by the user.
  3448. (Actually only the size of the HardwareState structure, not the
  3449. buffer it points to where the state is actually saved. The pointed-
  3450. to buffer is assumed to be big enough.)
  3451. OutputSize - Pointer to a buffer in which to return the actual size of
  3452. the data returned in the buffer.
  3453. Return Value:
  3454. NO_ERROR - information returned successfully
  3455. ERROR_INSUFFICIENT_BUFFER - output buffer not large enough to return
  3456. any useful data
  3457. --*/
  3458. {
  3459. PVIDEO_HARDWARE_STATE_HEADER hardwareStateHeader;
  3460. PUCHAR port;
  3461. PUCHAR pScreen;
  3462. PUCHAR portValue;
  3463. PUCHAR portValueDAC;
  3464. PUCHAR bufferPointer;
  3465. ULONG i;
  3466. UCHAR dummy, originalACIndex, originalACData;
  3467. UCHAR ucCRTC03;
  3468. ULONG bIsColor;
  3469. ULONG portIO ;
  3470. UCHAR value ;
  3471. //
  3472. // See if the buffer is big enough to hold the hardware state structure.
  3473. // (This is only the HardwareState structure itself, not the buffer it
  3474. // points to.)
  3475. //
  3476. if (HardwareStateSize < sizeof(VIDEO_HARDWARE_STATE) ) {
  3477. *OutputSize = 0; // nothing returned
  3478. return ERROR_INSUFFICIENT_BUFFER;
  3479. }
  3480. //
  3481. // Amount of data we're going to return in the output buffer.
  3482. // (The VIDEO_HARDWARE_STATE in the output buffer points to the actual
  3483. // buffer in which the state is stored, which is assumed to be large
  3484. // enough.)
  3485. //
  3486. *OutputSize = sizeof(VIDEO_HARDWARE_STATE);
  3487. //
  3488. // Indicate the size of the full state save info.
  3489. //
  3490. HardwareState->StateLength = VGA_TOTAL_STATE_SIZE;
  3491. //
  3492. // hardwareStateHeader is a structure of offsets at the start of the
  3493. // actual save area that indicates the locations in which various VGA
  3494. // register and memory components are saved.
  3495. //
  3496. hardwareStateHeader = HardwareState->StateHeader;
  3497. //
  3498. // Zero out the structure.
  3499. //
  3500. VideoPortZeroMemory(hardwareStateHeader, sizeof(VIDEO_HARDWARE_STATE_HEADER));
  3501. //
  3502. // Set the Length field, which is basically a version ID.
  3503. //
  3504. hardwareStateHeader->Length = sizeof(VIDEO_HARDWARE_STATE_HEADER);
  3505. //
  3506. // Set the basic register offsets properly.
  3507. //
  3508. hardwareStateHeader->BasicSequencerOffset = VGA_BASIC_SEQUENCER_OFFSET;
  3509. hardwareStateHeader->BasicCrtContOffset = VGA_BASIC_CRTC_OFFSET;
  3510. hardwareStateHeader->BasicGraphContOffset = VGA_BASIC_GRAPH_CONT_OFFSET;
  3511. hardwareStateHeader->BasicAttribContOffset = VGA_BASIC_ATTRIB_CONT_OFFSET;
  3512. hardwareStateHeader->BasicDacOffset = VGA_BASIC_DAC_OFFSET;
  3513. hardwareStateHeader->BasicLatchesOffset = VGA_BASIC_LATCHES_OFFSET;
  3514. //
  3515. // Set the entended register offsets properly.
  3516. //
  3517. hardwareStateHeader->ExtendedSequencerOffset = VGA_EXT_SEQUENCER_OFFSET;
  3518. hardwareStateHeader->ExtendedCrtContOffset = VGA_EXT_CRTC_OFFSET;
  3519. hardwareStateHeader->ExtendedGraphContOffset = VGA_EXT_GRAPH_CONT_OFFSET;
  3520. hardwareStateHeader->ExtendedAttribContOffset = VGA_EXT_ATTRIB_CONT_OFFSET;
  3521. hardwareStateHeader->ExtendedDacOffset = VGA_EXT_DAC_OFFSET;
  3522. //
  3523. // Figure out if color/mono switchable registers are at 3BX or 3DX.
  3524. // At the same time, save the state of the Miscellaneous Output register
  3525. // which is read from 3CC but written at 3C2.
  3526. //
  3527. if ((hardwareStateHeader->PortValue[MISC_OUTPUT_REG_WRITE_PORT-VGA_BASE_IO_PORT] =
  3528. VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3529. MISC_OUTPUT_REG_READ_PORT))
  3530. & 0x01) {
  3531. bIsColor = TRUE;
  3532. } else {
  3533. bIsColor = FALSE;
  3534. }
  3535. //
  3536. // Force the video subsystem enable state to enabled.
  3537. //
  3538. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3539. VIDEO_SUBSYSTEM_ENABLE_PORT, 1);
  3540. //
  3541. // Save the DAC state first, so we can set the DAC to blank the screen
  3542. // so nothing after this shows up at all.
  3543. //
  3544. // Save the DAC Mask register.
  3545. //
  3546. hardwareStateHeader->PortValue[DAC_PIXEL_MASK_PORT-VGA_BASE_IO_PORT] =
  3547. VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3548. DAC_PIXEL_MASK_PORT);
  3549. //
  3550. // Save the DAC Index register. Note that there is actually only one DAC
  3551. // Index register, which functions as either the Read Index or the Write
  3552. // Index as needed.
  3553. //
  3554. hardwareStateHeader->PortValue[DAC_ADDRESS_WRITE_PORT-VGA_BASE_IO_PORT] =
  3555. VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3556. DAC_ADDRESS_WRITE_PORT);
  3557. //
  3558. // Save the DAC read/write state. We determine if the DAC has been written
  3559. // to or read from at the current index 0, 1, or 2 times (the application
  3560. // is in the middle of reading or writing a DAC register triplet if the
  3561. // count is 1 or 2), and save enough info so we can restore things
  3562. // properly. The only hole is if the application writes to the Write Index,
  3563. // then reads from instead of writes to the Data register, or vice-versa,
  3564. // or if they do a partial read write, then never finish it.
  3565. // This is fairly ridiculous behavior, however, and anyway there's nothing
  3566. // we can do about it.
  3567. //
  3568. hardwareStateHeader->PortValue[DAC_STATE_PORT-VGA_BASE_IO_PORT] =
  3569. VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3570. DAC_STATE_PORT);
  3571. if (hardwareStateHeader->PortValue[DAC_STATE_PORT-VGA_BASE_IO_PORT] == 3) {
  3572. //
  3573. // The DAC Read Index was written to last. Figure out how many reads
  3574. // have been done from the current index. We'll restart this on restore
  3575. // by setting the Read Index to the current index - 1 (the read index
  3576. // is one greater than the index being read), then doing the proper
  3577. // number of reads.
  3578. //
  3579. // Read the Data register once, and see if the index changes.
  3580. //
  3581. dummy = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3582. DAC_DATA_REG_PORT);
  3583. if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3584. DAC_ADDRESS_WRITE_PORT) !=
  3585. hardwareStateHeader->PortValue[DAC_ADDRESS_WRITE_PORT-VGA_BASE_IO_PORT]) {
  3586. //
  3587. // The DAC Index changed, so two reads had already been done from
  3588. // the current index. Store the count "2" in the upper nibble of
  3589. // the read/write state field.
  3590. //
  3591. hardwareStateHeader->PortValue[DAC_STATE_PORT-VGA_BASE_IO_PORT] |= 0x20;
  3592. } else {
  3593. //
  3594. // Read the Data register again, and see if the index changes.
  3595. //
  3596. dummy = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3597. DAC_DATA_REG_PORT);
  3598. if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3599. DAC_ADDRESS_WRITE_PORT) !=
  3600. hardwareStateHeader->PortValue[DAC_ADDRESS_WRITE_PORT-VGA_BASE_IO_PORT]) {
  3601. //
  3602. // The DAC Index changed, so one read had already been done
  3603. // from the current index. Store the count "1" in the upper
  3604. // nibble of the read/write state field.
  3605. //
  3606. hardwareStateHeader->PortValue[DAC_STATE_PORT-VGA_BASE_IO_PORT] |= 0x10;
  3607. }
  3608. //
  3609. // If neither 2 nor 1 reads had been done from the current index,
  3610. // then 0 reads were done, and we're all set, since the upper
  3611. // nibble of the read/write state field is already 0.
  3612. //
  3613. }
  3614. } else {
  3615. //
  3616. // The DAC Write Index was written to last. Figure out how many writes
  3617. // have been done to the current index. We'll restart this on restore
  3618. // by setting the Write Index to the proper index, then doing the
  3619. // proper number of writes. When we do the DAC register save, we'll
  3620. // read out the value that gets written (if there was a partial write
  3621. // in progress), so we can restore the proper data later. This will
  3622. // cause this current DAC location to be briefly wrong in the 1- and
  3623. // 2-bytes-written case (until the app finishes the write), but that's
  3624. // better than having the wrong DAC values written for good.
  3625. //
  3626. // Write the Data register once, and see if the index changes.
  3627. //
  3628. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3629. DAC_DATA_REG_PORT, 0);
  3630. if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3631. DAC_ADDRESS_WRITE_PORT) !=
  3632. hardwareStateHeader->PortValue[DAC_ADDRESS_WRITE_PORT-VGA_BASE_IO_PORT]) {
  3633. //
  3634. // The DAC Index changed, so two writes had already been done to
  3635. // the current index. Store the count "2" in the upper nibble of
  3636. // the read/write state field.
  3637. //
  3638. hardwareStateHeader->PortValue[DAC_STATE_PORT-VGA_BASE_IO_PORT] |= 0x20;
  3639. } else {
  3640. //
  3641. // Write the Data register again, and see if the index changes.
  3642. //
  3643. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3644. DAC_DATA_REG_PORT, 0);
  3645. if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3646. DAC_ADDRESS_WRITE_PORT) !=
  3647. hardwareStateHeader->PortValue[DAC_ADDRESS_WRITE_PORT-VGA_BASE_IO_PORT]) {
  3648. //
  3649. // The DAC Index changed, so one write had already been done
  3650. // to the current index. Store the count "1" in the upper
  3651. // nibble of the read/write state field.
  3652. //
  3653. hardwareStateHeader->PortValue[DAC_STATE_PORT-VGA_BASE_IO_PORT] |= 0x10;
  3654. }
  3655. //
  3656. // If neither 2 nor 1 writes had been done to the current index,
  3657. // then 0 writes were done, and we're all set.
  3658. //
  3659. }
  3660. }
  3661. //
  3662. // Now, read out the 256 18-bit DAC palette registers (256 RGB triplets),
  3663. // and blank the screen.
  3664. //
  3665. portValueDAC = (PUCHAR) hardwareStateHeader + VGA_BASIC_DAC_OFFSET;
  3666. //
  3667. // Read out DAC register 0, so we can set it to black.
  3668. //
  3669. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3670. DAC_ADDRESS_READ_PORT, 0);
  3671. *portValueDAC++ = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3672. DAC_DATA_REG_PORT);
  3673. *portValueDAC++ = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3674. DAC_DATA_REG_PORT);
  3675. *portValueDAC++ = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3676. DAC_DATA_REG_PORT);
  3677. //
  3678. // Set DAC register 0 to display black.
  3679. //
  3680. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3681. DAC_ADDRESS_WRITE_PORT, 0);
  3682. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3683. DAC_DATA_REG_PORT, 0);
  3684. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3685. DAC_DATA_REG_PORT, 0);
  3686. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3687. DAC_DATA_REG_PORT, 0);
  3688. //
  3689. // Set the DAC mask register to force DAC register 0 to display all the
  3690. // time (this is the register we just set to display black). From now on,
  3691. // nothing but black will show up on the screen.
  3692. //
  3693. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3694. DAC_PIXEL_MASK_PORT, 0);
  3695. //
  3696. // Read out the Attribute Controller Index state, and deduce the Index/Data
  3697. // toggle state at the same time.
  3698. //
  3699. // Save the state of the Attribute Controller, both Index and Data,
  3700. // so we can test in which state the toggle currently is.
  3701. //
  3702. originalACIndex = hardwareStateHeader->PortValue[ATT_ADDRESS_PORT-VGA_BASE_IO_PORT] =
  3703. VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3704. ATT_ADDRESS_PORT);
  3705. originalACData = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3706. ATT_DATA_READ_PORT);
  3707. //
  3708. // Sequencer Index.
  3709. //
  3710. hardwareStateHeader->PortValue[SEQ_ADDRESS_PORT-VGA_BASE_IO_PORT] =
  3711. VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3712. SEQ_ADDRESS_PORT);
  3713. //
  3714. // Begin sync reset, just in case this is an SVGA and the currently
  3715. // indexed Attribute Controller register controls clocking stuff (a
  3716. // normal VGA won't require this).
  3717. //
  3718. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  3719. SEQ_ADDRESS_PORT),
  3720. (USHORT) (IND_SYNC_RESET + (START_SYNC_RESET_VALUE << 8)));
  3721. //
  3722. // Now, write a different Index setting to the Attribute Controller, and
  3723. // see if the Index changes.
  3724. //
  3725. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3726. ATT_ADDRESS_PORT, (UCHAR) (originalACIndex ^ 0x10));
  3727. if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3728. ATT_ADDRESS_PORT) == originalACIndex) {
  3729. //
  3730. // The Index didn't change, so the toggle was in the Data state.
  3731. //
  3732. hardwareStateHeader->AttribIndexDataState = 1;
  3733. //
  3734. // Restore the original Data state; we just corrupted it, and we need
  3735. // to read it out later; also, it may glitch the screen if not
  3736. // corrected. The toggle is already in the Index state.
  3737. //
  3738. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3739. ATT_ADDRESS_PORT, originalACIndex);
  3740. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3741. ATT_DATA_WRITE_PORT, originalACData);
  3742. } else {
  3743. //
  3744. // The Index did change, so the toggle was in the Index state.
  3745. // No need to restore anything, because the Data register didn't
  3746. // change, and we've already read out the Index register.
  3747. //
  3748. hardwareStateHeader->AttribIndexDataState = 0;
  3749. }
  3750. //
  3751. // End sync reset.
  3752. //
  3753. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  3754. SEQ_ADDRESS_PORT),
  3755. (USHORT) (IND_SYNC_RESET + (END_SYNC_RESET_VALUE << 8)));
  3756. //
  3757. // Save the rest of the DAC registers.
  3758. // Set the DAC address port Index, then read out the DAC Data registers.
  3759. // Each three reads get Red, Green, and Blue components for that register.
  3760. //
  3761. // Read them one at a time due to problems on local bus machines.
  3762. //
  3763. for (i = 1; i < VGA_NUM_DAC_ENTRIES; i++) {
  3764. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3765. DAC_ADDRESS_READ_PORT, (UCHAR)i);
  3766. *portValueDAC++ = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3767. DAC_DATA_REG_PORT);
  3768. *portValueDAC++ = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3769. DAC_DATA_REG_PORT);
  3770. *portValueDAC++ = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3771. DAC_DATA_REG_PORT);
  3772. }
  3773. //
  3774. // Is this color or mono ?
  3775. //
  3776. if (bIsColor) {
  3777. port = HwDeviceExtension->IOAddress + INPUT_STATUS_1_COLOR;
  3778. } else {
  3779. port = HwDeviceExtension->IOAddress + INPUT_STATUS_1_MONO;
  3780. }
  3781. //
  3782. // The Feature Control register is read from 3CA but written at 3BA/3DA.
  3783. //
  3784. if (bIsColor) {
  3785. hardwareStateHeader->PortValue[FEAT_CTRL_WRITE_PORT_COLOR-VGA_BASE_IO_PORT] =
  3786. VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3787. FEAT_CTRL_READ_PORT);
  3788. } else {
  3789. hardwareStateHeader->PortValue[FEAT_CTRL_WRITE_PORT_MONO-VGA_BASE_IO_PORT] =
  3790. VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3791. FEAT_CTRL_READ_PORT);
  3792. }
  3793. //
  3794. // CRT Controller Index.
  3795. //
  3796. if (bIsColor) {
  3797. hardwareStateHeader->PortValue[CRTC_ADDRESS_PORT_COLOR-VGA_BASE_IO_PORT] =
  3798. VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3799. CRTC_ADDRESS_PORT_COLOR);
  3800. } else {
  3801. hardwareStateHeader->PortValue[CRTC_ADDRESS_PORT_MONO-VGA_BASE_IO_PORT] =
  3802. VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3803. CRTC_ADDRESS_PORT_MONO);
  3804. }
  3805. //
  3806. // Graphics Controller Index.
  3807. //
  3808. hardwareStateHeader->PortValue[GRAPH_ADDRESS_PORT-VGA_BASE_IO_PORT] =
  3809. VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3810. GRAPH_ADDRESS_PORT);
  3811. //
  3812. // Sequencer indexed registers.
  3813. //
  3814. portValue = ((PUCHAR) hardwareStateHeader) + VGA_BASIC_SEQUENCER_OFFSET;
  3815. for (i = 0; i < VGA_NUM_SEQUENCER_PORTS; i++) {
  3816. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3817. SEQ_ADDRESS_PORT, (UCHAR)i);
  3818. *portValue++ = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3819. SEQ_DATA_PORT);
  3820. }
  3821. //
  3822. // Save extended sequencer registers.
  3823. //
  3824. #ifdef EXTENDED_REGISTER_SAVE_RESTORE
  3825. portValue = ((PUCHAR) hardwareStateHeader) + VGA_EXT_SEQUENCER_OFFSET;
  3826. if ((HwDeviceExtension->ChipType != CL6410) &&
  3827. (HwDeviceExtension->ChipType != CL6420))
  3828. {
  3829. //
  3830. // No extended sequencer registers for the CL64xx
  3831. //
  3832. for (i = CL542x_SEQUENCER_EXT_START;
  3833. i <= CL542x_SEQUENCER_EXT_END;
  3834. i++) {
  3835. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3836. SEQ_ADDRESS_PORT, (UCHAR)i);
  3837. *portValue++ = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3838. SEQ_DATA_PORT);
  3839. }
  3840. }
  3841. #endif
  3842. //
  3843. // CRT Controller indexed registers.
  3844. //
  3845. //
  3846. // Remember the state of CRTC register 3, then force bit 7
  3847. // to 1 so we will read back the Vertical Retrace start and
  3848. // end registers rather than the light pen info.
  3849. //
  3850. if (bIsColor) {
  3851. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3852. CRTC_ADDRESS_PORT_COLOR, 3);
  3853. ucCRTC03 = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3854. CRTC_DATA_PORT_COLOR);
  3855. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3856. CRTC_DATA_PORT_COLOR, (UCHAR) (ucCRTC03 | 0x80));
  3857. } else {
  3858. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3859. CRTC_ADDRESS_PORT_MONO, 3);
  3860. ucCRTC03 = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3861. CRTC_DATA_PORT_MONO);
  3862. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3863. CRTC_DATA_PORT_MONO, (UCHAR) (ucCRTC03 | 0x80));
  3864. }
  3865. portValue = (PUCHAR) hardwareStateHeader + VGA_BASIC_CRTC_OFFSET;
  3866. for (i = 0; i < VGA_NUM_CRTC_PORTS; i++) {
  3867. if (bIsColor) {
  3868. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3869. CRTC_ADDRESS_PORT_COLOR, (UCHAR)i);
  3870. *portValue++ =
  3871. VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3872. CRTC_DATA_PORT_COLOR);
  3873. }
  3874. else {
  3875. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3876. CRTC_ADDRESS_PORT_MONO, (UCHAR)i);
  3877. *portValue++ =
  3878. VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3879. CRTC_DATA_PORT_MONO);
  3880. }
  3881. }
  3882. portValue = (PUCHAR) hardwareStateHeader + VGA_BASIC_CRTC_OFFSET;
  3883. portValue[3] = ucCRTC03;
  3884. //
  3885. // Save extended crtc registers.
  3886. //
  3887. #ifdef EXTENDED_REGISTER_SAVE_RESTORE
  3888. portValue = (PUCHAR) hardwareStateHeader + VGA_EXT_CRTC_OFFSET;
  3889. if ((HwDeviceExtension->ChipType != CL6410) &&
  3890. (HwDeviceExtension->ChipType != CL6420))
  3891. {
  3892. //
  3893. // No CRTC Extensions in CL64xx chipset
  3894. //
  3895. for (i = CL542x_CRTC_EXT_START; i <= CL542x_CRTC_EXT_END; i++) {
  3896. if (bIsColor) {
  3897. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3898. CRTC_ADDRESS_PORT_COLOR, (UCHAR)i);
  3899. *portValue++ =
  3900. VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3901. CRTC_DATA_PORT_COLOR);
  3902. } else {
  3903. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3904. CRTC_ADDRESS_PORT_MONO, (UCHAR)i);
  3905. *portValue++ =
  3906. VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3907. CRTC_DATA_PORT_MONO);
  3908. }
  3909. }
  3910. }
  3911. /* myf2, crus
  3912. if (HwDeviceExtension->ChipType & CL755x)
  3913. {
  3914. for (i = 0x81; i <= 0x91; i++)
  3915. {
  3916. if (bIsColor)
  3917. {
  3918. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3919. CRTC_ADDRESS_PORT_COLOR, (UCHAR)i);
  3920. *portValue++ =
  3921. VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3922. CRTC_DATA_PORT_COLOR);
  3923. } else {
  3924. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3925. CRTC_ADDRESS_PORT_MONO, (UCHAR)i);
  3926. *portValue++ =
  3927. VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3928. CRTC_DATA_PORT_MONO);
  3929. }
  3930. }
  3931. }
  3932. crus, myf2 */
  3933. //if ((HwDeviceExtension->ChipType & CL754x) || //myf32
  3934. // (HwDeviceExtension->ChipType & CL755x) || //myf32
  3935. // (HwDeviceExtension->ChipType == CL756x)) {
  3936. // {
  3937. // NordicSaveRegs(HwDeviceExtension,
  3938. // (PUSHORT)hardwareStateHeader + sizeof(NORDIC_REG_SAVE_BUF));
  3939. // }
  3940. #endif
  3941. //
  3942. // Graphics Controller indexed registers.
  3943. //
  3944. portValue = (PUCHAR) hardwareStateHeader + VGA_BASIC_GRAPH_CONT_OFFSET;
  3945. for (i = 0; i < VGA_NUM_GRAPH_CONT_PORTS; i++) {
  3946. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3947. GRAPH_ADDRESS_PORT, (UCHAR)i);
  3948. *portValue++ = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3949. GRAPH_DATA_PORT);
  3950. }
  3951. //
  3952. // Save extended graphics controller registers.
  3953. //
  3954. #ifdef EXTENDED_REGISTER_SAVE_RESTORE
  3955. portValue = (PUCHAR) hardwareStateHeader + VGA_EXT_GRAPH_CONT_OFFSET;
  3956. if ((HwDeviceExtension->ChipType != CL6410) &&
  3957. (HwDeviceExtension->ChipType != CL6420))
  3958. {
  3959. for (i = CL542x_GRAPH_EXT_START; i <= CL542x_GRAPH_EXT_END; i++) {
  3960. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3961. GRAPH_ADDRESS_PORT, (UCHAR)i);
  3962. *portValue++ = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3963. GRAPH_DATA_PORT);
  3964. }
  3965. } else { // must be a CL64xx
  3966. for (i = CL64xx_GRAPH_EXT_START; i <= CL64xx_GRAPH_EXT_END; i++) {
  3967. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3968. GRAPH_ADDRESS_PORT, (UCHAR)i);
  3969. *portValue++ = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3970. GRAPH_DATA_PORT);
  3971. }
  3972. }
  3973. #endif
  3974. //
  3975. // Attribute Controller indexed registers.
  3976. //
  3977. portValue = (PUCHAR) hardwareStateHeader + VGA_BASIC_ATTRIB_CONT_OFFSET;
  3978. //
  3979. // For each indexed AC register, reset the flip-flop for reading the
  3980. // attribute register, then write the desired index to the AC Index,
  3981. // then read the value of the indexed register from the AC Data register.
  3982. //
  3983. for (i = 0; i < VGA_NUM_ATTRIB_CONT_PORTS; i++) {
  3984. if (bIsColor) {
  3985. dummy = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3986. INPUT_STATUS_1_COLOR);
  3987. } else {
  3988. dummy = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3989. INPUT_STATUS_1_MONO);
  3990. }
  3991. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  3992. ATT_ADDRESS_PORT, (UCHAR)i);
  3993. *portValue++ = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  3994. ATT_DATA_READ_PORT);
  3995. }
  3996. //
  3997. // Save the latches. This destroys one byte of display memory in each
  3998. // plane, which is unfortunate but unavoidable. Chips that provide
  3999. // a way to read back the latches can avoid this problem.
  4000. //
  4001. // Set up the VGA's hardware so we can write the latches, then read them
  4002. // back.
  4003. //
  4004. //
  4005. // Begin sync reset.
  4006. //
  4007. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  4008. SEQ_ADDRESS_PORT),
  4009. (USHORT) (IND_SYNC_RESET + (START_SYNC_RESET_VALUE << 8)));
  4010. //
  4011. // Set the Miscellaneous register to make sure we can access video RAM.
  4012. //
  4013. portIO = MISC_OUTPUT_REG_WRITE_PORT ;
  4014. value = (UCHAR) (hardwareStateHeader->
  4015. PortValue[MISC_OUTPUT_REG_WRITE_PORT-VGA_BASE_IO_PORT] |
  4016. 0x02) ;
  4017. IOWaitDisplEnableThenWrite ( HwDeviceExtension,
  4018. portIO,
  4019. value ) ;
  4020. //
  4021. // Turn off Chain mode and map display memory at A0000 for 64K.
  4022. //
  4023. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  4024. GRAPH_ADDRESS_PORT, IND_GRAPH_MISC);
  4025. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  4026. GRAPH_DATA_PORT,
  4027. (UCHAR) ((VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  4028. GRAPH_DATA_PORT) & 0xF1) | 0x04));
  4029. //
  4030. // Turn off Chain4 mode and odd/even.
  4031. //
  4032. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  4033. SEQ_ADDRESS_PORT, IND_MEMORY_MODE);
  4034. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  4035. SEQ_DATA_PORT,
  4036. (UCHAR) ((VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  4037. SEQ_DATA_PORT) & 0xF3) | 0x04));
  4038. //
  4039. // End sync reset.
  4040. //
  4041. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  4042. SEQ_ADDRESS_PORT),
  4043. (USHORT) (IND_SYNC_RESET + (END_SYNC_RESET_VALUE << 8)));
  4044. //
  4045. // Set the Map Mask to write to all planes.
  4046. //
  4047. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  4048. SEQ_ADDRESS_PORT), (USHORT) (IND_MAP_MASK + (0x0F << 8)));
  4049. //
  4050. // Set the write mode to 0, the read mode to 0, and turn off odd/even.
  4051. //
  4052. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  4053. GRAPH_ADDRESS_PORT, IND_GRAPH_MODE);
  4054. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  4055. GRAPH_DATA_PORT,
  4056. (UCHAR) ((VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  4057. GRAPH_DATA_PORT) & 0xE4) | 0x01));
  4058. //
  4059. // Point to the last byte of display memory.
  4060. //
  4061. pScreen = (PUCHAR) HwDeviceExtension->VideoMemoryAddress +
  4062. VGA_PLANE_SIZE - 1;
  4063. //
  4064. // Write the latches to the last byte of display memory.
  4065. //
  4066. VideoPortWriteRegisterUchar(pScreen, 0);
  4067. //
  4068. // Cycle through the four planes, reading the latch data from each plane.
  4069. //
  4070. //
  4071. // Point the Graphics Controller Index to the Read Map register.
  4072. //
  4073. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  4074. GRAPH_ADDRESS_PORT, IND_READ_MAP);
  4075. portValue = (PUCHAR) hardwareStateHeader + VGA_BASIC_LATCHES_OFFSET;
  4076. for (i=0; i<4; i++) {
  4077. //
  4078. // Set the Read Map for the current plane.
  4079. //
  4080. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  4081. GRAPH_DATA_PORT, (UCHAR)i);
  4082. //
  4083. // Read the latched data we've written to memory.
  4084. //
  4085. *portValue++ = VideoPortReadRegisterUchar(pScreen);
  4086. }
  4087. //
  4088. // Set the VDM flags
  4089. // We are a standard VGA, and then check if we have unemulated state.
  4090. //
  4091. hardwareStateHeader->VGAStateFlags = 0;
  4092. #ifdef EXTENDED_REGISTER_SAVE_RESTORE
  4093. hardwareStateHeader->VGAStateFlags |= VIDEO_STATE_NON_STANDARD_VGA;
  4094. #endif
  4095. if (HwDeviceExtension->TrappedValidatorCount) {
  4096. hardwareStateHeader->VGAStateFlags |= VIDEO_STATE_UNEMULATED_VGA_STATE;
  4097. //
  4098. // Save the VDM Emulator data
  4099. // No need to save the state of the seuencer port register for our
  4100. // emulated data since it may change when we come back. It will be
  4101. // recomputed.
  4102. //
  4103. hardwareStateHeader->ExtendedValidatorStateOffset = VGA_VALIDATOR_OFFSET;
  4104. VideoPortMoveMemory(((PUCHAR) (hardwareStateHeader)) +
  4105. hardwareStateHeader->ExtendedValidatorStateOffset,
  4106. &(HwDeviceExtension->TrappedValidatorCount),
  4107. VGA_VALIDATOR_AREA_SIZE);
  4108. } else {
  4109. hardwareStateHeader->ExtendedValidatorStateOffset = 0;
  4110. }
  4111. //
  4112. // Set the size of each plane.
  4113. //
  4114. hardwareStateHeader->PlaneLength = VGA_PLANE_SIZE;
  4115. //
  4116. // Store all the offsets for the planes in the structure.
  4117. //
  4118. hardwareStateHeader->Plane1Offset = VGA_PLANE_0_OFFSET;
  4119. hardwareStateHeader->Plane2Offset = VGA_PLANE_1_OFFSET;
  4120. hardwareStateHeader->Plane3Offset = VGA_PLANE_2_OFFSET;
  4121. hardwareStateHeader->Plane4Offset = VGA_PLANE_3_OFFSET;
  4122. //
  4123. // Now copy the contents of video VRAM into the buffer.
  4124. //
  4125. // The VGA hardware is already set up so that video memory is readable;
  4126. // we already turned off Chain mode, mapped in at A0000, turned off Chain4,
  4127. // turned off odd/even, and set read mode 0 when we saved the latches.
  4128. //
  4129. // Point the Graphics Controller Index to the Read Map register.
  4130. //
  4131. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  4132. GRAPH_ADDRESS_PORT, IND_READ_MAP);
  4133. //
  4134. // Point to the save area for the first plane.
  4135. //
  4136. bufferPointer = ((PUCHAR) (hardwareStateHeader)) +
  4137. hardwareStateHeader->Plane1Offset;
  4138. //
  4139. // Save the four planes consecutively.
  4140. //
  4141. for (i = 0; i < 4; i++) {
  4142. //
  4143. // Set the Read Map to select the plane we want to save next.
  4144. //
  4145. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  4146. GRAPH_DATA_PORT, (UCHAR)i);
  4147. //
  4148. // Copy this plane into the buffer.
  4149. //
  4150. // Some cirrus cards have a bug where DWORD reads from
  4151. // the frame buffer fail. When we restore the video
  4152. // memory, fonts are corrupted.
  4153. //
  4154. #if 1
  4155. {
  4156. int c;
  4157. for (c = 0; c < VGA_PLANE_SIZE / 2; c++)
  4158. {
  4159. ((PUSHORT)bufferPointer)[c] =
  4160. ((PUSHORT)(HwDeviceExtension->VideoMemoryAddress))[c];
  4161. }
  4162. }
  4163. #else
  4164. VideoPortMoveMemory(bufferPointer,
  4165. (PUCHAR) HwDeviceExtension->VideoMemoryAddress,
  4166. VGA_PLANE_SIZE);
  4167. #endif
  4168. //
  4169. // Point to the next plane's save area.
  4170. //
  4171. bufferPointer += VGA_PLANE_SIZE;
  4172. }
  4173. return NO_ERROR;
  4174. } // end VgaSaveHardwareState()
  4175. //---------------------------------------------------------------------------
  4176. VP_STATUS
  4177. VgaGetBankSelectCode(
  4178. PHW_DEVICE_EXTENSION HwDeviceExtension,
  4179. PVIDEO_BANK_SELECT BankSelect,
  4180. ULONG BankSelectSize,
  4181. PULONG OutputSize
  4182. )
  4183. /*++
  4184. Routine Description:
  4185. Returns information needed in order for caller to implement bank
  4186. management.
  4187. Arguments:
  4188. HwDeviceExtension - Pointer to the miniport driver's device extension.
  4189. BankSelect - Pointer to a VIDEO_BANK_SELECT structure in which the bank
  4190. select data will be returned (output buffer).
  4191. BankSelectSize - Length of the output buffer supplied by the user.
  4192. OutputSize - Pointer to a variable in which to return the actual size of
  4193. the data returned in the output buffer.
  4194. Return Value:
  4195. NO_ERROR - information returned successfully
  4196. ERROR_MORE_DATA - output buffer not large enough to hold all info (but
  4197. Size is returned, so caller can tell how large a buffer to allocate)
  4198. ERROR_INSUFFICIENT_BUFFER - output buffer not large enough to return
  4199. any useful data
  4200. ERROR_INVALID_PARAMETER - invalid video mode selection
  4201. --*/
  4202. {
  4203. #ifdef _X86_
  4204. ULONG codeSize;
  4205. ULONG codePlanarSize;
  4206. ULONG codeEnablePlanarSize;
  4207. ULONG codeDisablePlanarSize;
  4208. PUCHAR pCodeDest;
  4209. PUCHAR pCodeBank;
  4210. PUCHAR pCodePlanarBank;
  4211. PUCHAR pCodeEnablePlanar;
  4212. PUCHAR pCodeDisablePlanar;
  4213. ULONG AdapterType = HwDeviceExtension->ChipType;
  4214. PVIDEOMODE pMode = HwDeviceExtension->CurrentMode;
  4215. //
  4216. // check if a mode has been set
  4217. //
  4218. if (HwDeviceExtension->CurrentMode == NULL) {
  4219. return ERROR_INVALID_FUNCTION;
  4220. }
  4221. //
  4222. // The minimum passed buffer size is a VIDEO_BANK_SELECT
  4223. // structure, so that we can return the required size; we can't do
  4224. // anything if we don't have at least that much buffer.
  4225. //
  4226. if (BankSelectSize < sizeof(VIDEO_BANK_SELECT)) {
  4227. return ERROR_INSUFFICIENT_BUFFER;
  4228. }
  4229. //
  4230. // Determine the banking type, and set whether any banking is actually
  4231. // supported in this mode.
  4232. //
  4233. BankSelect->BankingFlags = 0;
  4234. codeSize = 0;
  4235. codePlanarSize = 0;
  4236. pCodeBank = NULL;
  4237. switch(pMode->banktype) {
  4238. case NoBanking:
  4239. BankSelect->BankingType = VideoNotBanked;
  4240. BankSelect->Granularity = 0;
  4241. break;
  4242. case PlanarHCBanking:
  4243. BankSelect->BankingFlags = PLANAR_HC; // planar mode supported
  4244. #if ONE_64K_BANK
  4245. //
  4246. // The Cirrus Logic VGA's support one 64K read/write bank.
  4247. //
  4248. BankSelect->PlanarHCBankingType = VideoBanked1RW;
  4249. BankSelect->PlanarHCGranularity = 0x10000; // 64K bank start adjustment
  4250. // in planar HC mode as well
  4251. #endif
  4252. #if TWO_32K_BANKS
  4253. //
  4254. // The Cirrus Logic VGA's support two 32K read/write banks.
  4255. //
  4256. BankSelect->PlanarHCBankingType = VideoBanked2RW;
  4257. BankSelect->PlanarHCGranularity = 0x8000; // 32K bank start adjustment
  4258. // in planar HC mode as well
  4259. #endif
  4260. // 64K bank start adjustment in planar HC mode as well
  4261. if ((HwDeviceExtension->ChipType != CL6410) &&
  4262. (HwDeviceExtension->ChipType != CL6420))
  4263. {
  4264. if ((HwDeviceExtension->ChipType != CL542x) &&
  4265. (HwDeviceExtension->ChipType != CL6245))
  4266. {
  4267. codePlanarSize = ((ULONG)&CL543xPlanarHCBankSwitchEnd) -
  4268. ((ULONG)&CL543xPlanarHCBankSwitchStart);
  4269. pCodePlanarBank = &CL543xPlanarHCBankSwitchStart;
  4270. }
  4271. else
  4272. {
  4273. codePlanarSize = ((ULONG)&CL542xPlanarHCBankSwitchEnd) -
  4274. ((ULONG)&CL542xPlanarHCBankSwitchStart);
  4275. pCodePlanarBank = &CL542xPlanarHCBankSwitchStart;
  4276. }
  4277. codeEnablePlanarSize = ((ULONG)&CL542xEnablePlanarHCEnd) -
  4278. ((ULONG)&CL542xEnablePlanarHCStart);
  4279. codeDisablePlanarSize = ((ULONG)&CL542xDisablePlanarHCEnd) -
  4280. ((ULONG)&CL542xDisablePlanarHCStart);
  4281. pCodeEnablePlanar = &CL542xEnablePlanarHCStart;
  4282. pCodeDisablePlanar = &CL542xDisablePlanarHCStart;
  4283. }
  4284. else
  4285. { // must be a CL64xx product
  4286. codePlanarSize = ((ULONG)&CL64xxPlanarHCBankSwitchEnd) -
  4287. ((ULONG)&CL64xxPlanarHCBankSwitchStart);
  4288. codeEnablePlanarSize = ((ULONG)&CL64xxEnablePlanarHCEnd) -
  4289. ((ULONG)&CL64xxEnablePlanarHCStart);
  4290. codeDisablePlanarSize = ((ULONG)&CL64xxDisablePlanarHCEnd) -
  4291. ((ULONG)&CL64xxDisablePlanarHCStart);
  4292. pCodePlanarBank = &CL64xxPlanarHCBankSwitchStart;
  4293. pCodeEnablePlanar = &CL64xxEnablePlanarHCStart;
  4294. pCodeDisablePlanar = &CL64xxDisablePlanarHCStart;
  4295. }
  4296. //
  4297. // Fall through to the normal banking case
  4298. //
  4299. case NormalBanking:
  4300. #if ONE_64K_BANK
  4301. //
  4302. // The Cirrus Logic VGA's support one 64K read/write bank.
  4303. //
  4304. BankSelect->BankingType = VideoBanked1RW;
  4305. BankSelect->Granularity = 0x10000;
  4306. #endif
  4307. #if TWO_32K_BANKS
  4308. //
  4309. // The Cirrus Logic VGA's support two 32K read/write banks.
  4310. //
  4311. BankSelect->BankingType = VideoBanked2RW;
  4312. BankSelect->Granularity = 0x8000;
  4313. #endif
  4314. if ((AdapterType == CL542x) ||
  4315. (AdapterType == CL6245))
  4316. {
  4317. codeSize = ((ULONG)&CL542xBankSwitchEnd) -
  4318. ((ULONG)&CL542xBankSwitchStart);
  4319. pCodeBank = &CL542xBankSwitchStart;
  4320. }
  4321. else if ((AdapterType == CL6410) ||
  4322. (AdapterType == CL6420))
  4323. {
  4324. codeSize = ((ULONG)&CL64xxBankSwitchEnd) -
  4325. ((ULONG)&CL64xxBankSwitchStart);
  4326. pCodeBank = &CL64xxBankSwitchStart;
  4327. }
  4328. else
  4329. {
  4330. codeSize = ((ULONG)&CL543xBankSwitchEnd) -
  4331. ((ULONG)&CL543xBankSwitchStart);
  4332. pCodeBank = &CL543xBankSwitchStart;
  4333. }
  4334. break;
  4335. }
  4336. //
  4337. // Size of banking info.
  4338. //
  4339. BankSelect->Size = sizeof(VIDEO_BANK_SELECT) + codeSize;
  4340. if (BankSelect->BankingFlags & PLANAR_HC) {
  4341. BankSelect->Size += codePlanarSize + codeEnablePlanarSize +
  4342. codeDisablePlanarSize;
  4343. }
  4344. //
  4345. // This serves an a ID for the version of the structure we're using.
  4346. //
  4347. BankSelect->Length = sizeof(VIDEO_BANK_SELECT);
  4348. //
  4349. // If the buffer isn't big enough to hold all info, just return
  4350. // ERROR_MORE_DATA; Size is already set.
  4351. //
  4352. if (BankSelectSize < BankSelect->Size ) {
  4353. //
  4354. // We're returning only the VIDEO_BANK_SELECT structure.
  4355. //
  4356. *OutputSize = sizeof(VIDEO_BANK_SELECT);
  4357. return ERROR_MORE_DATA;
  4358. }
  4359. //
  4360. // There's room enough for everything, so fill in all fields in
  4361. // VIDEO_BANK_SELECT. (All fields are always returned; the caller can
  4362. // just choose to ignore them, based on BankingFlags and BankingType.)
  4363. //
  4364. BankSelect->BitmapWidthInBytes = pMode->wbytes;
  4365. BankSelect->BitmapSize = pMode->sbytes;
  4366. //
  4367. // Copy all banking code into the output buffer.
  4368. //
  4369. pCodeDest = (PUCHAR)BankSelect + sizeof(VIDEO_BANK_SELECT);
  4370. if (pCodeBank != NULL) {
  4371. BankSelect->CodeOffset = pCodeDest - (PUCHAR)BankSelect;
  4372. VideoPortMoveMemory(pCodeDest,
  4373. pCodeBank,
  4374. codeSize);
  4375. pCodeDest += codeSize;
  4376. }
  4377. if (BankSelect->BankingFlags & PLANAR_HC) {
  4378. //
  4379. // Copy appropriate high-color planar Bank Switch code:
  4380. //
  4381. BankSelect->PlanarHCBankCodeOffset = pCodeDest - (PUCHAR)BankSelect;
  4382. VideoPortMoveMemory(pCodeDest,
  4383. pCodePlanarBank,
  4384. codePlanarSize);
  4385. pCodeDest += codePlanarSize;
  4386. //
  4387. // Copy high-color planar bank mode Enable code:
  4388. //
  4389. BankSelect->PlanarHCEnableCodeOffset = pCodeDest - (PUCHAR)BankSelect;
  4390. VideoPortMoveMemory(pCodeDest,
  4391. pCodeEnablePlanar,
  4392. codeEnablePlanarSize);
  4393. pCodeDest += codeEnablePlanarSize;
  4394. //
  4395. // Copy high-color planar bank mode Disable code:
  4396. //
  4397. BankSelect->PlanarHCDisableCodeOffset = pCodeDest - (PUCHAR)BankSelect;
  4398. VideoPortMoveMemory(pCodeDest,
  4399. pCodeDisablePlanar,
  4400. codeDisablePlanarSize);
  4401. }
  4402. //
  4403. // Number of bytes we're returning is the full banking info size.
  4404. //
  4405. *OutputSize = BankSelect->Size;
  4406. return NO_ERROR;
  4407. #else
  4408. //
  4409. // This function is only defined for x86
  4410. //
  4411. return ERROR_INVALID_FUNCTION;
  4412. #endif
  4413. } // end VgaGetBankSelectCode()
  4414. //---------------------------------------------------------------------------
  4415. VP_STATUS
  4416. VgaValidatorUcharEntry(
  4417. ULONG_PTR Context,
  4418. ULONG Port,
  4419. UCHAR AccessMode,
  4420. PUCHAR Data
  4421. )
  4422. /*++
  4423. Routine Description:
  4424. Entry point into the validator for byte I/O operations.
  4425. The entry point will be called whenever a byte operation was performed
  4426. by a DOS application on one of the specified Video ports. The kernel
  4427. emulator will forward these requests.
  4428. Arguments:
  4429. Context - Context value that is passed to each call made to the validator
  4430. function. This is the value the miniport driver specified in the
  4431. MiniportConfigInfo->EmulatorAccessEntriesContext.
  4432. Port - Port on which the operation is to be performed.
  4433. AccessMode - Determines if it is a read or write operation.
  4434. Data - Pointer to a variable containing the data to be written or a
  4435. variable into which the read data should be stored.
  4436. Return Value:
  4437. NO_ERROR.
  4438. --*/
  4439. {
  4440. PHW_DEVICE_EXTENSION hwDeviceExtension = (PHW_DEVICE_EXTENSION) Context;
  4441. PHW_DEVICE_EXTENSION HwDeviceExtension = (PHW_DEVICE_EXTENSION) Context;
  4442. ULONG endEmulation;
  4443. UCHAR temp;
  4444. UCHAR tempB ;
  4445. ULONG portIO ;
  4446. if (hwDeviceExtension->TrappedValidatorCount) {
  4447. //
  4448. // If we are processing a WRITE instruction, then store it in the
  4449. // playback buffer. If the buffer is full, then play it back right
  4450. // away, end sync reset and reinitialize the buffer with a sync
  4451. // reset instruction.
  4452. //
  4453. // If we have a READ, we must flush the buffer (which has the side
  4454. // effect of starting SyncReset), perform the read operation, stop
  4455. // sync reset, and put back a sync reset instruction in the buffer
  4456. // so we can go on appropriately
  4457. //
  4458. if (AccessMode & EMULATOR_WRITE_ACCESS) {
  4459. //
  4460. // Make sure Bit 3 of the Miscellaneous register is always 0.
  4461. // If it is 1 it could select a non-existent clock, and kill the
  4462. // system
  4463. //
  4464. if (Port == MISC_OUTPUT_REG_WRITE_PORT) {
  4465. *Data &= 0xF7;
  4466. }
  4467. hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
  4468. TrappedValidatorCount].Port = Port;
  4469. hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
  4470. TrappedValidatorCount].AccessType = VGA_VALIDATOR_UCHAR_ACCESS;
  4471. hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
  4472. TrappedValidatorCount].Data = *Data;
  4473. hwDeviceExtension->TrappedValidatorCount++;
  4474. //
  4475. // Check to see if this instruction was ending sync reset.
  4476. // If it did, we must flush the buffer and reset the trapped
  4477. // IO ports to the minimal set.
  4478. //
  4479. if ( (Port == SEQ_DATA_PORT) &&
  4480. ((*Data & END_SYNC_RESET_VALUE) == END_SYNC_RESET_VALUE) &&
  4481. (hwDeviceExtension->SequencerAddressValue == IND_SYNC_RESET)) {
  4482. endEmulation = 1;
  4483. } else {
  4484. //
  4485. // If we are accessing the seq address port, keep track of the
  4486. // data value
  4487. //
  4488. if (Port == SEQ_ADDRESS_PORT) {
  4489. hwDeviceExtension->SequencerAddressValue = *Data;
  4490. }
  4491. //
  4492. // If the buffer is not full, then just return right away.
  4493. //
  4494. if (hwDeviceExtension->TrappedValidatorCount <
  4495. VGA_MAX_VALIDATOR_DATA - 1) {
  4496. return NO_ERROR;
  4497. }
  4498. endEmulation = 0;
  4499. }
  4500. }
  4501. //
  4502. // We are either in a READ path or a WRITE path that caused a
  4503. // a full buffer. So flush the buffer either way.
  4504. //
  4505. // To do this put an END_SYNC_RESET at the end since we want to make
  4506. // the buffer is ended sync reset ended.
  4507. //
  4508. hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
  4509. TrappedValidatorCount].Port = SEQ_ADDRESS_PORT;
  4510. hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
  4511. TrappedValidatorCount].AccessType = VGA_VALIDATOR_USHORT_ACCESS;
  4512. hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
  4513. TrappedValidatorCount].Data = (USHORT) (IND_SYNC_RESET +
  4514. (END_SYNC_RESET_VALUE << 8));
  4515. hwDeviceExtension->TrappedValidatorCount++;
  4516. VideoPortSynchronizeExecution(hwDeviceExtension,
  4517. VpHighPriority,
  4518. (PMINIPORT_SYNCHRONIZE_ROUTINE)
  4519. VgaPlaybackValidatorData,
  4520. hwDeviceExtension);
  4521. //
  4522. // Write back the real value of the sequencer address port.
  4523. //
  4524. VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
  4525. SEQ_ADDRESS_PORT,
  4526. (UCHAR) hwDeviceExtension->SequencerAddressValue);
  4527. //
  4528. // If we are in a READ path, read the data
  4529. //
  4530. if (AccessMode & EMULATOR_READ_ACCESS) {
  4531. *Data = VideoPortReadPortUchar(hwDeviceExtension->IOAddress + Port);
  4532. endEmulation = 0;
  4533. }
  4534. //
  4535. // If we are ending emulation, reset trapping to the minimal amount
  4536. // and exit.
  4537. //
  4538. if (endEmulation) {
  4539. VideoPortSetTrappedEmulatorPorts(hwDeviceExtension,
  4540. NUM_MINIMAL_VGA_VALIDATOR_ACCESS_RANGE,
  4541. MinimalVgaValidatorAccessRange);
  4542. return NO_ERROR;
  4543. }
  4544. //
  4545. // For both cases, put back a START_SYNC_RESET in the buffer.
  4546. //
  4547. hwDeviceExtension->TrappedValidatorCount = 1;
  4548. hwDeviceExtension->TrappedValidatorData[0].Port = SEQ_ADDRESS_PORT;
  4549. hwDeviceExtension->TrappedValidatorData[0].AccessType =
  4550. VGA_VALIDATOR_USHORT_ACCESS;
  4551. hwDeviceExtension->TrappedValidatorData[0].Data =
  4552. (ULONG) (IND_SYNC_RESET + (START_SYNC_RESET_VALUE << 8));
  4553. } else {
  4554. //
  4555. // Nothing trapped.
  4556. // Lets check is the IO is trying to do something that would require
  4557. // us to stop trapping
  4558. //
  4559. if (AccessMode & EMULATOR_WRITE_ACCESS) {
  4560. //
  4561. // Make sure Bit 3 of the Miscelaneous register is always 0.
  4562. // If it is 1 it could select a non-existant clock, and kill the
  4563. // system
  4564. //
  4565. if (Port == MISC_OUTPUT_REG_WRITE_PORT) {
  4566. temp = VideoPortReadPortUchar(hwDeviceExtension->IOAddress +
  4567. SEQ_ADDRESS_PORT);
  4568. VideoPortWritePortUshort((PUSHORT) (hwDeviceExtension->IOAddress +
  4569. SEQ_ADDRESS_PORT),
  4570. (USHORT) (IND_SYNC_RESET +
  4571. (START_SYNC_RESET_VALUE << 8)));
  4572. tempB = (UCHAR) (*Data & 0xF7) ;
  4573. portIO = Port ;
  4574. IOWaitDisplEnableThenWrite ( hwDeviceExtension,
  4575. portIO,
  4576. tempB ) ;
  4577. VideoPortWritePortUshort((PUSHORT) (hwDeviceExtension->IOAddress +
  4578. SEQ_ADDRESS_PORT),
  4579. (USHORT) (IND_SYNC_RESET +
  4580. (END_SYNC_RESET_VALUE << 8)));
  4581. VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
  4582. SEQ_ADDRESS_PORT,
  4583. temp);
  4584. return NO_ERROR;
  4585. }
  4586. //
  4587. // If we get an access to the sequencer register, start trapping.
  4588. //
  4589. if ( (Port == SEQ_DATA_PORT) &&
  4590. ((*Data & END_SYNC_RESET_VALUE) != END_SYNC_RESET_VALUE) &&
  4591. (VideoPortReadPortUchar(hwDeviceExtension->IOAddress +
  4592. SEQ_ADDRESS_PORT) == IND_SYNC_RESET)) {
  4593. VideoPortSetTrappedEmulatorPorts(hwDeviceExtension,
  4594. NUM_FULL_VGA_VALIDATOR_ACCESS_RANGE,
  4595. FullVgaValidatorAccessRange);
  4596. hwDeviceExtension->TrappedValidatorCount = 1;
  4597. hwDeviceExtension->TrappedValidatorData[0].Port = Port;
  4598. hwDeviceExtension->TrappedValidatorData[0].AccessType =
  4599. VGA_VALIDATOR_UCHAR_ACCESS;
  4600. hwDeviceExtension->TrappedValidatorData[0].Data = *Data;
  4601. //
  4602. // Start keeping track of the state of the sequencer port.
  4603. //
  4604. hwDeviceExtension->SequencerAddressValue = IND_SYNC_RESET;
  4605. } else {
  4606. VideoPortWritePortUchar(hwDeviceExtension->IOAddress + Port,
  4607. *Data);
  4608. }
  4609. } else {
  4610. *Data = VideoPortReadPortUchar(hwDeviceExtension->IOAddress + Port);
  4611. }
  4612. }
  4613. return NO_ERROR;
  4614. } // end VgaValidatorUcharEntry()
  4615. //---------------------------------------------------------------------------
  4616. VP_STATUS
  4617. VgaValidatorUshortEntry(
  4618. ULONG_PTR Context,
  4619. ULONG Port,
  4620. UCHAR AccessMode,
  4621. PUSHORT Data
  4622. )
  4623. /*++
  4624. Routine Description:
  4625. Entry point into the validator for word I/O operations.
  4626. The entry point will be called whenever a byte operation was performed
  4627. by a DOS application on one of the specified Video ports. The kernel
  4628. emulator will forward these requests.
  4629. Arguments:
  4630. Context - Context value that is passed to each call made to the validator
  4631. function. This is the value the miniport driver specified in the
  4632. MiniportConfigInfo->EmulatorAccessEntriesContext.
  4633. Port - Port on which the operation is to be performed.
  4634. AccessMode - Determines if it is a read or write operation.
  4635. Data - Pointer to a variable containing the data to be written or a
  4636. variable into which the read data should be stored.
  4637. Return Value:
  4638. NO_ERROR.
  4639. --*/
  4640. {
  4641. PHW_DEVICE_EXTENSION hwDeviceExtension = (PHW_DEVICE_EXTENSION) Context;
  4642. PHW_DEVICE_EXTENSION HwDeviceExtension = (PHW_DEVICE_EXTENSION) Context;
  4643. ULONG endEmulation;
  4644. UCHAR temp;
  4645. UCHAR tempB ;
  4646. if (hwDeviceExtension->TrappedValidatorCount) {
  4647. //
  4648. // If we are processing a WRITE instruction, then store it in the
  4649. // playback buffer. If the buffer is full, then play it back right
  4650. // away, end sync reset and reinitialize the buffer with a sync
  4651. // reset instruction.
  4652. //
  4653. // If we have a READ, we must flush the buffer (which has the side
  4654. // effect of starting SyncReset), perform the read operation, stop
  4655. // sync reset, and put back a sync reset instruction in the buffer
  4656. // so we can go on appropriately
  4657. //
  4658. if (AccessMode & EMULATOR_WRITE_ACCESS) {
  4659. //
  4660. // Make sure Bit 3 of the Miscellaneous register is always 0.
  4661. // If it is 1 it could select a non-existent clock, and kill the
  4662. // system
  4663. //
  4664. if (Port == MISC_OUTPUT_REG_WRITE_PORT) {
  4665. *Data &= 0xFFF7;
  4666. }
  4667. hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
  4668. TrappedValidatorCount].Port = Port;
  4669. hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
  4670. TrappedValidatorCount].AccessType = VGA_VALIDATOR_USHORT_ACCESS;
  4671. hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
  4672. TrappedValidatorCount].Data = *Data;
  4673. hwDeviceExtension->TrappedValidatorCount++;
  4674. //
  4675. // Check to see if this instruction was ending sync reset.
  4676. // If it did, we must flush the buffer and reset the trapped
  4677. // IO ports to the minimal set.
  4678. //
  4679. if (Port == SEQ_ADDRESS_PORT) {
  4680. //
  4681. // If we are accessing the seq address port, keep track of its
  4682. // value
  4683. //
  4684. hwDeviceExtension->SequencerAddressValue = (*Data & 0xFF);
  4685. }
  4686. if ((Port == SEQ_ADDRESS_PORT) &&
  4687. ( ((*Data >> 8) & END_SYNC_RESET_VALUE) ==
  4688. END_SYNC_RESET_VALUE) &&
  4689. (hwDeviceExtension->SequencerAddressValue == IND_SYNC_RESET)) {
  4690. endEmulation = 1;
  4691. } else {
  4692. //
  4693. // If the buffer is not full, then just return right away.
  4694. //
  4695. if (hwDeviceExtension->TrappedValidatorCount <
  4696. VGA_MAX_VALIDATOR_DATA - 1) {
  4697. return NO_ERROR;
  4698. }
  4699. endEmulation = 0;
  4700. }
  4701. }
  4702. //
  4703. // We are either in a READ path or a WRITE path that caused a
  4704. // a full buffer. So flush the buffer either way.
  4705. //
  4706. // To do this put an END_SYNC_RESET at the end since we want to make
  4707. // the buffer is ended sync reset ended.
  4708. //
  4709. hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
  4710. TrappedValidatorCount].Port = SEQ_ADDRESS_PORT;
  4711. hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
  4712. TrappedValidatorCount].AccessType = VGA_VALIDATOR_USHORT_ACCESS;
  4713. hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
  4714. TrappedValidatorCount].Data = (USHORT) (IND_SYNC_RESET +
  4715. (END_SYNC_RESET_VALUE << 8));
  4716. hwDeviceExtension->TrappedValidatorCount++;
  4717. VideoPortSynchronizeExecution(hwDeviceExtension,
  4718. VpHighPriority,
  4719. (PMINIPORT_SYNCHRONIZE_ROUTINE)
  4720. VgaPlaybackValidatorData,
  4721. hwDeviceExtension);
  4722. //
  4723. // Write back the real value of the sequencer address port.
  4724. //
  4725. VideoPortWritePortUchar((PUCHAR) (hwDeviceExtension->IOAddress +
  4726. SEQ_ADDRESS_PORT),
  4727. (UCHAR) hwDeviceExtension->SequencerAddressValue);
  4728. //
  4729. // If we are in a READ path, read the data
  4730. //
  4731. if (AccessMode & EMULATOR_READ_ACCESS) {
  4732. *Data = VideoPortReadPortUshort((PUSHORT)(hwDeviceExtension->IOAddress
  4733. + Port));
  4734. endEmulation = 0;
  4735. }
  4736. //
  4737. // If we are ending emulation, reset trapping to the minimal amount
  4738. // and exit.
  4739. //
  4740. if (endEmulation) {
  4741. VideoPortSetTrappedEmulatorPorts(hwDeviceExtension,
  4742. NUM_MINIMAL_VGA_VALIDATOR_ACCESS_RANGE,
  4743. MinimalVgaValidatorAccessRange);
  4744. return NO_ERROR;
  4745. }
  4746. //
  4747. // For both cases, put back a START_SYNC_RESET in the buffer.
  4748. //
  4749. hwDeviceExtension->TrappedValidatorCount = 1;
  4750. hwDeviceExtension->TrappedValidatorData[0].Port = SEQ_ADDRESS_PORT;
  4751. hwDeviceExtension->TrappedValidatorData[0].AccessType =
  4752. VGA_VALIDATOR_USHORT_ACCESS;
  4753. hwDeviceExtension->TrappedValidatorData[0].Data =
  4754. (ULONG) (IND_SYNC_RESET + (START_SYNC_RESET_VALUE << 8));
  4755. } else {
  4756. //
  4757. // Nothing trapped.
  4758. // Lets check is the IO is trying to do something that would require
  4759. // us to stop trapping
  4760. //
  4761. if (AccessMode & EMULATOR_WRITE_ACCESS) {
  4762. //
  4763. // Make sure Bit 3 of the Miscelaneous register is always 0.
  4764. // If it is 1 it could select a non-existant clock, and kill the
  4765. // system
  4766. //
  4767. if (Port == MISC_OUTPUT_REG_WRITE_PORT) {
  4768. temp = VideoPortReadPortUchar(hwDeviceExtension->IOAddress +
  4769. SEQ_ADDRESS_PORT);
  4770. VideoPortWritePortUshort((PUSHORT) (hwDeviceExtension->IOAddress +
  4771. SEQ_ADDRESS_PORT),
  4772. (USHORT) (IND_SYNC_RESET +
  4773. (START_SYNC_RESET_VALUE << 8)));
  4774. VideoPortWritePortUshort((PUSHORT) (hwDeviceExtension->IOAddress +
  4775. (ULONG)Port),
  4776. (USHORT) (*Data & 0xFFF7) );
  4777. VideoPortWritePortUshort((PUSHORT) (hwDeviceExtension->IOAddress +
  4778. SEQ_ADDRESS_PORT),
  4779. (USHORT) (IND_SYNC_RESET +
  4780. (END_SYNC_RESET_VALUE << 8)));
  4781. VideoPortWritePortUchar(hwDeviceExtension->IOAddress + SEQ_ADDRESS_PORT,
  4782. temp);
  4783. return NO_ERROR;
  4784. }
  4785. if ( (Port == SEQ_ADDRESS_PORT) &&
  4786. (((*Data>> 8) & END_SYNC_RESET_VALUE) != END_SYNC_RESET_VALUE) &&
  4787. ((*Data & 0xFF) == IND_SYNC_RESET)) {
  4788. VideoPortSetTrappedEmulatorPorts(hwDeviceExtension,
  4789. NUM_FULL_VGA_VALIDATOR_ACCESS_RANGE,
  4790. FullVgaValidatorAccessRange);
  4791. hwDeviceExtension->TrappedValidatorCount = 1;
  4792. hwDeviceExtension->TrappedValidatorData[0].Port = Port;
  4793. hwDeviceExtension->TrappedValidatorData[0].AccessType =
  4794. VGA_VALIDATOR_USHORT_ACCESS;
  4795. hwDeviceExtension->TrappedValidatorData[0].Data = *Data;
  4796. //
  4797. // Start keeping track of the state of the sequencer port.
  4798. //
  4799. hwDeviceExtension->SequencerAddressValue = IND_SYNC_RESET;
  4800. } else {
  4801. VideoPortWritePortUshort((PUSHORT)(hwDeviceExtension->IOAddress +
  4802. Port),
  4803. *Data);
  4804. }
  4805. } else {
  4806. *Data = VideoPortReadPortUshort((PUSHORT)(hwDeviceExtension->IOAddress +
  4807. Port));
  4808. }
  4809. }
  4810. return NO_ERROR;
  4811. } // end VgaValidatorUshortEntry()
  4812. //---------------------------------------------------------------------------
  4813. VP_STATUS
  4814. VgaValidatorUlongEntry(
  4815. ULONG_PTR Context,
  4816. ULONG Port,
  4817. UCHAR AccessMode,
  4818. PULONG Data
  4819. )
  4820. /*++
  4821. Routine Description:
  4822. Entry point into the validator for dword I/O operations.
  4823. The entry point will be called whenever a byte operation was performed
  4824. by a DOS application on one of the specified Video ports. The kernel
  4825. emulator will forward these requests.
  4826. Arguments:
  4827. Context - Context value that is passed to each call made to the validator
  4828. function. This is the value the miniport driver specified in the
  4829. MiniportConfigInfo->EmulatorAccessEntriesContext.
  4830. Port - Port on which the operation is to be performed.
  4831. AccessMode - Determines if it is a read or write operation.
  4832. Data - Pointer to a variable containing the data to be written or a
  4833. variable into which the read data should be stored.
  4834. Return Value:
  4835. NO_ERROR.
  4836. --*/
  4837. {
  4838. PHW_DEVICE_EXTENSION hwDeviceExtension = (PHW_DEVICE_EXTENSION) Context;
  4839. PHW_DEVICE_EXTENSION HwDeviceExtension = (PHW_DEVICE_EXTENSION) Context;
  4840. ULONG endEmulation;
  4841. UCHAR temp;
  4842. if (hwDeviceExtension->TrappedValidatorCount) {
  4843. //
  4844. // If we are processing a WRITE instruction, then store it in the
  4845. // playback buffer. If the buffer is full, then play it back right
  4846. // away, end sync reset and reinitialize the buffer with a sync
  4847. // reset instruction.
  4848. //
  4849. // If we have a READ, we must flush the buffer (which has the side
  4850. // effect of starting SyncReset), perform the read operation, stop
  4851. // sync reset, and put back a sync reset instruction in the buffer
  4852. // so we can go on appropriately
  4853. //
  4854. if (AccessMode & EMULATOR_WRITE_ACCESS) {
  4855. //
  4856. // Make sure Bit 3 of the Miscellaneous register is always 0.
  4857. // If it is 1 it could select a non-existent clock, and kill the
  4858. // system
  4859. //
  4860. if (Port == MISC_OUTPUT_REG_WRITE_PORT) {
  4861. *Data &= 0xFFFFFFF7;
  4862. }
  4863. hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
  4864. TrappedValidatorCount].Port = Port;
  4865. hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
  4866. TrappedValidatorCount].AccessType = VGA_VALIDATOR_ULONG_ACCESS;
  4867. hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
  4868. TrappedValidatorCount].Data = *Data;
  4869. hwDeviceExtension->TrappedValidatorCount++;
  4870. //
  4871. // Check to see if this instruction was ending sync reset.
  4872. // If it did, we must flush the buffer and reset the trapped
  4873. // IO ports to the minimal set.
  4874. //
  4875. if (Port == SEQ_ADDRESS_PORT) {
  4876. //
  4877. // If we are accessing the seq address port, keep track of its
  4878. // value
  4879. //
  4880. hwDeviceExtension->SequencerAddressValue = (*Data & 0xFF);
  4881. }
  4882. if ((Port == SEQ_ADDRESS_PORT) &&
  4883. ( ((*Data >> 8) & END_SYNC_RESET_VALUE) ==
  4884. END_SYNC_RESET_VALUE) &&
  4885. (hwDeviceExtension->SequencerAddressValue == IND_SYNC_RESET)) {
  4886. endEmulation = 1;
  4887. } else {
  4888. //
  4889. // If the buffer is not full, then just return right away.
  4890. //
  4891. if (hwDeviceExtension->TrappedValidatorCount <
  4892. VGA_MAX_VALIDATOR_DATA - 1) {
  4893. return NO_ERROR;
  4894. }
  4895. endEmulation = 0;
  4896. }
  4897. }
  4898. //
  4899. // We are either in a READ path or a WRITE path that caused a
  4900. // a full buffer. So flush the buffer either way.
  4901. //
  4902. // To do this put an END_SYNC_RESET at the end since we want to make
  4903. // the buffer is ended sync reset ended.
  4904. //
  4905. hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
  4906. TrappedValidatorCount].Port = SEQ_ADDRESS_PORT;
  4907. hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
  4908. TrappedValidatorCount].AccessType = VGA_VALIDATOR_USHORT_ACCESS;
  4909. hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
  4910. TrappedValidatorCount].Data = (USHORT) (IND_SYNC_RESET +
  4911. (END_SYNC_RESET_VALUE << 8));
  4912. hwDeviceExtension->TrappedValidatorCount++;
  4913. VideoPortSynchronizeExecution(hwDeviceExtension,
  4914. VpHighPriority,
  4915. (PMINIPORT_SYNCHRONIZE_ROUTINE)
  4916. VgaPlaybackValidatorData,
  4917. hwDeviceExtension);
  4918. //
  4919. // Write back the real value of the sequencer address port.
  4920. //
  4921. VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
  4922. SEQ_ADDRESS_PORT,
  4923. (UCHAR) hwDeviceExtension->SequencerAddressValue);
  4924. //
  4925. // If we are in a READ path, read the data
  4926. //
  4927. if (AccessMode & EMULATOR_READ_ACCESS) {
  4928. *Data = VideoPortReadPortUlong((PULONG) (hwDeviceExtension->IOAddress +
  4929. Port));
  4930. endEmulation = 0;
  4931. }
  4932. //
  4933. // If we are ending emulation, reset trapping to the minimal amount
  4934. // and exit.
  4935. //
  4936. if (endEmulation) {
  4937. VideoPortSetTrappedEmulatorPorts(hwDeviceExtension,
  4938. NUM_MINIMAL_VGA_VALIDATOR_ACCESS_RANGE,
  4939. MinimalVgaValidatorAccessRange);
  4940. return NO_ERROR;
  4941. }
  4942. //
  4943. // For both cases, put back a START_SYNC_RESET in the buffer.
  4944. //
  4945. hwDeviceExtension->TrappedValidatorCount = 1;
  4946. hwDeviceExtension->TrappedValidatorData[0].Port = SEQ_ADDRESS_PORT;
  4947. hwDeviceExtension->TrappedValidatorData[0].AccessType =
  4948. VGA_VALIDATOR_USHORT_ACCESS;
  4949. hwDeviceExtension->TrappedValidatorData[0].Data =
  4950. (ULONG) (IND_SYNC_RESET + (START_SYNC_RESET_VALUE << 8));
  4951. } else {
  4952. //
  4953. // Nothing trapped.
  4954. // Lets check is the IO is trying to do something that would require
  4955. // us to stop trapping
  4956. //
  4957. if (AccessMode & EMULATOR_WRITE_ACCESS) {
  4958. //
  4959. // Make sure Bit 3 of the Miscelaneous register is always 0.
  4960. // If it is 1 it could select a non-existant clock, and kill the
  4961. // system
  4962. //
  4963. if (Port == MISC_OUTPUT_REG_WRITE_PORT) {
  4964. temp = VideoPortReadPortUchar(hwDeviceExtension->IOAddress +
  4965. SEQ_ADDRESS_PORT);
  4966. VideoPortWritePortUshort((PUSHORT) (hwDeviceExtension->IOAddress +
  4967. SEQ_ADDRESS_PORT),
  4968. (USHORT) (IND_SYNC_RESET +
  4969. (START_SYNC_RESET_VALUE << 8)));
  4970. VideoPortWritePortUlong((PULONG) (hwDeviceExtension->IOAddress +
  4971. Port),
  4972. (ULONG) (*Data & 0xFFFFFFF7) );
  4973. VideoPortWritePortUshort((PUSHORT) (hwDeviceExtension->IOAddress +
  4974. SEQ_ADDRESS_PORT),
  4975. (USHORT) (IND_SYNC_RESET +
  4976. (END_SYNC_RESET_VALUE << 8)));
  4977. VideoPortWritePortUchar(hwDeviceExtension->IOAddress + SEQ_ADDRESS_PORT,
  4978. temp);
  4979. return NO_ERROR;
  4980. }
  4981. if ( (Port == SEQ_ADDRESS_PORT) &&
  4982. (((*Data>> 8) & END_SYNC_RESET_VALUE) != END_SYNC_RESET_VALUE) &&
  4983. ((*Data & 0xFF) == IND_SYNC_RESET)) {
  4984. VideoPortSetTrappedEmulatorPorts(hwDeviceExtension,
  4985. NUM_FULL_VGA_VALIDATOR_ACCESS_RANGE,
  4986. FullVgaValidatorAccessRange);
  4987. hwDeviceExtension->TrappedValidatorCount = 1;
  4988. hwDeviceExtension->TrappedValidatorData[0].Port = Port;
  4989. hwDeviceExtension->TrappedValidatorData[0].AccessType =
  4990. VGA_VALIDATOR_ULONG_ACCESS;
  4991. hwDeviceExtension->TrappedValidatorData[0].Data = *Data;
  4992. //
  4993. // Start keeping track of the state of the sequencer port.
  4994. //
  4995. hwDeviceExtension->SequencerAddressValue = IND_SYNC_RESET;
  4996. } else {
  4997. VideoPortWritePortUlong((PULONG) (hwDeviceExtension->IOAddress +
  4998. Port),
  4999. *Data);
  5000. }
  5001. } else {
  5002. *Data = VideoPortReadPortUlong((PULONG) (hwDeviceExtension->IOAddress +
  5003. Port));
  5004. }
  5005. }
  5006. return NO_ERROR;
  5007. } // end VgaValidatorUlongEntry()
  5008. //---------------------------------------------------------------------------
  5009. BOOLEAN
  5010. VgaPlaybackValidatorData(
  5011. PVOID Context
  5012. )
  5013. /*++
  5014. Routine Description:
  5015. Performs all the DOS apps IO port accesses that were trapped by the
  5016. validator. Only IO accesses that can be processed are WRITEs
  5017. The number of outstanding IO access in deviceExtension is set to
  5018. zero as a side effect.
  5019. This function must be called via a call to VideoPortSynchronizeRoutine.
  5020. Arguments:
  5021. Context - Context parameter passed to the synchronized routine.
  5022. Must be a pointer to the miniport driver's device extension.
  5023. Return Value:
  5024. TRUE.
  5025. --*/
  5026. {
  5027. PHW_DEVICE_EXTENSION hwDeviceExtension = Context;
  5028. PHW_DEVICE_EXTENSION HwDeviceExtension = Context;
  5029. ULONG_PTR ioBaseAddress = PtrToUlong(hwDeviceExtension->IOAddress);
  5030. UCHAR i;
  5031. PVGA_VALIDATOR_DATA validatorData = hwDeviceExtension->TrappedValidatorData;
  5032. //
  5033. // Loop through the array of data and do instructions one by one.
  5034. //
  5035. for (i = 0; i < hwDeviceExtension->TrappedValidatorCount;
  5036. i++, validatorData++) {
  5037. //
  5038. // Calculate base address first
  5039. //
  5040. ioBaseAddress = PtrToUlong(hwDeviceExtension->IOAddress) +
  5041. validatorData->Port;
  5042. //
  5043. // This is a write operation. We will automatically stop when the
  5044. // buffer is empty.
  5045. //
  5046. switch (validatorData->AccessType) {
  5047. case VGA_VALIDATOR_UCHAR_ACCESS :
  5048. VideoPortWritePortUchar((PUCHAR)ioBaseAddress,
  5049. (UCHAR) validatorData->Data);
  5050. break;
  5051. case VGA_VALIDATOR_USHORT_ACCESS :
  5052. VideoPortWritePortUshort((PUSHORT)ioBaseAddress,
  5053. (USHORT) validatorData->Data);
  5054. break;
  5055. case VGA_VALIDATOR_ULONG_ACCESS :
  5056. VideoPortWritePortUlong((PULONG)ioBaseAddress,
  5057. (ULONG) validatorData->Data);
  5058. break;
  5059. default:
  5060. VideoDebugPrint((1, "InvalidValidatorAccessType\n" ));
  5061. }
  5062. }
  5063. hwDeviceExtension->TrappedValidatorCount = 0;
  5064. return TRUE;
  5065. } // end VgaPlaybackValidatorData()
  5066. //---------------------------------------------------------------------------
  5067. BOOLEAN
  5068. CirrusLogicIsPresent(
  5069. PHW_DEVICE_EXTENSION HwDeviceExtension
  5070. )
  5071. /*++
  5072. Routine Description:
  5073. This routine returns TRUE if an CL6410, 6420, 542x, or 543x is present.
  5074. It assumes that it's already been established that a VGA is present.
  5075. It performs the Cirrus Logic recommended ID test for each chip type:
  5076. 6410: we try to enable the extension registers and read back a 1, then
  5077. disable the extensions are read back a 0 in GR0A.
  5078. 6420: same as above
  5079. 54xx: Enable extended registers by writing 0x12 to the extensions
  5080. enable register, and reading back 0x12. Then read from the
  5081. ID register and make sure it specifies a 542x, 543x.
  5082. Finally, disable the extensions and make sure the
  5083. extensions enable register reads back 0x0F.
  5084. If this function fails to find an Cirrus Logic VGA, it attempts to undo any
  5085. damage it may have inadvertently done while testing.
  5086. If a Cirrus Logic VGA is found, the adapter is returned to its original
  5087. state after testing is finished, except that extensions are left enabled.
  5088. Arguments:
  5089. None.
  5090. Return Value:
  5091. TRUE if an CL6410/6420/542x/543x is present, FALSE if not.
  5092. --*/
  5093. {
  5094. #define MAX_ROM_SCAN 4096
  5095. UCHAR *pRomAddr;
  5096. PHYSICAL_ADDRESS paRom = {0x000C0000,0x00000000};
  5097. UCHAR originalGRIndex;
  5098. UCHAR originalGR0A;
  5099. UCHAR originalCRTCIndex;
  5100. UCHAR originalSeqIndex;
  5101. UCHAR originalExtsEnb;
  5102. UCHAR SystemBusSelect;
  5103. PUCHAR CRTCAddressPort, CRTCDataPort;
  5104. UCHAR temp1, temp2, temp3;
  5105. UCHAR revision;
  5106. ULONG rev10bit;
  5107. BOOLEAN retvalue = FALSE; // default return value
  5108. // Set default value, assuming it is not CL-GD5480.
  5109. HwDeviceExtension->BitBLTEnhance = FALSE ;
  5110. //
  5111. // first, save the Graphics controller index
  5112. //
  5113. originalGRIndex = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  5114. GRAPH_ADDRESS_PORT);
  5115. //
  5116. // Then save the value of GR0A
  5117. //
  5118. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  5119. GRAPH_ADDRESS_PORT, CL64xx_EXTENSION_ENABLE_INDEX);
  5120. originalGR0A = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  5121. GRAPH_DATA_PORT);
  5122. //
  5123. // then, Unlock the CL6410 extended registers., GR0A = 0ECH
  5124. //
  5125. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  5126. GRAPH_DATA_PORT, CL64xx_EXTENSION_ENABLE_VALUE);
  5127. //
  5128. // read back GR0A, it should be a 1
  5129. //
  5130. temp1 = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  5131. GRAPH_DATA_PORT);
  5132. //
  5133. // then, Lock the CL6410 extended registers., GR0A = 0CEH
  5134. //
  5135. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  5136. GRAPH_DATA_PORT, CL64xx_EXTENSION_DISABLE_VALUE);
  5137. //
  5138. // read back GR0A, it should be a 0
  5139. //
  5140. temp2 = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  5141. GRAPH_DATA_PORT);
  5142. //
  5143. // restore the GR0A value
  5144. // this will not have any effect if the chip IS a CL6410 or 6420
  5145. //
  5146. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  5147. GRAPH_DATA_PORT, originalGR0A);
  5148. //
  5149. // now restore the graphics index
  5150. //
  5151. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  5152. GRAPH_ADDRESS_PORT, originalGRIndex);
  5153. //
  5154. // now test to see if the returned values were correct!
  5155. //
  5156. if ((temp1 == 1) && (temp2 == 0))
  5157. {
  5158. //
  5159. // By golly, it *is* a CL6410 or CL6420!
  5160. //
  5161. // but now we have to determine the chip type, and which display is
  5162. // active.
  5163. // reenable the extension registers first
  5164. //
  5165. VideoPortWritePortUshort((PUSHORT)(HwDeviceExtension->IOAddress +
  5166. GRAPH_ADDRESS_PORT), CL64xx_EXTENSION_ENABLE_INDEX +
  5167. (CL64xx_EXTENSION_ENABLE_VALUE << 8));
  5168. //
  5169. // now get the chip type at ERAA
  5170. //
  5171. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  5172. GRAPH_ADDRESS_PORT, 0xaa);
  5173. revision = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  5174. GRAPH_DATA_PORT);
  5175. //
  5176. // now restore the graphics index
  5177. //
  5178. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  5179. GRAPH_ADDRESS_PORT, originalGRIndex);
  5180. if ((revision & 0xf0) == 0x80) // 6410 rev code
  5181. {
  5182. VideoDebugPrint((1, "CL 6410 found\n"));
  5183. //
  5184. // we don't support 6340 in this driver, so force it not to be
  5185. // installed.
  5186. //
  5187. if (!CirrusFind6340(HwDeviceExtension))
  5188. {
  5189. HwDeviceExtension->ChipType = CL6410;
  5190. HwDeviceExtension->AdapterMemorySize = 0x00040000; // 256K
  5191. HwDeviceExtension->DisplayType =
  5192. CirrusFind6410DisplayType(HwDeviceExtension);
  5193. retvalue = TRUE;
  5194. }
  5195. }
  5196. else if ((revision & 0xf0) == 0x70) // 6420 rev code
  5197. {
  5198. VideoDebugPrint((1, "CL 6420 found\n"));
  5199. //
  5200. // we don't support 6340 in this driver, so force it not to be
  5201. // installed.
  5202. //
  5203. if (!CirrusFind6340(HwDeviceExtension))
  5204. {
  5205. HwDeviceExtension->ChipType = CL6420;
  5206. HwDeviceExtension->ChipRevision = (USHORT) revision;
  5207. HwDeviceExtension->DisplayType =
  5208. CirrusFind6410DisplayType(HwDeviceExtension);
  5209. VideoDebugPrint((2, "CL 64xxx Adapter Memory size = %08lx\n",
  5210. HwDeviceExtension->AdapterMemorySize));
  5211. retvalue = TRUE;
  5212. }
  5213. }
  5214. else // we dont support 5410 at this time
  5215. {
  5216. VideoDebugPrint((1, "Unsupported CL VGA chip found\n"));
  5217. }
  5218. }
  5219. if (retvalue == FALSE) // Did not detect a 64x0, see if it's a 542x
  5220. {
  5221. //
  5222. // Determine where the CRTC registers are addressed (color or mono).
  5223. //
  5224. CRTCAddressPort = HwDeviceExtension->IOAddress;
  5225. CRTCDataPort = HwDeviceExtension->IOAddress;
  5226. if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  5227. MISC_OUTPUT_REG_READ_PORT) & 0x01)
  5228. {
  5229. CRTCAddressPort += CRTC_ADDRESS_PORT_COLOR;
  5230. CRTCDataPort += CRTC_DATA_PORT_COLOR;
  5231. }
  5232. else
  5233. {
  5234. CRTCAddressPort += CRTC_ADDRESS_PORT_MONO;
  5235. CRTCDataPort += CRTC_DATA_PORT_MONO;
  5236. }
  5237. //
  5238. // Save the original state of the CRTC and Sequencer Indices.
  5239. //
  5240. originalCRTCIndex = VideoPortReadPortUchar(CRTCAddressPort);
  5241. originalSeqIndex = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  5242. SEQ_ADDRESS_PORT);
  5243. //
  5244. // Try to enable all extensions:
  5245. // a) Set the Sequencer Index to IND_CL_EXTS_ENB.
  5246. //
  5247. VideoPortWritePortUchar(HwDeviceExtension->IOAddress + SEQ_ADDRESS_PORT,
  5248. IND_CL_EXTS_ENB);
  5249. //
  5250. // b) Save the original state of Sequencer register IND_CL_EXTS_ENB.
  5251. //
  5252. originalExtsEnb = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  5253. SEQ_DATA_PORT);
  5254. //
  5255. // c) Write enabling value (0x12) to extension enable register
  5256. //
  5257. VideoPortWritePortUshort((PUSHORT)(HwDeviceExtension->IOAddress +
  5258. SEQ_ADDRESS_PORT),(USHORT)((0x12 << 8) + IND_CL_EXTS_ENB));
  5259. VideoPortWritePortUchar(HwDeviceExtension->IOAddress + SEQ_ADDRESS_PORT,
  5260. IND_CL_EXTS_ENB);
  5261. temp1 = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  5262. SEQ_DATA_PORT);
  5263. //
  5264. // Read Chip ID Value from CRTC Register (Ignoring revision bits)
  5265. //
  5266. VideoPortWritePortUchar(CRTCAddressPort, IND_CL_ID_REG);
  5267. temp3 = VideoPortReadPortUchar(CRTCDataPort);
  5268. //
  5269. // Detect if CL-GD6245 chips ID=0x16
  5270. //
  5271. if (temp3 != 0x16)
  5272. {
  5273. rev10bit = (ULONG)temp3 & 0x3; // lo bits of ID are high bits of rev code
  5274. temp3 = temp3 >> 2; // shift off revision bits
  5275. }
  5276. //
  5277. // Write another value (!= 0x12) to IND_CL_EXTS_ENB to disable extensions
  5278. // Should read back as 0x0F
  5279. //
  5280. VideoPortWritePortUshort((PUSHORT)(HwDeviceExtension->IOAddress +
  5281. SEQ_ADDRESS_PORT),(USHORT)((0 << 8) + IND_CL_EXTS_ENB));
  5282. VideoPortWritePortUchar(HwDeviceExtension->IOAddress + SEQ_ADDRESS_PORT,
  5283. IND_CL_EXTS_ENB);
  5284. temp2 = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  5285. SEQ_DATA_PORT);
  5286. //
  5287. // Restore the original IND_CL_EXTS_ENB state.
  5288. //
  5289. VideoPortWritePortUshort((PUSHORT)(HwDeviceExtension->IOAddress
  5290. + SEQ_ADDRESS_PORT),
  5291. (USHORT)((originalExtsEnb << 8) + IND_CL_EXTS_ENB));
  5292. //
  5293. // Check values read from IND_CL_EXTS_ENB and IND_CL_ID_REG to be correct
  5294. //
  5295. if ((temp1 != (UCHAR) (0x12)) ||
  5296. (temp2 != (UCHAR) (0x0F)) ||
  5297. (temp3 > (UCHAR) (0x2F)) || // 2F is 5480
  5298. (temp3 < (UCHAR) (0x0B)) ) // 0B is Nordic (7542)
  5299. {
  5300. //
  5301. // Did not find appropriate CL VGA Chip.
  5302. //
  5303. VideoDebugPrint((1, "CL VGA chip not found\n"));
  5304. retvalue = FALSE;
  5305. }
  5306. //
  5307. // Detect if CL-GD6245 chips
  5308. //
  5309. else if ((temp1 == (UCHAR) (0x12)) &&
  5310. (temp2 == (UCHAR) (0x0F)) &&
  5311. (temp3 == (UCHAR) (0x16))) //6245
  5312. {
  5313. VideoDebugPrint((1, "CL 6245 found\n"));
  5314. HwDeviceExtension->ChipType = CL6245;
  5315. HwDeviceExtension->DisplayType =
  5316. CirrusFind6245DisplayType(HwDeviceExtension,
  5317. CRTCAddressPort,
  5318. CRTCDataPort);
  5319. retvalue = TRUE;
  5320. }
  5321. else
  5322. {
  5323. //
  5324. // It's a supported CL adapter.
  5325. //
  5326. // Save actual Chip ID in ChipRevision field of HwDeviceExtension
  5327. //
  5328. HwDeviceExtension->ChipRevision = temp3;
  5329. if ((temp3 > (UCHAR) (0x27)) || // 27 is 5429
  5330. (temp3 < (UCHAR) (0x22) ) ) // 22 is 5422
  5331. {
  5332. if ((temp3 >= (UCHAR) (0x0B)) && // Nordic
  5333. (temp3 <= (UCHAR) (0x0E)) ) // Everest
  5334. {
  5335. if (temp3 == (UCHAR)0x0B)
  5336. {
  5337. VideoDebugPrint((1, "CL 7542 found\n")); //myf32
  5338. HwDeviceExtension->ChipType = CL7542;
  5339. }
  5340. if (temp3 == (UCHAR)0x0C)
  5341. {
  5342. VideoDebugPrint((1, "CL 7543 found\n")); //myf32
  5343. HwDeviceExtension->ChipType = CL7543;
  5344. }
  5345. if (temp3 == (UCHAR)0x0D)
  5346. {
  5347. VideoDebugPrint((1, "CL 7541 found\n")); //myf32
  5348. HwDeviceExtension->ChipType = CL7541;
  5349. }
  5350. if (temp3 == (UCHAR)0x0E)
  5351. {
  5352. VideoDebugPrint((1, "CL 7548 found\n")); //myf32
  5353. HwDeviceExtension->ChipType = CL7548;
  5354. }
  5355. HwDeviceExtension->DisplayType =
  5356. CirrusFind754xDisplayType(HwDeviceExtension,
  5357. CRTCAddressPort,
  5358. CRTCDataPort);
  5359. } else if ((temp3 == (UCHAR) (0x10)) ||
  5360. (temp3 == (UCHAR) (0x13))) { //myf17, CF
  5361. if (temp3 == (UCHAR)0x10)
  5362. {
  5363. VideoDebugPrint((1, "CL 7555 found\n")) ;
  5364. HwDeviceExtension->ChipType = CL7555;
  5365. }
  5366. if (temp3 == (UCHAR)0x13)
  5367. {
  5368. VideoDebugPrint((1, "CL 7556 found\n")) ;
  5369. HwDeviceExtension->ChipType = CL7556;
  5370. }
  5371. HwDeviceExtension -> DisplayType =
  5372. CirrusFind755xDisplayType(HwDeviceExtension,
  5373. CRTCAddressPort,
  5374. CRTCDataPort) ;
  5375. } else if (temp3 == (UCHAR) (0x11)) {
  5376. VideoDebugPrint((1, "CL 756x found\n")) ;
  5377. HwDeviceExtension->ChipType = CL756x ;
  5378. HwDeviceExtension->DisplayType =
  5379. CirrusFind755xDisplayType(HwDeviceExtension,
  5380. CRTCAddressPort,
  5381. CRTCDataPort) ;
  5382. } else {
  5383. VideoDebugPrint((1, "CL 543x found\n"));
  5384. HwDeviceExtension->ChipType = CL543x;
  5385. HwDeviceExtension->DisplayType = crt;
  5386. // jl03 Read CR27(b1 & b0) + CR25 for chip revision
  5387. VideoPortWritePortUchar(CRTCAddressPort, IND_CL_REV_REG);
  5388. revision = (VideoPortReadPortUchar(CRTCDataPort));
  5389. rev10bit = (ULONG)(rev10bit << 8) | revision;
  5390. if (temp3 == (UCHAR) (0x2A)) // or a 5434?
  5391. {
  5392. VideoDebugPrint((1, "CL 5434 found\n"));
  5393. //
  5394. //Default to .8u 5434
  5395. //
  5396. HwDeviceExtension->ChipType = CL5434;
  5397. //
  5398. // Read the revision code from CR25&27 and compare to
  5399. // lowest rev that we know to be .6u
  5400. //
  5401. /* jl03
  5402. VideoPortWritePortUchar(CRTCAddressPort, IND_CL_REV_REG);
  5403. revision = (VideoPortReadPortUchar(CRTCDataPort));
  5404. rev10bit = (ULONG)(rev10bit << 8) | revision;
  5405. */
  5406. if ((rev10bit >= 0xB0) || // B0 is rev "EP", first .6u 5434
  5407. (rev10bit == 0x28) ) // 28 is rev "AH" also .6u 5434
  5408. {
  5409. VideoDebugPrint((1, "CL 5434.6 found\n"));
  5410. HwDeviceExtension->ChipType = CL5434_6;
  5411. }
  5412. } else if (temp3 == (UCHAR) (0x2B)) { // 5436
  5413. HwDeviceExtension->ChipType = CL5436 ;
  5414. } else if (temp3 == (UCHAR) (0x2E)) { // 5446
  5415. HwDeviceExtension->ChipType = CL5446 ;
  5416. if (rev10bit == 0x45)
  5417. HwDeviceExtension->ChipType = CL5446BE ; // jl02 5446-BE
  5418. } else if (temp3 == (UCHAR) (0x2F)) { // 5480
  5419. HwDeviceExtension->ChipType = CL5480;
  5420. HwDeviceExtension->BitBLTEnhance = TRUE ;
  5421. } else if (temp3 == (UCHAR) (0x3A)) { // 54UM36 ?
  5422. HwDeviceExtension->ChipType = CL54UM36 ;
  5423. }
  5424. }
  5425. }
  5426. else
  5427. {
  5428. VideoDebugPrint((1, "CL 542x found\n"));
  5429. HwDeviceExtension->ChipType = CL542x;
  5430. HwDeviceExtension->DisplayType = crt;
  5431. }
  5432. retvalue = TRUE;
  5433. }
  5434. //
  5435. // Restore modified index registers
  5436. //
  5437. VideoPortWritePortUchar(
  5438. (HwDeviceExtension->IOAddress + SEQ_ADDRESS_PORT),
  5439. originalSeqIndex);
  5440. VideoPortWritePortUchar(CRTCAddressPort, originalCRTCIndex);
  5441. }
  5442. if (retvalue)
  5443. {
  5444. //
  5445. // Restore the original Sequencer and CRTC Indices.
  5446. //
  5447. HwDeviceExtension->AutoFeature = FALSE ;
  5448. if ((HwDeviceExtension->ChipType == CL5436) ||
  5449. (HwDeviceExtension->ChipType == CL5446) ||
  5450. (HwDeviceExtension->ChipType == CL5446BE) ||
  5451. (HwDeviceExtension->ChipType == CL5480) ||
  5452. (HwDeviceExtension->ChipType & CL754x) ||
  5453. (HwDeviceExtension->ChipType & CL755x) ||
  5454. (HwDeviceExtension->ChipType == CL54UM36))
  5455. {
  5456. HwDeviceExtension->AutoFeature = TRUE;
  5457. }
  5458. }
  5459. return retvalue;
  5460. } // CirrusLogicIsPresent()
  5461. //---------------------------------------------------------------------------
  5462. #ifdef PANNING_SCROLL
  5463. VP_STATUS
  5464. CirrusSetDisplayPitch (
  5465. PHW_DEVICE_EXTENSION HwDeviceExtension,
  5466. PANNMODE PanningMode
  5467. )
  5468. {
  5469. PUCHAR CRTCAddressPort, CRTCDataPort;
  5470. USHORT RequestedPitchInBytes = PanningMode.wbytes;
  5471. USHORT PitchInQuadWords = RequestedPitchInBytes >> 3;
  5472. UCHAR savSEQidx, Panel_Type, LCD, ChipID;
  5473. //
  5474. // Determine where the CRTC registers are addressed (color or mono).
  5475. //
  5476. if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  5477. MISC_OUTPUT_REG_READ_PORT) & 0x01)
  5478. {
  5479. CRTCAddressPort = CRTC_ADDRESS_PORT_COLOR;
  5480. CRTCDataPort = CRTC_DATA_PORT_COLOR;
  5481. }
  5482. else
  5483. {
  5484. CRTCAddressPort = CRTC_ADDRESS_PORT_MONO;
  5485. CRTCDataPort = CRTC_DATA_PORT_MONO;
  5486. }
  5487. //
  5488. // Write out the requested pitch in quad words to CR13
  5489. //
  5490. VideoPortWritePortUchar(CRTCAddressPort, 0x13);
  5491. VideoPortWritePortUchar(CRTCDataPort,
  5492. (UCHAR) (PitchInQuadWords & 0xFF) );
  5493. //
  5494. // See if requested pitch overflows to bit 4 in CR1B
  5495. // NOTE: In either case we must either set or reset the bit.
  5496. //
  5497. VideoPortWritePortUchar(CRTCAddressPort, 0x1B);
  5498. if (PitchInQuadWords & 0x100)
  5499. {
  5500. VideoPortWritePortUchar(CRTCDataPort,
  5501. (UCHAR)(VideoPortReadPortUchar(CRTCDataPort) | 0x10) );
  5502. }
  5503. else
  5504. {
  5505. VideoPortWritePortUchar(CRTCDataPort,
  5506. (UCHAR)(VideoPortReadPortUchar(CRTCDataPort) & ~0x10) );
  5507. }
  5508. VideoDebugPrint((1,"CirrusSetDisplayPitch - Exit (not error)\n"));
  5509. return NO_ERROR;
  5510. }
  5511. #endif // PANNING_SCROLL
  5512. //---------------------------------------------------------------------------
  5513. //
  5514. // The memory manager needs a "C" interface to the banking functions
  5515. //
  5516. /*++
  5517. Routine Description:
  5518. Each of these functions is a "C" callable interface to the ASM banking
  5519. functions. They are NON paged because they are called from the
  5520. Memory Manager during some page faults.
  5521. Arguments:
  5522. iBankRead - Index of bank we want mapped in to read from.
  5523. iBankWrite - Index of bank we want mapped in to write to.
  5524. Return Value:
  5525. None.
  5526. --*/
  5527. VOID
  5528. vBankMap_CL64xx(
  5529. ULONG iBankRead,
  5530. ULONG iBankWrite,
  5531. PVOID pvContext
  5532. )
  5533. {
  5534. VideoDebugPrint((1, "vBankMap_CL64xx(%d,%d) - enter\n",iBankRead,iBankWrite));
  5535. #ifdef _X86_
  5536. _asm {
  5537. mov eax,iBankRead
  5538. mov edx,iBankWrite
  5539. lea ebx,CL64xxBankSwitchStart
  5540. call ebx
  5541. }
  5542. #endif
  5543. VideoDebugPrint((1, "vBankMap_CL64xx - exit\n"));
  5544. }
  5545. VOID
  5546. vBankMap_CL543x(
  5547. ULONG iBankRead,
  5548. ULONG iBankWrite,
  5549. PVOID pvContext
  5550. )
  5551. {
  5552. VideoDebugPrint((1, "vBankMap_CL543x(%d,%d) - enter\n",iBankRead,iBankWrite));
  5553. #ifdef _X86_
  5554. _asm {
  5555. mov eax,iBankRead
  5556. mov edx,iBankWrite
  5557. lea ebx,CL543xBankSwitchStart
  5558. call ebx
  5559. }
  5560. #endif
  5561. VideoDebugPrint((1, "vBankMap_CL543x - exit\n"));
  5562. }
  5563. VOID
  5564. vBankMap_CL542x(
  5565. ULONG iBankRead,
  5566. ULONG iBankWrite,
  5567. PVOID pvContext
  5568. )
  5569. {
  5570. VideoDebugPrint((1, "vBankMap_CL542x(%d,%d) - enter\n",iBankRead,iBankWrite));
  5571. #ifdef _X86_
  5572. _asm {
  5573. mov eax,iBankRead
  5574. mov edx,iBankWrite
  5575. lea ebx,CL542xBankSwitchStart
  5576. call ebx
  5577. }
  5578. #endif
  5579. VideoDebugPrint((1, "vBankMap_CL542x - exit\n"));
  5580. }
  5581. //---------------------------------------------------------------------------
  5582. ULONG
  5583. CirrusFindVmemSize(
  5584. PHW_DEVICE_EXTENSION HwDeviceExtension
  5585. )
  5586. /*++
  5587. Routine Description:
  5588. This routine returns the amount of vram detected for the
  5589. Cirrus Logic 6420 and 542x ONLY. It assumes that it is already known that
  5590. a Cirrus Logic VGA is in the system.
  5591. Arguments:
  5592. HwDeviceExtension - Pointer to the miniport driver's device extension.
  5593. Return Value:
  5594. Number of butes of VRAM.
  5595. --*/
  5596. {
  5597. UCHAR temp;
  5598. ULONG memsize=0;
  5599. UCHAR originalSeqIndex;
  5600. UCHAR originalGraphicsIndex;
  5601. UCHAR PostScratchPad;
  5602. if (HwDeviceExtension->ChipType == CL6420) {
  5603. #ifdef _X86_
  5604. originalGraphicsIndex =
  5605. VideoPortReadPortUchar((HwDeviceExtension->IOAddress +
  5606. GRAPH_ADDRESS_PORT));
  5607. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  5608. GRAPH_ADDRESS_PORT, 0x9a); // Video memory config register
  5609. temp = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  5610. GRAPH_DATA_PORT); // get the data
  5611. if ((temp & 0x07) == 0) { // 0 is accurate always
  5612. memsize = 0x00040000;
  5613. } else {
  5614. //
  5615. // We know now that the amount of vram is >256k. But we don't
  5616. // know if it is 512k or 1meg.
  5617. // They tell us to actually go out and see if memory is there by
  5618. // writing into it and reading it back.
  5619. //
  5620. VideoPortWritePortUshort((PUSHORT)(HwDeviceExtension->IOAddress +
  5621. SEQ_ADDRESS_PORT),0x0f02);
  5622. VideoPortWritePortUshort((PUSHORT)(HwDeviceExtension->IOAddress +
  5623. GRAPH_ADDRESS_PORT),0x0506);
  5624. //
  5625. // now pick a bank, and do the write
  5626. //
  5627. SetCirrusBanking(HwDeviceExtension,1); // start of 2nd 256k
  5628. VideoPortWriteRegisterUchar(HwDeviceExtension->VideoMemoryAddress,
  5629. 0x55);
  5630. SetCirrusBanking(HwDeviceExtension,3); // 3*256k is 768k
  5631. VideoPortWriteRegisterUchar(HwDeviceExtension->VideoMemoryAddress,
  5632. 0xaa);
  5633. SetCirrusBanking(HwDeviceExtension,1); // start of 2nd 256k
  5634. if (VideoPortReadRegisterUchar(HwDeviceExtension->VideoMemoryAddress)
  5635. == 0x55) {
  5636. memsize = 0x00100000; // 1 MEG
  5637. } else {
  5638. memsize = 0x00080000; // 512K
  5639. }
  5640. SetCirrusBanking(HwDeviceExtension,0); // reset the memory value
  5641. VgaInterpretCmdStream(HwDeviceExtension, DisableA000Color);
  5642. VideoPortWritePortUchar((HwDeviceExtension->IOAddress
  5643. + GRAPH_ADDRESS_PORT),
  5644. originalGraphicsIndex);
  5645. }
  5646. VideoPortWritePortUchar((HwDeviceExtension->IOAddress +
  5647. GRAPH_ADDRESS_PORT), originalGraphicsIndex);
  5648. #endif
  5649. return memsize;
  5650. } else { // its 542x or 543x
  5651. originalSeqIndex = VideoPortReadPortUchar((HwDeviceExtension->IOAddress +
  5652. SEQ_ADDRESS_PORT));
  5653. VideoPortWritePortUshort((PUSHORT)(HwDeviceExtension->IOAddress +
  5654. SEQ_ADDRESS_PORT),
  5655. (USHORT)((0x12 << 8) + IND_CL_EXTS_ENB));
  5656. //
  5657. // Read the POST scratch pad reg to determine amount of Video
  5658. // memory
  5659. //
  5660. if (HwDeviceExtension->ChipType == CL542x) {
  5661. VideoPortWritePortUchar(HwDeviceExtension->IOAddress + SEQ_ADDRESS_PORT,
  5662. IND_CL_SCRATCH_PAD);
  5663. PostScratchPad = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  5664. SEQ_DATA_PORT);
  5665. PostScratchPad = ((PostScratchPad & 0x18) >> 3); // in bits 3 and 4
  5666. }
  5667. else if (HwDeviceExtension->ChipType == CL6245) {
  5668. VideoPortWritePortUchar((HwDeviceExtension->IOAddress +
  5669. SEQ_ADDRESS_PORT),originalSeqIndex);
  5670. memsize = 0x00080000; // 512K
  5671. return memsize;
  5672. }
  5673. else
  5674. { // its 543x or 754x
  5675. if ((HwDeviceExtension->ChipType & CL754x) ||
  5676. (HwDeviceExtension->ChipType & CL755x) ||
  5677. (HwDeviceExtension->ChipType == CL756x))
  5678. {
  5679. VideoPortWritePortUchar(HwDeviceExtension->IOAddress + SEQ_ADDRESS_PORT,
  5680. IND_NORD_SCRATCH_PAD);
  5681. }
  5682. else // it's 543x, 5434, or 5434_6 by default
  5683. {
  5684. VideoPortWritePortUchar(HwDeviceExtension->IOAddress + SEQ_ADDRESS_PORT,
  5685. IND_ALP_SCRATCH_PAD);
  5686. }
  5687. // Nordic family uses same bits as 543x, but in different register
  5688. PostScratchPad = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  5689. SEQ_DATA_PORT);
  5690. PostScratchPad &= 0x0F; // It's in bits 0-3
  5691. }
  5692. VideoPortWritePortUchar((HwDeviceExtension->IOAddress + SEQ_ADDRESS_PORT),
  5693. originalSeqIndex);
  5694. //
  5695. // Installed video memory is stored in scratch pad register by POST.
  5696. //
  5697. switch (PostScratchPad) {
  5698. case 0x00:
  5699. memsize = 0x00040000; // 256K
  5700. break;
  5701. case 0x01:
  5702. memsize = 0x00080000; // 512K
  5703. break;
  5704. case 0x02:
  5705. memsize = 0x00100000; // 1 MEG
  5706. break;
  5707. case 0x03:
  5708. memsize = 0x00200000; // 2 MEG
  5709. break;
  5710. case 0x04:
  5711. memsize = 0x00400000; // 4 MEG
  5712. break;
  5713. case 0x05:
  5714. memsize = 0x00300000; // 3 MEG
  5715. break;
  5716. }
  5717. //
  5718. // The 542x cards don't properly address more than 1MB of
  5719. // video memory, so lie and limit these cards to 1MB.
  5720. //
  5721. if ((HwDeviceExtension->ChipType == CL542x) &&
  5722. (memsize > 0x00100000)) {
  5723. memsize = 0x00100000; // 1 MEG
  5724. }
  5725. //
  5726. // The memory size should not be zero!
  5727. //
  5728. ASSERT(memsize != 0);
  5729. return memsize;
  5730. }
  5731. } // CirrusFindVmemSize()
  5732. //---------------------------------------------------------------------------
  5733. VOID
  5734. SetCirrusBanking(
  5735. PHW_DEVICE_EXTENSION HwDeviceExtension,
  5736. USHORT BankNumber
  5737. )
  5738. /*++
  5739. Routine Description:
  5740. Arguments:
  5741. HwDeviceExtension - Pointer to the miniport driver's device extension.
  5742. BankNumber - the 256k bank number to set in 1RW mode(we will set this mode).
  5743. Return Value:
  5744. vmem256k, vmem512k, or vmem1Meg ONLY ( these are defined in cirrus.h).
  5745. --*/
  5746. {
  5747. if ((HwDeviceExtension->ChipType == CL542x) ||
  5748. (HwDeviceExtension->ChipType == CL6245)) {
  5749. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  5750. GRAPH_ADDRESS_PORT), 0x1206);
  5751. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  5752. GRAPH_ADDRESS_PORT), 0x010b);
  5753. VideoPortWritePortUshort((PUSHORT)(HwDeviceExtension->IOAddress +
  5754. GRAPH_ADDRESS_PORT),
  5755. (USHORT)(0x0009 + (BankNumber << (8+4))) );
  5756. } else if ((HwDeviceExtension->ChipType == CL543x) ||
  5757. (HwDeviceExtension->ChipType & CL755x) || //myf15, crus
  5758. (HwDeviceExtension->ChipType & CL754x) ) {
  5759. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  5760. GRAPH_ADDRESS_PORT), 0x1206);
  5761. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  5762. GRAPH_ADDRESS_PORT), 0x210b);
  5763. VideoPortWritePortUshort((PUSHORT)(HwDeviceExtension->IOAddress +
  5764. GRAPH_ADDRESS_PORT),
  5765. (USHORT)(0x0009 + (BankNumber << (8+2))) );
  5766. } else { // 6410 or 6420
  5767. VideoPortWritePortUshort((PUSHORT)(HwDeviceExtension->IOAddress +
  5768. GRAPH_ADDRESS_PORT), 0xec0a);
  5769. VideoPortWritePortUshort((PUSHORT)(HwDeviceExtension->IOAddress +
  5770. GRAPH_ADDRESS_PORT), 0x030d);
  5771. VideoPortWritePortUshort((PUSHORT)(HwDeviceExtension->IOAddress +
  5772. GRAPH_ADDRESS_PORT),
  5773. (USHORT)(0x000e + (BankNumber << (8+4))) );
  5774. }
  5775. } // SetCirrusBanking()
  5776. //---------------------------------------------------------------------------
  5777. USHORT
  5778. CirrusFind6410DisplayType(
  5779. PHW_DEVICE_EXTENSION HwDeviceExtension
  5780. )
  5781. /*++
  5782. Routine Description:
  5783. Determines the display type for CL6410 or CL6420 crt/panel controllers.
  5784. Arguments:
  5785. HwDeviceExtension - Pointer to the miniport driver's device extension.
  5786. Return Value:
  5787. crt, panel as defined in cirrus.h
  5788. --*/
  5789. {
  5790. UCHAR originalGraphicsIndex;
  5791. UCHAR temp1;
  5792. //
  5793. // now we need to check to see which display we are on...
  5794. //
  5795. originalGraphicsIndex =
  5796. VideoPortReadPortUchar((HwDeviceExtension->IOAddress +
  5797. GRAPH_ADDRESS_PORT));
  5798. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  5799. GRAPH_ADDRESS_PORT, 0xd6);
  5800. temp1 = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  5801. GRAPH_DATA_PORT);
  5802. VideoPortWritePortUchar((HwDeviceExtension->IOAddress
  5803. + GRAPH_ADDRESS_PORT), originalGraphicsIndex);
  5804. if (temp1 & 0x02) { // display is LCD Panel
  5805. return panel;
  5806. } else { // the display is a crt
  5807. return crt;
  5808. }
  5809. } // CirrusFind6410DisplayType()
  5810. // crus
  5811. //---------------------------------------------------------------------------
  5812. USHORT
  5813. CirrusFind6245DisplayType(
  5814. PHW_DEVICE_EXTENSION HwDeviceExtension,
  5815. PUCHAR CRTCAddrPort, PUCHAR CRTCDataPort
  5816. )
  5817. /*++
  5818. Routine Description:
  5819. Determines the display type for CL6245 crt/panel controllers.
  5820. Arguments:
  5821. HwDeviceExtension - Pointer to the miniport driver's device extension.
  5822. Return Value:
  5823. crt, panel as defined in cirrus.h
  5824. --*/
  5825. {
  5826. UCHAR originalCRTCIndex, originalLCDControl;
  5827. UCHAR originalSEQIndex;
  5828. USHORT temp2, temp4;
  5829. USHORT temp1, temp3;
  5830. //
  5831. // we need to check to see which display we are on...
  5832. //
  5833. originalCRTCIndex = VideoPortReadPortUchar(CRTCAddrPort);
  5834. VideoPortWritePortUchar(CRTCAddrPort, 0x20);
  5835. temp1 = VideoPortReadPortUchar(CRTCDataPort);
  5836. temp3 = 0;
  5837. temp4 = 0;
  5838. if (temp1 & 0x40) temp3 = 1;
  5839. if (temp1 & 0x20)
  5840. {
  5841. originalSEQIndex =
  5842. VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  5843. SEQ_ADDRESS_PORT);
  5844. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  5845. SEQ_ADDRESS_PORT, 0x1A);
  5846. temp4 = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  5847. SEQ_DATA_PORT) & 0x40;
  5848. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  5849. SEQ_ADDRESS_PORT, originalSEQIndex);
  5850. // Allow access to extended CRTC regs and read R8X[5], must CR1D[7]=1
  5851. //
  5852. VideoPortWritePortUchar(CRTCAddrPort, 0x1D);
  5853. originalLCDControl = VideoPortReadPortUchar(CRTCDataPort);
  5854. VideoPortWritePortUchar(CRTCDataPort,
  5855. (UCHAR) (originalLCDControl | 0x80));
  5856. VideoPortWritePortUchar(CRTCAddrPort, 0x08);
  5857. temp1 = (VideoPortReadPortUchar(CRTCDataPort) & 0x20);
  5858. VideoPortWritePortUchar (CRTCAddrPort, 0x1D);
  5859. VideoPortWritePortUchar (CRTCDataPort, originalLCDControl);
  5860. // CR1C bit 6,7 set indicate LCD type, TFT, STN color or STN mono
  5861. // STN mono, R8X bit 5 set Single or Dual
  5862. // STN color, CR1C bit 7,6 must 10 & SR1A bit 6 set Dual or Single
  5863. VideoPortWritePortUchar (CRTCAddrPort, 0x1C);
  5864. temp2 = VideoPortReadPortUchar(CRTCDataPort) & 0xC0;
  5865. if (temp2 == 0) //STN mono LCD
  5866. {
  5867. if (temp1 == 0)
  5868. temp3 |= (USHORT)Dual_LCD | Mono_LCD | STN_LCD;
  5869. else
  5870. temp3 |= (USHORT)Single_LCD | Mono_LCD | STN_LCD;
  5871. }
  5872. else if (temp2 == 0x80) //STN color LCD
  5873. {
  5874. if (temp4)
  5875. {
  5876. temp3 |= (USHORT)Dual_LCD | Color_LCD | STN_LCD;
  5877. }
  5878. else
  5879. {
  5880. temp3 |= (USHORT)Single_LCD | Color_LCD | STN_LCD;
  5881. }
  5882. }
  5883. else if (temp2 == 0xC0) //TFT LCD
  5884. {
  5885. temp3 |= (USHORT)TFT_LCD; //myf28
  5886. }
  5887. // Restore LCD Display Controls register and CRTC index to original state
  5888. //
  5889. VideoPortWritePortUchar(CRTCAddrPort, originalCRTCIndex);
  5890. return (temp3 | panel);
  5891. }
  5892. else // the display is a crt
  5893. {
  5894. VideoPortWritePortUchar(CRTCAddrPort, originalCRTCIndex);
  5895. return (temp3);
  5896. }
  5897. } // CirrusFind6245DisplayType()
  5898. // end crus
  5899. //---------------------------------------------------------------------------
  5900. USHORT
  5901. CirrusFind754xDisplayType(
  5902. PHW_DEVICE_EXTENSION HwDeviceExtension,
  5903. PUCHAR CRTCAddrPort, PUCHAR CRTCDataPort
  5904. )
  5905. /*++
  5906. Routine Description:
  5907. Determines the display type for CL754x crt/panel controllers.
  5908. Arguments:
  5909. HwDeviceExtension - Pointer to the miniport driver's device extension.
  5910. CRTCAddrPort, CRTCDataPort - Index of CRTC registers for current mode.
  5911. Return Value:
  5912. crt, panel, or panel8x6 as defined in cirrus.h
  5913. --*/
  5914. {
  5915. // crus
  5916. //
  5917. // update 754X Display Type Detect code
  5918. //
  5919. UCHAR originalCRTCIndex, originalLCDControl; // temp1;
  5920. UCHAR originalSEQIndex;
  5921. USHORT temp1, temp2, temp4;
  5922. USHORT temp3, temp5; // crus
  5923. // we need to check to see which display we are on...
  5924. //
  5925. originalCRTCIndex = VideoPortReadPortUchar(CRTCAddrPort);
  5926. VideoPortWritePortUchar(CRTCAddrPort, 0x20);
  5927. temp1 = VideoPortReadPortUchar(CRTCDataPort);
  5928. temp3 = 0; temp4 = 0; //myf28
  5929. if (temp1 & 0x40) temp3 = 1;
  5930. if (!(temp1 & 0x20)) temp3 |= Jump_type; //myf27
  5931. else temp3 &= (~Jump_type); //myf27,myf28
  5932. //myf27 if (temp1 & 0x20)
  5933. {
  5934. originalSEQIndex =
  5935. VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  5936. SEQ_ADDRESS_PORT);
  5937. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  5938. SEQ_ADDRESS_PORT, 0x21);
  5939. temp4 = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  5940. SEQ_DATA_PORT) & 0x40;
  5941. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  5942. SEQ_ADDRESS_PORT, originalSEQIndex);
  5943. // bit 5 set indicates that display is on LCD Panel
  5944. // Check extended reg to see if panel supports 800x600 display
  5945. //
  5946. VideoPortWritePortUchar(CRTCAddrPort, 0x2D);
  5947. originalLCDControl = VideoPortReadPortUchar(CRTCDataPort);
  5948. // Allow access to extended CRTC regs and read R9X[3:2]
  5949. //
  5950. VideoPortWritePortUchar(CRTCDataPort,
  5951. (UCHAR) (originalLCDControl | 0x80));
  5952. VideoPortWritePortUchar(CRTCAddrPort, 0x09);
  5953. temp1 = (VideoPortReadPortUchar(CRTCDataPort) & 0x0C) >> 2;
  5954. VideoPortWritePortUchar (CRTCAddrPort, 0x08);
  5955. temp5 = VideoPortReadPortUchar(CRTCDataPort) & 0x20;
  5956. VideoPortWritePortUchar (CRTCAddrPort, 0x2D);
  5957. VideoPortWritePortUchar (CRTCDataPort, originalLCDControl);
  5958. // CR2C bit 6,7 set indicate LCD type, TFT, STN color or STN mono
  5959. // STN mono, R8X bit 5 set Single or Dual
  5960. // STN color, CR2C bit 7,6 must 10 & SR21 bit 6 set Dual or Single
  5961. VideoPortWritePortUchar (CRTCAddrPort, 0x2C);
  5962. temp2 = VideoPortReadPortUchar(CRTCDataPort) & 0xC0;
  5963. if (temp2 == 0) //STN mono LCD
  5964. {
  5965. if (temp5 == 0)
  5966. temp3 |= (USHORT)Dual_LCD | Mono_LCD | STN_LCD;
  5967. else
  5968. temp3 |= (USHORT)Single_LCD | Mono_LCD | STN_LCD;
  5969. }
  5970. else if (temp2 == 0x80) //STN color LCD
  5971. {
  5972. if (temp4)
  5973. {
  5974. temp3 |= (USHORT)Dual_LCD | Color_LCD | STN_LCD;
  5975. }
  5976. else
  5977. {
  5978. temp3 |= (USHORT)Single_LCD | Color_LCD | STN_LCD;
  5979. }
  5980. }
  5981. else if (temp2 == 0xC0) //TFT LCD
  5982. {
  5983. temp3 |= (USHORT)TFT_LCD; //myf28
  5984. }
  5985. // Restore LCD Display Controls register and CRTC index to original state
  5986. //
  5987. VideoPortWritePortUchar(CRTCAddrPort, originalCRTCIndex);
  5988. if (temp1 == 1) // this means panel connected is 800x600
  5989. {
  5990. // will support either 800x600 or 640x480
  5991. // return panel type
  5992. return (temp3 | panel8x6);
  5993. }
  5994. else if (temp1 == 2)
  5995. {
  5996. return (temp3 | panel10x7);
  5997. }
  5998. else if (temp1 == 0)
  5999. {
  6000. return (temp3 | panel);
  6001. }
  6002. else //temp1 =4 :reserve
  6003. {
  6004. return (temp3);
  6005. }
  6006. }
  6007. //myf27 else // the display is a crt
  6008. //myf27 {
  6009. //myf27 VideoPortWritePortUchar(CRTCAddrPort, originalCRTCIndex);
  6010. //myf27 return (temp3);
  6011. //myf27 }
  6012. } // CirrusFind754xDisplayType()
  6013. //---------------------------------------------------------------------------
  6014. USHORT
  6015. CirrusFind755xDisplayType(
  6016. PHW_DEVICE_EXTENSION HwDeviceExtension,
  6017. PUCHAR CRTCAddrPort, PUCHAR CRTCDataPort
  6018. )
  6019. /*++
  6020. Routine Description:
  6021. Determines the display type for CL754x crt/panel controllers.
  6022. Arguments:
  6023. HwDeviceExtension - Pointer to the miniport driver's device extension.
  6024. CRTCAddrPort, CRTCDataPort - Index of CRTC registers for current mode.
  6025. Return Value:
  6026. crt, panel, or panel8x6 LCD_type as defined in cirrus.h
  6027. --*/
  6028. {
  6029. UCHAR originalCRTCIndex, originalLCDControl;
  6030. USHORT temp1, temp2, temp3;
  6031. // we need to check to see which display we are on...
  6032. //
  6033. originalCRTCIndex = VideoPortReadPortUchar(CRTCAddrPort);
  6034. VideoPortWritePortUchar(CRTCAddrPort, 0x80);
  6035. temp3 = 0;
  6036. if (VideoPortReadPortUchar(CRTCDataPort) & 0x02) temp3 = crt;
  6037. if (!(VideoPortReadPortUchar(CRTCDataPort) & 0x01)) //myf27
  6038. temp3 |= Jump_type; //myf27
  6039. else temp3 &= (~Jump_type); //myf27, myf28
  6040. //myf27 if (VideoPortReadPortUchar(CRTCDataPort) & 0x01)
  6041. {
  6042. // bit 0 set indicates that display is on LCD Panel
  6043. // Check extended reg to see panel data format
  6044. //
  6045. VideoPortWritePortUchar (CRTCAddrPort, 0x83);
  6046. originalLCDControl = VideoPortReadPortUchar(CRTCDataPort);
  6047. temp1 = originalLCDControl & 0x03;
  6048. // check LCD support mode
  6049. // CR83 bit 6:4 set indicate LCD type, TFT, DSTN color
  6050. temp2 = originalLCDControl & 0x70;
  6051. // temp3 = crt; //myf7, crus
  6052. if (temp2 == 0) //DSTN color LCD
  6053. {
  6054. temp3 |= Dual_LCD | Color_LCD | STN_LCD;
  6055. }
  6056. else if (temp2 == 0x20) //TFT color LCD
  6057. temp3 |= (USHORT)TFT_LCD;
  6058. // Restore CRTC index to original state
  6059. //
  6060. VideoPortWritePortUchar(CRTCAddrPort, originalCRTCIndex);
  6061. if (temp1 == 1) // this means panel connected is 800x600
  6062. {
  6063. // will support either 800x600 or 640x480
  6064. return (temp3 | panel8x6);
  6065. }
  6066. else if (temp1 == 2)
  6067. {
  6068. return (temp3 | panel10x7);
  6069. }
  6070. else
  6071. {
  6072. return (temp3 | panel);
  6073. }
  6074. }
  6075. //myf27 else // the display is a crt
  6076. //myf27 {
  6077. //myf27 VideoPortWritePortUchar(CRTCAddrPort, originalCRTCIndex);
  6078. //myf27 return crt;
  6079. //myf27 }
  6080. } // CirrusFind755xDisplayType()
  6081. //---------------------------------------------------------------------------
  6082. BOOLEAN
  6083. CirrusFind6340(
  6084. PHW_DEVICE_EXTENSION HwDeviceExtension
  6085. )
  6086. /*++
  6087. Routine Description:
  6088. Determines if a CL6340 (Peacock) Color LCD controller is in the system
  6089. along with a 6410 or 6420.
  6090. Assumes that a 6410 or 6420 is already in the system.
  6091. Arguments:
  6092. HwDeviceExtension - Pointer to the miniport driver's device extension.
  6093. Return Value:
  6094. TRUE, 6340 detected
  6095. FALSE, 6340 not detected
  6096. --*/
  6097. {
  6098. UCHAR originalGraphicsIndex;
  6099. UCHAR originalSRIndex;
  6100. UCHAR GRA1value;
  6101. UCHAR temp1,temp2;
  6102. originalGraphicsIndex =
  6103. VideoPortReadPortUchar((HwDeviceExtension->IOAddress +
  6104. GRAPH_ADDRESS_PORT));
  6105. originalSRIndex =
  6106. VideoPortReadPortUchar((HwDeviceExtension->IOAddress +
  6107. SEQ_ADDRESS_PORT));
  6108. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  6109. GRAPH_ADDRESS_PORT, CL64xx_TRISTATE_CONTROL_REG);
  6110. GRA1value = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  6111. GRAPH_DATA_PORT);
  6112. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  6113. GRAPH_DATA_PORT, (UCHAR) (0x80 | GRA1value));
  6114. VideoPortWritePortUshort((PUSHORT)(HwDeviceExtension->IOAddress +
  6115. SEQ_ADDRESS_PORT), (USHORT) CL6340_ENABLE_READBACK_REGISTER +
  6116. (CL6340_ENABLE_READBACK_ALLSEL_VALUE << 8));
  6117. VideoPortWritePortUchar((HwDeviceExtension->IOAddress +
  6118. SEQ_ADDRESS_PORT), CL6340_IDENTIFICATION_REGISTER);
  6119. temp1 = VideoPortReadPortUchar((HwDeviceExtension->IOAddress +
  6120. SEQ_DATA_PORT));
  6121. temp2 = VideoPortReadPortUchar((HwDeviceExtension->IOAddress +
  6122. SEQ_DATA_PORT));
  6123. VideoPortWritePortUshort((PUSHORT)(HwDeviceExtension->IOAddress +
  6124. SEQ_ADDRESS_PORT), (USHORT) CL6340_ENABLE_READBACK_REGISTER +
  6125. (CL6340_ENABLE_READBACK_OFF_VALUE << 8));
  6126. // Graphics index still points to CL64xx_TRISTATE_CONTROL_REG
  6127. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  6128. GRAPH_DATA_PORT, (UCHAR) (0x7f & GRA1value));
  6129. // now restore the Graphics and Sequencer indexes
  6130. VideoPortWritePortUchar((HwDeviceExtension->IOAddress +
  6131. GRAPH_ADDRESS_PORT),originalGraphicsIndex);
  6132. VideoPortWritePortUchar((HwDeviceExtension->IOAddress +
  6133. SEQ_ADDRESS_PORT),originalSRIndex);
  6134. // check the values for value peacock data
  6135. if ( ((temp1 & 0xf0) == 0x70 && (temp2 & 0xf0) == 0x80) ||
  6136. ((temp1 & 0xf0) == 0x80 && (temp2 & 0xf0) == 0x70) )
  6137. return TRUE;
  6138. else
  6139. return FALSE;
  6140. } // CirrusFind6410DisplayType()
  6141. BOOLEAN
  6142. CirrusConfigurePCI(
  6143. PHW_DEVICE_EXTENSION HwDeviceExtension,
  6144. PULONG NumPCIAccessRanges,
  6145. PVIDEO_ACCESS_RANGE PCIAccessRanges
  6146. )
  6147. {
  6148. USHORT VendorId = 0x1013; // Vender Id for Cirrus Logic
  6149. //
  6150. // The device id order is important. We want "most powerful"
  6151. // first on the assumption that someone might want to plug
  6152. // in a "more powerful" adapter into a system that has a "less
  6153. // powerful" on-board device.
  6154. //
  6155. USHORT DeviceId[] = {0x00BC, // 5480
  6156. 0x00B8, // 5446
  6157. 0x00AC, // 5436
  6158. 0x00E8, // UM36
  6159. 0x00A8, // 5434
  6160. 0x00A0, // 5430/5440
  6161. 0x1200, // Nordic
  6162. 0x1202, // Viking
  6163. 0x1204, // Nordic Light
  6164. 0x0038, // Everest, myf14, crus
  6165. 0x0040, // Matterhorn
  6166. 0x004C, // Matterhorn, LV, myf17
  6167. 0};
  6168. ULONG Slot;
  6169. ULONG ulRet;
  6170. PUSHORT pDeviceId;
  6171. VP_STATUS status;
  6172. UCHAR Command;
  6173. PCI_COMMON_CONFIG pciBuffer; // jl02
  6174. PPCI_COMMON_CONFIG pciData; // jl02
  6175. VIDEO_ACCESS_RANGE AccessRanges[3];
  6176. VideoPortZeroMemory(AccessRanges, 3 * sizeof(VIDEO_ACCESS_RANGE));
  6177. pDeviceId = DeviceId;
  6178. while (*pDeviceId != 0)
  6179. {
  6180. Slot = 0;
  6181. status = VideoPortGetAccessRanges(HwDeviceExtension,
  6182. 0,
  6183. NULL,
  6184. 3,
  6185. AccessRanges,
  6186. &VendorId,
  6187. pDeviceId,
  6188. &Slot);
  6189. if (status == NO_ERROR)
  6190. {
  6191. VideoDebugPrint((2, "\t Found Cirrus chip in Slot[0x%02.2x]\n",
  6192. Slot));
  6193. PCIAccessRanges[3].RangeStart = AccessRanges[0].RangeStart;
  6194. PCIAccessRanges[3].RangeLength = AccessRanges[0].RangeLength;
  6195. VideoDebugPrint((1, "VideoMemoryAddress %x , length %x\n",
  6196. PCIAccessRanges[3].RangeStart.LowPart,
  6197. PCIAccessRanges[3].RangeLength));
  6198. // sge01 begin
  6199. //
  6200. // checking CL5480 or CL5446BE
  6201. //
  6202. pciData = (PPCI_COMMON_CONFIG) &pciBuffer;
  6203. VideoPortGetBusData(HwDeviceExtension,
  6204. PCIConfiguration,
  6205. Slot,
  6206. (PVOID) pciData,
  6207. 0,
  6208. PCI_COMMON_HDR_LENGTH);
  6209. #if (_WIN32_WINNT >= 0x0400)
  6210. if ((pciData->DeviceID == 0x00B8 && pciData->RevisionID == 0x45)
  6211. || (pciData->DeviceID == 0x00BC))
  6212. {
  6213. HwDeviceExtension->bMMAddress = TRUE;
  6214. HwDeviceExtension->bSecondAperture = TRUE;
  6215. PCIAccessRanges[4].RangeStart = AccessRanges[1].RangeStart;
  6216. PCIAccessRanges[4].RangeLength = AccessRanges[1].RangeLength;
  6217. VideoDebugPrint((1, "MMIOMemoryAddress %x , length %x\n",
  6218. PCIAccessRanges[2].RangeStart.LowPart,
  6219. PCIAccessRanges[2].RangeLength));
  6220. //
  6221. // Assign pfnVideoPortReadXxx and pfnVideoPortWriteXxx
  6222. //
  6223. HwDeviceExtension->gPortRWfn.pfnVideoPortReadPortUchar = VideoPortReadRegisterUchar;
  6224. HwDeviceExtension->gPortRWfn.pfnVideoPortReadPortUshort = VideoPortReadRegisterUshort;
  6225. HwDeviceExtension->gPortRWfn.pfnVideoPortReadPortUlong = VideoPortReadRegisterUlong;
  6226. HwDeviceExtension->gPortRWfn.pfnVideoPortWritePortUchar = VideoPortWriteRegisterUchar;
  6227. HwDeviceExtension->gPortRWfn.pfnVideoPortWritePortUshort = VideoPortWriteRegisterUshort;
  6228. HwDeviceExtension->gPortRWfn.pfnVideoPortWritePortUlong = VideoPortWriteRegisterUlong;
  6229. }
  6230. #else // else of NT 4.0
  6231. if ((pciData->DeviceID == 0x00BC) ||
  6232. ((pciData->DeviceID == 0x00B8) && (pciData->RevisionID == 0x45)))
  6233. {
  6234. HwDeviceExtension->bMMAddress = FALSE;
  6235. HwDeviceExtension->bSecondAperture = TRUE;
  6236. //
  6237. //
  6238. // Assign pfnVideoPortReadXxx and pfnVideoPortWriteXxx
  6239. //
  6240. HwDeviceExtension->gPortRWfn.pfnVideoPortReadPortUchar = VideoPortReadPortUchar;
  6241. HwDeviceExtension->gPortRWfn.pfnVideoPortReadPortUshort = VideoPortReadPortUshort;
  6242. HwDeviceExtension->gPortRWfn.pfnVideoPortReadPortUlong = VideoPortReadPortUlong;
  6243. HwDeviceExtension->gPortRWfn.pfnVideoPortWritePortUchar = VideoPortWritePortUchar;
  6244. HwDeviceExtension->gPortRWfn.pfnVideoPortWritePortUshort = VideoPortWritePortUshort;
  6245. HwDeviceExtension->gPortRWfn.pfnVideoPortWritePortUlong = VideoPortWritePortUlong;
  6246. }
  6247. #endif // end of NT 4.0
  6248. else
  6249. {
  6250. HwDeviceExtension->bMMAddress = FALSE;
  6251. HwDeviceExtension->bSecondAperture = FALSE;
  6252. //
  6253. // Assign pfnVideoPortReadXxx and pfnVideoPortWriteXxx
  6254. //
  6255. HwDeviceExtension->gPortRWfn.pfnVideoPortReadPortUchar = VideoPortReadPortUchar;
  6256. HwDeviceExtension->gPortRWfn.pfnVideoPortReadPortUshort = VideoPortReadPortUshort;
  6257. HwDeviceExtension->gPortRWfn.pfnVideoPortReadPortUlong = VideoPortReadPortUlong;
  6258. HwDeviceExtension->gPortRWfn.pfnVideoPortWritePortUchar = VideoPortWritePortUchar;
  6259. HwDeviceExtension->gPortRWfn.pfnVideoPortWritePortUshort = VideoPortWritePortUshort;
  6260. HwDeviceExtension->gPortRWfn.pfnVideoPortWritePortUlong = VideoPortWritePortUlong;
  6261. }
  6262. VideoDebugPrint((1, "Read Write Functions are mapped"));
  6263. //sge01 end
  6264. return TRUE;
  6265. }
  6266. else
  6267. {
  6268. //
  6269. // We did not find the device. Use the next device ID.
  6270. //
  6271. VideoDebugPrint((1, "Check for DeviceID = %x failed.\n", *pDeviceId));
  6272. pDeviceId++;
  6273. }
  6274. }
  6275. VideoDebugPrint((1, "Returning a false from CirrusConfigurePCI\n"));
  6276. return FALSE;
  6277. }
  6278. VOID
  6279. WriteRegistryInfo(
  6280. PHW_DEVICE_EXTENSION hwDeviceExtension
  6281. )
  6282. {
  6283. PWSTR pwszChipType;
  6284. ULONG cbString;
  6285. PWSTR pnpId;
  6286. //
  6287. // Store Memory Size
  6288. //
  6289. VideoPortSetRegistryParameters(hwDeviceExtension,
  6290. L"HardwareInformation.MemorySize",
  6291. &hwDeviceExtension->AdapterMemorySize,
  6292. sizeof(ULONG));
  6293. //
  6294. // Store chip Type
  6295. //
  6296. switch (hwDeviceExtension->ChipType)
  6297. {
  6298. case CL6410: pwszChipType = L"Cirrus Logic 6410";
  6299. cbString = sizeof(L"Cirrus Logic 6410");
  6300. pnpId = L"*PNP0904";
  6301. break;
  6302. case CL6420: pwszChipType = L"Cirrus Logic 6420";
  6303. cbString = sizeof(L"Cirrus Logic 6420");
  6304. pnpId = L"*PNP0904";
  6305. break;
  6306. case CL542x: if (hwDeviceExtension->ChipRevision >= 0x22 &&
  6307. hwDeviceExtension->ChipRevision <= 0x27)
  6308. {
  6309. static PWSTR RevTable[] = { L"Cirrus Logic 5420",
  6310. L"Cirrus Logic 5422",
  6311. L"Cirrus Logic 5426", // yes, the 26
  6312. L"Cirrus Logic 5424", // is before
  6313. L"Cirrus Logic 5428", // the 24
  6314. L"Cirrus Logic 5429" };
  6315. pwszChipType =
  6316. RevTable[hwDeviceExtension->ChipRevision - 0x22];
  6317. }
  6318. else
  6319. {
  6320. pwszChipType = L"Cirrus Logic 542x";
  6321. }
  6322. cbString = sizeof(L"Cirrus Logic 542x");
  6323. pnpId = L"*PNP0904";
  6324. break;
  6325. case CL543x: if (hwDeviceExtension->ChipRevision == CL5430_ID)
  6326. {
  6327. pwszChipType = L"Cirrus Logic 5430/40"; // chu04
  6328. cbString = sizeof(L"Cirrus Logic 5430/40"); // chu04
  6329. }
  6330. else
  6331. {
  6332. pwszChipType = L"Cirrus Logic 543x";
  6333. cbString = sizeof(L"Cirrus Logic 543x");
  6334. }
  6335. pnpId = L"*PNP0905";
  6336. break;
  6337. case CL5434_6:
  6338. pwszChipType = L"Cirrus Logic 5434 (.6 micron)";
  6339. cbString = sizeof(L"Cirrus Logic 5434 (.6 micron)");
  6340. pnpId = L"*PNP0905";
  6341. break;
  6342. case CL5434: pwszChipType = L"Cirrus Logic 5434";
  6343. cbString = sizeof(L"Cirrus Logic 5434");
  6344. pnpId = L"*PNP0905";
  6345. break;
  6346. case CL5436: pwszChipType = L"Cirrus Logic 5436";
  6347. cbString = sizeof(L"Cirrus Logic 5436");
  6348. pnpId = L"*PNP0905";
  6349. break;
  6350. case CL5446: pwszChipType = L"Cirrus Logic 5446";
  6351. cbString = sizeof(L"Cirrus Logic 5446");
  6352. pnpId = L"*PNP0905";
  6353. break;
  6354. #if 1 // jl02
  6355. case CL5446BE:
  6356. pwszChipType = L"Cirrus Logic 5446BE";
  6357. cbString = sizeof(L"Cirrus Logic 5446BE");
  6358. pnpId = L"*PNP0905";
  6359. break;
  6360. #endif // jl02
  6361. case CL5480: pwszChipType = L"Cirrus Logic 5480";
  6362. cbString = sizeof(L"Cirrus Logic 5480");
  6363. pnpId = L"*PNP0905";
  6364. break;
  6365. //myf32 begin
  6366. case CL7541: pwszChipType = L"Cirrus Logic 7541";
  6367. cbString = sizeof(L"Cirrus Logic 7541");
  6368. pnpId = L"*PNP0914";
  6369. break;
  6370. case CL7542: pwszChipType = L"Cirrus Logic 7542";
  6371. cbString = sizeof(L"Cirrus Logic 7542");
  6372. pnpId = L"*PNP0914";
  6373. break;
  6374. case CL7543: pwszChipType = L"Cirrus Logic 7543";
  6375. cbString = sizeof(L"Cirrus Logic 7543");
  6376. pnpId = L"*PNP0914";
  6377. break;
  6378. case CL7548: pwszChipType = L"Cirrus Logic 7548";
  6379. cbString = sizeof(L"Cirrus Logic 7548");
  6380. pnpId = L"*PNP0914";
  6381. break;
  6382. case CL7555: pwszChipType = L"Cirrus Logic 7555";
  6383. cbString = sizeof(L"Cirrus Logic 7555");
  6384. pnpId = L"*PNP0914";
  6385. break;
  6386. case CL7556: pwszChipType = L"Cirrus Logic 7556";
  6387. cbString = sizeof(L"Cirrus Logic 7556");
  6388. pnpId = L"*PNP0914";
  6389. break;
  6390. //myf32
  6391. case CL756x: pwszChipType = L"Cirrus Logic 756x";
  6392. cbString = sizeof(L"Cirrus Logic 756x");
  6393. pnpId = L"*PNP0914";
  6394. break;
  6395. // crus
  6396. case CL6245: pwszChipType = L"Cirrus Logic 6245";
  6397. cbString = sizeof(L"Cirrus Logic 6245");
  6398. pnpId = L"*PNP0904";
  6399. break;
  6400. default:
  6401. //
  6402. // we should never get here
  6403. //
  6404. ASSERT(FALSE);
  6405. pwszChipType = NULL;
  6406. cbString = 0;
  6407. pnpId = NULL;
  6408. }
  6409. if (pnpId)
  6410. {
  6411. memcpy(hwDeviceExtension->LegacyPnPId, pnpId, 8*sizeof(WCHAR));
  6412. }
  6413. VideoPortSetRegistryParameters(hwDeviceExtension,
  6414. L"HardwareInformation.ChipType",
  6415. pwszChipType,
  6416. cbString);
  6417. //
  6418. // Store Adapter String
  6419. //
  6420. // the only interesting adapter string is
  6421. // for the speedstar pro
  6422. //
  6423. VideoPortSetRegistryParameters(hwDeviceExtension,
  6424. L"HardwareInformation.DacType",
  6425. L"Integrated RAMDAC",
  6426. sizeof(L"Integrated RAMDAC") );
  6427. if( hwDeviceExtension->BoardType == SPEEDSTARPRO )
  6428. {
  6429. VideoPortSetRegistryParameters(hwDeviceExtension,
  6430. L"HardwareInformation.AdapterString",
  6431. L"SpeedStar PRO",
  6432. sizeof(L"SpeedStar PRO"));
  6433. }
  6434. else
  6435. {
  6436. VideoPortSetRegistryParameters(hwDeviceExtension,
  6437. L"HardwareInformation.AdapterString",
  6438. L"Cirrus Logic Compatible",
  6439. sizeof (L"Cirrus Logic Compatible") );
  6440. }
  6441. }
  6442. VOID
  6443. IOWaitDisplEnableThenWrite(
  6444. PHW_DEVICE_EXTENSION hwDeviceExtension,
  6445. ULONG portIO,
  6446. UCHAR value
  6447. )
  6448. {
  6449. PHW_DEVICE_EXTENSION HwDeviceExtension = hwDeviceExtension;
  6450. USHORT FCReg ; // feature control register
  6451. UCHAR PSReg ; // 3?4.25
  6452. UCHAR DeviceID ; // 3?4.27
  6453. UCHAR bIsColor ; // 1 : Color, 0 : Mono
  6454. UCHAR tempB, tempB1 ;
  6455. ULONG port ;
  6456. PUCHAR CRTCAddrPort, CRTCDataPort;
  6457. // Figure out if color/mono switchable registers are at 3BX or 3DX.
  6458. port = PtrToUlong(hwDeviceExtension->IOAddress) + portIO ;
  6459. tempB = VideoPortReadPortUchar (hwDeviceExtension->IOAddress +
  6460. MISC_OUTPUT_REG_READ_PORT) ;
  6461. tempB &= 0x01 ;
  6462. if (tempB)
  6463. {
  6464. bIsColor = TRUE ;
  6465. FCReg = FEAT_CTRL_WRITE_PORT_COLOR ;
  6466. CRTCAddrPort = hwDeviceExtension->IOAddress + CRTC_ADDRESS_PORT_COLOR;
  6467. }
  6468. else
  6469. {
  6470. bIsColor = FALSE ;
  6471. FCReg = FEAT_CTRL_WRITE_PORT_MONO ;
  6472. CRTCAddrPort = hwDeviceExtension->IOAddress + CRTC_ADDRESS_PORT_MONO;
  6473. }
  6474. CRTCDataPort = CRTCAddrPort + 1;
  6475. tempB = VideoPortReadPortUchar(CRTCAddrPort);
  6476. VideoPortWritePortUchar(CRTCAddrPort, 0x27);
  6477. DeviceID = VideoPortReadPortUchar(CRTCDataPort);
  6478. VideoPortWritePortUchar(CRTCAddrPort, 0x25);
  6479. PSReg = VideoPortReadPortUchar(CRTCDataPort);
  6480. VideoPortWritePortUchar (CRTCAddrPort, tempB);
  6481. if ((DeviceID == 0xAC) && // 5436
  6482. ((PSReg == 0x45) || (PSReg == 0x47))) // BG or BE
  6483. {
  6484. hwDeviceExtension->DEPort = portIO;
  6485. hwDeviceExtension->DEValue = value;
  6486. while (!(0x1 & VideoPortReadPortUchar(hwDeviceExtension->IOAddress + FCReg)));
  6487. while ( (0x1 & VideoPortReadPortUchar(hwDeviceExtension->IOAddress + FCReg)));
  6488. VideoPortSynchronizeExecution(hwDeviceExtension,
  6489. VpHighPriority,
  6490. (PMINIPORT_SYNCHRONIZE_ROUTINE) IOCallback,
  6491. hwDeviceExtension);
  6492. }
  6493. else
  6494. {
  6495. VideoPortWritePortUchar(hwDeviceExtension->IOAddress + portIO, value);
  6496. }
  6497. } // IOWaitDisplEnableThenWrite
  6498. //sge08
  6499. VOID
  6500. CirrusUpdate440FX(
  6501. PHW_DEVICE_EXTENSION HwDeviceExtension
  6502. )
  6503. /*++
  6504. Routine Description:
  6505. Check and Update 440FX PCI[53] bit 1 if necessary.
  6506. Arguments:
  6507. HwDeviceExtension - Pointer to the miniport driver's device extension.
  6508. Return Value:
  6509. The routine has no return.
  6510. --*/
  6511. {
  6512. USHORT chipRevisionId ;
  6513. UCHAR chipId ;
  6514. PUCHAR pBuffer;
  6515. ULONG Slot;
  6516. USHORT VendorId = 0x8086; // Vender Id for Intel
  6517. USHORT DeviceId = 0x1237; // VS440FX
  6518. VP_STATUS status;
  6519. PCI_COMMON_CONFIG pciBuffer;
  6520. PPCI_COMMON_CONFIG pciData;
  6521. chipId = GetCirrusChipId(HwDeviceExtension) ; // chu06
  6522. chipRevisionId = GetCirrusChipRevisionId(HwDeviceExtension) ; // chu06
  6523. if ((chipId == 0xB8) && // 5446
  6524. (chipRevisionId == 0x0023)) // AC
  6525. {
  6526. //
  6527. // We got it's 5446AC, then to find 440FX
  6528. //
  6529. pciData = (PPCI_COMMON_CONFIG)&pciBuffer;
  6530. for (Slot = 0; Slot < 32; Slot++)
  6531. {
  6532. // chu05
  6533. // For 5436 checked build NT, system always crashes when you
  6534. // access the whole 256-byte PCI configuration registers.
  6535. // Since we only care index 53h bit 1, we access 4 bytes, rather
  6536. // than whole 256 bytes.
  6537. VideoPortGetBusData(HwDeviceExtension,
  6538. PCIConfiguration,
  6539. Slot,
  6540. (PVOID) pciData,
  6541. 0,
  6542. sizeof(PCI_COMMON_HDR_LENGTH)); // chu05
  6543. if ((pciData->VendorID == VendorId) &&
  6544. (pciData->DeviceID == DeviceId))
  6545. {
  6546. //
  6547. // Access a double word, which contains index 53h.
  6548. //
  6549. VideoPortGetBusData(HwDeviceExtension,
  6550. PCIConfiguration,
  6551. Slot,
  6552. (PVOID) pciData,
  6553. 0x53,
  6554. 0x04); // chu05
  6555. // We borrow the space which is the first 4 bytes of PCI
  6556. // configuration register. Please be aware that, at this
  6557. // moment, the content is index 53h, rather than
  6558. // vendor ID.
  6559. pciBuffer.DeviceSpecific[19] =
  6560. (UCHAR) pciData->VendorID ; // chu05
  6561. //
  6562. // Found the Intel VS440FX motherboard.
  6563. //
  6564. //
  6565. // Clear bit 1 of Register 0x53
  6566. //
  6567. pciBuffer.DeviceSpecific[19] &= 0xFD;
  6568. //
  6569. // Write Register 0x53 back.
  6570. //
  6571. pBuffer = (PUCHAR)&pciBuffer;
  6572. pBuffer += 0x53;
  6573. VideoPortSetBusData(HwDeviceExtension,
  6574. PCIConfiguration,
  6575. Slot,
  6576. (PVOID) pBuffer,
  6577. 0x53,
  6578. 1);
  6579. //
  6580. // Read back only 4 bytes to verify it.
  6581. //
  6582. VideoPortGetBusData(HwDeviceExtension,
  6583. PCIConfiguration,
  6584. Slot,
  6585. (PVOID) pciData,
  6586. 0x53,
  6587. 0x04); // chu05
  6588. break; // we have already modify it
  6589. }
  6590. }
  6591. }
  6592. }
  6593.