mirror of
git://nv-tegra.nvidia.com/linux-nvgpu.git
synced 2025-12-24 10:34:43 +03:00
- We are using exit() API to exit the process when gpu goes to quiesce state, but MISRA not allowing to use exit() API. JIRA NVGPU-7056 Signed-off-by: srajum <srajum@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2588005 (cherry picked from commit 219c172da5b6ae330121009765f7eb090b87e054) Change-Id: Id5b927693cc684931bd4aa56e66543b673d0c493 Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2674411 Tested-by: mobile promotions <svcmobile_promotions@nvidia.com> Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
119 lines
3.9 KiB
C
119 lines
3.9 KiB
C
/*
|
|
* Copyright (c) 2017-2021, NVIDIA CORPORATION. All rights reserved.
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
* to deal in the Software without restriction, including without limitation
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
* DEALINGS IN THE SOFTWARE.
|
|
*/
|
|
#ifndef NVGPU_BUG_H
|
|
#define NVGPU_BUG_H
|
|
|
|
#ifdef __KERNEL__
|
|
#include <linux/bug.h>
|
|
#else
|
|
#include <nvgpu/posix/bug.h>
|
|
#endif
|
|
#include <nvgpu/cov_whitelist.h>
|
|
#include <nvgpu/list.h>
|
|
|
|
/**
|
|
* @brief Assert macro based on condition check that code within nvgpu can use.
|
|
*
|
|
* The goal of this macro is to support handling an unexpected state in SW
|
|
* based on the \a cond parameter passed. The implementation is OS specific.
|
|
* In QNX and POSIX implementation, this macro will invoke the #BUG_ON() macro
|
|
* with parameter as #true or #false which is based on the evaluation of
|
|
* \a cond. MAcro does not perform any validation of the parameter.
|
|
*
|
|
* @param cond [in] The condition to check.
|
|
*/
|
|
#if defined(__KERNEL__)
|
|
#define nvgpu_assert(cond) ((void) WARN_ON(!(cond)))
|
|
#else
|
|
/*
|
|
* When this assert fails, the function will not return.
|
|
*/
|
|
#define nvgpu_assert(cond) \
|
|
({ \
|
|
NVGPU_COV_WHITELIST_BLOCK_BEGIN(false_positive, 1, NVGPU_MISRA(Rule, 14_4), "Bug 2277532") \
|
|
NVGPU_COV_WHITELIST_BLOCK_BEGIN(false_positive, 1, NVGPU_MISRA(Rule, 15_6), "Bug 2277532") \
|
|
BUG_ON((cond) == ((bool)(0 != 0))); \
|
|
NVGPU_COV_WHITELIST_BLOCK_END(NVGPU_MISRA(Rule, 14_4)) \
|
|
NVGPU_COV_WHITELIST_BLOCK_END(NVGPU_MISRA(Rule, 15_6)) \
|
|
})
|
|
#endif
|
|
|
|
/**
|
|
* @brief Macro to force a failed assert.
|
|
*
|
|
* The goal of this macro is to force the consequences of a failed assert.
|
|
* Invokes the macro #nvgpu_assert with parameter as #true.
|
|
*/
|
|
#define nvgpu_do_assert() \
|
|
NVGPU_COV_WHITELIST(false_positive, NVGPU_MISRA(Rule, 10_3), "Bug 2623654") \
|
|
nvgpu_assert((bool)(0 != 0))
|
|
|
|
/*
|
|
* Define compile-time assert check.
|
|
*/
|
|
#define ASSERT_CONCAT(a, b) a##b
|
|
#define ASSERT_ADD_INFO(a, b) ASSERT_CONCAT(a, b)
|
|
#define nvgpu_static_assert(e) \
|
|
enum { \
|
|
ASSERT_ADD_INFO(assert_line_, __LINE__) = 1 / (!!(e)) \
|
|
}
|
|
|
|
struct gk20a;
|
|
|
|
/**
|
|
* @brief Macro to force a failed assert with error prints.
|
|
*
|
|
* The goal of this macro is to print an error message and force the
|
|
* consequences of a failed assert. Invokes the macro #nvgpu_err with
|
|
* parameters \a g, \a fmt and \a arg to print an error info and then invokes
|
|
* #nvgpu_do_assert to force a failed assert.
|
|
*/
|
|
#define nvgpu_do_assert_print(g, fmt, arg...) \
|
|
do { \
|
|
nvgpu_err(g, fmt, ##arg); \
|
|
nvgpu_do_assert(); \
|
|
} while (false)
|
|
|
|
|
|
struct nvgpu_bug_cb
|
|
{
|
|
void (*cb)(void *arg);
|
|
void *arg;
|
|
struct nvgpu_list_node node;
|
|
bool sw_quiesce_data;
|
|
};
|
|
|
|
static inline struct nvgpu_bug_cb *
|
|
nvgpu_bug_cb_from_node(struct nvgpu_list_node *node)
|
|
{
|
|
return (struct nvgpu_bug_cb *)
|
|
((uintptr_t)node - offsetof(struct nvgpu_bug_cb, node));
|
|
};
|
|
|
|
#ifdef __KERNEL__
|
|
static inline void nvgpu_bug_exit(void) { }
|
|
static inline void nvgpu_bug_register_cb(struct nvgpu_bug_cb *cb) { }
|
|
static inline void nvgpu_bug_unregister_cb(struct nvgpu_bug_cb *cb) { }
|
|
#endif
|
|
|
|
#endif /* NVGPU_BUG_H */
|