|
|
Microsoft Windows NT Build 511 (DDK SDK) 11-01-1993
/*++
Copyright (c) 1993 - Colorado Memory Systems, Inc.
All Rights Reserved
Module Name:
ntalloc.c
Abstract:
routines to provide storage allocation for cached information and
queues.
Revision History:
--*/
#include <ntddk.h>
#include <ntddtape.h>
#include "common.h"
#include "q117.h"
#include "protos.h"
NTSTATUS
q117AllocatePermanentMemory(
PQ117_CONTEXT Context,
PADAPTER_OBJECT AdapterObject,
ULONG NumberOfMapRegisters
)
/*++
Routine Description:
Allocates track buffers at init time.
Arguments:
Context - Current context of the driver
Return Value:
NT Status
--*/
{
ULONG i;
ULONG totalBuffs;
PHYSICAL_ADDRESS logicalAddress;
Context->AdapterInfo = ExAllocatePool(NonPagedPool,
sizeof(*Context->AdapterInfo));
if (Context->AdapterInfo == NULL) {
return STATUS_INSUFFICIENT_RESOURCES;
}
Context->AdapterInfo->AdapterObject = AdapterObject;
Context->AdapterInfo->NumberOfMapRegisters = NumberOfMapRegisters;
//
// Allocate a DMA buffer in physically contiguous memory.
// For now we allocate one page since this MUST be contiguous.
// NOTE: HalAllocateCommonBuffer is really for BUS MASTERS ONLY
// but this is the only way we can guarantee that IoMapTransfer
// doesn't copy our buffer somewhere else for the device which
// doesn't work for autoinit DMA (see Bug 12011).
//
totalBuffs = 0;
for (i = 0; i < UNIX_MAXBFS; i++) {
if ((Context->SegmentBuffer[i].logical =
HalAllocateCommonBuffer(AdapterObject,
BLOCKS_PER_SEGMENT * BYTES_PER_SECTOR,
&logicalAddress,
FALSE)) == NULL) {
break;
}
++totalBuffs;
CheckedDump(QIC117SHOWTD,("q117: buffer %x ",i,Context->SegmentBuffer[i].logical));
CheckedDump(QIC117SHOWTD,("Logical: %x%08x Virtual: %x\n",
logicalAddress, Context->SegmentBuffer[i].logical));
}
Context->SegmentBuffersAvailable = totalBuffs;
//
// We need at least two buffers to stream
//
if (totalBuffs < 2) {
ExFreePool(Context->AdapterInfo);
return STATUS_INSUFFICIENT_RESOURCES;
}
//
// Initialize state information
//
Context->CurrentOperation.Type = NoOperation;
Context->CurrentTape.State = NeedInfoLoaded;
Context->DriverOpened = FALSE;
Context->CurrentTape.TapeHeader = NULL;
Context->IoRequest = NULL;
Context->CurrentTape.MediaInfo = NULL;
return STATUS_SUCCESS;
}
STATUS
q117GetTemporaryMemory (
PQ117_CONTEXT Context
)
/*++
Routine Description:
Allocates memory for the bad sector map, the IORequest array
at driver open time.
Arguments:
Context - Current context of the driver
Return Value:
NT Status
--*/
{
//
// Allocate I/O Request array for packets sent to q117i
//
Context->IoRequest = ExAllocatePool(
NonPagedPool,
UNIX_MAXBFS * sizeof(IO_REQUEST));
//
// Allocate current header info
//
Context->CurrentTape.TapeHeader = ExAllocatePool(
NonPagedPool,
sizeof(TAPE_HEADER));
Context->CurrentTape.BadMapPtr = &(Context->CurrentTape.TapeHeader->BadMap);
Context->CurrentTape.BadSectorMapSize = sizeof(BAD_MAP);
//
// Allocate tape info structure
//
Context->CurrentTape.MediaInfo = ExAllocatePool(
NonPagedPool,
sizeof(*Context->CurrentTape.MediaInfo));
if ( Context->CurrentTape.TapeHeader == NULL ||
Context->IoRequest == NULL ||
Context->CurrentTape.MediaInfo == NULL ) {
//
// Free anything that was allocated
//
q117FreeTemporaryMemory(Context);
return(FMemErr);
}
return(NoErr);
}
VOID
q117FreeTemporaryMemory (
PQ117_CONTEXT Context
)
/*++
Routine Description:
Frees memory allocated for the bad sector map, the IORequest
array driver open time. This
routine is called at driver close time or in the event of a
drive error.
Arguments:
Context - Current context of the driver
Return Value:
NT Status
--*/
{
//
// Free I/O request buffer array
//
if (Context->IoRequest) {
ExFreePool(Context->IoRequest);
Context->IoRequest = NULL;
}
//
// Free tape header buffer
//
if (Context->CurrentTape.TapeHeader) {
ExFreePool(Context->CurrentTape.TapeHeader);
Context->CurrentTape.TapeHeader = NULL;
}
//
// Free tape information buffer
//
if (Context->CurrentTape.MediaInfo) {
ExFreePool(Context->CurrentTape.MediaInfo);
Context->CurrentTape.MediaInfo = NULL;
}
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.