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.

441 lines
9.1 KiB

  1. /*++
  2. Copyright (c) 1990-2000 Microsoft Corporation
  3. Module Name:
  4. vpdata.c
  5. Abstract:
  6. Global data module for the video port
  7. Author:
  8. Andre Vachon (andreva) 12-Jul-1997
  9. Environment:
  10. kernel mode only
  11. Notes:
  12. This module is a driver which implements OS dependant functions on the
  13. behalf of the video drivers
  14. Revision History:
  15. --*/
  16. #include "videoprt.h"
  17. //
  18. //
  19. // Data that is NOT pageable
  20. //
  21. //
  22. //
  23. // Globals to support HwResetHw function
  24. //
  25. VP_RESET_HW HwResetHw[6];
  26. //
  27. // Globals array of Fdos for debugging purpose
  28. //
  29. PFDO_EXTENSION FdoList[8];
  30. //
  31. // Head of Fdo list
  32. //
  33. PFDO_EXTENSION FdoHead = NULL;
  34. //
  35. // Debug Level for output routine (not pageable because VideoDebugPrint
  36. // can be called at raised irql.
  37. //
  38. ULONG VideoDebugLevel = 0;
  39. //
  40. // Variable used to so int10 support.
  41. //
  42. PEPROCESS CsrProcess = NULL;
  43. //
  44. // Bugcheck Reason Callback support
  45. //
  46. KBUGCHECK_REASON_CALLBACK_RECORD VpCallbackRecord;
  47. //
  48. // Pointer to bugcheck data buffer
  49. //
  50. PVOID VpBugcheckData;
  51. //
  52. // Device Object for the device which caused the bugcheck EA
  53. //
  54. PDEVICE_OBJECT VpBugcheckDeviceObject;
  55. //
  56. //
  57. // Data that IS pageable
  58. //
  59. //
  60. #if defined(ALLOC_PRAGMA)
  61. #pragma data_seg("PAGE_DATA")
  62. #endif
  63. //
  64. // EA recovery event and event handle
  65. //
  66. PKEVENT VpThreadStuckEvent = NULL;
  67. HANDLE VpThreadStuckEventHandle = NULL;
  68. //
  69. // The dump buffer fro EA recovery
  70. //
  71. PVOID VpDump = NULL;
  72. //
  73. // Global videoprt lock
  74. //
  75. KMUTEX VpGlobalLock;
  76. //
  77. // Are we running setup ? This will never change once set.
  78. //
  79. ULONG VpSetupTypeAtBoot = 0;
  80. //
  81. // Are we running setup ? This may change when we start I/O.
  82. //
  83. ULONG VpSetupType = 0;
  84. //
  85. // Used to do first time initialization of the video port.
  86. //
  87. BOOLEAN VPFirstTime = TRUE;
  88. //
  89. // Callbacks to win32k
  90. //
  91. PVIDEO_WIN32K_CALLOUT Win32kCallout = NULL;
  92. //
  93. // Disable USWC is case the machine does not work properly with it.
  94. //
  95. BOOLEAN EnableUSWC = TRUE;
  96. //
  97. // Maximal total amount of memory we'll lock down.
  98. //
  99. ULONG VideoPortMaxDmaSize = 0;
  100. //
  101. // Count to determine the number of video devices
  102. //
  103. ULONG VideoDeviceNumber = 0;
  104. ULONG VideoChildDevices = 0;
  105. //
  106. // Registry Class in which all video information is stored.
  107. //
  108. PWSTR VideoClassString = L"VIDEO";
  109. UNICODE_STRING VideoClassName = {10,12,L"VIDEO"};
  110. //
  111. // Global variables used to keep track of where controllers or peripherals
  112. // are found by IoQueryDeviceDescription
  113. //
  114. CONFIGURATION_TYPE VpQueryDeviceControllerType = DisplayController;
  115. CONFIGURATION_TYPE VpQueryDevicePeripheralType = MonitorPeripheral;
  116. ULONG VpQueryDeviceControllerNumber = 0;
  117. ULONG VpQueryDevicePeripheralNumber = 0;
  118. //
  119. // Global used to determine if we are running in BASEVIDEO mode.
  120. //
  121. // If we are, we don't want to generate a conflict for the VGA driver resources
  122. // if there is one.
  123. // We also want to write a volatile key in the registry indicating we booted
  124. // in beasevideo so the display driver loading code can handle it properly
  125. //
  126. BOOLEAN VpBaseVideo = FALSE;
  127. //
  128. // Pointer to physical memory. It is created during driver initialization
  129. // and is only closed when the driver is closed.
  130. //
  131. PVOID PhysicalMemorySection = NULL;
  132. //
  133. // Variable to determine if there is a ROM at physical address C0000 on which
  134. // we can do the int 10
  135. //
  136. ULONG VpC0000Compatible = 0;
  137. //
  138. // HwDeviceExtension of the VGA miniport driver, if it is loaded.
  139. //
  140. PVOID VgaHwDeviceExtension = NULL;
  141. //
  142. // Pointer to list of bus addresses for devices which have been assigned
  143. // resources.
  144. //
  145. PDEVICE_ADDRESS gDeviceAddressList;
  146. //
  147. // Store the amount of physical memory in the machine.
  148. //
  149. ULONGLONG VpSystemMemorySize;
  150. //
  151. // Store the device object that is the LCD panel for dimming and for
  152. // lid closure purposes.
  153. //
  154. PDEVICE_OBJECT LCDPanelDevice = NULL;
  155. //
  156. // LCD Panel Device Object Mutex
  157. //
  158. KMUTEX LCDPanelMutex;
  159. //
  160. // Int10 Mutex
  161. //
  162. KMUTEX VpInt10Mutex;
  163. //
  164. // Handle to PowerState callback
  165. //
  166. PVOID PowerStateCallbackHandle = NULL;
  167. //
  168. // Handle to Dock/Undock callback
  169. //
  170. PVOID DockCallbackHandle = NULL;
  171. //
  172. // Keep track of the number of devices which have started
  173. //
  174. ULONG NumDevicesStarted = 0;
  175. //
  176. // Use the new way of generating the registry path
  177. //
  178. BOOLEAN EnableNewRegistryKey = FALSE;
  179. //
  180. // We want to use the VGA driver during setup. We don't want any pre-installed
  181. // driver to work until after the VGA driver has been initialized. This way
  182. // if there is a bad PNP driver which won't work on the current OS, we have
  183. // time to replace it before trying to start it.
  184. //
  185. BOOLEAN VpSetupAllowDriversToStart = FALSE;
  186. //
  187. // Lets track whether or not any devices have had HwInitialize called on them
  188. // so that we can force legacy drivers to start after the system is initialized.
  189. //
  190. BOOLEAN VpSystemInitialized = FALSE;
  191. //
  192. // Track whether we are running AC or DC.
  193. //
  194. // By default, this will be true. If we are actually running on DC, when we boot,
  195. // VpPowerStateCallback will be called notifying us. If we are running on AC, we
  196. // will not be called. We will therefore assume AC and track the state in
  197. // VpSetLCDPowerUsage.
  198. //
  199. BOOLEAN VpRunningOnAC = TRUE;
  200. //
  201. // We track the state of the backlight in this structure.
  202. //
  203. BACKLIGHT_STATUS VpBacklightStatus;
  204. //
  205. // Most laptops respond incorrectly to HwSetPowerState calls
  206. // on lid close. By default, we will support the XP behavior
  207. // and not notify the miniport on lid close.
  208. //
  209. BOOLEAN VpLidCloseSetPower = FALSE;
  210. //
  211. // This structure describes to which ports access is required.
  212. //
  213. #define MEM_VGA 0xA0000
  214. #define MEM_VGA_SIZE 0x20000
  215. #define VGA_BASE_IO_PORT 0x000003B0
  216. #define VGA_START_BREAK_PORT 0x000003BB
  217. #define VGA_END_BREAK_PORT 0x000003C0
  218. #define VGA_MAX_IO_PORT 0x000003DF
  219. PVIDEO_ACCESS_RANGE VgaAccessRanges = NULL;
  220. ULONG NumVgaAccessRanges = 0;
  221. PDEVICE_OBJECT DeviceOwningVga = NULL;
  222. VIDEO_ACCESS_RANGE VgaLegacyResources[NUM_VGA_LEGACY_RESOURCES] = {
  223. {
  224. VGA_BASE_IO_PORT, 0x00000000,
  225. VGA_START_BREAK_PORT - VGA_BASE_IO_PORT+ 1,
  226. 1,
  227. 1,
  228. 1
  229. },
  230. {
  231. VGA_END_BREAK_PORT, 0x00000000,
  232. VGA_MAX_IO_PORT - VGA_END_BREAK_PORT + 1,
  233. 1,
  234. 1,
  235. 1
  236. },
  237. {
  238. MEM_VGA, 0x00000000,
  239. MEM_VGA_SIZE,
  240. 0,
  241. 1,
  242. 1
  243. }
  244. };
  245. //
  246. // Control Whether or not the bottom MEG of the CSR address space has
  247. // already been committed.
  248. //
  249. ULONG ServerBiosAddressSpaceInitialized = 0;
  250. BOOLEAN Int10BufferAllocated = FALSE;
  251. #if defined(_IA64_) || defined(_AMD64_)
  252. PUCHAR BiosTransferArea = NULL;
  253. #endif
  254. #if DBG
  255. CHAR *BusType[] = { "Internal",
  256. "Isa",
  257. "Eisa",
  258. "MicroChannel",
  259. "TurboChannel",
  260. "PCIBus",
  261. "VMEBus",
  262. "NuBus",
  263. "PCMCIABus",
  264. "CBus",
  265. "MPIBus",
  266. "MPSABus",
  267. "ProcessorInternal",
  268. "InternalPowerBus",
  269. "PNPISABus",
  270. "MaximumInterfaceType"
  271. };
  272. #endif
  273. PROC_ADDRESS VideoPortEntryPoints[] =
  274. {
  275. PROC(VideoPortDDCMonitorHelper),
  276. PROC(VideoPortDoDma),
  277. PROC(VideoPortGetCommonBuffer),
  278. PROC(VideoPortGetMdl),
  279. PROC(VideoPortLockPages),
  280. PROC(VideoPortSignalDmaComplete),
  281. PROC(VideoPortUnlockPages),
  282. PROC(VideoPortAssociateEventsWithDmaHandle),
  283. PROC(VideoPortGetBytesUsed),
  284. PROC(VideoPortSetBytesUsed),
  285. PROC(VideoPortGetDmaContext),
  286. PROC(VideoPortSetDmaContext),
  287. PROC(VideoPortMapDmaMemory),
  288. PROC(VideoPortUnmapDmaMemory),
  289. PROC(VideoPortGetAgpServices),
  290. PROC(VideoPortAllocateContiguousMemory),
  291. PROC(VideoPortGetRomImage),
  292. PROC(VideoPortGetAssociatedDeviceExtension),
  293. PROC(VideoPortGetAssociatedDeviceID),
  294. PROC(VideoPortAcquireDeviceLock),
  295. PROC(VideoPortReleaseDeviceLock),
  296. PROC(VideoPortAllocateBuffer),
  297. PROC(VideoPortFreeCommonBuffer),
  298. PROC(VideoPortMapDmaMemory),
  299. PROC(VideoPortReleaseBuffer),
  300. PROC(VideoPortInterlockedIncrement),
  301. PROC(VideoPortInterlockedDecrement),
  302. PROC(VideoPortInterlockedExchange),
  303. PROC(VideoPortGetVgaStatus),
  304. PROC(VideoPortQueueDpc),
  305. PROC(VideoPortEnumerateChildren),
  306. PROC(VideoPortQueryServices),
  307. PROC(VideoPortGetDmaAdapter),
  308. PROC(VideoPortPutDmaAdapter),
  309. PROC(VideoPortAllocateCommonBuffer),
  310. PROC(VideoPortReleaseCommonBuffer),
  311. PROC(VideoPortLockBuffer),
  312. PROC(VideoPortUnlockBuffer),
  313. PROC(VideoPortStartDma),
  314. PROC(VideoPortCompleteDma),
  315. PROC(VideoPortCreateEvent),
  316. PROC(VideoPortDeleteEvent),
  317. PROC(VideoPortSetEvent),
  318. PROC(VideoPortClearEvent),
  319. PROC(VideoPortReadStateEvent),
  320. PROC(VideoPortWaitForSingleObject),
  321. PROC(VideoPortAllocatePool),
  322. PROC(VideoPortFreePool),
  323. PROC(VideoPortCreateSpinLock),
  324. PROC(VideoPortDeleteSpinLock),
  325. PROC(VideoPortAcquireSpinLock),
  326. PROC(VideoPortAcquireSpinLockAtDpcLevel),
  327. PROC(VideoPortReleaseSpinLock),
  328. PROC(VideoPortReleaseSpinLockFromDpcLevel),
  329. PROC(VideoPortCheckForDeviceExistence),
  330. PROC(VideoPortCreateSecondaryDisplay),
  331. PROC(VideoPortFlushRegistry),
  332. PROC(VideoPortQueryPerformanceCounter),
  333. PROC(VideoPortGetVersion),
  334. PROC(VideoPortRegisterBugcheckCallback),
  335. {NULL, NULL}
  336. };