Commit e61e3255 authored by Jens Korinth's avatar Jens Korinth
Browse files

WIP: port Zynq to new device setup

parent 25bb45df
#include <linux/slab.h>
#include <linux/gfp.h>
#include <linux/fs.h>
#include <linux/sched/signal.h>
#include <linux/version.h>
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,11,0)
#include <linux/sched.h>
#else
#include <linux/sched/signal.h>
#endif
#include "tlkm_logging.h"
#include "tlkm_control.h"
#include "tlkm_perfc.h"
......@@ -37,6 +42,7 @@ static void exit_miscdev(struct tlkm_control *pctl)
ssize_t tlkm_control_signal_slot_interrupt(struct tlkm_control *pctl, const u32 s_id)
{
BUG_ON(! pctl);
mutex_lock(&pctl->out_mutex);
while (pctl->outstanding > TLKM_CONTROL_BUFFER_SZ - 2) {
DEVWRN(pctl->dev_id, "buffer thrashing, throttling write ...");
......
......@@ -39,7 +39,7 @@ long tlkm_device_ioctl_info(struct file *fp, unsigned int ioctl,
kinfo.dev_id = c->dev_id;
kinfo.vendor_id = kdev->vendor_id;
kinfo.product_id = kdev->product_id;
strncpy(kinfo.name, kdev->name, TLKM_DEVNAME_SZ);
strncpy(kinfo.name, kdev->cls->name, TLKM_DEVNAME_SZ);
if (copy_to_user((void __user *)info, &kinfo, sizeof(kinfo))) {
ERR("could not copy all bytes to user space");
return -EAGAIN;
......
#include <linux/uaccess.h>
#include <linux/sched/signal.h>
#include <linux/version.h>
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,11,0)
#include <linux/sched.h>
#else
#include <linux/sched/signal.h>
#endif
#include "tlkm_device_rw.h"
#include "tlkm_control.h"
#include "tlkm_perfc.h"
......
......@@ -32,7 +32,6 @@
irqreturn_t blue_dma_intr_handler_read(int irq, void * dev_id)
{
struct dma_engine *dma = (struct dma_engine *)dev_id;
BUG_ON(dma->irq_no != irq);
atomic64_inc(&dma->rq_processed);
wake_up_interruptible_sync(&dma->rq);
return IRQ_HANDLED;
......@@ -41,7 +40,6 @@ irqreturn_t blue_dma_intr_handler_read(int irq, void * dev_id)
irqreturn_t blue_dma_intr_handler_write(int irq, void * dev_id)
{
struct dma_engine *dma = (struct dma_engine *)dev_id;
BUG_ON(dma->irq_no != irq);
atomic64_inc(&dma->wq_processed);
wake_up_interruptible_sync(&dma->wq);
return IRQ_HANDLED;
......@@ -49,14 +47,14 @@ irqreturn_t blue_dma_intr_handler_write(int irq, void * dev_id)
ssize_t blue_dma_copy_from(struct dma_engine *dma, void __user *usr_addr, dev_addr_t dev_addr, size_t len)
{
LOG(TLKM_LF_DMA, "dev_addr = 0x%08llx, usr_addr = 0x%08llx, len: %zu bytes", (u64)dev_addr, (u64)usr_addr, len);
LOG(TLKM_LF_DMA, "dev_addr = 0x%px, usr_addr = 0x%px, len: %zu bytes", (void *)dev_addr, usr_addr, len);
if(mutex_lock_interruptible(&dma->regs_mutex)) {
WRN("got killed while aquiring the mutex");
return len;
}
*(u64 *)(dma->regs + REG_FPGA_ADDR) = dev_addr;
*(u64 *)(dma->regs + REG_HOST_ADDR) = (u64)usr_addr;
*(u64 *)(dma->regs + REG_HOST_ADDR) = (u64)((uintptr_t)usr_addr);
*(u64 *)(dma->regs + REG_BTT) = len;
wmb();
*(u64 *)(dma->regs + REG_CMD) = CMD_READ;
......@@ -66,14 +64,14 @@ ssize_t blue_dma_copy_from(struct dma_engine *dma, void __user *usr_addr, dev_ad
ssize_t blue_dma_copy_to(struct dma_engine *dma, dev_addr_t dev_addr, const void __user *usr_addr, size_t len)
{
LOG(TLKM_LF_DMA, "dev_addr = 0x%08llx, usr_addr = 0x%08llx, len: %zu bytes", (u64)dev_addr, (u64)usr_addr, len);
LOG(TLKM_LF_DMA, "dev_addr = 0x%px, usr_addr = 0x%px, len: %zu bytes", (void *)dev_addr, usr_addr, len);
if(mutex_lock_interruptible(&dma->regs_mutex)) {
WRN("got killed while aquiring the mutex");
return len;
}
*(u64 *)(dma->regs + REG_FPGA_ADDR) = dev_addr;
*(u64 *)(dma->regs + REG_HOST_ADDR) = (u64)usr_addr;
*(u64 *)(dma->regs + REG_HOST_ADDR) = (u64)((uintptr_t)usr_addr);
*(u64 *)(dma->regs + REG_BTT) = len;
wmb();
*(u64 *)(dma->regs + REG_CMD) = CMD_WRITE;
......
//
// Copyright (C) 2014 David de la Chevallerie, TU Darmstadt
// Copyright (C) 2018 Jens Korinth, TU Darmstadt
//
// This file is part of Tapasco (TPC).
//
......@@ -36,7 +37,6 @@
irqreturn_t dual_dma_intr_handler_dma(int irq, void * dev_id)
{
struct dma_engine *dma = (struct dma_engine *)dev_id;
BUG_ON(dma->irq_no != irq);
*(u32 *)(dma->regs + REG_CMD) = CMD_ACK;
mutex_unlock(&dma->regs_mutex);
atomic64_inc(&dma->wq_processed);
......@@ -46,16 +46,15 @@ irqreturn_t dual_dma_intr_handler_dma(int irq, void * dev_id)
ssize_t dual_dma_copy_from(struct dma_engine *dma, void __user *usr_addr, dev_addr_t dev_addr, size_t len)
{
u64 usr = (u64)usr_addr;
LOG(TLKM_LF_DMA, "dev_addr = 0x%08llx, usr_addr = 0x%08llx, len: %zu bytes", (u64)dev_addr, (u64)usr_addr, len);
LOG(TLKM_LF_DMA, "dev_addr = 0x%px, usr_addr = 0x%px, len: %zu bytes", (void *)dev_addr, usr_addr, len);
if(mutex_lock_interruptible(&dma->regs_mutex)) {
WRN("got killed while aquiring the mutex");
return len;
}
*(u32 *)(dma->regs + REG_FPGA_ADDR_LOW) = (u32)dev_addr;
*(u32 *)(dma->regs + REG_HOST_ADDR_LOW) = (u32)usr;
*(u32 *)(dma->regs + REG_HOST_ADDR_HIGH) = (u32)(usr >> 32);
*(u32 *)(dma->regs + REG_HOST_ADDR_LOW) = (u32)usr_addr;
*(u32 *)(dma->regs + REG_HOST_ADDR_HIGH) = sizeof(usr_addr) > 4 ? (u32)((uintptr_t)usr_addr >> 32) : 0;
*(u32 *)(dma->regs + REG_BTT) = (u32)len;
wmb();
*(u32 *)(dma->regs + REG_CMD) = CMD_READ;
......@@ -64,15 +63,14 @@ ssize_t dual_dma_copy_from(struct dma_engine *dma, void __user *usr_addr, dev_ad
ssize_t dual_dma_copy_to(struct dma_engine *dma, dev_addr_t dev_addr, const void __user *usr_addr, size_t len)
{
u64 usr = (u64)usr_addr;
LOG(TLKM_LF_DMA, "dev_addr = 0x%08llx, usr_addr = 0x%08llx, len: %zu bytes", (u64)dev_addr, (u64)usr_addr, len);
LOG(TLKM_LF_DMA, "dev_addr = 0x%px, usr_addr = 0x%px, len: %zu bytes", (void *)dev_addr, usr_addr, len);
if(mutex_lock_interruptible(&dma->regs_mutex)) {
WRN("got killed while aquiring the mutex");
return len;
}
*(u32 *)(dma->regs + REG_HOST_ADDR_LOW) = (u32)usr;
*(u32 *)(dma->regs + REG_HOST_ADDR_HIGH) = (u32)(usr >> 32);
*(u32 *)(dma->regs + REG_HOST_ADDR_LOW) = (u32)usr_addr;
*(u32 *)(dma->regs + REG_HOST_ADDR_HIGH) = sizeof(usr_addr) > 4 ? (u32)((uintptr_t)usr_addr >> 32) : 0;
*(u32 *)(dma->regs + REG_FPGA_ADDR_LOW) = (u32)dev_addr;
*(u32 *)(dma->regs + REG_BTT) = (u32)len;
wmb();
......
#include <linux/gfp.h>
#include <linux/uaccess.h>
#include <linux/slab.h>
#include <linux/io.h>
#include "tlkm_dma.h"
#include "tlkm_logging.h"
#include "blue_dma.h"
......@@ -23,18 +25,18 @@ static const struct dma_operations dma_ops[] = {
},
};
int tlkm_dma_init(struct dma_engine *dma, dev_id_t dev_id, void *base, int irq_no)
int tlkm_dma_init(struct dma_engine *dma, dev_id_t dev_id, u64 dbase)
{
uint64_t id;
int i, ret = 0;
void *base = (void *)((uintptr_t)dbase);
BUG_ON(! dma);
DEVLOG(dev_id, TLKM_LF_DMA, "initializing DMA engine 0x%08llx (#%d) ...", (u64)base, irq_no);
DEVLOG(dev_id, TLKM_LF_DMA, "initializing DMA engine @ 0x%px ...", base);
DEVLOG(dev_id, TLKM_LF_DMA, "I/O remapping 0x%08llx - 0x%08llx...", (u64)base, (u64)base + DMA_SZ - 1);
DEVLOG(dev_id, TLKM_LF_DMA, "I/O remapping 0x%px - 0x%px...", base, base + DMA_SZ - 1);
dma->regs = ioremap_nocache((resource_size_t)base, DMA_SZ);
if (IS_ERR(dma->regs)) {
DEVERR(dev_id, "failed to map 0x%08llx - 0x%08llx: %ld",
(u64)base, (u64)base + DMA_SZ - 1, PTR_ERR(dma->regs));
DEVERR(dev_id, "failed to map 0x%px - 0x%px: %ld", base, base + DMA_SZ - 1, PTR_ERR(dma->regs));
return PTR_ERR(dma->regs);
}
......@@ -67,7 +69,6 @@ int tlkm_dma_init(struct dma_engine *dma, dev_id_t dev_id, void *base, int irq_n
mutex_init(&dma->wq_mutex);
dma->dev_id = dev_id;
dma->base = base;
dma->irq_no = irq_no;
atomic64_set(&dma->rq_processed, 0);
atomic64_set(&dma->wq_processed, 0);
DEVLOG(dev_id, TLKM_LF_DMA, "DMA engine initialized");
......@@ -95,8 +96,8 @@ ssize_t tlkm_dma_copy_to(struct dma_engine *dma, dev_addr_t dev_addr, const void
size_t cpy_sz = len;
ssize_t t_id;
while (len > 0) {
DEVLOG(dma->dev_id, TLKM_LF_DMA, "outstanding bytes: %zd - usr_addr = 0x%08llx, dev_addr = 0x%08llx",
len, (u64)usr_addr, (u64)dev_addr);
DEVLOG(dma->dev_id, TLKM_LF_DMA, "outstanding bytes: %zd - usr_addr = 0x%px, dev_addr = 0x%px",
len, usr_addr, (void *)dev_addr);
cpy_sz = len < TLKM_DMA_BUF_SZ ? len : TLKM_DMA_BUF_SZ;
if (copy_from_user(dma->dma_buf[0], usr_addr, cpy_sz)) {
DEVERR(dma->dev_id, "could not copy data from user");
......@@ -120,8 +121,8 @@ ssize_t tlkm_dma_copy_from(struct dma_engine *dma, void __user *usr_addr, dev_ad
size_t cpy_sz = len;
ssize_t t_id;
while (len > 0) {
DEVLOG(dma->dev_id, TLKM_LF_DMA, "outstanding bytes: %zd - usr_addr = 0x%08llx, dev_addr = 0x%08llx",
len, (u64)usr_addr, (u64)dev_addr);
DEVLOG(dma->dev_id, TLKM_LF_DMA, "outstanding bytes: %zd - usr_addr = 0x%px, dev_addr = 0x%px",
len, usr_addr, (void *)dev_addr);
cpy_sz = len < TLKM_DMA_BUF_SZ ? len : TLKM_DMA_BUF_SZ;
t_id = dma->ops.copy_from(dma, dma->dma_buf[1], dev_addr, cpy_sz);
if (wait_event_interruptible(dma->rq, atomic64_read(&dma->rq_processed) > t_id)) {
......
......@@ -3,9 +3,9 @@
#include <linux/atomic.h>
#include <linux/wait.h>
#include <linux/wait.h>
#include <linux/mutex.h>
#include <linux/interrupt.h>
#include <linux/version.h>
#include "tlkm_types.h"
struct dma_engine;
......@@ -31,21 +31,20 @@ struct dma_operations {
struct dma_engine {
dev_id_t dev_id;
void *base;
int irq_no;
void __iomem *regs;
struct mutex regs_mutex;
struct dma_operations ops;
dma_used_t dma_used;
struct wait_queue_head rq;
wait_queue_head_t rq;
struct mutex rq_mutex;
atomic64_t rq_processed;
struct wait_queue_head wq;
wait_queue_head_t wq;
struct mutex wq_mutex;
atomic64_t wq_processed;
void *dma_buf[TLKM_DMA_BUFS];
};
int tlkm_dma_init(struct dma_engine *dma, dev_id_t const dev_id, void *base, int irq_no);
int tlkm_dma_init(struct dma_engine *dma, dev_id_t const dev_id, u64 base);
void tlkm_dma_exit(struct dma_engine *dma);
ssize_t tlkm_dma_copy_to(struct dma_engine *dma, dev_addr_t dev_addr, const void __user *usr_addr, size_t len);
......
......@@ -60,7 +60,7 @@ static int claim_device(struct tlkm_pcie_device *pdev)
DEVERR(did, "could not remap bar 0 address to kernel space");
goto error_pci_remap;
}
DEVLOG(did, TLKM_LF_PCIE, "remapped bar 0 address: 0x%08llx", (u64)pdev->kvirt_addr_bar0);
DEVLOG(did, TLKM_LF_PCIE, "remapped bar 0 address: 0x%px", pdev->kvirt_addr_bar0);
pdev->parent->base_offset = pdev->phy_addr_bar0;
DEVLOG(did, TLKM_LF_PCIE, "status core base: 0x%08llx => 0x%08llx",
......
......@@ -16,10 +16,6 @@ static int test_dev_ioctl(dev_id_t dev_id)
char dfn[30] = "";
snprintf(dfn, 30, "%s_%03u", DEV_FN, dev_id);
//printf("ready to open %s?", dfn);
//getchar();
usleep(100000);
int dfd = open(dfn, O_RDWR);
if (dfd == -1) {
return errno;
......
......@@ -33,7 +33,7 @@ int dma_engines_init(struct tlkm_device *dev)
DEVLOG(dev->dev_id, TLKM_LF_DEVICE, "DMA%d base: 0x%08llx", i, dma_base[i]);
if (! dma_base[i]) continue;
dma_base[i] += dev->base_offset;
ret = tlkm_dma_init(&dev->dma[i], dev->dev_id, (void *)dma_base[i], 0); // FIXME irq number?
ret = tlkm_dma_init(&dev->dma[i], dev->dev_id, dma_base[i]);
if (ret) {
DEVERR(dev->dev_id, "failed to initialize DMA%d: %d", i, ret);
goto err_dma_engine;
......@@ -73,7 +73,7 @@ void dma_engines_exit(struct tlkm_device *dev)
int i, irqn = 0;
DEVLOG(dev->dev_id, TLKM_LF_DEVICE, "releasing DMA engines ...");
for (i = 0; i < TLKM_DEVICE_MAX_DMA_ENGINES; ++i) {
DEVLOG(dev->dev_id, TLKM_LF_DEVICE, "DMA #%d @ 0x%08llx", i, (u64)dev->dma[i].base);
DEVLOG(dev->dev_id, TLKM_LF_DEVICE, "DMA #%d @ 0x%px", i, (void *)dev->dma[i].base);
if (dev->dma[i].base) {
if (dev->dma[i].ops.intr_read)
tlkm_device_release_platform_irq(dev, irqn++);
......@@ -108,7 +108,7 @@ int tlkm_device_init(struct tlkm_device *dev, void *data)
DEVLOG(dev->dev_id, TLKM_LF_DEVICE, "reading address map ...");
if ((ret = tlkm_status_init(&dev->status, dev, dev->base_offset + dev->cls->status_base))) {
DEVERR(dev->dev_id, "coudl not initialize address map: %d", ret);
DEVERR(dev->dev_id, "could not initialize address map: %d", ret);
goto err_status;
}
......@@ -188,7 +188,7 @@ void tlkm_device_release(struct tlkm_device *pdev, tlkm_access_t access)
for (a = (tlkm_access_t)0; a < TLKM_ACCESS_TYPES; ++a) {
total_refs += pdev->ref_cnt[a];
}
if (total_refs > 1) {
if (total_refs > 0) {
DEVLOG(pdev->dev_id, TLKM_LF_DEVICE, "ref_cnt is %zu", total_refs);
--pdev->ref_cnt[access];
} else {
......
......@@ -88,18 +88,18 @@ extern ulong tlkm_logging_flags;
#define tlkm_device_log(dev_id, level, fmt, ...) do { \
switch ((int)level) { \
case 0: \
printk(KERN_ERR "tapasco device #%03u [%s]: " \
printk(KERN_ERR "tapasco device #%02u [%s]: " \
fmt "\n", dev_id, __func__, \
##__VA_ARGS__); \
break; \
case 1: \
printk(KERN_WARNING "tapasco device #%03u [%s]: " \
printk(KERN_WARNING "tapasco device #%02u [%s]: " \
fmt "\n", dev_id, __func__, \
##__VA_ARGS__); \
break; \
default: \
if (tlkm_logging_flags & level) \
printk(KERN_NOTICE "tapasco device #%03u [%s]: " \
printk(KERN_NOTICE "tapasco device #%02u [%s]: " \
fmt "\n", dev_id, __func__, \
##__VA_ARGS__); \
break; \
......@@ -119,11 +119,11 @@ extern ulong tlkm_logging_flags;
#define LOG(l, msg, ...)
#define tlkm_log(level, fmt, ...)
#define DEVERR(dev_id, fmt, ...) printk(KERN_ERR "tapasco device #%03u [%s]: " \
#define DEVERR(dev_id, fmt, ...) printk(KERN_ERR "tapasco device #%02u [%s]: " \
fmt "\n", dev_id, __func__, \
##__VA_ARGS__)
#define DEVWRN(dev_id, fmt, ...) printk(KERN_WARNING "tapasco device #%03u [%s]: " \
#define DEVWRN(dev_id, fmt, ...) printk(KERN_WARNING "tapasco device #%02u [%s]: " \
fmt "\n", dev_id, __func__, \
##__VA_ARGS__)
......
......@@ -7,9 +7,11 @@ typedef uint32_t u32;
typedef int32_t s32;
typedef uint64_t u64;
typedef int64_t s64;
#else
typedef uintptr_t intptr_t;
#endif
typedef u32 dev_id_t;
typedef u64 dev_addr_t;
typedef intptr_t dev_addr_t;
#endif /* TLKM_TYPES_H__ */
......@@ -3,8 +3,9 @@
#include "tlkm_class.h"
#include "zynq_device.h"
#define ZYNQ_CLASS_NAME "zynq"
#include "zynq_platform.h"
#include "zynq_ioctl.h"
#include "zynq_mmap.h"
static inline void zynq_remove(struct tlkm_class *cls) {}
......@@ -15,6 +16,8 @@ struct tlkm_class zynq_cls = {
.destroy = zynq_device_exit,
.probe = zynq_device_probe,
.remove = zynq_remove,
.ioctl = zynq_ioctl,
.mmap = zynq_mmap,
.status_base = 0x77770000ULL,
.npirqs = 0,
.private_data = NULL,
......
......@@ -21,49 +21,49 @@ static int init_iomapping(void)
{
int retval = 0;
u32 magic_id = 0;
DEVLOG(_zynq_dev.dev_id, TLKM_LF_DEVICE, "I/O mapping 0x%08llx-0x%08llx for GP0",
(u64)ZYNQ_PLATFORM_GP0_BASE,
(u64)(ZYNQ_PLATFORM_GP0_BASE + ZYNQ_PLATFORM_GP0_SIZE - 1));
DEVLOG(_zynq_dev.dev_id, TLKM_LF_DEVICE, "I/O mapping 0x%px-0x%px for GP0",
(void *)ZYNQ_PLATFORM_GP0_BASE,
(void *)(ZYNQ_PLATFORM_GP0_BASE + ZYNQ_PLATFORM_GP0_SIZE - 1));
_zynq_dev.gp_map[0] = ioremap_nocache(ZYNQ_PLATFORM_GP0_BASE, ZYNQ_PLATFORM_GP0_SIZE);
if (!_zynq_dev.gp_map[0] || IS_ERR(_zynq_dev.gp_map[0])) {
DEVERR(_zynq_dev.dev_id,
"could not ioremap the AXI register space at 0x%08llx-0x%08llx",
(u64)ZYNQ_PLATFORM_GP0_BASE,
(u64)(ZYNQ_PLATFORM_GP0_BASE + ZYNQ_PLATFORM_GP0_SIZE - 1));
"could not ioremap the AXI register space at 0x%px-0x%px",
(void *)ZYNQ_PLATFORM_GP0_BASE,
(void *)(ZYNQ_PLATFORM_GP0_BASE + ZYNQ_PLATFORM_GP0_SIZE - 1));
retval = PTR_ERR(_zynq_dev.gp_map[0]);
goto err_gp0;
}
DEVLOG(_zynq_dev.dev_id, TLKM_LF_DEVICE, "I/O mapping 0x%08llx-0x%08llx for GP1",
(u64)ZYNQ_PLATFORM_GP1_BASE,
(u64)(ZYNQ_PLATFORM_GP1_BASE + ZYNQ_PLATFORM_GP1_SIZE - 1));
DEVLOG(_zynq_dev.dev_id, TLKM_LF_DEVICE, "I/O mapping 0x%px-0x%px for GP1",
(void *)ZYNQ_PLATFORM_GP1_BASE,
(void *)(ZYNQ_PLATFORM_GP1_BASE + ZYNQ_PLATFORM_GP1_SIZE - 1));
_zynq_dev.gp_map[1] = ioremap_nocache(ZYNQ_PLATFORM_GP1_BASE, ZYNQ_PLATFORM_GP1_SIZE);
if (!_zynq_dev.gp_map[1] || IS_ERR(_zynq_dev.gp_map[1])) {
DEVERR(_zynq_dev.dev_id,
"could not ioremap the AXI register space at 0x%08llx-0x%08llx",
(u64)ZYNQ_PLATFORM_GP1_BASE,
(u64)(ZYNQ_PLATFORM_GP1_BASE + ZYNQ_PLATFORM_GP1_SIZE - 1));
"could not ioremap the AXI register space at 0x%px-0x%px",
(void *)ZYNQ_PLATFORM_GP1_BASE,
(void *)(ZYNQ_PLATFORM_GP1_BASE + ZYNQ_PLATFORM_GP1_SIZE - 1));
retval = PTR_ERR(_zynq_dev.gp_map[1]);
goto err_gp1;
}
DEVLOG(_zynq_dev.dev_id, TLKM_LF_DEVICE, "I/O mapping 0x%08llx-0x%08llx for ST",
(u64)ZYNQ_PLATFORM_STATUS_BASE,
(u64)(ZYNQ_PLATFORM_STATUS_BASE + ZYNQ_PLATFORM_STATUS_SIZE - 1));
DEVLOG(_zynq_dev.dev_id, TLKM_LF_DEVICE, "I/O mapping 0x%px-0x%px for ST",
(void *)ZYNQ_PLATFORM_STATUS_BASE,
(void *)(ZYNQ_PLATFORM_STATUS_BASE + ZYNQ_PLATFORM_STATUS_SIZE - 1));
_zynq_dev.tapasco_status = ioremap_nocache(ZYNQ_PLATFORM_STATUS_BASE, ZYNQ_PLATFORM_STATUS_SIZE);
if (!_zynq_dev.tapasco_status || IS_ERR(_zynq_dev.tapasco_status)) {
DEVERR(_zynq_dev.dev_id,
"could not ioremap the AXI register space at 0x%08llx-0x%08llx",
(u64)ZYNQ_PLATFORM_STATUS_BASE,
(u64)(ZYNQ_PLATFORM_STATUS_BASE + ZYNQ_PLATFORM_STATUS_SIZE));
"could not ioremap the AXI register space at 0x%px-0x%px",
(void *)ZYNQ_PLATFORM_STATUS_BASE,
(void *)(ZYNQ_PLATFORM_STATUS_BASE + ZYNQ_PLATFORM_STATUS_SIZE));
retval = PTR_ERR(_zynq_dev.tapasco_status);
goto err_tapasco_status;
}
magic_id = ioread32(_zynq_dev.tapasco_status);
DEVLOG(_zynq_dev.dev_id, TLKM_LF_DEVICE, "magic_id = 0x%08lx", (ulong)magic_id);
DEVLOG(_zynq_dev.dev_id, TLKM_LF_DEVICE,
"I/O mapped all registers successfully: GP0 = 0x%08lx, GP1 = 0x%08lx, ST=0x%08lx",
(ulong)_zynq_dev.gp_map[0], (ulong)_zynq_dev.gp_map[1], (ulong)_zynq_dev.tapasco_status);
"I/O mapped all registers successfully: GP0 = 0x%px, GP1 = 0x%08lx, ST=0x%08lx",
_zynq_dev.gp_map[0], (ulong)_zynq_dev.gp_map[1], (ulong)_zynq_dev.tapasco_status);
return retval;
err_tapasco_status:
......@@ -107,7 +107,7 @@ int zynq_device_init(struct tlkm_device *inst, void *data)
goto err_iomapping;
}
if ((ret = zynq_irq_init(&_zynq_dev, inst->ctrl))) {
if ((ret = zynq_irq_init(&_zynq_dev))) {
DEVERR(inst->dev_id, "could not initialize interrupts: %d", ret);
goto err_irq;
}
......@@ -146,7 +146,8 @@ int zynq_device_probe(struct tlkm_class *cls)
LOG(TLKM_LF_DEVICE, "found Xilinx Zynq-7000");
inst = tlkm_bus_new_device(cls, 0, 0, NULL);
BUG_ON(! inst);
} else {
LOG(TLKM_LF_DEVICE, "no Xilinx Zynq-7000 series device found");
}
LOG(TLKM_LF_DEVICE, "no Xilinx Zynq-7000 series device found");
return 0;
}
......@@ -59,7 +59,7 @@ long zynq_ioctl_alloc(struct tlkm_device *inst, struct tlkm_mm_cmd *cmd)
DEVWRN(inst->dev_id, "allocation failed: len = %zu", cmd->sz);
return -ENOMEM;
}
DEVLOG(inst->dev_id, TLKM_LF_IOCTL, "alloc: len = %zu, dma = 0x%08lx", cmd->sz, (unsigned long) dma_addr);
DEVLOG(inst->dev_id, TLKM_LF_IOCTL, "alloc: len = %zu, dma = %pad", cmd->sz, &dma_addr);
cmd->dev_addr = dma_addr;
tlkm_perfc_total_alloced_mem_add(inst->dev_id, cmd->sz);
return 0;
......@@ -68,7 +68,7 @@ long zynq_ioctl_alloc(struct tlkm_device *inst, struct tlkm_mm_cmd *cmd)
static inline
long zynq_ioctl_free(struct tlkm_device *inst, struct tlkm_mm_cmd *cmd)
{
DEVLOG(inst->dev_id, TLKM_LF_IOCTL, "free: len = %zu, dma = 0x%08lx", cmd->sz, (unsigned long)cmd->dev_addr);
DEVLOG(inst->dev_id, TLKM_LF_IOCTL, "free: len = %zu, dma = %pad", cmd->sz, &cmd->dev_addr);
if (cmd->dev_addr >= 0) {
zynq_dmamgmt_dealloc_dma(cmd->dev_addr);
cmd->dev_addr = 0;
......@@ -81,8 +81,8 @@ static inline
long zynq_ioctl_copyto(struct tlkm_device *inst, struct tlkm_copy_cmd *cmd)
{
struct dma_buf_t *dmab;
DEVLOG(inst->dev_id, TLKM_LF_IOCTL, "copyto: len = %zu, dma = 0x%08lx, p = 0x%08lx",
cmd->length, (ulong)cmd->dev_addr, (ulong) cmd->user_addr);
DEVLOG(inst->dev_id, TLKM_LF_IOCTL, "copyto: len = %zu, dma = %pad, p = 0x%px",
cmd->length, &cmd->dev_addr, cmd->user_addr);
// allocate, if necessary
if (cmd->dev_addr < 0 || ! (dmab = zynq_dmamgmt_get(zynq_dmamgmt_get_id(cmd->dev_addr)))) {
int ret;
......@@ -92,14 +92,14 @@ long zynq_ioctl_copyto(struct tlkm_device *inst, struct tlkm_copy_cmd *cmd)
cmd->dev_addr = mm_cmd.dev_addr;
if (ret) return ret;
}
DEVLOG(inst->dev_id, TLKM_LF_IOCTL, "cmd->dev_addr = %ld", (long)cmd->dev_addr);
DEVLOG(inst->dev_id, TLKM_LF_IOCTL, "cmd->dev_addr = %pad", &cmd->dev_addr);
dmab = zynq_dmamgmt_get(zynq_dmamgmt_get_id(cmd->dev_addr));
if (! dmab || ! dmab->kvirt_addr) {
DEVERR(inst->dev_id, "something went wrong in the allocation");
return -ENOMEM;
}
DEVLOG(inst->dev_id, TLKM_LF_IOCTL, "dmab->kvirt_addr = 0x%08lx, dmab->dma_addr = 0x%08lx",
(unsigned long)dmab->kvirt_addr, (unsigned long)dmab->dma_addr);
DEVLOG(inst->dev_id, TLKM_LF_IOCTL, "dmab->kvirt_addr = 0x%px, dmab->dma_addr = %pad",
dmab->kvirt_addr, &dmab->dma_addr);
if (copy_from_user(dmab->kvirt_addr, (void __user *) cmd->user_addr, cmd->length)) {
DEVWRN(inst->dev_id, "could not copy all bytes from user space");
return -EACCES;
......@@ -113,11 +113,11 @@ static inline
long zynq_ioctl_copyfrom(struct tlkm_device *inst, struct tlkm_copy_cmd *cmd)
{
struct dma_buf_t *dmab;
DEVLOG(inst->dev_id, TLKM_LF_DEVICE, "copyfrom: len = %zu, id = %ld, p = 0x%08lx",
cmd->length, (long)cmd->dev_addr, (unsigned long) cmd->user_addr);
DEVLOG(inst->dev_id, TLKM_LF_DEVICE, "copyfrom: len = %zu, dma = %pad, p = 0x%px",
cmd->length, &cmd->dev_addr, cmd->user_addr);
dmab = zynq_dmamgmt_get(zynq_dmamgmt_get_id(cmd->dev_addr));
if (! dmab || ! dmab->kvirt_addr) {
DEVERR(inst->dev_id, "could not get dma buffer with dma = 0x%08lx", (ulong)cmd->dev_addr);
DEVERR(inst->dev_id, "could not get dma buffer with dma = %pad", &cmd->dev_addr);
return -EINVAL;
}
if (copy_to_user((void __user *) cmd->user_addr, dmab->kvirt_addr, cmd->length)) {
......@@ -139,7 +139,7 @@ long zynq_ioctl_alloc_copyto(struct tlkm_device *inst, struct tlkm_bulk_cmd *cmd
}
cmd->copy.dev_addr = cmd->mm.dev_addr;
if ((ret = zynq_ioctl_copyto(inst, &cmd->copy))) {
DEVERR(inst->dev_id, "failed to copy memory to 0x%08llx: %ld", (u64)cmd->mm.dev_addr, ret);
DEVERR(inst->dev_id, "failed to copy memory to %pad: %ld", &cmd->mm.dev_addr, ret);
return ret;
}
return 0;
......@@ -169,8 +169,7 @@ long zynq_ioctl_read(struct tlkm_device *inst, struct tlkm_copy_cmd *cmd)
void __iomem *ptr = NULL;
void *buf = kzalloc(cmd->length, GFP_ATOMIC);
struct zynq_device *dev = (struct zynq_device *)inst->private_data;
DEVLOG(inst->dev_id, TLKM_LF_IOCTL, "received read of %zu bytes from 0x%08llx",
cmd->length, cmd->dev_addr);
DEVLOG(inst->dev_id, TLKM_LF_IOCTL, "received read of %zu bytes from %pad", cmd->length, &cmd->dev_addr);
if (cmd->dev_addr >= ZYNQ_PLATFORM_GP1_BASE) {
ptr = dev->gp_map[1] + (cmd->dev_addr - ZYNQ_PLATFORM_GP1_BASE);
} else if (cmd->dev_addr < ZYNQ_PLATFORM_GP0_HIGH) {
......@@ -179,13 +178,13 @@ long zynq_ioctl_read(struct tlkm_device *inst, struct tlkm_copy_cmd *cmd)
cmd->dev_addr < ZYNQ_PLATFORM_STATUS_HIGH) {
ptr = dev->tapasco_status + (cmd->dev_addr - ZYNQ_PLATFORM_STATUS_BASE);
} else {
DEVERR(inst->dev_id, "invalid address: 0x%08llx", cmd->dev_addr);
DEVERR(inst->dev_id, "invalid address: %pad", &cmd->dev_addr);
return -ENXIO;
}
memcpy_fromio(buf, ptr, cmd->length);
if ((ret = copy_to_user((u32 __user *)cmd->user_addr, buf, cmd->length))) {
DEVERR(inst->dev_id, "could not copy all bytes from 0x%08lx to user space 0x%08lx: %ld",
(ulong)buf, (ulong)cmd->user_addr, ret);
DEVERR(inst->dev_id, "could not copy all bytes from 0x%px to user space 0x%px: %ld",
buf, cmd->user_addr, ret);
ret = -EAGAIN;
}
kfree(buf);
......@@ -200,8 +199,8 @@ long zynq_ioctl_write(struct tlkm_device *inst, struct tlkm_copy_cmd *cmd)
void __iomem *ptr = NULL;
void *buf = kzalloc(cmd->length, GFP_ATOMIC);
struct zynq_device *dev = (struct zynq_device *)inst->private_data;
DEVLOG(inst->dev_id, TLKM_LF_IOCTL, "received write of %zu bytes to 0x%08llx",
cmd->length, cmd->dev_addr);
DEVLOG(inst->dev_id, TLKM_LF_IOCTL, "received write of %zu bytes to %pad",
cmd->length, &cmd->dev_addr);
if (cmd->dev_addr > ZYNQ_PLATFORM_GP1_BASE) {
ptr = dev->gp_map[1] + (cmd->dev_addr - ZYNQ_PLATFORM_GP1_BASE);
} else if (cmd->dev_addr < ZYNQ_PLATFORM_GP0_HIGH) {
......@@ -210,12 +209,12 @@ long zynq_ioctl_write(struct tlkm_device *inst, struct tlkm_copy_cmd *cmd)
cmd->dev_addr < ZYNQ_PLATFORM_STATUS_HIGH) {
ptr = dev->tapasco_status + (cmd->dev_addr - ZYNQ_PLATFORM_STATUS_BASE);
} else {
DEVERR(inst->dev_id, "invalid address: 0x%08llx", cmd->dev_addr);
DEVERR(inst->dev_id, "invalid address: %pad", &cmd->dev_addr);
return -ENXIO;
}
if ((ret = copy_from_user(buf, (u32 __user *)cmd->user_addr, cmd->length))) {
DEVERR(inst->dev_id, "could not copy all bytes from 0x%08lx to user space 0x%08lx: %ld",
(ulong)buf, (ulong)cmd->user_addr, ret);
DEVERR(inst->dev_id, "could not copy all bytes from 0x%px to user space 0x%px: %ld",
buf, cmd->user_addr, ret);
ret = -EAGAIN;
goto err;
}
......
......@@ -55,28 +55,31 @@ typedef struct {
#endif
static struct {
struct tlkm_control *ctrl;
#define _INTC(N) intc_t intc_ ## N;
INTERRUPT_CONTROLLERS
#undef _INTC
} zynq_irq;
#define _INTC(N) \