Annotation of ntddk/src/scsi/qic117/ntalloc.c, revision 1.1.1.1

1.1       root        1: /*++
                      2: 
                      3: Copyright (c) 1993 - Colorado Memory Systems, Inc.
                      4: All Rights Reserved
                      5: 
                      6: Module Name:
                      7: 
                      8:     ntalloc.c
                      9: 
                     10: Abstract:
                     11: 
                     12:     routines to provide storage allocation for cached information and
                     13:     queues.
                     14: 
                     15: Revision History:
                     16: 
                     17: 
                     18: 
                     19: 
                     20: --*/
                     21: 
                     22: #include <ntddk.h>
                     23: #include <ntddtape.h>
                     24: #include "common.h"
                     25: #include "q117.h"
                     26: #include "protos.h"
                     27: 
                     28: 
                     29: NTSTATUS
                     30: q117AllocatePermanentMemory(
                     31:     PQ117_CONTEXT   Context,
                     32:     PADAPTER_OBJECT AdapterObject,
                     33:     ULONG           NumberOfMapRegisters
                     34:     )
                     35: 
                     36: /*++
                     37: 
                     38: Routine Description:
                     39: 
                     40:     Allocates track buffers at init time.
                     41: 
                     42: Arguments:
                     43: 
                     44:     Context - Current context of the driver
                     45: 
                     46: Return Value:
                     47: 
                     48:     NT Status
                     49: 
                     50: --*/
                     51: 
                     52: {
                     53:     ULONG i;
                     54:     ULONG totalBuffs;
                     55:     PHYSICAL_ADDRESS logicalAddress;
                     56: 
                     57:     Context->AdapterInfo = ExAllocatePool(NonPagedPool,
                     58:                                 sizeof(*Context->AdapterInfo));
                     59: 
                     60:     if (Context->AdapterInfo == NULL) {
                     61:         return STATUS_INSUFFICIENT_RESOURCES;
                     62:     }
                     63: 
                     64:     Context->AdapterInfo->AdapterObject = AdapterObject;
                     65:     Context->AdapterInfo->NumberOfMapRegisters = NumberOfMapRegisters;
                     66: 
                     67: 
                     68:     //
                     69:     // Allocate a DMA buffer in physically contiguous memory.
                     70:     // For now we allocate one page since this MUST be contiguous.
                     71:     // NOTE: HalAllocateCommonBuffer is really for BUS MASTERS ONLY
                     72:     // but this is the only way we can guarantee that IoMapTransfer
                     73:     // doesn't copy our buffer somewhere else for the device which
                     74:     // doesn't work for autoinit DMA (see Bug 12011).
                     75:     //
                     76: 
                     77:     totalBuffs = 0;
                     78:     for (i = 0; i < UNIX_MAXBFS; i++) {
                     79:         if ((Context->SegmentBuffer[i].logical =
                     80:             HalAllocateCommonBuffer(AdapterObject,
                     81:                                     BLOCKS_PER_SEGMENT * BYTES_PER_SECTOR,
                     82:                                     &logicalAddress,
                     83:                                     FALSE)) == NULL) {
                     84:             break;
                     85:         }
                     86: 
                     87:         ++totalBuffs;
                     88: 
                     89:         CheckedDump(QIC117SHOWTD,("q117:  buffer %x ",i,Context->SegmentBuffer[i].logical));
                     90: 
                     91:         CheckedDump(QIC117SHOWTD,("Logical: %x%08x   Virtual: %x\n",
                     92:                     logicalAddress, Context->SegmentBuffer[i].logical));
                     93:     }
                     94:     Context->SegmentBuffersAvailable = totalBuffs;
                     95: 
                     96:     //
                     97:     // We need at least two buffers to stream
                     98:     //
                     99:     if (totalBuffs < 2) {
                    100: 
                    101:         ExFreePool(Context->AdapterInfo);
                    102: 
                    103:         return STATUS_INSUFFICIENT_RESOURCES;
                    104:     }
                    105: 
                    106:     //
                    107:     // Initialize state information
                    108:     //
                    109:     Context->CurrentOperation.Type = NoOperation;
                    110:     Context->CurrentTape.State = NeedInfoLoaded;
                    111:     Context->DriverOpened = FALSE;
                    112:     Context->CurrentTape.TapeHeader = NULL;
                    113:     Context->IoRequest = NULL;
                    114:     Context->CurrentTape.MediaInfo = NULL;
                    115: 
                    116:     return STATUS_SUCCESS;
                    117: }
                    118: 
                    119: STATUS
                    120: q117GetTemporaryMemory (
                    121:     PQ117_CONTEXT Context
                    122:     )
                    123: 
                    124: /*++
                    125: 
                    126: Routine Description:
                    127: 
                    128: Allocates memory for the bad sector map, the IORequest array
                    129: at driver open time.
                    130: 
                    131: Arguments:
                    132: 
                    133:     Context - Current context of the driver
                    134: 
                    135: Return Value:
                    136: 
                    137:     NT Status
                    138: 
                    139: --*/
                    140: 
                    141: {
                    142: 
                    143:     //
                    144:     // Allocate I/O Request array for packets sent to q117i
                    145:     //
                    146:     Context->IoRequest = ExAllocatePool(
                    147:         NonPagedPool,
                    148:         UNIX_MAXBFS * sizeof(IO_REQUEST));
                    149: 
                    150:     //
                    151:     // Allocate current header info
                    152:     //
                    153: 
                    154:     Context->CurrentTape.TapeHeader = ExAllocatePool(
                    155:                                         NonPagedPool,
                    156:                                         sizeof(TAPE_HEADER));
                    157: 
                    158:     Context->CurrentTape.BadMapPtr = &(Context->CurrentTape.TapeHeader->BadMap);
                    159:     Context->CurrentTape.BadSectorMapSize = sizeof(BAD_MAP);
                    160: 
                    161: 
                    162:     //
                    163:     // Allocate tape info structure
                    164:     //
                    165:     Context->CurrentTape.MediaInfo = ExAllocatePool(
                    166:                                         NonPagedPool,
                    167:                                         sizeof(*Context->CurrentTape.MediaInfo));
                    168: 
                    169:     if ( Context->CurrentTape.TapeHeader == NULL ||
                    170:             Context->IoRequest == NULL ||
                    171:             Context->CurrentTape.MediaInfo == NULL ) {
                    172: 
                    173:         //
                    174:         // Free anything that was allocated
                    175:         //
                    176:         q117FreeTemporaryMemory(Context);
                    177:         return(FMemErr);
                    178: 
                    179:     }
                    180: 
                    181:     return(NoErr);
                    182: }
                    183: 
                    184: VOID
                    185: q117FreeTemporaryMemory (
                    186:     PQ117_CONTEXT Context
                    187:     )
                    188: 
                    189: /*++
                    190: 
                    191: Routine Description:
                    192: 
                    193: Frees memory allocated for the bad sector map, the IORequest
                    194: array driver open time.  This
                    195: routine is called at driver close time or in the event of a
                    196: drive error.
                    197: 
                    198: Arguments:
                    199: 
                    200:     Context - Current context of the driver
                    201: 
                    202: Return Value:
                    203: 
                    204:     NT Status
                    205: 
                    206: --*/
                    207: 
                    208: {
                    209: 
                    210:     //
                    211:     // Free I/O request buffer array
                    212:     //
                    213:     if (Context->IoRequest) {
                    214:         ExFreePool(Context->IoRequest);
                    215:         Context->IoRequest = NULL;
                    216:     }
                    217: 
                    218:     //
                    219:     // Free tape header buffer
                    220:     //
                    221:     if (Context->CurrentTape.TapeHeader) {
                    222:         ExFreePool(Context->CurrentTape.TapeHeader);
                    223:         Context->CurrentTape.TapeHeader = NULL;
                    224:     }
                    225: 
                    226:     //
                    227:     // Free tape information buffer
                    228:     //
                    229:     if (Context->CurrentTape.MediaInfo) {
                    230:         ExFreePool(Context->CurrentTape.MediaInfo);
                    231:         Context->CurrentTape.MediaInfo = NULL;
                    232:     }
                    233: }
                    234: 
                    235: 
                    236: 
                    237: 
                    238: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.