diff options
author | Alex Waterman <alexw@nvidia.com> | 2017-10-19 18:34:47 -0400 |
---|---|---|
committer | mobile promotions <svcmobile_promotions@nvidia.com> | 2017-11-10 18:46:58 -0500 |
commit | 8428c82c816f361ce7bbb1fe4804f350b8cbea2f (patch) | |
tree | 7a1cf630fd9de6ed2acf33d6b9e2085d074a6906 | |
parent | ee4970a33f41b56f2ada6a0b5ab6f9c400e39d88 (diff) |
gpu: nvgpu: Add nvgpu_os_buffer
Add a generic nvgpu_os_buffer type, defined by each OS, to abstract
a "user" buffer. This allows the comptag interface to be used in the
core code.
The end goal of this patch is to allow the OS specific mapping code
to call a generic mapping function that handles most of the mapping
logic. The problem is a lot of the logic involves comptags which are
highly dependent on the operating systems buffer management scheme.
With this, each OS can implement the buffer comptag mechanics
however it wishes without the core MM code caring.
JIRA NVGPU-30
JIRA NVGPU-223
Change-Id: Iaf64bc52e01ef3f262b4f8f9173a84384db7dc3e
Signed-off-by: Alex Waterman <alexw@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/1583986
Reviewed-by: Automatic_Commit_Validation_User
GVS: Gerrit_Virtual_Submit
Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/cde.c | 6 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/comptags.c | 13 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/dmabuf.h | 13 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/vm.c | 8 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/comptags.h | 12 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/linux/vm.h | 6 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/vm.h | 6 |
7 files changed, 41 insertions, 23 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/cde.c b/drivers/gpu/nvgpu/common/linux/cde.c index 5063ba88..003da143 100644 --- a/drivers/gpu/nvgpu/common/linux/cde.c +++ b/drivers/gpu/nvgpu/common/linux/cde.c | |||
@@ -973,6 +973,10 @@ __releases(&l->cde_app->mutex) | |||
973 | struct gk20a *g = &l->g; | 973 | struct gk20a *g = &l->g; |
974 | struct gk20a_cde_ctx *cde_ctx = NULL; | 974 | struct gk20a_cde_ctx *cde_ctx = NULL; |
975 | struct gk20a_comptags comptags; | 975 | struct gk20a_comptags comptags; |
976 | struct nvgpu_os_buffer os_buf = { | ||
977 | compbits_scatter_buf, | ||
978 | dev_from_gk20a(g) | ||
979 | }; | ||
976 | u64 mapped_compbits_offset = 0; | 980 | u64 mapped_compbits_offset = 0; |
977 | u64 compbits_size = 0; | 981 | u64 compbits_size = 0; |
978 | u64 mapped_scatterbuffer_offset = 0; | 982 | u64 mapped_scatterbuffer_offset = 0; |
@@ -1103,7 +1107,7 @@ __releases(&l->cde_app->mutex) | |||
1103 | } | 1107 | } |
1104 | 1108 | ||
1105 | /* store source buffer compression tags */ | 1109 | /* store source buffer compression tags */ |
1106 | gk20a_get_comptags(dev_from_gk20a(g), compbits_scatter_buf, &comptags); | 1110 | gk20a_get_comptags(&os_buf, &comptags); |
1107 | cde_ctx->surf_param_offset = comptags.offset; | 1111 | cde_ctx->surf_param_offset = comptags.offset; |
1108 | cde_ctx->surf_param_lines = comptags.lines; | 1112 | cde_ctx->surf_param_lines = comptags.lines; |
1109 | 1113 | ||
diff --git a/drivers/gpu/nvgpu/common/linux/comptags.c b/drivers/gpu/nvgpu/common/linux/comptags.c index 517429d8..f55989f7 100644 --- a/drivers/gpu/nvgpu/common/linux/comptags.c +++ b/drivers/gpu/nvgpu/common/linux/comptags.c | |||
@@ -18,12 +18,15 @@ | |||
18 | 18 | ||
19 | #include <nvgpu/comptags.h> | 19 | #include <nvgpu/comptags.h> |
20 | 20 | ||
21 | #include <nvgpu/linux/vm.h> | ||
22 | |||
21 | #include "dmabuf.h" | 23 | #include "dmabuf.h" |
22 | 24 | ||
23 | void gk20a_get_comptags(struct device *dev, struct dma_buf *dmabuf, | 25 | void gk20a_get_comptags(struct nvgpu_os_buffer *buf, |
24 | struct gk20a_comptags *comptags) | 26 | struct gk20a_comptags *comptags) |
25 | { | 27 | { |
26 | struct gk20a_dmabuf_priv *priv = dma_buf_get_drvdata(dmabuf, dev); | 28 | struct gk20a_dmabuf_priv *priv = dma_buf_get_drvdata(buf->dmabuf, |
29 | buf->dev); | ||
27 | 30 | ||
28 | if (!comptags) | 31 | if (!comptags) |
29 | return; | 32 | return; |
@@ -37,12 +40,12 @@ void gk20a_get_comptags(struct device *dev, struct dma_buf *dmabuf, | |||
37 | } | 40 | } |
38 | 41 | ||
39 | int gk20a_alloc_comptags(struct gk20a *g, | 42 | int gk20a_alloc_comptags(struct gk20a *g, |
40 | struct device *dev, | 43 | struct nvgpu_os_buffer *buf, |
41 | struct dma_buf *dmabuf, | ||
42 | struct gk20a_comptag_allocator *allocator, | 44 | struct gk20a_comptag_allocator *allocator, |
43 | u32 lines) | 45 | u32 lines) |
44 | { | 46 | { |
45 | struct gk20a_dmabuf_priv *priv = dma_buf_get_drvdata(dmabuf, dev); | 47 | struct gk20a_dmabuf_priv *priv = dma_buf_get_drvdata(buf->dmabuf, |
48 | buf->dev); | ||
46 | u32 ctaglines_allocsize; | 49 | u32 ctaglines_allocsize; |
47 | u32 offset; | 50 | u32 offset; |
48 | int err; | 51 | int err; |
diff --git a/drivers/gpu/nvgpu/common/linux/dmabuf.h b/drivers/gpu/nvgpu/common/linux/dmabuf.h index b4b61459..8e6c139b 100644 --- a/drivers/gpu/nvgpu/common/linux/dmabuf.h +++ b/drivers/gpu/nvgpu/common/linux/dmabuf.h | |||
@@ -48,19 +48,6 @@ struct gk20a_dmabuf_priv { | |||
48 | u64 buffer_id; | 48 | u64 buffer_id; |
49 | }; | 49 | }; |
50 | 50 | ||
51 | /* | ||
52 | * These are implemented in common/linux/comptags.c - these are dmabuf related | ||
53 | * functions though so they are defined here. They cannot be defined in | ||
54 | * <nvgpu/comptags.h> since that file must be OS agnostic. | ||
55 | */ | ||
56 | int gk20a_alloc_comptags(struct gk20a *g, | ||
57 | struct device *dev, | ||
58 | struct dma_buf *dmabuf, | ||
59 | struct gk20a_comptag_allocator *allocator, | ||
60 | u32 lines); | ||
61 | void gk20a_get_comptags(struct device *dev, struct dma_buf *dmabuf, | ||
62 | struct gk20a_comptags *comptags); | ||
63 | |||
64 | struct sg_table *gk20a_mm_pin(struct device *dev, struct dma_buf *dmabuf); | 51 | struct sg_table *gk20a_mm_pin(struct device *dev, struct dma_buf *dmabuf); |
65 | void gk20a_mm_unpin(struct device *dev, struct dma_buf *dmabuf, | 52 | void gk20a_mm_unpin(struct device *dev, struct dma_buf *dmabuf, |
66 | struct sg_table *sgt); | 53 | struct sg_table *sgt); |
diff --git a/drivers/gpu/nvgpu/common/linux/vm.c b/drivers/gpu/nvgpu/common/linux/vm.c index 006216c2..9178a0b0 100644 --- a/drivers/gpu/nvgpu/common/linux/vm.c +++ b/drivers/gpu/nvgpu/common/linux/vm.c | |||
@@ -165,6 +165,7 @@ int nvgpu_vm_map_linux(struct vm_gk20a *vm, | |||
165 | struct nvgpu_sgt *nvgpu_sgt = NULL; | 165 | struct nvgpu_sgt *nvgpu_sgt = NULL; |
166 | struct sg_table *sgt; | 166 | struct sg_table *sgt; |
167 | struct nvgpu_mapped_buf *mapped_buffer = NULL; | 167 | struct nvgpu_mapped_buf *mapped_buffer = NULL; |
168 | struct nvgpu_os_buffer os_buf = { dmabuf, dev }; | ||
168 | enum nvgpu_aperture aperture; | 169 | enum nvgpu_aperture aperture; |
169 | bool va_allocated = false; | 170 | bool va_allocated = false; |
170 | bool clear_ctags = false; | 171 | bool clear_ctags = false; |
@@ -277,11 +278,11 @@ int nvgpu_vm_map_linux(struct vm_gk20a *vm, | |||
277 | if (!vm->enable_ctag) | 278 | if (!vm->enable_ctag) |
278 | binfo.ctag_lines = 0; | 279 | binfo.ctag_lines = 0; |
279 | 280 | ||
280 | gk20a_get_comptags(dev, dmabuf, &comptags); | 281 | gk20a_get_comptags(&os_buf, &comptags); |
281 | 282 | ||
282 | if (binfo.ctag_lines && !comptags.lines) { | 283 | if (binfo.ctag_lines && !comptags.lines) { |
283 | /* allocate compression resources if needed */ | 284 | /* allocate compression resources if needed */ |
284 | err = gk20a_alloc_comptags(g, dev, dmabuf, | 285 | err = gk20a_alloc_comptags(g, &os_buf, |
285 | &g->gr.comp_tags, | 286 | &g->gr.comp_tags, |
286 | binfo.ctag_lines); | 287 | binfo.ctag_lines); |
287 | if (err) { | 288 | if (err) { |
@@ -296,8 +297,7 @@ int nvgpu_vm_map_linux(struct vm_gk20a *vm, | |||
296 | goto clean_up; | 297 | goto clean_up; |
297 | } | 298 | } |
298 | } else { | 299 | } else { |
299 | gk20a_get_comptags(dev, | 300 | gk20a_get_comptags(&os_buf, &comptags); |
300 | dmabuf, &comptags); | ||
301 | 301 | ||
302 | if (g->ops.ltc.cbc_ctrl) | 302 | if (g->ops.ltc.cbc_ctrl) |
303 | g->ops.ltc.cbc_ctrl(g, gk20a_cbc_op_clear, | 303 | g->ops.ltc.cbc_ctrl(g, gk20a_cbc_op_clear, |
diff --git a/drivers/gpu/nvgpu/include/nvgpu/comptags.h b/drivers/gpu/nvgpu/include/nvgpu/comptags.h index 6e3062ec..5482d0ce 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/comptags.h +++ b/drivers/gpu/nvgpu/include/nvgpu/comptags.h | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <nvgpu/lock.h> | 20 | #include <nvgpu/lock.h> |
21 | 21 | ||
22 | struct gk20a; | 22 | struct gk20a; |
23 | struct nvgpu_os_buffer; | ||
23 | 24 | ||
24 | struct gk20a_comptags { | 25 | struct gk20a_comptags { |
25 | u32 offset; | 26 | u32 offset; |
@@ -52,6 +53,17 @@ int gk20a_comptaglines_alloc(struct gk20a_comptag_allocator *allocator, | |||
52 | void gk20a_comptaglines_free(struct gk20a_comptag_allocator *allocator, | 53 | void gk20a_comptaglines_free(struct gk20a_comptag_allocator *allocator, |
53 | u32 offset, u32 len); | 54 | u32 offset, u32 len); |
54 | 55 | ||
56 | /* | ||
57 | * Defined by OS specific code since comptags are stored in a highly OS specific | ||
58 | * way. | ||
59 | */ | ||
60 | int gk20a_alloc_comptags(struct gk20a *g, | ||
61 | struct nvgpu_os_buffer *buf, | ||
62 | struct gk20a_comptag_allocator *allocator, | ||
63 | u32 lines); | ||
64 | void gk20a_get_comptags(struct nvgpu_os_buffer *buf, | ||
65 | struct gk20a_comptags *comptags); | ||
66 | |||
55 | 67 | ||
56 | 68 | ||
57 | #endif | 69 | #endif |
diff --git a/drivers/gpu/nvgpu/include/nvgpu/linux/vm.h b/drivers/gpu/nvgpu/include/nvgpu/linux/vm.h index dee8fa09..39deeb69 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/linux/vm.h +++ b/drivers/gpu/nvgpu/include/nvgpu/linux/vm.h | |||
@@ -33,11 +33,17 @@ | |||
33 | 33 | ||
34 | struct sg_table; | 34 | struct sg_table; |
35 | struct dma_buf; | 35 | struct dma_buf; |
36 | struct device; | ||
36 | 37 | ||
37 | struct vm_gk20a; | 38 | struct vm_gk20a; |
38 | struct vm_gk20a_mapping_batch; | 39 | struct vm_gk20a_mapping_batch; |
39 | struct nvgpu_vm_area; | 40 | struct nvgpu_vm_area; |
40 | 41 | ||
42 | struct nvgpu_os_buffer { | ||
43 | struct dma_buf *dmabuf; | ||
44 | struct device *dev; | ||
45 | }; | ||
46 | |||
41 | /* NVGPU_AS_MAP_BUFFER_FLAGS_DIRECT_KIND_CTRL must be set */ | 47 | /* NVGPU_AS_MAP_BUFFER_FLAGS_DIRECT_KIND_CTRL must be set */ |
42 | int nvgpu_vm_map_linux(struct vm_gk20a *vm, | 48 | int nvgpu_vm_map_linux(struct vm_gk20a *vm, |
43 | struct dma_buf *dmabuf, | 49 | struct dma_buf *dmabuf, |
diff --git a/drivers/gpu/nvgpu/include/nvgpu/vm.h b/drivers/gpu/nvgpu/include/nvgpu/vm.h index 10a7f7ce..b91b41e4 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/vm.h +++ b/drivers/gpu/nvgpu/include/nvgpu/vm.h | |||
@@ -107,6 +107,12 @@ struct nvgpu_mapped_buf { | |||
107 | bool va_allocated; | 107 | bool va_allocated; |
108 | }; | 108 | }; |
109 | 109 | ||
110 | /* | ||
111 | * Defined by each OS. Allows the common VM code do things to the OS specific | ||
112 | * buffer structures. | ||
113 | */ | ||
114 | struct nvgpu_os_buffer; | ||
115 | |||
110 | static inline struct nvgpu_mapped_buf * | 116 | static inline struct nvgpu_mapped_buf * |
111 | nvgpu_mapped_buf_from_buffer_list(struct nvgpu_list_node *node) | 117 | nvgpu_mapped_buf_from_buffer_list(struct nvgpu_list_node *node) |
112 | { | 118 | { |