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.

179 lines
3.1 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. flush.c
  5. Abstract:
  6. This module implements AMD64 machine dependent kernel functions to
  7. flush the data and instruction caches on all processors.
  8. Author:
  9. David N. Cutler (davec) 22-Apr-2000
  10. Environment:
  11. Kernel mode only.
  12. Revision History:
  13. --*/
  14. #include "ki.h"
  15. //
  16. // Define prototypes for forward referenced functions.
  17. //
  18. VOID
  19. KiInvalidateAllCachesTarget (
  20. IN PKIPI_CONTEXT SignalDone,
  21. IN PVOID Parameter1,
  22. IN PVOID Parameter2,
  23. IN PVOID Parameter3
  24. );
  25. BOOLEAN
  26. KeInvalidateAllCaches (
  27. IN BOOLEAN AllProcessors
  28. )
  29. /*++
  30. Routine Description:
  31. This function writes back and invalidates the cache on all processors
  32. that are currently running threads which are children of the current
  33. process or on all processors in the host configuration.
  34. Arguments:
  35. AllProcessors - Supplies a boolean value that determines which data
  36. caches are flushed.
  37. Return Value:
  38. TRUE is returned as the function value.
  39. --*/
  40. {
  41. KIRQL OldIrql;
  42. PKPRCB Prcb;
  43. PKPROCESS Process;
  44. KAFFINITY TargetProcessors;
  45. //
  46. // Compute the target set of processors, disable context switching,
  47. // and send the writeback invalidate all to the target processors,
  48. // if any, for execution.
  49. //
  50. #if !defined(NT_UP)
  51. if (AllProcessors != FALSE) {
  52. OldIrql = KeRaiseIrqlToSynchLevel();
  53. Prcb = KeGetCurrentPrcb();
  54. TargetProcessors = KeActiveProcessors;
  55. } else {
  56. KiLockContextSwap(&OldIrql);
  57. Prcb = KeGetCurrentPrcb();
  58. Process = Prcb->CurrentThread->ApcState.Process;
  59. TargetProcessors = Process->ActiveProcessors;
  60. }
  61. //
  62. // Send packet to target processors.
  63. //
  64. TargetProcessors &= Prcb->NotSetMember;
  65. if (TargetProcessors != 0) {
  66. KiIpiSendPacket(TargetProcessors,
  67. KiInvalidateAllCachesTarget,
  68. NULL,
  69. NULL,
  70. NULL);
  71. }
  72. #endif
  73. //
  74. // Invalidate cache on current processor.
  75. //
  76. WritebackInvalidate();
  77. //
  78. // Wait until all target processors have finished and complete packet.
  79. //
  80. #if !defined(NT_UP)
  81. if (TargetProcessors != 0) {
  82. KiIpiStallOnPacketTargets(TargetProcessors);
  83. }
  84. //
  85. // Lower IRQL and unlock as appropriate.
  86. //
  87. if (AllProcessors != FALSE) {
  88. KeLowerIrql(OldIrql);
  89. } else {
  90. KiUnlockContextSwap(OldIrql);
  91. }
  92. #endif
  93. return TRUE;
  94. }
  95. #if !defined(NT_UP)
  96. VOID
  97. KiInvalidateAllCachesTarget (
  98. IN PKIPI_CONTEXT SignalDone,
  99. IN PVOID Parameter1,
  100. IN PVOID Parameter2,
  101. IN PVOID Parameter3
  102. )
  103. /*++
  104. Routine Description:
  105. This is the target function for writeback invalidating the cache on
  106. target processors.
  107. Arguments:
  108. SignalDone - Supplies a pointer to a variable that is cleared when the
  109. requested operation has been performed.
  110. Parameter2 - Parameter3 - not used.
  111. Return Value:
  112. None.
  113. --*/
  114. {
  115. //
  116. // Write back invalidate current cache.
  117. //
  118. KiIpiSignalPacketDone(SignalDone);
  119. WritebackInvalidate();
  120. return;
  121. }
  122. #endif