iPXE
mlx_memory.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Mellanox Technologies Ltd.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  */
19 
20 FILE_LICENCE ( GPL2_OR_LATER );
21 
22 #include <stddef.h>
23 #include "../../include/private/mlx_memory_priv.h"
24 #include "../../include/public/mlx_memory.h"
25 
28  IN mlx_utils *utils,
30  OUT mlx_void **ptr
31  )
32 {
34  *ptr = NULL;
35  if ( utils == NULL || size == 0 || *ptr != NULL ){
37  goto bad_param;
38  }
39  status = mlx_memory_alloc_priv(utils, size, ptr);
40 bad_param:
41  return status;
42 }
43 
46  IN mlx_utils *utils,
48  OUT mlx_void **ptr
49  )
50 {
52  *ptr = NULL;
53  if ( utils == NULL || size == 0 || *ptr != NULL ){
55  goto bad_param;
56  }
57  status = mlx_memory_zalloc_priv(utils, size, ptr);
58 bad_param:
59  return status;
60 }
61 
64  IN mlx_utils *utils,
65  IN mlx_void **ptr
66  )
67 {
69  if ( utils == NULL || ptr == NULL || *ptr == NULL ){
71  goto bad_param;
72  }
73  status = mlx_memory_free_priv(utils, *ptr);
74  *ptr = NULL;
75 bad_param:
76  return status;
77 }
80  IN mlx_utils *utils,
81  IN mlx_size size ,
82  IN mlx_size align,
83  OUT mlx_void **ptr
84  )
85 {
87  *ptr = NULL;
88  if ( utils == NULL || size == 0 || *ptr != NULL ){
90  goto bad_param;
91  }
92  status = mlx_memory_alloc_dma_priv(utils, size, align, ptr);
93 bad_param:
94  return status;
95 }
96 
99  IN mlx_utils *utils,
100  IN mlx_size size ,
101  IN mlx_void **ptr
102  )
103 {
105  if ( utils == NULL || size == 0 || ptr == NULL || *ptr == NULL ){
107  goto bad_param;
108  }
109  status = mlx_memory_free_dma_priv(utils, size, *ptr);
110  *ptr = NULL;
111 bad_param:
112  return status;
113 }
114 
117  IN mlx_utils *utils,
118  IN mlx_void *addr ,
119  IN mlx_size number_of_bytes,
120  OUT mlx_physical_address *phys_addr,
121  OUT mlx_void **mapping
122  )
123 {
125  if ( utils == NULL || phys_addr == NULL ){
127  goto bad_param;
128  }
129  status = mlx_memory_map_dma_priv(utils, addr, number_of_bytes, phys_addr, mapping);
130 bad_param:
131  return status;
132 }
133 
136  IN mlx_utils *utils,
137  IN mlx_void *mapping
138  )
139 {
141  if ( utils == NULL){
143  goto bad_param;
144  }
145  status = mlx_memory_ummap_dma_priv(utils, mapping);
146 bad_param:
147  return status;
148 }
149 
152  IN mlx_utils *utils,
153  IN mlx_void *first_block,
154  IN mlx_void *second_block,
155  IN mlx_size size,
157  )
158 {
160  if ( utils == NULL || first_block == NULL || second_block == NULL ||
161  out == NULL){
163  goto bad_param;
164  }
165  status = mlx_memory_cmp_priv(utils, first_block, second_block, size, out);
166 bad_param:
167  return status;
168 }
169 
172  IN mlx_utils *utils,
173  IN mlx_void *block,
176  )
177 {
179  if ( utils == NULL || block == NULL){
181  goto bad_param;
182  }
184 bad_param:
185  return status;
186 }
187 
190  IN mlx_utils *utils,
191  OUT mlx_void *destination_buffer,
192  IN mlx_void *source_buffer,
194  )
195 {
197  if ( utils == NULL || destination_buffer == NULL || source_buffer == NULL){
199  goto bad_param;
200  }
201  status = mlx_memory_cpy_priv(utils, destination_buffer, source_buffer, length);
202 bad_param:
203  return status;
204 }
205 
208  IN mlx_utils *utils,
209  IN mlx_uint32 source,
210  IN mlx_uint32 *destination
211  )
212 {
214  if ( utils == NULL || destination == NULL ){
216  goto bad_param;
217  }
218  status = mlx_memory_cpu_to_be32_priv(utils, source, destination);
219 bad_param:
220  return status;
221 }
222 
225  IN mlx_utils *utils,
226  IN mlx_uint32 source,
227  IN mlx_uint32 *destination
228  )
229 {
231  if ( utils == NULL || destination == NULL ){
233  goto bad_param;
234  }
235  status = mlx_memory_be32_to_cpu_priv(utils, source, destination);
236 bad_param:
237  return status;
238 }
mlx_status mlx_memory_cmp(IN mlx_utils *utils, IN mlx_void *first_block, IN mlx_void *second_block, IN mlx_size size, OUT mlx_uint32 *out)
Definition: mlx_memory.c:151
uint16_t length
Length.
Definition: intel.h:14
#define MLX_INVALID_PARAMETER
mlx_status mlx_memory_free(IN mlx_utils *utils, IN mlx_void **ptr)
Definition: mlx_memory.c:63
uint16_t block
Definition: tftp.h:12
mlx_status mlx_memory_cpy_priv(IN mlx_utils *utils, OUT mlx_void *destination_buffer, IN mlx_void *source_buffer, IN mlx_size length)
mlx_status mlx_memory_set(IN mlx_utils *utils, IN mlx_void *block, IN mlx_int32 value, IN mlx_size size)
Definition: mlx_memory.c:171
mlx_status mlx_memory_cpu_to_be32_priv(IN mlx_utils *utils, IN mlx_uint32 source, IN mlx_uint32 *destination)
uint8_t status
Status.
Definition: ena.h:16
uint32_t mlx_uint32
#define OUT
Definition: mlx_utils.h:29
int32_t mlx_int32
mlx_status mlx_memory_ummap_dma(IN mlx_utils *utils, IN mlx_void *mapping)
Definition: mlx_memory.c:135
mlx_status mlx_memory_be32_to_cpu_priv(IN mlx_utils *utils, IN mlx_uint32 source, IN mlx_uint32 *destination)
mlx_status mlx_memory_be32_to_cpu(IN mlx_utils *utils, IN mlx_uint32 source, IN mlx_uint32 *destination)
Definition: mlx_memory.c:224
__be32 out[4]
Definition: CIB_PRM.h:36
#define MLX_SUCCESS
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
mlx_status mlx_memory_free_dma(IN mlx_utils *utils, IN mlx_size size, IN mlx_void **ptr)
Definition: mlx_memory.c:98
mlx_status mlx_memory_map_dma(IN mlx_utils *utils, IN mlx_void *addr, IN mlx_size number_of_bytes, OUT mlx_physical_address *phys_addr, OUT mlx_void **mapping)
Definition: mlx_memory.c:116
mlx_status mlx_memory_set_priv(IN mlx_utils *utils, IN mlx_void *block, IN mlx_int32 value, IN mlx_size size)
u32 addr
Definition: sky2.h:8
size_t mlx_size
mlx_status mlx_memory_alloc_dma(IN mlx_utils *utils, IN mlx_size size, IN mlx_size align, OUT mlx_void **ptr)
Definition: mlx_memory.c:79
mlx_status mlx_memory_cpu_to_be32(IN mlx_utils *utils, IN mlx_uint32 source, IN mlx_uint32 *destination)
Definition: mlx_memory.c:207
mlx_status mlx_memory_ummap_dma_priv(IN mlx_utils *utils, IN mlx_void *mapping)
mlx_status mlx_memory_alloc_dma_priv(IN mlx_utils *utils, IN mlx_size size, IN mlx_size align, OUT mlx_void **ptr)
void mlx_void
#define IN
Definition: mlx_utils.h:28
mlx_status mlx_memory_alloc(IN mlx_utils *utils, IN mlx_size size, OUT mlx_void **ptr)
Definition: mlx_memory.c:27
mlx_status mlx_memory_free_dma_priv(IN mlx_utils *utils, IN mlx_size size, IN mlx_void *ptr)
FILE_LICENCE(GPL2_OR_LATER)
mlx_status mlx_memory_zalloc_priv(IN mlx_utils *utils, IN mlx_size size, OUT mlx_void **ptr)
mlx_status mlx_memory_map_dma_priv(IN mlx_utils *utils, IN mlx_void *addr, IN mlx_size number_of_bytes, OUT mlx_physical_address *phys_addr, OUT mlx_void **mapping)
mlx_status mlx_memory_cpy(IN mlx_utils *utils, OUT mlx_void *destination_buffer, IN mlx_void *source_buffer, IN mlx_size length)
Definition: mlx_memory.c:189
uint8_t size
Entry size (in 32-bit words)
Definition: ena.h:16
mlx_status mlx_memory_free_priv(IN mlx_utils *utils, IN mlx_void *ptr)
int mlx_status
mlx_status mlx_memory_alloc_priv(IN mlx_utils *utils, IN mlx_size size, OUT mlx_void **ptr)
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
mlx_status mlx_memory_zalloc(IN mlx_utils *utils, IN mlx_size size, OUT mlx_void **ptr)
Definition: mlx_memory.c:45
unsigned long mlx_physical_address
mlx_status mlx_memory_cmp_priv(IN mlx_utils *utils, IN mlx_void *first_block, IN mlx_void *second_block, IN mlx_size size, OUT mlx_uint32 *out)