11/*******************************************************************************
22 *
33 * Xilinx XDMA IP Core Linux Driver
4- * Copyright(c) 2015 - 2017 Xilinx, Inc.
4+ * Copyright(c) 2015 - 2020 Xilinx, Inc.
55 *
66 * This program is free software; you can redistribute it and/or modify it
77 * under the terms and conditions of the GNU General Public License,
2121 * Karen Xie <karen.xie@xilinx.com>
2222 *
2323 ******************************************************************************/
24+
2425#define pr_fmt (fmt ) KBUILD_MODNAME ":%s: " fmt, __func__
2526
2627#include <linux/ioctl.h>
2728#include "version.h"
2829#include "xdma_cdev.h"
2930#include "cdev_ctrl.h"
3031
32+ #if KERNEL_VERSION (5 , 0 , 0 ) <= LINUX_VERSION_CODE
33+ #define xlx_access_ok (X , Y , Z ) access_ok(Y, Z)
34+ #else
35+ #define xlx_access_ok (X , Y , Z ) access_ok(X, Y, Z)
36+ #endif
37+
3138/*
3239 * character device file operations for control bus (through control bridge)
3340 */
@@ -36,13 +43,13 @@ static ssize_t char_ctrl_read(struct file *fp, char __user *buf, size_t count,
3643{
3744struct xdma_cdev * xcdev = (struct xdma_cdev * )fp -> private_data ;
3845struct xdma_dev * xdev ;
39- void * reg ;
46+ void __iomem * reg ;
4047u32 w ;
4148int rv ;
4249
4350rv = xcdev_check (__func__ , xcdev , 0 );
4451if (rv < 0 )
45- return rv ;
52+ return rv ;
4653xdev = xcdev -> xdev ;
4754
4855/* only 32-bit aligned and 32-bit multiples */
@@ -52,8 +59,8 @@ static ssize_t char_ctrl_read(struct file *fp, char __user *buf, size_t count,
5259reg = xdev -> bar [xcdev -> bar ] + * pos ;
5360//w = read_register(reg);
5461w = ioread32 (reg );
55- dbg_sg ("char_ctrl_read (@%p, count=%ld, pos=%d) value = 0x%08x\n" , reg ,
56- (long )count , (int )* pos , w );
62+ dbg_sg ("%s (@%p, count=%ld, pos=%d) value = 0x%08x\n" ,
63+ __func__ , reg , (long )count , (int )* pos , w );
5764rv = copy_to_user (buf , & w , 4 );
5865if (rv )
5966dbg_sg ("Copy to userspace failed but continuing\n" );
@@ -67,13 +74,13 @@ static ssize_t char_ctrl_write(struct file *file, const char __user *buf,
6774{
6875struct xdma_cdev * xcdev = (struct xdma_cdev * )file -> private_data ;
6976struct xdma_dev * xdev ;
70- void * reg ;
77+ void __iomem * reg ;
7178u32 w ;
7279int rv ;
7380
7481rv = xcdev_check (__func__ , xcdev , 0 );
7582if (rv < 0 )
76- return rv ;
83+ return rv ;
7784xdev = xcdev -> xdev ;
7885
7986/* only 32-bit aligned and 32-bit multiples */
@@ -83,12 +90,11 @@ static ssize_t char_ctrl_write(struct file *file, const char __user *buf,
8390/* first address is BAR base plus file position offset */
8491reg = xdev -> bar [xcdev -> bar ] + * pos ;
8592rv = copy_from_user (& w , buf , 4 );
86- if (rv ) {
93+ if (rv )
8794pr_info ("copy from user failed %d/4, but continuing.\n" , rv );
88- }
8995
90- dbg_sg ("char_ctrl_write (0x%08x @%p, count=%ld, pos=%d)\n" , w , reg ,
91- (long )count , (int )* pos );
96+ dbg_sg ("%s (0x%08x @%p, count=%ld, pos=%d)\n" ,
97+ __func__ , w , reg , (long )count , (int )* pos );
9298//write_register(w, reg);
9399iowrite32 (w , reg );
94100* pos += 4 ;
@@ -133,9 +139,13 @@ long char_ctrl_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
133139
134140rv = xcdev_check (__func__ , xcdev , 0 );
135141if (rv < 0 )
136- return rv ;
137- xdev = xcdev -> xdev ;
142+ return rv ;
138143
144+ xdev = xcdev -> xdev ;
145+ if (!xdev ) {
146+ pr_info ("cmd %u, xdev NULL.\n" , cmd );
147+ return - EINVAL ;
148+ }
139149pr_info ("cmd 0x%x, xdev 0x%p, pdev 0x%p.\n" , cmd , xdev , xdev -> pdev );
140150
141151if (_IOC_TYPE (cmd ) != XDMA_IOC_MAGIC ) {
@@ -145,10 +155,10 @@ long char_ctrl_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
145155}
146156
147157if (_IOC_DIR (cmd ) & _IOC_READ )
148- result = !access_ok (VERIFY_WRITE , (void __user * )arg ,
158+ result = !xlx_access_ok (VERIFY_WRITE , (void __user * )arg ,
149159_IOC_SIZE (cmd ));
150160else if (_IOC_DIR (cmd ) & _IOC_WRITE )
151- result = !access_ok (VERIFY_READ , (void __user * )arg ,
161+ result = !xlx_access_ok (VERIFY_READ , (void __user * )arg ,
152162_IOC_SIZE (cmd ));
153163
154164if (result ) {
@@ -158,7 +168,7 @@ long char_ctrl_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
158168
159169switch (cmd ) {
160170case XDMA_IOCINFO :
161- if (copy_from_user ((void * )& ioctl_obj , (void * ) arg ,
171+ if (copy_from_user ((void * )& ioctl_obj , (void __user * ) arg ,
162172 sizeof (struct xdma_ioc_base ))) {
163173pr_err ("copy_from_user failed.\n" );
164174return - EFAULT ;
@@ -169,20 +179,11 @@ long char_ctrl_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
169179ioctl_obj .magic , XDMA_XCL_MAGIC );
170180return - ENOTTY ;
171181}
172-
173182return version_ioctl (xcdev , (void __user * )arg );
174183case XDMA_IOCOFFLINE :
175- if (!xdev ) {
176- pr_info ("cmd %u, xdev NULL.\n" , cmd );
177- return - EINVAL ;
178- }
179184xdma_device_offline (xdev -> pdev , xdev );
180185break ;
181186case XDMA_IOCONLINE :
182- if (!xdev ) {
183- pr_info ("cmd %u, xdev NULL.\n" , cmd );
184- return - EINVAL ;
185- }
186187xdma_device_online (xdev -> pdev , xdev );
187188break ;
188189default :
@@ -205,7 +206,7 @@ int bridge_mmap(struct file *file, struct vm_area_struct *vma)
205206
206207rv = xcdev_check (__func__ , xcdev , 0 );
207208if (rv < 0 )
208- return rv ;
209+ return rv ;
209210xdev = xcdev -> xdev ;
210211
211212off = vma -> vm_pgoff << PAGE_SHIFT ;
0 commit comments