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.

208 lines
3.7 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. flush.c
  5. Abstract:
  6. This module implements i386 machine dependent kernel functions to flush
  7. the data and instruction caches and to stall processor execution.
  8. Author:
  9. David N. Cutler (davec) 26-Apr-1990
  10. Environment:
  11. Kernel mode only.
  12. Revision History:
  13. --*/
  14. #include "ki.h"
  15. //
  16. // Prototypes
  17. //
  18. VOID
  19. KiInvalidateAllCachesTarget (
  20. IN PKIPI_CONTEXT SignalDone,
  21. IN PVOID Parameter1,
  22. IN PVOID Parameter2,
  23. IN PVOID Parameter3
  24. );
  25. extern ULONG KeI386CpuType;
  26. BOOLEAN
  27. KeInvalidateAllCaches (
  28. VOID
  29. )
  30. /*++
  31. Routine Description:
  32. This function writes back and invalidates the cache on all processors
  33. in the host configuration.
  34. Arguments:
  35. None.
  36. Return Value:
  37. TRUE if the invalidation was done, FALSE otherwise.
  38. --*/
  39. {
  40. #ifndef NT_UP
  41. KIRQL OldIrql;
  42. PKPRCB Prcb;
  43. KAFFINITY TargetProcessors;
  44. #endif
  45. //
  46. // Support for wbinvd on Pentium based platforms is vendor dependent.
  47. // Check for family first and support on Pentium Pro based platforms
  48. // onward.
  49. //
  50. if (KeI386CpuType < 6 ) {
  51. return FALSE;
  52. }
  53. //
  54. // Raise IRQL and compute target set of processors.
  55. //
  56. #ifndef NT_UP
  57. //
  58. // Synchronize with other IPI functions which may stall
  59. //
  60. OldIrql = KeRaiseIrqlToSynchLevel();
  61. KeAcquireSpinLockAtDpcLevel (&KiReverseStallIpiLock);
  62. Prcb = KeGetCurrentPrcb();
  63. TargetProcessors = KeActiveProcessors & ~Prcb->SetMember;
  64. //
  65. // If any target processors are specified, then send writeback
  66. // invalidate packet to the target set of processors.
  67. //
  68. if (TargetProcessors != 0) {
  69. KiIpiSendSynchronousPacket(Prcb,
  70. TargetProcessors,
  71. KiInvalidateAllCachesTarget,
  72. (PVOID)&Prcb->ReverseStall,
  73. NULL,
  74. NULL);
  75. KiIpiStallOnPacketTargets(TargetProcessors);
  76. }
  77. #endif
  78. //
  79. // All target processors have written back and invalidated caches and
  80. // are waiting to proceed. Write back invalidate current cache and
  81. // then continue the execution of target processors.
  82. //
  83. _asm {
  84. ;
  85. ; wbinvd
  86. ;
  87. _emit 0Fh
  88. _emit 09h
  89. }
  90. //
  91. // Wait until all target processors have finished and completed packet.
  92. //
  93. #ifndef NT_UP
  94. if (TargetProcessors != 0) {
  95. Prcb->ReverseStall += 1;
  96. }
  97. //
  98. // Drop reverse IPI lock and Lower IRQL to its previous value.
  99. //
  100. KeReleaseSpinLockFromDpcLevel (&KiReverseStallIpiLock);
  101. KeLowerIrql(OldIrql);
  102. #endif
  103. return TRUE;
  104. }
  105. #if !defined(NT_UP)
  106. VOID
  107. KiInvalidateAllCachesTarget (
  108. IN PKIPI_CONTEXT SignalDone,
  109. IN PVOID Proceed,
  110. IN PVOID Parameter2,
  111. IN PVOID Parameter3
  112. )
  113. /*++
  114. Routine Description:
  115. This is the target function for writing back and invalidating the cache.
  116. Arguments:
  117. SignalDone - Supplies a pointer to a variable that is cleared when the
  118. requested operation has been performed.
  119. Proceed - pointer to flag to syncronize with
  120. Return Value:
  121. None.
  122. --*/
  123. {
  124. UNREFERENCED_PARAMETER (Parameter2);
  125. UNREFERENCED_PARAMETER (Parameter3);
  126. //
  127. // Write back invalidate current cache
  128. //
  129. _asm {
  130. ;
  131. ; wbinvd
  132. ;
  133. _emit 0Fh
  134. _emit 09h
  135. }
  136. KiIpiSignalPacketDoneAndStall (SignalDone, Proceed);
  137. }
  138. #endif