From ba8fa334f40223ad491ab61a6c072a276017787f Mon Sep 17 00:00:00 2001 From: Konsta Holtta Date: Mon, 22 Jan 2018 12:19:08 +0200 Subject: 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 Reviewed-on: https://git-master.nvidia.com/r/1643555 GVS: Gerrit_Virtual_Submit Reviewed-by: Vijayakumar Subbu Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/include/nvgpu/nvgpu_mem.h | 38 ++++++++++++++++++----------- 1 file changed, 24 insertions(+), 14 deletions(-) (limited to 'drivers/gpu/nvgpu/include') diff --git a/drivers/gpu/nvgpu/include/nvgpu/nvgpu_mem.h b/drivers/gpu/nvgpu/include/nvgpu/nvgpu_mem.h index 2b8b7015..04e947e0 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/nvgpu_mem.h +++ b/drivers/gpu/nvgpu/include/nvgpu/nvgpu_mem.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2017-2018, NVIDIA CORPORATION. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -54,12 +54,19 @@ enum nvgpu_aperture { APERTURE_VIDMEM }; +/* + * Forward declared opaque placeholder type that does not really exist, but + * helps the compiler help us about getting types right. In reality, + * implementors of nvgpu_sgt_ops will have some concrete type in place of this. + */ +struct nvgpu_sgl; + struct nvgpu_sgt_ops { - void *(*sgl_next)(void *sgl); - u64 (*sgl_phys)(void *sgl); - u64 (*sgl_dma)(void *sgl); - u64 (*sgl_length)(void *sgl); - u64 (*sgl_gpu_addr)(struct gk20a *g, void *sgl, + struct nvgpu_sgl *(*sgl_next)(struct nvgpu_sgl *sgl); + u64 (*sgl_phys)(struct nvgpu_sgl *sgl); + u64 (*sgl_dma)(struct nvgpu_sgl *sgl); + u64 (*sgl_length)(struct nvgpu_sgl *sgl); + u64 (*sgl_gpu_addr)(struct gk20a *g, struct nvgpu_sgl *sgl, struct nvgpu_gmmu_attrs *attrs); /* * If left NULL then iommuable is assumed to be false. @@ -85,15 +92,16 @@ struct nvgpu_sgt { /* * The first node in the scatter gather list. */ - void *sgl; + struct nvgpu_sgl *sgl; }; /* * This struct holds the necessary information for describing a struct * nvgpu_mem's scatter gather list. * - * Not all nvgpu_sgt's use this particular implementation. Nor is a given OS - * required to use this at all. + * This is one underlying implementation for nvgpu_sgl. Not all nvgpu_sgt's use + * this particular implementation. Nor is a given OS required to use this at + * all. */ struct nvgpu_mem_sgl { /* @@ -233,11 +241,13 @@ struct nvgpu_sgt *nvgpu_sgt_create(struct gk20a *g); struct nvgpu_sgt *nvgpu_sgt_create_from_mem(struct gk20a *g, struct nvgpu_mem *mem); -void *nvgpu_sgt_get_next(struct nvgpu_sgt *sgt, void *sgl); -u64 nvgpu_sgt_get_phys(struct nvgpu_sgt *sgt, void *sgl); -u64 nvgpu_sgt_get_dma(struct nvgpu_sgt *sgt, void *sgl); -u64 nvgpu_sgt_get_length(struct nvgpu_sgt *sgt, void *sgl); -u64 nvgpu_sgt_get_gpu_addr(struct gk20a *g, struct nvgpu_sgt *sgt, void *sgl, +struct nvgpu_sgl *nvgpu_sgt_get_next(struct nvgpu_sgt *sgt, + struct nvgpu_sgl *sgl); +u64 nvgpu_sgt_get_phys(struct nvgpu_sgt *sgt, struct nvgpu_sgl *sgl); +u64 nvgpu_sgt_get_dma(struct nvgpu_sgt *sgt, struct nvgpu_sgl *sgl); +u64 nvgpu_sgt_get_length(struct nvgpu_sgt *sgt, struct nvgpu_sgl *sgl); +u64 nvgpu_sgt_get_gpu_addr(struct gk20a *g, struct nvgpu_sgt *sgt, + struct nvgpu_sgl *sgl, struct nvgpu_gmmu_attrs *attrs); void nvgpu_sgt_free(struct gk20a *g, struct nvgpu_sgt *sgt); -- cgit v1.2.2