diff options
| author | David Gilhooley <dgilhooley@nvidia.com> | 2018-05-23 13:13:15 -0400 |
|---|---|---|
| committer | mobile promotions <svcmobile_promotions@nvidia.com> | 2018-06-07 19:23:24 -0400 |
| commit | ca7c5d4bf66b245fc3821640256a39115bb6abf4 (patch) | |
| tree | 8bafa96162aca3f4429d12dd3502b3a90c2a3d51 | |
| parent | 99f5166af5eb515c63d03488c1b1a4cf822178a8 (diff) | |
video: tegra: nvmap: Seperate carveout functions from dev
Move carveout functions into a seperate file
for better code cohesion.
JIRA: TMM-114
Change-Id: Iad34c90616063bdac42f549218bfe412299fc354
Signed-off-by: David Gilhooley <dgilhooley@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/1728409
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Krishna Reddy <vdumpa@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
| -rw-r--r-- | drivers/video/tegra/nvmap/Makefile | 1 | ||||
| -rw-r--r-- | drivers/video/tegra/nvmap/nvmap_carveout.c | 151 | ||||
| -rw-r--r-- | drivers/video/tegra/nvmap/nvmap_dev.c | 92 |
3 files changed, 154 insertions, 90 deletions
diff --git a/drivers/video/tegra/nvmap/Makefile b/drivers/video/tegra/nvmap/Makefile index 2defaf4b6..2c045cde3 100644 --- a/drivers/video/tegra/nvmap/Makefile +++ b/drivers/video/tegra/nvmap/Makefile | |||
| @@ -23,6 +23,7 @@ obj-y += nvmap_init.o | |||
| 23 | obj-y += nvmap_tag.o | 23 | obj-y += nvmap_tag.o |
| 24 | obj-y += nvmap_mm.o | 24 | obj-y += nvmap_mm.o |
| 25 | obj-y += nvmap_stats.o | 25 | obj-y += nvmap_stats.o |
| 26 | obj-y += nvmap_carveout.o | ||
| 26 | 27 | ||
| 27 | obj-$(CONFIG_NVMAP_PAGE_POOLS) += nvmap_pp.o | 28 | obj-$(CONFIG_NVMAP_PAGE_POOLS) += nvmap_pp.o |
| 28 | 29 | ||
diff --git a/drivers/video/tegra/nvmap/nvmap_carveout.c b/drivers/video/tegra/nvmap/nvmap_carveout.c new file mode 100644 index 000000000..51134456d --- /dev/null +++ b/drivers/video/tegra/nvmap/nvmap_carveout.c | |||
| @@ -0,0 +1,151 @@ | |||
| 1 | /* | ||
| 2 | * drivers/video/tegra/nvmap/nvmap_dev.c | ||
| 3 | * | ||
| 4 | * Interface with nvmap carveouts | ||
| 5 | * | ||
| 6 | * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or modify it | ||
| 9 | * under the terms and conditions of the GNU General Public License, | ||
| 10 | * version 2, as published by the Free Software Foundation. | ||
| 11 | * | ||
| 12 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| 15 | * more details. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <linux/debugfs.h> | ||
| 19 | |||
| 20 | #include "nvmap_priv.h" | ||
| 21 | |||
| 22 | extern struct nvmap_device *nvmap_dev; | ||
| 23 | |||
| 24 | extern const struct file_operations debug_clients_fops; | ||
| 25 | extern const struct file_operations debug_allocations_fops; | ||
| 26 | extern const struct file_operations debug_all_allocations_fops; | ||
| 27 | extern const struct file_operations debug_orphan_handles_fops; | ||
| 28 | extern const struct file_operations debug_maps_fops; | ||
| 29 | |||
| 30 | int nvmap_create_carveout(const struct nvmap_platform_carveout *co) | ||
| 31 | { | ||
| 32 | int i, err = 0; | ||
| 33 | struct nvmap_carveout_node *node; | ||
| 34 | |||
| 35 | if (!nvmap_dev->heaps) { | ||
| 36 | nvmap_dev->nr_carveouts = 0; | ||
| 37 | nvmap_dev->nr_heaps = nvmap_dev->plat->nr_carveouts + 1; | ||
| 38 | nvmap_dev->heaps = kzalloc(sizeof(struct nvmap_carveout_node) * | ||
| 39 | nvmap_dev->nr_heaps, GFP_KERNEL); | ||
| 40 | if (!nvmap_dev->heaps) { | ||
| 41 | err = -ENOMEM; | ||
| 42 | pr_err("couldn't allocate carveout memory\n"); | ||
| 43 | goto out; | ||
| 44 | } | ||
| 45 | } else if (nvmap_dev->nr_carveouts >= nvmap_dev->nr_heaps) { | ||
| 46 | node = krealloc(nvmap_dev->heaps, | ||
| 47 | sizeof(*node) * (nvmap_dev->nr_carveouts + 1), | ||
| 48 | GFP_KERNEL); | ||
| 49 | if (!node) { | ||
| 50 | err = -ENOMEM; | ||
| 51 | pr_err("nvmap heap array resize failed\n"); | ||
| 52 | goto out; | ||
| 53 | } | ||
| 54 | nvmap_dev->heaps = node; | ||
| 55 | nvmap_dev->nr_heaps = nvmap_dev->nr_carveouts + 1; | ||
| 56 | } | ||
| 57 | |||
| 58 | for (i = 0; i < nvmap_dev->nr_heaps; i++) | ||
| 59 | if ((co->usage_mask != NVMAP_HEAP_CARVEOUT_IVM) && | ||
| 60 | (nvmap_dev->heaps[i].heap_bit & co->usage_mask)) { | ||
| 61 | pr_err("carveout %s already exists\n", co->name); | ||
| 62 | return -EEXIST; | ||
| 63 | } | ||
| 64 | |||
| 65 | node = &nvmap_dev->heaps[nvmap_dev->nr_carveouts]; | ||
| 66 | |||
| 67 | node->base = round_up(co->base, PAGE_SIZE); | ||
| 68 | node->size = round_down(co->size - | ||
| 69 | (node->base - co->base), PAGE_SIZE); | ||
| 70 | if (!co->size) | ||
| 71 | goto out; | ||
| 72 | |||
| 73 | node->carveout = nvmap_heap_create( | ||
| 74 | nvmap_dev->dev_user.this_device, co, | ||
| 75 | node->base, node->size, node); | ||
| 76 | |||
| 77 | if (!node->carveout) { | ||
| 78 | err = -ENOMEM; | ||
| 79 | pr_err("couldn't create %s\n", co->name); | ||
| 80 | goto out; | ||
| 81 | } | ||
| 82 | node->index = nvmap_dev->nr_carveouts; | ||
| 83 | nvmap_dev->nr_carveouts++; | ||
| 84 | node->heap_bit = co->usage_mask; | ||
| 85 | |||
| 86 | if (!IS_ERR_OR_NULL(nvmap_dev->debug_root)) { | ||
| 87 | struct dentry *heap_root = | ||
| 88 | debugfs_create_dir(co->name, nvmap_dev->debug_root); | ||
| 89 | if (!IS_ERR_OR_NULL(heap_root)) { | ||
| 90 | debugfs_create_file("clients", S_IRUGO, | ||
| 91 | heap_root, | ||
| 92 | (void *)(uintptr_t)node->heap_bit, | ||
| 93 | &debug_clients_fops); | ||
| 94 | debugfs_create_file("allocations", S_IRUGO, | ||
| 95 | heap_root, | ||
| 96 | (void *)(uintptr_t)node->heap_bit, | ||
| 97 | &debug_allocations_fops); | ||
| 98 | debugfs_create_file("all_allocations", S_IRUGO, | ||
| 99 | heap_root, | ||
| 100 | (void *)(uintptr_t)node->heap_bit, | ||
| 101 | &debug_all_allocations_fops); | ||
| 102 | debugfs_create_file("orphan_handles", S_IRUGO, | ||
| 103 | heap_root, | ||
| 104 | (void *)(uintptr_t)node->heap_bit, | ||
| 105 | &debug_orphan_handles_fops); | ||
| 106 | debugfs_create_file("maps", S_IRUGO, | ||
| 107 | heap_root, | ||
| 108 | (void *)(uintptr_t)node->heap_bit, | ||
| 109 | &debug_maps_fops); | ||
| 110 | nvmap_heap_debugfs_init(heap_root, | ||
| 111 | node->carveout); | ||
| 112 | } | ||
| 113 | } | ||
| 114 | out: | ||
| 115 | return err; | ||
| 116 | } | ||
| 117 | |||
| 118 | static | ||
| 119 | struct nvmap_heap_block *do_nvmap_carveout_alloc(struct nvmap_client *client, | ||
| 120 | struct nvmap_handle *handle, | ||
| 121 | unsigned long type, | ||
| 122 | phys_addr_t *start) | ||
| 123 | { | ||
| 124 | struct nvmap_carveout_node *co_heap; | ||
| 125 | struct nvmap_device *dev = nvmap_dev; | ||
| 126 | int i; | ||
| 127 | |||
| 128 | for (i = 0; i < dev->nr_carveouts; i++) { | ||
| 129 | struct nvmap_heap_block *block; | ||
| 130 | co_heap = &dev->heaps[i]; | ||
| 131 | |||
| 132 | if (!(co_heap->heap_bit & type)) | ||
| 133 | continue; | ||
| 134 | |||
| 135 | if (type & NVMAP_HEAP_CARVEOUT_IVM) | ||
| 136 | handle->size = ALIGN(handle->size, NVMAP_IVM_ALIGNMENT); | ||
| 137 | |||
| 138 | block = nvmap_heap_alloc(co_heap->carveout, handle, start); | ||
| 139 | if (block) | ||
| 140 | return block; | ||
| 141 | } | ||
| 142 | return NULL; | ||
| 143 | } | ||
| 144 | |||
| 145 | struct nvmap_heap_block *nvmap_carveout_alloc(struct nvmap_client *client, | ||
| 146 | struct nvmap_handle *handle, | ||
| 147 | unsigned long type, | ||
| 148 | phys_addr_t *start) | ||
| 149 | { | ||
| 150 | return do_nvmap_carveout_alloc(client, handle, type, start); | ||
| 151 | } | ||
diff --git a/drivers/video/tegra/nvmap/nvmap_dev.c b/drivers/video/tegra/nvmap/nvmap_dev.c index 34f1e68d4..65c921450 100644 --- a/drivers/video/tegra/nvmap/nvmap_dev.c +++ b/drivers/video/tegra/nvmap/nvmap_dev.c | |||
| @@ -266,7 +266,7 @@ struct nvmap_handle *nvmap_validate_get(struct nvmap_handle *id) | |||
| 266 | return NULL; | 266 | return NULL; |
| 267 | } | 267 | } |
| 268 | 268 | ||
| 269 | static const struct file_operations debug_handles_by_pid_fops; | 269 | const struct file_operations debug_handles_by_pid_fops; |
| 270 | 270 | ||
| 271 | struct nvmap_pid_data { | 271 | struct nvmap_pid_data { |
| 272 | struct rb_node node; | 272 | struct rb_node node; |
| @@ -699,7 +699,7 @@ static int nvmap_debug_##name##_open(struct inode *inode, \ | |||
| 699 | inode->i_private); \ | 699 | inode->i_private); \ |
| 700 | } \ | 700 | } \ |
| 701 | \ | 701 | \ |
| 702 | static const struct file_operations debug_##name##_fops = { \ | 702 | const struct file_operations debug_##name##_fops = { \ |
| 703 | .open = nvmap_debug_##name##_open, \ | 703 | .open = nvmap_debug_##name##_open, \ |
| 704 | .read = seq_read, \ | 704 | .read = seq_read, \ |
| 705 | .llseek = seq_lseek, \ | 705 | .llseek = seq_lseek, \ |
| @@ -1362,94 +1362,6 @@ ulong nvmap_iovmm_get_used_pages(void) | |||
| 1362 | return total >> PAGE_SHIFT; | ||
