diff options
Diffstat (limited to 'drivers/gpu/nvgpu/common/enabled.c')
-rw-r--r-- | drivers/gpu/nvgpu/common/enabled.c | 48 |
1 files changed, 48 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..d56f0551 --- /dev/null +++ b/drivers/gpu/nvgpu/common/enabled.c | |||
@@ -0,0 +1,48 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify it | ||
5 | * under the terms and conditions of the GNU General Public License, | ||
6 | * version 2, as published by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
11 | * more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #include <nvgpu/enabled.h> | ||
18 | #include <nvgpu/bitops.h> | ||
19 | |||
20 | #include "gk20a/gk20a.h" | ||
21 | |||
22 | int nvgpu_init_enabled_flags(struct gk20a *g) | ||
23 | { | ||
24 | /* | ||
25 | * Zero all flags initially. Flags that should be set to non-zero states | ||
26 | * can be done so during driver init. | ||
27 | */ | ||
28 | g->enabled_flags = nvgpu_kzalloc(g, | ||
29 | BITS_TO_LONGS(NVGPU_MAX_ENABLED_BITS) * | ||
30 | sizeof(unsigned long)); | ||
31 | if (!g->enabled_flags) | ||
32 | return -ENOMEM; | ||
33 | |||
34 | return 0; | ||
35 | } | ||
36 | |||
37 | bool nvgpu_is_enabled(struct gk20a *g, int flag) | ||
38 | { | ||
39 | return test_bit(flag, g->enabled_flags); | ||
40 | } | ||
41 | |||
42 | bool __nvgpu_set_enabled(struct gk20a *g, int flag, bool state) | ||
43 | { | ||
44 | if (state) | ||
45 | return test_and_set_bit(flag, g->enabled_flags); | ||
46 | else | ||
47 | return test_and_clear_bit(flag, g->enabled_flags); | ||
48 | } | ||