https://git.reactos.org/?p=reactos.git;a=commitdiff;h=6c93669012c654efc46354...
commit 6c93669012c654efc46354670251a5475ac0f41f Author: Thomas Faber thomas.faber@reactos.org AuthorDate: Fri Jan 31 23:03:57 2020 +0100 Commit: Thomas Faber thomas.faber@reactos.org CommitDate: Sun Feb 9 08:32:56 2020 +0100
[HAL] Use a spin lock for the DMA adapter list. CORE-16611
This is necessary because HalPutDmaAdapter can be called at DISPATCH_LEVEL. --- hal/halx86/generic/dma.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/hal/halx86/generic/dma.c b/hal/halx86/generic/dma.c index 7bcfc33e037..39c2efe42a6 100644 --- a/hal/halx86/generic/dma.c +++ b/hal/halx86/generic/dma.c @@ -85,6 +85,7 @@
#ifndef _MINIHAL_ static KEVENT HalpDmaLock; +static KSPIN_LOCK HalpDmaAdapterListLock; static LIST_ENTRY HalpDmaAdapterList; static PADAPTER_OBJECT HalpEisaAdapter[8]; #endif @@ -165,6 +166,7 @@ HalpInitDma(VOID) * first map buffers. */ InitializeListHead(&HalpDmaAdapterList); + KeInitializeSpinLock(&HalpDmaAdapterListLock); KeInitializeEvent(&HalpDmaLock, NotificationEvent, TRUE); HalpMasterAdapter = HalpDmaAllocateMasterAdapter();
@@ -621,6 +623,7 @@ HalGetAdapter(IN PDEVICE_DESCRIPTION DeviceDescription, BOOLEAN EisaAdapter; ULONG MapRegisters; ULONG MaximumLength; + KIRQL OldIrql;
/* Validate parameters in device description */ if (DeviceDescription->Version > DEVICE_DESCRIPTION_VERSION2) return NULL; @@ -688,8 +691,7 @@ HalGetAdapter(IN PDEVICE_DESCRIPTION DeviceDescription, }
/* - * Acquire the DMA lock that is used to protect adapter lists and - * EISA adapter array. + * Acquire the DMA lock that is used to protect the EISA adapter array. */ KeWaitForSingleObject(&HalpDmaLock, Executive, KernelMode, FALSE, NULL);
@@ -745,14 +747,20 @@ HalGetAdapter(IN PDEVICE_DESCRIPTION DeviceDescription, } }
- if (!EisaAdapter) InsertTailList(&HalpDmaAdapterList, &AdapterObject->AdapterList); - /* - * Release the DMA lock. HalpDmaAdapterList and HalpEisaAdapter will - * no longer be touched, so we don't need it. + * Release the DMA lock. HalpEisaAdapter will no longer be touched, + * so we don't need it. */ KeSetEvent(&HalpDmaLock, 0, 0);
+ if (!EisaAdapter) + { + /* If it's not one of the static adapters, add it to the list */ + KeAcquireSpinLock(&HalpDmaAdapterListLock, &OldIrql); + InsertTailList(&HalpDmaAdapterList, &AdapterObject->AdapterList); + KeReleaseSpinLock(&HalpDmaAdapterListLock, OldIrql); + } + /* * Setup the values in the adapter object that are common for all * types of buses. @@ -818,11 +826,12 @@ VOID NTAPI HalPutDmaAdapter(IN PADAPTER_OBJECT AdapterObject) { + KIRQL OldIrql; if (AdapterObject->ChannelNumber == 0xFF) { - KeWaitForSingleObject(&HalpDmaLock, Executive, KernelMode, FALSE, NULL); + KeAcquireSpinLock(&HalpDmaAdapterListLock, &OldIrql); RemoveEntryList(&AdapterObject->AdapterList); - KeSetEvent(&HalpDmaLock, 0, 0); + KeReleaseSpinLock(&HalpDmaAdapterListLock, OldIrql); }
ObDereferenceObject(AdapterObject);