summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/common/mm/comptags.c
diff options
context:
space:
mode:
authorAlex Waterman <alexw@nvidia.com>2017-09-07 18:27:55 -0400
committermobile promotions <svcmobile_promotions@nvidia.com>2017-10-18 19:00:37 -0400
commitb3446bc0b6fca6cb992667f80a95f8503b6a652a (patch)
tree9882c36bfaef83da9d0a6eefec5e8c3564b93cea /drivers/gpu/nvgpu/common/mm/comptags.c
parentbee9c830c7898ceebf8c396b40598350229a7203 (diff)
gpu: nvgpu: Move dma_buf usage from mm_gk20a.c
Move most of the dma_buf usage present in the mm_gk20a.c code out to Linux specific code and some commom/mm code. There's two primary groups of code: 1. dma_buf priv field code (for holding comptag data) 2. Comptag usage that relies on dma_buf pointers For (1) the dma_buf code was simply moved to common/linux/dmabuf.c since most of this code is clearly Linux specific. The comptag code was a bit more complicated since there is two parts to the comptag code. Firstly there's the code that manages the comptag memory. This is essentially a simple allocator. This was moved to common/mm/comptags.c since it can be shared across all chips. The second set of code is moved to common/linux/comptags.c since it is the interface between dma_bufs and the comptag memory. Two other fixes were done as well: - Add struct gk20a to the comptag allocator init so that the proper nvgpu_vzalloc() function could be used. - Add necessary includes to common/linux/vm_priv.h. JIRA NVGPU-30 JIRA NVGPU-138 Change-Id: I96c57f2763e5ebe18a2f2ee4b33e0e1a2597848c Signed-off-by: Alex Waterman <alexw@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1566628 Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/common/mm/comptags.c')
-rw-r--r--drivers/gpu/nvgpu/common/mm/comptags.c95
1 files changed, 95 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/common/mm/comptags.c b/drivers/gpu/nvgpu/common/mm/comptags.c
new file mode 100644
index 00000000..01ab646a
--- /dev/null
+++ b/drivers/gpu/nvgpu/common/mm/comptags.c
@@ -0,0 +1,95 @@
1/*
2 * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 */
22
23#include <nvgpu/bitops.h>
24#include <nvgpu/comptags.h>
25
26#include "gk20a/gk20a.h"
27
28int gk20a_comptaglines_alloc(struct gk20a_comptag_allocator *allocator,
29 u32 *offset, u32 len)
30{
31 unsigned long addr;
32 int err = 0;
33
34 nvgpu_mutex_acquire(&allocator->lock);
35 addr = bitmap_find_next_zero_area(allocator->bitmap, allocator->size,
36 0, len, 0);
37 if (addr < allocator->size) {
38 /* number zero is reserved; bitmap base is 1 */
39 *offset = 1 + addr;
40 bitmap_set(allocator->bitmap, addr, len);
41 } else {
42 err = -ENOMEM;
43 }
44 nvgpu_mutex_release(&allocator->lock);
45
46 return err;
47}
48
49void gk20a_comptaglines_free(struct gk20a_comptag_allocator *allocator,
50 u32 offset, u32 len)
51{
52 /* number zero is reserved; bitmap base is 1 */
53 u32 addr = offset - 1;
54
55 WARN_ON(offset == 0);
56 WARN_ON(addr > allocator->size);
57 WARN_ON(addr + len > allocator->size);
58
59 nvgpu_mutex_acquire(&allocator->lock);
60 bitmap_clear(allocator->bitmap, addr, len);
61 nvgpu_mutex_release(&allocator->lock);
62}
63
64int gk20a_comptag_allocator_init(struct gk20a *g,
65 struct gk20a_comptag_allocator *allocator,
66 unsigned long size)
67{
68 nvgpu_mutex_init(&allocator->lock);
69
70 /*
71 * 0th comptag is special and is never used. The base for this bitmap
72 * is 1, and its size is one less than the size of comptag store.
73 */
74 size--;
75 allocator->bitmap = nvgpu_vzalloc(g,
76 BITS_TO_LONGS(size) * sizeof(long));
77 if (!allocator->bitmap)
78 return -ENOMEM;
79
80 allocator->size = size;
81
82 return 0;
83}
84
85void gk20a_comptag_allocator_destroy(struct gk20a *g,
86 struct gk20a_comptag_allocator *allocator)
87{
88 /*
89 * called only when exiting the driver (gk20a_remove, or unwinding the
90 * init stage); no users should be active, so taking the mutex is
91 * unnecessary here.
92 */
93 allocator->size = 0;
94 nvgpu_vfree(allocator->g, allocator->bitmap);
95}