]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/netapi.git/commitdiff
port module to 4.1.y kernel
authorVitaly Andrianov <vitalya@ti.com>
Tue, 8 Mar 2016 00:37:08 +0000 (19:37 -0500)
committerTinku Mannan <tmannan@ti.com>
Mon, 14 Mar 2016 18:13:59 +0000 (14:13 -0400)
The new kernel changes way to work with dma addresses.
While 3.10 kernel sets the dma mask 0x87fffffff for KS2 SOC,
and that was the default settings, the 4.1 kernel has 32 bit dma mask
and expects the proper dma_pfn_offset. The offset is 0x780000 for KS2
SOCs. In that module we set the offset and mask explicitly.

Signed-off-by: Vitaly Andrianov <vitalya@ti.com>
ti/runtime/hplib/module/hplibmod.c

index af44a5bef5196cd08e61e1fe705513357c9ded99..c4c312741e2e316977f72fc53bc700cbc4641bfd 100755 (executable)
@@ -308,25 +308,11 @@ static int __init hplibmod_init_module(void)
     
      __D("init\n");
 
-    /* allocate space from CMA */
-    cpuAddr = dma_alloc_coherent(NULL,
-                                 memSize,
-                                 &dmaAddr, 
-                                 GFP_KERNEL | GFP_DMA);
-
-    if (!cpuAddr) {
-        __E("Error allocating from CMA for size 0x%x\n", memSize);
-        return -ENOMEM;
-    } else {
-        __D("hplibmod_init_module: Allocated 0x%x size memory from CMA.\n",memSize);
-        __D("hplibmod_init_module: dmaAddr %#llx\n", (long long)dmaAddr);
-    }
     hplibmod_major = register_chrdev(0, HPLIBMOD_DEVNAME, &hplibmod_fxns);
 
     if (hplibmod_major < 0) {
         __E("Failed to allocate major number.\n");
-        ret = -ENODEV;
-        goto cleanup_mem;
+        return -ENODEV;
     }
 
     __D("Allocated major number: %d\n", hplibmod_major);
@@ -338,8 +324,10 @@ static int __init hplibmod_init_module(void)
         goto cleanup_dev;
     }
 
-    hplib_dev = device_create(hplibmod_class, NULL, MKDEV(hplibmod_major, 0), NULL,
-                  HPLIBMOD_DEVNAME);
+    hplib_dev = device_create(hplibmod_class, NULL, MKDEV(hplibmod_major, 0),
+                             NULL, HPLIBMOD_DEVNAME);
+    hplib_dev->coherent_dma_mask = DMA_BIT_MASK(32);
+    hplib_dev->dma_pfn_offset = 0x780000UL;
 
     if (IS_ERR(hplib_dev)) {
         __E("Error creating hplib device .\n");
@@ -349,14 +337,25 @@ static int __init hplibmod_init_module(void)
     ret = device_create_file(hplib_dev,&dev_attr_hplib);
     WARN_ON(ret < 0);
 
+    /* allocate space from CMA */
+    cpuAddr = dma_alloc_coherent(hplib_dev, memSize, &dmaAddr,
+                                GFP_KERNEL | GFP_DMA);
+
+    if (!cpuAddr) {
+        __E("Error allocating from CMA for size 0x%x\n", memSize);
+        ret = -ENOMEM;
+       goto cleanup_dev;
+    } else {
+        __D("hplibmod_init_module: Allocated 0x%x size memory from CMA.\n",memSize);
+        __D("hplibmod_init_module: dmaAddr %#llx\n", (long long)dmaAddr);
+    }
+
     __D("module loaded\n");
 
     return 0;
 
 cleanup_dev:
     unregister_chrdev(hplibmod_major, HPLIBMOD_DEVNAME);
-cleanup_mem:
-    dma_free_coherent(NULL, memSize, cpuAddr, dmaAddr);
 
     return ret;
 }
@@ -368,14 +367,14 @@ cleanup_mem:
  *********************************************************************************/
 static void __exit hplibmod_cleanup_module(void)
 {
+    /* Free CMA buffer */
+     dma_free_coherent(hplib_dev, memSize, cpuAddr, dmaAddr);
+
     /* Remove netapi device */
     device_destroy(hplibmod_class, MKDEV(hplibmod_major, 0));
     unregister_chrdev(hplibmod_major, HPLIBMOD_DEVNAME);
     class_destroy(hplibmod_class);
 
-    /* Free CMA buffer */
-    dma_free_coherent(NULL, memSize, cpuAddr, dmaAddr);
-
     __D("module unloaded\n");
     return;
 }