diff options
| -rw-r--r-- | drivers/video/tegra/nvmap/nvmap.c | 14 | ||||
| -rw-r--r-- | drivers/video/tegra/nvmap/nvmap_alloc.c | 2 | ||||
| -rw-r--r-- | drivers/video/tegra/nvmap/nvmap_cache.c | 5 | ||||
| -rw-r--r-- | drivers/video/tegra/nvmap/nvmap_dev.c | 6 | ||||
| -rw-r--r-- | drivers/video/tegra/nvmap/nvmap_heap.c | 6 | ||||
| -rw-r--r-- | drivers/video/tegra/nvmap/nvmap_ioctl.c | 8 | ||||
| -rw-r--r-- | drivers/video/tegra/nvmap/nvmap_priv.h | 1 | ||||
| -rw-r--r-- | include/linux/nvmap.h | 1 |
8 files changed, 39 insertions, 4 deletions
diff --git a/drivers/video/tegra/nvmap/nvmap.c b/drivers/video/tegra/nvmap/nvmap.c index 7d31d92f3..4565e8e71 100644 --- a/drivers/video/tegra/nvmap/nvmap.c +++ b/drivers/video/tegra/nvmap/nvmap.c | |||
| @@ -60,6 +60,9 @@ void *__nvmap_kmap(struct nvmap_handle *h, unsigned int pagenum) | |||
| 60 | if (!h) | 60 | if (!h) |
| 61 | return NULL; | 61 | return NULL; |
| 62 | 62 | ||
| 63 | if (!(h->heap_type & nvmap_dev->cpu_access_mask)) | ||
| 64 | goto put_handle; | ||
| 65 | |||
| 63 | nvmap_kmaps_inc(h); | 66 | nvmap_kmaps_inc(h); |
| 64 | if (pagenum >= h->size >> PAGE_SHIFT) | 67 | if (pagenum >= h->size >> PAGE_SHIFT) |
| 65 | goto out; | 68 | goto out; |
| @@ -78,6 +81,7 @@ void *__nvmap_kmap(struct nvmap_handle *h, unsigned int pagenum) | |||
| 78 | return (void *)kaddr; | 81 | return (void *)kaddr; |
| 79 | out: | 82 | out: |
| 80 | nvmap_kmaps_dec(h); | 83 | nvmap_kmaps_dec(h); |
| 84 | put_handle: | ||
| 81 | nvmap_handle_put(h); | 85 | nvmap_handle_put(h); |
| 82 | return NULL; | 86 | return NULL; |
| 83 | } | 87 | } |
| @@ -90,7 +94,8 @@ void __nvmap_kunmap(struct nvmap_handle *h, unsigned int pagenum, | |||
| 90 | 94 | ||
| 91 | if (!h || | 95 | if (!h || |
| 92 | WARN_ON(!virt_addr_valid(h)) || | 96 | WARN_ON(!virt_addr_valid(h)) || |
| 93 | WARN_ON(!addr)) | 97 | WARN_ON(!addr) || |
| 98 | !(h->heap_type & nvmap_dev->cpu_access_mask)) | ||
| 94 | return; | 99 | return; |
| 95 | 100 | ||
| 96 | if (WARN_ON(pagenum >= h->size >> PAGE_SHIFT)) | 101 | if (WARN_ON(pagenum >= h->size >> PAGE_SHIFT)) |
| @@ -131,6 +136,9 @@ void *__nvmap_mmap(struct nvmap_handle *h) | |||
| 131 | if (!h) | 136 | if (!h) |
| 132 | return NULL; | 137 | return NULL; |
| 133 | 138 | ||
| 139 | if (!(h->heap_type & nvmap_dev->cpu_access_mask)) | ||
| 140 | goto put_handle; | ||
| 141 | |||
| 134 | if (h->vaddr) | 142 | if (h->vaddr) |
| 135 | return h->vaddr; | 143 | return h->vaddr; |
| 136 | 144 | ||
| @@ -183,6 +191,7 @@ void *__nvmap_mmap(struct nvmap_handle *h) | |||
| 183 | return h->vaddr; | 191 | return h->vaddr; |
| 184 | out: | 192 | out: |
| 185 | nvmap_kmaps_dec(h); | 193 | nvmap_kmaps_dec(h); |
| 194 | put_handle: | ||
| 186 | nvmap_handle_put(h); | 195 | nvmap_handle_put(h); |
| 187 | return NULL; | 196 | return NULL; |
| 188 | } | 197 | } |
| @@ -191,7 +200,8 @@ void __nvmap_munmap(struct nvmap_handle *h, void *addr) | |||
| 191 | { | 200 | { |
| 192 | if (!h || | 201 | if (!h || |
| 193 | WARN_ON(!virt_addr_valid(h)) || | 202 | WARN_ON(!virt_addr_valid(h)) || |
| 194 | WARN_ON(!addr)) | 203 | WARN_ON(!addr) || |
| 204 | !(h->heap_type & nvmap_dev->cpu_access_mask)) | ||
| 195 | return; | 205 | return; |
| 196 | 206 | ||
| 197 | nvmap_handle_put(h); | 207 | nvmap_handle_put(h); |
diff --git a/drivers/video/tegra/nvmap/nvmap_alloc.c b/drivers/video/tegra/nvmap/nvmap_alloc.c index 45241570d..2154bca21 100644 --- a/drivers/video/tegra/nvmap/nvmap_alloc.c +++ b/drivers/video/tegra/nvmap/nvmap_alloc.c | |||
| @@ -306,7 +306,7 @@ int nvmap_alloc_handle(struct nvmap_client *client, | |||
| 306 | h->userflags = flags; | 306 | h->userflags = flags; |
| 307 | nr_page = ((h->size + PAGE_SIZE - 1) >> PAGE_SHIFT); | 307 | nr_page = ((h->size + PAGE_SIZE - 1) >> PAGE_SHIFT); |
| 308 | /* Force mapping to uncached for VPR memory. */ | 308 | /* Force mapping to uncached for VPR memory. */ |
| 309 | if (heap_mask & NVMAP_HEAP_CARVEOUT_VPR) | 309 | if (heap_mask & (NVMAP_HEAP_CARVEOUT_VPR | ~nvmap_dev->cpu_access_mask)) |
| 310 | h->flags = NVMAP_HANDLE_UNCACHEABLE; | 310 | h->flags = NVMAP_HANDLE_UNCACHEABLE; |
| 311 | else | 311 | else |
| 312 | h->flags = (flags & NVMAP_HANDLE_CACHE_FLAG); | 312 | h->flags = (flags & NVMAP_HANDLE_CACHE_FLAG); |
diff --git a/drivers/video/tegra/nvmap/nvmap_cache.c b/drivers/video/tegra/nvmap/nvmap_cache.c index 7877b1b19..c2bf634c8 100644 --- a/drivers/video/tegra/nvmap/nvmap_cache.c +++ b/drivers/video/tegra/nvmap/nvmap_cache.c | |||
| @@ -421,6 +421,11 @@ int __nvmap_do_cache_maint(struct nvmap_client *client, | |||
| 421 | if (!h) | 421 | if (!h) |
| 422 | return -EFAULT; | 422 | return -EFAULT; |
| 423 | 423 | ||
| 424 | if (!(h->heap_type & nvmap_dev->cpu_access_mask)) { | ||
| 425 | nvmap_handle_put(h); | ||
| 426 | return -EPERM; | ||
| 427 | } | ||
| 428 | |||
| 424 | nvmap_kmaps_inc(h); | 429 | nvmap_kmaps_inc(h); |
| 425 | if (op == NVMAP_CACHE_OP_INV) | 430 | if (op == NVMAP_CACHE_OP_INV) |
| 426 | op = NVMAP_CACHE_OP_WB_INV; | 431 | op = NVMAP_CACHE_OP_WB_INV; |
diff --git a/drivers/video/tegra/nvmap/nvmap_dev.c b/drivers/video/tegra/nvmap/nvmap_dev.c index ce0f8dcfa..c22995d75 100644 --- a/drivers/video/tegra/nvmap/nvmap_dev.c +++ b/drivers/video/tegra/nvmap/nvmap_dev.c | |||
| @@ -511,6 +511,11 @@ int __nvmap_map(struct nvmap_handle *h, struct vm_area_struct *vma) | |||
| 511 | if (!h) | 511 | if (!h) |
| 512 | return -EINVAL; | 512 | return -EINVAL; |
| 513 | 513 | ||
| 514 | if (!(h->heap_type & nvmap_dev->cpu_access_mask)) { | ||
| 515 | nvmap_handle_put(h); | ||
| 516 | return -EPERM; | ||
| 517 | } | ||
| 518 | |||
| 514 | /* | 519 | /* |
| 515 | * Don't allow mmap on VPR memory as it would be mapped | 520 | * Don't allow mmap on VPR memory as it would be mapped |
| 516 | * as device memory. User space shouldn't be accessing | 521 | * as device memory. User space shouldn't be accessing |
| @@ -1693,6 +1698,7 @@ int __init nvmap_probe(struct platform_device *pdev) | |||
| 1693 | nvmap_debug_root, &nvmap_max_handle_count); | 1698 | nvmap_debug_root, &nvmap_max_handle_count); |
| 1694 | 1699 | ||
| 1695 | nvmap_dev->dynamic_dma_map_mask = ~0; | 1700 | nvmap_dev->dynamic_dma_map_mask = ~0; |
| 1701 | nvmap_dev->cpu_access_mask = ~0; | ||
| 1696 | for (i = 0; i < plat->nr_carveouts; i++) | 1702 | for (i = 0; i < plat->nr_carveouts; i++) |
| 1697 | (void)nvmap_create_carveout(&plat->carveouts[i]); | 1703 | (void)nvmap_create_carveout(&plat->carveouts[i]); |
| 1698 | 1704 | ||
diff --git a/drivers/video/tegra/nvmap/nvmap_heap.c b/drivers/video/tegra/nvmap/nvmap_heap.c index d5e9ce70a..cf1fcd764 100644 --- a/drivers/video/tegra/nvmap/nvmap_heap.c +++ b/drivers/video/tegra/nvmap/nvmap_heap.c | |||
| @@ -377,7 +377,8 @@ struct nvmap_heap *nvmap_heap_create(struct device *parent, | |||
| 377 | h->vm_id = co->vmid; | 377 | h->vm_id = co->vmid; |
| 378 | INIT_LIST_HEAD(&h->all_list); | 378 | INIT_LIST_HEAD(&h->all_list); |
| 379 | mutex_init(&h->lock); | 379 | mutex_init(&h->lock); |
| 380 | if (nvmap_cache_maint_phys_range(NVMAP_CACHE_OP_WB_INV, | 380 | if (!co->no_cpu_access && |
| 381 | nvmap_cache_maint_phys_range(NVMAP_CACHE_OP_WB_INV, | ||
| 381 | base, base + len, true, true)) { | 382 | base, base + len, true, true)) { |
| 382 | dev_err(parent, "cache flush failed\n"); | 383 | dev_err(parent, "cache flush failed\n"); |
| 383 | goto fail; | 384 | goto fail; |
| @@ -398,6 +399,9 @@ finish: | |||
| 398 | if (co->disable_dynamic_dma_map) | 399 | if (co->disable_dynamic_dma_map) |
| 399 | nvmap_dev->dynamic_dma_map_mask &= ~co->usage_mask; | 400 | nvmap_dev->dynamic_dma_map_mask &= ~co->usage_mask; |
| 400 | 401 | ||
| 402 | if (co->no_cpu_access) | ||
| 403 | nvmap_dev->cpu_access_mask &= ~co->usage_mask; | ||
| 404 | |||
| 401 | dev_info(parent, "created heap %s base 0x%p size (%zuKiB)\n", | 405 | dev_info(parent, "created heap %s base 0x%p size (%zuKiB)\n", |
| 402 | co->name, (void *)(uintptr_t)base, len/1024); | 406 | co->name, (void *)(uintptr_t)base, len/1024); |
| 403 | return h; | 407 | return h; |
diff --git a/drivers/video/tegra/nvmap/nvmap_ioctl.c b/drivers/video/tegra/nvmap/nvmap_ioctl.c index 0c02f16fc..095554fa7 100644 --- a/drivers/video/tegra/nvmap/nvmap_ioctl.c +++ b/drivers/video/tegra/nvmap/nvmap_ioctl.c | |||
| @@ -403,6 +403,9 @@ static ssize_t rw_handle(struct nvmap_client *client, struct nvmap_handle *h, | |||
| 403 | void *addr; | 403 | void *addr; |
| 404 | int ret = 0; | 404 | int ret = 0; |
| 405 | 405 | ||
| 406 | if (!(h->heap_type & nvmap_dev->cpu_access_mask)) | ||
| 407 | return -EPERM; | ||
| 408 | |||
| 406 | if (!elem_size || !count) | 409 | if (!elem_size || !count) |
| 407 | return -EINVAL; | 410 | return -EINVAL; |
| 408 | 411 | ||
| @@ -657,6 +660,11 @@ int nvmap_ioctl_cache_maint_list(struct file *filp, void __user *arg, | |||
| 657 | err = -EINVAL; | 660 | err = -EINVAL; |
| 658 | goto free_mem; | 661 | goto free_mem; |
| 659 | } | 662 | } |
| 663 | if (!(refs[i]->heap_type & nvmap_dev->cpu_access_mask)) { | ||
| 664 | err = -EPERM; | ||
| 665 | goto free_mem; | ||
| 666 | } | ||
| 667 | |||
| 660 | n_unmarshal_handles++; | 668 | n_unmarshal_handles++; |
| 661 | } | 669 | } |
| 662 | 670 | ||
diff --git a/drivers/video/tegra/nvmap/nvmap_priv.h b/drivers/video/tegra/nvmap/nvmap_priv.h index 5048f6aea..d31235fe8 100644 --- a/drivers/video/tegra/nvmap/nvmap_priv.h +++ b/drivers/video/tegra/nvmap/nvmap_priv.h | |||
| @@ -237,6 +237,7 @@ struct nvmap_device { | |||
| 237 | struct rb_root tags; | 237 | struct rb_root tags; |
| 238 | struct mutex tags_lock; | 238 | struct mutex tags_lock; |
| 239 | u32 dynamic_dma_map_mask; | 239 | u32 dynamic_dma_map_mask; |
| 240 | u32 cpu_access_mask; | ||
| 240 | }; | 241 | }; |
| 241 | 242 | ||
| 242 | enum nvmap_stats_t { | 243 | enum nvmap_stats_t { |
diff --git a/include/linux/nvmap.h b/include/linux/nvmap.h index d551f992d..764e03fe3 100644 --- a/include/linux/nvmap.h +++ b/include/linux/nvmap.h | |||
| @@ -87,6 +87,7 @@ struct nvmap_platform_carveout { | |||
| 87 | int can_alloc; | 87 | int can_alloc; |
| 88 | bool enable_static_dma_map; | 88 | bool enable_static_dma_map; |
| 89 | bool disable_dynamic_dma_map; | 89 | bool disable_dynamic_dma_map; |
| 90 | bool no_cpu_access; /* carveout can't be accessed from cpu at all */ | ||
| 90 | bool init_done; /* FIXME: remove once all caveouts use reserved-memory */ | 91 | bool init_done; /* FIXME: remove once all caveouts use reserved-memory */ |
| 91 | }; | 92 | }; |
| 92 | 93 | ||
