diff options
author | Joshua Bakita <bakitajoshua@gmail.com> | 2023-06-28 18:24:25 -0400 |
---|---|---|
committer | Joshua Bakita <bakitajoshua@gmail.com> | 2023-06-28 18:24:25 -0400 |
commit | 01e6fac4d61fdd7fff5433942ec93fc2ea1e4df1 (patch) | |
tree | 4ef34501728a087be24f4ba0af90f91486bf780b /include/os/posix/nvgpu.c | |
parent | 306a03d18b305e4e573be3b2931978fa10679eb9 (diff) |
Include nvgpu headers
These are needed to build on NVIDIA's Jetson boards for the time
being. Only a couple structs are required, so it should be fairly
easy to remove this dependency at some point in the future.
Diffstat (limited to 'include/os/posix/nvgpu.c')
-rw-r--r-- | include/os/posix/nvgpu.c | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/include/os/posix/nvgpu.c b/include/os/posix/nvgpu.c new file mode 100644 index 0000000..e485ed7 --- /dev/null +++ b/include/os/posix/nvgpu.c | |||
@@ -0,0 +1,149 @@ | |||
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 | #include <unistd.h> | ||
24 | #include <stdlib.h> | ||
25 | #include <pthread.h> | ||
26 | |||
27 | #include <nvgpu/gk20a.h> | ||
28 | #include <nvgpu/bug.h> | ||
29 | #include <nvgpu/types.h> | ||
30 | #include <nvgpu/atomic.h> | ||
31 | #include <nvgpu/nvgpu_common.h> | ||
32 | #include <nvgpu/os_sched.h> | ||
33 | #include <nvgpu/gk20a.h> | ||
34 | |||
35 | #include <nvgpu/posix/probe.h> | ||
36 | |||
37 | #include "os_posix.h" | ||
38 | |||
39 | void nvgpu_wait_for_deferred_interrupts(struct gk20a *g) | ||
40 | { | ||
41 | /* | ||
42 | * No interrupts in userspace so nothing to wait for. | ||
43 | */ | ||
44 | } | ||
45 | |||
46 | int nvgpu_current_pid(struct gk20a *g) | ||
47 | { | ||
48 | /* | ||
49 | * In the kernel this gets us the PID of the calling process for IOCTLs. | ||
50 | * But since we are in userspace this doesn't quite mean the same thing. | ||
51 | * This simply returns the PID of the currently running process. | ||
52 | */ | ||
53 | return (int)getpid(); | ||
54 | } | ||
55 | |||
56 | int nvgpu_current_tid(struct gk20a *g) | ||
57 | { | ||
58 | /* | ||
59 | * In POSIX thread ID is not the same as a process ID. In Linux threads | ||
60 | * and processes are represented by the same thing, but userspace can't | ||
61 | * really rely on that. | ||
62 | * | ||
63 | * We can, however, get a pthread_t for a given thread. But this | ||
64 | * pthread_t need not have any relation to the underlying system's | ||
65 | * representation of "threads". | ||
66 | */ | ||
67 | return (int)pthread_self(); | ||
68 | } | ||
69 | |||
70 | void __nvgpu_print_current(struct gk20a *g, const char *func_name, int line, | ||
71 | void *ctx, enum nvgpu_log_type type) | ||
72 | { | ||
73 | __nvgpu_log_msg(g, func_name, line, type, | ||
74 | "Current process: (nvgpu userspace)"); | ||
75 | } | ||
76 | |||
77 | /* | ||
78 | * Somewhat meaningless in userspace... | ||
79 | */ | ||
80 | void nvgpu_kernel_restart(void *cmd) | ||
81 | { | ||
82 | BUG(); | ||
83 | } | ||
84 | |||
85 | /* | ||
86 | * We have no runtime PM stuff in userspace so these are really just noops. | ||
87 | */ | ||
88 | void gk20a_busy_noresume(struct gk20a *g) | ||
89 | { | ||
90 | } | ||
91 | |||
92 | void gk20a_idle_nosuspend(struct gk20a *g) | ||
93 | { | ||
94 | } | ||
95 | |||
96 | bool gk20a_check_poweron(struct gk20a *g) | ||
97 | { | ||
98 | return false; | ||
99 | } | ||
100 | |||
101 | int gk20a_busy(struct gk20a *g) | ||
102 | { | ||
103 | nvgpu_atomic_inc(&g->usage_count); | ||
104 | |||
105 | return 0; | ||
106 | } | ||
107 | |||
108 | void gk20a_idle(struct gk20a *g) | ||
109 | { | ||
110 | nvgpu_atomic_dec(&g->usage_count); | ||
111 | } | ||
112 | |||
113 | /* | ||
114 | * This function aims to initialize enough stuff to make unit testing worth | ||
115 | * while. There are several interfaces and APIs that rely on the struct gk20a's | ||
116 | * state in order to function: logging, for example, but there are many other | ||
117 | * things, too. | ||
118 | * | ||
119 | * Initialize as much of that as possible here. This is meant to be equivalent | ||
120 | * to the kernel space driver's probe function. | ||
121 | */ | ||
122 | struct gk20a *nvgpu_posix_probe(void) | ||
123 | { | ||
124 | struct gk20a *g; | ||
125 | struct nvgpu_os_posix *p; | ||
126 | int err; | ||
127 | |||
128 | p = malloc(sizeof(*p)); | ||
129 | if (p == NULL) | ||
130 | return NULL; | ||
131 | |||
132 | g = &p->g; | ||
133 | |||
134 | err = nvgpu_kmem_init(g); | ||
135 | if (err != 0) | ||
136 | goto fail; | ||
137 | |||
138 | return g; | ||
139 | |||
140 | fail: | ||
141 | free(p); | ||
142 | |||
143 | return NULL; | ||
144 | } | ||
145 | |||
146 | void nvgpu_posix_cleanup(struct gk20a *g) | ||
147 | { | ||
148 | nvgpu_kmem_fini(g, 0); | ||
149 | } | ||