Leaked source code of windows server 2003
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.

1105 lines
22 KiB

  1. /*++
  2. Copyright (c) 1990-1998 Microsoft Corporation
  3. Module Name:
  4. bootvid.c
  5. Abstract:
  6. This file implements the interface between the kernel, and the
  7. graphical boot driver.
  8. Author:
  9. Erick Smith (ericks) Feb. 3, 1998
  10. Environment:
  11. kernel mode
  12. Revision History:
  13. --*/
  14. #include "ntos.h"
  15. #include "ntimage.h"
  16. #include <zwapi.h>
  17. #include <ntdddisk.h>
  18. #include <setupblk.h>
  19. #include <fsrtl.h>
  20. #include <ntverp.h>
  21. #include "stdlib.h"
  22. #include "stdio.h"
  23. #include <string.h>
  24. #include <safeboot.h>
  25. #include <inbv.h>
  26. #include <bootvid.h>
  27. #include <hdlsblk.h>
  28. #include <hdlsterm.h>
  29. #include "anim.h"
  30. ULONG InbvTerminalBkgdColor = HEADLESS_TERM_DEFAULT_BKGD_COLOR;
  31. ULONG InbvTerminalTextColor = HEADLESS_TERM_DEFAULT_TEXT_COLOR;
  32. PUCHAR
  33. FindBitmapResource(
  34. IN PLOADER_PARAMETER_BLOCK LoaderBlock,
  35. IN ULONG_PTR ResourceIdentifier
  36. );
  37. #if defined(ALLOC_PRAGMA)
  38. #pragma alloc_text(INIT,InbvIndicateProgress)
  39. #pragma alloc_text(INIT,InbvDriverInitialize)
  40. #pragma alloc_text(INIT,FindBitmapResource)
  41. #endif
  42. //
  43. // System global variable
  44. //
  45. BOOLEAN InbvBootDriverInstalled = FALSE;
  46. BOOLEAN InbvDisplayDebugStrings = FALSE;
  47. INBV_DISPLAY_STATE InbvDisplayState = INBV_DISPLAY_STATE_OWNED;
  48. KSPIN_LOCK BootDriverLock;
  49. KIRQL InbvOldIrql;
  50. INBV_RESET_DISPLAY_PARAMETERS InbvResetDisplayParameters = NULL;
  51. INBV_DISPLAY_STRING_FILTER InbvDisplayFilter = NULL;
  52. #define MAX_RESOURCES 16
  53. ULONG ResourceCount = 0;
  54. PUCHAR ResourceList[MAX_RESOURCES];
  55. ULONG ProgressBarLeft;
  56. ULONG ProgressBarTop;
  57. BOOLEAN ShowProgressBar = TRUE;
  58. struct _InbvProgressState {
  59. ULONG Floor;
  60. ULONG Ceiling;
  61. ULONG Bias;
  62. } InbvProgressState;
  63. #ifdef ALLOC_DATA_PRAGMA
  64. #pragma data_seg("INITDATA")
  65. #endif
  66. struct _BT_PROGRESS_INDICATOR {
  67. ULONG Count;
  68. ULONG Expected;
  69. ULONG Percentage;
  70. } InbvProgressIndicator = { 0, 25, 0 };
  71. #ifdef ALLOC_DATA_PRAGMA
  72. #pragma data_seg()
  73. #endif
  74. VOID
  75. InbvAcquireLock(
  76. VOID
  77. )
  78. /*++
  79. Routine Description:
  80. This is an internal function used to grab the boot driver lock. This
  81. ensures that only one thread will enter the driver code at a time.
  82. Notes:
  83. You must call ReleaseLock for each call to AcquireLock.
  84. --*/
  85. {
  86. KIRQL Irql;
  87. KIRQL LocalIrql;
  88. LocalIrql = KeGetCurrentIrql();
  89. if (LocalIrql <= DISPATCH_LEVEL) {
  90. while (!KeTestSpinLock(&BootDriverLock))
  91. ;
  92. KeRaiseIrql(DISPATCH_LEVEL, &Irql);
  93. LocalIrql = Irql;
  94. }
  95. KiAcquireSpinLock(&BootDriverLock);
  96. InbvOldIrql = LocalIrql;
  97. }
  98. VOID
  99. InbvReleaseLock(
  100. VOID
  101. )
  102. /*++
  103. Routine Description:
  104. This routine releases the boot driver lock.
  105. --*/
  106. {
  107. KIRQL OldIrql = InbvOldIrql;
  108. KiReleaseSpinLock(&BootDriverLock);
  109. if (OldIrql <= DISPATCH_LEVEL) {
  110. KeLowerIrql(OldIrql);
  111. }
  112. }
  113. BOOLEAN
  114. InbvTestLock(
  115. VOID
  116. )
  117. /*++
  118. Routine Description:
  119. This routine allows you to try to acquire the display lock. If it
  120. can't get the lock right away, it returns failure.
  121. Returns:
  122. TRUE - If you aqcuired the lock.
  123. FALSE - If another thread is currently using the boot driver.
  124. Notes:
  125. You must call InbvReleaseLock if this function returns TRUE!
  126. --*/
  127. {
  128. KIRQL Irql;
  129. if (KeTryToAcquireSpinLock(&BootDriverLock, &Irql)) {
  130. InbvOldIrql = Irql;
  131. return TRUE;
  132. } else {
  133. return FALSE;
  134. }
  135. }
  136. VOID
  137. InbvEnableBootDriver(
  138. BOOLEAN bEnable
  139. )
  140. /*++
  141. Routine Description:
  142. This routine allows the kernel to control whether Inbv
  143. calls make it through to the boot driver, and when they don't.
  144. Arguments:
  145. bEnable - If TRUE, we will allow Inbv calls to display,
  146. otherwise we will not.
  147. --*/
  148. {
  149. if (InbvBootDriverInstalled) {
  150. if (InbvDisplayState < INBV_DISPLAY_STATE_LOST) {
  151. //
  152. // We can only wait for our lock, and execute our clean up code
  153. // if the driver is installed.
  154. //
  155. InbvAcquireLock();
  156. if (InbvDisplayState == INBV_DISPLAY_STATE_OWNED) {
  157. VidCleanUp();
  158. }
  159. InbvDisplayState = (bEnable ? INBV_DISPLAY_STATE_OWNED : INBV_DISPLAY_STATE_DISABLED);
  160. InbvReleaseLock();
  161. }
  162. } else {
  163. //
  164. // This allow us to set display state before boot driver starts.
  165. //
  166. InbvDisplayState = (bEnable ? INBV_DISPLAY_STATE_OWNED : INBV_DISPLAY_STATE_DISABLED);
  167. }
  168. }
  169. BOOLEAN
  170. InbvEnableDisplayString(
  171. BOOLEAN bEnable
  172. )
  173. /*++
  174. Routine Description:
  175. This routine allows the kernel to control when HalDisplayString
  176. calls make it through to the boot driver, and when they don't.
  177. Arguments:
  178. bEnable - If TRUE, we will allow HalDisplayString calls to display,
  179. otherwise we will not.
  180. Returns:
  181. TRUE - If display string were currently being dumped.
  182. FALSE - otherwise.
  183. --*/
  184. {
  185. BOOLEAN PrevValue = InbvDisplayDebugStrings;
  186. InbvDisplayDebugStrings = bEnable;
  187. return PrevValue;
  188. }
  189. BOOLEAN
  190. InbvIsBootDriverInstalled(
  191. VOID
  192. )
  193. /*++
  194. Routine Description:
  195. This routine allows a component to determine if the gui boot
  196. driver is in use.
  197. --*/
  198. {
  199. return InbvBootDriverInstalled;
  200. }
  201. BOOLEAN
  202. InbvResetDisplay(
  203. )
  204. /*++
  205. Routine Description:
  206. This routine will reset the display from text mode to a
  207. supported graphics mode.
  208. Notes:
  209. This routine expects the display to be in text mode when called.
  210. --*/
  211. {
  212. if (InbvBootDriverInstalled && (InbvDisplayState == INBV_DISPLAY_STATE_OWNED)) {
  213. VidResetDisplay(TRUE);
  214. return TRUE;
  215. } else {
  216. return FALSE;
  217. }
  218. }
  219. VOID
  220. InbvScreenToBufferBlt(
  221. PUCHAR Buffer,
  222. ULONG x,
  223. ULONG y,
  224. ULONG width,
  225. ULONG height,
  226. ULONG lDelta
  227. )
  228. /*++
  229. Routine Description:
  230. This routine allows for copying portions of video memory into system
  231. memory.
  232. Arguments:
  233. Buffer - Location in which to place the video image.
  234. x, y - X and Y coordinates of top-left corner of image.
  235. width, height - The width and height of the image in pixels.
  236. lDelta - width of the buffer in bytes
  237. Notes:
  238. This routine does not automatically acquire the device lock, so
  239. the caller must call InbvAquireLock or InbvTestLock to acquire
  240. the device lock.
  241. --*/
  242. {
  243. if (InbvBootDriverInstalled && (InbvDisplayState == INBV_DISPLAY_STATE_OWNED)) {
  244. VidScreenToBufferBlt(Buffer, x, y, width, height, lDelta);
  245. }
  246. }
  247. VOID
  248. InbvBufferToScreenBlt(
  249. PUCHAR Buffer,
  250. ULONG x,
  251. ULONG y,
  252. ULONG width,
  253. ULONG height,
  254. ULONG lDelta
  255. )
  256. /*++
  257. Routine Description:
  258. This routine allows for copying previously saved portions of video
  259. memory back to the screen.
  260. Arguments:
  261. Buffer - Location in which to place the video image.
  262. x, y - X and Y coordinates of top-left corner of image.
  263. width, height - The width and height of the image in pixels.
  264. lDelta - width of the buffer in bytes
  265. Notes:
  266. This routine does not automatically acquire the device lock, so
  267. the caller must call InbvAquireLock or InbvTestLock to acquire
  268. the device lock.
  269. --*/
  270. {
  271. if (InbvBootDriverInstalled && (InbvDisplayState == INBV_DISPLAY_STATE_OWNED)) {
  272. VidBufferToScreenBlt(Buffer, x, y, width, height, lDelta);
  273. }
  274. }
  275. VOID
  276. InbvBitBlt(
  277. PUCHAR Buffer,
  278. ULONG x,
  279. ULONG y
  280. )
  281. /*++
  282. Routine Description:
  283. This routine blts the bitmap described in 'Buffer' to the location
  284. x and y on the screen.
  285. Arguments:
  286. Buffer - points to a bitmap (in the same format as stored on disk).
  287. x, y - the upper left corner at which the bitmap will be drawn.
  288. --*/
  289. {
  290. if (InbvBootDriverInstalled && (InbvDisplayState == INBV_DISPLAY_STATE_OWNED)) {
  291. InbvAcquireLock();
  292. VidBitBlt(Buffer, x, y);
  293. InbvReleaseLock();
  294. }
  295. }
  296. VOID
  297. InbvSolidColorFill(
  298. ULONG x1,
  299. ULONG y1,
  300. ULONG x2,
  301. ULONG y2,
  302. ULONG color
  303. )
  304. /*++
  305. Routine Description:
  306. This routine fills a rectangular portion of the screen with a
  307. given color.
  308. --*/
  309. {
  310. ULONG x, y;
  311. HEADLESS_CMD_SET_COLOR HeadlessCmd;
  312. if (InbvDisplayState == INBV_DISPLAY_STATE_OWNED) {
  313. InbvAcquireLock();
  314. if (InbvBootDriverInstalled) {
  315. VidSolidColorFill(x1, y1, x2, y2, color);
  316. }
  317. //
  318. // Now fill in the area on the terminal
  319. //
  320. InbvTerminalBkgdColor = HEADLESS_TERM_DEFAULT_BKGD_COLOR;
  321. HeadlessCmd.FgColor = InbvTerminalTextColor;
  322. HeadlessCmd.BkgColor = InbvTerminalBkgdColor;
  323. HeadlessDispatch(HeadlessCmdSetColor,
  324. &HeadlessCmd,
  325. sizeof(HEADLESS_CMD_SET_COLOR),
  326. NULL,
  327. NULL
  328. );
  329. //
  330. // All block fills come in as if on VGA (640x480). The terminal is only 24x80
  331. // so just assume it is full screen reset for now. This works because the only
  332. // thing enables terminal output is KeBugCheckEx(), which does a full screen fill.
  333. //
  334. HeadlessDispatch(HeadlessCmdClearDisplay, NULL, 0, NULL, NULL);
  335. InbvReleaseLock();
  336. }
  337. }
  338. ULONG
  339. InbvSetTextColor(
  340. ULONG Color
  341. )
  342. /*++
  343. Routine Description:
  344. Sets the text color used when dislaying text.
  345. Arguments:
  346. Color - the new text color.
  347. Returns:
  348. The previous text color.
  349. --*/
  350. {
  351. HEADLESS_CMD_SET_COLOR HeadlessCmd;
  352. InbvTerminalTextColor = HEADLESS_TERM_DEFAULT_TEXT_COLOR;
  353. HeadlessCmd.FgColor = InbvTerminalTextColor;
  354. HeadlessCmd.BkgColor = InbvTerminalBkgdColor;
  355. HeadlessDispatch(HeadlessCmdSetColor,
  356. &HeadlessCmd,
  357. sizeof(HEADLESS_CMD_SET_COLOR),
  358. NULL,
  359. NULL
  360. );
  361. return VidSetTextColor(Color);
  362. }
  363. VOID
  364. InbvInstallDisplayStringFilter(
  365. INBV_DISPLAY_STRING_FILTER DisplayFilter
  366. )
  367. /*++
  368. --*/
  369. {
  370. InbvDisplayFilter = DisplayFilter;
  371. }
  372. BOOLEAN
  373. InbvDisplayString(
  374. PUCHAR Str
  375. )
  376. /*++
  377. Routine Description:
  378. This routine displays a string on the screen.
  379. Arguments:
  380. Str - The string to be displayed.
  381. --*/
  382. {
  383. PUCHAR *String = &Str;
  384. if (InbvDisplayState == INBV_DISPLAY_STATE_OWNED) {
  385. if (InbvDisplayDebugStrings) {
  386. if (InbvDisplayFilter) {
  387. InbvDisplayFilter(String);
  388. }
  389. InbvAcquireLock();
  390. if (InbvBootDriverInstalled) {
  391. VidDisplayString(*String);
  392. }
  393. //
  394. // Since the command structure is exactly a string, we can do this. The
  395. // ASSERT() will catch if this ever changes. If it does change, then
  396. // we will need to allocate a structure, or have one pre-allocated, for
  397. // filling in and copying over the string.
  398. //
  399. ASSERT(FIELD_OFFSET(HEADLESS_CMD_PUT_STRING, String) == 0);
  400. HeadlessDispatch(HeadlessCmdPutString,
  401. *String,
  402. strlen(*String) + sizeof(UCHAR),
  403. NULL,
  404. NULL
  405. );
  406. InbvReleaseLock();
  407. }
  408. return TRUE;
  409. } else {
  410. return FALSE;
  411. }
  412. }
  413. #define PROGRESS_BAR_TICK_WIDTH 9
  414. #define PROGRESS_BAR_TICK_HEIGHT 8
  415. #define PROGRESS_BAR_TICKS 18
  416. #define PROGRESS_BAR_COLOR 11
  417. VOID
  418. InbvSetProgressBarCoordinates(
  419. ULONG x,
  420. ULONG y
  421. )
  422. /*++
  423. Routine Description:
  424. This routine sets the upper left coordinate of the progress bar.
  425. Arguments:
  426. x, y - upper left coordinate of progress bar.
  427. --*/
  428. {
  429. ProgressBarLeft = x;
  430. ProgressBarTop = y;
  431. ShowProgressBar = TRUE;
  432. }
  433. VOID
  434. InbvUpdateProgressBar(
  435. ULONG Percentage
  436. )
  437. /*++
  438. Routine Description:
  439. This routine is called by the system during startup to update
  440. the status bar displayed on the gui boot screen.
  441. --*/
  442. {
  443. int i, Ticks;
  444. if (ShowProgressBar && InbvBootDriverInstalled && (InbvDisplayState == INBV_DISPLAY_STATE_OWNED)) {
  445. //
  446. // Draw the ticks for the current percentage
  447. //
  448. //
  449. // The following calculations are biased by 100 do that
  450. // InbvProgressState.Bias can be expressed as an integer fraction.
  451. //
  452. Ticks = Percentage * InbvProgressState.Bias;
  453. Ticks += InbvProgressState.Floor;
  454. Ticks *= PROGRESS_BAR_TICKS;
  455. Ticks /= 10000;
  456. for (i=0; i<Ticks; i++) {
  457. InbvAcquireLock();
  458. VidSolidColorFill(ProgressBarLeft + (i * PROGRESS_BAR_TICK_WIDTH),
  459. ProgressBarTop,
  460. ProgressBarLeft + ((i + 1) * PROGRESS_BAR_TICK_WIDTH) - 2,
  461. ProgressBarTop + PROGRESS_BAR_TICK_HEIGHT - 1,
  462. PROGRESS_BAR_COLOR);
  463. InbvReleaseLock();
  464. }
  465. }
  466. }
  467. VOID
  468. InbvSetProgressBarSubset(
  469. ULONG Floor,
  470. ULONG Ceiling
  471. )
  472. /*++
  473. Routine Description:
  474. Sets floor and ceiling for subsequent calls to InbvUpdateProgressBar.
  475. While a floor and ceiling are in effect, a caller's 100% is a
  476. percentage of this range. If floor and ceiling are zero, the
  477. entire range is used.
  478. Arguments:
  479. Floor Lower limit of the subset.
  480. Ceiling Upper limit of the subset.
  481. Return Value:
  482. None.
  483. --*/
  484. {
  485. ASSERT(Floor < Ceiling);
  486. ASSERT(Ceiling <= 100);
  487. InbvProgressState.Floor = Floor * 100;
  488. InbvProgressState.Ceiling = Ceiling * 100;
  489. InbvProgressState.Bias = (Ceiling - Floor);
  490. }
  491. VOID
  492. InbvIndicateProgress(
  493. VOID
  494. )
  495. /*++
  496. Routine Description:
  497. This routine is called to indicate that progress is being
  498. made. The number of calls is counted and compared to the
  499. expected number of calls, the boot progress bar is updated
  500. apropriately.
  501. Arguments:
  502. None.
  503. Return Value:
  504. None.
  505. --*/
  506. {
  507. ULONG Percentage;
  508. InbvProgressIndicator.Count++;
  509. //
  510. // Calculate how far along we think we are.
  511. //
  512. Percentage = (InbvProgressIndicator.Count * 100) /
  513. InbvProgressIndicator.Expected;
  514. //
  515. // The Expected number of calls can vary from boot to boot
  516. // but should remain relatively constant. Allow for the
  517. // possibility we were called more than we expected to be.
  518. // (The progress bar simply stalls at this point).
  519. //
  520. if (Percentage > 99) {
  521. Percentage = 99;
  522. }
  523. //
  524. // See if the progress bar should be updated.
  525. //
  526. if (Percentage != InbvProgressIndicator.Percentage) {
  527. InbvProgressIndicator.Percentage = Percentage;
  528. InbvUpdateProgressBar(Percentage);
  529. }
  530. }
  531. PUCHAR
  532. FindBitmapResource(
  533. IN PLOADER_PARAMETER_BLOCK LoaderBlock,
  534. IN ULONG_PTR ResourceIdentifier
  535. )
  536. /*++
  537. Routine Description:
  538. Gets a pointer to the bitmap image compiled into this binary,
  539. if one exists.
  540. Arguments:
  541. LoaderBlock - Used in obtaining the bitmap resource
  542. ResourceIdentifier - Identifier for the resource to return the address for
  543. Return Value:
  544. Pointer to bitmap resource, if successful. NULL otherwise.
  545. --*/
  546. {
  547. NTSTATUS Status;
  548. PLIST_ENTRY Entry;
  549. PKLDR_DATA_TABLE_ENTRY DataTableEntry;
  550. ULONG_PTR ResourceIdPath[3];
  551. PIMAGE_RESOURCE_DATA_ENTRY ResourceDataEntry;
  552. PUCHAR Bitmap;
  553. UNICODE_STRING KernelString1;
  554. UNICODE_STRING KernelString2;
  555. RtlInitUnicodeString(&KernelString1, L"NTOSKRNL.EXE");
  556. RtlInitUnicodeString(&KernelString2, L"NTKRNLMP.EXE");
  557. //
  558. // Find our loader block entry
  559. //
  560. Entry = LoaderBlock->LoadOrderListHead.Flink;
  561. while (Entry != &LoaderBlock->LoadOrderListHead) {
  562. //
  563. // Get the address of the data table entry for this component.
  564. //
  565. DataTableEntry = CONTAINING_RECORD(Entry,
  566. KLDR_DATA_TABLE_ENTRY,
  567. InLoadOrderLinks);
  568. //
  569. // Case-insensitive comparison with "NTOSKRNL.EXE" and "NTKRNLMP.EXE"
  570. //
  571. if (RtlEqualUnicodeString(&DataTableEntry->BaseDllName,
  572. &KernelString1,
  573. TRUE) == TRUE) {
  574. break;
  575. }
  576. if (RtlEqualUnicodeString(&DataTableEntry->BaseDllName,
  577. &KernelString2,
  578. TRUE) == TRUE) {
  579. break;
  580. }
  581. Entry = Entry->Flink;
  582. }
  583. //
  584. // If we couldn't find ntoskrnl in the loader list, give up
  585. //
  586. if (Entry == &LoaderBlock->LoadOrderListHead) {
  587. return NULL;
  588. }
  589. ResourceIdPath[0] = 2; // RT_BITMAP = 2
  590. ResourceIdPath[1] = ResourceIdentifier;
  591. ResourceIdPath[2] = 0; // ??
  592. Status = LdrFindResource_U( DataTableEntry->DllBase,
  593. ResourceIdPath,
  594. 3,
  595. (VOID *) &ResourceDataEntry );
  596. if (!NT_SUCCESS(Status)) {
  597. return NULL;
  598. }
  599. Status = LdrAccessResource( DataTableEntry->DllBase,
  600. ResourceDataEntry,
  601. &Bitmap,
  602. NULL );
  603. if (!NT_SUCCESS(Status)) {
  604. return NULL;
  605. }
  606. return Bitmap;
  607. }
  608. PUCHAR
  609. InbvGetResourceAddress(
  610. IN ULONG ResourceNumber
  611. )
  612. /*++
  613. Routine Description:
  614. This routine returns the cached resources address for a given
  615. resource.
  616. --*/
  617. {
  618. if (ResourceNumber <= ResourceCount) {
  619. return ResourceList[ResourceNumber-1];
  620. } else {
  621. return NULL;
  622. }
  623. }
  624. BOOLEAN
  625. InbvDriverInitialize(
  626. IN PLOADER_PARAMETER_BLOCK LoaderBlock,
  627. ULONG Count
  628. )
  629. /*++
  630. Routine Description:
  631. This routine will call into the graphical boot driver and give the
  632. driver a chance to initialize. At this point, the boot driver
  633. should determine whether it can run on the hardware in the machine.
  634. --*/
  635. {
  636. ULONG i;
  637. ULONG_PTR p;
  638. PCHAR Options;
  639. BOOLEAN DispModeChange = FALSE;
  640. //
  641. // Only do this once.
  642. //
  643. if (InbvBootDriverInstalled == TRUE) {
  644. return TRUE;
  645. }
  646. KeInitializeSpinLock(&BootDriverLock);
  647. if (InbvDisplayState == INBV_DISPLAY_STATE_OWNED) {
  648. Options = LoaderBlock->LoadOptions ? _strupr(LoaderBlock->LoadOptions) : NULL;
  649. if (Options) {
  650. DispModeChange = (BOOLEAN)(strstr(Options, "BOOTLOGO") == NULL);
  651. } else {
  652. DispModeChange = TRUE;
  653. }
  654. }
  655. InbvBootDriverInstalled = VidInitialize(DispModeChange);
  656. if (InbvBootDriverInstalled == FALSE) {
  657. return FALSE;
  658. }
  659. ResourceCount = Count;
  660. for (i=1; i<=Count; i++) {
  661. p = (ULONG_PTR) i;
  662. ResourceList[i-1] = FindBitmapResource(LoaderBlock, p);
  663. }
  664. //
  665. // Set prograss bar to full range.
  666. //
  667. InbvSetProgressBarSubset(0, 100);
  668. return InbvBootDriverInstalled;
  669. }
  670. VOID
  671. InbvNotifyDisplayOwnershipLost(
  672. INBV_RESET_DISPLAY_PARAMETERS ResetDisplayParameters
  673. )
  674. /*++
  675. Routine Description:
  676. This routine is called by the hal when the hal looses
  677. display ownership. At this point win32k.sys has taken
  678. over.
  679. --*/
  680. {
  681. if (InbvBootDriverInstalled) {
  682. //
  683. // We can only wait for our lock, and execute our clean up code
  684. // if the driver is installed and we still own the display.
  685. //
  686. InbvAcquireLock();
  687. if (InbvDisplayState != INBV_DISPLAY_STATE_LOST) {
  688. VidCleanUp();
  689. }
  690. InbvDisplayState = INBV_DISPLAY_STATE_LOST;
  691. InbvResetDisplayParameters = ResetDisplayParameters;
  692. InbvReleaseLock();
  693. } else {
  694. InbvDisplayState = INBV_DISPLAY_STATE_LOST;
  695. InbvResetDisplayParameters = ResetDisplayParameters;
  696. }
  697. }
  698. VOID
  699. InbvAcquireDisplayOwnership(
  700. VOID
  701. )
  702. /*++
  703. Routine Description:
  704. Allows the kernel to reaquire ownership of the display.
  705. --*/
  706. {
  707. if (InbvResetDisplayParameters && (InbvDisplayState == INBV_DISPLAY_STATE_LOST)) {
  708. InbvResetDisplayParameters(80,50);
  709. }
  710. InbvDisplayState = INBV_DISPLAY_STATE_OWNED;
  711. }
  712. VOID
  713. InbvSetDisplayOwnership(
  714. BOOLEAN DisplayOwned
  715. )
  716. /*++
  717. Routine Description:
  718. This routine allows the kernel to set a display state. This is useful
  719. after a hibernate. At this point win32k will reacquire display ownership
  720. but will not tell us.
  721. Arguments:
  722. Whether the display is owned or not.
  723. --*/
  724. {
  725. if (DisplayOwned) {
  726. InbvDisplayState = INBV_DISPLAY_STATE_OWNED;
  727. } else {
  728. InbvDisplayState = INBV_DISPLAY_STATE_LOST;
  729. }
  730. }
  731. BOOLEAN
  732. InbvCheckDisplayOwnership(
  733. VOID
  734. )
  735. /*++
  736. Routine Description:
  737. Indicates whether the Hal owns the display.
  738. --*/
  739. {
  740. return (InbvDisplayState != INBV_DISPLAY_STATE_LOST);
  741. }
  742. INBV_DISPLAY_STATE
  743. InbvGetDisplayState(
  744. VOID
  745. )
  746. /*++
  747. Routine Description:
  748. Indicates whether the Hal owns the display.
  749. --*/
  750. {
  751. return InbvDisplayState;
  752. }
  753. VOID
  754. InbvSetScrollRegion(
  755. ULONG x1,
  756. ULONG y1,
  757. ULONG x2,
  758. ULONG y2
  759. )
  760. /*++
  761. Routine Description:
  762. Control what portions of the screen are used for text.
  763. Arguments:
  764. Lines - number of lines of text.
  765. --*/
  766. {
  767. VidSetScrollRegion(x1, y1, x2, y2);
  768. }