diff options
author | Konsta Holtta <kholtta@nvidia.com> | 2018-01-22 05:19:08 -0500 |
---|---|---|
committer | mobile promotions <svcmobile_promotions@nvidia.com> | 2018-03-01 15:24:06 -0500 |
commit | ba8fa334f40223ad491ab61a6c072a276017787f (patch) | |
tree | eb06807ed4fdee3a708f66949c6daf82f193a531 /drivers/gpu/nvgpu/common/linux/nvgpu_mem.c | |
parent | 5a35a95654d561fce09a3b9abf6b82bb7a29d74b (diff) |
gpu: nvgpu: introduce explicit nvgpu_sgl type
The operations in struct nvgpu_sgt_ops have a scatter-gather list (sgl)
argument which is a void pointer. Change the type signatures to take
struct nvgpu_sgl * which is an opaque marker type that makes it more
difficult to pass around wrong arguments, as anything goes for void *.
Explicit types add also self-documentation to the code.
For some added safety, some explicit type casts are now required in
implementors of the nvgpu_sgt_ops interface when converting between the
general nvgpu_sgl type and implementation-specific types. This is not
purely a bad thing because the casts explain clearly where type
conversions are happening.
Jira NVGPU-30
Jira NVGPU-52
Jira NVGPU-305
Change-Id: Ic64eed6d2d39ca5786e62b172ddb7133af16817a
Signed-off-by: Konsta Holtta <kholtta@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/1643555
GVS: Gerrit_Virtual_Submit
Reviewed-by: Vijayakumar Subbu <vsubbu@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/common/linux/nvgpu_mem.c')
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/nvgpu_mem.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/nvgpu_mem.c b/drivers/gpu/nvgpu/common/linux/nvgpu_mem.c index 206b83e1..7406c4d7 100644 --- a/drivers/gpu/nvgpu/common/linux/nvgpu_mem.c +++ b/drivers/gpu/nvgpu/common/linux/nvgpu_mem.c | |||
@@ -499,27 +499,28 @@ int __nvgpu_mem_create_from_phys(struct gk20a *g, struct nvgpu_mem *dest, | |||
499 | } | 499 | } |
500 | #endif | 500 | #endif |
501 | 501 | ||
502 | static void *nvgpu_mem_linux_sgl_next(void *sgl) | 502 | static struct nvgpu_sgl *nvgpu_mem_linux_sgl_next(struct nvgpu_sgl *sgl) |
503 | { | 503 | { |
504 | return sg_next((struct scatterlist *)sgl); | 504 | return (struct nvgpu_sgl *)sg_next((struct scatterlist *)sgl); |
505 | } | 505 | } |
506 | 506 | ||
507 | static u64 nvgpu_mem_linux_sgl_phys(void *sgl) | 507 | static u64 nvgpu_mem_linux_sgl_phys(struct nvgpu_sgl *sgl) |
508 | { | 508 | { |
509 | return (u64)sg_phys((struct scatterlist *)sgl); | 509 | return (u64)sg_phys((struct scatterlist *)sgl); |
510 | } | 510 | } |
511 | 511 | ||
512 | static u64 nvgpu_mem_linux_sgl_dma(void *sgl) | 512 | static u64 nvgpu_mem_linux_sgl_dma(struct nvgpu_sgl *sgl) |
513 | { | 513 | { |
514 | return (u64)sg_dma_address((struct scatterlist *)sgl); | 514 | return (u64)sg_dma_address((struct scatterlist *)sgl); |
515 | } | 515 | } |
516 | 516 | ||
517 | static u64 nvgpu_mem_linux_sgl_length(void *sgl) | 517 | static u64 nvgpu_mem_linux_sgl_length(struct nvgpu_sgl *sgl) |
518 | { | 518 | { |
519 | return (u64)((struct scatterlist *)sgl)->length; | 519 | return (u64)((struct scatterlist *)sgl)->length; |
520 | } | 520 | } |
521 | 521 | ||
522 | static u64 nvgpu_mem_linux_sgl_gpu_addr(struct gk20a *g, void *sgl, | 522 | static u64 nvgpu_mem_linux_sgl_gpu_addr(struct gk20a *g, |
523 | struct nvgpu_sgl *sgl, | ||
523 | struct nvgpu_gmmu_attrs *attrs) | 524 | struct nvgpu_gmmu_attrs *attrs) |
524 | { | 525 | { |
525 | if (sg_dma_address((struct scatterlist *)sgl) == 0) | 526 | if (sg_dma_address((struct scatterlist *)sgl) == 0) |
@@ -587,7 +588,7 @@ struct nvgpu_sgt *nvgpu_linux_sgt_create(struct gk20a *g, struct sg_table *sgt) | |||
587 | 588 | ||
588 | nvgpu_log(g, gpu_dbg_sgl, "Making Linux SGL!"); | 589 | nvgpu_log(g, gpu_dbg_sgl, "Making Linux SGL!"); |
589 | 590 | ||
590 | nvgpu_sgt->sgl = sgt->sgl; | 591 | nvgpu_sgt->sgl = (struct nvgpu_sgl *)linux_sgl; |
591 | nvgpu_sgt->ops = &nvgpu_linux_sgt_ops; | 592 | nvgpu_sgt->ops = &nvgpu_linux_sgt_ops; |
592 | 593 | ||
593 | return nvgpu_sgt; | 594 | return nvgpu_sgt; |