summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/common/enabled.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/nvgpu/common/enabled.c')
-rw-r--r--drivers/gpu/nvgpu/common/enabled.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/common/enabled.c b/drivers/gpu/nvgpu/common/enabled.c
new file mode 100644
index 00000000..06cbbe34
--- /dev/null
+++ b/drivers/gpu/nvgpu/common/enabled.c
@@ -0,0 +1,54 @@
1/*
2 * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 */
22
23#include <nvgpu/enabled.h>
24#include <nvgpu/bitops.h>
25
26#include "gk20a/gk20a.h"
27
28int nvgpu_init_enabled_flags(struct gk20a *g)
29{
30 /*
31 * Zero all flags initially. Flags that should be set to non-zero states
32 * can be done so during driver init.
33 */
34 g->enabled_flags = nvgpu_kzalloc(g,
35 BITS_TO_LONGS(NVGPU_MAX_ENABLED_BITS) *
36 sizeof(unsigned long));
37 if (!g->enabled_flags)
38 return -ENOMEM;
39
40 return 0;
41}
42
43bool nvgpu_is_enabled(struct gk20a *g, int flag)
44{
45 return test_bit(flag, g->enabled_flags);
46}
47
48bool __nvgpu_set_enabled(struct gk20a *g, int flag, bool state)
49{
50 if (state)
51 return test_and_set_bit(flag, g->enabled_flags);
52 else
53 return test_and_clear_bit(flag, g->enabled_flags);
54}