Skip to content

Commit 288bee0

Browse files
xdma: driver update (#498)
* xdma: driver update * xdma: add back F1 specific device ids * xdma: update license header check * keep enable_credit_mp disabled * back out experimental aio code
1 parent 8b5c86b commit 288bee0

20 files changed

+1076
-910
lines changed

sdk/linux_kernel_drivers/xdma/10-xdma.rules

100755100644
File mode changed.

sdk/linux_kernel_drivers/xdma/Makefile

100755100644
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ all :
4242

4343
clean:
4444
$(MAKE) -C $(BUILDSYSTEM_DIR) M=$(PWD) clean
45+
@/bin/rm -f *.ko modules.order *.mod.c *.o *.o.ur-safe .*.o.cmd
4546

4647
install: all
4748
$(MAKE) -C $(BUILDSYSTEM_DIR) M=$(PWD) modules_install

sdk/linux_kernel_drivers/xdma/cdev_bypass.c

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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,
@@ -21,11 +21,12 @@
2121
* Karen Xie <[email protected]>
2222
*
2323
******************************************************************************/
24+
#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
2425

2526
#include "libxdma_api.h"
2627
#include "xdma_cdev.h"
2728

28-
#define write_register(v,mem,off) iowrite32(v, mem)
29+
#define write_register(v, mem, off) iowrite32(v, mem)
2930

3031
static int copy_desc_data(struct xdma_transfer *transfer, char __user *buf,
3132
size_t *buf_offset, size_t buf_size)
@@ -34,8 +35,15 @@ static int copy_desc_data(struct xdma_transfer *transfer, char __user *buf,
3435
int copy_err;
3536
int rc = 0;
3637

37-
BUG_ON(!buf);
38-
BUG_ON(!buf_offset);
38+
if (!buf) {
39+
pr_err("Invalid user buffer\n");
40+
return -EINVAL;
41+
}
42+
43+
if (!buf_offset) {
44+
pr_err("Invalid user buffer offset\n");
45+
return -EINVAL;
46+
}
3947

4048
/* Fill user buffer with descriptor data */
4149
for (i = 0; i < transfer->desc_num; i++) {
@@ -76,7 +84,7 @@ static ssize_t char_bypass_read(struct file *file, char __user *buf,
7684
xdev = xcdev->xdev;
7785
engine = xcdev->engine;
7886

79-
dbg_sg("In char_bypass_read()\n");
87+
dbg_sg("In %s()\n", __func__);
8088

8189
if (count & 3) {
8290
dbg_sg("Buffer size must be a multiple of 4 bytes\n");
@@ -119,7 +127,7 @@ static ssize_t char_bypass_write(struct file *file, const char __user *buf,
119127
struct xdma_cdev *xcdev = (struct xdma_cdev *)file->private_data;
120128

121129
u32 desc_data;
122-
u32 *bypass_addr;
130+
void __iomem *bypass_addr;
123131
size_t buf_offset = 0;
124132
int rc = 0;
125133
int copy_err;
@@ -145,18 +153,21 @@ static ssize_t char_bypass_write(struct file *file, const char __user *buf,
145153
return -ENODEV;
146154
}
147155

148-
dbg_sg("In char_bypass_write()\n");
156+
dbg_sg("In %s()\n", __func__);
149157

150158
spin_lock(&engine->lock);
151159

152160
/* Write descriptor data to the bypass BAR */
153-
bypass_addr = (u32 *)xdev->bar[xdev->bypass_bar_idx];
154-
bypass_addr += engine->bypass_offset;
161+
bypass_addr = xdev->bar[xdev->bypass_bar_idx];
162+
bypass_addr = (void __iomem *)(
163+
(u32 __iomem *)bypass_addr + engine->bypass_offset
164+
);
155165
while (buf_offset < count) {
156166
copy_err = copy_from_user(&desc_data, &buf[buf_offset],
157167
sizeof(u32));
158168
if (!copy_err) {
159-
write_register(desc_data, bypass_addr, bypass_addr - engine->bypass_offset);
169+
write_register(desc_data, bypass_addr,
170+
bypass_addr - engine->bypass_offset);
160171
buf_offset += sizeof(u32);
161172
rc = buf_offset;
162173
} else {
@@ -188,5 +199,5 @@ static const struct file_operations bypass_fops = {
188199

189200
void cdev_bypass_init(struct xdma_cdev *xcdev)
190201
{
191-
cdev_init(&xcdev->cdev, &bypass_fops);
202+
cdev_init(&xcdev->cdev, &bypass_fops);
192203
}

sdk/linux_kernel_drivers/xdma/cdev_ctrl.c

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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,
@@ -21,13 +21,20 @@
2121
* Karen Xie <[email protected]>
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
{
3744
struct xdma_cdev *xcdev = (struct xdma_cdev *)fp->private_data;
3845
struct xdma_dev *xdev;
39-
void *reg;
46+
void __iomem *reg;
4047
u32 w;
4148
int rv;
4249

4350
rv = xcdev_check(__func__, xcdev, 0);
4451
if (rv < 0)
45-
return rv;
52+
return rv;
4653
xdev = 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,
5259
reg = xdev->bar[xcdev->bar] + *pos;
5360
//w = read_register(reg);
5461
w = 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);
5764
rv = copy_to_user(buf, &w, 4);
5865
if (rv)
5966
dbg_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
{
6875
struct xdma_cdev *xcdev = (struct xdma_cdev *)file->private_data;
6976
struct xdma_dev *xdev;
70-
void *reg;
77+
void __iomem *reg;
7178
u32 w;
7279
int rv;
7380

7481
rv = xcdev_check(__func__, xcdev, 0);
7582
if (rv < 0)
76-
return rv;
83+
return rv;
7784
xdev = 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 */
8491
reg = xdev->bar[xcdev->bar] + *pos;
8592
rv = copy_from_user(&w, buf, 4);
86-
if (rv) {
93+
if (rv)
8794
pr_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);
9399
iowrite32(w, reg);
94100
*pos += 4;
@@ -133,9 +139,13 @@ long char_ctrl_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
133139

134140
rv = xcdev_check(__func__, xcdev, 0);
135141
if (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+
}
139149
pr_info("cmd 0x%x, xdev 0x%p, pdev 0x%p.\n", cmd, xdev, xdev->pdev);
140150

141151
if (_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

147157
if (_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));
150160
else 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

154164
if (result) {
@@ -158,7 +168,7 @@ long char_ctrl_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
158168

159169
switch (cmd) {
160170
case 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))) {
163173
pr_err("copy_from_user failed.\n");
164174
return -EFAULT;
@@ -169,20 +179,11 @@ long char_ctrl_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
169179
ioctl_obj.magic, XDMA_XCL_MAGIC);
170180
return -ENOTTY;
171181
}
172-
173182
return version_ioctl(xcdev, (void __user *)arg);
174183
case XDMA_IOCOFFLINE:
175-
if (!xdev) {
176-
pr_info("cmd %u, xdev NULL.\n", cmd);
177-
return -EINVAL;
178-
}
179184
xdma_device_offline(xdev->pdev, xdev);
180185
break;
181186
case XDMA_IOCONLINE:
182-
if (!xdev) {
183-
pr_info("cmd %u, xdev NULL.\n", cmd);
184-
return -EINVAL;
185-
}
186187
xdma_device_online(xdev->pdev, xdev);
187188
break;
188189
default:
@@ -205,7 +206,7 @@ int bridge_mmap(struct file *file, struct vm_area_struct *vma)
205206

206207
rv = xcdev_check(__func__, xcdev, 0);
207208
if (rv < 0)
208-
return rv;
209+
return rv;
209210
xdev = xcdev->xdev;
210211

211212
off = vma->vm_pgoff << PAGE_SHIFT;

sdk/linux_kernel_drivers/xdma/cdev_ctrl.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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,
@@ -21,6 +21,7 @@
2121
* Karen Xie <[email protected]>
2222
*
2323
******************************************************************************/
24+
2425
#ifndef _XDMA_IOCALLS_POSIX_H_
2526
#define _XDMA_IOCALLS_POSIX_H_
2627

@@ -64,14 +65,14 @@ struct xdma_ioc_base {
6465
};
6566

6667
struct xdma_ioc_info {
67-
struct xdma_ioc_base base;
68-
unsigned short vendor;
69-
unsigned short device;
70-
unsigned short subsystem_vendor;
71-
unsigned short subsystem_device;
72-
unsigned int dma_engine_version;
73-
unsigned int driver_version;
74-
unsigned long long feature_id;
68+
struct xdma_ioc_base base;
69+
unsigned short vendor;
70+
unsigned short device;
71+
unsigned short subsystem_vendor;
72+
unsigned short subsystem_device;
73+
unsigned int dma_engine_version;
74+
unsigned int driver_version;
75+
unsigned long long feature_id;
7576
unsigned short domain;
7677
unsigned char bus;
7778
unsigned char dev;

sdk/linux_kernel_drivers/xdma/cdev_events.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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,
@@ -39,7 +39,7 @@ static ssize_t char_events_read(struct file *file, char __user *buf,
3939

4040
rv = xcdev_check(__func__, xcdev, 0);
4141
if (rv < 0)
42-
return rv;
42+
return rv;
4343
user_irq = xcdev->user_irq;
4444
if (!user_irq) {
4545
pr_info("xcdev 0x%p, user_irq NULL.\n", xcdev);
@@ -88,7 +88,7 @@ static unsigned int char_events_poll(struct file *file, poll_table *wait)
8888

8989
rv = xcdev_check(__func__, xcdev, 0);
9090
if (rv < 0)
91-
return rv;
91+
return rv;
9292
user_irq = xcdev->user_irq;
9393
if (!user_irq) {
9494
pr_info("xcdev 0x%p, user_irq NULL.\n", xcdev);

0 commit comments

Comments
 (0)