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.

727 lines
17 KiB

  1. /*++
  2. Copyright (c) 1996-1997 Microsoft Corporation.
  3. Copyright (c) 1996-1997 Cirrus Logic, Inc.,
  4. Module Name:
  5. C A L L B A C K . C
  6. Abstract:
  7. This routine contains various callback routines. e.g.,
  8. - Gamma correction information from the following NT 4.0 registry.
  9. Registry subdirectory : System\CurrentControlSet\Services\cirrus\Device0
  10. Keys : "G Gamma", and "G Contrast"
  11. - Callback routines for the DDC and Non-DDC monitors.
  12. - IBM specific callback routine to get rid of 1024x768x16bpp 85Hz.
  13. Registry subdirectory : System\CurrentControlSet\Services\cirrus\Device0
  14. Keys : "OemModeOff"
  15. Environment:
  16. Kernel mode only
  17. Notes:
  18. *
  19. * chu01 12-16-96 : Color correction start coding.
  20. * chu02 03-26-97 : Get rid of 1024x768x16bpp ( Mode 0x74 ) 85H for IBM only.
  21. *
  22. *
  23. --*/
  24. //---------------------------------------------------------------------------
  25. // HEADER FILES
  26. //---------------------------------------------------------------------------
  27. //#include <ntddk.h>
  28. #include <dderror.h>
  29. #include <devioctl.h>
  30. #include <miniport.h> // I added
  31. #include "clmini.h"
  32. #include <ntddvdeo.h>
  33. #include <video.h>
  34. #include "cirrus.h"
  35. extern UCHAR EDIDBuffer[] ;
  36. //---------------------------------------------------------------------------
  37. // FUNCTION PROTOTYPE
  38. //---------------------------------------------------------------------------
  39. VP_STATUS
  40. VgaGetGammaFactor(
  41. PHW_DEVICE_EXTENSION HwDeviceExtension,
  42. PGAMMA_VALUE value,
  43. ULONG ValueLength,
  44. PULONG OutputSize
  45. );
  46. VP_STATUS
  47. VgaGetContrastFactor(
  48. PHW_DEVICE_EXTENSION HwDeviceExtension,
  49. PCONTRAST_VALUE value,
  50. ULONG ValueLength,
  51. PULONG OutputSize
  52. );
  53. VP_STATUS GetGammaKeyInfoFromReg(
  54. PHW_DEVICE_EXTENSION HwDeviceExtension
  55. ) ;
  56. VP_STATUS GetContrastKeyInfoFromReg(
  57. PHW_DEVICE_EXTENSION HwDeviceExtension
  58. ) ;
  59. VP_STATUS GetGammaCorrectInfoCallBack (
  60. PVOID HwDeviceExtension,
  61. PVOID Context,
  62. PWSTR ValueName,
  63. PVOID ValueData,
  64. ULONG ValueLength
  65. ) ;
  66. VP_STATUS
  67. CirrusDDC2BRegistryCallback(
  68. PVOID HwDeviceExtension,
  69. PVOID Context,
  70. PWSTR ValueName,
  71. PVOID ValueData,
  72. ULONG ValueLength
  73. );
  74. VP_STATUS
  75. CirrusNonDDCRegistryCallback(
  76. PVOID HwDeviceExtension,
  77. PVOID Context,
  78. PWSTR ValueName,
  79. PVOID ValueData,
  80. ULONG ValueLength
  81. );
  82. BOOLEAN
  83. IOCallback(
  84. PHW_DEVICE_EXTENSION HwDeviceExtension
  85. ) ;
  86. VP_STATUS
  87. CirrusGetDeviceDataCallback(
  88. PVOID HwDeviceExtension,
  89. PVOID Context,
  90. VIDEO_DEVICE_DATA_TYPE DeviceDataType,
  91. PVOID Identifier,
  92. ULONG IdentifierLength,
  93. PVOID ConfigurationData,
  94. ULONG ConfigurationDataLength,
  95. PVOID ComponentInformation,
  96. ULONG ComponentInformationLength
  97. );
  98. // chu02
  99. VP_STATUS
  100. GetOemModeOffInfoCallBack (
  101. PVOID HwDeviceExtension,
  102. PVOID Context,
  103. PWSTR ValueName,
  104. PVOID ValueData,
  105. ULONG ValueLength
  106. );
  107. #if defined(ALLOC_PRAGMA)
  108. #pragma alloc_text(PAGE,GetGammaKeyInfoFromReg)
  109. #pragma alloc_text(PAGE,GetContrastKeyInfoFromReg)
  110. #pragma alloc_text(PAGE,GetGammaCorrectInfoCallBack)
  111. #pragma alloc_text(PAGE,VgaGetGammaFactor)
  112. #pragma alloc_text(PAGE,VgaGetContrastFactor)
  113. #pragma alloc_text(PAGE,CirrusDDC2BRegistryCallback)
  114. #pragma alloc_text(PAGE,CirrusNonDDCRegistryCallback)
  115. #pragma alloc_text(PAGE,CirrusGetDeviceDataCallback)
  116. #pragma alloc_text(PAGE,GetOemModeOffInfoCallBack) // chu02
  117. #endif
  118. UCHAR GammaInfo[4] ;
  119. UCHAR ModesExclude[4] ; // chu02
  120. OEMMODE_EXCLUDE ModeExclude = { 0, 0, 1 } ; // chu02
  121. //---------------------------------------------------------------------------
  122. //
  123. // Function: Get Gamma factor
  124. //
  125. // Input:
  126. // None
  127. //
  128. // Output:
  129. // NO_ERROR: successful; otherwise: fail
  130. //
  131. //---------------------------------------------------------------------------
  132. VP_STATUS VgaGetGammaFactor(
  133. PHW_DEVICE_EXTENSION HwDeviceExtension,
  134. PGAMMA_VALUE value,
  135. ULONG ValueLength,
  136. PULONG OutputSize
  137. )
  138. {
  139. VP_STATUS status ;
  140. int i ;
  141. VideoDebugPrint((2, "VgaGetGammaFactor\n")) ;
  142. if ( ValueLength < (*OutputSize = sizeof(PGAMMA_VALUE)) )
  143. return ERROR_INSUFFICIENT_BUFFER;
  144. status = GetGammaKeyInfoFromReg(HwDeviceExtension) ;
  145. if (status == NO_ERROR)
  146. {
  147. for (i = 0; i < 4; i++)
  148. value->value[i] = GammaInfo[i] ;
  149. }
  150. else if (status == ERROR_INVALID_PARAMETER)
  151. {
  152. //
  153. // If no subkey exists, we assign the default value. Otherwise the
  154. // system would fail.
  155. //
  156. for (i = 0; i < 4; i++)
  157. value->value[i] = 0x7f ;
  158. status = NO_ERROR ;
  159. }
  160. VideoDebugPrint((1, "Gamma value = %lx\n", *value)) ;
  161. return status ;
  162. } // VgaGetGammaFactor
  163. //---------------------------------------------------------------------------
  164. //
  165. // Function: Get Contrast factor
  166. //
  167. // Input:
  168. // None
  169. //
  170. // Output:
  171. // NO_ERROR: successful; otherwise: fail
  172. //
  173. //---------------------------------------------------------------------------
  174. VP_STATUS VgaGetContrastFactor(
  175. PHW_DEVICE_EXTENSION HwDeviceExtension,
  176. PCONTRAST_VALUE value,
  177. ULONG ValueLength,
  178. PULONG OutputSize
  179. )
  180. {
  181. VP_STATUS status ;
  182. int i ;
  183. VideoDebugPrint((2, "VgaGetContrastFactor\n")) ;
  184. if ( ValueLength < (*OutputSize = sizeof(PCONTRAST_VALUE)) ) {
  185. return ERROR_INSUFFICIENT_BUFFER;
  186. }
  187. status = GetContrastKeyInfoFromReg(HwDeviceExtension) ;
  188. if (status == NO_ERROR)
  189. {
  190. for (i = 0; i < 4; i++)
  191. value->value[i] = GammaInfo[i] ;
  192. }
  193. else if (status == ERROR_INVALID_PARAMETER)
  194. {
  195. //
  196. // If no subkey exists, we assign the default value. Otherwise the
  197. // system would fail.
  198. //
  199. for (i = 0; i < 4; i++)
  200. value->value[i] = 0x80 ;
  201. status = NO_ERROR ;
  202. }
  203. VideoDebugPrint((1, "Contrast value = %lx\n", *value)) ;
  204. return status ;
  205. } // VgaGetContrastFactor
  206. //---------------------------------------------------------------------------
  207. //
  208. // Function: Get Gamma Key information from data registry.
  209. //
  210. // Input:
  211. // None
  212. //
  213. // Output:
  214. // NO_ERROR: successful; otherwise: fail
  215. //
  216. //---------------------------------------------------------------------------
  217. VP_STATUS GetGammaKeyInfoFromReg(
  218. PHW_DEVICE_EXTENSION HwDeviceExtension
  219. )
  220. {
  221. VP_STATUS status ;
  222. VideoDebugPrint((2, "GetGammaKeyInfoFromReg\n")) ;
  223. status = VideoPortGetRegistryParameters(HwDeviceExtension,
  224. L"G Gamma",
  225. FALSE,
  226. GetGammaCorrectInfoCallBack,
  227. NULL) ;
  228. if (status != NO_ERROR)
  229. {
  230. VideoDebugPrint((1, "Fail to access Gamma key info from registry\n"));
  231. }
  232. return status ;
  233. } // GetGammaKeyInfoFromReg
  234. //---------------------------------------------------------------------------
  235. //
  236. // Function: Get Contrast Key information from data registry.
  237. //
  238. // Input:
  239. // None
  240. //
  241. // Output:
  242. // NO_ERROR: successful; otherwise: fail
  243. //
  244. //---------------------------------------------------------------------------
  245. VP_STATUS GetContrastKeyInfoFromReg(
  246. PHW_DEVICE_EXTENSION HwDeviceExtension
  247. )
  248. {
  249. VP_STATUS status ;
  250. VideoDebugPrint((2, "GetContrastKeyInfoFromReg\n")) ;
  251. status = VideoPortGetRegistryParameters(HwDeviceExtension,
  252. L"G Contrast",
  253. FALSE,
  254. GetGammaCorrectInfoCallBack,
  255. NULL) ;
  256. if (status != NO_ERROR)
  257. {
  258. VideoDebugPrint((1, "Fail to access Contrast key info from registry\n"));
  259. }
  260. return status ;
  261. } // GetContrastKeyInfoFromReg
  262. //---------------------------------------------------------------------------
  263. //
  264. // Function: Get Gamma coorrection information from data registry.
  265. //
  266. // Input:
  267. // None
  268. //
  269. // Output:
  270. // NO_ERROR: successful ; otherwise: fail
  271. //
  272. //---------------------------------------------------------------------------
  273. VP_STATUS
  274. GetGammaCorrectInfoCallBack (
  275. PVOID HwDeviceExtension,
  276. PVOID Context,
  277. PWSTR ValueName,
  278. PVOID ValueData,
  279. ULONG ValueLength
  280. )
  281. /*++
  282. Routine Description:
  283. This routine get the desired info from data registry.
  284. Arguments:
  285. HwDeviceExtension - Supplies a pointer to the miniport's device extension.
  286. Context - Context value passed to the get registry paramters routine.
  287. ValueName - Name of the value requested.
  288. ValueData - Pointer to the requested data.
  289. ValueLength - Length of the requested data.
  290. Return Value:
  291. returns NO_ERROR if the paramter was TRUE.
  292. returns ERROR_INVALID_PARAMETER otherwise.
  293. --*/
  294. {
  295. VideoDebugPrint((2, "GetGammaCorrectInfoCallBack\n"));
  296. if (ValueLength == 0x04)
  297. {
  298. VideoPortMoveMemory (GammaInfo, ValueData, ValueLength) ;
  299. return NO_ERROR ;
  300. }
  301. else
  302. {
  303. return ERROR_INVALID_PARAMETER ;
  304. }
  305. } // GetGammaCorrectInfoCallBack
  306. //---------------------------------------------------------------------------
  307. //
  308. // Function:
  309. //
  310. // Input:
  311. // None
  312. //
  313. // Output:
  314. // NO_ERROR: successful ; otherwise: fail
  315. //
  316. //---------------------------------------------------------------------------
  317. VP_STATUS
  318. CirrusDDC2BRegistryCallback(
  319. PVOID HwDeviceExtension,
  320. PVOID Context,
  321. PWSTR ValueName,
  322. PVOID ValueData,
  323. ULONG ValueLength
  324. )
  325. /*++
  326. Routine Description:
  327. This routine determines if the alternate register set was requested via
  328. the registry.
  329. Arguments:
  330. HwDeviceExtension - Supplies a pointer to the miniport's device extension.
  331. Context - Context value passed to the get registry paramters routine.
  332. ValueName - Name of the value requested.
  333. ValueData - Pointer to the requested data.
  334. ValueLength - Length of the requested data.
  335. Return Value:
  336. returns NO_ERROR if the paramter was TRUE.
  337. returns ERROR_INVALID_PARAMETER otherwise.
  338. --*/
  339. {
  340. PULONG pManuID = (PULONG)&EDIDBuffer[8];
  341. if (ValueLength &&
  342. ((*((PULONG)ValueData)) == *pManuID)) {
  343. return NO_ERROR;
  344. } else {
  345. return ERROR_INVALID_PARAMETER;
  346. }
  347. } // CirrusDDC2BRegistryCallback
  348. //---------------------------------------------------------------------------
  349. //
  350. // Function:
  351. // CirrusNonDDCRegistryCallback
  352. //
  353. // Input:
  354. // None
  355. //
  356. // Output:
  357. // NO_ERROR: successful ; otherwise: fail
  358. //
  359. //---------------------------------------------------------------------------
  360. VP_STATUS
  361. CirrusNonDDCRegistryCallback(
  362. PVOID HwDeviceExtension,
  363. PVOID Context,
  364. PWSTR ValueName,
  365. PVOID ValueData,
  366. ULONG ValueLength
  367. )
  368. /*++
  369. Routine Description:
  370. This routine determines if the alternate register set was requested via
  371. the registry.
  372. Arguments:
  373. HwDeviceExtension - Supplies a pointer to the miniport's device extension.
  374. Context - Context value passed to the get registry paramters routine.
  375. ValueName - Name of the value requested.
  376. ValueData - Pointer to the requested data.
  377. ValueLength - Length of the requested data.
  378. Return Value:
  379. returns NO_ERROR if the paramter was TRUE.
  380. returns ERROR_INVALID_PARAMETER otherwise.
  381. --*/
  382. {
  383. if(ValueLength &&
  384. ValueLength == 128 )
  385. {
  386. VideoPortMoveMemory(EDIDBuffer, ValueData, ValueLength);
  387. return NO_ERROR;
  388. }
  389. else
  390. return ERROR_INVALID_PARAMETER;
  391. } // CirrusNonDDCRegistryCallback
  392. //---------------------------------------------------------------------------
  393. //
  394. // Function:
  395. // Perform an IO operation during display enable.
  396. //
  397. // Input:
  398. // HwDeviceExtension - Pointer to the miniport driver's device extension.
  399. //
  400. // Output:
  401. // The routine always returns TRUE.
  402. //
  403. //---------------------------------------------------------------------------
  404. BOOLEAN
  405. IOCallback(
  406. PHW_DEVICE_EXTENSION HwDeviceExtension
  407. )
  408. {
  409. ULONG InputStatusReg;
  410. //
  411. // Figure out if color/mono switchable registers are at 3BX or 3DX.
  412. //
  413. if (VideoPortReadPortUchar (HwDeviceExtension->IOAddress +
  414. MISC_OUTPUT_REG_READ_PORT) & 0x01)
  415. InputStatusReg = INPUT_STATUS_1_COLOR;
  416. else
  417. InputStatusReg = INPUT_STATUS_1_MONO;
  418. //
  419. // Guarantee that the display is in display mode
  420. //
  421. while (0x1 & VideoPortReadPortUchar(HwDeviceExtension->IOAddress
  422. + InputStatusReg));
  423. //
  424. // Perform the IO operation
  425. //
  426. VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
  427. HwDeviceExtension->DEPort,
  428. HwDeviceExtension->DEValue);
  429. return TRUE;
  430. } // IOCallback
  431. // chu02
  432. //---------------------------------------------------------------------------
  433. //
  434. // Function: Get rid of one mode, specific to IBM only
  435. // - 1024x768x16bpp, 85Hz ( mode 0x74 )
  436. //
  437. // Input:
  438. // None
  439. //
  440. // Output:
  441. // NO_ERROR: successful ; otherwise: fail
  442. //
  443. //---------------------------------------------------------------------------
  444. VP_STATUS
  445. GetOemModeOffInfoCallBack (
  446. PVOID HwDeviceExtension,
  447. PVOID Context,
  448. PWSTR ValueName,
  449. PVOID ValueData,
  450. ULONG ValueLength
  451. )
  452. /*++
  453. Routine Description:
  454. This routine get the desired info from data registry.
  455. Arguments:
  456. HwDeviceExtension - Supplies a pointer to the miniport's device extension.
  457. Context - Context value passed to the get registry paramters routine.
  458. ValueName - Name of the value requested.
  459. ValueData - Pointer to the requested data.
  460. ValueLength - Length of the requested data.
  461. Return Value:
  462. returns NO_ERROR if the paramter was TRUE.
  463. returns ERROR_INVALID_PARAMETER otherwise.
  464. --*/
  465. {
  466. VideoDebugPrint((2, "GetOemModeOffInfoCallBack\n"));
  467. if (ValueLength == 0x04)
  468. {
  469. VideoPortMoveMemory (ModesExclude, ValueData, ValueLength) ;
  470. ModeExclude.refresh = (UCHAR)ModesExclude[0] ;
  471. ModeExclude.mode = (UCHAR)ModesExclude[1] ;
  472. return NO_ERROR ;
  473. }
  474. else
  475. {
  476. return ERROR_INVALID_PARAMETER ;
  477. }
  478. } // GetOemModeOffInfoCallBack
  479. //---------------------------------------------------------------------------
  480. //
  481. // Function:
  482. // Callback routine for the VideoPortGetDeviceData function.
  483. //
  484. // Input:
  485. // HwDeviceExtension - Pointer to the miniport drivers device extension.
  486. // Context - Context value passed to the VideoPortGetDeviceData function.
  487. // DeviceDataType - The type of data that was requested in
  488. // VideoPortGetDeviceData.
  489. // Identifier - Pointer to a string that contains the name of the device,
  490. // as setup by the ROM or ntdetect.
  491. // IdentifierLength - Length of the Identifier string.
  492. // ConfigurationData - Pointer to the configuration data for the device or
  493. // BUS.
  494. // ConfigurationDataLength - Length of the data in the configurationData
  495. // field.
  496. // ComponentInformation - Undefined.
  497. // ComponentInformationLength - Undefined.
  498. //
  499. // Output:
  500. // Returns NO_ERROR if the function completed properly.
  501. // Returns ERROR_DEV_NOT_EXIST if we did not find the device.
  502. // Returns ERROR_INVALID_PARAMETER otherwise.
  503. //
  504. //---------------------------------------------------------------------------
  505. VP_STATUS
  506. CirrusGetDeviceDataCallback(
  507. PVOID HwDeviceExtension,
  508. PVOID Context,
  509. VIDEO_DEVICE_DATA_TYPE DeviceDataType,
  510. PVOID Identifier,
  511. ULONG IdentifierLength,
  512. PVOID ConfigurationData,
  513. ULONG ConfigurationDataLength,
  514. PVOID ComponentInformation,
  515. ULONG ComponentInformationLength
  516. )
  517. /*++
  518. Routine Description:
  519. Arguments:
  520. HwDeviceExtension - Pointer to the miniport drivers device extension.
  521. Context - Context value passed to the VideoPortGetDeviceData function.
  522. DeviceDataType - The type of data that was requested in
  523. VideoPortGetDeviceData.
  524. Identifier - Pointer to a string that contains the name of the device,
  525. as setup by the ROM or ntdetect.
  526. IdentifierLength - Length of the Identifier string.
  527. ConfigurationData - Pointer to the configuration data for the device or
  528. BUS.
  529. ConfigurationDataLength - Length of the data in the configurationData
  530. field.
  531. ComponentInformation - Undefined.
  532. ComponentInformationLength - Undefined.
  533. Return Value:
  534. Returns NO_ERROR if the function completed properly.
  535. Returns ERROR_DEV_NOT_EXIST if we did not find the device.
  536. Returns ERROR_INVALID_PARAMETER otherwise.
  537. --*/
  538. {
  539. PWCHAR identifier = Identifier;
  540. PVIDEO_PORT_CONFIG_INFO ConfigInfo = (PVIDEO_PORT_CONFIG_INFO) Context;
  541. PHW_DEVICE_EXTENSION hwDeviceExtension = HwDeviceExtension;
  542. switch (DeviceDataType) {
  543. case VpMachineData:
  544. //
  545. // The caller assumes no-error mean that this machine was found, and
  546. // then memory mapped IO will be disabled.
  547. //
  548. // All other machine types must return an error.
  549. //
  550. if (VideoPortCompareMemory(L"TRICORDES",
  551. Identifier,
  552. sizeof(L"TRICORDES")) ==
  553. sizeof(L"TRICORDES"))
  554. {
  555. return NO_ERROR;
  556. }
  557. break;
  558. default:
  559. VideoDebugPrint((2, "Cirrus: callback has bad device type\n"));
  560. }
  561. return ERROR_INVALID_PARAMETER;
  562. } // CirrusGetDeviceDataCallback