Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / pci / n8 / common / api / n8_buffer.c
blobe68661a3232b6635456553c93905720c0a2a0174
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 static char const n8_id[] = "$Id: n8_buffer.c,v 1.1 2008/10/30 12:02:14 darran Exp $";
36 /*****************************************************************************/
37 /** @file n8_buffer.c
38 * @briefs file contains the N8_BufferAllocate and N8_BufferFree API calls.
41 *****************************************************************************/
43 /*****************************************************************************
44 * Revision history:
45 * 03/29/02 hml Use new style KMALLOC and deleted a user space include file.
46 * 02/12/02 hml First functioning version. Added calls to N8_preamble.
47 * 02/06/02 hml Original version.
48 ****************************************************************************/
49 /** @defgroup Buffer
52 #include "n8_malloc_common.h"
53 #include "n8_util.h"
54 #include "n8_pub_buffer.h"
55 #include "n8_pub_errors.h"
56 #include "n8_pub_common.h"
57 #include "n8_API_Initialize.h"
59 /*****************************************************************************
60 * N8_BufferAllocate
61 *****************************************************************************/
62 /** @ingroup Buffer
63 * @brief Allocates a buffer of contiguous kernel memory of the requested
64 * size.
66 * @param bufferHandle_p WO: Pointer to return area for handle.
67 * @param virtualAddress_pp WO: Pointer to return area for virtual address.
68 * @param nBytes RO: Number of bytes in desired buffer.
70 * @return
71 * returns N8_STATUS_OK if successful or Error value.
72 * @par Errors
73 * N8_INVALID_OBJECT One of the parameters is invalid.
74 * @par Assumptions
75 * None<br>
76 *****************************************************************************/
77 N8_Status_t N8_BufferAllocate(N8_BufferHandle_t *bufferHandle_p,
78 N8_Buffer_t **virtualAddress_pp,
79 const unsigned int nBytes)
81 N8_Status_t ret = N8_STATUS_OK;
82 N8_MemoryHandle_t *kmem_p = NULL;
86 ret = N8_preamble();
87 CHECK_RETURN(ret);
89 /* Parameter checking */
90 CHECK_OBJECT(bufferHandle_p, ret);
91 CHECK_OBJECT(virtualAddress_pp, ret);
93 if (nBytes == 0)
95 /* This is ok, but there is nothing to do */
96 break;
99 /* Allocate the buffer */
100 kmem_p = N8_KMALLOC(nBytes);
101 CHECK_OBJECT(kmem_p, ret);
103 /* Return the data to the user */
104 *bufferHandle_p = (N8_BufferHandle_t) kmem_p;
105 *virtualAddress_pp = (N8_Buffer_t *) kmem_p->VirtualAddress;
106 } while (FALSE);
108 return ret;
111 /*****************************************************************************
112 * N8_BufferFree
113 *****************************************************************************/
114 /** @ingroup Buffer
115 * @brief Frees a previously allocated buffer of contiguous kernel memory.
117 * @param bufferHandle RO: Handle of buffer to free.
119 * @return
120 * returns N8_STATUS_OK if successful or Error value.
121 * @par Errors
122 * N8_INVALID_OBJECT One of the parameters is invalid.
123 * @par Assumptions
124 * None<br>
125 *****************************************************************************/
126 N8_Status_t N8_BufferFree(N8_BufferHandle_t bufferHandle)
128 N8_Status_t ret = N8_STATUS_OK;
132 ret = N8_preamble();
133 CHECK_RETURN(ret);
135 /* Parameter checking */
136 CHECK_OBJECT(bufferHandle, ret);
138 /* Free the buffer */
139 N8_KFREE((N8_MemoryHandle_t *) bufferHandle);
140 } while (FALSE);
142 return ret;