aboutsummaryrefslogtreecommitdiffstats
path: root/include/nvgpu/linux
diff options
context:
space:
mode:
Diffstat (limited to 'include/nvgpu/linux')
-rw-r--r--include/nvgpu/linux/atomic.h149
-rw-r--r--include/nvgpu/linux/barrier.h37
-rw-r--r--include/nvgpu/linux/cond.h81
-rw-r--r--include/nvgpu/linux/dma.h38
-rw-r--r--include/nvgpu/linux/kmem.h47
-rw-r--r--include/nvgpu/linux/lock.h81
-rw-r--r--include/nvgpu/linux/nvgpu_mem.h89
-rw-r--r--include/nvgpu/linux/nvlink.h31
-rw-r--r--include/nvgpu/linux/os_fence_android.h48
-rw-r--r--include/nvgpu/linux/rwsem.h26
-rw-r--r--include/nvgpu/linux/sim.h38
-rw-r--r--include/nvgpu/linux/sim_pci.h26
-rw-r--r--include/nvgpu/linux/thread.h29
-rw-r--r--include/nvgpu/linux/vm.h92
14 files changed, 812 insertions, 0 deletions
diff --git a/include/nvgpu/linux/atomic.h b/include/nvgpu/linux/atomic.h
new file mode 100644
index 0000000..0734672
--- /dev/null
+++ b/include/nvgpu/linux/atomic.h
@@ -0,0 +1,149 @@
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#ifndef __NVGPU_ATOMIC_LINUX_H__
17#define __NVGPU_ATOMIC_LINUX_H__
18
19#ifdef __KERNEL__
20#include <linux/atomic.h>
21#endif
22
23typedef struct nvgpu_atomic {
24 atomic_t atomic_var;
25} nvgpu_atomic_t;
26
27typedef struct nvgpu_atomic64 {
28 atomic64_t atomic_var;
29} nvgpu_atomic64_t;
30
31#define __nvgpu_atomic_init(i) { ATOMIC_INIT(i) }
32#define __nvgpu_atomic64_init(i) { ATOMIC64_INIT(i) }
33
34static inline void __nvgpu_atomic_set(nvgpu_atomic_t *v, int i)
35{
36 atomic_set(&v->atomic_var, i);
37}
38
39static inline int __nvgpu_atomic_read(nvgpu_atomic_t *v)
40{
41 return atomic_read(&v->atomic_var);
42}
43
44static inline void __nvgpu_atomic_inc(nvgpu_atomic_t *v)
45{
46 atomic_inc(&v->atomic_var);
47}
48
49static inline int __nvgpu_atomic_inc_return(nvgpu_atomic_t *v)
50{
51 return atomic_inc_return(&v->atomic_var);
52}
53
54static inline void __nvgpu_atomic_dec(nvgpu_atomic_t *v)
55{
56 atomic_dec(&v->atomic_var);
57}
58
59static inline int __nvgpu_atomic_dec_return(nvgpu_atomic_t *v)
60{
61 return atomic_dec_return(&v->atomic_var);
62}
63
64static inline int __nvgpu_atomic_cmpxchg(nvgpu_atomic_t *v, int old, int new)
65{
66 return atomic_cmpxchg(&v->atomic_var, old, new);
67}
68
69static inline int __nvgpu_atomic_xchg(nvgpu_atomic_t *v, int new)
70{
71 return atomic_xchg(&v->atomic_var, new);
72}
73
74static inline bool __nvgpu_atomic_inc_and_test(nvgpu_atomic_t *v)
75{
76 return atomic_inc_and_test(&v->atomic_var);
77}
78
79static inline bool __nvgpu_atomic_dec_and_test(nvgpu_atomic_t *v)
80{
81 return atomic_dec_and_test(&v->atomic_var);
82}
83
84static inline bool __nvgpu_atomic_sub_and_test(int i, nvgpu_atomic_t *v)
85{
86 return atomic_sub_and_test(i, &v->atomic_var);
87}
88
89static inline int __nvgpu_atomic_add_return(int i, nvgpu_atomic_t *v)
90{
91 return atomic_add_return(i, &v->atomic_var);
92}
93
94static inline int __nvgpu_atomic_add_unless(nvgpu_atomic_t *v, int a, int u)
95{
96 return atomic_add_unless(&v->atomic_var, a, u);
97}
98
99static inline void __nvgpu_atomic64_set(nvgpu_atomic64_t *v, long i)
100{
101 atomic64_set(&v->atomic_var, i);
102}
103
104static inline long __nvgpu_atomic64_read(nvgpu_atomic64_t *v)
105{
106 return atomic64_read(&v->atomic_var);
107}
108
109static inline void __nvgpu_atomic64_add(long x, nvgpu_atomic64_t *v)
110{
111 atomic64_add(x, &v->atomic_var);
112}
113
114static inline void __nvgpu_atomic64_inc(nvgpu_atomic64_t *v)
115{
116 atomic64_inc(&v->atomic_var);
117}
118
119static inline long __nvgpu_atomic64_inc_return(nvgpu_atomic64_t *v)
120{
121 return atomic64_inc_return(&v->atomic_var);
122}
123
124static inline void __nvgpu_atomic64_dec(nvgpu_atomic64_t *v)
125{
126 atomic64_dec(&v->atomic_var);
127}
128
129static inline void __nvgpu_atomic64_dec_return(nvgpu_atomic64_t *v)
130{
131 atomic64_dec_return(&v->atomic_var);
132}
133
134static inline long __nvgpu_atomic64_cmpxchg(nvgpu_atomic64_t *v,
135 long old, long new)
136{
137 return atomic64_cmpxchg(&v->atomic_var, old, new);
138}
139
140static inline void __nvgpu_atomic64_sub(long x, nvgpu_atomic64_t *v)
141{
142 atomic64_sub(x, &v->atomic_var);
143}
144
145static inline long __nvgpu_atomic64_sub_return(long x, nvgpu_atomic64_t *v)
146{
147 return atomic64_sub_return(x, &v->atomic_var);
148}
149#endif /*__NVGPU_ATOMIC_LINUX_H__ */
diff --git a/include/nvgpu/linux/barrier.h b/include/nvgpu/linux/barrier.h
new file mode 100644
index 0000000..ef867c4
--- /dev/null
+++ b/include/nvgpu/linux/barrier.h
@@ -0,0 +1,37 @@
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#ifndef __NVGPU_BARRIER_LINUX_H__
18#define __NVGPU_BARRIER_LINUX_H__
19
20#include <asm/barrier.h>
21
22#define __nvgpu_mb() mb()
23#define __nvgpu_rmb() rmb()
24#define __nvgpu_wmb() wmb()
25
26#define __nvgpu_smp_mb() smp_mb()
27#define __nvgpu_smp_rmb() smp_rmb()
28#define __nvgpu_smp_wmb() smp_wmb()
29
30#define __nvgpu_read_barrier_depends() read_barrier_depends()
31#define __nvgpu_smp_read_barrier_depends() smp_read_barrier_depends()
32
33#define __NV_ACCESS_ONCE(x) ACCESS_ONCE(x)
34
35#define __nvgpu_speculation_barrier() speculation_barrier()
36
37#endif /* __NVGPU_BARRIER_LINUX_H__ */
diff --git a/include/nvgpu/linux/cond.h b/include/nvgpu/linux/cond.h
new file mode 100644
index 0000000..b53ada3
--- /dev/null
+++ b/include/nvgpu/linux/cond.h
@@ -0,0 +1,81 @@
1/*
2 * Copyright (c) 2017-2019, 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#ifndef __NVGPU_COND_LINUX_H__
18#define __NVGPU_COND_LINUX_H__
19
20#include <linux/wait.h>
21#include <linux/sched.h>
22
23struct nvgpu_cond {
24 bool initialized;
25 wait_queue_head_t wq;
26};
27
28/**
29 * NVGPU_COND_WAIT - Wait for a condition to be true
30 *
31 * @c - The condition variable to sleep on
32 * @condition - The condition that needs to be true
33 * @timeout_ms - Timeout in milliseconds, or 0 for infinite wait
34 *
35 * Wait for a condition to become true. Returns -ETIMEOUT if
36 * the wait timed out with condition false.
37 */
38#define NVGPU_COND_WAIT(c, condition, timeout_ms) \
39({\
40 int ret = 0; \
41 long _timeout_ms = timeout_ms;\
42 if (_timeout_ms > 0) { \
43 long _ret = wait_event_timeout((c)->wq, condition, \
44 msecs_to_jiffies(_timeout_ms)); \
45 if (_ret == 0) \
46 ret = -ETIMEDOUT; \
47 } else { \
48 wait_event((c)->wq, condition); \
49 } \
50 ret;\
51})
52
53/**
54 * NVGPU_COND_WAIT_INTERRUPTIBLE - Wait for a condition to be true
55 *
56 * @c - The condition variable to sleep on
57 * @condition - The condition that needs to be true
58 * @timeout_ms - Timeout in milliseconds, or 0 for infinite wait
59 *
60 * Wait for a condition to become true. Returns -ETIMEOUT if
61 * the wait timed out with condition false or -ERESTARTSYS on
62 * signal.
63 */
64#define NVGPU_COND_WAIT_INTERRUPTIBLE(c, condition, timeout_ms) \
65({ \
66 int ret = 0; \
67 long _timeout_ms = timeout_ms;\
68 if (_timeout_ms > 0) { \
69 long _ret = wait_event_interruptible_timeout((c)->wq, condition, \
70 msecs_to_jiffies(_timeout_ms)); \
71 if (_ret == 0) \
72 ret = -ETIMEDOUT; \
73 else if (_ret == -ERESTARTSYS) \
74 ret = -ERESTARTSYS; \
75 } else { \
76 ret = wait_event_interruptible((c)->wq, condition); \
77 } \
78 ret; \
79})
80
81#endif /* __NVGPU_LOCK_LINUX_H__ */
diff --git a/include/nvgpu/linux/dma.h b/include/nvgpu/linux/dma.h
new file mode 100644
index 0000000..342b278
--- /dev/null
+++ b/include/nvgpu/linux/dma.h
@@ -0,0 +1,38 @@
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#ifndef __NVGPU_LINUX_DMA_H__
18#define __NVGPU_LINUX_DMA_H__
19
20/**
21 * Functions used internally for building the backing SGTs for nvgpu_mems.
22 */
23
24
25int nvgpu_get_sgtable_attrs(struct gk20a *g, struct sg_table **sgt,
26 void *cpuva, u64 iova,
27 size_t size, unsigned long flags);
28
29int nvgpu_get_sgtable(struct gk20a *g, struct sg_table **sgt,
30 void *cpuva, u64 iova, size_t size);
31
32int nvgpu_get_sgtable_from_pages(struct gk20a *g, struct sg_table **sgt,
33 struct page **pages, u64 iova,
34 size_t size);
35
36void nvgpu_free_sgtable(struct gk20a *g, struct sg_table **sgt);
37
38#endif
diff --git a/include/nvgpu/linux/kmem.h b/include/nvgpu/linux/kmem.h
new file mode 100644
index 0000000..660aac9
--- /dev/null
+++ b/include/nvgpu/linux/kmem.h
@@ -0,0 +1,47 @@
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#ifndef __NVGPU_KMEM_LINUX_H__
18#define __NVGPU_KMEM_LINUX_H__
19
20struct gk20a;
21struct device;
22
23#ifdef CONFIG_NVGPU_TRACK_MEM_USAGE
24void *__nvgpu_track_vmalloc(struct gk20a *g, unsigned long size, void *ip);
25void *__nvgpu_track_vzalloc(struct gk20a *g, unsigned long size, void *ip);
26void *__nvgpu_track_kmalloc(struct gk20a *g, size_t size, void *ip);
27void *__nvgpu_track_kzalloc(struct gk20a *g, size_t size, void *ip);
28void *__nvgpu_track_kcalloc(struct gk20a *g, size_t n, size_t size, void *ip);
29void __nvgpu_track_vfree(struct gk20a *g, void *addr);
30void __nvgpu_track_kfree(struct gk20a *g, void *addr);
31#endif
32
33/**
34 * DOC: Linux pass through kmem implementation.
35 *
36 * These are the Linux implementations of the various kmem functions defined by
37 * nvgpu. This should not be included directly - instead include <nvgpu/kmem.h>.
38 */
39void *__nvgpu_kmalloc(struct gk20a *g, size_t size, void *ip);
40void *__nvgpu_kzalloc(struct gk20a *g, size_t size, void *ip);
41void *__nvgpu_kcalloc(struct gk20a *g, size_t n, size_t size, void *ip);
42void *__nvgpu_vmalloc(struct gk20a *g, unsigned long size, void *ip);
43void *__nvgpu_vzalloc(struct gk20a *g, unsigned long size, void *ip);
44void __nvgpu_kfree(struct gk20a *g, void *addr);
45void __nvgpu_vfree(struct gk20a *g, void *addr);
46
47#endif
diff --git a/include/nvgpu/linux/lock.h b/include/nvgpu/linux/lock.h
new file mode 100644
index 0000000..fbf26e9
--- /dev/null
+++ b/include/nvgpu/linux/lock.h
@@ -0,0 +1,81 @@
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#ifndef NVGPU_LOCK_LINUX_H
18#define NVGPU_LOCK_LINUX_H
19
20#include <linux/mutex.h>
21#include <linux/spinlock.h>
22
23struct nvgpu_mutex {
24 struct mutex mutex;
25};
26struct nvgpu_spinlock {
27 spinlock_t spinlock;
28};
29struct nvgpu_raw_spinlock {
30 raw_spinlock_t spinlock;
31};
32
33static inline int nvgpu_mutex_init(struct nvgpu_mutex *mutex)
34{
35 mutex_init(&mutex->mutex);
36 return 0;
37};
38static inline void nvgpu_mutex_acquire(struct nvgpu_mutex *mutex)
39{
40 mutex_lock(&mutex->mutex);
41};
42static inline void nvgpu_mutex_release(struct nvgpu_mutex *mutex)
43{
44 mutex_unlock(&mutex->mutex);
45};
46static inline int nvgpu_mutex_tryacquire(struct nvgpu_mutex *mutex)
47{
48 return mutex_trylock(&mutex->mutex);
49};
50static inline void nvgpu_mutex_destroy(struct nvgpu_mutex *mutex)
51{
52 mutex_destroy(&mutex->mutex);
53};
54
55static inline void nvgpu_spinlock_init(struct nvgpu_spinlock *spinlock)
56{
57 spin_lock_init(&spinlock->spinlock);
58};
59static inline void nvgpu_spinlock_acquire(struct nvgpu_spinlock *spinlock)
60{
61 spin_lock(&spinlock->spinlock);
62};
63static inline void nvgpu_spinlock_release(struct nvgpu_spinlock *spinlock)
64{
65 spin_unlock(&spinlock->spinlock);
66};
67
68static inline void nvgpu_raw_spinlock_init(struct nvgpu_raw_spinlock *spinlock)
69{
70 raw_spin_lock_init(&spinlock->spinlock);
71};
72static inline void nvgpu_raw_spinlock_acquire(struct nvgpu_raw_spinlock *spinlock)
73{
74 raw_spin_lock(&spinlock->spinlock);
75};
76static inline void nvgpu_raw_spinlock_release(struct nvgpu_raw_spinlock *spinlock)
77{
78 raw_spin_unlock(&spinlock->spinlock);
79};
80
81#endif /* NVGPU_LOCK_LINUX_H */
diff --git a/include/nvgpu/linux/nvgpu_mem.h b/include/nvgpu/linux/nvgpu_mem.h
new file mode 100644
index 0000000..e5f5031
--- /dev/null
+++ b/include/nvgpu/linux/nvgpu_mem.h
@@ -0,0 +1,89 @@
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#ifndef __NVGPU_LINUX_NVGPU_MEM_H__
18#define __NVGPU_LINUX_NVGPU_MEM_H__
19
20struct page;
21struct sg_table;
22struct scatterlist;
23struct nvgpu_sgt;
24
25struct gk20a;
26struct nvgpu_mem;
27struct nvgpu_gmmu_attrs;
28
29struct nvgpu_mem_priv {
30 struct page **pages;
31 struct sg_table *sgt;
32 unsigned long flags;
33};
34
35u64 nvgpu_mem_get_addr_sgl(struct gk20a *g, struct scatterlist *sgl);
36struct nvgpu_sgt *nvgpu_mem_linux_sgt_create(struct gk20a *g,
37 struct sg_table *sgt);
38void nvgpu_mem_linux_sgt_free(struct gk20a *g, struct nvgpu_sgt *sgt);
39struct nvgpu_sgt *nvgpu_linux_sgt_create(struct gk20a *g,
40 struct sg_table *sgt);
41/**
42 * __nvgpu_mem_create_from_pages - Create an nvgpu_mem from physical pages.
43 *
44 * @g - The GPU.
45 * @dest - nvgpu_mem to initialize.
46 * @pages - A list of page pointers.
47 * @nr_pages - The number of pages in @pages.
48 *
49 * Create a new nvgpu_mem struct from a pre-existing list of physical pages. The
50 * pages need not be contiguous (the underlying scatter gather list will help
51 * with that). However, note, this API will explicitly make it so that the GMMU
52 * mapping code bypasses SMMU access for the passed pages. This allows one to
53 * make mem_descs that describe MMIO regions or other non-DRAM things.
54 *
55 * This only works for SYSMEM (or other things like SYSMEM - basically just not
56 * VIDMEM). Also, this API is only available for Linux as it heavily depends on
57 * the notion of struct %page.
58 *
59 * The resulting nvgpu_mem should be released with the nvgpu_dma_free() or the
60 * nvgpu_dma_unmap_free() function depending on whether or not the resulting
61 * nvgpu_mem has been mapped. The underlying pages themselves must be cleaned up
62 * by the caller of this API.
63 *
64 * Returns 0 on success, or a relevant error otherwise.
65 */
66int __nvgpu_mem_create_from_pages(struct gk20a *g, struct nvgpu_mem *dest,
67 struct page **pages, int nr_pages);
68
69/**
70 * __nvgpu_mem_create_from_phys - Create an nvgpu_mem from physical mem.
71 *
72 * @g - The GPU.
73 * @dest - nvgpu_mem to initialize.
74 * @src_phys - start address of physical mem
75 * @nr_pages - The number of pages in phys.
76 *
77 * Create a new nvgpu_mem struct from a physical memory aperure. The physical
78 * memory aperture needs to be contiguous for requested @nr_pages. This API
79 * only works for SYSMEM.
80 *
81 * The resulting nvgpu_mem should be released with the nvgpu_dma_free() or the
82 * nvgpu_dma_unmap_free() function depending on whether or not the resulting
83 * nvgpu_mem has been mapped.
84 *
85 * Returns 0 on success, or a relevant error otherwise.
86 */
87int __nvgpu_mem_create_from_phys(struct gk20a *g, struct nvgpu_mem *dest,
88 u64 src_phys, int nr_pages);
89#endif
diff --git a/include/nvgpu/linux/nvlink.h b/include/nvgpu/linux/nvlink.h
new file mode 100644
index 0000000..550a897
--- /dev/null
+++ b/include/nvgpu/linux/nvlink.h
@@ -0,0 +1,31 @@
1/*
2 * Copyright (c) 2018, 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_LINUX_NVLINK_H__
24#define __NVGPU_LINUX_NVLINK_H__
25
26#ifdef CONFIG_TEGRA_NVLINK
27#include <linux/mutex.h>
28#include <linux/platform/tegra/tegra-nvlink.h>
29#endif
30
31#endif
diff --git a/include/nvgpu/linux/os_fence_android.h b/include/nvgpu/linux/os_fence_android.h
new file mode 100644
index 0000000..201b530
--- /dev/null
+++ b/include/nvgpu/linux/os_fence_android.h
@@ -0,0 +1,48 @@
1/*
2 * Copyright (c) 2018, 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_OS_FENCE_ANDROID_H__
24#define __NVGPU_OS_FENCE_ANDROID_H__
25
26struct gk20a;
27struct nvgpu_os_fence;
28struct sync_fence;
29struct channel_gk20a;
30
31struct sync_fence *nvgpu_get_sync_fence(struct nvgpu_os_fence *s);
32
33void nvgpu_os_fence_android_drop_ref(struct nvgpu_os_fence *s);
34
35int nvgpu_os_fence_sema_fdget(struct nvgpu_os_fence *fence_out,
36 struct channel_gk20a *c, int fd);
37
38void nvgpu_os_fence_init(struct nvgpu_os_fence *fence_out,
39 struct gk20a *g, const struct nvgpu_os_fence_ops *fops,
40 struct sync_fence *fence);
41
42void nvgpu_os_fence_android_install_fd(struct nvgpu_os_fence *s, int fd);
43
44int nvgpu_os_fence_syncpt_fdget(
45 struct nvgpu_os_fence *fence_out,
46 struct channel_gk20a *c, int fd);
47
48#endif /* __NVGPU_OS_FENCE_ANDROID_H__ */ \ No newline at end of file
diff --git a/include/nvgpu/linux/rwsem.h b/include/nvgpu/linux/rwsem.h
new file mode 100644
index 0000000..7d073d3
--- /dev/null
+++ b/include/nvgpu/linux/rwsem.h
@@ -0,0 +1,26 @@
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#ifndef __NVGPU_RWSEM_LINUX_H__
18#define __NVGPU_RWSEM_LINUX_H__
19
20#include <linux/rwsem.h>
21
22struct nvgpu_rwsem {
23 struct rw_semaphore rwsem;
24};
25
26#endif
diff --git a/include/nvgpu/linux/sim.h b/include/nvgpu/linux/sim.h
new file mode 100644
index 0000000..99c6348
--- /dev/null
+++ b/include/nvgpu/linux/sim.h
@@ -0,0 +1,38 @@
1/*
2 *
3 * nvgpu sim support
4 *
5 * Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms and conditions of the GNU General Public License,
9 * version 2, as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef __SIM_LINUX_H__
21#define __SIM_LINUX_H__
22
23struct platform_device;
24
25struct sim_nvgpu_linux {
26 struct sim_nvgpu sim;
27 struct resource *reg_mem;
28 void __iomem *regs;
29 void (*remove_support_linux)(struct gk20a *g);
30};
31
32void sim_writel(struct sim_nvgpu *sim, u32 r, u32 v);
33u32 sim_readl(struct sim_nvgpu *sim, u32 r);
34
35int nvgpu_init_sim_support_linux(struct gk20a *g,
36 struct platform_device *dev);
37void nvgpu_remove_sim_support_linux(struct gk20a *g);
38#endif
diff --git a/include/nvgpu/linux/sim_pci.h b/include/nvgpu/linux/sim_pci.h
new file mode 100644
index 0000000..b248f07
--- /dev/null
+++ b/include/nvgpu/linux/sim_pci.h
@@ -0,0 +1,26 @@
1/*
2 *
3 * nvgpu sim support pci
4 *
5 * Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms and conditions of the GNU General Public License,
9 * version 2, as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef __SIM_PCI_LINUX_H__
21#define __SIM_PCI_LINUX_H__
22
23int nvgpu_init_sim_support_linux_pci(struct gk20a *g);
24void nvgpu_remove_sim_support_linux_pci(struct gk20a *g);
25
26#endif
diff --git a/include/nvgpu/linux/thread.h b/include/nvgpu/linux/thread.h
new file mode 100644
index 0000000..1355319
--- /dev/null
+++ b/include/nvgpu/linux/thread.h
@@ -0,0 +1,29 @@
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#ifndef __NVGPU_THREAD_LINUX_H__
18#define __NVGPU_THREAD_LINUX_H__
19
20struct task_struct;
21
22struct nvgpu_thread {
23 struct task_struct *task;
24 bool running;
25 int (*fn)(void *);
26 void *data;
27};
28
29#endif /* __NVGPU_THREAD_LINUX_H__ */
diff --git a/include/nvgpu/linux/vm.h b/include/nvgpu/linux/vm.h
new file mode 100644
index 0000000..6f3beaa
--- /dev/null
+++ b/include/nvgpu/linux/vm.h
@@ -0,0 +1,92 @@
1/*
2 * Copyright (c) 2017-2018, 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#ifndef __COMMON_LINUX_VM_PRIV_H__
18#define __COMMON_LINUX_VM_PRIV_H__
19
20#include <nvgpu/types.h>
21
22#include <asm/cacheflush.h>
23
24/*
25 * Couple of places explicitly flush caches still. Any DMA buffer we allocate
26 * from within the GPU is writecombine and as a result does not need this but
27 * there seem to be exceptions.
28 */
29#ifdef CONFIG_ARM64
30#define outer_flush_range(a, b)
31#define __cpuc_flush_dcache_area __flush_dcache_area
32#endif
33
34struct sg_table;
35struct dma_buf;
36struct device;
37
38struct vm_gk20a;
39struct vm_gk20a_mapping_batch;
40struct nvgpu_vm_area;
41
42struct nvgpu_os_buffer {
43 struct dma_buf *dmabuf;
44 struct dma_buf_attachment *attachment;
45 struct device *dev;
46};
47
48struct nvgpu_mapped_buf_priv {
49 struct dma_buf *dmabuf;
50 struct dma_buf_attachment *attachment;
51 struct sg_table *sgt;
52};
53
54/* NVGPU_AS_MAP_BUFFER_FLAGS_DIRECT_KIND_CTRL must be set */
55int nvgpu_vm_map_linux(struct vm_gk20a *vm,
56 struct dma_buf *dmabuf,
57 u64 map_addr,
58 u32 flags,
59 u32 page_size,
60 s16 compr_kind,
61 s16 incompr_kind,
62 int rw_flag,
63 u64 buffer_offset,
64 u64 mapping_size,
65 struct vm_gk20a_mapping_batch *mapping_batch,
66 u64 *gpu_va);
67
68/*
69 * Notes:
70 * - Batch may be NULL if map op is not part of a batch.
71 * - NVGPU_AS_MAP_BUFFER_FLAGS_DIRECT_KIND_CTRL must be set
72 */
73int nvgpu_vm_map_buffer(struct vm_gk20a *vm,
74 int dmabuf_fd,
75 u64 *map_addr,
76 u32 flags, /* NVGPU_AS_MAP_BUFFER_FLAGS_ */
77 u32 page_size,
78 s16 compr_kind,
79 s16 incompr_kind,
80 u64 buffer_offset,
81 u64 mapping_size,
82 struct vm_gk20a_mapping_batch *batch);
83
84/* find buffer corresponding to va */
85int nvgpu_vm_find_buf(struct vm_gk20a *vm, u64 gpu_va,
86 struct dma_buf **dmabuf,
87 u64 *offset);
88
89enum nvgpu_aperture gk20a_dmabuf_aperture(struct gk20a *g,
90 struct dma_buf *dmabuf);
91
92#endif