Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / pci / n8 / include_private / n8_malloc_common.h
blob10499fe020d24c29da23ddd12b8229fb07dc931f
1 /*-
2 * Copyright (C) 2001-2003 by NBMK Encryption Technologies.
3 * All rights reserved.
5 * NBMK Encryption Technologies provides no support of any kind for
6 * this software. Questions or concerns about it may be addressed to
7 * the members of the relevant open-source community at
8 * <tech-crypto@netbsd.org>.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are
12 * met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above
18 * copyright notice, this list of conditions and the following
19 * disclaimer in the documentation and/or other materials provided
20 * with the distribution.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 /*****************************************************************************
36 * @(#) n8_malloc_common.h 1.24@(#)
37 *****************************************************************************/
38 /*****************************************************************************/
39 /** @file n8_malloc_common.h
40 * @brief This file contains portability macros for user space and kernel
41 * space memory allocation.
43 * This file provides a portable set of macros for allocating and freeing
44 * memory blocks in both user and kernel space. The memory blocks are
45 * zero filled on allocation. The pointers to the memory blocks are set
46 * to NULL on free. A free of a NULL pointer generates a lowest priority
47 * message using the N8_Debug function. Platforms currently supported are
49 * Behavioral Model
50 * Linux
51 * Solaris
53 * To support a new platform, execute the following command in a directory
54 * where you have write permission:
56 * touch foo.h; cpp -dM foo.h
58 * This will show all of the preprocesser defined macros (such as __linux__).
59 * Pick one of these macros to use as the new platform ifdef.
60 *****************************************************************************/
62 /*****************************************************************************
63 * Revision history:
64 * 10/25/02 brr Clean up function prototypes & include files.
65 * 06/11/02 hml Added externs for the memroy bank control structs.
66 * 03/26/02 brr Added Buffer states, dropped unused parameters from N8_KMALLOC.
67 * 03/08/02 brr Added size to N8_UmallocHdr_t.
68 * 02/18/02 brr Removed all kernel specific references, reconciled function
69 * name discrepancies with n8_driver_api.c.
70 * 02/14/02 brr Reconcile 2.0 memory management changes.
71 * 01/30/02 brr Removed old definition of KMALLOC.
72 * 01/23/02 brr Modifed N8_UMALLOC/FREE macros to call QM_calloc/free.
73 * 01/21/02 bac Changes to support new kernel allocation scheme.
74 * 01/12/02 bac Changed the call to QM_AllocateBuffer to match new signature,
75 * which now includes the __FILE__ and __LINE__ values.
76 * 01/16/02 brr Changed N8_UMALLOC/FREE macros to call n8 functions.
77 * 01/14/02 brr Check size before performing vmalloc.
78 * 01/14/02 hml Added a memset to the N8_UMALLOC macro in kernel build.
79 * 01/10/01 hml Updated for kernel/user space environment.
80 * 01/08/01 brr Define N8_UMALLOC conditionally base on OS.
81 * 12/18/01 brr Removed obsolete bitflags from KMALLOC.
82 * 09/14/01 bac Added macro definition for N8_KMEM_DEFAULT_BITFIELDS which
83 * specifies the default flags for allocating unshared kernel
84 * memory. Changed the macro N8_KMALLOC to use these defaults
85 * when calling QM_AllocateBuffer.
86 * 07/30/01 bac Removed dead code for U/KMALLOC definitions.
87 * 06/22/01 bac Added include of QMMemory.h
88 * 06/15/01 bac Changed N8_KMALLOC/N8_KFREE
89 * 05/09/01 bac Fixed some compilation bugs.
90 * 05/03/01 HML Original version.
91 ****************************************************************************/
92 #ifndef N8_MALLOC_COMMON_H
93 #define N8_MALLOC_COMMON_H
95 #include "n8_pub_common.h"
96 #include "n8_pub_errors.h"
97 #include "n8_OS_intf.h"
98 #include "n8_manage_memory.h"
100 typedef struct {
101 void *nextPtr;
102 int size;
103 } N8_UmallocHdr_t;
105 #if defined(__KERNEL__)
106 #include <asm/io.h>
107 #endif
109 extern void *n8_vmalloc(unsigned long size);
110 extern void n8_vfree(void *memPtr);
112 #define N8_BUFFER_HEADER_SIZE 32
114 /* The following defines are the possible states of a KMALLOC'ed buffer */
115 #define N8_BUFFER_NOT_QUEUED 0 /* Buffer is not on a command Queue */
116 #define N8_BUFFER_QUEUED 1 /* Buffer has been placed on a command Queue */
117 #define N8_BUFFER_SESS_DELETED 2 /* Buffer has been placed on a command Queue */
118 /* but the process has terminated. */
120 /* User space malloc and free macros. Note these are identical regardless
121 of platform. */
123 #define N8_UMALLOC(SIZE) n8_vmalloc((unsigned long)SIZE)
124 #define N8_UFREE(BUF) n8_vfree((void *)BUF)
126 #define N8_KMALLOC(SIZE) N8_AllocateBuffer(SIZE)
127 #define N8_KMALLOC_PK(SIZE) N8_AllocateBufferPK(SIZE)
128 #define N8_KFREE(MEM) N8_FreeBuffer(MEM)
130 #endif /* N8_MALLOC_COMMON_H */