EvtDeviceFilterRemoveResourceRequirements

I am trying to remove the IO Port assigned to my Function driver as I do not need the IO Port. With the IO Port required as a resource I will get the code 12 on some systems.

I am using EvtDeviceFilterRemoveResourceRequirements to attempt to remove this resource from the requirements, but the IO Port is still getting assigned. Is there any trick to removing the Resource Requirement?

Do I need to use both WdfIoResourceListRemove and WdfIoResourceListRemoveByDescriptor, to remove a resource descriptor?
That did not seem to make sense that I needed to call both.

Code is shown below and is getting called:
(Sorry for the formatting)

NTSTATUS EvtDeviceFilterRemoveResourceRequirements(
IN WDFDEVICE Device,
IN WDFIORESREQLIST RequirementsList
)
{
NTSTATUS status = STATUS_SUCCESS;
PRDC_DEVICE_CONTEXT rdc;
ULONG requirementCount;
ULONG resourceCount;
ULONG i,j;

rdc = GetDeviceContext(Device);

if (!rdc)
return STATUS_UNSUCCESSFUL;

KdPrint((“%s:–> EvtDeviceFilterRemoveResourceRequirements\n”, rdc->name));

// Obtain the number of logical configurations.
requirementCount = WdfIoResourceRequirementsListGetCount(RequirementsList);
KdPrint((" %s: requirementCount %d\n", rdc->name, requirementCount));

// Search each logical configuration.
for (i = 0; i < requirementCount; i++)
{
WDFIORESLIST resList;
BOOLEAN foundIOPort = FALSE;

resList =
WdfIoResourceRequirementsListGetIoResList(RequirementsList,i);

if (resList == NULL)
break;

// Get the number of resource descriptors that
// are in this logical configuration.
resourceCount = WdfIoResourceListGetCount(resList);
KdPrint((“%s: –> resourceCount %d\n”, rdc->name, resourceCount));

for (j = 0; j < resourceCount; j++)
{
PIO_RESOURCE_DESCRIPTOR descriptor;

//
// Get the next resource descriptor.
//
descriptor =
WdfIoResourceListGetDescriptor(resList, j);

if (descriptor == NULL)
{
KdPrint((“%d: NULL descriptor\n”, j));
continue;
}

switch (descriptor->Type)
{
case CmResourceTypePort:
KdPrint((“%d:Port min:(%x:%x) max:(%x:%x) Len:%x drop\n”,
j,
descriptor->u.Port.MinimumAddress.HighPart,
descriptor->u.Port.MinimumAddress.LowPart,
descriptor->u.Port.MaximumAddress.HighPart,
descriptor->u.Port.MaximumAddress.LowPart,
descriptor->u.Port.Length));
foundIOPort = TRUE;
//WdfIoResourceListRemove(resList, j);
WdfIoResourceListRemoveByDescriptor(resList, descriptor);
break;

case CmResourceTypeInterrupt:
KdPrint((“%d:Int min:(%x:%x) keep\n”, j,
descriptor->u.Interrupt.MinimumVector,
descriptor->u.Interrupt.MaximumVector));
break;

case CmResourceTypeMemory:
KdPrint((“%d:Mem min:(%x:%x) max:(%x:%x) Len:%x %s\n”,
j,
descriptor->u.Memory.MinimumAddress.HighPart,
descriptor->u.Memory.MinimumAddress.LowPart,
descriptor->u.Memory.MaximumAddress.HighPart,
descriptor->u.Memory.MaximumAddress.LowPart,
descriptor->u.Memory.Length, “keep”));
//j == 0 ? “keep”:“drop”));
//if (j != 0)
// WdfIoResourceListRemove(resList, j);
break;

default:
KdPrint((“%d:Unknown %d Priv:(%x:%x:%x) drop\n”, j,
descriptor->Type,
descriptor->u.DevicePrivate.Data[0],
descriptor->u.DevicePrivate.Data[1],
descriptor->u.DevicePrivate.Data[2]));

WdfIoResourceListRemove(resList, j);
break;
} // End Switch
} // End for (j = 0; j < resourceCount; j++)

} // End for (i = 0; i < requirementCount; i++)

KdPrint((“%s:<– EvtDeviceFilterRemoveResourceRequirements\n”, rdc->name));

return status;

}

I found this in one of the posts which did work to eliminate the I/O resource.
I could not get the KMDF Filter Resource Requirements to work.

I/O Resource Usage Reduction
http://msdn.microsoft.com/en-us/library/ff537424.aspx

Basically says to add a section in the .inf file:

