Read PCI configuration

I confuse with the code?from http://support.microsoft.com/kb/253232?about read/writeconfig space.?I don’t understand, in?which part?in?the code that we?read the configuration of PCI??In which variable we read the configuration here.?I attach the code. Thank you.?
?
?
?
NTSTATUS
ReadWriteConfigSpace(
??? IN PDEVICE_OBJECT DeviceObject,
??? IN ULONG ??? ReadOrWrite, // 0 for read 1 for write
??? IN PVOID ??? Buffer,
??? IN ULONG ??? Offset,
??? IN ULONG ??? Length
??? )
{
??? KEVENT event;
??? NTSTATUS status;
??? PIRP irp;
??? IO_STATUS_BLOCK ioStatusBlock;
??? PIO_STACK_LOCATION irpStack;
??? PDEVICE_OBJECT targetObject;

??? PAGED_CODE();

??? KeInitializeEvent( &event, NotificationEvent, FALSE );

??? targetObject = IoGetAttachedDeviceReference( DeviceObject );

??? irp = IoBuildSynchronousFsdRequest( IRP_MJ_PNP,
??? targetObject,
??? NULL,
??? 0,
??? NULL,
??? &event,
??? &ioStatusBlock );

??? if (irp == NULL) {
??? status = STATUS_INSUFFICIENT_RESOURCES;
??? goto End;
??? }

??? irpStack = IoGetNextIrpStackLocation( irp );

??? if (ReadOrWrite == 0) {
??? irpStack->MinorFunction = IRP_MN_READ_CONFIG;
??? }else {
??? irpStack->MinorFunction = IRP_MN_WRITE_CONFIG;
??? }

??? irpStack->Parameters.ReadWriteConfig.WhichSpace = PCI_WHICHSPACE_CONFIG;
??? irpStack->Parameters.ReadWriteConfig.Buffer = Buffer;
??? irpStack->Parameters.ReadWriteConfig.Offset = Offset;
??? irpStack->Parameters.ReadWriteConfig.Length = Length;

??? //
??? // Initialize the status to error in case the bus driver does not
??? // set it correctly.
??? //

??? irp->IoStatus.Status = STATUS_NOT_SUPPORTED ;

??? status = IoCallDriver( targetObject, irp );

??? if (status == STATUS_PENDING) {

??? KeWaitForSingleObject( &event, Executive, KernelMode, FALSE, NULL );
??? status = ioStatusBlock.Status;
??? }

End:
??? //
??? // Done with reference
??? //
??? ObDereferenceObject( targetObject );

??? return status;

}

Have a look at
http://msdn.microsoft.com/en-us/library/ms806523.aspx

You are sending an IRP_MN_READ_CONFIG request to bus driver.
“Typically, a function driver sends this IRP to the top driver in the
device stack to which it is attached and the IRP is handled by the
parent bus driver.”
You receive configuration space data in Buffer variable. The place in
this code where this buffer is filled with data is inside
IoCallDriver().
It is your task to interpret received data according to PCI config space
layout.

Regards,
Alex Krol


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of sahrizal sofian
Sent: Monday, September 07, 2009 1:43 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Read PCI configuration

I confuse with the code from
http://support.microsoft.com/kb/253232 about read/writeconfig space. I
don’t understand, in which part in the code that we read the
configuration of PCI? In which variable we read the configuration here.
I attach the code. Thank you.

NTSTATUS
ReadWriteConfigSpace(
IN PDEVICE_OBJECT DeviceObject,
IN ULONG ReadOrWrite, // 0 for read 1 for write
IN PVOID Buffer,
IN ULONG Offset,
IN ULONG Length
)
{
KEVENT event;
NTSTATUS status;
PIRP irp;
IO_STATUS_BLOCK ioStatusBlock;
PIO_STACK_LOCATION irpStack;
PDEVICE_OBJECT targetObject;

PAGED_CODE();

KeInitializeEvent( &event, NotificationEvent, FALSE );

targetObject = IoGetAttachedDeviceReference( DeviceObject );

irp = IoBuildSynchronousFsdRequest( IRP_MJ_PNP,
targetObject,
NULL,
0,
NULL,
&event,
&ioStatusBlock );

if (irp == NULL) {
status = STATUS_INSUFFICIENT_RESOURCES;
goto End;
}

irpStack = IoGetNextIrpStackLocation( irp );

if (ReadOrWrite == 0) {
irpStack->MinorFunction = IRP_MN_READ_CONFIG;
}else {
irpStack->MinorFunction = IRP_MN_WRITE_CONFIG;
}

irpStack->Parameters.ReadWriteConfig.WhichSpace =
PCI_WHICHSPACE_CONFIG;
irpStack->Parameters.ReadWriteConfig.Buffer = Buffer;
irpStack->Parameters.ReadWriteConfig.Offset = Offset;
irpStack->Parameters.ReadWriteConfig.Length = Length;

//
// Initialize the status to error in case the bus driver
does not
// set it correctly.
//

irp->IoStatus.Status = STATUS_NOT_SUPPORTED ;

status = IoCallDriver( targetObject, irp );

if (status == STATUS_PENDING) {

KeWaitForSingleObject( &event, Executive, KernelMode,
FALSE, NULL );
status = ioStatusBlock.Status;
}

End:
//
// Done with reference
//
ObDereferenceObject( targetObject );

return status;

}

So, with this code we can get directly the pci configuration associated device, isn’it? Or do we have to scan the buses (256 possibility) and devices (32 possibilities) and function number (8 possibilites) to get the asociated pci configuration of the device?
?

— On Mon, 9/7/09, Alexander Krol wrote:

From: Alexander Krol
Subject: RE: [ntdev] Read PCI configuration
To: “Windows System Software Devs Interest List”
Date: Monday, September 7, 2009, 7:26 AM

Have a look at
? http://msdn.microsoft.com/en-us/library/ms806523.aspx

You are sending an IRP_MN_READ_CONFIG request to bus driver.
“Typically, a function driver sends this IRP to the top driver in the
device stack to which it is attached and the IRP is handled by the
parent bus driver.”
You receive configuration space data in Buffer variable. The place in
this code where this buffer is filled with data is inside
IoCallDriver().
It is your task to interpret received data according to PCI config space
layout.

Regards,
? ? Alex Krol

________________________________

From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of sahrizal sofian
Sent: Monday, September 07, 2009 1:43 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Read PCI configuration

??? ??? I confuse with the code from
http://support.microsoft.com/kb/253232 about read/writeconfig space. I
don’t understand, in which part in the code that we read the
configuration of PCI? In which variable we read the configuration here.
I attach the code. Thank you.
???
???
???
??? NTSTATUS
??? ReadWriteConfigSpace(
??? ? ? IN PDEVICE_OBJECT DeviceObject,
??? ? ? IN ULONG? ? ???ReadOrWrite, // 0 for read 1 for write
??? ? ? IN PVOID? ? ???Buffer,
??? ? ? IN ULONG? ? ???Offset,
??? ? ? IN ULONG? ? ???Length
??? ? ? )
??? {
??? ? ? KEVENT event;
??? ? ? NTSTATUS status;
??? ? ? PIRP irp;
??? ? ? IO_STATUS_BLOCK ioStatusBlock;
??? ? ? PIO_STACK_LOCATION irpStack;
??? ? ? PDEVICE_OBJECT targetObject;
???
??? ? ? PAGED_CODE();
???
??? ? ? KeInitializeEvent( &event, NotificationEvent, FALSE );
???
??? ? ? targetObject = IoGetAttachedDeviceReference( DeviceObject );
???
??? ? ? irp = IoBuildSynchronousFsdRequest( IRP_MJ_PNP,
??? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? targetObject,
??? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? NULL,
??? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 0,
??? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? NULL,
??? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? &event,
??? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? &ioStatusBlock );
???
??? ? ? if (irp == NULL) {
??? ? ? ? ? status = STATUS_INSUFFICIENT_RESOURCES;
??? ? ? ? ? goto End;
??? ? ? }
???
??? ? ? irpStack = IoGetNextIrpStackLocation( irp );
???
??? ? ? if (ReadOrWrite == 0) {
??? ? ? ? ? irpStack->MinorFunction = IRP_MN_READ_CONFIG;
??? ? ? }else {
??? ? ? ? ? irpStack->MinorFunction = IRP_MN_WRITE_CONFIG;
??? ? ? }
???
??? ? ? irpStack->Parameters.ReadWriteConfig.WhichSpace =
PCI_WHICHSPACE_CONFIG;
??? ? ? irpStack->Parameters.ReadWriteConfig.Buffer = Buffer;
??? ? ? irpStack->Parameters.ReadWriteConfig.Offset = Offset;
??? ? ? irpStack->Parameters.ReadWriteConfig.Length = Length;
???
??? ? ? //
??? ? ? // Initialize the status to error in case the bus driver
does not
??? ? ? // set it correctly.
??? ? ? //
???
??? ? ? irp->IoStatus.Status = STATUS_NOT_SUPPORTED ;
???
??? ? ? status = IoCallDriver( targetObject, irp );
???
??? ? ? if (status == STATUS_PENDING) {
???
??? ? ? ? ? KeWaitForSingleObject( &event, Executive, KernelMode,
FALSE, NULL );
??? ? ? ? ? status = ioStatusBlock.Status;
??? ? ? }
???
??? End:
??? ? ? //
??? ? ? // Done with reference
??? ? ? //
??? ? ? ObDereferenceObject( targetObject );
???
??? ? ? return status;
???
??? }
???
??? ???


NTDEV is sponsored by OSR

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

Yes, you have access to PCI configuration data of your specific device.
Read this old but relevant article:
http://www.hollistech.com/Resources/Misc%20articles/getbusdata.htm
http:



From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of sahrizal sofian
Sent: Monday, September 07, 2009 5:22 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Read PCI configuration

So, with this code we can get directly the pci configuration associated
device, isn’it? Or do we have to scan the buses (256 possibility) and
devices (32 possibilities) and function number (8 possibilites) to get
the asociated pci configuration of the device?

— On Mon, 9/7/09, Alexander Krol wrote:

From: Alexander Krol
Subject: RE: [ntdev] Read PCI configuration
To: “Windows System Software Devs Interest List”

Date: Monday, September 7, 2009, 7:26 AM

Have a look at
http://msdn.microsoft.com/en-us/library/ms806523.aspx

You are sending an IRP_MN_READ_CONFIG request to bus driver.
“Typically, a function driver sends this IRP to the top driver
in the
device stack to which it is attached and the IRP is handled by
the
parent bus driver.”
You receive configuration space data in Buffer variable. The
place in
this code where this buffer is filled with data is inside
IoCallDriver().
It is your task to interpret received data according to PCI
config space
layout.

Regards,
Alex Krol



From: xxxxx@lists.osr.com
http:osr.com>
[mailto:xxxxx@lists.osr.com
http:osr.com>] On Behalf Of sahrizal sofian
Sent: Monday, September 07, 2009 1:43 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Read PCI configuration

I confuse with the code from
http://support.microsoft.com/kb/253232 about read/writeconfig
space. I
don’t understand, in which part in the code that we read the
configuration of PCI? In which variable we read the
configuration here.
I attach the code. Thank you.

NTSTATUS
ReadWriteConfigSpace(
IN PDEVICE_OBJECT DeviceObject,
IN ULONG ReadOrWrite, // 0 for read 1 for write
IN PVOID Buffer,
IN ULONG Offset,
IN ULONG Length
)
{
KEVENT event;
NTSTATUS status;
PIRP irp;
IO_STATUS_BLOCK ioStatusBlock;
PIO_STACK_LOCATION irpStack;
PDEVICE_OBJECT targetObject;

PAGED_CODE();

KeInitializeEvent( &event, NotificationEvent, FALSE );

targetObject = IoGetAttachedDeviceReference(
DeviceObject );

irp = IoBuildSynchronousFsdRequest( IRP_MJ_PNP,
targetObject,
NULL,
0,
NULL,
&event,
&ioStatusBlock );

if (irp == NULL) {
status = STATUS_INSUFFICIENT_RESOURCES;
goto End;
}

irpStack = IoGetNextIrpStackLocation( irp );

if (ReadOrWrite == 0) {
irpStack->MinorFunction = IRP_MN_READ_CONFIG;
}else {
irpStack->MinorFunction = IRP_MN_WRITE_CONFIG;
}

irpStack->Parameters.ReadWriteConfig.WhichSpace =
PCI_WHICHSPACE_CONFIG;
irpStack->Parameters.ReadWriteConfig.Buffer = Buffer;
irpStack->Parameters.ReadWriteConfig.Offset = Offset;
irpStack->Parameters.ReadWriteConfig.Length = Length;

//
// Initialize the status to error in case the bus driver
does not
// set it correctly.
//

irp->IoStatus.Status = STATUS_NOT_SUPPORTED ;

status = IoCallDriver( targetObject, irp );

if (status == STATUS_PENDING) {

KeWaitForSingleObject( &event, Executive,
KernelMode,
FALSE, NULL );
status = ioStatusBlock.Status;
}

End:
//
// Done with reference
//
ObDereferenceObject( targetObject );

return status;

}


NTDEV is sponsored by OSR

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

— NTDEV is sponsored by OSR 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</http:></http:></http:>

>don’t understand, in which part in the code that we read the configuration of PCI? In which variable we

read the configuration here.

Buffer/Length are filled with the configuration value.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

sahrizal sofian wrote:

So, with this code we can get directly the pci configuration
associated device, isn’it? Or do we have to scan the buses (256
possibility) and devices (32 possibilities) and function number (8
possibilites) to get the asociated pci configuration of the device?

I apologize in advance for what I’m about to say.

This is a stupid question, as was the one before it. Did you look at
the code at all? Do you see what it’s doing? If you don’t, then you
need a lot more C experience before you go digging around in the driver
world. There are more than 2,000 Google hits for “irp_mn_read_config”,
and any of the top dozen or so would provide all of the background you need.

You should have been able to figure out the answers to BOTH of these
questions on your own.


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

Don’t worry, I forgive you. Yes, i?don’t have?much experience in c since i am used to java and .net.?I have tried to understand about driver programming since one month, not easy but i am working hard to understand from many sources, not only just to ask from forum.
If you are smart,?and you don’t want to answer ‘easy question’, just delete it. No need to say like that.

— On Mon, 9/7/09, Tim Roberts wrote:

From: Tim Roberts
Subject: Re: [ntdev] Read PCI configuration
To: “Windows System Software Devs Interest List”
Date: Monday, September 7, 2009, 5:32 PM

sahrizal sofian wrote:
> So, with this code we can get directly the pci configuration
> associated device, isn’it? Or do we have to scan the buses (256
> possibility) and devices (32 possibilities) and function number (8
> possibilites) to get the asociated pci configuration of the device?
>

I apologize in advance for what I’m about to say.

This is a stupid question, as was the one before it.? Did you look at
the code at all?? Do you see what it’s doing?? If you don’t, then you
need a lot more C experience before you go digging around in the driver
world.? There are more than 2,000 Google hits for “irp_mn_read_config”,
and any of the top dozen or so would provide all of the background you need.

You should have been able to figure out the answers to BOTH of these
questions on your own.


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


NTDEV is sponsored by OSR

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