Are there any examples of how to access the PCI regs,
BAR’s etc, from a driver or windows App?
We need to write a PCI resouce editor for .NET IA-64.
thanks, Ed
Are there any examples of how to access the PCI regs,
BAR’s etc, from a driver or windows App?
We need to write a PCI resouce editor for .NET IA-64.
thanks, Ed
Hi Ed,
You need to send IRP_MN_READ_CONFIG to bus driver to read config space of
PCI.
Then you get pointer to config space. From application you can send and
IOCTL and get pointer to Config space.
That is the easiest way.
Please find following code snippet …
/**************************************************************************
ReadWriteConfigSpace - Reads Config space of PCI device
Input : DeviceObject - Pointer to Device Object
ReadOrWrite - 0 for reading and 1 for writing
Buffer - Pointer to buffer containing space to receive
the config
space information
Length - number of bytes of data to read
Output : returns NTSTATUS code.
Notes : Must be called at <dispatch_level> Only handles PCI config space
************************************************************************** /
NTSTATUS ReadWriteConfigSpace(PDEVICE_OBJECT DeviceObject,
ULONG ReadOrWrite,
// 0 to read and 1 to write
PVOID Buffer,ULONG Length)
{
KEVENT event;
NTSTATUS status;
PIRP irp;
IO_STATUS_BLOCK ioStatusBlock;
PIO_STACK_LOCATION irpStack;
PDEVICE_OBJECT targetObject;
#if DBG
DbgPrint(“ReadWriteConfigSpace Entered\n”);
#endif
PAGED_CODE();
KeInitializeEvent( &event, NotificationEvent, FALSE );
targetObject = IoGetAttachedDeviceReference( DeviceObject );
//IRP to be sent synchronously to bus driver to read config space
irp =
oBuildSynchronousFsdRequest( 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;
#if DBG
DbgPrint(“IRP_MN_READ_CONFIG\n”);
#endif
}
else
{
irpStack->MinorFunction = IRP_MN_WRITE_CONFIG;
#if DBG
DbgPrint(“IRP_MN_WRITE_CONFIG\n”);
#endif
}
irpStack->Parameters.ReadWriteConfig.WhichSpace = PCI_WHICHSPACE_CONFIG;
irpStack->Parameters.ReadWriteConfig.Buffer = Buffer;
irpStack->Parameters.ReadWriteConfig.Offset = 0;
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 );
#if DBG
DbgPrint(“ReadWriteConfigSpace Exiting\n”);
#endif
return status;
}
I got this from some web site and it is working …
call this function in IOCTL and get pointer to PCI config space , then use
it…
Bye,
Anil
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of xxxxx@attbi.com
Sent: Friday, September 27, 2002 3:35 AM
To: NT Developers Interest List
Subject: [ntdev] How to Access PCI HW Config Space
Are there any examples of how to access the PCI regs,
BAR’s etc, from a driver or windows App?
We need to write a PCI resouce editor for .NET IA-64.
thanks, Ed
—
You are currently subscribed to ntdev as: xxxxx@tatainfotech.com
To unsubscribe send a blank email to %%email.unsub%%</dispatch_level>
There is a KB article from MS on this here:
http://support.microsoft.com/default.aspx?ID=KB;EN-US;Q253232&
–
Bill McKenzie
Windows DDK MVP
OSR - Windows System Software Development, Training, and Consulting
wrote in message news:xxxxx@ntdev…
>
> Are there any examples of how to access the PCI regs,
> BAR’s etc, from a driver or windows App?
>
> We need to write a PCI resouce editor for .NET IA-64.
>
> thanks, Ed
>
>
>