2007-07-05 16:02:19 +00:00
|
|
|
/*
|
2009-12-15 08:11:09 +00:00
|
|
|
* hostfile.c - use files from the host to simalute barebox devices
|
2007-07-05 16:02:19 +00:00
|
|
|
*
|
|
|
|
* Copyright (c) 2007 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
|
|
|
|
*
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-07-05 16:01:42 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <driver.h>
|
|
|
|
#include <malloc.h>
|
2009-10-22 12:21:29 +00:00
|
|
|
#include <mach/linux.h>
|
2007-07-05 16:01:42 +00:00
|
|
|
#include <init.h>
|
|
|
|
#include <errno.h>
|
2009-10-22 12:21:29 +00:00
|
|
|
#include <mach/hostfile.h>
|
2007-07-05 16:01:42 +00:00
|
|
|
#include <xfuncs.h>
|
|
|
|
|
2009-06-11 13:33:49 +00:00
|
|
|
struct hf_priv {
|
|
|
|
struct cdev cdev;
|
|
|
|
struct hf_platform_data *pdata;
|
|
|
|
};
|
|
|
|
|
2011-10-14 11:46:09 +00:00
|
|
|
static ssize_t hf_read(struct cdev *cdev, void *buf, size_t count, loff_t offset, ulong flags)
|
2007-07-05 16:01:42 +00:00
|
|
|
{
|
2009-06-11 13:33:49 +00:00
|
|
|
struct hf_platform_data *hf = cdev->priv;
|
2007-07-05 16:01:42 +00:00
|
|
|
int fd = hf->fd;
|
|
|
|
|
|
|
|
if (linux_lseek(fd, offset) != offset)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return linux_read(fd, buf, count);
|
|
|
|
}
|
|
|
|
|
2011-10-14 11:46:09 +00:00
|
|
|
static ssize_t hf_write(struct cdev *cdev, const void *buf, size_t count, loff_t offset, ulong flags)
|
2007-07-05 16:01:42 +00:00
|
|
|
{
|
2009-06-11 13:33:49 +00:00
|
|
|
struct hf_platform_data *hf = cdev->priv;
|
2007-07-05 16:01:42 +00:00
|
|
|
int fd = hf->fd;
|
|
|
|
|
|
|
|
if (linux_lseek(fd, offset) != offset)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return linux_write(fd, buf, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hf_info(struct device_d *dev)
|
|
|
|
{
|
|
|
|
struct hf_platform_data *hf = dev->platform_data;
|
|
|
|
|
|
|
|
printf("file: %s\n", hf->filename);
|
|
|
|
}
|
|
|
|
|
2009-06-11 13:33:49 +00:00
|
|
|
static struct file_operations hf_fops = {
|
2007-07-05 16:01:42 +00:00
|
|
|
.read = hf_read,
|
|
|
|
.write = hf_write,
|
2011-05-17 11:53:54 +00:00
|
|
|
.lseek = dev_lseek_default,
|
2009-06-11 13:33:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int hf_probe(struct device_d *dev)
|
|
|
|
{
|
|
|
|
struct hf_platform_data *hf = dev->platform_data;
|
|
|
|
struct hf_priv *priv = xzalloc(sizeof(*priv));
|
|
|
|
|
|
|
|
priv->pdata = hf;
|
|
|
|
|
|
|
|
priv->cdev.name = hf->name;
|
|
|
|
priv->cdev.size = hf->size;
|
|
|
|
priv->cdev.ops = &hf_fops;
|
|
|
|
priv->cdev.priv = hf;
|
2010-11-01 08:26:16 +00:00
|
|
|
#ifdef CONFIG_FS_DEVFS
|
2009-06-11 13:33:49 +00:00
|
|
|
devfs_create(&priv->cdev);
|
2010-11-01 08:26:16 +00:00
|
|
|
#endif
|
2009-06-11 13:33:49 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct driver_d hf_drv = {
|
|
|
|
.name = "hostfile",
|
|
|
|
.probe = hf_probe,
|
2007-07-05 16:01:42 +00:00
|
|
|
.info = hf_info,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int hf_init(void)
|
|
|
|
{
|
2012-09-19 19:22:17 +00:00
|
|
|
return platform_driver_register(&hf_drv);
|
2007-07-05 16:01:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
device_initcall(hf_init);
|
|
|
|
|
2009-12-15 08:11:09 +00:00
|
|
|
int barebox_register_filedev(struct hf_platform_data *hf)
|
2007-07-05 16:01:42 +00:00
|
|
|
{
|
2012-09-20 05:36:42 +00:00
|
|
|
struct device_d *dev;
|
|
|
|
struct resource *res;
|
|
|
|
|
|
|
|
dev = xzalloc(sizeof(*dev));
|
|
|
|
strcpy(dev->name, "hostfile");
|
|
|
|
dev->id = DEVICE_ID_DYNAMIC;
|
|
|
|
dev->platform_data = hf;
|
|
|
|
|
|
|
|
res = xzalloc(sizeof(struct resource));
|
|
|
|
res[0].start = hf->base;
|
|
|
|
res[0].end = hf->base + hf->size - 1;
|
|
|
|
res[0].flags = IORESOURCE_MEM;
|
|
|
|
|
|
|
|
dev->resource = res;
|
|
|
|
dev->num_resources = 1;
|
|
|
|
|
|
|
|
return sandbox_add_device(dev);
|
2007-07-05 16:01:42 +00:00
|
|
|
}
|
|
|
|
|