📄 pcidpprotect.c
字号:
//*****************************************************************************
// THIS CODE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
// OR IMPLIED. THIS CODE IS LABELED "OPEN SOFTWARE" AND MAY BE FREELY USED,
// REPRODUCED, MODIFIED, AND/OR REDISTRIBUTED WITH THE STIPULATION THAT THIS
// NOTICE REMAIN INTACT. REDISTRIBUTION OF ANY KIND IMPLIES THAT ALL
// MODIFICATIONS FALL UNDER THIS "OPEN SOFTWARE" LABEL.
//
// Copyright (C) 2000, Foxen Solutions
// Copyright (C) 2000, FXN
//
// All Rights Reserved.
//*****************************************************************************
//
// This is PCIDPProtect.c. It contains those routines whose access status
// is protected to within the PCIDP kernel driver.
#include "PCIDPInc.h"
#include "PCIDP.h"
// ----------------------------------------------------------------------------
// Report Resources
// ----------------------------------------------------------------------------
NTSTATUS ReportResources(
IN PDEVICE_OBJECT DeviceObject,
IN PPCI_COMMON_CONFIG CardInfo
){
BOOLEAN ConflictDetected;
NTSTATUS NTStatus;
PHYSICAL_ADDRESS PhysicalAddress = {0,0};
ULONG SizeOfResourceList;
//ULONG* DataPointer;
PCM_RESOURCE_LIST ResourceList;
PCM_FULL_RESOURCE_DESCRIPTOR FullResource;
PCM_PARTIAL_RESOURCE_LIST PartialList;
PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialResource;
pPCIDP_EXTENSION ObjExt = (pPCIDP_EXTENSION)DeviceObject->DeviceExtension;
// The size of the resource list is going to be one full resource
// list which already has one full resource descriptor included
// which already has one partial list included which already has
// one partial descriptor included; plus four more partial descriptors.
// One partial descriptor will be for the interrupt, one for the port,
// and the remaining three for memory. The full resource descriptor
// describes the PCI bus. Each partial resource descriptor describes
// each type of resource (e.g. interrupts, memory, ports).
SizeOfResourceList = sizeof(CM_RESOURCE_LIST);
SizeOfResourceList += sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR)*8;
SizeOfResourceList += sizeof(ULONG)*5; //device specific data
// Now allocate memory pool for the structure.
ResourceList = ExAllocatePool(
PagedPool,
SizeOfResourceList
);
// Initialize the structure prior to calling IoReportResourceUsage.
if(ResourceList){
RtlZeroMemory(ResourceList, SizeOfResourceList);
ResourceList->Count = 1; // number of resource descriptors
FullResource = &ResourceList->List[0];
FullResource->InterfaceType = PCIBus;
FullResource->BusNumber = ObjExt->BusNumber;
PartialList = &FullResource->PartialResourceList;
PartialList->Version = 1;
PartialList->Revision = 0;
// Calculate the number of partial resource descriptors.
if((ULONG)CardInfo->u.type0.InterruptPin == 0)
PartialList->Count = 3;
else
PartialList->Count = 4;
PartialResource = &PartialList->PartialDescriptors[0];
// Fill the partial resource for the interrupt.
PartialResource++;
if((ULONG)CardInfo->u.type0.InterruptPin != 0){
PartialResource->Type = CmResourceTypeInterrupt;
PartialResource->ShareDisposition = CmResourceShareShared;
//PartialResource->Flags = CM_RESOURCE_INTERRUPT_LATCHED;
PartialResource->Flags = CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE;
PartialResource->u.Interrupt.Level = (ULONG)CardInfo->u.type0.InterruptLine;
PartialResource->u.Interrupt.Vector = 0;
PartialResource->u.Interrupt.Affinity = 0;
PartialResource++;
}
// Fill the partial resource for the port I/O board registers.
PartialResource->Type = CmResourceTypePort;
PartialResource->ShareDisposition = CmResourceShareDeviceExclusive;
PartialResource->Flags = CM_RESOURCE_PORT_IO;
PhysicalAddress.LowPart = CardInfo->u.type0.BaseAddresses[1] & 0xFFFFFFFE;
PartialResource->u.Port.Start = PhysicalAddress;
PartialResource->u.Port.Length = 8;
// Fill the partial resource for the memory mapped RAM.
PartialResource++;
PartialResource->Type = CmResourceTypeMemory;
PartialResource->ShareDisposition = CmResourceShareDeviceExclusive;
PartialResource->Flags = CM_RESOURCE_MEMORY_READ_WRITE;
PhysicalAddress.LowPart = CardInfo->u.type0.BaseAddresses[0];
PartialResource->u.Memory.Start = PhysicalAddress;
PartialResource->u.Memory.Length = MemoryBaseSize;
// Fill the partial resource for the memory mapped DMA.
PartialResource++;
PartialResource->Type = CmResourceTypeMemory;
PartialResource->ShareDisposition = CmResourceShareShared;
PartialResource->Flags = CM_RESOURCE_MEMORY_READ_WRITE;
PhysicalAddress.LowPart = (ULONG)ObjExt->PhysicalDMAAddress;
PartialResource->u.Memory.Start = PhysicalAddress;
PartialResource->u.Memory.Length = DMASize;
// Fill the partial resource with device specific data.
//PartialResource++;
//PartialResource->Type = CmResourceTypeDeviceSpecific;
//PartialResource->ShareDisposition = CmResourceShareUndetermined;
//PartialResource->u.DeviceSpecificData.DataSize = 20;
//PartialResource++;
//DataPointer = (ULONG*)PartialResource;
//*DataPointer = CardInfo->u.type0.BaseAddresses[0] & 0xFFFFFFFE;
//DataPointer++;
//*DataPointer = CardInfo->u.type0.BaseAddresses[1];
//DataPointer++;
//*DataPointer = CardInfo->u.type0.BaseAddresses[2];
//DataPointer++;
//*DataPointer = CardInfo->u.type0.BaseAddresses[3];
//DataPointer++;
//*DataPointer = (ULONG)CardInfo->u.type0.InterruptLine;
// Now report all of this stuff.
NTStatus = IoReportResourceUsage(
NULL,
DeviceObject->DriverObject,
NULL,
0,
DeviceObject,
ResourceList,
SizeOfResourceList,
FALSE, // override conflict
&ConflictDetected
);
if(NTStatus == STATUS_SUCCESS)
if(ConflictDetected == TRUE)
NTStatus = STATUS_INSUFFICIENT_RESOURCES;
ExFreePool(ResourceList);
}
else
NTStatus = STATUS_NO_MEMORY;
return NTStatus;
}
// ----------------------------------------------------------------------------
// UnReportResoureces
// ----------------------------------------------------------------------------
NTSTATUS UnReportResources(
IN PDEVICE_OBJECT DeviceObject
){
NTSTATUS NTStatus;
BOOLEAN ConflictDetected;
ULONG SizeOfResourceList;
PCM_RESOURCE_LIST ResourceList;
// The size of the resource list is going to be one full resource
// list which already has one full resource descriptor included
// which already has one partial list included which already has
// one partial descriptor included.
SizeOfResourceList = sizeof(CM_RESOURCE_LIST);
// Now allocate memory pool for the structure.
ResourceList = ExAllocatePool(
PagedPool,
SizeOfResourceList
);
// Initialize the structure prior to calling IoReportResourceUsage.
if(ResourceList){
RtlZeroMemory(ResourceList, SizeOfResourceList);
// Having the resource list "empty" is equilvalent to deallocating the
// driver's assigned resources.
NTStatus = IoReportResourceUsage(
NULL,
DeviceObject->DriverObject,
NULL,
0,
DeviceObject,
ResourceList,
SizeOfResourceList,
FALSE,
&ConflictDetected
);
if(ConflictDetected == FALSE && NTStatus == STATUS_SUCCESS)
;
else
NTStatus = STATUS_INSUFFICIENT_RESOURCES;
ExFreePool(ResourceList);
}
else
NTStatus = STATUS_NO_MEMORY;
return NTStatus;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -