2 * Copyright (C) 2001-2003 by NBMK Encryption Technologies.
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>.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are
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 /*****************************************************************************/
38 * @briefs file contains the N8_BufferAllocate and N8_BufferFree API calls.
41 *****************************************************************************/
43 /*****************************************************************************
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 ****************************************************************************/
52 #include "n8_malloc_common.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 /*****************************************************************************
61 *****************************************************************************/
63 * @brief Allocates a buffer of contiguous kernel memory of the requested
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.
71 * returns N8_STATUS_OK if successful or Error value.
73 * N8_INVALID_OBJECT One of the parameters is invalid.
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
;
89 /* Parameter checking */
90 CHECK_OBJECT(bufferHandle_p
, ret
);
91 CHECK_OBJECT(virtualAddress_pp
, ret
);
95 /* This is ok, but there is nothing to do */
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
;
111 /*****************************************************************************
113 *****************************************************************************/
115 * @brief Frees a previously allocated buffer of contiguous kernel memory.
117 * @param bufferHandle RO: Handle of buffer to free.
120 * returns N8_STATUS_OK if successful or Error value.
122 * N8_INVALID_OBJECT One of the parameters is invalid.
125 *****************************************************************************/
126 N8_Status_t
N8_BufferFree(N8_BufferHandle_t bufferHandle
)
128 N8_Status_t ret
= N8_STATUS_OK
;
135 /* Parameter checking */
136 CHECK_OBJECT(bufferHandle
, ret
);
138 /* Free the buffer */
139 N8_KFREE((N8_MemoryHandle_t
*) bufferHandle
);