[YourDriverNameInstall.HW]
include=machine.inf
Needs=PciIoSpaceNotRequired

When asking questions, it is usually a good idea to make them clear. WTF
is an “error 12”? It may surprise you to learn that the experts have not
memorized all 1300+ error codes, but we haven’t. What call are you making
when you get this error? Or is it a BSOD code? As far as I know, the
port and memory resources are assigned by the PCI BIOS and Windows honors
them, so why do you think removing this port as a resource is going to
change anything?

So the question as posed is unanswerable, unless you luck out and find
someone who has had to solve this exact problem and recognizes it.
joe

I am trying to remove the IO Port assigned to my Function driver as I do
not need the IO Port. With the IO Port required as a resource I will get
the code 12 on some systems.

I am using EvtDeviceFilterRemoveResourceRequirements to attempt to remove
this resource from the requirements, but the IO Port is still getting
assigned. Is there any trick to removing the Resource Requirement?

Do I need to use both WdfIoResourceListRemove and
WdfIoResourceListRemoveByDescriptor, to remove a resource descriptor?
That did not seem to make sense that I needed to call both.

Code is shown below and is getting called:
(Sorry for the formatting)

NTSTATUS EvtDeviceFilterRemoveResourceRequirements(
IN WDFDEVICE Device,
IN WDFIORESREQLIST RequirementsList
)
{
NTSTATUS status = STATUS_SUCCESS;
PRDC_DEVICE_CONTEXT rdc;
ULONG requirementCount;
ULONG resourceCount;
ULONG i,j;

rdc = GetDeviceContext(Device);

if (!rdc)
return STATUS_UNSUCCESSFUL;

KdPrint((“%s:–> EvtDeviceFilterRemoveResourceRequirements\n”,
rdc->name));

// Obtain the number of logical configurations.
requirementCount =
WdfIoResourceRequirementsListGetCount(RequirementsList);
KdPrint((" %s: requirementCount %d\n", rdc->name, requirementCount));

// Search each logical configuration.
for (i = 0; i < requirementCount; i++)
{
WDFIORESLIST resList;
BOOLEAN foundIOPort = FALSE;

resList =
WdfIoResourceRequirementsListGetIoResList(RequirementsList,i);

if (resList == NULL)
break;

// Get the number of resource descriptors that
// are in this logical configuration.
resourceCount = WdfIoResourceListGetCount(resList);
KdPrint((“%s: –> resourceCount %d\n”, rdc->name, resourceCount));

for (j = 0; j < resourceCount; j++)
{
PIO_RESOURCE_DESCRIPTOR descriptor;

//
// Get the next resource descriptor.
//
descriptor =
WdfIoResourceListGetDescriptor(resList, j);

if (descriptor == NULL)
{
KdPrint((“%d: NULL descriptor\n”, j));
continue;
}

switch (descriptor->Type)
{
case CmResourceTypePort:
KdPrint((“%d:Port min:(%x:%x) max:(%x:%x) Len:%x drop\n”,
j,
descriptor->u.Port.MinimumAddress.HighPart,
descriptor->u.Port.MinimumAddress.LowPart,
descriptor->u.Port.MaximumAddress.HighPart,
descriptor->u.Port.MaximumAddress.LowPart,
descriptor->u.Port.Length));
foundIOPort = TRUE;
//WdfIoResourceListRemove(resList, j);
WdfIoResourceListRemoveByDescriptor(resList, descriptor);
break;

case CmResourceTypeInterrupt:
KdPrint((“%d:Int min:(%x:%x) keep\n”, j,
descriptor->u.Interrupt.MinimumVector,
descriptor->u.Interrupt.MaximumVector));
break;

case CmResourceTypeMemory:
KdPrint((“%d:Mem min:(%x:%x) max:(%x:%x) Len:%x %s\n”,
j,
descriptor->u.Memory.MinimumAddress.HighPart,
descriptor->u.Memory.MinimumAddress.LowPart,
descriptor->u.Memory.MaximumAddress.HighPart,
descriptor->u.Memory.MaximumAddress.LowPart,
descriptor->u.Memory.Length, “keep”));
//j == 0 ? “keep”:“drop”));
//if (j != 0)
// WdfIoResourceListRemove(resList, j);
break;

default:
KdPrint((“%d:Unknown %d Priv:(%x:%x:%x) drop\n”, j,
descriptor->Type,
descriptor->u.DevicePrivate.Data[0],
descriptor->u.DevicePrivate.Data[1],
descriptor->u.DevicePrivate.Data[2]));

WdfIoResourceListRemove(resList, j);
break;
} // End Switch
} // End for (j = 0; j < resourceCount; j++)

} // End for (i = 0; i < requirementCount; i++)

KdPrint((“%s:<– EvtDeviceFilterRemoveResourceRequirements\n”,
rdc->name));

return status;

}


