1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2020 Mellanox Technologies, Ltd
5 #ifndef RTE_PMD_MLX5_COMMON_OS_H_
6 #define RTE_PMD_MLX5_COMMON_OS_H_
11 #include <rte_errno.h>
13 #include "mlx5_autoconf.h"
14 #include "mlx5_glue.h"
15 #include "mlx5_malloc.h"
16 #include "mlx5_common_mr.h"
17 #include "mlx5_win_ext.h"
19 #define MLX5_BF_OFFSET 0x800
22 * This API allocates aligned or non-aligned memory. The free can be on either
23 * aligned or nonaligned memory. To be protected - even though there may be no
24 * alignment - in Windows this API will unconditionally call _aligned_malloc()
25 * with at least a minimal alignment size.
28 * The alignment value, which must be an integer power of 2 (or 0 for
31 * Size in bytes to allocate
34 * Valid pointer to allocated memory, NULL in case of failure
37 mlx5_os_malloc(size_t align, size_t size)
39 if (align < MLX5_MALLOC_ALIGNMENT)
40 align = MLX5_MALLOC_ALIGNMENT;
41 return _aligned_malloc(size, align);
45 * This API de-allocates a memory that originally could have been allocated
46 * aligned or non-aligned. In Windows since the allocation was with
47 * _aligned_malloc() - it is safe to always call _aligned_free().
50 * Pointer to address to free
54 mlx5_os_free(void *addr)
60 * Get fd. Given a pointer to DevX channel object of type
61 * 'struct mlx5dv_devx_event_channel*' - return its fd.
62 * Under Windows it is a stub.
65 * Pointer to channel object.
71 mlx5_os_get_devx_channel_fd(void *channel)
79 * Get device name. Given a device pointer - return a
80 * pointer to the corresponding device name.
86 * Pointer to device name if dev is valid, NULL otherwise.
88 static inline const char *
89 mlx5_os_get_dev_device_name(void *dev)
93 return ((struct devx_device *)dev)->name;
97 * Get device name. Given a context pointer - return a
98 * pointer to the corresponding device name.
101 * Pointer to context.
104 * Pointer to device name if ctx is valid, NULL otherwise.
106 static inline const char *
107 mlx5_os_get_ctx_device_name(void *ctx)
111 return ((mlx5_context_st *)ctx)->mlx5_dev.name;
115 * Get a device path name. Given acontext pointer - return a
116 * pointer to the corresponding device path name.
119 * Pointer to context.
122 * Pointer to device path name if ctx is valid, NULL otherwise.
125 static inline const char *
126 mlx5_os_get_ctx_device_path(void *ctx)
130 return ((mlx5_context_st *)ctx)->mlx5_dev.dev_pnp_id;
134 * Get umem id. Given a pointer to umem object of type return its id.
137 * Pointer to umem object.
140 * The umem id if umem is valid, 0 otherwise.
142 static inline uint32_t
143 mlx5_os_get_umem_id(void *umem)
147 return ((struct mlx5_devx_umem *)umem)->umem_id;
151 * Get mmap offset. Given a pointer to an DevX UAR object of type
152 * 'struct mlx5dv_devx_uar *' - return its mmap offset.
153 * In Windows, mmap_offset is unused.
156 * Pointer to UAR object.
159 * 0 as mmap_offset is unused
162 mlx5_os_get_devx_uar_mmap_offset(void *uar)
169 * Get base addr pointer. Given a pointer to an UAR object of type
170 * 'struct mlx5dv_devx_uar *' - return its base address.
173 * Pointer to an UAR object.
176 * The base address if UAR is valid, NULL otherwise.
179 mlx5_os_get_devx_uar_base_addr(void *uar)
183 return ((devx_uar_handle *)uar)->uar_page;
187 * Get reg addr pointer. Given a pointer to an UAR object of type
188 * 'struct mlx5dv_devx_uar *' - return its reg address.
191 * Pointer to an UAR object.
194 * The reg address if UAR is valid, NULL otherwise.
197 mlx5_os_get_devx_uar_reg_addr(void *uar)
201 return ((char *)((devx_uar_handle *)uar)->uar_page) + MLX5_BF_OFFSET;
205 * Get page id. Given a pointer to an UAR object of type
206 * 'struct mlx5dv_devx_uar *' - return its page id.
209 * Pointer to an UAR object.
212 * The page id if UAR is valid, 0 otherwise.
214 static inline uint32_t
215 mlx5_os_get_devx_uar_page_id(void *uar)
219 return ((devx_uar_handle *)uar)->uar_index;
223 mlx5_os_devx_create_event_channel(void *ctx, int flags)
232 mlx5_os_devx_destroy_event_channel(void *eventc)
238 mlx5_os_devx_subscribe_devx_event(void *eventc,
240 uint16_t events_sz, uint16_t events_num[],
252 void *mlx5_os_umem_reg(void *ctx, void *addr, size_t size, uint32_t access);
254 int mlx5_os_umem_dereg(void *pumem);
256 #endif /* RTE_PMD_MLX5_COMMON_OS_H_ */