diff options
-rw-r--r-- | drivers/gpu/nvgpu/gk20a/ctrl_gk20a.c | 23 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/gk20a/mm_gk20a.c | 20 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/gk20a/mm_gk20a.h | 1 | ||||
-rw-r--r-- | include/uapi/linux/nvgpu.h | 17 |
4 files changed, 60 insertions, 1 deletions
diff --git a/drivers/gpu/nvgpu/gk20a/ctrl_gk20a.c b/drivers/gpu/nvgpu/gk20a/ctrl_gk20a.c index 6b832670..2fdf719a 100644 --- a/drivers/gpu/nvgpu/gk20a/ctrl_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/ctrl_gk20a.c | |||
@@ -747,6 +747,24 @@ static int nvgpu_gpu_alloc_vidmem(struct gk20a *g, | |||
747 | return 0; | 747 | return 0; |
748 | } | 748 | } |
749 | 749 | ||
750 | static int nvgpu_gpu_get_memory_state(struct gk20a *g, | ||
751 | struct nvgpu_gpu_get_memory_state_args *args) | ||
752 | { | ||
753 | int err; | ||
754 | |||
755 | gk20a_dbg_fn(""); | ||
756 | |||
757 | if (args->reserved[0] || args->reserved[1] || | ||
758 | args->reserved[2] || args->reserved[3]) | ||
759 | return -EINVAL; | ||
760 | |||
761 | err = gk20a_vidmem_get_space(g, &args->total_free_bytes); | ||
762 | |||
763 | gk20a_dbg_fn("done, err=%d, bytes=%lld", err, args->total_free_bytes); | ||
764 | |||
765 | return err; | ||
766 | } | ||
767 | |||
750 | long gk20a_ctrl_dev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) | 768 | long gk20a_ctrl_dev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) |
751 | { | 769 | { |
752 | struct device *dev = filp->private_data; | 770 | struct device *dev = filp->private_data; |
@@ -999,6 +1017,11 @@ long gk20a_ctrl_dev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg | |||
999 | (struct nvgpu_gpu_alloc_vidmem_args *)buf); | 1017 | (struct nvgpu_gpu_alloc_vidmem_args *)buf); |
1000 | break; | 1018 | break; |
1001 | 1019 | ||
1020 | case NVGPU_GPU_IOCTL_GET_MEMORY_STATE: | ||
1021 | err = nvgpu_gpu_get_memory_state(g, | ||
1022 | (struct nvgpu_gpu_get_memory_state_args *)buf); | ||
1023 | break; | ||
1024 | |||
1002 | default: | 1025 | default: |
1003 | dev_dbg(dev_from_gk20a(g), "unrecognized gpu ioctl cmd: 0x%x", cmd); | 1026 | dev_dbg(dev_from_gk20a(g), "unrecognized gpu ioctl cmd: 0x%x", cmd); |
1004 | err = -ENOTTY; | 1027 | err = -ENOTTY; |
diff --git a/drivers/gpu/nvgpu/gk20a/mm_gk20a.c b/drivers/gpu/nvgpu/gk20a/mm_gk20a.c index f46f7a81..ff9bb5e2 100644 --- a/drivers/gpu/nvgpu/gk20a/mm_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/mm_gk20a.c | |||
@@ -2276,6 +2276,26 @@ err_kfree: | |||
2276 | #endif | 2276 | #endif |
2277 | } | 2277 | } |
2278 | 2278 | ||
2279 | int gk20a_vidmem_get_space(struct gk20a *g, u64 *space) | ||
2280 | { | ||
2281 | #if defined(CONFIG_GK20A_VIDMEM) | ||
2282 | struct gk20a_allocator *allocator = &g->mm.vidmem.allocator; | ||
2283 | |||
2284 | gk20a_dbg_fn(""); | ||
2285 | |||
2286 | if (!gk20a_alloc_initialized(allocator)) | ||
2287 | return -ENOSYS; | ||
2288 | |||
2289 | mutex_lock(&g->mm.vidmem.clear_list_mutex); | ||
2290 | *space = gk20a_alloc_space(allocator) + | ||
2291 | atomic64_read(&g->mm.vidmem.bytes_pending); | ||
2292 | mutex_unlock(&g->mm.vidmem.clear_list_mutex); | ||
2293 | return 0; | ||
2294 | #else | ||
2295 | return -ENOSYS; | ||
2296 | #endif | ||
2297 | } | ||
2298 | |||
2279 | static u64 gk20a_mm_get_align(struct gk20a *g, struct scatterlist *sgl, | 2299 | static u64 gk20a_mm_get_align(struct gk20a *g, struct scatterlist *sgl, |
2280 | enum gk20a_aperture aperture) | 2300 | enum gk20a_aperture aperture) |
2281 | { | 2301 | { |
diff --git a/drivers/gpu/nvgpu/gk20a/mm_gk20a.h b/drivers/gpu/nvgpu/gk20a/mm_gk20a.h index b25a7789..e8f7da98 100644 --- a/drivers/gpu/nvgpu/gk20a/mm_gk20a.h +++ b/drivers/gpu/nvgpu/gk20a/mm_gk20a.h | |||
@@ -755,6 +755,7 @@ void gk20a_vm_mapping_batch_finish_locked( | |||
755 | 755 | ||
756 | 756 | ||
757 | int gk20a_vidmem_buf_alloc(struct gk20a *g, size_t bytes); | 757 | int gk20a_vidmem_buf_alloc(struct gk20a *g, size_t bytes); |
758 | int gk20a_vidmem_get_space(struct gk20a *g, u64 *space); | ||
758 | 759 | ||
759 | /* Note: batch may be NULL if map op is not part of a batch */ | 760 | /* Note: batch may be NULL if map op is not part of a batch */ |
760 | int gk20a_vm_map_buffer(struct vm_gk20a *vm, | 761 | int gk20a_vm_map_buffer(struct vm_gk20a *vm, |
diff --git a/include/uapi/linux/nvgpu.h b/include/uapi/linux/nvgpu.h index 84732452..0bf88628 100644 --- a/include/uapi/linux/nvgpu.h +++ b/include/uapi/linux/nvgpu.h | |||
@@ -510,6 +510,18 @@ struct nvgpu_gpu_alloc_vidmem_args { | |||
510 | }; | 510 | }; |
511 | }; | 511 | }; |
512 | 512 | ||
513 | struct nvgpu_gpu_get_memory_state_args { | ||
514 | /* | ||
515 | * Current free space for this device; may change even when any | ||
516 | * kernel-managed metadata (e.g., page tables or channels) is allocated | ||
517 | * or freed. For an idle gpu, an allocation of this size would succeed. | ||
518 | */ | ||
519 | __u64 total_free_bytes; | ||
520 | |||
521 | /* For future use; must be set to 0. */ | ||
522 | __u64 reserved[4]; | ||
523 | }; | ||
524 | |||
513 | #define NVGPU_GPU_IOCTL_ZCULL_GET_CTX_SIZE \ | 525 | #define NVGPU_GPU_IOCTL_ZCULL_GET_CTX_SIZE \ |
514 | _IOR(NVGPU_GPU_IOCTL_MAGIC, 1, struct nvgpu_gpu_zcull_get_ctx_size_args) | 526 | _IOR(NVGPU_GPU_IOCTL_MAGIC, 1, struct nvgpu_gpu_zcull_get_ctx_size_args) |
515 | #define NVGPU_GPU_IOCTL_ZCULL_GET_INFO \ | 527 | #define NVGPU_GPU_IOCTL_ZCULL_GET_INFO \ |
@@ -568,8 +580,11 @@ struct nvgpu_gpu_alloc_vidmem_args { | |||
568 | #define NVGPU_GPU_IOCTL_ALLOC_VIDMEM \ | 580 | #define NVGPU_GPU_IOCTL_ALLOC_VIDMEM \ |
569 | _IOWR(NVGPU_GPU_IOCTL_MAGIC, 27, \ | 581 | _IOWR(NVGPU_GPU_IOCTL_MAGIC, 27, \ |
570 | struct nvgpu_gpu_alloc_vidmem_args) | 582 | struct nvgpu_gpu_alloc_vidmem_args) |
583 | #define NVGPU_GPU_IOCTL_GET_MEMORY_STATE \ | ||
584 | _IOWR(NVGPU_GPU_IOCTL_MAGIC, 33, \ | ||
585 | struct nvgpu_gpu_get_memory_state_args) | ||
571 | #define NVGPU_GPU_IOCTL_LAST \ | 586 | #define NVGPU_GPU_IOCTL_LAST \ |
572 | _IOC_NR(NVGPU_GPU_IOCTL_ALLOC_VIDMEM) | 587 | _IOC_NR(NVGPU_GPU_IOCTL_GET_MEMORY_STATE) |
573 | #define NVGPU_GPU_IOCTL_MAX_ARG_SIZE \ | 588 | #define NVGPU_GPU_IOCTL_MAX_ARG_SIZE \ |
574 | sizeof(struct nvgpu_gpu_get_cpu_time_correlation_info_args) | 589 | sizeof(struct nvgpu_gpu_get_cpu_time_correlation_info_args) |
575 | 590 | ||