1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2019-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23 
24 #ifndef _NVLINK_OS_H_
25 #define _NVLINK_OS_H_
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 #include "nvlink_common.h"
32 
33 #define TOP_LEVEL_LOCKING_DISABLED 1
34 #define PER_LINK_LOCKING_DISABLED 1
35 
36 #define NVLINK_FREE(x) nvlink_free((void *)x)
37 
38 // Memory management functions
39 void *      nvlink_malloc(NvLength);
40 void        nvlink_free(void *);
41 void *      nvlink_memset(void *, int, NvLength);
42 void *      nvlink_memcpy(void *, const void *, NvLength);
43 int         nvlink_memcmp(const void *, const void *, NvLength);
44 NvU32       nvlink_memRd32(const volatile void *);
45 void        nvlink_memWr32(volatile void *, NvU32);
46 NvU64       nvlink_memRd64(const volatile void *);
47 void        nvlink_memWr64(volatile void *, NvU64);
48 
49 // String management functions
50 char *      nvlink_strcpy(char *, const char *);
51 NvLength    nvlink_strlen(const char *);
52 int         nvlink_strcmp(const char *, const char *);
53 int         nvlink_snprintf(char *, NvLength, const char *, ...);
54 
55 // Locking support functions
56 void *      nvlink_allocLock(void);
57 void        nvlink_acquireLock(void *);
58 NvBool      nvlink_isLockOwner(void *);
59 void        nvlink_releaseLock(void *);
60 void        nvlink_freeLock(void *);
61 
62 // Miscellaneous functions
63 void        nvlink_assert(int expression);
64 void        nvlink_sleep(unsigned int ms);
65 void        nvlink_print(const char *, int, const char *, int, const char *, ...);
66 int         nvlink_is_admin(void);
67 
68 // Capability functions
69 NvlStatus nvlink_acquire_fabric_mgmt_cap(void *osPrivate, NvU64 capDescriptor);
70 int nvlink_is_fabric_manager(void *osPrivate);
71 
72 #define NVLINK_DBG_LEVEL_INFO       0x0
73 #define NVLINK_DBG_LEVEL_SETUP      0x1
74 #define NVLINK_DBG_LEVEL_USERERRORS 0x2
75 #define NVLINK_DBG_LEVEL_WARNINGS   0x3
76 #define NVLINK_DBG_LEVEL_ERRORS     0x4
77 
78 #define NVLINK_DBG_WHERE       __FILE__, __LINE__, __FUNCTION__
79 #define NVLINK_DBG_INFO        NVLINK_DBG_WHERE, NVLINK_DBG_LEVEL_INFO
80 #define NVLINK_DBG_SETUP       NVLINK_DBG_WHERE, NVLINK_DBG_LEVEL_SETUP
81 #define NVLINK_DBG_USERERRORS  NVLINK_DBG_WHERE, NVLINK_DBG_LEVEL_USERERRORS
82 #define NVLINK_DBG_WARNINGS    NVLINK_DBG_WHERE, NVLINK_DBG_LEVEL_WARNINGS
83 #define NVLINK_DBG_ERRORS      NVLINK_DBG_WHERE, NVLINK_DBG_LEVEL_ERRORS
84 
85 #ifdef __cplusplus
86 }
87 #endif
88 
89 #endif //_NVLINK_OS_H_
90