Commit 8966fdf9 authored by Oleg Dzhimiev's avatar Oleg Dzhimiev
Browse files

+ ability to change buffer sizes (no checks for circbuf - stop and unload everything)

parent 5920f604
Loading
Loading
Loading
Loading
+136 −50
Original line number Diff line number Diff line
@@ -138,8 +138,6 @@ static int elphelmem_of_get_init_data(void){
	of_property_read_u32(node, "histograms_size",&_elphel_buf.histograms_size);
	of_property_read_u32(node, "logger_size",&_elphel_buf.logger_size);

	pr_debug("SIZE: %d",_elphel_buf.size);

	if (of_property_read_u32_array(node,
			                       "memsize-partitions-circbuf",
								   parts,
@@ -169,30 +167,10 @@ static int elphelmem_of_get_init_data(void){
	return 0;
}

static int __init elphelmem_init(void)
{
    struct device_node *node;
	const __be32 *bufsize_be;
	pElphel_buf = &_elphel_buf;
int elphelmem_update_partitions(void){

	dma_addr_t tmpsize=0;

	node = of_find_node_by_name(NULL, "elphel393-mem");
	if (!node)
	{
		pr_err("DMA buffer allocation ERROR: No device tree node found\n");
		return -ENODEV;
	}

	elphelmem_of_get_init_data();

	//bufsize_be = (__be32 *)of_get_property(node, "memsize", NULL);
	//_elphel_buf.size = be32_to_cpup(bufsize_be);

	_elphel_buf.vaddr = dma_alloc_coherent(NULL,(_elphel_buf.size*PAGE_SIZE),&(_elphel_buf.paddr),GFP_KERNEL);
    if(_elphel_buf.vaddr) {
    	pr_info("Allocated %u pages for DMA at address 0x%x\n", (u32)_elphel_buf.size, (u32)_elphel_buf.paddr);

	// fill out buffers info
	_elphel_buf.circbuf_chn0_vaddr = _elphel_buf.vaddr;
	_elphel_buf.circbuf_chn0_paddr = _elphel_buf.paddr;
@@ -232,6 +210,34 @@ static int __init elphelmem_init(void)
	_elphel_buf.raw_chn3_vaddr = _elphel_buf.vaddr+tmpsize;
	_elphel_buf.raw_chn3_paddr = _elphel_buf.paddr+tmpsize;

	return 0;
}
EXPORT_SYMBOL_GPL(elphelmem_update_partitions);

static int __init elphelmem_init(void)
{
    struct device_node *node;
	const __be32 *bufsize_be;
	pElphel_buf = &_elphel_buf;

	node = of_find_node_by_name(NULL, "elphel393-mem");
	if (!node)
	{
		pr_err("DMA buffer allocation ERROR: No device tree node found\n");
		return -ENODEV;
	}

	elphelmem_of_get_init_data();

	//bufsize_be = (__be32 *)of_get_property(node, "memsize", NULL);
	//_elphel_buf.size = be32_to_cpup(bufsize_be);

	_elphel_buf.vaddr = dma_alloc_coherent(NULL,(_elphel_buf.size*PAGE_SIZE),&(_elphel_buf.paddr),GFP_KERNEL);
    if(_elphel_buf.vaddr) {
    	pr_info("Allocated %u pages for DMA at address 0x%x\n", (u32)_elphel_buf.size, (u32)_elphel_buf.paddr);

    	elphelmem_update_paritions();

    } else {
    	pr_err("ERROR allocating coherent DMA memory buffer\n");
    }
@@ -388,6 +394,16 @@ static ssize_t get_size_circbuf_chn0(struct device *dev, struct device_attribute
    return sprintf(buf,"%u\n", _elphel_buf.circbuf_chn0_size);
}

static ssize_t set_size_circbuf_chn0(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
	u32 val;
	if (sscanf(buf, "%u", &val)>0){
		_elphel_buf.circbuf_chn0_size = val;
	    elphelmem_update_partitions();
	}
    return count;
}

static ssize_t get_paddr_circbuf_chn1(struct device *dev, struct device_attribute *attr, char *buf)
{
    return sprintf(buf,"0x%x\n", (u32)_elphel_buf.circbuf_chn1_paddr);
@@ -398,6 +414,16 @@ static ssize_t get_size_circbuf_chn1(struct device *dev, struct device_attribute
    return sprintf(buf,"%u\n", _elphel_buf.circbuf_chn1_size);
}

static ssize_t set_size_circbuf_chn1(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
	u32 val;
	if (sscanf(buf, "%u", &val)>0){
		_elphel_buf.circbuf_chn1_size = val;
	    elphelmem_update_partitions();
	}
    return count;
}

static ssize_t get_paddr_circbuf_chn2(struct device *dev, struct device_attribute *attr, char *buf)
{
    return sprintf(buf,"0x%x\n", (u32)_elphel_buf.circbuf_chn2_paddr);
@@ -408,6 +434,16 @@ static ssize_t get_size_circbuf_chn2(struct device *dev, struct device_attribute
    return sprintf(buf,"%u\n", _elphel_buf.circbuf_chn2_size);
}

static ssize_t set_size_circbuf_chn2(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
	u32 val;
	if (sscanf(buf, "%u", &val)>0){
		_elphel_buf.circbuf_chn2_size = val;
	    elphelmem_update_partitions();
	}
    return count;
}

static ssize_t get_paddr_circbuf_chn3(struct device *dev, struct device_attribute *attr, char *buf)
{
    return sprintf(buf,"0x%x\n", (u32)_elphel_buf.circbuf_chn3_paddr);
@@ -418,6 +454,16 @@ static ssize_t get_size_circbuf_chn3(struct device *dev, struct device_attribute
    return sprintf(buf,"%u\n", _elphel_buf.circbuf_chn3_size);
}

static ssize_t set_size_circbuf_chn3(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
	u32 val;
	if (sscanf(buf, "%u", &val)>0){
		_elphel_buf.circbuf_chn3_size = val;
	    elphelmem_update_partitions();
	}
    return count;
}

static ssize_t get_paddr_raw_chn0(struct device *dev, struct device_attribute *attr, char *buf)
{
    return sprintf(buf,"0x%x\n", (u32)_elphel_buf.raw_chn0_paddr);
@@ -428,6 +474,16 @@ static ssize_t get_size_raw_chn0(struct device *dev, struct device_attribute *at
    return sprintf(buf,"%u\n", _elphel_buf.raw_chn0_size);
}

static ssize_t set_size_raw_chn0(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
	u32 val;
	if (sscanf(buf, "%u", &val)>0){
		_elphel_buf.circbuf_chn0_size = val;
	    elphelmem_update_partitions();
	}
    return count;
}

static ssize_t get_paddr_raw_chn1(struct device *dev, struct device_attribute *attr, char *buf)
{
    return sprintf(buf,"0x%x\n", (u32)_elphel_buf.raw_chn1_paddr);
@@ -438,6 +494,16 @@ static ssize_t get_size_raw_chn1(struct device *dev, struct device_attribute *at
    return sprintf(buf,"%u\n", _elphel_buf.raw_chn1_size);
}

static ssize_t set_size_raw_chn1(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
	u32 val;
	if (sscanf(buf, "%u", &val)>0){
		_elphel_buf.circbuf_chn1_size = val;
	    elphelmem_update_partitions();
	}
    return count;
}

static ssize_t get_paddr_raw_chn2(struct device *dev, struct device_attribute *attr, char *buf)
{
    return sprintf(buf,"0x%x\n", (u32)_elphel_buf.raw_chn2_paddr);
@@ -448,6 +514,16 @@ static ssize_t get_size_raw_chn2(struct device *dev, struct device_attribute *at
    return sprintf(buf,"%u\n", _elphel_buf.raw_chn2_size);
}

static ssize_t set_size_raw_chn2(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
	u32 val;
	if (sscanf(buf, "%u", &val)>0){
		_elphel_buf.circbuf_chn2_size = val;
	    elphelmem_update_partitions();
	}
    return count;
}

static ssize_t get_paddr_raw_chn3(struct device *dev, struct device_attribute *attr, char *buf)
{
    return sprintf(buf,"0x%x\n", (u32)_elphel_buf.raw_chn3_paddr);
@@ -458,6 +534,16 @@ static ssize_t get_size_raw_chn3(struct device *dev, struct device_attribute *at
    return sprintf(buf,"%u\n", _elphel_buf.raw_chn3_size);
}

static ssize_t set_size_raw_chn3(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
	u32 val;
	if (sscanf(buf, "%u", &val)>0){
		_elphel_buf.circbuf_chn3_size = val;
	    elphelmem_update_partitions();
	}
    return count;
}

static ssize_t sync_for_cpu_h2d(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
	dma_addr_t paddr;
@@ -676,21 +762,21 @@ static DEVICE_ATTR(buffer_pages_histograms, SYSFS_PERMISSIONS & SYSFS_READONLY
static DEVICE_ATTR(buffer_address_logger,     SYSFS_PERMISSIONS & SYSFS_READONLY, get_paddr_logger,               NULL);
static DEVICE_ATTR(buffer_pages_logger,       SYSFS_PERMISSIONS & SYSFS_READONLY, get_size_logger,                NULL);
static DEVICE_ATTR(buffer_address_circbuf_chn0, SYSFS_PERMISSIONS & SYSFS_READONLY, get_paddr_circbuf_chn0,       NULL);
static DEVICE_ATTR(  buffer_pages_circbuf_chn0, SYSFS_PERMISSIONS & SYSFS_READONLY,  get_size_circbuf_chn0,       NULL);
static DEVICE_ATTR(  buffer_pages_circbuf_chn0, SYSFS_PERMISSIONS,                   get_size_circbuf_chn0,       set_size_circbuf_chn0);
static DEVICE_ATTR(buffer_address_circbuf_chn1, SYSFS_PERMISSIONS & SYSFS_READONLY, get_paddr_circbuf_chn1,       NULL);
static DEVICE_ATTR(  buffer_pages_circbuf_chn1, SYSFS_PERMISSIONS & SYSFS_READONLY,  get_size_circbuf_chn1,       NULL);
static DEVICE_ATTR(  buffer_pages_circbuf_chn1, SYSFS_PERMISSIONS,                   get_size_circbuf_chn1,       set_size_circbuf_chn1);
static DEVICE_ATTR(buffer_address_circbuf_chn2, SYSFS_PERMISSIONS & SYSFS_READONLY, get_paddr_circbuf_chn2,       NULL);
static DEVICE_ATTR(  buffer_pages_circbuf_chn2, SYSFS_PERMISSIONS & SYSFS_READONLY,  get_size_circbuf_chn2,       NULL);
static DEVICE_ATTR(  buffer_pages_circbuf_chn2, SYSFS_PERMISSIONS,                   get_size_circbuf_chn2,       set_size_circbuf_chn2);
static DEVICE_ATTR(buffer_address_circbuf_chn3, SYSFS_PERMISSIONS & SYSFS_READONLY, get_paddr_circbuf_chn3,       NULL);
static DEVICE_ATTR(  buffer_pages_circbuf_chn3, SYSFS_PERMISSIONS & SYSFS_READONLY,  get_size_circbuf_chn3,       NULL);
static DEVICE_ATTR(  buffer_pages_circbuf_chn3, SYSFS_PERMISSIONS,                   get_size_circbuf_chn3,       set_size_circbuf_chn3);
static DEVICE_ATTR(buffer_address_raw_chn0,     SYSFS_PERMISSIONS & SYSFS_READONLY, get_paddr_raw_chn0,           NULL);
static DEVICE_ATTR(  buffer_pages_raw_chn0,     SYSFS_PERMISSIONS & SYSFS_READONLY,  get_size_raw_chn0,           NULL);
static DEVICE_ATTR(  buffer_pages_raw_chn0,     SYSFS_PERMISSIONS,                   get_size_raw_chn0,           set_size_raw_chn0);
static DEVICE_ATTR(buffer_address_raw_chn1,     SYSFS_PERMISSIONS & SYSFS_READONLY, get_paddr_raw_chn1,           NULL);
static DEVICE_ATTR(  buffer_pages_raw_chn1,     SYSFS_PERMISSIONS & SYSFS_READONLY,  get_size_raw_chn1,           NULL);
static DEVICE_ATTR(  buffer_pages_raw_chn1,     SYSFS_PERMISSIONS,                   get_size_raw_chn1,           set_size_raw_chn1);
static DEVICE_ATTR(buffer_address_raw_chn2,     SYSFS_PERMISSIONS & SYSFS_READONLY, get_paddr_raw_chn2,           NULL);
static DEVICE_ATTR(  buffer_pages_raw_chn2,     SYSFS_PERMISSIONS & SYSFS_READONLY,  get_size_raw_chn2,           NULL);
static DEVICE_ATTR(  buffer_pages_raw_chn2,     SYSFS_PERMISSIONS,                   get_size_raw_chn2,           set_size_raw_chn2);
static DEVICE_ATTR(buffer_address_raw_chn3,     SYSFS_PERMISSIONS & SYSFS_READONLY, get_paddr_raw_chn3,           NULL);
static DEVICE_ATTR(  buffer_pages_raw_chn3,     SYSFS_PERMISSIONS & SYSFS_READONLY,  get_size_raw_chn3,           NULL);
static DEVICE_ATTR(  buffer_pages_raw_chn3,     SYSFS_PERMISSIONS,                   get_size_raw_chn3,           set_size_raw_chn3);
static DEVICE_ATTR(sync_for_cpu_h2d,          SYSFS_PERMISSIONS,                  get_sync_for_cpu_h2d,           sync_for_cpu_h2d);
static DEVICE_ATTR(sync_for_device_h2d,       SYSFS_PERMISSIONS,                  get_sync_for_device_h2d,        sync_for_device_h2d);
static DEVICE_ATTR(sync_for_cpu_d2h,          SYSFS_PERMISSIONS,                  get_sync_for_cpu_d2h,           sync_for_cpu_d2h);
+1 −0
Original line number Diff line number Diff line
@@ -92,3 +92,4 @@ struct elphel_buf_t
};
extern struct elphel_buf_t *pElphel_buf;

int elphelmem_update_partitions(void);