iPXE
mlx_memory_priv.c
Go to the documentation of this file.
00001 /*
00002  * MemoryPriv.c
00003  *
00004  *  Created on: Jan 21, 2015
00005  *      Author: maord
00006  */
00007 
00008 #include <ipxe/malloc.h>
00009 #include <stddef.h>
00010 #include <byteswap.h>
00011 #include <ipxe/io.h>
00012 #include "../../mlx_utils/include/private/mlx_memory_priv.h"
00013 
00014 
00015 mlx_status
00016 mlx_memory_alloc_priv(
00017                                 IN mlx_utils *utils __attribute__ ((unused)),
00018                                 IN mlx_size size,
00019                                 OUT mlx_void **ptr
00020                                 )
00021 {
00022         mlx_status status = MLX_SUCCESS;
00023         *ptr = malloc(size);
00024         if(*ptr == NULL){
00025                 status = MLX_OUT_OF_RESOURCES;
00026         }
00027         return status;
00028 }
00029 
00030 mlx_status
00031 mlx_memory_zalloc_priv(
00032                                 IN mlx_utils *utils __attribute__ ((unused)),
00033                                 IN mlx_size size,
00034                                 OUT mlx_void **ptr
00035                                 )
00036 {
00037         mlx_status status = MLX_SUCCESS;
00038         *ptr = zalloc(size);
00039         if(*ptr == NULL){
00040                 status = MLX_OUT_OF_RESOURCES;
00041         }
00042         return status;
00043 }
00044 
00045 mlx_status
00046 mlx_memory_free_priv(
00047                                 IN mlx_utils *utils __attribute__ ((unused)),
00048                                 IN mlx_void *ptr
00049                                 )
00050 {
00051         mlx_status status = MLX_SUCCESS;
00052         free(ptr);
00053         return status;
00054 }
00055 mlx_status
00056 mlx_memory_alloc_dma_priv(
00057                                         IN mlx_utils *utils __attribute__ ((unused)),
00058                                         IN mlx_size size ,
00059                                         IN mlx_size align,
00060                                         OUT mlx_void **ptr
00061                                         )
00062 {
00063         mlx_status status = MLX_SUCCESS;
00064         *ptr = malloc_dma(size, align);
00065         if (*ptr == NULL) {
00066                 status = MLX_OUT_OF_RESOURCES;
00067         } else {
00068                 memset(*ptr, 0, size);
00069         }
00070         return status;
00071 }
00072 
00073 mlx_status
00074 mlx_memory_free_dma_priv(
00075                                         IN mlx_utils *utils __attribute__ ((unused)),
00076                                         IN mlx_size size ,
00077                                         IN mlx_void *ptr
00078                                         )
00079 {
00080         mlx_status status = MLX_SUCCESS;
00081         free_dma(ptr, size);
00082         return status;
00083 }
00084 mlx_status
00085 mlx_memory_map_dma_priv(
00086                                         IN mlx_utils *utils __attribute__ ((unused)),
00087                                         IN mlx_void *addr ,
00088                                         IN mlx_size number_of_bytes __attribute__ ((unused)),
00089                                         OUT mlx_physical_address *phys_addr,
00090                                         OUT mlx_void **mapping __attribute__ ((unused))
00091                                         )
00092 {
00093         mlx_status status = MLX_SUCCESS;
00094         *phys_addr = virt_to_bus(addr);
00095         return status;
00096 }
00097 
00098 mlx_status
00099 mlx_memory_ummap_dma_priv(
00100                                         IN mlx_utils *utils __attribute__ ((unused)),
00101                                         IN mlx_void *mapping __attribute__ ((unused))
00102                                         )
00103 {
00104         mlx_status status = MLX_SUCCESS;
00105         return status;
00106 }
00107 
00108 mlx_status
00109 mlx_memory_cmp_priv(
00110                                         IN mlx_utils *utils __unused,
00111                                         IN mlx_void *first_block,
00112                                         IN mlx_void *second_block,
00113                                         IN mlx_size size,
00114                                         OUT mlx_uint32 *out
00115                                         )
00116 {
00117         mlx_status status = MLX_SUCCESS;
00118         *out = memcmp(first_block, second_block, size);
00119         return status;
00120 }
00121 
00122 mlx_status
00123 mlx_memory_set_priv(
00124                                         IN mlx_utils *utils __unused,
00125                                         IN mlx_void *block,
00126                                         IN mlx_int32 value,
00127                                         IN mlx_size size
00128                                         )
00129 {
00130         mlx_status status = MLX_SUCCESS;
00131         memset(block, value, size);
00132         return status;
00133 }
00134 
00135 mlx_status
00136 mlx_memory_cpy_priv(
00137                                         IN mlx_utils *utils __unused,
00138                                         OUT mlx_void *destination_buffer,
00139                                         IN mlx_void *source_buffer,
00140                                         IN mlx_size length
00141                                         )
00142 {
00143         mlx_status status = MLX_SUCCESS;
00144         memcpy(destination_buffer, source_buffer, length);
00145         return status;
00146 }
00147 
00148 mlx_status
00149 mlx_memory_cpu_to_be32_priv(
00150                         IN mlx_utils *utils __unused,
00151                         IN mlx_uint32 source,
00152                         IN mlx_uint32 *destination
00153                         )
00154 {
00155         mlx_status status = MLX_SUCCESS;
00156         *destination = cpu_to_be32(source);
00157         return status;
00158 }
00159 
00160 
00161 mlx_status
00162 mlx_memory_be32_to_cpu_priv(
00163                         IN mlx_utils *utils __unused,
00164                         IN mlx_uint32 source,
00165                         IN mlx_uint32 *destination
00166                         )
00167 {
00168         mlx_status status = MLX_SUCCESS;
00169         *destination = be32_to_cpu(source);
00170         return status;
00171 }
00172