Commit 01547b49 authored by Federico Vaga's avatar Federico Vaga

sw:drv: add parameter to customize DMA allocation

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 2a10539c
......@@ -238,6 +238,14 @@ attributes. Here we focus only on those.
the user can use ``lseek(2)`` to set the offset in the DDR, and
``read(2)``/``write(2)`` to start the DMA transfer.
Module Parameters
-----------------
``user_dma_coherent_size`` [RW]
It sets the maximum size for a coherent DMA memory allocation. A
change to this value is applied on ``open(2)``
(file ``<pci-id>/spec-<pci-id>/dma``).
DMA
---
......
......@@ -41,7 +41,7 @@ class PySPEC:
f.write(os.path.dirname(prev))
@contextmanager
def dma(self):
def dma(self, dma_coherent_size=None):
"""
Create a DMA context from which users can do DMA
transfers. Within this context the user can use
......@@ -64,7 +64,7 @@ class PySPEC:
>>> spec_dma.close()
"""
spec_dma = self.PySPECDMA(self)
spec_dma.request()
spec_dma.request(dma_coherent_size)
try:
yield spec_dma
finally:
......@@ -97,12 +97,18 @@ class PySPEC:
"""
self.spec = spec
def request(self):
def request(self, dma_coherent_size=None):
"""
Open a DMA file descriptor
:var dma_coherent_size: DMA coherent allocation size (in-kernel).
:raise OSError: if the open(2) or the driver fails
"""
if dma_coherent_size is not None:
with open("/sys/module/spec_fmc_carrier/parameters/user_dma_coherent_size", "w") as f:
f.write(str(dma_coherent_size))
self.dma_file = open(os.path.join(self.spec.debugfs_fpga, "dma"),
"rb+", buffering=0)
def release(self):
......
......@@ -19,11 +19,16 @@
#include <linux/completion.h>
#include <linux/jiffies.h>
#include <linux/uaccess.h>
#include <linux/moduleparam.h>
#include "linux/printk.h"
#include "spec.h"
#include "spec-compat.h"
static int user_dma_coherent_size = 4 * 1024 * 1024;
module_param(user_dma_coherent_size, int, 0644);
MODULE_PARM_DESC(user_dma_coherent_size,
"DMA coherent allocation's size in bytes (default 4MiB)");
enum spec_fpga_irq_lines {
SPEC_FPGA_IRQ_FMC_I2C = 0,
......@@ -320,7 +325,7 @@ static int spec_fpga_dbg_dma_open(struct inode *inode, struct file *file)
return -ENOMEM;
init_completion(&dbgdma->compl);
dbgdma->spec_fpga = spec_fpga;
dbgdma->datalen = 4 * 1024 *1024;
dbgdma->datalen = user_dma_coherent_size;
dbgdma->data = dma_alloc_coherent(dbgdma->spec_fpga->dev.parent,
dbgdma->datalen, &dbgdma->datadma,
GFP_KERNEL);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment