summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/common
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/nvgpu/common')
-rw-r--r--drivers/gpu/nvgpu/common/linux/ioctl_as.c15
-rw-r--r--drivers/gpu/nvgpu/common/linux/vm.c37
-rw-r--r--drivers/gpu/nvgpu/common/mm/vm.c124
3 files changed, 43 insertions, 133 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/ioctl_as.c b/drivers/gpu/nvgpu/common/linux/ioctl_as.c
index 8a5318e4..f23dc53c 100644
--- a/drivers/gpu/nvgpu/common/linux/ioctl_as.c
+++ b/drivers/gpu/nvgpu/common/linux/ioctl_as.c
@@ -79,22 +79,19 @@ static int gk20a_as_ioctl_map_buffer_ex(
79 struct gk20a_as_share *as_share, 79 struct gk20a_as_share *as_share,
80 struct nvgpu_as_map_buffer_ex_args *args) 80 struct nvgpu_as_map_buffer_ex_args *args)
81{ 81{
82 s16 compressible_kind;
83 s16 incompressible_kind;
84
85 gk20a_dbg_fn(""); 82 gk20a_dbg_fn("");
86 83
87 if (args->flags & NVGPU_AS_MAP_BUFFER_FLAGS_DIRECT_KIND_CTRL) { 84 /* unsupported, direct kind control must be used */
88 compressible_kind = args->compr_kind; 85 if (!(args->flags & NVGPU_AS_MAP_BUFFER_FLAGS_DIRECT_KIND_CTRL)) {
89 incompressible_kind = args->incompr_kind; 86 struct gk20a *g = as_share->vm->mm->g;
90 } else { 87 nvgpu_log_info(g, "Direct kind control must be requested");
91 /* unsupported, direct kind control must be used */
92 return -EINVAL; 88 return -EINVAL;
93 } 89 }
94 90
95 return nvgpu_vm_map_buffer(as_share->vm, args->dmabuf_fd, 91 return nvgpu_vm_map_buffer(as_share->vm, args->dmabuf_fd,
96 &args->offset, args->flags, 92 &args->offset, args->flags,
97 compressible_kind, incompressible_kind, 93 args->compr_kind,
94 args->incompr_kind,
98 args->buffer_offset, 95 args->buffer_offset,
99 args->mapping_size, 96 args->mapping_size,
100 NULL); 97 NULL);
diff --git a/drivers/gpu/nvgpu/common/linux/vm.c b/drivers/gpu/nvgpu/common/linux/vm.c
index 0cfd010b..895a5771 100644
--- a/drivers/gpu/nvgpu/common/linux/vm.c
+++ b/drivers/gpu/nvgpu/common/linux/vm.c
@@ -32,7 +32,6 @@
32 32
33#include "gk20a/gk20a.h" 33#include "gk20a/gk20a.h"
34#include "gk20a/mm_gk20a.h" 34#include "gk20a/mm_gk20a.h"
35#include "gk20a/kind_gk20a.h"
36 35
37#include "platform_gk20a.h" 36#include "platform_gk20a.h"
38#include "os_linux.h" 37#include "os_linux.h"
@@ -239,14 +238,17 @@ int nvgpu_vm_map_linux(struct vm_gk20a *vm,
239 238
240 binfo.flags = flags; 239 binfo.flags = flags;
241 binfo.size = dmabuf->size; 240 binfo.size = dmabuf->size;
241 binfo.compr_kind = compr_kind;
242 binfo.incompr_kind = incompr_kind;
242 243
243 if (flags & NVGPU_AS_MAP_BUFFER_FLAGS_DIRECT_KIND_CTRL) { 244 if (compr_kind != NV_KIND_INVALID)
244 if (compr_kind != NV_KIND_INVALID)
245 map_key_kind = compr_kind;
246 else
247 map_key_kind = incompr_kind;
248 } else {
249 map_key_kind = compr_kind; 245 map_key_kind = compr_kind;
246 else
247 map_key_kind = incompr_kind;
248
249 if (map_key_kind == NV_KIND_INVALID) {
250 nvgpu_err(g, "Valid kind must be supplied");
251 return -EINVAL;
250 } 252 }
251 253
252 if (vm->userspace_managed && 254 if (vm->userspace_managed &&
@@ -277,10 +279,6 @@ int nvgpu_vm_map_linux(struct vm_gk20a *vm,
277 goto clean_up; 279 goto clean_up;
278 } 280 }
279 281
280 err = nvgpu_vm_init_kind_info(&binfo, compr_kind, incompr_kind);
281 if (err)
282 goto clean_up;
283
284 aperture = gk20a_dmabuf_aperture(g, dmabuf); 282 aperture = gk20a_dmabuf_aperture(g, dmabuf);
285 if (aperture == APERTURE_INVALID) { 283 if (aperture == APERTURE_INVALID) {
286 err = -EINVAL; 284 err = -EINVAL;
@@ -321,9 +319,9 @@ int nvgpu_vm_map_linux(struct vm_gk20a *vm,
321 va_allocated = true; 319 va_allocated = true;
322 } 320 }
323 321
324 err = nvgpu_vm_compute_kind_and_compression(vm, &binfo); 322 err = nvgpu_vm_compute_compression(vm, &binfo);
325 if (err) { 323 if (err) {
326 nvgpu_err(g, "failure setting up kind and compression"); 324 nvgpu_err(g, "failure setting up compression");
327 goto clean_up; 325 goto clean_up;
328 } 326 }
329 327
@@ -340,10 +338,12 @@ int nvgpu_vm_map_linux(struct vm_gk20a *vm,
340 binfo.ctag_lines); 338 binfo.ctag_lines);
341 if (err) { 339 if (err) {
342 /* TBD: we can partially alloc ctags as well... */ 340 /* TBD: we can partially alloc ctags as well... */
343 if (binfo.use_uc_kind_v) { 341
344 /* no comptags, but fallback kind available */ 342 /* prevent compression ... */
345 binfo.kind_v = binfo.uc_kind_v; 343 binfo.compr_kind = NV_KIND_INVALID;
346 } else { 344
345 /* ... and make sure we have the fallback */
346 if (binfo.incompr_kind == NV_KIND_INVALID) {
347 nvgpu_err(g, "comptag alloc failed and no fallback kind specified"); 347 nvgpu_err(g, "comptag alloc failed and no fallback kind specified");
348 goto clean_up; 348 goto clean_up;
349 } 349 }
@@ -379,7 +379,8 @@ int nvgpu_vm_map_linux(struct vm_gk20a *vm,
379 buffer_offset, /* sg offset */ 379 buffer_offset, /* sg offset */
380 mapping_size, 380 mapping_size,
381 binfo.pgsz_idx, 381 binfo.pgsz_idx,
382 binfo.kind_v, 382 (binfo.compr_kind != NV_KIND_INVALID ?
383 binfo.compr_kind : binfo.incompr_kind),
383 ctag_offset, 384 ctag_offset,
384 flags, rw_flag, 385 flags, rw_flag,
385 clear_ctags, 386 clear_ctags,
diff --git a/drivers/gpu/nvgpu/common/mm/vm.c b/drivers/gpu/nvgpu/common/mm/vm.c
index 64c9c217..46783e4e 100644
--- a/drivers/gpu/nvgpu/common/mm/vm.c
+++ b/drivers/gpu/nvgpu/common/mm/vm.c
@@ -35,7 +35,6 @@
35 35
36#include "gk20a/gk20a.h" 36#include "gk20a/gk20a.h"
37#include "gk20a/mm_gk20a.h" 37#include "gk20a/mm_gk20a.h"
38#include "gk20a/kind_gk20a.h"
39 38
40static void __nvgpu_vm_unmap(struct nvgpu_mapped_buf *mapped_buffer, 39static void __nvgpu_vm_unmap(struct nvgpu_mapped_buf *mapped_buffer,
41 struct vm_gk20a_mapping_batch *batch); 40 struct vm_gk20a_mapping_batch *batch);
@@ -829,123 +828,36 @@ done:
829 return; 828 return;
830} 829}
831 830
832int nvgpu_vm_init_kind_info(struct nvgpu_ctag_buffer_info *binfo, 831int nvgpu_vm_compute_compression(struct vm_gk20a *vm,
833 s16 compr_kind, s16 incompr_kind) 832 struct nvgpu_ctag_buffer_info *binfo)
834{
835 if (binfo->flags & NVGPU_AS_MAP_BUFFER_FLAGS_DIRECT_KIND_CTRL) {
836 /* were we supplied with a kind in either parameter? */
837 if ((compr_kind < 0 || compr_kind >= NV_KIND_ATTR_SIZE) &&
838 (incompr_kind < 0 || incompr_kind >= NV_KIND_ATTR_SIZE))
839 return -EINVAL;
840
841 if (compr_kind != NV_KIND_INVALID) {
842 binfo->use_kind_v = true;
843 binfo->kind_v = (u8)compr_kind;
844 }
845
846 if (incompr_kind != NV_KIND_INVALID) {
847 binfo->use_uc_kind_v = true;
848 binfo->uc_kind_v = (u8)incompr_kind;
849 }
850 } else {
851 if (compr_kind < 0 || compr_kind >= NV_KIND_ATTR_SIZE)
852 return -EINVAL;
853
854 binfo->use_kind_v = true;
855 binfo->kind_v = (u8)compr_kind;
856
857 /*
858 * Note: nvgpu_vm_kind_and_compression() will figure out
859 * uc_kind_v or return an error.
860 */
861 }
862
863 return 0;
864}
865
866static int nvgpu_vm_setup_kind_legacy(struct vm_gk20a *vm,
867 struct nvgpu_ctag_buffer_info *binfo,
868 bool *pkind_compressible)
869{ 833{
870 struct gk20a *g = gk20a_from_vm(vm); 834 bool kind_compressible = (binfo->compr_kind != NV_KIND_INVALID);
871 bool kind_compressible;
872
873 if (unlikely(binfo->kind_v == g->ops.mm.get_kind_invalid()))
874 binfo->kind_v = g->ops.mm.get_kind_pitch();
875
876 if (unlikely(!gk20a_kind_is_supported(binfo->kind_v))) {
877 nvgpu_err(g, "kind 0x%x not supported", binfo->kind_v);
878 return -EINVAL;
879 }
880
881 binfo->uc_kind_v = g->ops.mm.get_kind_invalid();
882
883 /*
884 * Find a suitable incompressible kind if it becomes necessary later.
885 */
886 kind_compressible = gk20a_kind_is_compressible(binfo->kind_v);
887 if (kind_compressible) {
888 binfo->uc_kind_v = gk20a_get_uncompressed_kind(binfo->kind_v);
889 if (binfo->uc_kind_v == g->ops.mm.get_kind_invalid()) {
890 /*
891 * Shouldn't happen, but it is worth cross-checking.
892 */
893 nvgpu_err(g, "comptag kind 0x%x can't be"
894 " downgraded to uncompressed kind",
895 binfo->kind_v);
896 return -EINVAL;
897 }
898 }
899
900 *pkind_compressible = kind_compressible;
901
902 return 0;
903}
904
905int nvgpu_vm_compute_kind_and_compression(struct vm_gk20a *vm,
906 struct nvgpu_ctag_buffer_info *binfo)
907{
908 bool kind_compressible;
909 struct gk20a *g = gk20a_from_vm(vm); 835 struct gk20a *g = gk20a_from_vm(vm);
910 int ctag_granularity = g->ops.fb.compression_page_size(g); 836 int ctag_granularity = g->ops.fb.compression_page_size(g);
911 837
912 if (!binfo->use_kind_v)
913 binfo->kind_v = g->ops.mm.get_kind_invalid();
914 if (!binfo->use_uc_kind_v)
915 binfo->uc_kind_v = g->ops.mm.get_kind_invalid();
916
917 if (binfo->flags & NVGPU_AS_MAP_BUFFER_FLAGS_DIRECT_KIND_CTRL) {
918 kind_compressible = (binfo->kind_v !=
919 g->ops.mm.get_kind_invalid());
920 if (!kind_compressible)
921 binfo->kind_v = binfo->uc_kind_v;
922 } else {
923 int err = nvgpu_vm_setup_kind_legacy(vm, binfo,
924 &kind_compressible);
925
926 if (err)
927 return err;
928 }
929
930 /* comptags only supported for suitable kinds, 128KB pagesize */
931 if (kind_compressible && 838 if (kind_compressible &&
932 vm->gmmu_page_sizes[binfo->pgsz_idx] < 839 vm->gmmu_page_sizes[binfo->pgsz_idx] <
933 g->ops.fb.compressible_page_size(g)) { 840 g->ops.fb.compressible_page_size(g)) {
934 /* it is safe to fall back to uncompressed as 841 /*
935 functionality is not harmed */ 842 * Let's double check that there is a fallback kind
936 binfo->kind_v = binfo->uc_kind_v; 843 */
937 kind_compressible = false; 844 if (binfo->incompr_kind == NV_KIND_INVALID) {
845 nvgpu_err(g,
846 "Unsupported page size for compressible "
847 "kind, but no fallback kind");
848 return -EINVAL;
849 } else {
850 nvgpu_log(g, gpu_dbg_map,
851 "Unsupported page size for compressible "
852 "kind, demoting to incompressible");
853 binfo->compr_kind = NV_KIND_INVALID;
854 kind_compressible = false;
855 }
938 } 856 }
939 857
940 if (kind_compressible) 858 if (kind_compressible)
941 binfo->ctag_lines = DIV_ROUND_UP_ULL(binfo->size, 859 binfo->ctag_lines = DIV_ROUND_UP_ULL(binfo->size,
942 ctag_granularity); 860 ctag_granularity);
943 else
944 binfo->ctag_lines = 0;
945
946 binfo->use_kind_v = (binfo->kind_v != g->ops.mm.get_kind_invalid());
947 binfo->use_uc_kind_v = (binfo->uc_kind_v !=
948 g->ops.mm.get_kind_invalid());
949 861
950 return 0; 862 return 0;
951} 863}