Error creating fast mutex lock

I created a WDF driver that talks to a device over an I2C bus. I need to lock the bus to prevent simultaneous access to it. I cannot use a spinlock since the transaction takes several milliseconds (and many 10s of milliseconds if communication times out). I cannot use a spinlock because it should not be used for that length of time. So I am trying to use a fast mutex. When I use the following code to create the lock in EvtDeviceAdd(), I get ntstatus error 0xC0200211.

WDF_OBJECT_ATTRIBUTES attributes;
WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
attributes.ParentObject = fdoData->WdfDevice;
attributes.ExecutionLevel = WdfExecutionLevelPassive; // force lock to be a fast mutex
status = WdfWaitLockCreate(&attributes, &I2cLock);

When I comment out the line “attributes.ExecutionLevel = WdfExecutionLevelPassive” I do not get the error. According to the documentation for WdfObjectAcquireLock, it says that “If the driver specified WdfExecutionLevelPassive for the ExecutionLevel member of the specified object’s WDF_OBJECT_ATTRIBUTES structure…WdfObjectAcquireLock acquires a fast mutex…” and “If the driver did not specify WdfExecutionLevelPassive for the ExecutionLevel member of the specified object’s WDF_OBJECT_ATTRIBUTES structure…WdfObjectAcquireLock acquires a spin lock…”

I am trying to use a fast mutex so I think I need WdfExecutionLevelPassive for this object. Please help, thanks.

You are over reading it. You don’t use WdfbjectAcquireLock to grab the wait lock, you use WdfWaitLockAcquire which has the right IRQL behavior.

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@goodrich.com
Sent: Wednesday, April 15, 2015 12:14 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Error creating fast mutex lock

I created a WDF driver that talks to a device over an I2C bus. I need to lock the bus to prevent simultaneous access to it. I cannot use a spinlock since the transaction takes several milliseconds (and many 10s of milliseconds if communication times out). I cannot use a spinlock because it should not be used for that length of time. So I am trying to use a fast mutex. When I use the following code to create the lock in EvtDeviceAdd(), I get ntstatus error 0xC0200211.

WDF_OBJECT_ATTRIBUTES attributes;
WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
attributes.ParentObject = fdoData->WdfDevice;
attributes.ExecutionLevel = WdfExecutionLevelPassive; // force lock to be a fast mutex
status = WdfWaitLockCreate(&attributes, &I2cLock);

When I comment out the line “attributes.ExecutionLevel = WdfExecutionLevelPassive” I do not get the error. According to the documentation for WdfObjectAcquireLock, it says that “If the driver specified WdfExecutionLevelPassive for the ExecutionLevel member of the specified object’s WDF_OBJECT_ATTRIBUTES structure…WdfObjectAcquireLock acquires a fast mutex…” and “If the driver did not specify WdfExecutionLevelPassive for the ExecutionLevel member of the specified object’s WDF_OBJECT_ATTRIBUTES structure…WdfObjectAcquireLock acquires a spin lock…”

I am trying to use a fast mutex so I think I need WdfExecutionLevelPassive for this object. Please help, thanks.


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

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

Do you own the I2C bus controller? Or are you talking to another driver to send traffic on the bus?

I would hope the I2C controller driver would take responsibility for managing simultaneous access to the underlying bus. All you might need to do is ensure that you don’t make more than one request of the bus driver at a time. To do that you don’t hold a lock while talking to the bus driver. You hold a lock while deciding if there’s an active request already, and queuing the new work if there is. Then you drop the lock and, if there wasn’t an active request, you start one up.

-p

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@goodrich.com
Sent: Wednesday, April 15, 2015 12:14 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Error creating fast mutex lock

I created a WDF driver that talks to a device over an I2C bus. I need to lock the bus to prevent simultaneous access to it. I cannot use a spinlock since the transaction takes several milliseconds (and many 10s of milliseconds if communication times out). I cannot use a spinlock because it should not be used for that length of time. So I am trying to use a fast mutex. When I use the following code to create the lock in EvtDeviceAdd(), I get ntstatus error 0xC0200211.

WDF_OBJECT_ATTRIBUTES attributes;
WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
attributes.ParentObject = fdoData->WdfDevice;
attributes.ExecutionLevel = WdfExecutionLevelPassive; // force lock to be a fast mutex
status = WdfWaitLockCreate(&attributes, &I2cLock);

When I comment out the line “attributes.ExecutionLevel = WdfExecutionLevelPassive” I do not get the error. According to the documentation for WdfObjectAcquireLock, it says that “If the driver specified WdfExecutionLevelPassive for the ExecutionLevel member of the specified object’s WDF_OBJECT_ATTRIBUTES structure…WdfObjectAcquireLock acquires a fast mutex…” and “If the driver did not specify WdfExecutionLevelPassive for the ExecutionLevel member of the specified object’s WDF_OBJECT_ATTRIBUTES structure…WdfObjectAcquireLock acquires a spin lock…”

I am trying to use a fast mutex so I think I need WdfExecutionLevelPassive for this object. Please help, thanks.


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

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