Merge branch 'work.get_user_pages_fast' of git://git.kernel.org/pub/scm/linux/kernel...
[sfrench/cifs-2.6.git] / drivers / staging / vc04_services / interface / vchiq_arm / vchiq_2835_arm.c
index cd2b19f335d8d1466855cd515d8ab80b31f9716c..315b49c1de3bb323f4383e4ba8acb3e3ded422b1 100644 (file)
 #define BELL0  0x00
 #define BELL2  0x08
 
-typedef struct vchiq_2835_state_struct {
+struct vchiq_2835_state {
        int inited;
        VCHIQ_ARM_STATE_T arm_state;
-} VCHIQ_2835_ARM_STATE_T;
+};
 
 struct vchiq_pagelist_info {
        PAGELIST_T *pagelist;
@@ -84,8 +84,6 @@ static char *g_free_fragments;
 static struct semaphore g_free_fragments_sema;
 static struct device *g_dev;
 
-extern int vchiq_arm_log_level;
-
 static DEFINE_SEMAPHORE(g_free_fragments_mutex);
 
 static irqreturn_t
@@ -205,25 +203,31 @@ VCHIQ_STATUS_T
 vchiq_platform_init_state(VCHIQ_STATE_T *state)
 {
        VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
+       struct vchiq_2835_state *platform_state;
+
+       state->platform_state = kzalloc(sizeof(*platform_state), GFP_KERNEL);
+       platform_state = (struct vchiq_2835_state *)state->platform_state;
+
+       platform_state->inited = 1;
+       status = vchiq_arm_init_state(state, &platform_state->arm_state);
 
-       state->platform_state = kzalloc(sizeof(VCHIQ_2835_ARM_STATE_T), GFP_KERNEL);
-       ((VCHIQ_2835_ARM_STATE_T *)state->platform_state)->inited = 1;
-       status = vchiq_arm_init_state(state, &((VCHIQ_2835_ARM_STATE_T *)state->platform_state)->arm_state);
        if (status != VCHIQ_SUCCESS)
-       {
-               ((VCHIQ_2835_ARM_STATE_T *)state->platform_state)->inited = 0;
-       }
+               platform_state->inited = 0;
+
        return status;
 }
 
 VCHIQ_ARM_STATE_T*
 vchiq_platform_get_arm_state(VCHIQ_STATE_T *state)
 {
-       if (!((VCHIQ_2835_ARM_STATE_T *)state->platform_state)->inited)
-       {
+       struct vchiq_2835_state *platform_state;
+
+       platform_state   = (struct vchiq_2835_state *)state->platform_state;
+
+       if (!platform_state->inited)
                BUG();
-       }
-       return &((VCHIQ_2835_ARM_STATE_T *)state->platform_state)->arm_state;
+
+       return &platform_state->arm_state;
 }
 
 void
@@ -381,12 +385,12 @@ cleanup_pagelistinfo(struct vchiq_pagelist_info *pagelistinfo)
 }
 
 /* There is a potential problem with partial cache lines (pages?)
-** at the ends of the block when reading. If the CPU accessed anything in
-** the same line (page?) then it may have pulled old data into the cache,
-** obscuring the new data underneath. We can solve this by transferring the
-** partial cache lines separately, and allowing the ARM to copy into the
-** cached area.
-*/
+ * at the ends of the block when reading. If the CPU accessed anything in
+ * the same line (page?) then it may have pulled old data into the cache,
+ * obscuring the new data underneath. We can solve this by transferring the
+ * partial cache lines separately, and allowing the ARM to copy into the
+ * cached area.
+ */
 
 static struct vchiq_pagelist_info *
 create_pagelist(char __user *buf, size_t count, unsigned short type)
@@ -412,15 +416,15 @@ create_pagelist(char __user *buf, size_t count, unsigned short type)
                        sizeof(struct vchiq_pagelist_info);
 
        /* Allocate enough storage to hold the page pointers and the page
-       ** list
-       */
+        * list
+        */
        pagelist = dma_zalloc_coherent(g_dev,
                                       pagelist_size,
                                       &dma_addr,
                                       GFP_KERNEL);
 
-       vchiq_log_trace(vchiq_arm_log_level, "create_pagelist - %pK",
-                       pagelist);
+       vchiq_log_trace(vchiq_arm_log_level, "%s - %pK", __func__, pagelist);
+
        if (!pagelist)
                return NULL;
 
@@ -477,9 +481,8 @@ create_pagelist(char __user *buf, size_t count, unsigned short type)
 
                if (actual_pages != num_pages) {
                        vchiq_log_info(vchiq_arm_log_level,
-                                      "create_pagelist - only %d/%d pages locked",
-                                      actual_pages,
-                                      num_pages);
+                                      "%s - only %d/%d pages locked",
+                                      __func__, actual_pages, num_pages);
 
                        /* This is probably due to the process being killed */
                        while (actual_pages > 0)
@@ -606,18 +609,20 @@ free_pagelist(struct vchiq_pagelist_info *pagelistinfo,
                        if (head_bytes > actual)
                                head_bytes = actual;
 
-                       memcpy((char *)page_address(pages[0]) +
+                       memcpy((char *)kmap(pages[0]) +
                                pagelist->offset,
                                fragments,
                                head_bytes);
+                       kunmap(pages[0]);
                }
                if ((actual >= 0) && (head_bytes < actual) &&
                        (tail_bytes != 0)) {
-                       memcpy((char *)page_address(pages[num_pages - 1]) +
+                       memcpy((char *)kmap(pages[num_pages - 1]) +
                                ((pagelist->offset + actual) &
                                (PAGE_SIZE - 1) & ~(g_cache_line_size - 1)),
                                fragments + g_cache_line_size,
                                tail_bytes);
+                       kunmap(pages[num_pages - 1]);
                }
 
                down(&g_free_fragments_mutex);