tlk_driver: use dma_alloc_coherent for uncached mem
Chris Johnson [Tue, 23 Jul 2013 18:20:34 +0000 (11:20 -0700)]
Instead of relying on change page attribute calls, instead use DMA
routines to get uncached mem. This will go away in the near future
when we can map these buffers directly in the kernel.

Change-Id: I6a375f2b1b09f987deae8a61e0907209b90c870e
Signed-off-by: Chris Johnson <cwj@nvidia.com>
Reviewed-on: http://git-master/r/252523
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Aaron Gamble <jgamble@nvidia.com>
Reviewed-by: Bharat Nihalani <bnihalani@nvidia.com>
Tested-by: Aaron Gamble <jgamble@nvidia.com>

security/tlk_driver/ote_device.c
security/tlk_driver/ote_protocol.h

index 44d8a09..5c5447b 100644 (file)
@@ -28,6 +28,7 @@
 #include <asm/cacheflush.h>
 #include <asm/outercache.h>
 #include <linux/list.h>
+#include <linux/dma-mapping.h>
 
 #include "ote_protocol.h"
 
@@ -55,22 +56,19 @@ u32 notrace tegra_read_cycle(void)
 
 static int te_create_free_cmd_list(struct tlk_device *dev)
 {
-       struct page *te_cmd_pages;
-       int cmd_desc_count = 0, ret = 0;
+       int cmd_desc_count, ret = 0;
        struct te_cmd_req_desc *req_desc;
        int bitmap_size;
 
-       te_cmd_pages = alloc_pages(GFP_KERNEL, get_count_order(2));
-       if (!te_cmd_pages) {
+       dev->req_addr = dma_alloc_coherent(NULL, PAGE_SIZE,
+                               &dev->req_addr_phys, GFP_KERNEL);
+       dev->param_addr = dma_alloc_coherent(NULL, PAGE_SIZE,
+                               &dev->param_addr_phys, GFP_KERNEL);
+       if ((dev->req_addr == NULL) || (dev->param_addr == NULL)) {
                ret = -ENOMEM;
                goto error;
        }
 
-       /* first 4KB page is request freelist, second is param freelist */
-       dev->req_addr = (unsigned long) page_address(te_cmd_pages);
-       dev->param_addr = (struct te_oper_param *)(dev->req_addr + PAGE_SIZE);
-       set_memory_uc(dev->req_addr, 2);
-
        /* alloc param bitmap allocator */
        bitmap_size = BITS_TO_LONGS(TE_PARAM_MAX) * sizeof(long);
        dev->param_bitmap = kzalloc(bitmap_size, GFP_KERNEL);
@@ -84,8 +82,7 @@ static int te_create_free_cmd_list(struct tlk_device *dev)
                        ret = -ENOMEM;
                        goto error;
                }
-               req_desc->req_addr = dev->req_addr +
-                       sizeof(struct te_request) * cmd_desc_count;
+               req_desc->req_addr = dev->req_addr + cmd_desc_count;
                INIT_LIST_HEAD(&(req_desc->list));
 
                /* Add the cmd param descriptor to free list */
@@ -162,7 +159,7 @@ static void __attribute__((unused)) te_print_cmd_list(
                if (!(list_empty(&(dev->free_cmd_list)))) {
                        list_for_each_entry(param_desc, &(dev->free_cmd_list),
                                        list)
-                               pr_info("Phys addr for cmd req desc (%lx)\n",
+                               pr_info("Phys addr for cmd req desc (%p)\n",
                                        param_desc->req_addr);
                }
        } else {
@@ -170,7 +167,7 @@ static void __attribute__((unused)) te_print_cmd_list(
                if (!(list_empty(&(dev->used_cmd_list)))) {
                        list_for_each_entry(param_desc, &(dev->used_cmd_list),
                                        list)
-                               pr_info("Phys addr for cmd req desc (%lx)\n",
+                               pr_info("Phys addr for cmd req desc (%p)\n",
                                        param_desc->req_addr);
                }
        }
@@ -301,7 +298,7 @@ static long te_handle_trustedapp_ioctl(struct file *file,
                        goto error;
                }
 
-               request = (struct te_request *)cmd_desc->req_addr;
+               request = cmd_desc->req_addr;
                memset(request, 0, sizeof(struct te_request));
 
                request->params = params;
@@ -330,7 +327,7 @@ static long te_handle_trustedapp_ioctl(struct file *file,
                        goto error;
                }
 
-               request = (struct te_request *)cmd_desc->req_addr;
+               request = cmd_desc->req_addr;
                memset(request, 0, sizeof(struct te_request));
 
                /* close session cannot fail */
@@ -352,7 +349,7 @@ static long te_handle_trustedapp_ioctl(struct file *file,
                        goto error;
                }
 
-               request = (struct te_request *)cmd_desc->req_addr;
+               request = cmd_desc->req_addr;
                memset(request, 0, sizeof(struct te_request));
 
                request->params = params;
index 79224e1..531406e 100644 (file)
@@ -45,8 +45,11 @@ extern uint32_t tlk_extended_smc(uint32_t *args);
 extern void tlk_irq_handler(void);
 
 struct tlk_device {
-       unsigned long req_addr;
+       struct te_request *req_addr;
+       dma_addr_t req_addr_phys;
        struct te_oper_param *param_addr;
+       dma_addr_t param_addr_phys;
+
        unsigned long *param_bitmap;
 
        struct list_head used_cmd_list;
@@ -54,7 +57,7 @@ struct tlk_device {
 };
 
 struct te_cmd_req_desc {
-       unsigned long req_addr;
+       struct te_request *req_addr;
        struct list_head list;
 };