vboxrwr.cpp revision 59190ecd61435d19ba3515b876272aee7bd12298
/*++
Copyright (c) 2000 Microsoft Corporation
Module Name:
Abstract:
This file has routines to perform reads and writes.
The read and writes are for bulk transfers.
Environment:
Kernel mode
Notes:
Copyright (c) 2000 Microsoft Corporation.
All Rights Reserved.
--*/
#include "vboxusb.h"
#include "vboxpnp.h"
#include "vboxpwr.h"
#include "vboxdev.h"
#include "vboxrwr.h"
)
/*++
Routine Description:
This routine will pass the string pipe name and
fetch the pipe number.
Arguments:
DeviceObject - pointer to DeviceObject
FileName - string pipe name
Return Value:
The device extension maintains a pipe context for
the pipes on 82930 board.
This routine returns the pointer to this context in
the device extension for the "FileName" pipe.
--*/
{
//
// initialize variables
//
pipeContext = NULL;
//
// typedef WCHAR *PWSTR;
//
dprintf(("VBoxUSB_PipeWithName - begins\n"));
if(nameLength != 0) {
//
// Parse the pipe#
//
// if last char isn't digit, decrement it.
while((ix > -1) &&
ix--;
}
if(ix > -1) {
uval = 0;
umultiplier = 1;
// traversing least to most significant digits.
while((ix > -1) &&
uval += (umultiplier *
ix--;
umultiplier *= 10;
}
}
}
}
dprintf(("VBoxUSB_PipeWithName - ends\n"));
return pipeContext;
}
)
/*++
Routine Description:
Dispatch routine for read and write.
once a stage of transfer is complete, then the irp is circulated again,
until the requested length of tranfer is performed.
Arguments:
DeviceObject - pointer to device object
Irp - I/O request packet
Return Value:
NT status value
--*/
{
//
// initialize variables
//
totalLength = 0;
dprintf(("VBoxUSB_DispatchReadWrite - begins\n"));
dprintf(("Invalid device state\n"));
}
//
// It is true that the client driver cancelled the selective suspend
// request in the dispatch routine for create Irps.
// But there is no guarantee that it has indeed completed.
// so wait on the NoIdleReqPendEvent and proceed only if this event
// is signalled.
//
dprintf(("Waiting on the IdleReqPendEvent\n"));
//
// make sure that the selective suspend request has been completed.
//
if(deviceExtension->SSEnable) {
NULL);
}
dprintf(("Usbd pipe type is not bulk or interrupt\n"));
}
}
else {
dprintf(("Invalid handle\n"));
}
sizeof(VBOXUSB_RW_CONTEXT));
dprintf(("Failed to alloc mem for rwContext\n"));
}
if(Irp->MdlAddress) {
}
dprintf(("Transfer length > circular buffer\n"));
}
if(totalLength == 0) {
dprintf(("Transfer data length = 0\n"));
}
if(read) {
dprintf(("Read operation\n"));
}
else {
dprintf(("Write operation\n"));
}
//
// the transfer request is for totalLength.
// we can perform a max of VBoxUSB_MAX_TRANSFER_SIZE
// in each stage.
//
if(totalLength > VBOXUSB_MAX_TRANSFER_SIZE) {
}
else {
}
NULL);
dprintf(("Failed to alloc mem for mdl\n"));
}
//
// map the portion of user-buffer described by an mdl to another mdl
//
mdl,
dprintf(("Failed to alloc mem for urb\n"));
}
urb,
sizeof(struct _URB_BULK_OR_INTERRUPT_TRANSFER),
NULL,
mdl,
NULL);
//
// set VBOXUSB_RW_CONTEXT parameters.
//
//
//
TRUE,
TRUE,
TRUE);
//
// since we return STATUS_PENDING call IoMarkIrpPending.
// This is the boiler plate code.
// This may cause extra overhead of an APC for the Irp completion
// but this is the correct thing to do.
//
dprintf(("VBoxUSB_DispatchReadWrite::"));
Irp);
if(!NT_SUCCESS(ntStatus)) {
//
// if the device was yanked out, then the pipeInformation
// field is invalid.
// similarly if the request was cancelled, then we need not
//
if((ntStatus != STATUS_CANCELLED) &&
(ntStatus != STATUS_DEVICE_NOT_CONNECTED)) {
if(!NT_SUCCESS(ntStatus)) {
dprintf(("VBoxUSB_ResetPipe failed\n"));
}
}
else {
dprintf(("ntStatus is STATUS_CANCELLED or "
"STATUS_DEVICE_NOT_CONNECTED\n"));
}
}
//
// we return STATUS_PENDING and not the status returned by the lower layer.
//
return STATUS_PENDING;
dprintf(("VBoxUSB_DispatchReadWrite - ends\n"));
return ntStatus;
}
)
/*++
Routine Description:
If the irp completes with success, we check if we
need to recirculate this irp for another stage of
transfer. In this case return STATUS_MORE_PROCESSING_REQUIRED.
if the irp completes in error, free all memory allocs and
return the status.
Arguments:
DeviceObject - pointer to device object
Irp - I/O request packet
Context - context passed to the completion routine.
Return Value:
NT status value
--*/
{
//
// initialize variables
//
dprintf(("VBoxUSB_ReadWriteCompletion - begins\n"));
//
// successfully performed a stageLength of transfer.
// check if we need to recirculate the irp.
//
if(NT_SUCCESS(ntStatus)) {
if(rwContext) {
//
// another stage transfer
//
dprintf(("Another stage transfer...\n"));
}
else {
}
// the source MDL is not mapped and so when the lower driver
// calls MmGetSystemAddressForMdl(Safe) on Urb->Mdl (target Mdl),
// system PTEs are used.
// IoFreeMdl calls MmPrepareMdlForReuse to release PTEs (unlock
// VA address before freeing any Mdl
// Rather than calling IoFreeMdl and IoAllocateMdl each time,
// just call MmPrepareMdlForReuse
// Not calling MmPrepareMdlForReuse will leak system PTEs
//
//
// reinitialize the urb
//
= stageLength;
TRUE,
TRUE,
TRUE);
Irp);
return STATUS_MORE_PROCESSING_REQUIRED;
}
else {
//
// this is the last transfer
//
}
}
}
else {
}
if(rwContext) {
//
// dump rwContext
//
dprintf(("rwContext->Urb = %X\n",
dprintf(("rwContext->Mdl = %X\n",
dprintf(("rwContext->Length = %d\n",
dprintf(("rwContext->Numxfer = %d\n",
dprintf(("rwContext->VirtualAddress = %X\n",
dprintf(("rwContext->DeviceExtension = %X\n",
dprintf(("VBoxUSB_ReadWriteCompletion::"));
}
dprintf(("VBoxUSB_ReadWriteCompletion - ends\n"));
return ntStatus;
}