diff --git a/drivers/gpu/nvgpu/common/vgpu/gp10b/vgpu_hal_gp10b.c b/drivers/gpu/nvgpu/common/vgpu/gp10b/vgpu_hal_gp10b.c index 023ee9819..d26dc9a11 100644 --- a/drivers/gpu/nvgpu/common/vgpu/gp10b/vgpu_hal_gp10b.c +++ b/drivers/gpu/nvgpu/common/vgpu/gp10b/vgpu_hal_gp10b.c @@ -292,7 +292,8 @@ static const struct gpu_ops vgpu_gp10b_ops = { .fecs_trace = { .alloc_user_buffer = vgpu_alloc_user_buffer, .free_user_buffer = vgpu_free_user_buffer, - .mmap_user_buffer = vgpu_mmap_user_buffer, + .get_mmap_user_buffer_info = + vgpu_get_mmap_user_buffer_info, .init = vgpu_fecs_trace_init, .deinit = vgpu_fecs_trace_deinit, .enable = vgpu_fecs_trace_enable, diff --git a/drivers/gpu/nvgpu/common/vgpu/gr/fecs_trace_vgpu.h b/drivers/gpu/nvgpu/common/vgpu/gr/fecs_trace_vgpu.h index 30b9721a1..734bb6eed 100644 --- a/drivers/gpu/nvgpu/common/vgpu/gr/fecs_trace_vgpu.h +++ b/drivers/gpu/nvgpu/common/vgpu/gr/fecs_trace_vgpu.h @@ -50,7 +50,8 @@ bool vgpu_fecs_trace_is_enabled(struct gk20a *g); int vgpu_fecs_trace_poll(struct gk20a *g); int vgpu_alloc_user_buffer(struct gk20a *g, void **buf, size_t *size); int vgpu_free_user_buffer(struct gk20a *g); -int vgpu_mmap_user_buffer(struct gk20a *g, struct vm_area_struct *vma); +void vgpu_get_mmap_user_buffer_info(struct gk20a *g, + void **mmapaddr, size_t *mmapsize); int vgpu_fecs_trace_max_entries(struct gk20a *g, struct nvgpu_gpu_ctxsw_trace_filter *filter); int vgpu_fecs_trace_set_filter(struct gk20a *g, diff --git a/drivers/gpu/nvgpu/common/vgpu/gv11b/vgpu_hal_gv11b.c b/drivers/gpu/nvgpu/common/vgpu/gv11b/vgpu_hal_gv11b.c index 022706e4b..ac99b9d8b 100644 --- a/drivers/gpu/nvgpu/common/vgpu/gv11b/vgpu_hal_gv11b.c +++ b/drivers/gpu/nvgpu/common/vgpu/gv11b/vgpu_hal_gv11b.c @@ -341,7 +341,8 @@ static const struct gpu_ops vgpu_gv11b_ops = { .fecs_trace = { .alloc_user_buffer = vgpu_alloc_user_buffer, .free_user_buffer = vgpu_free_user_buffer, - .mmap_user_buffer = vgpu_mmap_user_buffer, + .get_mmap_user_buffer_info = + vgpu_get_mmap_user_buffer_info, .init = vgpu_fecs_trace_init, .deinit = vgpu_fecs_trace_deinit, .enable = vgpu_fecs_trace_enable, diff --git a/drivers/gpu/nvgpu/gp10b/hal_gp10b.c b/drivers/gpu/nvgpu/gp10b/hal_gp10b.c index 3101777b8..c1fd40144 100644 --- a/drivers/gpu/nvgpu/gp10b/hal_gp10b.c +++ b/drivers/gpu/nvgpu/gp10b/hal_gp10b.c @@ -443,7 +443,8 @@ static const struct gpu_ops gp10b_ops = { .fecs_trace = { .alloc_user_buffer = nvgpu_gr_fecs_trace_ring_alloc, .free_user_buffer = nvgpu_gr_fecs_trace_ring_free, - .mmap_user_buffer = nvgpu_gr_fecs_trace_mmap_buffer, + .get_mmap_user_buffer_info = + nvgpu_gr_fecs_trace_get_mmap_buffer_info, .init = nvgpu_gr_fecs_trace_init, .deinit = nvgpu_gr_fecs_trace_deinit, .enable = nvgpu_gr_fecs_trace_enable, diff --git a/drivers/gpu/nvgpu/gv100/hal_gv100.c b/drivers/gpu/nvgpu/gv100/hal_gv100.c index 5c32e8eac..7262b83bb 100644 --- a/drivers/gpu/nvgpu/gv100/hal_gv100.c +++ b/drivers/gpu/nvgpu/gv100/hal_gv100.c @@ -561,7 +561,8 @@ static const struct gpu_ops gv100_ops = { .fecs_trace = { .alloc_user_buffer = nvgpu_gr_fecs_trace_ring_alloc, .free_user_buffer = nvgpu_gr_fecs_trace_ring_free, - .mmap_user_buffer = nvgpu_gr_fecs_trace_mmap_buffer, + .get_mmap_user_buffer_info = + nvgpu_gr_fecs_trace_get_mmap_buffer_info, .init = nvgpu_gr_fecs_trace_init, .deinit = nvgpu_gr_fecs_trace_deinit, .enable = nvgpu_gr_fecs_trace_enable, diff --git a/drivers/gpu/nvgpu/gv11b/hal_gv11b.c b/drivers/gpu/nvgpu/gv11b/hal_gv11b.c index 8c7341cc5..8b25acde1 100644 --- a/drivers/gpu/nvgpu/gv11b/hal_gv11b.c +++ b/drivers/gpu/nvgpu/gv11b/hal_gv11b.c @@ -540,7 +540,8 @@ static const struct gpu_ops gv11b_ops = { .fecs_trace = { .alloc_user_buffer = nvgpu_gr_fecs_trace_ring_alloc, .free_user_buffer = nvgpu_gr_fecs_trace_ring_free, - .mmap_user_buffer = nvgpu_gr_fecs_trace_mmap_buffer, + .get_mmap_user_buffer_info = + nvgpu_gr_fecs_trace_get_mmap_buffer_info, .init = nvgpu_gr_fecs_trace_init, .deinit = nvgpu_gr_fecs_trace_deinit, .enable = nvgpu_gr_fecs_trace_enable, diff --git a/drivers/gpu/nvgpu/include/nvgpu/gk20a.h b/drivers/gpu/nvgpu/include/nvgpu/gk20a.h index 34323029c..fd3588e69 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/gk20a.h +++ b/drivers/gpu/nvgpu/include/nvgpu/gk20a.h @@ -173,7 +173,7 @@ struct railgate_stats { #define GPU_LIT_PERFMON_PMMFBP_ROP_DOMAIN_START 43 #define GPU_LIT_PERFMON_PMMFBP_ROP_DOMAIN_COUNT 44 -#define nvgpu_get_litter_value(g, v) (g)->ops.get_litter_value((g), v) +#define nvgpu_get_litter_value(g, v) ((g)->ops.get_litter_value((g), v)) #define MAX_TPC_PG_CONFIGS 3 @@ -274,7 +274,7 @@ struct gpu_ops { int (*handle_sw_method)(struct gk20a *g, u32 addr, u32 class_num, u32 offset, u32 data); void (*set_alpha_circular_buffer_size)(struct gk20a *g, - u32 data); + u32 data); void (*set_circular_buffer_size)(struct gk20a *g, u32 data); void (*set_bes_crop_debug3)(struct gk20a *g, u32 data); void (*set_bes_crop_debug4)(struct gk20a *g, u32 data); @@ -612,8 +612,8 @@ struct gpu_ops { int (*alloc_user_buffer)(struct gk20a *g, void **buf, size_t *size); int (*free_user_buffer)(struct gk20a *g); - int (*mmap_user_buffer)(struct gk20a *g, - struct vm_area_struct *vma); + void (*get_mmap_user_buffer_info)(struct gk20a *g, + void **addr, size_t *size); int (*set_filter)(struct gk20a *g, struct nvgpu_gpu_ctxsw_trace_filter *filter); u32 (*get_buffer_full_mailbox_val)(void); @@ -1333,7 +1333,7 @@ struct gpu_ops { } boardobj; struct { int (*clk_set_boot_clk)(struct gk20a *g); - }clk; + } clk; } pmu_ver; struct { int (*get_netlist_name)(struct gk20a *g, int index, char *name); @@ -1566,7 +1566,7 @@ struct gpu_ops { int (*arbiter_clk_init)(struct gk20a *g); bool (*check_clk_arb_support)(struct gk20a *g); u32 (*get_arbiter_clk_domains)(struct gk20a *g); - int (*get_arbiter_f_points)(struct gk20a *g,u32 api_domain, + int (*get_arbiter_f_points)(struct gk20a *g, u32 api_domain, u32 *num_points, u16 *freqs_in_mhz); int (*get_arbiter_clk_range)(struct gk20a *g, u32 api_domain, u16 *min_mhz, u16 *max_mhz); diff --git a/drivers/gpu/nvgpu/include/nvgpu/gr/fecs_trace.h b/drivers/gpu/nvgpu/include/nvgpu/gr/fecs_trace.h index 6da7c8d28..9a5990257 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/gr/fecs_trace.h +++ b/drivers/gpu/nvgpu/include/nvgpu/gr/fecs_trace.h @@ -176,7 +176,8 @@ int nvgpu_gr_fecs_trace_unbind_channel(struct gk20a *g, */ int nvgpu_gr_fecs_trace_ring_alloc(struct gk20a *g, void **buf, size_t *size); int nvgpu_gr_fecs_trace_ring_free(struct gk20a *g); -int nvgpu_gr_fecs_trace_mmap_buffer(struct gk20a *g, struct vm_area_struct *vma); +void nvgpu_gr_fecs_trace_get_mmap_buffer_info(struct gk20a *g, + void **mmapaddr, size_t *mmapsize); void nvgpu_gr_fecs_trace_add_tsg_reset(struct gk20a *g, struct tsg_gk20a *tsg); u8 nvgpu_gpu_ctxsw_tags_to_common_tags(u8 tags); int nvgpu_gr_fecs_trace_write_entry(struct gk20a *g, diff --git a/drivers/gpu/nvgpu/include/nvgpu/kref.h b/drivers/gpu/nvgpu/include/nvgpu/kref.h index 460eb4b38..0e096deed 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/kref.h +++ b/drivers/gpu/nvgpu/include/nvgpu/kref.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2017-2019, 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"), @@ -27,6 +27,7 @@ #define NVGPU_KREF_H #include +#include struct nvgpu_ref { nvgpu_atomic_t refcount; diff --git a/drivers/gpu/nvgpu/include/nvgpu/log2.h b/drivers/gpu/nvgpu/include/nvgpu/log2.h index 98db1ecc7..f1f78d80f 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/log2.h +++ b/drivers/gpu/nvgpu/include/nvgpu/log2.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2017-2019, 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"), @@ -24,7 +24,7 @@ #ifdef __KERNEL__ #include -#elif defined(__NVGPU_POSIX__) +#else #include #endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/posix/log2.h b/drivers/gpu/nvgpu/include/nvgpu/posix/log2.h index e98768ab6..37420b35b 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/posix/log2.h +++ b/drivers/gpu/nvgpu/include/nvgpu/posix/log2.h @@ -33,7 +33,6 @@ #define is_power_of_2(x) \ ({ \ typeof(x) __x__ = (x); \ - (__x__ != 0U && ((__x__ & (__x__ - 1U)) == 0U)); \ + (__x__ != 0U && ((__x__ & (__x__ - 1U)) == 0U));\ }) - #endif /* NVGPU_POSIX_LOG2_H */ diff --git a/drivers/gpu/nvgpu/include/nvgpu/posix/types.h b/drivers/gpu/nvgpu/include/nvgpu/posix/types.h index 5550f88c8..488f554cd 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/posix/types.h +++ b/drivers/gpu/nvgpu/include/nvgpu/posix/types.h @@ -91,16 +91,22 @@ typedef signed long long s64; #define DIV_ROUND_UP(n, d) (((n) + (d) - 1U) / (d)) -/* - * Only used in clk_gm20b.c which we will never unit test. Don't use! - */ -#define DIV_ROUND_CLOSEST(x, divisor) ({BUG(); 0; }) - +#define DIV_ROUND_CLOSEST(a, divisor)( \ +{ \ + typeof(a) val = a; \ + typeof(divisor) div = divisor; \ + (((typeof(a))-1) > 0 || \ + ((typeof(divisor))-1) > 0 || (val) > 0) ? \ + (((val) + ((div) / 2)) / (div)) : \ + (((val) - ((div) / 2)) / (div)); \ +} \ +) /* * Joys of userspace: usually division just works since the compiler can link * against external division functions implicitly. */ #define do_div(a, b) ((a) /= (b)) + #define div64_u64(a, b) ((a) / (b)) #define __round_mask(x, y) ((__typeof__(x))((y) - 1U)) @@ -177,12 +183,12 @@ static inline unsigned long __hweight64(uint64_t x) * Better suited under a compiler.h type header file, but for now these can live * here. */ -#define __must_check +#define __must_check __attribute__((warn_unused_result)) #define __maybe_unused __attribute__((unused)) #define __iomem #define __user -#define unlikely -#define likely +#define unlikely(x) (x) +#define likely(x) (x) #define __stringify(x) #x @@ -196,9 +202,9 @@ static inline unsigned long __hweight64(uint64_t x) *__p__ = (v); \ }) -#define container_of(ptr, type, member) ({ \ - const typeof( ((type *)0)->member ) *__mptr = (ptr); \ - (type *)( (char *)__mptr - offsetof(type,member) );}) +#define container_of(ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) #define __packed __attribute__((packed)) diff --git a/drivers/gpu/nvgpu/include/nvgpu/types.h b/drivers/gpu/nvgpu/include/nvgpu/types.h index 016b4ef22..670942f02 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/types.h +++ b/drivers/gpu/nvgpu/include/nvgpu/types.h @@ -24,10 +24,8 @@ #ifdef __KERNEL__ #include -#elif defined(__NVGPU_POSIX__) -#include #else -#include +#include #endif /* diff --git a/drivers/gpu/nvgpu/os/linux/fecs_trace_linux.c b/drivers/gpu/nvgpu/os/linux/fecs_trace_linux.c index ad83c540e..65114f272 100644 --- a/drivers/gpu/nvgpu/os/linux/fecs_trace_linux.c +++ b/drivers/gpu/nvgpu/os/linux/fecs_trace_linux.c @@ -508,22 +508,42 @@ static struct vm_operations_struct gk20a_ctxsw_dev_vma_ops = { .close = gk20a_ctxsw_dev_vma_close, }; -int nvgpu_gr_fecs_trace_mmap_buffer(struct gk20a *g, - struct vm_area_struct *vma) +void nvgpu_gr_fecs_trace_get_mmap_buffer_info(struct gk20a *g, + void **mmapaddr, size_t *mmapsize) { - return remap_vmalloc_range(vma, g->ctxsw_trace->devs[0].hdr, 0); + *mmapaddr = g->ctxsw_trace->devs[0].hdr; + *mmapsize = 0; } int gk20a_ctxsw_dev_mmap(struct file *filp, struct vm_area_struct *vma) { struct gk20a_ctxsw_dev *dev = filp->private_data; struct gk20a *g = dev->g; + size_t mmapsize = 0; + void *mmapaddr; int ret; nvgpu_log(g, gpu_dbg_fn|gpu_dbg_ctxsw, "vm_start=%lx vm_end=%lx", vma->vm_start, vma->vm_end); - ret = dev->g->ops.gr.fecs_trace.mmap_user_buffer(dev->g, vma); + dev->g->ops.gr.fecs_trace.get_mmap_user_buffer_info(dev->g, + &mmapaddr, &mmapsize); + if (mmapsize) { + unsigned long size = 0; + unsigned long vsize = vma->vm_end - vma->vm_start; + + size = min(mmapsize, vsize); + size = round_up(size, PAGE_SIZE); + + ret = remap_pfn_range(vma, vma->vm_start, + (unsigned long) mmapaddr, + size, + vma->vm_page_prot); + + } else { + ret = remap_vmalloc_range(vma, mmapaddr, 0); + } + if (likely(!ret)) { vma->vm_private_data = dev; vma->vm_ops = &gk20a_ctxsw_dev_vma_ops; @@ -757,7 +777,7 @@ void nvgpu_gr_fecs_trace_add_tsg_reset(struct gk20a *g, struct tsg_gk20a *tsg) u8 nvgpu_gpu_ctxsw_tags_to_common_tags(u8 tags) { - switch (tags){ + switch (tags) { case NVGPU_CTXSW_TAG_SOF: return NVGPU_GPU_CTXSW_TAG_SOF; case NVGPU_CTXSW_TAG_CTXSW_REQ_BY_HOST: diff --git a/drivers/gpu/nvgpu/os/linux/vgpu/fecs_trace_vgpu_linux.c b/drivers/gpu/nvgpu/os/linux/vgpu/fecs_trace_vgpu_linux.c index 09c89df6f..e893a40ee 100644 --- a/drivers/gpu/nvgpu/os/linux/vgpu/fecs_trace_vgpu_linux.c +++ b/drivers/gpu/nvgpu/os/linux/vgpu/fecs_trace_vgpu_linux.c @@ -37,17 +37,11 @@ int vgpu_alloc_user_buffer(struct gk20a *g, void **buf, size_t *size) return 0; } -int vgpu_mmap_user_buffer(struct gk20a *g, struct vm_area_struct *vma) +void vgpu_get_mmap_user_buffer_info(struct gk20a *g, + void **mmapaddr, size_t *mmapsize) { struct vgpu_fecs_trace *vcst = (struct vgpu_fecs_trace *)g->fecs_trace; - unsigned long size = vgpu_ivm_get_size(vcst->cookie); - unsigned long vsize = vma->vm_end - vma->vm_start; - size = min(size, vsize); - size = round_up(size, PAGE_SIZE); - - return remap_pfn_range(vma, vma->vm_start, - vgpu_ivm_get_ipa(vcst->cookie) >> PAGE_SHIFT, - size, - vma->vm_page_prot); + *mmapsize = vgpu_ivm_get_size(vcst->cookie); + *mmapaddr = (void *) (vgpu_ivm_get_ipa(vcst->cookie) >> PAGE_SHIFT); } diff --git a/drivers/gpu/nvgpu/tu104/hal_tu104.c b/drivers/gpu/nvgpu/tu104/hal_tu104.c index 73a8e4a29..de0c3ea64 100644 --- a/drivers/gpu/nvgpu/tu104/hal_tu104.c +++ b/drivers/gpu/nvgpu/tu104/hal_tu104.c @@ -590,7 +590,8 @@ static const struct gpu_ops tu104_ops = { .fecs_trace = { .alloc_user_buffer = nvgpu_gr_fecs_trace_ring_alloc, .free_user_buffer = nvgpu_gr_fecs_trace_ring_free, - .mmap_user_buffer = nvgpu_gr_fecs_trace_mmap_buffer, + .get_mmap_user_buffer_info = + nvgpu_gr_fecs_trace_get_mmap_buffer_info, .init = nvgpu_gr_fecs_trace_init, .deinit = nvgpu_gr_fecs_trace_deinit, .enable = nvgpu_gr_fecs_trace_enable,