|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. ! 3: * ! 4: * @APPLE_LICENSE_HEADER_START@ ! 5: * ! 6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights ! 7: * Reserved. This file contains Original Code and/or Modifications of ! 8: * Original Code as defined in and that are subject to the Apple Public ! 9: * Source License Version 1.1 (the "License"). You may not use this file ! 10: * except in compliance with the License. Please obtain a copy of the ! 11: * License at http://www.apple.com/publicsource and read it before using ! 12: * this file. ! 13: * ! 14: * The Original Code and all software distributed under the License are ! 15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER ! 16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ! 17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, ! 18: * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the ! 19: * License for the specific language governing rights and limitations ! 20: * under the License. ! 21: * ! 22: * @APPLE_LICENSE_HEADER_END@ ! 23: */ ! 24: /* Copyright (c) 1991 NeXT Computer, Inc. All rights reserved. ! 25: * ! 26: * IOMallocLow.m - IOMallocLow(), IOFreeLow() for i386. ! 27: * ! 28: * HISTORY ! 29: * 01-Apr-93 Doug Mitchell at NeXT ! 30: * Created. ! 31: */ ! 32: ! 33: #import <driverkit/i386/kernelDriver.h> ! 34: #import <mach/vm_param.h> ! 35: #import <kernserv/queue.h> ! 36: #import <machdep/i386/dma_exported.h> ! 37: #import <driverkit/generalFuncs.h> ! 38: ! 39: queue_head_t dmaBufQueue; ! 40: ! 41: /* ! 42: * Need to keep dma_buf_t's around for IOFreeLow(). ! 43: */ ! 44: typedef struct { ! 45: dma_buf_t *buf; ! 46: queue_chain_t link; ! 47: } low16Buf; ! 48: ! 49: ! 50: void *IOMallocLow(int size) ! 51: { ! 52: boolean_t brtn; ! 53: dma_buf_t *buf; ! 54: low16Buf *lowBuf; ! 55: ! 56: buf = IOMalloc(sizeof(*buf)); ! 57: brtn = dma_buf_alloc(buf, size); ! 58: if(brtn == FALSE) { ! 59: IOFree(buf, sizeof(*buf)); ! 60: return 0; ! 61: } ! 62: ! 63: /* ! 64: * Enqueue this on dmaBufQueue. ! 65: */ ! 66: lowBuf = IOMalloc(sizeof(*lowBuf)); ! 67: lowBuf->buf = buf; ! 68: queue_enter(&dmaBufQueue, lowBuf, low16Buf *, link); ! 69: return buf->_ptr; ! 70: } ! 71: ! 72: void IOFreeLow(void *p, int size) ! 73: { ! 74: low16Buf *lowBuf; ! 75: ! 76: /* ! 77: * Find the associated low16Buf. ! 78: */ ! 79: lowBuf = (low16Buf *)queue_first(&dmaBufQueue); ! 80: while(!queue_end(&dmaBufQueue, (queue_t)lowBuf)) { ! 81: if(lowBuf->buf->_ptr == p) { ! 82: queue_remove(&dmaBufQueue, lowBuf, low16Buf *, link); ! 83: dma_buf_free(lowBuf->buf); ! 84: IOFree(lowBuf->buf, sizeof(*lowBuf->buf)); ! 85: IOFree(lowBuf, sizeof(*lowBuf)); ! 86: return; ! 87: } ! 88: lowBuf = (low16Buf *)lowBuf->link.next; ! 89: } ! 90: IOLog("IOFreeLow: buf 0x%x not found\n", (unsigned)p); ! 91: } ! 92:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.