1 /* SPDX-License-Identifier: Apache-2.0
2 * Copyright (c) 2022 Cisco Systems, Inc.
7 #include <vlib/dma/dma.h>
9 VLIB_REGISTER_LOG_CLASS (dma_log) = {
13 vlib_dma_main_t vlib_dma_main = {};
16 vlib_dma_register_backend (vlib_main_t *vm, vlib_dma_backend_t *b)
18 vlib_dma_main_t *dm = &vlib_dma_main;
19 vec_add1 (dm->backends, *b);
20 dma_log_info ("backend '%s' registered", b->name);
25 vlib_dma_config_add (vlib_main_t *vm, vlib_dma_config_t *c)
27 vlib_dma_main_t *dm = &vlib_dma_main;
28 vlib_dma_backend_t *b;
29 vlib_dma_config_data_t *cd;
31 pool_get_zero (dm->configs, cd);
32 cd->config_index = cd - dm->configs;
34 clib_memcpy (&cd->cfg, c, sizeof (vlib_dma_config_t));
36 vec_foreach (b, dm->backends)
38 dma_log_info ("calling '%s' config_add_fn", b->name);
39 if (b->config_add_fn (vm, cd))
41 dma_log_info ("config %u added into backend %s", cd - dm->configs,
43 cd->backend_index = b - dm->backends;
44 return cd - dm->configs;
48 pool_put (dm->configs, cd);
53 vlib_dma_config_del (vlib_main_t *vm, u32 config_index)
55 vlib_dma_main_t *dm = &vlib_dma_main;
56 vlib_dma_config_data_t *cd = pool_elt_at_index (dm->configs, config_index);
57 vlib_dma_backend_t *b = vec_elt_at_index (dm->backends, cd->backend_index);
60 b->config_del_fn (vm, cd);
62 pool_put (dm->configs, cd);
63 dma_log_info ("config %u deleted from backend %s", config_index, b->name);
67 vlib_dma_config_info (u8 *s, va_list *args)
69 vlib_dma_main_t *dm = &vlib_dma_main;
70 int config_index = va_arg (*args, int);
71 u32 len = pool_elts (dm->configs);
72 if (config_index >= len)
73 return format (s, "%s", "not found");
74 vlib_dma_config_data_t *cd = pool_elt_at_index (dm->configs, config_index);
76 vlib_dma_backend_t *b = vec_elt_at_index (dm->backends, cd->backend_index);
79 return b->info_fn (s, args);