diff options
author | Arto Merilainen <amerilainen@nvidia.com> | 2014-03-19 03:38:25 -0400 |
---|---|---|
committer | Dan Willemsen <dwillemsen@nvidia.com> | 2015-03-18 15:08:53 -0400 |
commit | a9785995d5f22aaeb659285f8aeb64d8b56982e0 (patch) | |
tree | cc75f75bcf43db316a002a7a240b81f299bf6d7f /drivers/gpu/nvgpu/gk20a/ctrl_gk20a.c | |
parent | 61efaf843c22b85424036ec98015121c08f5f16c (diff) |
gpu: nvgpu: Add NVIDIA GPU Driver
This patch moves the NVIDIA GPU driver to a new location.
Bug 1482562
Change-Id: I24293810b9d0f1504fd9be00135e21dad656ccb6
Signed-off-by: Arto Merilainen <amerilainen@nvidia.com>
Reviewed-on: http://git-master/r/383722
Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/gk20a/ctrl_gk20a.c')
-rw-r--r-- | drivers/gpu/nvgpu/gk20a/ctrl_gk20a.c | 240 |
1 files changed, 240 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/gk20a/ctrl_gk20a.c b/drivers/gpu/nvgpu/gk20a/ctrl_gk20a.c new file mode 100644 index 00000000..9128959f --- /dev/null +++ b/drivers/gpu/nvgpu/gk20a/ctrl_gk20a.c | |||
@@ -0,0 +1,240 @@ | |||
1 | /* | ||
2 | * GK20A Ctrl | ||
3 | * | ||
4 | * Copyright (c) 2011-2014, NVIDIA Corporation. All rights reserved. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms and conditions of the GNU General Public License, | ||
8 | * version 2, as published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | * more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | #include <linux/highmem.h> | ||
20 | #include <linux/cdev.h> | ||
21 | #include <linux/nvhost_gpu_ioctl.h> | ||
22 | |||
23 | #include "gk20a.h" | ||
24 | |||
25 | int gk20a_ctrl_dev_open(struct inode *inode, struct file *filp) | ||
26 | { | ||
27 | int err; | ||
28 | struct gk20a *g; | ||
29 | |||
30 | gk20a_dbg_fn(""); | ||
31 | |||
32 | g = container_of(inode->i_cdev, | ||
33 | struct gk20a, ctrl.cdev); | ||
34 | |||
35 | filp->private_data = g->dev; | ||
36 | |||
37 | err = gk20a_get_client(g); | ||
38 | if (err) { | ||
39 | gk20a_dbg_fn("fail to get channel!"); | ||
40 | return err; | ||
41 | } | ||
42 | |||
43 | return 0; | ||
44 | } | ||
45 | |||
46 | int gk20a_ctrl_dev_release(struct inode *inode, struct file *filp) | ||
47 | { | ||
48 | struct platform_device *dev = filp->private_data; | ||
49 | |||
50 | gk20a_dbg_fn(""); | ||
51 | |||
52 | gk20a_put_client(get_gk20a(dev)); | ||
53 | return 0; | ||
54 | } | ||
55 | |||
56 | static long | ||
57 | gk20a_ctrl_ioctl_gpu_characteristics( | ||
58 | struct gk20a *g, | ||
59 | struct nvhost_gpu_get_characteristics *request) | ||
60 | { | ||
61 | struct nvhost_gpu_characteristics *pgpu = &g->gpu_characteristics; | ||
62 | long err = 0; | ||
63 | |||
64 | if (request->gpu_characteristics_buf_size > 0) { | ||
65 | size_t write_size = sizeof(*pgpu); | ||
66 | |||
67 | if (write_size > request->gpu_characteristics_buf_size) | ||
68 | write_size = request->gpu_characteristics_buf_size; | ||
69 | |||
70 | err = copy_to_user((void __user *)(uintptr_t) | ||
71 | request->gpu_characteristics_buf_addr, | ||
72 | pgpu, write_size); | ||
73 | } | ||
74 | |||
75 | if (err == 0) | ||
76 | request->gpu_characteristics_buf_size = sizeof(*pgpu); | ||
77 | |||
78 | return err; | ||
79 | } | ||
80 | |||
81 | long gk20a_ctrl_dev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) | ||
82 | { | ||
83 | struct platform_device *dev = filp->private_data; | ||
84 | struct gk20a *g = get_gk20a(dev); | ||
85 | struct nvhost_gpu_zcull_get_ctx_size_args *get_ctx_size_args; | ||
86 | struct nvhost_gpu_zcull_get_info_args *get_info_args; | ||
87 | struct nvhost_gpu_zbc_set_table_args *set_table_args; | ||
88 | struct nvhost_gpu_zbc_query_table_args *query_table_args; | ||
89 | u8 buf[NVHOST_GPU_IOCTL_MAX_ARG_SIZE]; | ||
90 | struct gr_zcull_info *zcull_info; | ||
91 | struct zbc_entry *zbc_val; | ||
92 | struct zbc_query_params *zbc_tbl; | ||
93 | int i, err = 0; | ||
94 | |||
95 | gk20a_dbg_fn(""); | ||
96 | |||
97 | if ((_IOC_TYPE(cmd) != NVHOST_GPU_IOCTL_MAGIC) || | ||
98 | (_IOC_NR(cmd) == 0) || | ||
99 | (_IOC_NR(cmd) > NVHOST_GPU_IOCTL_LAST)) | ||
100 | return -EFAULT; | ||
101 | |||
102 | BUG_ON(_IOC_SIZE(cmd) > NVHOST_GPU_IOCTL_MAX_ARG_SIZE); | ||
103 | |||
104 | if (_IOC_DIR(cmd) & _IOC_WRITE) { | ||
105 | if (copy_from_user(buf, (void __user *)arg, _IOC_SIZE(cmd))) | ||
106 | return -EFAULT; | ||
107 | } | ||
108 | |||
109 | if (!g->gr.sw_ready) { | ||
110 | err = gk20a_busy(g->dev); | ||
111 | if (err) | ||
112 | return err; | ||
113 | |||
114 | gk20a_idle(g->dev); | ||
115 | } | ||
116 | |||
117 | switch (cmd) { | ||
118 | case NVHOST_GPU_IOCTL_ZCULL_GET_CTX_SIZE: | ||
119 | get_ctx_size_args = (struct nvhost_gpu_zcull_get_ctx_size_args *)buf; | ||
120 | |||
121 | get_ctx_size_args->size = gr_gk20a_get_ctxsw_zcull_size(g, &g->gr); | ||
122 | |||
123 | break; | ||
124 | case NVHOST_GPU_IOCTL_ZCULL_GET_INFO: | ||
125 | get_info_args = (struct nvhost_gpu_zcull_get_info_args *)buf; | ||
126 | |||
127 | memset(get_info_args, 0, sizeof(struct nvhost_gpu_zcull_get_info_args)); | ||
128 | |||
129 | zcull_info = kzalloc(sizeof(struct gr_zcull_info), GFP_KERNEL); | ||
130 | if (zcull_info == NULL) | ||
131 | return -ENOMEM; | ||
132 | |||
133 | err = gr_gk20a_get_zcull_info(g, &g->gr, zcull_info); | ||
134 | if (err) { | ||
135 | kfree(zcull_info); | ||
136 | break; | ||
137 | } | ||
138 | |||
139 | get_info_args->width_align_pixels = zcull_info->width_align_pixels; | ||
140 | get_info_args->height_align_pixels = zcull_info->height_align_pixels; | ||
141 | get_info_args->pixel_squares_by_aliquots = zcull_info->pixel_squares_by_aliquots; | ||
142 | get_info_args->aliquot_total = zcull_info->aliquot_total; | ||
143 | get_info_args->region_byte_multiplier = zcull_info->region_byte_multiplier; | ||
144 | get_info_args->region_header_size = zcull_info->region_header_size; | ||
145 | get_info_args->subregion_header_size = zcull_info->subregion_header_size; | ||
146 | get_info_args->subregion_width_align_pixels = zcull_info->subregion_width_align_pixels; | ||
147 | get_info_args->subregion_height_align_pixels = zcull_info->subregion_height_align_pixels; | ||
148 | get_info_args->subregion_count = zcull_info->subregion_count; | ||
149 | |||
150 | kfree(zcull_info); | ||
151 | break; | ||
152 | case NVHOST_GPU_IOCTL_ZBC_SET_TABLE: | ||
153 | set_table_args = (struct nvhost_gpu_zbc_set_table_args *)buf; | ||
154 | |||
155 | zbc_val = kzalloc(sizeof(struct zbc_entry), GFP_KERNEL); | ||
156 | if (zbc_val == NULL) | ||
157 | return -ENOMEM; | ||
158 | |||
159 | zbc_val->format = set_table_args->format; | ||
160 | zbc_val->type = set_table_args->type; | ||
161 | |||
162 | switch (zbc_val->type) { | ||
163 | case GK20A_ZBC_TYPE_COLOR: | ||
164 | for (i = 0; i < GK20A_ZBC_COLOR_VALUE_SIZE; i++) { | ||
165 | zbc_val->color_ds[i] = set_table_args->color_ds[i]; | ||
166 | zbc_val->color_l2[i] = set_table_args->color_l2[i]; | ||
167 | } | ||
168 | break; | ||
169 | case GK20A_ZBC_TYPE_DEPTH: | ||
170 | zbc_val->depth = set_table_args->depth; | ||
171 | break; | ||
172 | default: | ||
173 | err = -EINVAL; | ||
174 | } | ||
175 | |||
176 | if (!err) { | ||
177 | gk20a_busy(dev); | ||
178 | err = gk20a_gr_zbc_set_table(g, &g->gr, zbc_val); | ||
179 | gk20a_idle(dev); | ||
180 | } | ||
181 | |||
182 | if (zbc_val) | ||
183 | kfree(zbc_val); | ||
184 | break; | ||
185 | case NVHOST_GPU_IOCTL_ZBC_QUERY_TABLE: | ||
186 | query_table_args = (struct nvhost_gpu_zbc_query_table_args *)buf; | ||
187 | |||
188 | zbc_tbl = kzalloc(sizeof(struct zbc_query_params), GFP_KERNEL); | ||
189 | if (zbc_tbl == NULL) | ||
190 | return -ENOMEM; | ||
191 | |||
192 | zbc_tbl->type = query_table_args->type; | ||
193 | zbc_tbl->index_size = query_table_args->index_size; | ||
194 | |||
195 | err = gr_gk20a_query_zbc(g, &g->gr, zbc_tbl); | ||
196 | |||
197 | if (!err) { | ||
198 | switch (zbc_tbl->type) { | ||
199 | case GK20A_ZBC_TYPE_COLOR: | ||
200 | for (i = 0; i < GK20A_ZBC_COLOR_VALUE_SIZE; i++) { | ||
201 | query_table_args->color_ds[i] = zbc_tbl->color_ds[i]; | ||
202 | query_table_args->color_l2[i] = zbc_tbl->color_l2[i]; | ||
203 | } | ||
204 | break; | ||
205 | case GK20A_ZBC_TYPE_DEPTH: | ||
206 | query_table_args->depth = zbc_tbl->depth; | ||
207 | break; | ||
208 | case GK20A_ZBC_TYPE_INVALID: | ||
209 | query_table_args->index_size = zbc_tbl->index_size; | ||
210 | break; | ||
211 | default: | ||
212 | err = -EINVAL; | ||
213 | } | ||
214 | if (!err) { | ||
215 | query_table_args->format = zbc_tbl->format; | ||
216 | query_table_args->ref_cnt = zbc_tbl->ref_cnt; | ||
217 | } | ||
218 | } | ||
219 | |||
220 | if (zbc_tbl) | ||
221 | kfree(zbc_tbl); | ||
222 | break; | ||
223 | |||
224 | case NVHOST_GPU_IOCTL_GET_CHARACTERISTICS: | ||
225 | err = gk20a_ctrl_ioctl_gpu_characteristics( | ||
226 | g, (struct nvhost_gpu_get_characteristics *)buf); | ||
227 | break; | ||
228 | |||
229 | default: | ||
230 | gk20a_err(dev_from_gk20a(g), "unrecognized gpu ioctl cmd: 0x%x", cmd); | ||
231 | err = -ENOTTY; | ||
232 | break; | ||
233 | } | ||
234 | |||
235 | if ((err == 0) && (_IOC_DIR(cmd) & _IOC_READ)) | ||
236 | err = copy_to_user((void __user *)arg, buf, _IOC_SIZE(cmd)); | ||
237 | |||
238 | return err; | ||
239 | } | ||
240 | |||