iPXE
mlx_memory.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2015 Mellanox Technologies Ltd.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  */
00019 
00020 FILE_LICENCE ( GPL2_OR_LATER );
00021 
00022 #include <stddef.h>
00023 #include "../../include/private/mlx_memory_priv.h"
00024 #include "../../include/public/mlx_memory.h"
00025 
00026 mlx_status
00027 mlx_memory_alloc(
00028                                 IN mlx_utils *utils,
00029                                 IN mlx_size size,
00030                                 OUT mlx_void **ptr
00031                                 )
00032 {
00033         mlx_status status = MLX_SUCCESS;
00034         *ptr = NULL;
00035         if ( utils == NULL || size == 0 || *ptr != NULL ){
00036                 status = MLX_INVALID_PARAMETER;
00037                 goto bad_param;
00038         }
00039         status = mlx_memory_alloc_priv(utils, size, ptr);
00040 bad_param:
00041         return status;
00042 }
00043 
00044 mlx_status
00045 mlx_memory_zalloc(
00046                                 IN mlx_utils *utils,
00047                                 IN mlx_size size,
00048                                 OUT mlx_void **ptr
00049                                 )
00050 {
00051         mlx_status status = MLX_SUCCESS;
00052         *ptr = NULL;
00053         if ( utils == NULL || size == 0 || *ptr != NULL ){
00054                 status = MLX_INVALID_PARAMETER;
00055                 goto bad_param;
00056         }
00057         status = mlx_memory_zalloc_priv(utils, size, ptr);
00058 bad_param:
00059         return status;
00060 }
00061 
00062 mlx_status
00063 mlx_memory_free(
00064                                 IN mlx_utils *utils,
00065                                 IN mlx_void **ptr
00066                                 )
00067 {
00068         mlx_status status = MLX_SUCCESS;
00069         if ( utils == NULL ||  ptr == NULL || *ptr == NULL ){
00070                 status = MLX_INVALID_PARAMETER;
00071                 goto bad_param;
00072         }
00073         status = mlx_memory_free_priv(utils, *ptr);
00074         *ptr = NULL;
00075 bad_param:
00076         return status;
00077 }
00078 mlx_status
00079 mlx_memory_alloc_dma(
00080                                         IN mlx_utils *utils,
00081                                         IN mlx_size size ,
00082                                         IN mlx_size align,
00083                                         OUT mlx_void **ptr
00084                                         )
00085 {
00086         mlx_status status = MLX_SUCCESS;
00087         *ptr = NULL;
00088         if ( utils == NULL || size == 0 || *ptr != NULL ){
00089                 status = MLX_INVALID_PARAMETER;
00090                 goto bad_param;
00091         }
00092         status = mlx_memory_alloc_dma_priv(utils, size, align, ptr);
00093 bad_param:
00094         return status;
00095 }
00096 
00097 mlx_status
00098 mlx_memory_free_dma(
00099                                         IN mlx_utils *utils,
00100                                         IN mlx_size size ,
00101                                         IN mlx_void **ptr
00102                                         )
00103 {
00104         mlx_status status = MLX_SUCCESS;
00105         if ( utils == NULL || size == 0 || ptr == NULL || *ptr == NULL ){
00106                 status = MLX_INVALID_PARAMETER;
00107                 goto bad_param;
00108         }
00109         status = mlx_memory_free_dma_priv(utils, size, *ptr);
00110         *ptr = NULL;
00111 bad_param:
00112         return status;
00113 }
00114 
00115 mlx_status
00116 mlx_memory_map_dma(
00117                                         IN mlx_utils *utils,
00118                                         IN mlx_void *addr ,
00119                                         IN mlx_size number_of_bytes,
00120                                         OUT mlx_physical_address *phys_addr,
00121                                         OUT mlx_void **mapping
00122                                         )
00123 {
00124         mlx_status status = MLX_SUCCESS;
00125         if ( utils == NULL || phys_addr == NULL ){
00126                 status = MLX_INVALID_PARAMETER;
00127                 goto bad_param;
00128         }
00129         status = mlx_memory_map_dma_priv(utils, addr, number_of_bytes, phys_addr, mapping);
00130 bad_param:
00131         return status;
00132 }
00133 
00134 mlx_status
00135 mlx_memory_ummap_dma(
00136                                         IN mlx_utils *utils,
00137                                         IN mlx_void *mapping
00138                                         )
00139 {
00140         mlx_status status = MLX_SUCCESS;
00141         if ( utils == NULL){
00142                 status = MLX_INVALID_PARAMETER;
00143                 goto bad_param;
00144         }
00145         status = mlx_memory_ummap_dma_priv(utils, mapping);
00146 bad_param:
00147         return status;
00148 }
00149 
00150 mlx_status
00151 mlx_memory_cmp(
00152                         IN mlx_utils *utils,
00153                         IN mlx_void *first_block,
00154                         IN mlx_void *second_block,
00155                         IN mlx_size size,
00156                         OUT mlx_uint32 *out
00157                         )
00158 {
00159         mlx_status status = MLX_SUCCESS;
00160         if ( utils == NULL || first_block == NULL || second_block == NULL ||
00161                         out == NULL){
00162                 status = MLX_INVALID_PARAMETER;
00163                 goto bad_param;
00164         }
00165         status = mlx_memory_cmp_priv(utils, first_block, second_block, size, out);
00166 bad_param:
00167         return status;
00168 }
00169 
00170 mlx_status
00171 mlx_memory_set(
00172                                         IN mlx_utils *utils,
00173                                         IN mlx_void *block,
00174                                         IN mlx_int32 value,
00175                                         IN mlx_size size
00176                                         )
00177 {
00178         mlx_status status = MLX_SUCCESS;
00179         if ( utils == NULL || block == NULL){
00180                 status = MLX_INVALID_PARAMETER;
00181                 goto bad_param;
00182         }
00183         status = mlx_memory_set_priv(utils, block, value, size);
00184 bad_param:
00185         return status;
00186 }
00187 
00188 mlx_status
00189 mlx_memory_cpy(
00190                         IN mlx_utils *utils,
00191                         OUT mlx_void *destination_buffer,
00192                         IN mlx_void *source_buffer,
00193                         IN mlx_size length
00194                         )
00195 {
00196         mlx_status status = MLX_SUCCESS;
00197         if ( utils == NULL || destination_buffer == NULL || source_buffer == NULL){
00198                 status = MLX_INVALID_PARAMETER;
00199                 goto bad_param;
00200         }
00201         status = mlx_memory_cpy_priv(utils, destination_buffer, source_buffer, length);
00202 bad_param:
00203         return status;
00204 }
00205 
00206 mlx_status
00207 mlx_memory_cpu_to_be32(
00208                         IN mlx_utils *utils,
00209                         IN mlx_uint32 source,
00210                         IN mlx_uint32 *destination
00211                         )
00212 {
00213         mlx_status status = MLX_SUCCESS;
00214         if ( utils == NULL || destination == NULL ){
00215                 status = MLX_INVALID_PARAMETER;
00216                 goto bad_param;
00217         }
00218         status = mlx_memory_cpu_to_be32_priv(utils, source, destination);
00219 bad_param:
00220         return status;
00221 }
00222 
00223 mlx_status
00224 mlx_memory_be32_to_cpu(
00225                         IN mlx_utils *utils,
00226                         IN mlx_uint32 source,
00227                         IN mlx_uint32 *destination
00228                         )
00229 {
00230         mlx_status status = MLX_SUCCESS;
00231         if ( utils == NULL || destination == NULL ){
00232                 status = MLX_INVALID_PARAMETER;
00233                 goto bad_param;
00234         }
00235         status = mlx_memory_be32_to_cpu_priv(utils, source, destination);
00236 bad_param:
00237         return status;
00238 }