summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/os/posix/nvgpu.c
diff options
context:
space:
mode:
authorAlex Waterman <alexw@nvidia.com>2018-08-15 19:32:37 -0400
committermobile promotions <svcmobile_promotions@nvidia.com>2018-08-17 16:54:25 -0400
commitb15624b39b9b19ba139776e2a917bcd4e361c01e (patch)
tree0944c60323eb7565cfa84759abc16d69600d0dd7 /drivers/gpu/nvgpu/os/posix/nvgpu.c
parent9feeae658acc2c997ef05b669ace8a0621e68ebb (diff)
gpu: nvgpu: posix: move the posix dir to os
Since the posix code is supporting a particular OS this code should belong under os/ not common/. Change-Id: Idf5f75b8ab9d614c9dd43ea23dab8df3c346c0ef Signed-off-by: Alex Waterman <alexw@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1800658 Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/os/posix/nvgpu.c')
-rw-r--r--drivers/gpu/nvgpu/os/posix/nvgpu.c144
1 files changed, 144 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/os/posix/nvgpu.c b/drivers/gpu/nvgpu/os/posix/nvgpu.c
new file mode 100644
index 00000000..a275f2de
--- /dev/null
+++ b/drivers/gpu/nvgpu/os/posix/nvgpu.c
@@ -0,0 +1,144 @@
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
70void __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 */
80void 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 */
88void gk20a_busy_noresume(struct gk20a *g)
89{
90}
91
92void gk20a_idle_nosuspend(struct gk20a *g)
93{
94}
95
96int gk20a_busy(struct gk20a *g)
97{
98 nvgpu_atomic_inc(&g->usage_count);
99
100 return 0;
101}
102
103void gk20a_idle(struct gk20a *g)
104{
105 nvgpu_atomic_dec(&g->usage_count);
106}
107
108/*
109 * This function aims to initialize enough stuff to make unit testing worth
110 * while. There are several interfaces and APIs that rely on the struct gk20a's
111 * state in order to function: logging, for example, but there are many other
112 * things, too.
113 *
114 * Initialize as much of that as possible here. This is meant to be equivalent
115 * to the kernel space driver's probe function.
116 */
117struct gk20a *nvgpu_posix_probe(void)
118{
119 struct gk20a *g;
120 struct nvgpu_os_posix *p;
121 int err;
122
123 p = malloc(sizeof(*p));
124 if (p == NULL)
125 return NULL;
126
127 g = &p->g;
128
129 err = nvgpu_kmem_init(g);
130 if (err != 0)
131 goto fail;
132
133 return g;
134
135fail:
136 free(p);
137
138 return NULL;
139}
140
141void nvgpu_posix_cleanup(struct gk20a *g)
142{
143 nvgpu_kmem_fini(g, 0);
144}