NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
apsh_modules_get_sample.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022 NVIDIA CORPORATION AND AFFILIATES. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are permitted
5  * provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21  * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  */
25 #include <doca_apsh.h>
26 #include <doca_log.h>
27 
28 #include "apsh_common.h"
29 
30 DOCA_LOG_REGISTER(MODULES_GET);
31 
32 /*
33  * Calls the DOCA APSH API function that matches this sample name and prints the result
34  *
35  * @dma_device_name [in]: IBDEV Name of the device to use for DMA
36  * @pci_vuid [in]: VUID of the device exposed to the target system
37  * @os_type [in]: Indicates the OS type of the target system
38  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
39  */
40 doca_error_t modules_get(const char *dma_device_name,
41  const char *pci_vuid,
42  enum doca_apsh_system_os os_type,
43  const char *mem_region,
44  const char *os_symbols)
45 {
47  int num_modules, i;
48  struct doca_apsh_ctx *apsh_ctx;
49  struct doca_apsh_system *sys;
50  struct doca_apsh_module **modules;
52 
53  /* Init */
54  result = init_doca_apsh(dma_device_name, &apsh_ctx);
55  if (result != DOCA_SUCCESS) {
56  DOCA_LOG_ERR("Failed to init the DOCA APSH lib");
57  return result;
58  }
59  DOCA_LOG_INFO("DOCA APSH lib context init successful");
60 
61  result = init_doca_apsh_system(apsh_ctx, os_type, os_symbols, mem_region, pci_vuid, &sys);
62  if (result != DOCA_SUCCESS) {
63  DOCA_LOG_ERR("Failed to init the system context");
64  return result;
65  }
66  DOCA_LOG_INFO("DOCA APSH system context created");
67 
68  result = doca_apsh_modules_get(sys, &modules, &num_modules);
69  if (result != DOCA_SUCCESS) {
70  DOCA_LOG_ERR("Failed to get modules of system");
71  cleanup_doca_apsh(apsh_ctx, sys);
72  return result;
73  }
74  DOCA_LOG_INFO("Successfully performed %s. Host system has %d modules", __func__, num_modules);
75 
76  /* Print names of some modules */
77  DOCA_LOG_INFO("System modules (showing only 5 or less):");
78  for (i = 0; i < 5 && i < num_modules; ++i) {
80  DOCA_LOG_INFO("\t%s", mod_name);
81  }
82 
83  /* Cleanup */
84  doca_apsh_module_free(modules);
85  cleanup_doca_apsh(apsh_ctx, sys);
86  return DOCA_SUCCESS;
87 }
int32_t result
doca_error_t cleanup_doca_apsh(struct doca_apsh_ctx *ctx, struct doca_apsh_system *system)
Definition: apsh_common.c:384
doca_error_t init_doca_apsh_system(struct doca_apsh_ctx *ctx, enum doca_apsh_system_os os_type, const char *os_symbols, const char *mem_region, const char *pci_vuid, struct doca_apsh_system **system)
Definition: apsh_common.c:325
doca_error_t init_doca_apsh(const char *dma_device_name, struct doca_apsh_ctx **ctx)
Definition: apsh_common.c:287
doca_error_t modules_get(const char *dma_device_name, const char *pci_vuid, enum doca_apsh_system_os os_type, const char *mem_region, const char *os_symbols)
DOCA_LOG_REGISTER(MODULES_GET)
const char * DOCA_APSH_MODULES_NAME_TYPE
module name type
doca_apsh_system_os
system os types
@ DOCA_APSH_MODULES_NAME
#define doca_apsh_module_info_get(module, attr)
Get attribute value for a module.
Definition: doca_apsh.h:553
DOCA_EXPERIMENTAL void doca_apsh_module_free(struct doca_apsh_module **modules)
Destroys a modules array.
DOCA_EXPERIMENTAL doca_error_t doca_apsh_modules_get(struct doca_apsh_system *system, struct doca_apsh_module ***modules, int *modules_size)
Get array of current modules installed on the system.
enum doca_error doca_error_t
DOCA API return codes.
@ DOCA_SUCCESS
Definition: doca_error.h:38
#define DOCA_LOG_ERR(format,...)
Generates an ERROR application log message.
Definition: doca_log.h:466
#define DOCA_LOG_INFO(format,...)
Generates an INFO application log message.
Definition: doca_log.h:486