summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/gk20a/cde_gk20a.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/nvgpu/gk20a/cde_gk20a.c')
-rw-r--r--drivers/gpu/nvgpu/gk20a/cde_gk20a.c75
1 files changed, 21 insertions, 54 deletions
diff --git a/drivers/gpu/nvgpu/gk20a/cde_gk20a.c b/drivers/gpu/nvgpu/gk20a/cde_gk20a.c
index ea01914c..fb368fda 100644
--- a/drivers/gpu/nvgpu/gk20a/cde_gk20a.c
+++ b/drivers/gpu/nvgpu/gk20a/cde_gk20a.c
@@ -46,15 +46,11 @@ static struct gk20a_cde_ctx *gk20a_cde_allocate_context(struct gk20a *g);
46 46
47static void gk20a_deinit_cde_img(struct gk20a_cde_ctx *cde_ctx) 47static void gk20a_deinit_cde_img(struct gk20a_cde_ctx *cde_ctx)
48{ 48{
49 struct device *dev = &cde_ctx->pdev->dev;
50 int i; 49 int i;
51 50
52 for (i = 0; i < cde_ctx->num_bufs; i++) { 51 for (i = 0; i < cde_ctx->num_bufs; i++) {
53 struct gk20a_cde_mem_desc *mem = cde_ctx->mem + i; 52 struct mem_desc *mem = cde_ctx->mem + i;
54 gk20a_gmmu_unmap(cde_ctx->vm, mem->gpu_va, mem->num_bytes, 1); 53 gk20a_gmmu_unmap_free(cde_ctx->vm, mem);
55 gk20a_free_sgtable(&mem->sgt);
56 dma_free_writecombine(dev, mem->num_bytes, mem->cpuva,
57 mem->iova);
58 } 54 }
59 55
60 kfree(cde_ctx->init_convert_cmd); 56 kfree(cde_ctx->init_convert_cmd);
@@ -225,8 +221,7 @@ static int gk20a_init_cde_buf(struct gk20a_cde_ctx *cde_ctx,
225 const struct firmware *img, 221 const struct firmware *img,
226 struct gk20a_cde_hdr_buf *buf) 222 struct gk20a_cde_hdr_buf *buf)
227{ 223{
228 struct device *dev = &cde_ctx->pdev->dev; 224 struct mem_desc *mem;
229 struct gk20a_cde_mem_desc *mem;
230 int err; 225 int err;
231 226
232 /* check that the file can hold the buf */ 227 /* check that the file can hold the buf */
@@ -246,49 +241,21 @@ static int gk20a_init_cde_buf(struct gk20a_cde_ctx *cde_ctx,
246 241
247 /* allocate buf */ 242 /* allocate buf */
248 mem = cde_ctx->mem + cde_ctx->num_bufs; 243 mem = cde_ctx->mem + cde_ctx->num_bufs;
249 mem->num_bytes = buf->num_bytes; 244 err = gk20a_gmmu_alloc_map(cde_ctx->vm, buf->num_bytes, mem);
250 mem->cpuva = dma_alloc_writecombine(dev, mem->num_bytes, &mem->iova, 245 if (err) {
251 GFP_KERNEL);
252 if (!mem->cpuva) {
253 gk20a_warn(&cde_ctx->pdev->dev, "cde: could not allocate device memory. buffer idx = %d", 246 gk20a_warn(&cde_ctx->pdev->dev, "cde: could not allocate device memory. buffer idx = %d",
254 cde_ctx->num_bufs); 247 cde_ctx->num_bufs);
255 return -ENOMEM; 248 return -ENOMEM;
256 } 249 }
257 250
258 err = gk20a_get_sgtable(dev, &mem->sgt, mem->cpuva, mem->iova,
259 mem->num_bytes);
260 if (err) {
261 gk20a_warn(&cde_ctx->pdev->dev, "cde: could not get sg table. buffer idx = %d",
262 cde_ctx->num_bufs);
263 err = -ENOMEM;
264 goto err_get_sgtable;
265 }
266
267 mem->gpu_va = gk20a_gmmu_map(cde_ctx->vm, &mem->sgt, mem->num_bytes,
268 0,
269 gk20a_mem_flag_none);
270 if (!mem->gpu_va) {
271 gk20a_warn(&cde_ctx->pdev->dev, "cde: could not map buffer to gpuva. buffer idx = %d",
272 cde_ctx->num_bufs);
273 err = -ENOMEM;
274 goto err_map_buffer;
275 }
276
277 /* copy the content */ 251 /* copy the content */
278 if (buf->data_byte_offset != 0) 252 if (buf->data_byte_offset != 0)
279 memcpy(mem->cpuva, img->data + buf->data_byte_offset, 253 memcpy(mem->cpu_va, img->data + buf->data_byte_offset,
280 buf->num_bytes); 254 buf->num_bytes);
281 255
282 cde_ctx->num_bufs++; 256 cde_ctx->num_bufs++;
283 257
284 return 0; 258 return 0;
285
286err_map_buffer:
287 gk20a_free_sgtable(&mem->sgt);
288 kfree(mem->sgt);
289err_get_sgtable:
290 dma_free_writecombine(dev, mem->num_bytes, &mem->cpuva, mem->iova);
291 return err;
292} 259}
293 260
294static int gk20a_replace_data(struct gk20a_cde_ctx *cde_ctx, void *target, 261static int gk20a_replace_data(struct gk20a_cde_ctx *cde_ctx, void *target,
@@ -340,8 +307,8 @@ static int gk20a_init_cde_replace(struct gk20a_cde_ctx *cde_ctx,
340 const struct firmware *img, 307 const struct firmware *img,
341 struct gk20a_cde_hdr_replace *replace) 308 struct gk20a_cde_hdr_replace *replace)
342{ 309{
343 struct gk20a_cde_mem_desc *source_mem; 310 struct mem_desc *source_mem;
344 struct gk20a_cde_mem_desc *target_mem; 311 struct mem_desc *target_mem;
345 u32 *target_mem_ptr; 312 u32 *target_mem_ptr;
346 u64 vaddr; 313 u64 vaddr;
347 int err; 314 int err;
@@ -356,15 +323,15 @@ static int gk20a_init_cde_replace(struct gk20a_cde_ctx *cde_ctx,
356 323
357 source_mem = cde_ctx->mem + replace->source_buf; 324 source_mem = cde_ctx->mem + replace->source_buf;
358 target_mem = cde_ctx->mem + replace->target_buf; 325 target_mem = cde_ctx->mem + replace->target_buf;
359 target_mem_ptr = target_mem->cpuva; 326 target_mem_ptr = target_mem->cpu_va;
360 327
361 if (source_mem->num_bytes < (replace->source_byte_offset + 3) || 328 if (source_mem->size < (replace->source_byte_offset + 3) ||
362 target_mem->num_bytes < (replace->target_byte_offset + 3)) { 329 target_mem->size < (replace->target_byte_offset + 3)) {
363 gk20a_warn(&cde_ctx->pdev->dev, "cde: invalid buffer offsets. target_buf_offs=%lld, source_buf_offs=%lld, source_buf_size=%zu, dest_buf_size=%zu", 330 gk20a_warn(&cde_ctx->pdev->dev, "cde: invalid buffer offsets. target_buf_offs=%lld, source_buf_offs=%lld, source_buf_size=%zu, dest_buf_size=%zu",
364 replace->target_byte_offset, 331 replace->target_byte_offset,
365 replace->source_byte_offset, 332 replace->source_byte_offset,
366 source_mem->num_bytes, 333 source_mem->size,
367 target_mem->num_bytes); 334 target_mem->size);
368 return -EINVAL; 335 return -EINVAL;
369 } 336 }
370 337
@@ -390,7 +357,7 @@ static int gk20a_init_cde_replace(struct gk20a_cde_ctx *cde_ctx,
390static int gk20a_cde_patch_params(struct gk20a_cde_ctx *cde_ctx) 357static int gk20a_cde_patch_params(struct gk20a_cde_ctx *cde_ctx)
391{ 358{
392 struct gk20a *g = cde_ctx->g; 359 struct gk20a *g = cde_ctx->g;
393 struct gk20a_cde_mem_desc *target_mem; 360 struct mem_desc *target_mem;
394 u32 *target_mem_ptr; 361 u32 *target_mem_ptr;
395 u64 new_data; 362 u64 new_data;
396 int user_id = 0, i, err; 363 int user_id = 0, i, err;
@@ -398,7 +365,7 @@ static int gk20a_cde_patch_params(struct gk20a_cde_ctx *cde_ctx)
398 for (i = 0; i < cde_ctx->num_params; i++) { 365 for (i = 0; i < cde_ctx->num_params; i++) {
399 struct gk20a_cde_hdr_param *param = cde_ctx->params + i; 366 struct gk20a_cde_hdr_param *param = cde_ctx->params + i;
400 target_mem = cde_ctx->mem + param->target_buf; 367 target_mem = cde_ctx->mem + param->target_buf;
401 target_mem_ptr = target_mem->cpuva; 368 target_mem_ptr = target_mem->cpu_va;
402 target_mem_ptr += (param->target_byte_offset / sizeof(u32)); 369 target_mem_ptr += (param->target_byte_offset / sizeof(u32));
403 370
404 switch (param->id) { 371 switch (param->id) {
@@ -472,7 +439,7 @@ static int gk20a_init_cde_param(struct gk20a_cde_ctx *cde_ctx,
472 const struct firmware *img, 439 const struct firmware *img,
473 struct gk20a_cde_hdr_param *param) 440 struct gk20a_cde_hdr_param *param)
474{ 441{
475 struct gk20a_cde_mem_desc *target_mem; 442 struct mem_desc *target_mem;
476 443
477 if (param->target_buf >= cde_ctx->num_bufs) { 444 if (param->target_buf >= cde_ctx->num_bufs) {
478 gk20a_warn(&cde_ctx->pdev->dev, "cde: invalid buffer parameter. param idx = %d, target_buf=%u, num_bufs=%u", 445 gk20a_warn(&cde_ctx->pdev->dev, "cde: invalid buffer parameter. param idx = %d, target_buf=%u, num_bufs=%u",
@@ -482,10 +449,10 @@ static int gk20a_init_cde_param(struct gk20a_cde_ctx *cde_ctx,
482 } 449 }
483 450
484 target_mem = cde_ctx->mem + param->target_buf; 451 target_mem = cde_ctx->mem + param->target_buf;
485 if (target_mem->num_bytes < (param->target_byte_offset + 3)) { 452 if (target_mem->size< (param->target_byte_offset + 3)) {
486 gk20a_warn(&cde_ctx->pdev->dev, "cde: invalid buffer parameter. param idx = %d, target_buf_offs=%lld, target_buf_size=%zu", 453 gk20a_warn(&cde_ctx->pdev->dev, "cde: invalid buffer parameter. param idx = %d, target_buf_offs=%lld, target_buf_size=%zu",
487 cde_ctx->num_params, param->target_byte_offset, 454 cde_ctx->num_params, param->target_byte_offset,
488 target_mem->num_bytes); 455 target_mem->size);
489 return -EINVAL; 456 return -EINVAL;
490 } 457 }
491 458
@@ -563,7 +530,7 @@ static int gk20a_init_cde_command(struct gk20a_cde_ctx *cde_ctx,
563 530
564 gpfifo_elem = *gpfifo; 531 gpfifo_elem = *gpfifo;
565 for (i = 0; i < num_elems; i++, cmd_elem++, gpfifo_elem++) { 532 for (i = 0; i < num_elems; i++, cmd_elem++, gpfifo_elem++) {
566 struct gk20a_cde_mem_desc *target_mem; 533 struct mem_desc *target_mem;
567 534
568 /* validate the current entry */ 535 /* validate the current entry */
569 if (cmd_elem->target_buf >= cde_ctx->num_bufs) { 536 if (cmd_elem->target_buf >= cde_ctx->num_bufs) {
@@ -573,10 +540,10 @@ static int gk20a_init_cde_command(struct gk20a_cde_ctx *cde_ctx,
573 } 540 }
574 541
575 target_mem = cde_ctx->mem + cmd_elem->target_buf; 542 target_mem = cde_ctx->mem + cmd_elem->target_buf;
576 if (target_mem->num_bytes < 543 if (target_mem->size<
577 cmd_elem->target_byte_offset + cmd_elem->num_bytes) { 544 cmd_elem->target_byte_offset + cmd_elem->num_bytes) {
578 gk20a_warn(&cde_ctx->pdev->dev, "cde: target buffer cannot hold all entries (target_size=%zu, target_byte_offset=%lld, num_bytes=%llu)", 545 gk20a_warn(&cde_ctx->pdev->dev, "cde: target buffer cannot hold all entries (target_size=%zu, target_byte_offset=%lld, num_bytes=%llu)",
579 target_mem->num_bytes, 546 target_mem->size,
580 cmd_elem->target_byte_offset, 547 cmd_elem->target_byte_offset,
581 cmd_elem->num_bytes); 548 cmd_elem->num_bytes);
582 return -EINVAL; 549 return -EINVAL;