From 6e739d924fe9b778fa82396e0e941143f498acb8 Mon Sep 17 00:00:00 2001 From: Alex Waterman Date: Mon, 22 Jan 2018 16:30:53 -0800 Subject: 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 Reviewed-on: https://git-master.nvidia.com/r/1683914 GVS: Gerrit_Virtual_Submit Reviewed-by: Terje Bergstrom Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/include/nvgpu/atomic.h | 2 + drivers/gpu/nvgpu/include/nvgpu/barrier.h | 2 + drivers/gpu/nvgpu/include/nvgpu/bitops.h | 2 + drivers/gpu/nvgpu/include/nvgpu/bsearch.h | 2 + drivers/gpu/nvgpu/include/nvgpu/bug.h | 2 + drivers/gpu/nvgpu/include/nvgpu/circ_buf.h | 2 + drivers/gpu/nvgpu/include/nvgpu/cond.h | 2 + drivers/gpu/nvgpu/include/nvgpu/kmem.h | 2 + drivers/gpu/nvgpu/include/nvgpu/lock.h | 4 +- drivers/gpu/nvgpu/include/nvgpu/log.h | 2 +- drivers/gpu/nvgpu/include/nvgpu/log2.h | 2 + drivers/gpu/nvgpu/include/nvgpu/nvgpu_mem.h | 2 + drivers/gpu/nvgpu/include/nvgpu/posix/atomic.h | 191 +++++++++++++++++++ drivers/gpu/nvgpu/include/nvgpu/posix/barrier.h | 44 +++++ drivers/gpu/nvgpu/include/nvgpu/posix/bitops.h | 92 +++++++++ drivers/gpu/nvgpu/include/nvgpu/posix/bug.h | 56 ++++++ drivers/gpu/nvgpu/include/nvgpu/posix/circ_buf.h | 44 +++++ drivers/gpu/nvgpu/include/nvgpu/posix/cond.h | 59 ++++++ drivers/gpu/nvgpu/include/nvgpu/posix/kmem.h | 36 ++++ drivers/gpu/nvgpu/include/nvgpu/posix/lock.h | 69 +++++++ drivers/gpu/nvgpu/include/nvgpu/posix/log2.h | 37 ++++ drivers/gpu/nvgpu/include/nvgpu/posix/nvgpu_mem.h | 32 ++++ drivers/gpu/nvgpu/include/nvgpu/posix/probe.h | 31 +++ drivers/gpu/nvgpu/include/nvgpu/posix/rwsem.h | 35 ++++ drivers/gpu/nvgpu/include/nvgpu/posix/sizes.h | 38 ++++ drivers/gpu/nvgpu/include/nvgpu/posix/sort.h | 35 ++++ drivers/gpu/nvgpu/include/nvgpu/posix/thread.h | 51 +++++ drivers/gpu/nvgpu/include/nvgpu/posix/types.h | 219 ++++++++++++++++++++++ drivers/gpu/nvgpu/include/nvgpu/posix/vm.h | 41 ++++ drivers/gpu/nvgpu/include/nvgpu/rwsem.h | 2 + drivers/gpu/nvgpu/include/nvgpu/sizes.h | 2 + drivers/gpu/nvgpu/include/nvgpu/sort.h | 2 + drivers/gpu/nvgpu/include/nvgpu/thread.h | 4 + drivers/gpu/nvgpu/include/nvgpu/types.h | 2 + drivers/gpu/nvgpu/include/nvgpu/vm.h | 2 + 35 files changed, 1148 insertions(+), 2 deletions(-) create mode 100644 drivers/gpu/nvgpu/include/nvgpu/posix/atomic.h create mode 100644 drivers/gpu/nvgpu/include/nvgpu/posix/barrier.h create mode 100644 drivers/gpu/nvgpu/include/nvgpu/posix/bitops.h create mode 100644 drivers/gpu/nvgpu/include/nvgpu/posix/bug.h create mode 100644 drivers/gpu/nvgpu/include/nvgpu/posix/circ_buf.h create mode 100644 drivers/gpu/nvgpu/include/nvgpu/posix/cond.h create mode 100644 drivers/gpu/nvgpu/include/nvgpu/posix/kmem.h create mode 100644 drivers/gpu/nvgpu/include/nvgpu/posix/lock.h create mode 100644 drivers/gpu/nvgpu/include/nvgpu/posix/log2.h create mode 100644 drivers/gpu/nvgpu/include/nvgpu/posix/nvgpu_mem.h create mode 100644 drivers/gpu/nvgpu/include/nvgpu/posix/probe.h create mode 100644 drivers/gpu/nvgpu/include/nvgpu/posix/rwsem.h create mode 100644 drivers/gpu/nvgpu/include/nvgpu/posix/sizes.h create mode 100644 drivers/gpu/nvgpu/include/nvgpu/posix/sort.h create mode 100644 drivers/gpu/nvgpu/include/nvgpu/posix/thread.h create mode 100644 drivers/gpu/nvgpu/include/nvgpu/posix/types.h create mode 100644 drivers/gpu/nvgpu/include/nvgpu/posix/vm.h (limited to 'drivers/gpu/nvgpu/include') diff --git a/drivers/gpu/nvgpu/include/nvgpu/atomic.h b/drivers/gpu/nvgpu/include/nvgpu/atomic.h index 0f319f71..12d1c86e 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/atomic.h +++ b/drivers/gpu/nvgpu/include/nvgpu/atomic.h @@ -24,6 +24,8 @@ #ifdef __KERNEL__ #include +#elif defined(__NVGPU_POSIX__) +#include #else #include #endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/barrier.h b/drivers/gpu/nvgpu/include/nvgpu/barrier.h index 03a14a99..49b10b86 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/barrier.h +++ b/drivers/gpu/nvgpu/include/nvgpu/barrier.h @@ -30,6 +30,8 @@ #ifdef __KERNEL__ #include +#elif defined(__NVGPU_POSIX__) +#include #else #include #endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/bitops.h b/drivers/gpu/nvgpu/include/nvgpu/bitops.h index d3bac60e..26b6e19d 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/bitops.h +++ b/drivers/gpu/nvgpu/include/nvgpu/bitops.h @@ -25,6 +25,8 @@ #ifdef __KERNEL__ #include #include +#elif defined(__NVGPU_POSIX__) +#include #else #include #endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/bsearch.h b/drivers/gpu/nvgpu/include/nvgpu/bsearch.h index b02cc85c..872701e6 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/bsearch.h +++ b/drivers/gpu/nvgpu/include/nvgpu/bsearch.h @@ -24,6 +24,8 @@ #ifdef __KERNEL__ #include +#elif defined(__NVGPU_POSIX__) +#include #endif #endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/bug.h b/drivers/gpu/nvgpu/include/nvgpu/bug.h index ea62c6d8..671439a1 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/bug.h +++ b/drivers/gpu/nvgpu/include/nvgpu/bug.h @@ -24,6 +24,8 @@ #ifdef __KERNEL__ #include +#elif defined(__NVGPU_POSIX__) +#include #else #include #endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/circ_buf.h b/drivers/gpu/nvgpu/include/nvgpu/circ_buf.h index c6620663..4dd9e0d8 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/circ_buf.h +++ b/drivers/gpu/nvgpu/include/nvgpu/circ_buf.h @@ -24,6 +24,8 @@ #ifdef __KERNEL__ #include +#elif defined(__NVGPU_POSIX__) +#include #endif #endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/cond.h b/drivers/gpu/nvgpu/include/nvgpu/cond.h index b6f2598e..340fb460 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/cond.h +++ b/drivers/gpu/nvgpu/include/nvgpu/cond.h @@ -25,6 +25,8 @@ #ifdef __KERNEL__ #include +#elif defined(__NVGPU_POSIX__) +#include #else #include #endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/kmem.h b/drivers/gpu/nvgpu/include/nvgpu/kmem.h index fef837cf..91574ce0 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/kmem.h +++ b/drivers/gpu/nvgpu/include/nvgpu/kmem.h @@ -40,6 +40,8 @@ struct gk20a; */ #ifdef __KERNEL__ #include +#elif defined(__NVGPU_POSIX__) +#include #else #include #endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/lock.h b/drivers/gpu/nvgpu/include/nvgpu/lock.h index bccded57..7e4b2ac3 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/lock.h +++ b/drivers/gpu/nvgpu/include/nvgpu/lock.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2018, 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"), @@ -25,6 +25,8 @@ #ifdef __KERNEL__ #include +#elif defined(__NVGPU_POSIX__) +#include #else #include #endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/log.h b/drivers/gpu/nvgpu/include/nvgpu/log.h index 897dcfc6..87ab17ee 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/log.h +++ b/drivers/gpu/nvgpu/include/nvgpu/log.h @@ -106,7 +106,7 @@ int nvgpu_log_mask_enabled(struct gk20a *g, u64 log_mask); * Print a message if the log_mask matches the enabled debugging. */ #define nvgpu_log(g, log_mask, fmt, arg...) \ - __nvgpu_log_dbg(g, log_mask, __func__, __LINE__, fmt, ##arg) + __nvgpu_log_dbg(g, (u32)log_mask, __func__, __LINE__, fmt, ##arg) /** * nvgpu_err - Print an error diff --git a/drivers/gpu/nvgpu/include/nvgpu/log2.h b/drivers/gpu/nvgpu/include/nvgpu/log2.h index 827162f8..57b77217 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/log2.h +++ b/drivers/gpu/nvgpu/include/nvgpu/log2.h @@ -24,6 +24,8 @@ #ifdef __KERNEL__ #include +#elif defined(__NVGPU_POSIX__) +#include #endif #endif /* __NVGPU_LOG2_H__ */ diff --git a/drivers/gpu/nvgpu/include/nvgpu/nvgpu_mem.h b/drivers/gpu/nvgpu/include/nvgpu/nvgpu_mem.h index c5e3e752..93fce81e 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/nvgpu_mem.h +++ b/drivers/gpu/nvgpu/include/nvgpu/nvgpu_mem.h @@ -29,6 +29,8 @@ #ifdef __KERNEL__ #include +#elif defined(__NVGPU_POSIX__) +#include #else #include #endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/posix/atomic.h b/drivers/gpu/nvgpu/include/nvgpu/posix/atomic.h new file mode 100644 index 00000000..c9d92128 --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/posix/atomic.h @@ -0,0 +1,191 @@ +/* + * Copyright (c) 2017, 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_POSIX_ATOMIC_H__ +#define __NVGPU_POSIX_ATOMIC_H__ + +#include + +/* + * Note: this code uses the GCC builtins to implement atomics. + */ + +#define __atomic_cmpxchg(p, v, c) __sync_val_compare_and_swap(p, v, c) +#define __atomic_and(p, v) __sync_fetch_and_and(p, v) +#define __atomic_or(p, v) __sync_fetch_and_or(p, v) + +#define cmpxchg __atomic_cmpxchg + +/* + * Place holders until real atomics can be implemented... Yay for GCC builtins! + * We can use those eventually to define all the Linux atomic ops. + * + * TODO: make these _actually_ atomic! + */ +typedef struct __nvgpu_posix_atomic { + int v; +} nvgpu_atomic_t; + +typedef struct __nvgpu_posix_atomic64 { + long v; +} nvgpu_atomic64_t; + +#define __nvgpu_atomic_init(i) { i } +#define __nvgpu_atomic64_init(i) { i } + +static inline void __nvgpu_atomic_set(nvgpu_atomic_t *v, int i) +{ + v->v = i; +} + +static inline int __nvgpu_atomic_read(nvgpu_atomic_t *v) +{ + return v->v; +} + +static inline void __nvgpu_atomic_inc(nvgpu_atomic_t *v) +{ + v->v++; +} + +static inline int __nvgpu_atomic_inc_return(nvgpu_atomic_t *v) +{ + v->v++; + return v->v; +} + +static inline void __nvgpu_atomic_dec(nvgpu_atomic_t *v) +{ + v->v--; +} + +static inline int __nvgpu_atomic_dec_return(nvgpu_atomic_t *v) +{ + v->v--; + return v->v; +} + +static inline int __nvgpu_atomic_cmpxchg(nvgpu_atomic_t *v, int old, int new) +{ + if (v->v == old) + v->v = new; + + return v->v; +} + +static inline int __nvgpu_atomic_xchg(nvgpu_atomic_t *v, int new) +{ + v->v = new; + return new; +} + +static inline bool __nvgpu_atomic_inc_and_test(nvgpu_atomic_t *v) +{ + v->v++; + return v->v ? true : false; +} + +static inline bool __nvgpu_atomic_dec_and_test(nvgpu_atomic_t *v) +{ + v->v--; + return v->v ? true : false; +} + +static inline bool __nvgpu_atomic_sub_and_test(int i, nvgpu_atomic_t *v) +{ + v->v -= i; + return v->v ? true : false; +} + +static inline int __nvgpu_atomic_add_return(int i, nvgpu_atomic_t *v) +{ + v->v += i; + return v->v; +} + +static inline int __nvgpu_atomic_add_unless(nvgpu_atomic_t *v, int a, int u) +{ + if (v->v != u) + v->v += a; + + return v->v; +} + +static inline void __nvgpu_atomic64_set(nvgpu_atomic64_t *v, long i) +{ + v->v = i; +} + +static inline long __nvgpu_atomic64_read(nvgpu_atomic64_t *v) +{ + return v->v; +} + +static inline void __nvgpu_atomic64_add(long x, nvgpu_atomic64_t *v) +{ + v->v += x; +} + +static inline void __nvgpu_atomic64_inc(nvgpu_atomic64_t *v) +{ + v->v++; +} + +static inline long __nvgpu_atomic64_inc_return(nvgpu_atomic64_t *v) +{ + v->v++; + return v->v; +} + +static inline void __nvgpu_atomic64_dec(nvgpu_atomic64_t *v) +{ + v->v--; +} + +static inline long __nvgpu_atomic64_dec_return(nvgpu_atomic64_t *v) +{ + v->v--; + return v->v; +} + +static inline long __nvgpu_atomic64_cmpxchg(nvgpu_atomic64_t *v, + long old, long new) +{ + + if (v->v == old) + v->v = new; + + return v->v; +} + +static inline void __nvgpu_atomic64_sub(long x, nvgpu_atomic64_t *v) +{ + v->v -= x; +} + +static inline long __nvgpu_atomic64_sub_return(long x, nvgpu_atomic64_t *v) +{ + v->v -= x; + return v->v; +} + +#endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/posix/barrier.h b/drivers/gpu/nvgpu/include/nvgpu/posix/barrier.h new file mode 100644 index 00000000..edc7b129 --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/posix/barrier.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017, 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_POSIX_BARRIER_H__ +#define __NVGPU_POSIX_BARRIER_H__ + +#define ACCESS_ONCE(x) (*(volatile __typeof__(x) *)&x) + +/* + * TODO: implement all these! + */ +#define __nvgpu_mb() +#define __nvgpu_rmb() +#define __nvgpu_wmb() + +#define __nvgpu_smp_mb() +#define __nvgpu_smp_rmb() +#define __nvgpu_smp_wmb() + +#define __nvgpu_read_barrier_depends() +#define __nvgpu_smp_read_barrier_depends() + +#define __NV_ACCESS_ONCE(x) ACCESS_ONCE(x) + +#endif 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 @@ +/* + * Copyright (c) 2017, 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_POSIX_BITOPS_H__ +#define __NVGPU_POSIX_BITOPS_H__ + +#include + +/* + * Assume an 8 bit byte, of course. + */ +#define BITS_PER_BYTE 8UL +#define BITS_PER_LONG (__SIZEOF_LONG__ * BITS_PER_BYTE) +#define BITS_TO_LONGS(bits) \ + (bits + (BITS_PER_LONG - 1) / BITS_PER_LONG) + +#define BIT(i) (1UL << (i)) + +#define GENMASK(h, l) \ + (((~0UL) - (1UL << (l)) + 1) & (~0UL >> (BITS_PER_LONG - 1 - (h)))) + +#define DECLARE_BITMAP(bmap, bits) \ + unsigned long bmap[BITS_TO_LONGS(bits)] + +#define for_each_set_bit(bit, addr, size) \ + for ((bit) = find_first_bit((addr), (size)); \ + (bit) < (size); \ + (bit) = find_next_bit((addr), (size), (bit) + 1)) + +#define ffs(word) __ffs(word) +#define ffz(word) __ffs(~(word)) +#define fls(word) __fls(word) + +/* + * Clashes with symbols in libc it seems. + */ +#define __ffs(word) __nvgpu_posix_ffs(word) +#define __fls(word) __nvgpu_posix_fls(word) + +unsigned long __nvgpu_posix_ffs(unsigned long word); +unsigned long __nvgpu_posix_fls(unsigned long word); + +unsigned long find_first_bit(const unsigned long *addr, unsigned long size); +unsigned long find_next_bit(const unsigned long *addr, unsigned long size, + unsigned long offset); +unsigned long find_first_zero_bit(const unsigned long *addr, + unsigned long size); + +bool test_bit(int nr, const volatile unsigned long *addr); +bool test_and_set_bit(int nr, volatile unsigned long *addr); +bool test_and_clear_bit(int nr, volatile unsigned long *addr); + +/* + * These two are atomic. + */ +void set_bit(int nr, volatile unsigned long *addr); +void clear_bit(int nr, volatile unsigned long *addr); + +void bitmap_set(unsigned long *map, unsigned int start, int len); +void bitmap_clear(unsigned long *map, unsigned int start, int len); +unsigned long bitmap_find_next_zero_area_off(unsigned long *map, + unsigned long size, + unsigned long start, + unsigned int nr, + unsigned long align_mask, + unsigned long align_offset); +unsigned long bitmap_find_next_zero_area(unsigned long *map, + unsigned long size, + unsigned long start, + unsigned int nr, + unsigned long align_mask); + +#endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/posix/bug.h b/drivers/gpu/nvgpu/include/nvgpu/posix/bug.h new file mode 100644 index 00000000..04389a90 --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/posix/bug.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2018, 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_POSIX_BUG_H__ +#define __NVGPU_POSIX_BUG_H__ + +#include + +/* + * TODO: make these actually useful! + */ + +#define BUG() __bug("") +#define BUG_ON(cond) \ + do { \ + if (cond) \ + BUG(); \ + } while (0) + +#define WARN(cond, msg, arg...) __warn(cond, msg, ##arg) +#define WARN_ON(cond) __warn(cond, "") + +#define WARN_ONCE(cond, msg, arg...) \ + ({static int __warned__ = 0; \ + if (!__warned__) { \ + WARN(cond, msg, ##arg); \ + __warned__ = 1; \ + } \ + cond; }) + + +void dump_stack(void); + +void __bug(const char *fmt, ...) __attribute__ ((noreturn)); +bool __warn(bool cond, const char *fmt, ...); + +#endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/posix/circ_buf.h b/drivers/gpu/nvgpu/include/nvgpu/posix/circ_buf.h new file mode 100644 index 00000000..8d9b5ea0 --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/posix/circ_buf.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2018, 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_POSIX_CIRC_BUF_H__ +#define __NVGPU_POSIX_CIRC_BUF_H__ + +#include + +/* TODO: implement. */ + +#define CIRC_CNT(head, tail, size) \ + ({(void)head; \ + (void)tail; \ + (void)size; \ + BUG(); \ + 1; }) + +#define CIRC_SPACE(head, tail, size) \ + ({(void)head; \ + (void)tail; \ + (void)size; \ + BUG(); \ + 1; }) + +#endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/posix/cond.h b/drivers/gpu/nvgpu/include/nvgpu/posix/cond.h new file mode 100644 index 00000000..3528388b --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/posix/cond.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2018, 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_POSIX_COND_H__ +#define __NVGPU_POSIX_COND_H__ + +#include + +struct nvgpu_cond { + /* Place holder until this can be properly implemented. */ +}; + +/** + * NVGPU_COND_WAIT - Wait for a condition to be true + * + * @c - The condition variable to sleep on + * @condition - The condition that needs to be true + * @timeout_ms - Timeout in milliseconds, or 0 for infinite wait + * + * Wait for a condition to become true. Returns -ETIMEOUT if + * the wait timed out with condition false. + */ +#define NVGPU_COND_WAIT(c, condition, timeout_ms) \ + ({BUG(); 1; }) + +/** + * NVGPU_COND_WAIT_INTERRUPTIBLE - Wait for a condition to be true + * + * @c - The condition variable to sleep on + * @condition - The condition that needs to be true + * @timeout_ms - Timeout in milliseconds, or 0 for infinite wait + * + * Wait for a condition to become true. Returns -ETIMEOUT if + * the wait timed out with condition false or -ERESTARTSYS on + * signal. + */ +#define NVGPU_COND_WAIT_INTERRUPTIBLE(c, condition, timeout_ms) \ + ({BUG(); 1; }) + +#endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/posix/kmem.h b/drivers/gpu/nvgpu/include/nvgpu/posix/kmem.h new file mode 100644 index 00000000..483ac3b3 --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/posix/kmem.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2017, 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_POSIX_KMEM_H__ +#define __NVGPU_POSIX_KMEM_H__ + +#include + +void *__nvgpu_kmalloc(struct gk20a *g, size_t size, unsigned long ip); +void *__nvgpu_kzalloc(struct gk20a *g, size_t size, unsigned long ip); +void *__nvgpu_kcalloc(struct gk20a *g, size_t n, size_t size, unsigned long ip); +void *__nvgpu_vmalloc(struct gk20a *g, unsigned long size, unsigned long ip); +void *__nvgpu_vzalloc(struct gk20a *g, unsigned long size, unsigned long ip); +void __nvgpu_kfree(struct gk20a *g, void *addr); +void __nvgpu_vfree(struct gk20a *g, void *addr); + +#endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/posix/lock.h b/drivers/gpu/nvgpu/include/nvgpu/posix/lock.h new file mode 100644 index 00000000..82eddd02 --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/posix/lock.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2017, 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_POSIX_LOCK_H__ +#define __NVGPU_POSIX_LOCK_H__ + +#include + +#include + +/* + * All locks for posix nvgpu are just pthread locks. There's not a lot of reason + * to have real spinlocks in userspace since we aren't using real HW or running + * perf critical code where a sleep could be devestating. + * + * This could be revisited later, though. + */ +struct __nvgpu_posix_lock { + pthread_mutex_t mutex; +}; + +static inline void __nvgpu_posix_lock_acquire(struct __nvgpu_posix_lock *lock) +{ + pthread_mutex_lock(&lock->mutex); +} + +static inline int __nvgpu_posix_lock_try_acquire( + struct __nvgpu_posix_lock *lock) +{ + return pthread_mutex_trylock(&lock->mutex); +} + +static inline void __nvgpu_posix_lock_release(struct __nvgpu_posix_lock *lock) +{ + pthread_mutex_unlock(&lock->mutex); +} + +struct nvgpu_mutex { + struct __nvgpu_posix_lock lock; +}; + +struct nvgpu_spinlock { + struct __nvgpu_posix_lock lock; +}; + +struct nvgpu_raw_spinlock { + struct __nvgpu_posix_lock lock; +}; + +#endif /* NVGPU_LOCK_LINUX_H */ diff --git a/drivers/gpu/nvgpu/include/nvgpu/posix/log2.h b/drivers/gpu/nvgpu/include/nvgpu/posix/log2.h new file mode 100644 index 00000000..ca95c10a --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/posix/log2.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2018, 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_POSIX_LOG2_H__ +#define __NVGPU_POSIX_LOG2_H__ + +#define ilog2(x) (fls(x) - 1) + +#define roundup_pow_of_two(x) (1UL << fls((x) - 1)) +#define rounddown_pow_of_two(x) (1UL << (fls(x) - 1)) + +#define is_power_of_2(x) \ + ({ \ + typeof(x) __x__ = (x); \ + (__x__ != 0 && ((__x__ & (__x__ - 1)) == 0)); \ + }) + +#endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/posix/nvgpu_mem.h b/drivers/gpu/nvgpu/include/nvgpu/posix/nvgpu_mem.h new file mode 100644 index 00000000..30cdf60f --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/posix/nvgpu_mem.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2017, 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_POSIX_NVGPU_MEM_H__ +#define __NVGPU_POSIX_NVGPU_MEM_H__ + +struct nvgpu_mem_priv { + /* + * Eventually this will require an implementation using nvmap. + */ +}; + +#endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/posix/probe.h b/drivers/gpu/nvgpu/include/nvgpu/posix/probe.h new file mode 100644 index 00000000..a9763aa9 --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/posix/probe.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2018, 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_POSIX_PROBE_H__ +#define __NVGPU_POSIX_PROBE_H__ + +struct gk20a; + +struct gk20a *nvgpu_posix_probe(void); +void nvgpu_posix_cleanup(struct gk20a *g); + +#endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/posix/rwsem.h b/drivers/gpu/nvgpu/include/nvgpu/posix/rwsem.h new file mode 100644 index 00000000..65aa931b --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/posix/rwsem.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2018, 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_POSIX_RWSEM_H__ +#define __NVGPU_POSIX_RWSEM_H__ + +#include + +struct nvgpu_rwsem { + struct nvgpu_spinlock lock; + + int readers; + int writers; +}; + +#endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/posix/sizes.h b/drivers/gpu/nvgpu/include/nvgpu/posix/sizes.h new file mode 100644 index 00000000..3fda7574 --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/posix/sizes.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2017, 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_POSIX_SIZES_H__ +#define __NVGPU_POSIX_SIZES_H__ + +#define SZ_1K (1UL << 10) +#define SZ_4K (SZ_1K << 2) +#define SZ_64K (SZ_1K << 6) +#define SZ_128K (SZ_1K << 7) + +#define SZ_1M (1UL << 20) +#define SZ_16M (SZ_1M << 4) +#define SZ_256M (SZ_1M << 8) + +#define SZ_1G (1UL << 30) +#define SZ_4G (SZ_1G << 2) + +#endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/posix/sort.h b/drivers/gpu/nvgpu/include/nvgpu/posix/sort.h new file mode 100644 index 00000000..6a6920eb --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/posix/sort.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2017, 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_POSIX_SORT_H__ +#define __NVGPU_POSIX_SORT_H__ + +#include + +static void sort(void *base, size_t num, size_t size, + int (*cmp)(const void *, const void *), + void (*swap)(void *, void *, int)) +{ + __bug("sort() not implemented yet!"); +} + +#endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/posix/thread.h b/drivers/gpu/nvgpu/include/nvgpu/posix/thread.h new file mode 100644 index 00000000..a312cc13 --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/posix/thread.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2018, 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_POSIX_THREAD_H__ +#define __NVGPU_POSIX_THREAD_H__ + +#include + +#include + +/* + * Handles passing an nvgpu thread function into a posix thread. + */ +struct nvgpu_posix_thread_data { + int (*fn)(void *data); + void *data; +}; + +/* + * For some reason POSIX only allows 16 bytes of name length. + */ +#define NVGPU_THREAD_POSIX_MAX_NAMELEN 16 + +struct nvgpu_thread { + bool running; + bool should_stop; + pthread_t thread; + struct nvgpu_posix_thread_data nvgpu; + char tname[16]; +}; + +#endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/posix/types.h b/drivers/gpu/nvgpu/include/nvgpu/posix/types.h new file mode 100644 index 00000000..3dfcec6c --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/posix/types.h @@ -0,0 +1,219 @@ +/* + * Copyright (c) 2017, 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_POSIX_TYPES_H__ +#define __NVGPU_POSIX_TYPES_H__ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * For endianness functions. + */ +#include + +typedef unsigned char __u8; +typedef unsigned short __u16; +typedef unsigned int __u32; +typedef unsigned long long __u64; + +typedef __u8 u8; +typedef __u16 u16; +typedef __u32 u32; +typedef __u64 u64; + +typedef char s8; +typedef short s16; +typedef int s32; +typedef long long s64; + +#define min_t(type, a, b) \ + ({ \ + type __a = (a); \ + type __b = (b); \ + __a < __b ? __a : __b; \ + }) + +#define min(a, b) \ + ({ \ + (a) < (b) ? a : b; \ + }) +#define min3(a, b, c) min(min(a, b), c) + +#define max(a, b) \ + ({ \ + (a) > (b) ? a : b; \ + }) + +#define PAGE_SIZE 4096 + +#define ARRAY_SIZE(array) \ + (sizeof(array) / sizeof((array)[0])) + +#define MAX_SCHEDULE_TIMEOUT LONG_MAX + +#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) + +/* + * Only used in clk_gm20b.c which we will never unit test. Don't use! + */ +#define DIV_ROUND_CLOSEST(x, divisor) ({BUG(); 0; }) + +/* + * Joys of userspace: usually division just works since the compiler can link + * against external division functions implicitly. + */ +#define do_div(a, b) ((a) /= (b)) +#define div64_u64(a, b) ((a) / (b)) + +#define __round_mask(x, y) ((__typeof__(x))((y) - 1)) +#define round_up(x, y) ((((x) - 1) | __round_mask(x, y)) + 1) +#define roundup(x, y) round_up(x, y) +#define round_down(x, y) ((x) & ~__round_mask(x, y)) + +#define ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask)) +#define ALIGN(x, a) ALIGN_MASK(x, (typeof(x))(a) - 1) +#define PAGE_ALIGN(x) ALIGN(x, PAGE_SIZE) + +/* + * Caps return at the size of the buffer not what would have been written if buf + * were arbitrarily sized. + */ +static inline int scnprintf(char *buf, size_t size, const char *format, ...) +{ + size_t ret; + va_list args; + + va_start(args, format); + ret = vsnprintf(buf, size, format, args); + va_end(args); + + return ret <= size ? ret : size; +} + +static inline u32 be32_to_cpu(u32 x) +{ + /* + * Conveniently big-endian happens to be network byte order as well so + * we can use ntohl() for this. + */ + return ntohl(x); +} + +/* + * Hamming weights. + */ +static inline unsigned long __hweight8(uint8_t x) +{ + return (unsigned long)(!!(x & (1 << 0)) + + !!(x & (1 << 1)) + + !!(x & (1 << 2)) + + !!(x & (1 << 3)) + + !!(x & (1 << 4)) + + !!(x & (1 << 5)) + + !!(x & (1 << 6)) + + !!(x & (1 << 7))); +} + +static inline unsigned long __hweight16(uint16_t x) +{ + return __hweight8((uint8_t)x) + + __hweight8((uint8_t)((x & 0xff00) >> 8)); +} + +static inline unsigned long __hweight32(uint32_t x) +{ + return __hweight16((uint16_t)x) + + __hweight16((uint16_t)((x & 0xffff0000) >> 16)); +} + +static inline unsigned long __hweight64(uint64_t x) +{ + return __hweight32((uint32_t)x) + + __hweight32((uint32_t)((x & 0xffffffff00000000) >> 32)); +} + +#define hweight32 __hweight32 +#define hweight_long __hweight64 + +/* + * Better suited under a compiler.h type header file, but for now these can live + * here. + */ +#define __must_check +#define __maybe_unused __attribute__((unused)) +#define __iomem +#define unlikely +#define likely + +#define __stringify(x) #x + +/* + * Prevent compiler optimizations from mangling writes. But likely most uses of + * this in nvgpu are incorrect (i.e unnecessary). + */ +#define WRITE_ONCE(p, v) \ + ({ \ + volatile typeof(p) *__p__ = &(p); \ + *__p__ = v; \ + }) + +#define container_of(ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) + +#define __packed __attribute__((packed)) + +#define IS_ENABLED(config) 0 + +#define MAX_ERRNO 4095 + +#define IS_ERR_VALUE(x) ((x) >= (unsigned long)-MAX_ERRNO) + +static inline void *ERR_PTR(long error) +{ + return (void *) error; +} + +static inline long PTR_ERR(void *error) +{ + return (long)(uintptr_t)error; +} + +static inline bool IS_ERR(const void *ptr) +{ + return IS_ERR_VALUE((unsigned long)ptr); +} + +static inline bool IS_ERR_OR_NULL(const void *ptr) +{ + return (ptr == NULL) || IS_ERR_VALUE((unsigned long)ptr); +} + +#endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/posix/vm.h b/drivers/gpu/nvgpu/include/nvgpu/posix/vm.h new file mode 100644 index 00000000..ae997d3c --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/posix/vm.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017, 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_POSIX_VM_H__ +#define __NVGPU_POSIX_VM_H__ + +#include + +struct nvgpu_os_buffer { + /* + * We just use malloc() buffers in userspace. + */ + void *buf; + size_t size; +}; + +struct nvgpu_mapped_buf_priv { + void *buf; + size_t size; +}; + +#endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/rwsem.h b/drivers/gpu/nvgpu/include/nvgpu/rwsem.h index 0366ceff..4facf138 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/rwsem.h +++ b/drivers/gpu/nvgpu/include/nvgpu/rwsem.h @@ -24,6 +24,8 @@ #ifdef __KERNEL__ #include +#elif defined(__NVGPU_POSIX__) +#include #else #include #endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/sizes.h b/drivers/gpu/nvgpu/include/nvgpu/sizes.h index bb6f9c3d..588e772d 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/sizes.h +++ b/drivers/gpu/nvgpu/include/nvgpu/sizes.h @@ -24,6 +24,8 @@ #ifdef __KERNEL__ #include +#elif defined(__NVGPU_POSIX__) +#include #else #include #endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/sort.h b/drivers/gpu/nvgpu/include/nvgpu/sort.h index 0bef3593..20d86680 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/sort.h +++ b/drivers/gpu/nvgpu/include/nvgpu/sort.h @@ -24,6 +24,8 @@ #ifdef __KERNEL__ #include +#elif defined(__NVGPU_POSIX__) +#include #else #include #endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/thread.h b/drivers/gpu/nvgpu/include/nvgpu/thread.h index 79df9cda..316ca146 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/thread.h +++ b/drivers/gpu/nvgpu/include/nvgpu/thread.h @@ -25,10 +25,14 @@ #ifdef __KERNEL__ #include +#elif defined(__NVGPU_POSIX__) +#include #else #include #endif +#include + /** * nvgpu_thread_create - Create and run a new thread. * diff --git a/drivers/gpu/nvgpu/include/nvgpu/types.h b/drivers/gpu/nvgpu/include/nvgpu/types.h index 8425c25d..1e243e53 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/types.h +++ b/drivers/gpu/nvgpu/include/nvgpu/types.h @@ -24,6 +24,8 @@ #ifdef __KERNEL__ #include +#elif defined(__NVGPU_POSIX__) +#include #else #include #endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/vm.h b/drivers/gpu/nvgpu/include/nvgpu/vm.h index a5a358ea..30a2d71d 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/vm.h +++ b/drivers/gpu/nvgpu/include/nvgpu/vm.h @@ -43,6 +43,8 @@ struct nvgpu_os_buffer; #ifdef __KERNEL__ #include +#elif defined(__NVGPU_POSIX__) +#include #else /* QNX include goes here. */ #include -- cgit v1.2.2