NTDEV is sponsored by OSR

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

> As far as I know, the port and memory resources are assigned by the PCI BIOS and Windows

honors them, so why do you think removing this port as a resource is going to change anything?

If a device tells the OS that it does not need any IO resources, then the OS can turn off IO decode for this particular device. If no devices behind a particular bridge are enabled for IO decode, then the bridge?s IO window can be closed. Therefore, the OP just tries to optimise things for the systems that implement
multilevel rebalance (i.e Vista+), although, as far as the earlier OS versions are concerned, all his endeavors seem to be, indeed, pointless…

Anton Bassov

If that’s a PCI(e) device, changing a layout of resources (so their order doesn’t match order of BARs) may confuse PCI.SYS. Why not just simply reprogram NVRAM in your device that reports config information?

This is the correct way to solve your problem. It’s possible to make the resource filtering work, but you need to put back the resources that you filtered out before the START comes down to the bus driver, which is obviously problematic.

If you’re curious, you can read machine.inf to see all the other things that you can do like this in your INF to change the behavior of PCI.sys.

  • Jake Oshins
    (sometime PCI guy)
    Windows Kernel Team

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@yahoo.com
Sent: Saturday, May 11, 2013 6:26 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] EvtDeviceFilterRemoveResourceRequirements

I found this in one of the posts which did work to eliminate the I/O resource.
I could not get the KMDF Filter Resource Requirements to work.

I/O Resource Usage Reduction
http://msdn.microsoft.com/en-us/library/ff537424.aspx

Basically says to add a section in the .inf file:

[YourDriverNameInstall.HW]
include=machine.inf
Needs=PciIoSpaceNotRequired


NTDEV is sponsored by OSR

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Sorry for not being clear on the error code.
The Code 12 was reported by the Device Manager after installing the device.
Code 12: This device cannot find enough free resources that it can use.
I have seen “Code 12” referred to on this and other Forums so I assumed that this was a common enough condition that it need no further explanation.

My question is still on the proper usage of EvtDeviceFilterRemoveResourceRequirements. I have seen some examples from Microsoft on the usage of the routine, but I still have not found a comprehensive explanation as to when and how to properly use the routine.

The name of the Event seemed imply that it would accomplish what I was trying to achieve (telling the OS that I did not require the IO resource). I was not aware that the resource had to be added back in on the way back up the device stack. We had used the IRP_MN_FILTER_RESOURCE_REQUIREMENTS in the WDM driver to achieve the desired result of removing unneeded resources from our requirements list and I assumed that EvtDeviceFilterRemoveResourceRequirements would provide the same for the WDF driver.

Any insight into the proper usage of EvtDeviceFilterRemoveResourceRequirements would be much appreciated.

I agree that the best solution would be to modify the NVRAM of the device to disable any unneeded resources. Unfortunately we can not achieve this practically as we have many device out in the field and also several version of NVRAM so it is difficult to programmatically modify the devices.

The WDM driver appeared to be able to discard unrequired resources so I am trying to achieve the same with the WDF driver.

Thanks.

Also I would like to refer the group to this article from Microsoft http://msdn.microsoft.com/en-us/library/windows/hardware/ff544331(v=vs.85).aspx which seems to show the usage of EvtDeviceFilterRemoveResourceRequirements for the same purpose of removing the IO resource as a requirement. I just can’t get it to work as the IO resource still shows up when trying to use this method:

After the PnP manager has ensured that all of a newly connected device’s drivers have been loaded, it sends the device’s hardware requirements list to the device’s driver stack.

As the list travels down the stack, the framework calls each function and filter driver’s EvtDeviceFilterRemoveResourceRequirements callback function, passing the hardware requirements list as an input argument. This callback function can remove hardware resources from the hardware requirements list that the bus driver has specified but that the function driver determines are not necessary for the device to operate.

For example, a PCI bus driver might, in accordance with the PCI specification, replicate an I/O space resource in memory space. If your device can operate without using the I/O space resource, the device’s function driver can remove the I/O space resource from the hardware requirements list.

> Sorry for not being clear on the error code.

The Code 12 was reported by the Device Manager after installing the
device.
Code 12: This device cannot find enough free resources that it can use.
I have seen “Code 12” referred to on this and other Forums so I assumed
that this was a common enough condition that it need no further
explanation.

