Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified sdk/linux_kernel_drivers/xdma/10-xdma.rules
100755 → 100644
Empty file.
1 change: 1 addition & 0 deletions sdk/linux_kernel_drivers/xdma/Makefile
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ all :

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

install: all
$(MAKE) -C $(BUILDSYSTEM_DIR) M=$(PWD) modules_install
Expand Down
33 changes: 22 additions & 11 deletions sdk/linux_kernel_drivers/xdma/cdev_bypass.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*******************************************************************************
*
* Xilinx XDMA IP Core Linux Driver
* Copyright(c) 2015 - 2017 Xilinx, Inc.
* Copyright(c) 2015 - 2020 Xilinx, Inc.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
Expand All @@ -21,11 +21,12 @@
* Karen Xie <[email protected]>
*
******************************************************************************/
#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__

#include "libxdma_api.h"
#include "xdma_cdev.h"

#define write_register(v,mem,off) iowrite32(v, mem)
#define write_register(v, mem, off) iowrite32(v, mem)

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

BUG_ON(!buf);
BUG_ON(!buf_offset);
if (!buf) {
pr_err("Invalid user buffer\n");
return -EINVAL;
}

if (!buf_offset) {
pr_err("Invalid user buffer offset\n");
return -EINVAL;
}

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

dbg_sg("In char_bypass_read()\n");
dbg_sg("In %s()\n", __func__);

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

u32 desc_data;
u32 *bypass_addr;
void __iomem *bypass_addr;
size_t buf_offset = 0;
int rc = 0;
int copy_err;
Expand All @@ -145,18 +153,21 @@ static ssize_t char_bypass_write(struct file *file, const char __user *buf,
return -ENODEV;
}

dbg_sg("In char_bypass_write()\n");
dbg_sg("In %s()\n", __func__);

spin_lock(&engine->lock);

