Source
x
static int sram_add_partition(struct sram_dev *sram, struct sram_reserve *block,
/*
* Generic on-chip SRAM allocation driver
*
* Copyright (C) 2012 Philipp Zabel, Pengutronix
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
static ssize_t sram_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr,
char *buf, loff_t pos, size_t count)
{
struct sram_partition *part;
part = container_of(attr, struct sram_partition, battr);
mutex_lock(&part->lock);
memcpy_fromio(buf, part->base + pos, count);
mutex_unlock(&part->lock);
return count;
}
static ssize_t sram_write(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr,
char *buf, loff_t pos, size_t count)
{
struct sram_partition *part;
part = container_of(attr, struct sram_partition, battr);
mutex_lock(&part->lock);
memcpy_toio(part->base + pos, buf, count);
mutex_unlock(&part->lock);
return count;
}
static int sram_add_pool(struct sram_dev *sram, struct sram_reserve *block,
phys_addr_t start, struct sram_partition *part)
{
int ret;
part->pool = devm_gen_pool_create(sram->dev, ilog2(SRAM_GRANULARITY),
NUMA_NO_NODE, block->label);
if (IS_ERR(part->pool))
return PTR_ERR(part->pool);
ret = gen_pool_add_virt(part->pool, (unsigned long)part->base, start,
block->size, NUMA_NO_NODE);
if (ret < 0) {
dev_err(sram->dev, "failed to register subpool: %d\n", ret);
return ret;
}
return 0;
}
static int sram_add_export(struct sram_dev *sram, struct sram_reserve *block,
phys_addr_t start, struct sram_partition *part)
{
sysfs_bin_attr_init(&part->battr);
part->battr.attr.name = devm_kasprintf(sram->dev, GFP_KERNEL,