It might have been to some, but it conveyed nothing to me.

My question is still on the proper usage of
EvtDeviceFilterRemoveResourceRequirements. I have seen some examples from
Microsoft on the usage of the routine, but I still have not found a
comprehensive explanation as to when and how to properly use the routine.

But there’s a problem here. The resources are supposed to be preallocated
by the PCI BIOS, so there shouldn’t be a problem obtaining them by the
time the driver loads, geological eons later (mapping computer time to
human time).

If there is a problem, it would appear in the HAL routines that map bus
resources to virtual resources, such as memory resources. These still
exist, lurking deep in the WDM support code (by which we get the raw and
translated resources for IRP_MJ_PNP:IRP_MN_START_DEVICE (if I’ve
remembered the MN name correctly).

So I’m still unclear about the temporal relationship between the Evt
method in a filter driver, and the underlying hardware driver, which
presumably has to be loaded before the filter driver (or might be), and
the rest of the startup sequence when the device is loaded. Or why a
filter driver can know what hardware resources a device well below it on
the stack can need.

Then again, someone may point out that I am totally clueless here.
joe

The name of the Event seemed imply that it would accomplish what I was
trying to achieve (telling the OS that I did not require the IO resource).
I was not aware that the resource had to be added back in on the way back
up the device stack. We had used the IRP_MN_FILTER_RESOURCE_REQUIREMENTS
in the WDM driver to achieve the desired result of removing unneeded
resources from our requirements list and I assumed that
EvtDeviceFilterRemoveResourceRequirements would provide the same for the
WDF driver.

Any insight into the proper usage of
EvtDeviceFilterRemoveResourceRequirements would be much appreciated.

I agree that the best solution would be to modify the NVRAM of the device
to disable any unneeded resources. Unfortunately we can not achieve this
practically as we have many device out in the field and also several
version of NVRAM so it is difficult to programmatically modify the
devices.

There is no supported interface that I am aware of form modifying NVRAM.

The WDM driver appeared to be able to discard unrequired resources so I am
trying to achieve the same with the WDF driver.

Thanks.


NTDEV is sponsored by OSR

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

xxxxx@flounder.com wrote:

> My question is still on the proper usage of
> EvtDeviceFilterRemoveResourceRequirements. I have seen some examples from
> Microsoft on the usage of the routine, but I still have not found a
> comprehensive explanation as to when and how to properly use the routine.
But there’s a problem here. The resources are supposed to be preallocated
by the PCI BIOS, so there shouldn’t be a problem obtaining them by the
time the driver loads, geological eons later (mapping computer time to
human time).

Then again, someone may point out that I am totally clueless here.

Not totally, but you’re taking a very narrow viewpoint, which is
something that you have a habit of doing.

The PnP resource negotiations are supposed to allow him to do exactly
what he’s asking. The PnP subsystem passes the requirements list down
through the driver stack. Even if a device cannot have its resources
satisfied by the BIOS, if the conflicting requirements can be trimmed
from the list, then PnP can do its own allocation. Please note that he
has an existence proof that this works from a WDM driver.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Please dump the wdf log (!wdfkd.wdflogdump ) for your driver in an initial call to a power up callback (if you get that far). If you don’t get that far, dump the log in your cleanup() routine on your WDFDEVICE. Io resource removal SHOULD work with this callback.

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Tim Roberts
Sent: Wednesday, May 15, 2013 10:07 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] EvtDeviceFilterRemoveResourceRequirements

xxxxx@flounder.com wrote:
>> My question is still on the proper usage of
>> EvtDeviceFilterRemoveResourceRequirements. I have seen some examples
>> from Microsoft on the usage of the routine, but I still have not
>> found a comprehensive explanation as to when and how to properly use the routine.
> But there’s a problem here. The resources are supposed to be
> preallocated by the PCI BIOS, so there shouldn’t be a problem
> obtaining them by the time the driver loads, geological eons later
> (mapping computer time to human time).
> …
> Then again, someone may point out that I am totally clueless here.

Not totally, but you’re taking a very narrow viewpoint, which is something that you have a habit of doing.

The PnP resource negotiations are supposed to allow him to do exactly what he’s asking. The PnP subsystem passes the requirements list down through the driver stack. Even if a device cannot have its resources satisfied by the BIOS, if the conflicting requirements can be trimmed from the list, then PnP can do its own allocation. Please note that he has an existence proof that this works from a WDM driver.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.


NTDEV is sponsored by OSR

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer