diff options
author | Deepak Nibade <dnibade@nvidia.com> | 2014-06-05 07:30:20 -0400 |
---|---|---|
committer | Dan Willemsen <dwillemsen@nvidia.com> | 2015-03-18 15:10:11 -0400 |
commit | 725b56f71aa321816368d54332e68a2e93eda6fa (patch) | |
tree | 74c9a0faf7f8e060145b197d84831e8d9a87a6a3 /drivers/gpu | |
parent | bea4bb915a4a15042057a21170bcc2058f2bfb16 (diff) |
gpu: nvgpu: add APIs to allocate/free dummy secure buffer
Add APIs to allocate and free dummy secure buffer of size PAGE_SIZE.
Also, fix small errors during secure memory alloc/free.
Bug 1487804
Change-Id: If078116fb973e81bfcee054b900c09a313e389c6
Signed-off-by: Deepak Nibade <dnibade@nvidia.com>
Reviewed-on: http://git-master/r/421700
(cherry picked from commit 5391515dab27cc88b921cf81913085dea98197e0)
Reviewed-on: http://git-master/r/419609
GVS: Gerrit_Virtual_Submit
Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com>
Diffstat (limited to 'drivers/gpu')
-rw-r--r-- | drivers/gpu/nvgpu/gk20a/platform_gk20a.h | 15 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/gk20a/platform_gk20a_tegra.c | 38 |
2 files changed, 49 insertions, 4 deletions
diff --git a/drivers/gpu/nvgpu/gk20a/platform_gk20a.h b/drivers/gpu/nvgpu/gk20a/platform_gk20a.h index 49f386d8..4e454140 100644 --- a/drivers/gpu/nvgpu/gk20a/platform_gk20a.h +++ b/drivers/gpu/nvgpu/gk20a/platform_gk20a.h | |||
@@ -20,12 +20,20 @@ | |||
20 | 20 | ||
21 | #include <linux/platform_device.h> | 21 | #include <linux/platform_device.h> |
22 | #include <linux/pm_domain.h> | 22 | #include <linux/pm_domain.h> |
23 | #include <linux/dma-attrs.h> | ||
23 | 24 | ||
24 | struct gk20a; | 25 | struct gk20a; |
25 | struct channel_gk20a; | 26 | struct channel_gk20a; |
26 | struct gr_ctx_buffer_desc; | 27 | struct gr_ctx_buffer_desc; |
27 | struct gk20a_scale_profile; | 28 | struct gk20a_scale_profile; |
28 | 29 | ||
30 | struct secure_page_buffer { | ||
31 | void (*destroy)(struct platform_device *, struct secure_page_buffer *); | ||
32 | size_t size; | ||
33 | u64 iova; | ||
34 | struct dma_attrs attrs; | ||
35 | }; | ||
36 | |||
29 | struct gk20a_platform { | 37 | struct gk20a_platform { |
30 | #ifdef CONFIG_TEGRA_GK20A | 38 | #ifdef CONFIG_TEGRA_GK20A |
31 | u32 syncpt_base; | 39 | u32 syncpt_base; |
@@ -79,6 +87,13 @@ struct gk20a_platform { | |||
79 | struct gr_ctx_buffer_desc *desc, | 87 | struct gr_ctx_buffer_desc *desc, |
80 | size_t size); | 88 | size_t size); |
81 | 89 | ||
90 | /* Function to allocate a secure buffer of PAGE_SIZE at probe time. | ||
91 | * This is also helpful to trigger secure memory resizing | ||
92 | * while GPU is off | ||
93 | */ | ||
94 | int (*secure_page_alloc)(struct platform_device *dev); | ||
95 | struct secure_page_buffer secure_buffer; | ||
96 | |||
82 | /* Device is going to be suspended */ | 97 | /* Device is going to be suspended */ |
83 | int (*suspend)(struct device *); | 98 | int (*suspend)(struct device *); |
84 | 99 | ||
diff --git a/drivers/gpu/nvgpu/gk20a/platform_gk20a_tegra.c b/drivers/gpu/nvgpu/gk20a/platform_gk20a_tegra.c index 813053e0..9f2a7971 100644 --- a/drivers/gpu/nvgpu/gk20a/platform_gk20a_tegra.c +++ b/drivers/gpu/nvgpu/gk20a/platform_gk20a_tegra.c | |||
@@ -93,12 +93,41 @@ int FXDIV(int x, int y) | |||
93 | return (x << pos) / y; | 93 | return (x << pos) / y; |
94 | } | 94 | } |
95 | 95 | ||
96 | static void gk20a_tegra_secure_page_destroy(struct platform_device *pdev, | ||
97 | struct secure_page_buffer *secure_buffer) | ||
98 | { | ||
99 | dma_free_attrs(&tegra_vpr_dev, secure_buffer->size, | ||
100 | (void *)(uintptr_t)secure_buffer->iova, | ||
101 | secure_buffer->iova, &secure_buffer->attrs); | ||
102 | } | ||
103 | |||
104 | static int gk20a_tegra_secure_page_alloc(struct platform_device *pdev) | ||
105 | { | ||
106 | struct gk20a_platform *platform = platform_get_drvdata(pdev); | ||
107 | struct secure_page_buffer *secure_buffer = &platform->secure_buffer; | ||
108 | DEFINE_DMA_ATTRS(attrs); | ||
109 | dma_addr_t iova; | ||
110 | size_t size = PAGE_SIZE; | ||
111 | |||
112 | (void)dma_alloc_attrs(&tegra_vpr_dev, size, &iova, | ||
113 | DMA_MEMORY_NOMAP, &attrs); | ||
114 | if (dma_mapping_error(&tegra_vpr_dev, iova)) | ||
115 | return -ENOMEM; | ||
116 | |||
117 | secure_buffer->size = size; | ||
118 | secure_buffer->iova = iova; | ||
119 | secure_buffer->attrs = attrs; | ||
120 | secure_buffer->destroy = gk20a_tegra_secure_page_destroy; | ||
121 | |||
122 | return 0; | ||
123 | } | ||
124 | |||
96 | static void gk20a_tegra_secure_destroy(struct platform_device *pdev, | 125 | static void gk20a_tegra_secure_destroy(struct platform_device *pdev, |
97 | struct gr_ctx_buffer_desc *desc) | 126 | struct gr_ctx_buffer_desc *desc) |
98 | { | 127 | { |
99 | gk20a_free_sgtable(&desc->sgt); | 128 | gk20a_free_sgtable(&desc->sgt); |
100 | dma_free_attrs(&tegra_vpr_dev, desc->size, | 129 | dma_free_attrs(&tegra_vpr_dev, desc->size, |
101 | (void *)(uintptr_t)&desc->iova, | 130 | (void *)(uintptr_t)desc->iova, |
102 | desc->iova, &desc->attrs); | 131 | desc->iova, &desc->attrs); |
103 | } | 132 | } |
104 | 133 | ||
@@ -113,10 +142,8 @@ static int gk20a_tegra_secure_alloc(struct platform_device *pdev, | |||
113 | struct page *page; | 142 | struct page *page; |
114 | int err = 0; | 143 | int err = 0; |
115 | 144 | ||
116 | dma_set_attr(DMA_ATTR_NO_KERNEL_MAPPING, &attrs); | ||
117 | |||
118 | (void)dma_alloc_attrs(&tegra_vpr_dev, size, &iova, | 145 | (void)dma_alloc_attrs(&tegra_vpr_dev, size, &iova, |
119 | GFP_KERNEL, &attrs); | 146 | DMA_MEMORY_NOMAP, &attrs); |
120 | if (dma_mapping_error(&tegra_vpr_dev, iova)) | 147 | if (dma_mapping_error(&tegra_vpr_dev, iova)) |
121 | return -ENOMEM; | 148 | return -ENOMEM; |
122 | 149 | ||
@@ -524,6 +551,7 @@ struct gk20a_platform t132_gk20a_tegra_platform = { | |||
524 | .qos_id = PM_QOS_GPU_FREQ_MIN, | 551 | .qos_id = PM_QOS_GPU_FREQ_MIN, |
525 | 552 | ||
526 | .secure_alloc = gk20a_tegra_secure_alloc, | 553 | .secure_alloc = gk20a_tegra_secure_alloc, |
554 | .secure_page_alloc = gk20a_tegra_secure_page_alloc, | ||
527 | .dump_platform_dependencies = gk20a_tegra_debug_dump, | 555 | .dump_platform_dependencies = gk20a_tegra_debug_dump, |
528 | }; | 556 | }; |
529 | 557 | ||
@@ -551,6 +579,7 @@ struct gk20a_platform gk20a_tegra_platform = { | |||
551 | .qos_id = PM_QOS_GPU_FREQ_MIN, | 579 | .qos_id = PM_QOS_GPU_FREQ_MIN, |
552 | 580 | ||
553 | .secure_alloc = gk20a_tegra_secure_alloc, | 581 | .secure_alloc = gk20a_tegra_secure_alloc, |
582 | .secure_page_alloc = gk20a_tegra_secure_page_alloc, | ||
554 | .dump_platform_dependencies = gk20a_tegra_debug_dump, | 583 | .dump_platform_dependencies = gk20a_tegra_debug_dump, |
555 | }; | 584 | }; |
556 | 585 | ||
@@ -574,6 +603,7 @@ struct gk20a_platform gm20b_tegra_platform = { | |||
574 | .qos_id = PM_QOS_GPU_FREQ_MIN, | 603 | .qos_id = PM_QOS_GPU_FREQ_MIN, |
575 | 604 | ||
576 | .secure_alloc = gk20a_tegra_secure_alloc, | 605 | .secure_alloc = gk20a_tegra_secure_alloc, |
606 | .secure_page_alloc = gk20a_tegra_secure_page_alloc, | ||
577 | .dump_platform_dependencies = gk20a_tegra_debug_dump, | 607 | .dump_platform_dependencies = gk20a_tegra_debug_dump, |
578 | }; | 608 | }; |
579 | 609 | ||