Hello all,
I am suppose to write a PC Card driver for our 16bit PC Card.
I was wondering how to access the Configuration and status register of PC
card. Through
DDK i found out it can be done using IRP_MN_READ_CONFIG. But i don’t know
what kind of structure
to pass in.
Ashish
Hi Ashish,
For accessing the Status and configuration registers of 16-bit PC card, U
will have to do READ/WRITE access to the Attribute Memory…The following
code is what I implemented using a sample in Knowledge base article…U can
use the following code to access the attribute memory…
#pragma PAGEDCODE
NTSTATUS ReadWriteAttribMem(PDEVICE_OBJECT fdo,BOOLEAN flag,UCHAR
*attribMemBuffContent,int offset)
{ KdPrint((“Entering READWRITEATTRIBMEM function”));
int i;
PIRP Irp=IoAllocateIrp(fdo->StackSize,TRUE);
if(!Irp)
{
KdPrint((“Hardware not found,resource not allocated”));
return STATUS_INSUFFICIENT_RESOURCES;
}
Irp->IoStatus.Status=STATUS_NOT_SUPPORTED;
PIO_STACK_LOCATION stack=IoGetNextIrpStackLocation(Irp);
KEVENT Event;
KeInitializeEvent(&Event,NotificationEvent,FALSE);
IoSetCompletionRoutine(Irp,Pcmcia_RW_Completion_Routine,
&Event,TRUE,TRUE,TRUE);
KdPrint((“Setting the Stack parameter for reading attrib Mem”));
stack->MajorFunction=IRP_MJ_PNP;
stack->MinorFunction=flag? IRP_MN_WRITE_CONFIG : IRP_MN_READ_CONFIG;
if(flag)
{
KdPrint((“Performing Attrib Mem Write”));
}
else
{
KdPrint((“Performing Attrib Mem Read”));
}
stack->Parameters.ReadWriteConfig.WhichSpace=PCCARD_ATTRIBUTE_MEMORY;
stack->Parameters.ReadWriteConfig.Buffer=attribMemBuffContent;
stack->Parameters.ReadWriteConfig.Offset=offset;
stack->Parameters.ReadWriteConfig.Length=sizeof(*(attribMemBuffContent));
PDEVICE_EXTENSION pdx= (PDEVICE_EXTENSION)fdo->DeviceExtension;
NTSTATUS status=IoCallDriver(pdx->LowerDeviceObject,Irp);
if(status == STATUS_PENDING)
{
KeWaitForSingleObject(&Event,Executive,KernelMode,FALSE,NULL);
status=Irp->IoStatus.Status;
}
IoFreeIrp(Irp);
KdPrint((“Quitting READWRITEATTRIBMEM Function”));
return status;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/****************Completion Routine for the ReadWriteAttribMem
Function***************************/
#pragma PAGEDCODE
NTSTATUS Pcmcia_RW_Completion_Routine(IN PDEVICE_OBJECT fdo,
IN PIRP Irp,
IN PVOID Context)
{
KeSetEvent((PKEVENT) Context, IO_NO_INCREMENT, FALSE);
return STATUS_MORE_PROCESSING_REQUIRED;
}
Hope this helps,
regards,
Shiv