summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/include/nvgpu/posix/bitops.h
diff options
context:
space:
mode:
authorAlex Waterman <alexw@nvidia.com>2018-01-22 19:30:53 -0500
committermobile promotions <svcmobile_promotions@nvidia.com>2018-05-07 07:41:26 -0400
commit6e739d924fe9b778fa82396e0e941143f498acb8 (patch)
treef112ede8573c2f8bf76e0bdaadf33c6c71343820 /drivers/gpu/nvgpu/include/nvgpu/posix/bitops.h
parente6b3bb4e6b3d4013f83ba6d31c780947f16cf410 (diff)
gpu: nvgpu: Userspace POSIX support
Add support for compiling nvgpu in a POSIX compliant userspace. This code adds all of the necessary abstraction interfaces (mostly stubbed) to enabled extremely limited and basic functionality in nvgpu. The goal of this code is to facilitate unit testing of the nvgpu common core. By doing this in userspace it is much easier to write tests that rely on very particular states within nvgpu since a user can very precisely control the state of nvgpu. JIRA NVGPU-525 Change-Id: I30e95016df14997d951075777e0585f912dc5960 Signed-off-by: Alex Waterman <alexw@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1683914 GVS: Gerrit_Virtual_Submit Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com> Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/include/nvgpu/posix/bitops.h')
-rw-r--r--drivers/gpu/nvgpu/include/nvgpu/posix/bitops.h92
1 files changed, 92 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/include/nvgpu/posix/bitops.h b/drivers/gpu/nvgpu/include/nvgpu/posix/bitops.h
new file mode 100644
index 00000000..bfc6fef1
--- /dev/null
+++ b/drivers/gpu/nvgpu/include/nvgpu/posix/bitops.h
@@ -0,0 +1,92 @@
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#ifndef __NVGPU_POSIX_BITOPS_H__
24#define __NVGPU_POSIX_BITOPS_H__
25
26#include <nvgpu/types.h>
27
28/*
29 * Assume an 8 bit byte, of course.
30 */
31#define BITS_PER_BYTE 8UL
32#define BITS_PER_LONG (__SIZEOF_LONG__ * BITS_PER_BYTE)
33#define BITS_TO_LONGS(bits) \
34 (bits + (BITS_PER_LONG - 1) / BITS_PER_LONG)
35
36#define BIT(i) (1UL << (i))
37
38#define GENMASK(h, l) \
39 (((~0UL) - (1UL << (l)) + 1) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
40
41#define DECLARE_BITMAP(bmap, bits) \
42 unsigned long bmap[BITS_TO_LONGS(bits)]
43
44#define for_each_set_bit(bit, addr, size) \
45 for ((bit) = find_first_bit((addr), (size)); \
46 (bit) < (size); \
47 (bit) = find_next_bit((addr), (size), (bit) + 1))
48
49#define ffs(word) __ffs(word)
50#define ffz(word) __ffs(~(word))
51#define fls(word) __fls(word)
52
53/*
54 * Clashes with symbols in libc it seems.
55 */
56#define __ffs(word) __nvgpu_posix_ffs(word)
57#define __fls(word) __nvgpu_posix_fls(word)
58
59unsigned long __nvgpu_posix_ffs(unsigned long word);
60unsigned long __nvgpu_posix_fls(unsigned long word);
61
62unsigned long find_first_bit(const unsigned long *addr, unsigned long size);
63unsigned long find_next_bit(const unsigned long *addr, unsigned long size,
64 unsigned long offset);
65unsigned long find_first_zero_bit(const unsigned long *addr,
66 unsigned long size);
67
68bool test_bit(int nr, const volatile unsigned long *addr);
69bool test_and_set_bit(int nr, volatile unsigned long *addr);
70bool test_and_clear_bit(int nr, volatile unsigned long *addr);
71
72/*
73 * These two are atomic.
74 */
75void set_bit(int nr, volatile unsigned long *addr);
76void clear_bit(int nr, volatile unsigned long *addr);
77
78void bitmap_set(unsigned long *map, unsigned int start, int len);
79void bitmap_clear(unsigned long *map, unsigned int start, int len);
80unsigned long bitmap_find_next_zero_area_off(unsigned long *map,
81 unsigned long size,
82 unsigned long start,
83 unsigned int nr,
84 unsigned long align_mask,
85 unsigned long align_offset);
86unsigned long bitmap_find_next_zero_area(unsigned long *map,
87 unsigned long size,
88 unsigned long start,
89 unsigned int nr,
90 unsigned long align_mask);
91
92#endif