summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/common/posix/nvgpu.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/nvgpu/common/posix/nvgpu.c')
-rw-r--r--drivers/gpu/nvgpu/common/posix/nvgpu.c137
1 files changed, 137 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/common/posix/nvgpu.c b/drivers/gpu/nvgpu/common/posix/nvgpu.c
new file mode 100644
index 00000000..6f2a5fe9
--- /dev/null
+++ b/drivers/gpu/nvgpu/common/posix/nvgpu.c
@@ -0,0 +1,137 @@
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/bug.h>
28#include <nvgpu/types.h>
29#include <nvgpu/atomic.h>
30#include <nvgpu/nvgpu_common.h>
31#include <nvgpu/os_sched.h>
32
33#include <nvgpu/posix/probe.h>
34
35#include "os_posix.h"
36
37#include "gk20a/gk20a.h"
38
39void nvgpu_wait_for_deferred_interrupts(struct gk20a *g)
40{
41 /*
42 * No interrupts in userspace so nothing to wait for.
43 */
44}
45
46int 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
56int 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/*
71 * Somewhat meaningless in userspace...
72 */
73void nvgpu_kernel_restart(void *cmd)
74{
75 BUG();
76}
77
78/*
79 * We have no runtime PM stuff in userspace so these are really just noops.
80 */
81void gk20a_busy_noresume(struct gk20a *g)
82{
83}
84
85void gk20a_idle_nosuspend(struct gk20a *g)
86{
87}
88
89int gk20a_busy(struct gk20a *g)
90{
91 nvgpu_atomic_inc(&g->usage_count);
92
93 return 0;
94}
95
96void gk20a_idle(struct gk20a *g)
97{
98 nvgpu_atomic_dec(&g->usage_count);
99}
100
101/*
102 * This function aims to initialize enough stuff to make unit testing worth
103 * while. There are several interfaces and APIs that rely on the struct gk20a's
104 * state in order to function: logging, for example, but there are many other
105 * things, too.
106 *
107 * Initialize as much of that as possible here. This is meant to be equivalent
108 * to the kernel space driver's probe function.
109 */
110struct gk20a *nvgpu_posix_probe(void)
111{
112 struct gk20a *g;
113 struct nvgpu_os_posix *p;
114 int err;
115
116 p = malloc(sizeof(*p));
117 if (p == NULL)
118 return NULL;
119
120 g = &p->g;
121
122 err = nvgpu_kmem_init(g);
123 if (err != 0)
124 goto fail;
125
126 return g;
127
128fail:
129 free(p);
130
131 return NULL;
132}
133
134void nvgpu_posix_cleanup(struct gk20a *g)
135{
136 nvgpu_kmem_fini(g, 0);
137}