Ressources

On peut travailler directement avec des entrées-sorties, la mémoire des cartes ou les interruptions sans qu'elles apparaissent dans la liste des ressources allouées au driver (panneau de configuration/Système, onglet ressource)

Pour les réserver il faut faire appel à IoReportResourceUsage en lui indiquant par une structure un peu complexe les ressources utilisées. Voici in exemple.

 

// positionnement / retrait des ressources
bool Ressources(IN PDRIVER_OBJECT DriverObject,bool set)
{

// Variables used to register resource usage (ports). 
BOOLEAN ResourceConflict; // This is set true if our I/O ports. 
CM_RESOURCE_LIST *pResourceList; // Resource usage list to report to system.
ULONG sizeofResourceList; 
struct
{
CM_RESOURCE_LIST ResourceList;
CM_PARTIAL_RESOURCE_DESCRIPTOR rdesc[3];
} totalResourceList;
PHYSICAL_ADDRESS PortAddress;
PHYSICAL_ADDRESS MemoryAddress;
sizeofResourceList = sizeof(totalResourceList);
pResourceList = (CM_RESOURCE_LIST*) & totalResourceList ;

RtlZeroMemory( (PVOID)pResourceList, sizeofResourceList );
PortAddress.LowPart = RegistryConfig.Cards[0].Port ;
PortAddress.HighPart = 0;
MemoryAddress.LowPart = RegistryConfig.Cards[0].Memory ;
MemoryAddress.HighPart = 0;

if(!set)
pResourceList->Count = 0;
else
{
pResourceList->Count = 1;
pResourceList->List[0].InterfaceType = Isa;
// ResourceList.List[0].Busnumber = 0; Already 0 by previous call of RtlZeroMemory().
pResourceList->List[0].PartialResourceList.Count = 3;
pResourceList->List[0].PartialResourceList.PartialDescriptors[0].Type = CmResourceTypePort;
pResourceList->List[0].PartialResourceList.PartialDescriptors[0].Flags = CM_RESOURCE_PORT_IO;
pResourceList->List[0].PartialResourceList.PartialDescriptors[0].ShareDisposition = CmResourceShareDriverExclusive;
pResourceList->List[0].PartialResourceList.PartialDescriptors[0].u.Port.Start = PortAddress;
pResourceList->List[0].PartialResourceList.PartialDescriptors[0].u.Port.Length = 0X40;

pResourceList->List[0].PartialResourceList.PartialDescriptors[1].Type = CmResourceTypeInterrupt;
pResourceList->List[0].PartialResourceList.PartialDescriptors[1].Flags = CM_RESOURCE_INTERRUPT_LATCHED; // or _LEVEL_SENSITIVE .
pResourceList->List[0].PartialResourceList.PartialDescriptors[1].ShareDisposition = CmResourceShareDriverExclusive;
pResourceList->List[0].PartialResourceList.PartialDescriptors[1].u.Interrupt.Level = 10;
pResourceList->List[0].PartialResourceList.PartialDescriptors[1].u.Interrupt.Vector = 10;
pResourceList->List[0].PartialResourceList.PartialDescriptors[1].u.Interrupt.Affinity = -1;

pResourceList->List[0].PartialResourceList.PartialDescriptors[2].Type = CmResourceTypeMemory;
pResourceList->List[0].PartialResourceList.PartialDescriptors[2].Flags = CM_RESOURCE_MEMORY_READ_WRITE;
pResourceList->List[0].PartialResourceList.PartialDescriptors[2].ShareDisposition = CmResourceShareDriverExclusive;
pResourceList->List[0].PartialResourceList.PartialDescriptors[2].u.Memory.Start = MemoryAddress;
pResourceList->List[0].PartialResourceList.PartialDescriptors[2].u.Memory.Length = 0X10000;

IoReportResourceUsage(
NULL, /* optional */
DriverObject,
pResourceList, // Driver resources list. 
sizeofResourceList,
DeviceObject,
NULL, /* optional */
0, /* optional */
FALSE,
& ResourceConflict
);
if(set && ResourceConflict)
DbgPrint("Conflit de ressource\n");
return(!ResourceConflict);
}

Accueil ] Remonter ]