From de6313d89e8c28d6390a1cd7e8f6bfd783918e02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Fri, 23 Jun 2023 15:56:20 +0200 Subject: [PATCH] [VIDEOPRT] Reformat VideoPortVerifyAccessRanges() Fix indentation, add SAL annotations and Doxygen description. --- sdk/include/ddk/video.h | 6 +- win32ss/drivers/videoprt/resource.c | 156 +++++++++++++++------------- 2 files changed, 89 insertions(+), 73 deletions(-) diff --git a/sdk/include/ddk/video.h b/sdk/include/ddk/video.h index d4f32002b15..58c2420754b 100644 --- a/sdk/include/ddk/video.h +++ b/sdk/include/ddk/video.h @@ -1251,9 +1251,9 @@ VPAPI VP_STATUS NTAPI VideoPortVerifyAccessRanges( - IN PVOID HwDeviceExtension, - IN ULONG NumAccessRanges, - IN PVIDEO_ACCESS_RANGE AccessRanges); + _In_ PVOID HwDeviceExtension, + _In_opt_ ULONG NumAccessRanges, + _In_reads_opt_(NumAccessRanges) PVIDEO_ACCESS_RANGE AccessRanges); VPAPI VOID diff --git a/win32ss/drivers/videoprt/resource.c b/win32ss/drivers/videoprt/resource.c index cd85c9feb43..1cbf1f609a9 100644 --- a/win32ss/drivers/videoprt/resource.c +++ b/win32ss/drivers/videoprt/resource.c @@ -816,84 +816,100 @@ VideoPortGetAccessRanges( return NO_ERROR; } -/* - * @implemented - */ - -VP_STATUS NTAPI +/** + * @brief + * Claims or releases a range of hardware resources and checks for conflicts. + * + * @param[in] HwDeviceExtension + * The miniport device extension. + * + * @param[in] NumAccessRanges + * The number of hardware resource ranges in the @p AccessRanges array. + * Specify zero to release the hardware resources held by the miniport. + * + * @param[in] AccessRanges + * The array of hardware resource ranges to claim ownership. + * Specify NULL to release the hardware resources held by the miniport. + * + * @return + * NO_ERROR if the resources have been successfully claimed or released. + * ERROR_INVALID_PARAMETER if an error or a conflict occurred. + **/ +VP_STATUS +NTAPI VideoPortVerifyAccessRanges( - IN PVOID HwDeviceExtension, - IN ULONG NumAccessRanges, - IN PVIDEO_ACCESS_RANGE AccessRanges) + _In_ PVOID HwDeviceExtension, + _In_opt_ ULONG NumAccessRanges, + _In_reads_opt_(NumAccessRanges) PVIDEO_ACCESS_RANGE AccessRanges) { - PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension; - BOOLEAN ConflictDetected; - ULONG i; - PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor; - PCM_RESOURCE_LIST ResourceList; - ULONG ResourceListSize; - NTSTATUS Status; + PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension; + BOOLEAN ConflictDetected; + ULONG i; + PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor; + PCM_RESOURCE_LIST ResourceList; + ULONG ResourceListSize; + NTSTATUS Status; - TRACE_(VIDEOPRT, "VideoPortVerifyAccessRanges\n"); + TRACE_(VIDEOPRT, "VideoPortVerifyAccessRanges\n"); - DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension); + DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension); - /* Create the resource list */ - ResourceListSize = sizeof(CM_RESOURCE_LIST) - + (NumAccessRanges - 1) * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR); - ResourceList = ExAllocatePool(PagedPool, ResourceListSize); - if (!ResourceList) - { - WARN_(VIDEOPRT, "ExAllocatePool() failed\n"); - return ERROR_NOT_ENOUGH_MEMORY; - } + /* Create the resource list */ + ResourceListSize = sizeof(CM_RESOURCE_LIST) + + (NumAccessRanges - 1) * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR); + ResourceList = ExAllocatePool(PagedPool, ResourceListSize); + if (!ResourceList) + { + WARN_(VIDEOPRT, "ExAllocatePool() failed\n"); + return ERROR_NOT_ENOUGH_MEMORY; + } - /* Fill resource list */ - ResourceList->Count = 1; - ResourceList->List[0].InterfaceType = DeviceExtension->AdapterInterfaceType; - ResourceList->List[0].BusNumber = DeviceExtension->SystemIoBusNumber; - ResourceList->List[0].PartialResourceList.Version = 1; - ResourceList->List[0].PartialResourceList.Revision = 1; - ResourceList->List[0].PartialResourceList.Count = NumAccessRanges; - for (i = 0; i < NumAccessRanges; i++, AccessRanges++) - { - PartialDescriptor = &ResourceList->List[0].PartialResourceList.PartialDescriptors[i]; - if (AccessRanges->RangeInIoSpace) - { - PartialDescriptor->Type = CmResourceTypePort; - PartialDescriptor->u.Port.Start = AccessRanges->RangeStart; - PartialDescriptor->u.Port.Length = AccessRanges->RangeLength; - } - else - { - PartialDescriptor->Type = CmResourceTypeMemory; - PartialDescriptor->u.Memory.Start = AccessRanges->RangeStart; - PartialDescriptor->u.Memory.Length = AccessRanges->RangeLength; - } - if (AccessRanges->RangeShareable) - PartialDescriptor->ShareDisposition = CmResourceShareShared; - else - PartialDescriptor->ShareDisposition = CmResourceShareDeviceExclusive; - PartialDescriptor->Flags = 0; - if (AccessRanges->RangePassive & VIDEO_RANGE_PASSIVE_DECODE) - PartialDescriptor->Flags |= CM_RESOURCE_PORT_PASSIVE_DECODE; - if (AccessRanges->RangePassive & VIDEO_RANGE_10_BIT_DECODE) - PartialDescriptor->Flags |= CM_RESOURCE_PORT_10_BIT_DECODE; - } + /* Fill resource list */ + ResourceList->Count = 1; + ResourceList->List[0].InterfaceType = DeviceExtension->AdapterInterfaceType; + ResourceList->List[0].BusNumber = DeviceExtension->SystemIoBusNumber; + ResourceList->List[0].PartialResourceList.Version = 1; + ResourceList->List[0].PartialResourceList.Revision = 1; + ResourceList->List[0].PartialResourceList.Count = NumAccessRanges; + for (i = 0; i < NumAccessRanges; i++, AccessRanges++) + { + PartialDescriptor = &ResourceList->List[0].PartialResourceList.PartialDescriptors[i]; + if (AccessRanges->RangeInIoSpace) + { + PartialDescriptor->Type = CmResourceTypePort; + PartialDescriptor->u.Port.Start = AccessRanges->RangeStart; + PartialDescriptor->u.Port.Length = AccessRanges->RangeLength; + } + else + { + PartialDescriptor->Type = CmResourceTypeMemory; + PartialDescriptor->u.Memory.Start = AccessRanges->RangeStart; + PartialDescriptor->u.Memory.Length = AccessRanges->RangeLength; + } + if (AccessRanges->RangeShareable) + PartialDescriptor->ShareDisposition = CmResourceShareShared; + else + PartialDescriptor->ShareDisposition = CmResourceShareDeviceExclusive; + PartialDescriptor->Flags = 0; + if (AccessRanges->RangePassive & VIDEO_RANGE_PASSIVE_DECODE) + PartialDescriptor->Flags |= CM_RESOURCE_PORT_PASSIVE_DECODE; + if (AccessRanges->RangePassive & VIDEO_RANGE_10_BIT_DECODE) + PartialDescriptor->Flags |= CM_RESOURCE_PORT_10_BIT_DECODE; + } - /* Try to acquire all resource ranges */ - Status = IoReportResourceForDetection( - DeviceExtension->DriverObject, - NULL, 0, /* Driver List */ - DeviceExtension->PhysicalDeviceObject, - ResourceList, ResourceListSize, - &ConflictDetected); - ExFreePool(ResourceList); + /* Try to acquire all resource ranges */ + Status = IoReportResourceForDetection( + DeviceExtension->DriverObject, + NULL, 0, /* Driver List */ + DeviceExtension->PhysicalDeviceObject, + ResourceList, ResourceListSize, + &ConflictDetected); + ExFreePool(ResourceList); - if (!NT_SUCCESS(Status) || ConflictDetected) - return ERROR_INVALID_PARAMETER; - else - return NO_ERROR; + if (!NT_SUCCESS(Status) || ConflictDetected) + return ERROR_INVALID_PARAMETER; + else + return NO_ERROR; } /*