Stream class mini-driver with PCI interface

Hi all,
I am developing a stream class mini-driver with PCI interface. I use following example codes to implement:
WINDDK\3790.1830\src\wdm\videocap\testcap
WINDDK\3790.1830\src\general\pcidrv\sys
I add pcidrv’s code into testcap, and now I can install testcap.sys and can get PCI BusInterface.
However, I encounter a problem as following:
I do “MapHWResources” in “HwInitialize” of testcap, and map IO space as below:

for (i = 0; i < partialResourceListTranslated->Count; i++, resourceTrans++)
{
switch (resourceTrans->Type) {
case CmResourceTypeMemory:
if(numberOfBARs == 1) {
pHwDevExt->MemPhysAddress_bar0 = resourceTrans->u.Memory.Start;
resourceTrans->u.Memory.Length = 0x10000000 ; /* 28 bit : 256mb */
pHwDevExt->CSRAddress =(ULONG)( MmMapIoSpace(
resourceTrans->u.Memory.Start,
resourceTrans->u.Memory.Length, /*28 bit :256mb*/
MmNonCached));

When I perform memory read/write such as “READ_REGISTER_ULONG/WRITE_REGISTER_ULONG” or “RtlCopyMemory” in CSRAddress region, it doesn’t work. That is , it can’t read/write memory in “CSRAddress” region. I have tried to use SoftICE to modify the value in CSRAddress region, the value also can’t be modified.
Since I can change bar 3 base address of PCI using following method, I am sure the mini-driver is connectted to my PCI device:
pHwDevExt->BusInterface.SetBusData(
pHwDevExt->BusInterface.Context,
PCI_WHICHSPACE_CONFIG,
buffer,
FIELD_OFFSET(PCI_COMMON_CONFIG, VendorID),
PCI_PAC_HDR_LENGTH);

How could I read/write the memory in CSRAddress?
Could anyone help me to solve this problem? Or is there any example code for stream class mini-driver with PCI interface?
Thanks for your help!

xxxxx@sunplusct.com wrote:

I am developing a stream class mini-driver with PCI interface. I use following example codes to implement:
WINDDK\3790.1830\src\wdm\videocap\testcap
WINDDK\3790.1830\src\general\pcidrv\sys

Why would you go stream-class for a capture driver, instead of using
AVStream? AVStream is conceptually much simpler. You should also
realize that you are using an outdated DDK.

I add pcidrv’s code into testcap, and now I can install testcap.sys and can get PCI BusInterface.
However, I encounter a problem as following:
I do “MapHWResources” in “HwInitialize” of testcap, and map IO space as below:

for (i = 0; i < partialResourceListTranslated->Count; i++, resourceTrans++)
{
switch (resourceTrans->Type) {
case CmResourceTypeMemory:
if(numberOfBARs == 1) {

What is this “if” statement trying to do? Are you sure you’re getting
the right BAR?

pHwDevExt->MemPhysAddress_bar0 = resourceTrans->u.Memory.Start;
resourceTrans->u.Memory.Length = 0x10000000 ; /* 28 bit : 256mb */

Why are you overriding the length? Is the BAR bigger than 256MB? PnP
hands you the length from the BAR.

pHwDevExt->CSRAddress =(ULONG)( MmMapIoSpace(
resourceTrans->u.Memory.Start,
resourceTrans->u.Memory.Length, /*28 bit :256mb*/
MmNonCached));

When I perform memory read/write such as “READ_REGISTER_ULONG/WRITE_REGISTER_ULONG” or “RtlCopyMemory” in CSRAddress region, it doesn’t work. That is , it can’t read/write memory in “CSRAddress” region. I have tried to use SoftICE to modify the value in CSRAddress region, the value also can’t be modified.

What do you mean by “can’t read/write memory”? You certainly CAN read
it, although it might return the wrong data. Do you mean that you
always read ffffffff? Are you sure your device is working properly?
Can you access the memory by using the physical address itself? (I’m
sure SoftICE can read/write physical addresses.)


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

Thanks for your response!

Why would you go stream-class for a capture driver, instead of using
AVStream? AVStream is conceptually much simpler. You should also
realize that you are using an outdated DDK.

I realize “testcap” is outdated, maybe I will try “AVStream” later.
By the way, I need to use “Srb”, for example, I need to set
Srb->CommandData.ConfigInfo->ClassDeviceObject->Flags |= DO_DIRECT_IO;
If I use “AVStream”, how could I get “Srb”?

> switch (resourceTrans->Type) {
> case CmResourceTypeMemory:
> if(numberOfBARs == 1) {
What is this “if” statement trying to do? Are you sure you’re getting
the right BAR?

I am sure I get the right BAR.

> pHwDevExt->MemPhysAddress_bar0 = resourceTrans->u.Memory.Start;
> resourceTrans->u.Memory.Length = 0x10000000 ; /*256mb */
Why are you overriding the length? Is the BAR bigger than 256MB? PnP hands you the length from the BAR.

I have also tried not to overriding the length. But it gets the same result. That is, it can’t access the CSRAddress region.

What do you mean by “can’t read/write memory”? You certainly CAN read
it, although it might return the wrong data. Do you mean that you
always read ffffffff?

Yes! You got it. I can read the memory, but it returns the wrong data. It always returns 0xffffffff.

Are you sure your device is working properly?
I am sure my device is working properly. I have another port driver(not stream class) built by “DriverStudio”, it works fine.

Can you access the memory by using the physical address itself? (I’m
sure SoftICE can read/write physical addresses.)
I have tried to access the memory with physical address, but it also doesn’t work. I use SoftICE to watch the physical address, it shows “???” and the value can’t be modified.

In the capture driver, I can change bar3 base address properly. So, I am sure the capture driver is connected to the device.
Finally, how could I access the memoey in CSRAddress region? Does anything I have to do before “MmMapIoSpace”?

Thank you again!

xxxxx@sunplusct.com wrote:

Thanks for your response!

> Why would you go stream-class for a capture driver, instead of using
> AVStream? AVStream is conceptually much simpler. You should also
> realize that you are using an outdated DDK.
>

I realize “testcap” is outdated, maybe I will try “AVStream” later.
By the way, I need to use “Srb”, for example, I need to set
Srb->CommandData.ConfigInfo->ClassDeviceObject->Flags |= DO_DIRECT_IO;
If I use “AVStream”, how could I get “Srb”?

With AVStream, you DON’T need to use the SRB. The AVStream wrappers
will handle all of that overhead for you. That’s one of its big
advantages. You focus on the data stream, not on the scaffolding.

> Are you sure your device is working properly?
>
I am sure my device is working properly. I have another port driver(not stream class) built by “DriverStudio”, it works fine.

But you’re not trying to load them both at the same time, right?

> Can you access the memory by using the physical address itself? (I’m
> sure SoftICE can read/write physical addresses.)
>
I have tried to access the memory with physical address, but it also doesn’t work. I use SoftICE to watch the physical address, it shows “???” and the value can’t be modified.

Did you use the “PEEK” command to look at the physical memory? You
can’t just use “D” with a physical address.

In the capture driver, I can change bar3 base address properly. So, I am sure the capture driver is connected to the device.
Finally, how could I access the memoey in CSRAddress region? Does anything I have to do before “MmMapIoSpace”?

Nope, that’s all it takes. Are you checking the return of MmMapIoSpace
to make sure the call is succeeding? Are you using KdPrint to dump the
physical address you are mapping, just to make sure it matches your
expectations?


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

I have solved this problem. I modify the parameters in “BusInterface.SetBusData” while I change base address of bar3, then it can access the memory.

>With AVStream, you DON’T need to use the SRB. The AVStream wrappers
>will handle all of that overhead for you. That’s one of its big
>advantages. You focus on the data stream, not on the scaffolding.
By the way, I have used “AVStream” as my sample code. However, I have another problem:
In “testcap”, I can modify power state and Fags of DeviceObject through Srb. For example:
Srb->CommandData.DeviceState
Srb->CommandData.ConfigInfo->ClassDeviceObject->Flags |= DO_DIRECT_IO;
In AVStream, how could I modify the power state and Flags of DeviceObject?

Thank you very much!

xxxxx@sunplusct.com wrote:

I have solved this problem. I modify the parameters in “BusInterface.SetBusData” while I change base address of bar3, then it can access the memory.

That still says you have a problem. Just because you have modified BAR3
doesn’t mean that the BIOS or the operating system either knows or
agrees to this change. What’s the matter with the address the BIOS gave
you?

>> With AVStream, you DON’T need to use the SRB. The AVStream wrappers
>> will handle all of that overhead for you. That’s one of its big
>> advantages. You focus on the data stream, not on the scaffolding.
>>
By the way, I have used “AVStream” as my sample code. However, I have another problem:
In “testcap”, I can modify power state and Fags of DeviceObject through Srb. For example:
Srb->CommandData.DeviceState
Srb->CommandData.ConfigInfo->ClassDeviceObject->Flags |= DO_DIRECT_IO;
In AVStream, how could I modify the power state and Flags of DeviceObject?

You DON’T do that. AVStream manages the device object. You do power
management via the PnP callbacks in AVStream. The DO_DIRECT_IO thing is
completely unnecessary, because AVStream doesn’t communicate through
read and write requests. Everything is an ioctl.

Come to think of it, I thought stream-class drivers did I/O the same
way: all SRBs arrive as ioctls. What led you to believe that the
DO_DIRECT_IO thing was necessary?


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

>>That still says you have a problem. Just because you have modified BAR3

>doesn’t mean that the BIOS or the operating system either knows or
>agrees to this change. What’s the matter with the address the BIOS gave
>you?
I use following function to change bar3 base address, then I can access the memroy.
ulResult = BusInterface.SetBusData(
BusInterface.Context,
PCI_WHICHSPACE_CONFIG,
&bar3_BaseAddress,
FIELD_OFFSET(PCI_COMMON_CONFIG, u.type0.BaseAddresses[3]),
0x4);
I think the address returned by “MmMapIoSpace” is correct.

In addition, I use SoftIce v2.6 to debug my code. When I am debugging , it can watch local variable and global variable. But it seems that it can’t watch the member variable of class.
Do you have any idea to watch class member variable with SoftIce?

Thank you.

Something is amiss here. Do you by any chance of v2.6 of DriverStudio
and not SoftICE? I’m not sure that this is even a product, but SoftICE
was in the neighborhood of 4.3.2.2485 when it was pulled. I’m not sure
exactly how old SoftICE v2.6 would be, but, assuming that Compuware
didn’t just screw with the version numbers, which is certainly a
possibility, it would easily go back to the NuMega days, and I think it
would indicate that you using a DOS version. This can’t be correct.

Wat does the ‘VER’ command say when you are broken in to the debugger?

Good luck,

mm

xxxxx@sunplusct.com wrote:

>> That still says you have a problem. Just because you have modified BAR3
>> doesn’t mean that the BIOS or the operating system either knows or
>> agrees to this change. What’s the matter with the address the BIOS gave
>> you?
I use following function to change bar3 base address, then I can access the memroy.
ulResult = BusInterface.SetBusData(
BusInterface.Context,
PCI_WHICHSPACE_CONFIG,
&bar3_BaseAddress,
FIELD_OFFSET(PCI_COMMON_CONFIG, u.type0.BaseAddresses[3]),
0x4);
I think the address returned by “MmMapIoSpace” is correct.

In addition, I use SoftIce v2.6 to debug my code. When I am debugging , it can watch local variable and global variable. But it seems that it can’t watch the member variable of class.
Do you have any idea to watch class member variable with SoftIce?

Thank you.

xxxxx@sunplusct.com wrote:

>> That still says you have a problem. Just because you have modified BAR3
>> doesn’t mean that the BIOS or the operating system either knows or
>> agrees to this change. What’s the matter with the address the BIOS gave
>> you?
>>
I use following function to change bar3 base address, then I can access the memroy.
ulResult = BusInterface.SetBusData(
BusInterface.Context,
PCI_WHICHSPACE_CONFIG,
&bar3_BaseAddress,
FIELD_OFFSET(PCI_COMMON_CONFIG, u.type0.BaseAddresses[3]),
0x4);
I think the address returned by “MmMapIoSpace” is correct.

That doesn’t answer my question. What is wrong with the BAR3 address
that you get originally, without this code? Have you checked the
address in the debugger? Why isn’t it correct? Where are you coming up
the base address in bar3_BaseAddress? How do you know that’s a safe
physical address?


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

>Something is amiss here. Do you by any chance of v2.6 of DriverStudio

and not SoftICE? I’m not sure that this is even a product, but SoftICE
was in the neighborhood of 4.3.2.2485 when it was pulled. I’m not sure
exactly how old SoftICE v2.6 would be, but, assuming that Compuware
didn’t just screw with the version numbers, which is certainly a
possibility, it would easily go back to the NuMega days, and I think it
would indicate that you using a DOS version. This can’t be correct.

What does the ‘VER’ command say when you are broken in to the debugger?

I use DriverStudio V2.6. Would you mind to tell me the version number of DriverStudio that you are using? Can you watch the member variable of c++ class?

That doesn’t answer my question. What is wrong with the BAR3 address
that you get originally, without this code? Have you checked the
address in the debugger? Why isn’t it correct? Where are you coming up
the base address in bar3_BaseAddress? How do you know that’s a safe
physical address?

I get the bar3 base address from our hardware spec. For our hardware design, it is necessary to assign bar3 base address, then it can access the memory in bar0. For example, if I set bar3 base address as 0x1c000000, then it will map the memory starting form 0x1c000000 (in hardware) to bar0.

In addition, I still have another problem:
After I install the “avshws.inf”, it shows installation successfully in device mananger. But, when I use graphedit to insert source filter, avshws doesn’t appears in “WDM Streaming Capture Devices”. That is, I can’t insert source filter in graphedit.
I only modified following sectoion in “avshws.inf”
[Microsoft]
%avshws.DeviceDesc%=avshws,PCI\VEN_0700&DEV_1107

If I don’t modify avshws.inf, the device name can appear in “WDM Streaming Capture Devices”. In other word, if I use the original avshws.inf, it works well. The original setting is as in below:

%avshws.DeviceDesc%=avshws,SW{7D5F2A97-CEBC-45a3-9FC3-7F618AAD939C}

Do you know what’s wrong?

Thanks for your kindly help!

If you type ‘VER’ in SoftICE, what does it report? I’m just curious,
because 2.6, even of DriverStudio, is old I think.

mm

xxxxx@sunplusct.com wrote:

> Something is amiss here. Do you by any chance of v2.6 of DriverStudio
> and not SoftICE? I’m not sure that this is even a product, but SoftICE
> was in the neighborhood of 4.3.2.2485 when it was pulled. I’m not sure
> exactly how old SoftICE v2.6 would be, but, assuming that Compuware
> didn’t just screw with the version numbers, which is certainly a
> possibility, it would easily go back to the NuMega days, and I think it
> would indicate that you using a DOS version. This can’t be correct.

> What does the ‘VER’ command say when you are broken in to the debugger?

I use DriverStudio V2.6. Would you mind to tell me the version number of DriverStudio that you are using? Can you watch the member variable of c++ class?

> That doesn’t answer my question. What is wrong with the BAR3 address
> that you get originally, without this code? Have you checked the
> address in the debugger? Why isn’t it correct? Where are you coming up
> the base address in bar3_BaseAddress? How do you know that’s a safe
> physical address?

I get the bar3 base address from our hardware spec. For our hardware design, it is necessary to assign bar3 base address, then it can access the memory in bar0. For example, if I set bar3 base address as 0x1c000000, then it will map the memory starting form 0x1c000000 (in hardware) to bar0.

In addition, I still have another problem:
After I install the “avshws.inf”, it shows installation successfully in device mananger. But, when I use graphedit to insert source filter, avshws doesn’t appears in “WDM Streaming Capture Devices”. That is, I can’t insert source filter in graphedit.
I only modified following sectoion in “avshws.inf”
[Microsoft]
%avshws.DeviceDesc%=avshws,PCI\VEN_0700&DEV_1107

If I don’t modify avshws.inf, the device name can appear in “WDM Streaming Capture Devices”. In other word, if I use the original avshws.inf, it works well. The original setting is as in below:

%avshws.DeviceDesc%=avshws,SW{7D5F2A97-CEBC-45a3-9FC3-7F618AAD939C}

Do you know what’s wrong?

Thanks for your kindly help!

>>If you type ‘VER’ in SoftICE, what does it report? I’m just curious,

>because 2.6, even of DriverStudio, is old I think.
If I type “VER” in SoftICE, it shows" DriverStudio ™ 2.6.0 (Build 336)".
Do you know whick version of DriverStudio can watch member variable of c++ class?

In addition, I still have another problem:
After I install the “avshws.inf”, it shows installation successfully in
device mananger. But, when I use graphedit to insert source filter, avshws
doesn’t appears in “WDM Streaming Capture Devices”. That is, I can’t insert
source filter in graphedit.
I only modified following sectoion in “avshws.inf”
[Microsoft]
%avshws.DeviceDesc%=avshws,PCI\VEN_0700&DEV_1107

If I don’t modify avshws.inf, the device name can appear in “WDM Streaming
Capture Devices”. In other word, if I use the original avshws.inf, it works
well. The original setting is as in below:

%avshws.DeviceDesc%=avshws,SW{7D5F2A97-CEBC-45a3-9FC3-7F618AAD939C}

Does anyone know what’s wrong?
Thanks!

xxxxx@sunplusct.com wrote:

In addition, I still have another problem:
After I install the “avshws.inf”, it shows installation successfully in
device mananger. But, when I use graphedit to insert source filter, avshws
doesn’t appears in “WDM Streaming Capture Devices”. That is, I can’t insert
source filter in graphedit.
I only modified following sectoion in “avshws.inf”
[Microsoft]
%avshws.DeviceDesc%=avshws,PCI\VEN_0700&DEV_1107

If I don’t modify avshws.inf, the device name can appear in “WDM Streaming
Capture Devices”. In other word, if I use the original avshws.inf, it works
well. The original setting is as in below:

%avshws.DeviceDesc%=avshws,SW{7D5F2A97-CEBC-45a3-9FC3-7F618AAD939C}

Does anyone know what’s wrong?

That one line tells me you are using an old DDK. (The avshws samples in
the 6000 and 6001 DDKs do not use the SW enumerator.) The INF file is
quite different in the newer DDKs.

How did you install this? Did you right-click and use “Install”, or did
you actually insert this piece of hardware?


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

>>That one line tells me you are using an old DDK. (The avshws samples in

>the 6000 and 6001 DDKs do not use the SW enumerator.) The INF file is
>quite different in the newer DDKs.
How did you install this? Did you right-click and use “Install”, or did
>you actually insert this piece of hardware?
I use DDK 3790 right now. I insert piece of hardware and then install right-click to install the driver.
My platform is Windows 2000, do you know what’s wrong with it?

By the way, I have tried to use WDK 6000, avshws works fine.
Since I use Windows 2000 as platform to develop the driver, do you know how could install WDK 6000 into Windows 2000.

xxxxx@sunplusct.com wrote:

>> That one line tells me you are using an old DDK. (The avshws samples in
>> the 6000 and 6001 DDKs do not use the SW enumerator.) The INF file is
>> quite different in the newer DDKs.
>>
> How did you install this? Did you right-click and use “Install”, or did
>
>> you actually insert this piece of hardware?
>>
I use DDK 3790 right now. I insert piece of hardware and then install right-click to install the driver.

That, right there, should tell you that you have a problem. With a
proper INF file, the driver will be installed automatically when you
insert the piece of hardware. Didn’t the operating system complain
about there not being a driver when the hardware was detected? Or is
there already another driver for this hardware?

My platform is Windows 2000, do you know what’s wrong with it?

By the way, I have tried to use WDK 6000, avshws works fine.

Step back a little and think for yourself. If the 6000 sample worked
but the 3790 sample didn’t, then you need to ask “what changed?” The
source code itself is not significantly different. However, the INF is
different, just as I said above. Wouldn’t you guess, then, that you
need to change your INF file to look more like the 6000 version, and
less like the 3790 version?

Since I use Windows 2000 as platform to develop the driver, do you know how could install WDK 6000 into Windows 2000.

What happens when you try it?


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

> Since I use Windows 2000 as platform to develop the driver, do you know how

could install WDK 6000 into Windows 2000.

You cannot.

You can build for w2k using WDK though.


Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

>>Step back a little and think for yourself. If the 6000 sample worked

>but the 3790 sample didn’t, then you need to ask “what changed?” The
>source code itself is not significantly different. However, the INF is
>different, just as I said above. Wouldn’t you guess, then, that you
>need to change your INF file to look more like the 6000 version, and
>less like the 3790 version?
Thanks for your suggestion. I have solved my problem.
I use avshws source code of WDK 6000 to build in DDK 3790, and use avshws inf of WDK 6000 to install driver in Windos 2000. It works well. Therefore, I can develop avshws in Windows 2000 and can insert Video Capture Source in GraphEdit.