[golan] Add Connect-IB, ConnectX-4 and ConnectX-4 Lx (Infiniband) support
[ipxe.git] / src / drivers / infiniband / mlx_utils_flexboot / src / mlx_memory_priv.c
1 /*
2 * MemoryPriv.c
3 *
4 * Created on: Jan 21, 2015
5 * Author: maord
6 */
7
8 #include <ipxe/malloc.h>
9 #include <stddef.h>
10 #include <byteswap.h>
11 #include <ipxe/io.h>
12 #include "../../mlx_utils/include/private/mlx_memory_priv.h"
13
14
15 mlx_status
16 mlx_memory_alloc_priv(
17 IN mlx_utils *utils __attribute__ ((unused)),
18 IN mlx_size size,
19 OUT mlx_void **ptr
20 )
21 {
22 mlx_status status = MLX_SUCCESS;
23 *ptr = malloc(size);
24 if(*ptr == NULL){
25 status = MLX_OUT_OF_RESOURCES;
26 }
27 return status;
28 }
29
30 mlx_status
31 mlx_memory_zalloc_priv(
32 IN mlx_utils *utils __attribute__ ((unused)),
33 IN mlx_size size,
34 OUT mlx_void **ptr
35 )
36 {
37 mlx_status status = MLX_SUCCESS;
38 *ptr = zalloc(size);
39 if(*ptr == NULL){
40 status = MLX_OUT_OF_RESOURCES;
41 }
42 return status;
43 }
44
45 mlx_status
46 mlx_memory_free_priv(
47 IN mlx_utils *utils __attribute__ ((unused)),
48 IN mlx_void *ptr
49 )
50 {
51 mlx_status status = MLX_SUCCESS;
52 free(ptr);
53 return status;
54 }
55 mlx_status
56 mlx_memory_alloc_dma_priv(
57 IN mlx_utils *utils __attribute__ ((unused)),
58 IN mlx_size size ,
59 IN mlx_size align,
60 OUT mlx_void **ptr
61 )
62 {
63 mlx_status status = MLX_SUCCESS;
64 *ptr = malloc_dma(size, align);
65 if (*ptr == NULL) {
66 status = MLX_OUT_OF_RESOURCES;
67 } else {
68 memset(*ptr, 0, size);
69 }
70 return status;
71 }
72
73 mlx_status
74 mlx_memory_free_dma_priv(
75 IN mlx_utils *utils __attribute__ ((unused)),
76 IN mlx_size size ,
77 IN mlx_void *ptr
78 )
79 {
80 mlx_status status = MLX_SUCCESS;
81 free_dma(ptr, size);
82 return status;
83 }
84 mlx_status
85 mlx_memory_map_dma_priv(
86 IN mlx_utils *utils __attribute__ ((unused)),
87 IN mlx_void *addr ,
88 IN mlx_size number_of_bytes __attribute__ ((unused)),
89 OUT mlx_physical_address *phys_addr,
90 OUT mlx_void **mapping __attribute__ ((unused))
91 )
92 {
93 mlx_status status = MLX_SUCCESS;
94 *phys_addr = virt_to_bus(addr);
95 return status;
96 }
97
98 mlx_status
99 mlx_memory_ummap_dma_priv(
100 IN mlx_utils *utils __attribute__ ((unused)),
101 IN mlx_void *mapping __attribute__ ((unused))
102 )
103 {
104 mlx_status status = MLX_SUCCESS;
105 return status;
106 }
107
108 mlx_status
109 mlx_memory_cmp_priv(
110 IN mlx_utils *utils __unused,
111 IN mlx_void *first_block,
112 IN mlx_void *second_block,
113 IN mlx_size size,
114 OUT mlx_uint32 *out
115 )
116 {
117 mlx_status status = MLX_SUCCESS;
118 *out = memcmp(first_block, second_block, size);
119 return status;
120 }
121
122 mlx_status
123 mlx_memory_set_priv(
124 IN mlx_utils *utils __unused,
125 IN mlx_void *block,
126 IN mlx_int32 value,
127 IN mlx_size size
128 )
129 {
130 mlx_status status = MLX_SUCCESS;
131 memset(block, value, size);
132 return status;
133 }
134
135 mlx_status
136 mlx_memory_cpy_priv(
137 IN mlx_utils *utils __unused,
138 OUT mlx_void *destination_buffer,
139 IN mlx_void *source_buffer,
140 IN mlx_size length
141 )
142 {
143 mlx_status status = MLX_SUCCESS;
144 memcpy(destination_buffer, source_buffer, length);
145 return status;
146 }
147
148 mlx_status
149 mlx_memory_cpu_to_be32_priv(
150 IN mlx_utils *utils __unused,
151 IN mlx_uint32 source,
152 IN mlx_uint32 *destination
153 )
154 {
155 mlx_status status = MLX_SUCCESS;
156 *destination = cpu_to_be32(source);
157 return status;
158 }
159
160
161 mlx_status
162 mlx_memory_be32_to_cpu_priv(
163 IN mlx_utils *utils __unused,
164 IN mlx_uint32 source,
165 IN mlx_uint32 *destination
166 )
167 {
168 mlx_status status = MLX_SUCCESS;
169 *destination = be32_to_cpu(source);
170 return status;
171 }
172