- Use spinlock.h from ntoskrnl, instead of duplicating the definitions
- Use one spinlock.c, but compiled for 2 static libs (hal_generic_up and hal_generic_mp)
- Move HalpAcquireSystemHardwareSpinLock and HalpReleaseCmosSpinLock to spinlock.c and use the inline functions for the kernel to make Arch happy.

svn path=/branches/ros-amd64-bringup/; revision=44894
This commit is contained in:
Timo Kreuzer
2010-01-02 20:03:49 +00:00
parent 3a0ef6c524
commit 909e90aceb
7 changed files with 67 additions and 340 deletions
+1
View File
@@ -4,6 +4,7 @@
<xi:include href="hal_generic.rbuild" />
<xi:include href="hal_generic_up.rbuild" />
<xi:include href="hal_generic_mp.rbuild" />
<if property="ARCH" value="i386">
<xi:include href="hal.rbuild" />
-44
View File
@@ -16,54 +16,10 @@
/* GLOBALS *******************************************************************/
KSPIN_LOCK HalpSystemHardwareLock;
UCHAR HalpCmosCenturyOffset;
ULONG HalpSystemHardwareFlags;
/* PRIVATE FUNCTIONS *********************************************************/
VOID
NTAPI
HalpAcquireSystemHardwareSpinLock(VOID)
{
ULONG Flags;
/* Get flags and disable interrupts */
Flags = __readeflags();
_disable();
/* Try to acquire the lock */
while (InterlockedBitTestAndSet((PLONG)&HalpSystemHardwareLock, 0))
{
/* Lock is held, spin until it's free */
while (*(volatile ULONG*)HalpSystemHardwareLock & 1)
YieldProcessor();
}
/* We have the lock, save the flags now */
HalpSystemHardwareFlags = Flags;
}
VOID
NTAPI
HalpReleaseCmosSpinLock(VOID)
{
ULONG Flags;
/* Get the flags */
Flags = HalpSystemHardwareFlags;
/* Release lock and check if we owned it */
if (!InterlockedBitTestAndReset((PLONG)&HalpSystemHardwareLock, 0))
{
/* The spin lock was not owned! */
KeBugCheckEx(SPIN_LOCK_NOT_OWNED, 0, 0, 0, 0);
}
/* Restore the flags */
__writeeflags(Flags);
}
FORCEINLINE
UCHAR
HalpReadCmos(IN UCHAR Reg)
@@ -4,6 +4,7 @@
* FILE: hal/halx86/up/spinlock.c
* PURPOSE: Spinlock and Queued Spinlock Support
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
* Timo Kreuzer (timo.kreuzer@reactos.org)
*/
/* INCLUDES ******************************************************************/
@@ -15,106 +16,20 @@
#define NDEBUG
#include <debug.h>
#include <internal/spinlock.h>
#undef KeAcquireSpinLock
#undef KeReleaseSpinLock
//
// This is duplicated from ke_x.h
//
#ifdef CONFIG_SMP
//
// Spinlock Acquisition at IRQL >= DISPATCH_LEVEL
//
FORCEINLINE
VOID
KxAcquireSpinLock(IN PKSPIN_LOCK SpinLock)
{
/* Make sure that we don't own the lock already */
if (((KSPIN_LOCK)KeGetCurrentThread() | 1) == *SpinLock)
{
/* We do, bugcheck! */
KeBugCheckEx(SPIN_LOCK_ALREADY_OWNED, (ULONG_PTR)SpinLock, 0, 0, 0);
}
/* GLOBALS *******************************************************************/
for (;;)
{
/* Try to acquire it */
if (InterlockedBitTestAndSet((PLONG)SpinLock, 0))
{
/* Value changed... wait until it's locked */
while (*(volatile KSPIN_LOCK *)SpinLock == 1)
{
#ifdef DBG
/* On debug builds, we use a much slower but useful routine */
//Kii386SpinOnSpinLock(SpinLock, 5);
/* FIXME: Do normal yield for now */
YieldProcessor();
#else
/* Otherwise, just yield and keep looping */
YieldProcessor();
#endif
}
}
else
{
#ifdef DBG
/* On debug builds, we OR in the KTHREAD */
*SpinLock = (KSPIN_LOCK)KeGetCurrentThread() | 1;
#endif
/* All is well, break out */
break;
}
}
}
//
// Spinlock Release at IRQL >= DISPATCH_LEVEL
//
FORCEINLINE
VOID
KxReleaseSpinLock(IN PKSPIN_LOCK SpinLock)
{
#ifdef DBG
/* Make sure that the threads match */
if (((KSPIN_LOCK)KeGetCurrentThread() | 1) != *SpinLock)
{
/* They don't, bugcheck */
KeBugCheckEx(SPIN_LOCK_NOT_OWNED, (ULONG_PTR)SpinLock, 0, 0, 0);
}
#endif
/* Clear the lock */
InterlockedAnd((PLONG)SpinLock, 0);
}
#else
//
// Spinlock Acquire at IRQL >= DISPATCH_LEVEL
//
FORCEINLINE
VOID
KxAcquireSpinLock(IN PKSPIN_LOCK SpinLock)
{
/* On UP builds, spinlocks don't exist at IRQL >= DISPATCH */
UNREFERENCED_PARAMETER(SpinLock);
}
//
// Spinlock Release at IRQL >= DISPATCH_LEVEL
//
FORCEINLINE
VOID
KxReleaseSpinLock(IN PKSPIN_LOCK SpinLock)
{
/* On UP builds, spinlocks don't exist at IRQL >= DISPATCH */
UNREFERENCED_PARAMETER(SpinLock);
}
#endif
ULONG HalpSystemHardwareFlags;
KSPIN_LOCK HalpSystemHardwareLock;
/* FUNCTIONS *****************************************************************/
#ifdef _M_IX86
/*
* @implemented
*/
@@ -347,3 +262,39 @@ KeLowerIrql(KIRQL NewIrql)
/* Call the fastcall function */
KfLowerIrql(NewIrql);
}
#endif
VOID
NTAPI
HalpAcquireSystemHardwareSpinLock(VOID)
{
ULONG Flags;
/* Get flags and disable interrupts */
Flags = __readeflags();
_disable();
/* Acquire the lock */
KxAcquireSpinLock(&HalpSystemHardwareLock);
/* We have the lock, save the flags now */
HalpSystemHardwareFlags = Flags;
}
VOID
NTAPI
HalpReleaseCmosSpinLock(VOID)
{
ULONG Flags;
/* Get the flags */
Flags = HalpSystemHardwareFlags;
/* Release the lock */
KxReleaseSpinLock(&HalpSystemHardwareLock);
/* Restore the flags */
__writeeflags(Flags);
}
+18
View File
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<!DOCTYPE group SYSTEM "../../../tools/rbuild/project.dtd">
<group>
<module name="hal_generic_mp" type="objectlibrary">
<include>include</include>
<include base="ntoskrnl">include</include>
<define name="_NTHAL_" />
<define name="CONFIG_SMP" />
<directory name="generic">
<file>spinlock.c</file>
</directory>
<directory name="mp">
<if property="ARCH" value="i386">
<file>irq.S</file>
</if>
</directory>
</module>
</group>
+3 -1
View File
@@ -5,11 +5,13 @@
<include>include</include>
<include base="ntoskrnl">include</include>
<define name="_NTHAL_" />
<directory name="generic">
<file>spinlock.c</file>
</directory>
<directory name="up">
<file>processor.c</file>
<if property="ARCH" value="i386">
<file>irq.S</file>
<file>spinlock.c</file>
</if>
</directory>
</module>
+1 -1
View File
@@ -9,6 +9,7 @@
<define name="CONFIG_SMP" />
<define name="_NTHAL_" />
<library>hal_generic</library>
<library>hal_generic_mp</library>
<library>ntoskrnl</library>
<directory name="mp">
<file>apic.c</file>
@@ -22,7 +23,6 @@
<directory name="i386">
<file>mps.S</file>
<file>mpsboot.asm</file>
<file>spinlock.c</file>
</directory>
</directory>
</module>
-201
View File
@@ -1,201 +0,0 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/hal/x86/spinlock.c
* PURPOSE: Implements spinlocks
* PROGRAMMER: David Welch ([email protected])
* Eric Kohl ([email protected])
* UPDATE HISTORY:
* 09/06/2000 Created
*/
/*
* NOTE: On a uniprocessor machine spinlocks are implemented by raising
* the irq level
*/
/* INCLUDES ****************************************************************/
#include <hal.h>
#define NDEBUG
#include <debug.h>
/* Hmm, needed for KDBG := 1. Why? */
#undef KeGetCurrentIrql
/* FUNCTIONS ***************************************************************/
#undef KeAcquireSpinLock
VOID NTAPI
KeAcquireSpinLock (
PKSPIN_LOCK SpinLock,
PKIRQL OldIrql
)
/*
* FUNCTION: Acquires a spinlock
* ARGUMENTS:
* SpinLock = Spinlock to acquire
* OldIrql (OUT) = Caller supplied storage for the previous irql
*/
{
*OldIrql = KfAcquireSpinLock(SpinLock);
}
KIRQL FASTCALL
KeAcquireSpinLockRaiseToSynch (
PKSPIN_LOCK SpinLock
)
{
KIRQL OldIrql;
OldIrql = KfRaiseIrql(CLOCK2_LEVEL);
KiAcquireSpinLock(SpinLock);
return OldIrql;
}
#undef KeReleaseSpinLock
VOID NTAPI
KeReleaseSpinLock (
PKSPIN_LOCK SpinLock,
KIRQL NewIrql
)
/*
* FUNCTION: Releases a spinlock
* ARGUMENTS:
* SpinLock = Spinlock to release
* NewIrql = Irql level before acquiring the spinlock
*/
{
KfReleaseSpinLock(SpinLock, NewIrql);
}
LOGICAL
FASTCALL
KeTryToAcquireQueuedSpinLock(
KSPIN_LOCK_QUEUE_NUMBER LockNumber,
PKIRQL OldIrql)
{
UNIMPLEMENTED;
return FALSE;
}
BOOLEAN
FASTCALL
KeTryToAcquireQueuedSpinLockRaiseToSynch(
KSPIN_LOCK_QUEUE_NUMBER LockNumber,
PKIRQL OldIrql)
{
UNIMPLEMENTED;
return FALSE;
}
KIRQL FASTCALL
KfAcquireSpinLock (
PKSPIN_LOCK SpinLock
)
{
KIRQL OldIrql;
ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
OldIrql = KfRaiseIrql(DISPATCH_LEVEL);
KiAcquireSpinLock(SpinLock);
return OldIrql;
}
VOID FASTCALL
KfReleaseSpinLock (
PKSPIN_LOCK SpinLock,
KIRQL NewIrql
)
/*
* FUNCTION: Releases a spinlock
* ARGUMENTS:
* SpinLock = Spinlock to release
* NewIrql = Irql level before acquiring the spinlock
*/
{
ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL || KeGetCurrentIrql() == SYNCH_LEVEL);
KiReleaseSpinLock(SpinLock);
KfLowerIrql(NewIrql);
}
/*
* @unimplemented
*/
VOID
FASTCALL
KeAcquireInStackQueuedSpinLock(
IN PKSPIN_LOCK SpinLock,
IN PKLOCK_QUEUE_HANDLE LockHandle
)
{
UNIMPLEMENTED;
}
/*
* @unimplemented
*/
VOID
FASTCALL
KeAcquireInStackQueuedSpinLockRaiseToSynch(
IN PKSPIN_LOCK SpinLock,
IN PKLOCK_QUEUE_HANDLE LockHandle
)
{
UNIMPLEMENTED;
}
/*
* @unimplemented
*/
VOID
FASTCALL
KeReleaseInStackQueuedSpinLock(
IN PKLOCK_QUEUE_HANDLE LockHandle
)
{
UNIMPLEMENTED;
}
/*
* @unimplemented
*/
KIRQL
FASTCALL
KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER Number)
{
UNIMPLEMENTED;
return 0;
}
/*
* @unimplemented
*/
KIRQL
FASTCALL
KeAcquireQueuedSpinLockRaiseToSynch(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
{
UNIMPLEMENTED;
return 0;
}
/*
* @unimplemented
*/
VOID
FASTCALL
KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER Number,
IN KIRQL OldIrql)
{
UNIMPLEMENTED;
}
/* EOF */