/* Write descriptor data to the bypass BAR */
bypass_addr = (u32 *)xdev->bar[xdev->bypass_bar_idx];
bypass_addr += engine->bypass_offset;
bypass_addr = xdev->bar[xdev->bypass_bar_idx];
bypass_addr = (void __iomem *)(
(u32 __iomem *)bypass_addr + engine->bypass_offset
);
while (buf_offset < count) {
copy_err = copy_from_user(&desc_data, &buf[buf_offset],
sizeof(u32));
if (!copy_err) {
write_register(desc_data, bypass_addr, bypass_addr - engine->bypass_offset);
write_register(desc_data, bypass_addr,
bypass_addr - engine->bypass_offset);
buf_offset += sizeof(u32);
rc = buf_offset;
} else {
Expand Down Expand Up @@ -188,5 +199,5 @@ static const struct file_operations bypass_fops = {

void cdev_bypass_init(struct xdma_cdev *xcdev)
{
cdev_init(&xcdev->cdev, &bypass_fops);
cdev_init(&xcdev->cdev, &bypass_fops);
}
53 changes: 27 additions & 26 deletions sdk/linux_kernel_drivers/xdma/cdev_ctrl.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*******************************************************************************
*
* Xilinx XDMA IP Core Linux Driver
* Copyright(c) 2015 - 2017 Xilinx, Inc.
* Copyright(c) 2015 - 2020 Xilinx, Inc.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
Expand All @@ -21,13 +21,20 @@
* Karen Xie <[email protected]>
*
******************************************************************************/

#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__

#include <linux/ioctl.h>
#include "version.h"
#include "xdma_cdev.h"
#include "cdev_ctrl.h"

#if KERNEL_VERSION(5, 0, 0) <= LINUX_VERSION_CODE
#define xlx_access_ok(X, Y, Z) access_ok(Y, Z)
#else
#define xlx_access_ok(X, Y, Z) access_ok(X, Y, Z)
#endif

/*
* character device file operations for control bus (through control bridge)
*/
Expand All @@ -36,13 +43,13 @@ static ssize_t char_ctrl_read(struct file *fp, char __user *buf, size_t count,
{
struct xdma_cdev *xcdev = (struct xdma_cdev *)fp->private_data;
struct xdma_dev *xdev;
void *reg;
void __iomem *reg;
u32 w;
int rv;

rv = xcdev_check(__func__, xcdev, 0);
if (rv < 0)
return rv;
return rv;
xdev = xcdev->xdev;

/* only 32-bit aligned and 32-bit multiples */
Expand All @@ -52,8 +59,8 @@ static ssize_t char_ctrl_read(struct file *fp, char __user *buf, size_t count,
reg = xdev->bar[xcdev->bar] + *pos;
//w = read_register(reg);
w = ioread32(reg);
dbg_sg("char_ctrl_read(@%p, count=%ld, pos=%d) value = 0x%08x\n", reg,
(long)count, (int)*pos, w);
dbg_sg("%s(@%p, count=%ld, pos=%d) value = 0x%08x\n",
__func__, reg, (long)count, (int)*pos, w);
rv = copy_to_user(buf, &w, 4);
if (rv)
dbg_sg("Copy to userspace failed but continuing\n");
Expand All @@ -67,13 +74,13 @@ static ssize_t char_ctrl_write(struct file *file, const char __user *buf,
{
struct xdma_cdev *xcdev = (struct xdma_cdev *)file->private_data;
struct xdma_dev *xdev;
void *reg;
void __iomem *reg;
u32 w;
int rv;

rv = xcdev_check(__func__, xcdev, 0);
if (rv < 0)
return rv;
return rv;
xdev = xcdev->xdev;

/* only 32-bit aligned and 32-bit multiples */
Expand All @@ -83,12 +90,11 @@ static ssize_t char_ctrl_write(struct file *file, const char __user *buf,
/* first address is BAR base plus file position offset */
reg = xdev->bar[xcdev->bar] + *pos;
rv = copy_from_user(&w, buf, 4);
if (rv) {
if (rv)
pr_info("copy from user failed %d/4, but continuing.\n", rv);
}

dbg_sg("char_ctrl_write(0x%08x @%p, count=%ld, pos=%d)\n", w, reg,
(long)count, (int)*pos);
dbg_sg("%s(0x%08x @%p, count=%ld, pos=%d)\n",
__func__, w, reg, (long)count, (int)*pos);
//write_register(w, reg);
iowrite32(w, reg);
*pos += 4;
Expand Down Expand Up @@ -133,9 +139,13 @@ long char_ctrl_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)

rv = xcdev_check(__func__, xcdev, 0);
if (rv < 0)
return rv;
xdev = xcdev->xdev;
return rv;

xdev = xcdev->xdev;
if (!xdev) {
pr_info("cmd %u, xdev NULL.\n", cmd);
return -EINVAL;
}
pr_info("cmd 0x%x, xdev 0x%p, pdev 0x%p.\n", cmd, xdev, xdev->pdev);

if (_IOC_TYPE(cmd) != XDMA_IOC_MAGIC) {
Expand All @@ -145,10 +155,10 @@ long char_ctrl_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
}

if (_IOC_DIR(cmd) & _IOC_READ)
result = !access_ok(VERIFY_WRITE, (void __user *)arg,
result = !xlx_access_ok(VERIFY_WRITE, (void __user *)arg,
_IOC_SIZE(cmd));
else if (_IOC_DIR(cmd) & _IOC_WRITE)
result = !access_ok(VERIFY_READ, (void __user *)arg,
result = !xlx_access_ok(VERIFY_READ, (void __user *)arg,
_IOC_SIZE(cmd));

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

switch (cmd) {
case XDMA_IOCINFO:
if (copy_from_user((void *)&ioctl_obj, (void *) arg,
if (copy_from_user((void *)&ioctl_obj, (void __user *) arg,
sizeof(struct xdma_ioc_base))) {
pr_err("copy_from_user failed.\n");
return -EFAULT;
Expand All @@ -169,20 +179,11 @@ long char_ctrl_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
ioctl_obj.magic, XDMA_XCL_MAGIC);
return -ENOTTY;
}

return version_ioctl(xcdev, (void __user *)arg);
case XDMA_IOCOFFLINE:
if (!xdev) {
pr_info("cmd %u, xdev NULL.\n", cmd);
return -EINVAL;
}
xdma_device_offline(xdev->pdev, xdev);
break;
case XDMA_IOCONLINE:
if (!xdev) {
pr_info("cmd %u, xdev NULL.\n", cmd);
return -EINVAL;
}
xdma_device_online(xdev->pdev, xdev);
break;
default:
Expand All @@ -205,7 +206,7 @@ int bridge_mmap(struct file *file, struct vm_area_struct *vma)

rv = xcdev_check(__func__, xcdev, 0);
if (rv < 0)
return rv;
return rv;
xdev = xcdev->xdev;

off = vma->vm_pgoff << PAGE_SHIFT;
Expand Down
19 changes: 10 additions & 9 deletions sdk/linux_kernel_drivers/xdma/cdev_ctrl.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*******************************************************************************
*
* Xilinx XDMA IP Core Linux Driver
* Copyright(c) 2015 - 2017 Xilinx, Inc.
* Copyright(c) 2015 - 2020 Xilinx, Inc.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
Expand All @@ -21,6 +21,7 @@
* Karen Xie <[email protected]>
*
******************************************************************************/

#ifndef _XDMA_IOCALLS_POSIX_H_
#define _XDMA_IOCALLS_POSIX_H_

Expand Down Expand Up @@ -64,14 +65,14 @@ struct xdma_ioc_base {
};

struct xdma_ioc_info {
struct xdma_ioc_base base;
unsigned short vendor;
unsigned short device;
unsigned short subsystem_vendor;
unsigned short subsystem_device;
unsigned int dma_engine_version;
unsigned int driver_version;
unsigned long long feature_id;
struct xdma_ioc_base base;
unsigned short vendor;
unsigned short device;
unsigned short subsystem_vendor;
unsigned short subsystem_device;
unsigned int dma_engine_version;
unsigned int driver_version;
unsigned long long feature_id;
unsigned short domain;
unsigned char bus;
unsigned char dev;
Expand Down
6 changes: 3 additions & 3 deletions sdk/linux_kernel_drivers/xdma/cdev_events.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*******************************************************************************
*
* Xilinx XDMA IP Core Linux Driver
* Copyright(c) 2015 - 2017 Xilinx, Inc.
* Copyright(c) 2015 - 2020 Xilinx, Inc.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
Expand Down Expand Up @@ -39,7 +39,7 @@ static ssize_t char_events_read(struct file *file, char __user *buf,

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

rv = xcdev_check(__func__, xcdev, 0);
if (rv < 0)
return rv;
return rv;
user_irq = xcdev->user_irq;
if (!user_irq) {
pr_info("xcdev 0x%p, user_irq NULL.\n", xcdev);
Expand Down
Loading