get rid of device ids
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
2f8df2a003
commit
02ba8a0542
|
@ -34,7 +34,6 @@ extra-y += u-boot.lds
|
||||||
|
|
||||||
static struct device_d scb9328_serial_device = {
|
static struct device_d scb9328_serial_device = {
|
||||||
.name = "imx_serial",
|
.name = "imx_serial",
|
||||||
.id = "cs0",
|
|
||||||
.map_base = IMX_UART1_BASE,
|
.map_base = IMX_UART1_BASE,
|
||||||
.size = 4096,
|
.size = 4096,
|
||||||
};
|
};
|
||||||
|
|
|
@ -220,7 +220,7 @@ void flush_cache(unsigned long dummy1, unsigned long dummy2)
|
||||||
extern void start_uboot(void);
|
extern void start_uboot(void);
|
||||||
extern void mem_malloc_init(void *start, void *end);
|
extern void mem_malloc_init(void *start, void *end);
|
||||||
|
|
||||||
static int add_image(char *str, char *name_template)
|
static int add_image(char *str, char *name)
|
||||||
{
|
{
|
||||||
char *file;
|
char *file;
|
||||||
int readonly = 0, map = 1;
|
int readonly = 0, map = 1;
|
||||||
|
@ -257,6 +257,7 @@ static int add_image(char *str, char *name_template)
|
||||||
}
|
}
|
||||||
|
|
||||||
hf->size = s.st_size;
|
hf->size = s.st_size;
|
||||||
|
hf->name = strdup(name);
|
||||||
|
|
||||||
if (map) {
|
if (map) {
|
||||||
hf->map_base = (unsigned long)mmap(NULL, hf->size,
|
hf->map_base = (unsigned long)mmap(NULL, hf->size,
|
||||||
|
@ -266,8 +267,7 @@ static int add_image(char *str, char *name_template)
|
||||||
printf("warning: mmapping %s failed\n", file);
|
printf("warning: mmapping %s failed\n", file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = u_boot_register_filedev(hf);
|
||||||
ret = u_boot_register_filedev(hf, name_template);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err_out;
|
goto err_out;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -286,6 +286,8 @@ int main(int argc, char *argv[])
|
||||||
void *ram;
|
void *ram;
|
||||||
int opt, ret, fd;
|
int opt, ret, fd;
|
||||||
int malloc_size = 8 * 1024 * 1024;
|
int malloc_size = 8 * 1024 * 1024;
|
||||||
|
char str[6];
|
||||||
|
int fdno = 0, envno = 0;
|
||||||
|
|
||||||
ram = malloc(malloc_size);
|
ram = malloc(malloc_size);
|
||||||
if (!ram) {
|
if (!ram) {
|
||||||
|
@ -300,9 +302,11 @@ int main(int argc, char *argv[])
|
||||||
print_usage(basename(argv[0]));
|
print_usage(basename(argv[0]));
|
||||||
exit(0);
|
exit(0);
|
||||||
case 'i':
|
case 'i':
|
||||||
ret = add_image(optarg, "fd");
|
sprintf(str, "fd%d", fdno);
|
||||||
|
ret = add_image(optarg, str);
|
||||||
if (ret)
|
if (ret)
|
||||||
exit(1);
|
exit(1);
|
||||||
|
fdno++;
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
/* This option is broken. add_image needs malloc, so
|
/* This option is broken. add_image needs malloc, so
|
||||||
|
@ -312,9 +316,11 @@ int main(int argc, char *argv[])
|
||||||
malloc_size = strtoul(optarg, NULL, 0);
|
malloc_size = strtoul(optarg, NULL, 0);
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
|
sprintf(str, "env%d", envno);
|
||||||
ret = add_image(optarg, "env");
|
ret = add_image(optarg, "env");
|
||||||
if (ret)
|
if (ret)
|
||||||
exit(1);
|
exit(1);
|
||||||
|
envno++;
|
||||||
break;
|
break;
|
||||||
case 'O':
|
case 'O':
|
||||||
fd = open(optarg, O_WRONLY);
|
fd = open(optarg, O_WRONLY);
|
||||||
|
|
|
@ -29,9 +29,14 @@
|
||||||
#include <asm/arch/hostfile.h>
|
#include <asm/arch/hostfile.h>
|
||||||
#include <xfuncs.h>
|
#include <xfuncs.h>
|
||||||
|
|
||||||
static ssize_t hf_read(struct device_d *dev, void *buf, size_t count, ulong offset, ulong flags)
|
struct hf_priv {
|
||||||
|
struct cdev cdev;
|
||||||
|
struct hf_platform_data *pdata;
|
||||||
|
};
|
||||||
|
|
||||||
|
static ssize_t hf_read(struct cdev *cdev, void *buf, size_t count, ulong offset, ulong flags)
|
||||||
{
|
{
|
||||||
struct hf_platform_data *hf = dev->platform_data;
|
struct hf_platform_data *hf = cdev->priv;
|
||||||
int fd = hf->fd;
|
int fd = hf->fd;
|
||||||
|
|
||||||
if (linux_lseek(fd, offset) != offset)
|
if (linux_lseek(fd, offset) != offset)
|
||||||
|
@ -40,9 +45,9 @@ static ssize_t hf_read(struct device_d *dev, void *buf, size_t count, ulong offs
|
||||||
return linux_read(fd, buf, count);
|
return linux_read(fd, buf, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t hf_write(struct device_d *dev, const void *buf, size_t count, ulong offset, ulong flags)
|
static ssize_t hf_write(struct cdev *cdev, const void *buf, size_t count, ulong offset, ulong flags)
|
||||||
{
|
{
|
||||||
struct hf_platform_data *hf = dev->platform_data;
|
struct hf_platform_data *hf = cdev->priv;
|
||||||
int fd = hf->fd;
|
int fd = hf->fd;
|
||||||
|
|
||||||
if (linux_lseek(fd, offset) != offset)
|
if (linux_lseek(fd, offset) != offset)
|
||||||
|
@ -58,11 +63,30 @@ static void hf_info(struct device_d *dev)
|
||||||
printf("file: %s\n", hf->filename);
|
printf("file: %s\n", hf->filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct driver_d hf_drv = {
|
static struct file_operations hf_fops = {
|
||||||
.name = "hostfile",
|
|
||||||
.probe = dummy_probe,
|
|
||||||
.read = hf_read,
|
.read = hf_read,
|
||||||
.write = hf_write,
|
.write = hf_write,
|
||||||
|
};
|
||||||
|
|
||||||
|
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;
|
||||||
|
devfs_create(&priv->cdev);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct driver_d hf_drv = {
|
||||||
|
.name = "hostfile",
|
||||||
|
.probe = hf_probe,
|
||||||
.info = hf_info,
|
.info = hf_info,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -73,7 +97,7 @@ static int hf_init(void)
|
||||||
|
|
||||||
device_initcall(hf_init);
|
device_initcall(hf_init);
|
||||||
|
|
||||||
int u_boot_register_filedev(struct hf_platform_data *hf, char *name_template)
|
int u_boot_register_filedev(struct hf_platform_data *hf)
|
||||||
{
|
{
|
||||||
struct device_d *dev;
|
struct device_d *dev;
|
||||||
|
|
||||||
|
@ -81,10 +105,7 @@ int u_boot_register_filedev(struct hf_platform_data *hf, char *name_template)
|
||||||
|
|
||||||
dev->platform_data = hf;
|
dev->platform_data = hf;
|
||||||
|
|
||||||
hf = dev->platform_data;
|
|
||||||
|
|
||||||
strcpy(dev->name, "hostfile");
|
strcpy(dev->name, "hostfile");
|
||||||
get_free_deviceid(dev->id, name_template);
|
|
||||||
dev->size = hf->size;
|
dev->size = hf->size;
|
||||||
dev->map_base = hf->map_base;
|
dev->map_base = hf->map_base;
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ static int do_mount (cmd_tbl_t *cmdtp, int argc, char *argv[])
|
||||||
entry = mtab_next_entry(entry);
|
entry = mtab_next_entry(entry);
|
||||||
if (entry) {
|
if (entry) {
|
||||||
printf("%s on %s type %s\n",
|
printf("%s on %s type %s\n",
|
||||||
entry->parent_device ? entry->parent_device->id : "none",
|
entry->parent_device ? entry->parent_device->name : "none",
|
||||||
entry->path,
|
entry->path,
|
||||||
entry->dev->name);
|
entry->dev->name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,10 +45,10 @@ static void netboot_update_env (void)
|
||||||
char tmp[22];
|
char tmp[22];
|
||||||
|
|
||||||
if (NetOurGatewayIP)
|
if (NetOurGatewayIP)
|
||||||
dev_set_param_ip(eth_current->dev, "gateway", NetOurGatewayIP);
|
dev_set_param_ip(ð_current->dev, "gateway", NetOurGatewayIP);
|
||||||
|
|
||||||
if (NetOurSubnetMask)
|
if (NetOurSubnetMask)
|
||||||
dev_set_param_ip(eth_current->dev, "netmask", NetOurSubnetMask);
|
dev_set_param_ip(ð_current->dev, "netmask", NetOurSubnetMask);
|
||||||
|
|
||||||
|
|
||||||
if (NetOurHostName[0])
|
if (NetOurHostName[0])
|
||||||
|
@ -58,10 +58,10 @@ static void netboot_update_env (void)
|
||||||
setenv ("rootpath", NetOurRootPath);
|
setenv ("rootpath", NetOurRootPath);
|
||||||
|
|
||||||
if (NetOurIP)
|
if (NetOurIP)
|
||||||
dev_set_param_ip(eth_current->dev, "ipaddr", NetOurIP);
|
dev_set_param_ip(ð_current->dev, "ipaddr", NetOurIP);
|
||||||
|
|
||||||
if (NetServerIP)
|
if (NetServerIP)
|
||||||
dev_set_param_ip(eth_current->dev, "serverip", NetServerIP);
|
dev_set_param_ip(ð_current->dev, "serverip", NetServerIP);
|
||||||
|
|
||||||
if (NetOurDNSIP) {
|
if (NetOurDNSIP) {
|
||||||
ip_to_string (NetOurDNSIP, tmp);
|
ip_to_string (NetOurDNSIP, tmp);
|
||||||
|
|
|
@ -120,10 +120,14 @@ postcore_initcall(getc_buffer_flush);
|
||||||
|
|
||||||
int console_register(struct console_device *newcdev)
|
int console_register(struct console_device *newcdev)
|
||||||
{
|
{
|
||||||
struct device_d *dev = newcdev->dev;
|
struct device_d *dev = &newcdev->class_dev;
|
||||||
int first = 0;
|
int first = 0;
|
||||||
char ch;
|
char ch;
|
||||||
|
|
||||||
|
strcpy(dev->name, "cs");
|
||||||
|
dev->type_data = newcdev->dev->type_data;
|
||||||
|
register_device(dev);
|
||||||
|
|
||||||
if (newcdev->setbrg) {
|
if (newcdev->setbrg) {
|
||||||
newcdev->baudrate_param.set = console_baudrate_set;
|
newcdev->baudrate_param.set = console_baudrate_set;
|
||||||
newcdev->baudrate_param.name = "baudrate";
|
newcdev->baudrate_param.name = "baudrate";
|
||||||
|
|
|
@ -142,7 +142,7 @@ const char *getenv (const char *name)
|
||||||
char *par = strchr(devstr, '.');
|
char *par = strchr(devstr, '.');
|
||||||
struct device_d *dev;
|
struct device_d *dev;
|
||||||
*par = 0;
|
*par = 0;
|
||||||
dev = get_device_by_id(devstr);
|
dev = get_device_by_name(devstr);
|
||||||
if (dev) {
|
if (dev) {
|
||||||
par++;
|
par++;
|
||||||
ret = dev_get_param(dev, par);
|
ret = dev_get_param(dev, par);
|
||||||
|
@ -213,7 +213,7 @@ int setenv(const char *_name, const char *value)
|
||||||
struct device_d *dev;
|
struct device_d *dev;
|
||||||
|
|
||||||
*par++ = 0;
|
*par++ = 0;
|
||||||
dev = get_device_by_id(name);
|
dev = get_device_by_name(name);
|
||||||
if (dev)
|
if (dev)
|
||||||
ret = dev_set_param(dev, par, value);
|
ret = dev_set_param(dev, par, value);
|
||||||
else
|
else
|
||||||
|
|
|
@ -152,37 +152,16 @@ static struct file_operations nand_ops = {
|
||||||
.erase = nand_erase,
|
.erase = nand_erase,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int nand_device_probe(struct device_d *dev)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct driver_d nand_device_driver = {
|
|
||||||
.name = "nand_device",
|
|
||||||
.probe = nand_device_probe,
|
|
||||||
};
|
|
||||||
|
|
||||||
static int nand_init(void)
|
|
||||||
{
|
|
||||||
register_driver(&nand_device_driver);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
device_initcall(nand_init);
|
|
||||||
|
|
||||||
int add_mtd_device(struct mtd_info *mtd)
|
int add_mtd_device(struct mtd_info *mtd)
|
||||||
{
|
{
|
||||||
struct device_d *dev = &mtd->class_dev;
|
strcpy(mtd->class_dev.name, "nand");
|
||||||
char name[MAX_DRIVER_NAME];
|
register_device(&mtd->class_dev);
|
||||||
|
|
||||||
get_free_deviceid(name, "nand");
|
|
||||||
|
|
||||||
mtd->cdev.ops = &nand_ops;
|
mtd->cdev.ops = &nand_ops;
|
||||||
mtd->cdev.size = mtd->size;
|
mtd->cdev.size = mtd->size;
|
||||||
mtd->cdev.name = strdup(name);
|
mtd->cdev.name = asprintf("nand%d", mtd->class_dev.id);
|
||||||
mtd->cdev.dev = dev;
|
|
||||||
mtd->cdev.priv = mtd;
|
mtd->cdev.priv = mtd;
|
||||||
|
mtd->cdev.dev = &mtd->class_dev;
|
||||||
|
|
||||||
devfs_create(&mtd->cdev);
|
devfs_create(&mtd->cdev);
|
||||||
|
|
||||||
|
|
|
@ -1451,7 +1451,6 @@ static int cfi_probe (struct device_d *dev)
|
||||||
{
|
{
|
||||||
unsigned long size = 0;
|
unsigned long size = 0;
|
||||||
flash_info_t *info = xzalloc(sizeof(flash_info_t));
|
flash_info_t *info = xzalloc(sizeof(flash_info_t));
|
||||||
char name[MAX_DRIVER_NAME];
|
|
||||||
|
|
||||||
dev->priv = (void *)info;
|
dev->priv = (void *)info;
|
||||||
|
|
||||||
|
@ -1466,8 +1465,7 @@ static int cfi_probe (struct device_d *dev)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
get_free_deviceid(name, "nor");
|
info->cdev.name = asprintf("nor%d", dev->id);
|
||||||
info->cdev.name = strdup(name);
|
|
||||||
info->cdev.size = info->size;
|
info->cdev.size = info->size;
|
||||||
info->cdev.dev = dev;
|
info->cdev.dev = dev;
|
||||||
info->cdev.ops = &cfi_ops;
|
info->cdev.ops = &cfi_ops;
|
||||||
|
|
|
@ -948,7 +948,6 @@ static int cfi_probe (struct device_d *dev)
|
||||||
{
|
{
|
||||||
unsigned long size = 0;
|
unsigned long size = 0;
|
||||||
flash_info_t *info = xzalloc(sizeof(flash_info_t));
|
flash_info_t *info = xzalloc(sizeof(flash_info_t));
|
||||||
char name[MAX_DRIVER_NAME];
|
|
||||||
|
|
||||||
dev->priv = (void *)info;
|
dev->priv = (void *)info;
|
||||||
|
|
||||||
|
@ -969,8 +968,7 @@ static int cfi_probe (struct device_d *dev)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
get_free_deviceid(name, "nor");
|
info->cdev.name = asprintf("nor%d", dev->id);
|
||||||
info->cdev.name = strdup(name);
|
|
||||||
info->cdev.size = info->size;
|
info->cdev.size = info->size;
|
||||||
info->cdev.dev = dev;
|
info->cdev.dev = dev;
|
||||||
info->cdev.ops = &cfi_ops;
|
info->cdev.ops = &cfi_ops;
|
||||||
|
|
|
@ -424,7 +424,6 @@ static int usb_new_device(struct usb_device *dev)
|
||||||
usb_hub_probe(dev, 0);
|
usb_hub_probe(dev, 0);
|
||||||
|
|
||||||
sprintf(dev->dev.name, "usb%d-%d", dev->host->busnum, dev->devnum);
|
sprintf(dev->dev.name, "usb%d-%d", dev->host->busnum, dev->devnum);
|
||||||
sprintf(dev->dev.id, "usb%d-%d", dev->host->busnum, dev->devnum);
|
|
||||||
|
|
||||||
print_usb_device(dev);
|
print_usb_device(dev);
|
||||||
|
|
||||||
|
|
38
fs/devfs.c
38
fs/devfs.c
|
@ -47,29 +47,37 @@ struct cdev *cdev_by_name(const char *filename)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int devfs_read(struct device_d *_dev, FILE *f, void *buf, size_t size)
|
ssize_t cdev_read(struct cdev *cdev, void *buf, size_t count, ulong offset, ulong flags)
|
||||||
{
|
{
|
||||||
struct cdev *cdev = f->inode;
|
|
||||||
|
|
||||||
if (!cdev->ops->read)
|
if (!cdev->ops->read)
|
||||||
return -ENOSYS;
|
return -ENOSYS;
|
||||||
|
|
||||||
return cdev->ops->read(cdev, buf, size,
|
return cdev->ops->read(cdev, buf, count, cdev->offset +offset, flags);
|
||||||
f->pos + cdev->offset, f->flags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int devfs_write(struct device_d *_dev, FILE *f, const void *buf, size_t size)
|
ssize_t cdev_write(struct cdev *cdev, const void *buf, size_t count, ulong offset, ulong flags)
|
||||||
{
|
{
|
||||||
struct cdev *cdev = f->inode;
|
|
||||||
|
|
||||||
if (!cdev->ops->write)
|
if (!cdev->ops->write)
|
||||||
return -ENOSYS;
|
return -ENOSYS;
|
||||||
|
|
||||||
return cdev->ops->write(cdev, buf, size,
|
return cdev->ops->write(cdev, buf, count, cdev->offset + offset, flags);
|
||||||
f->pos + cdev->offset, f->flags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t devfs_lseek(struct device_d *_dev, FILE *f, off_t pos)
|
static int devfs_read(struct device_d *_dev, FILE *f, void *buf, size_t size)
|
||||||
|
{
|
||||||
|
struct cdev *cdev = f->inode;
|
||||||
|
|
||||||
|
return cdev_read(cdev, buf, size, f->pos, f->flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int devfs_write(struct device_d *_dev, FILE *f, const void *buf, size_t size)
|
||||||
|
{
|
||||||
|
struct cdev *cdev = f->inode;
|
||||||
|
|
||||||
|
return cdev_write(cdev, buf, size, f->pos, f->flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
static off_t devfs_lseek(struct device_d *_dev, FILE *f, off_t pos)
|
||||||
{
|
{
|
||||||
struct cdev *cdev = f->inode;
|
struct cdev *cdev = f->inode;
|
||||||
off_t ret = -1;
|
off_t ret = -1;
|
||||||
|
@ -83,7 +91,7 @@ off_t devfs_lseek(struct device_d *_dev, FILE *f, off_t pos)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int devfs_erase(struct device_d *_dev, FILE *f, size_t count, unsigned long offset)
|
static int devfs_erase(struct device_d *_dev, FILE *f, size_t count, unsigned long offset)
|
||||||
{
|
{
|
||||||
struct cdev *cdev = f->inode;
|
struct cdev *cdev = f->inode;
|
||||||
|
|
||||||
|
@ -93,7 +101,7 @@ int devfs_erase(struct device_d *_dev, FILE *f, size_t count, unsigned long offs
|
||||||
return cdev->ops->erase(cdev, count, offset + cdev->offset);
|
return cdev->ops->erase(cdev, count, offset + cdev->offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
int devfs_protect(struct device_d *_dev, FILE *f, size_t count, unsigned long offset, int prot)
|
static int devfs_protect(struct device_d *_dev, FILE *f, size_t count, unsigned long offset, int prot)
|
||||||
{
|
{
|
||||||
struct cdev *cdev = f->inode;
|
struct cdev *cdev = f->inode;
|
||||||
|
|
||||||
|
@ -287,6 +295,8 @@ int devfs_create(struct cdev *new)
|
||||||
return -EEXIST;
|
return -EEXIST;
|
||||||
|
|
||||||
list_add_tail(&new->list, &cdev_list);
|
list_add_tail(&new->list, &cdev_list);
|
||||||
|
if (new->dev)
|
||||||
|
list_add_tail(&new->devices_list, &new->dev->cdevs);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -294,6 +304,8 @@ int devfs_create(struct cdev *new)
|
||||||
void devfs_remove(struct cdev *cdev)
|
void devfs_remove(struct cdev *cdev)
|
||||||
{
|
{
|
||||||
list_del(&cdev->list);
|
list_del(&cdev->list);
|
||||||
|
if (cdev->dev)
|
||||||
|
list_del(&cdev->devices_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
int devfs_add_partition(const char *devname, unsigned long offset, size_t size,
|
int devfs_add_partition(const char *devname, unsigned long offset, size_t size,
|
||||||
|
|
13
fs/fs.c
13
fs/fs.c
|
@ -698,16 +698,16 @@ int mount(const char *device, const char *fsname, const char *_path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fsdev = xzalloc(sizeof(struct fs_device_d));
|
||||||
if (!fs_drv->flags & FS_DRIVER_NO_DEV) {
|
if (!fs_drv->flags & FS_DRIVER_NO_DEV) {
|
||||||
parent_device = get_device_by_id(device + 5);
|
fsdev->backingstore = strdup(device);
|
||||||
if (!parent_device) {
|
if (!device) {
|
||||||
printf("need a device for driver %s\n", fsname);
|
printf("need a device for driver %s\n", fsname);
|
||||||
errno = -ENODEV;
|
errno = -ENODEV;
|
||||||
|
free(fsdev);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fsdev = xzalloc(sizeof(struct fs_device_d));
|
|
||||||
fsdev->parent = parent_device;
|
|
||||||
sprintf(fsdev->dev.name, "%s", fsname);
|
sprintf(fsdev->dev.name, "%s", fsname);
|
||||||
fsdev->dev.type_data = fsdev;
|
fsdev->dev.type_data = fsdev;
|
||||||
|
|
||||||
|
@ -755,6 +755,7 @@ int umount(const char *pathname)
|
||||||
struct mtab_entry *entry = mtab;
|
struct mtab_entry *entry = mtab;
|
||||||
struct mtab_entry *last = mtab;
|
struct mtab_entry *last = mtab;
|
||||||
char *p = normalise_path(pathname);
|
char *p = normalise_path(pathname);
|
||||||
|
struct fs_device_d *fsdev;
|
||||||
|
|
||||||
while(entry && strcmp(p, entry->path)) {
|
while(entry && strcmp(p, entry->path)) {
|
||||||
last = entry;
|
last = entry;
|
||||||
|
@ -774,7 +775,9 @@ int umount(const char *pathname)
|
||||||
last->next = entry->next;
|
last->next = entry->next;
|
||||||
|
|
||||||
unregister_device(entry->dev);
|
unregister_device(entry->dev);
|
||||||
free(entry->dev->type_data);
|
fsdev = entry->dev->type_data;
|
||||||
|
free(fsdev->backingstore);
|
||||||
|
free(fsdev);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,10 @@ struct hf_platform_data {
|
||||||
size_t size;
|
size_t size;
|
||||||
unsigned long map_base;
|
unsigned long map_base;
|
||||||
char *filename;
|
char *filename;
|
||||||
|
char *name;
|
||||||
};
|
};
|
||||||
|
|
||||||
int u_boot_register_filedev(struct hf_platform_data *hf, char *name_template);
|
int u_boot_register_filedev(struct hf_platform_data *hf);
|
||||||
|
|
||||||
#endif /* __ASM_ARCH_HOSTFILE_H */
|
#endif /* __ASM_ARCH_HOSTFILE_H */
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#include <param.h>
|
#include <param.h>
|
||||||
#include <list.h>
|
#include <list.h>
|
||||||
|
#include <driver.h>
|
||||||
|
|
||||||
#define CONSOLE_STDIN (1 << 0)
|
#define CONSOLE_STDIN (1 << 0)
|
||||||
#define CONSOLE_STDOUT (1 << 1)
|
#define CONSOLE_STDOUT (1 << 1)
|
||||||
|
@ -33,6 +34,7 @@
|
||||||
|
|
||||||
struct console_device {
|
struct console_device {
|
||||||
struct device_d *dev;
|
struct device_d *dev;
|
||||||
|
struct device_d class_dev;
|
||||||
|
|
||||||
int (*tstc)(struct console_device *cdev);
|
int (*tstc)(struct console_device *cdev);
|
||||||
void (*putc)(struct console_device *cdev, char c);
|
void (*putc)(struct console_device *cdev, char c);
|
||||||
|
|
|
@ -67,7 +67,7 @@ struct device_d {
|
||||||
/*! The id is used to uniquely identify a device in the system. The id
|
/*! The id is used to uniquely identify a device in the system. The id
|
||||||
* will show up under /dev/ as the device's name. Usually this is
|
* will show up under /dev/ as the device's name. Usually this is
|
||||||
* something like eth0 or nor0. */
|
* something like eth0 or nor0. */
|
||||||
char id[MAX_DRIVER_NAME];
|
int id;
|
||||||
|
|
||||||
/*! FIXME */
|
/*! FIXME */
|
||||||
unsigned long size;
|
unsigned long size;
|
||||||
|
@ -99,6 +99,8 @@ struct device_d {
|
||||||
/*! The parameters for this device. This is used to carry information
|
/*! The parameters for this device. This is used to carry information
|
||||||
* of board specific data from the board code to the device driver. */
|
* of board specific data from the board code to the device driver. */
|
||||||
struct param_d *param;
|
struct param_d *param;
|
||||||
|
|
||||||
|
struct list_head cdevs;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @brief Describes a driver present in the system */
|
/** @brief Describes a driver present in the system */
|
||||||
|
@ -165,13 +167,13 @@ int dev_add_child(struct device_d *dev, struct device_d *child);
|
||||||
*/
|
*/
|
||||||
struct device_d *get_device_by_type(ulong type, struct device_d *last);
|
struct device_d *get_device_by_type(ulong type, struct device_d *last);
|
||||||
struct device_d *get_device_by_id(const char *id);
|
struct device_d *get_device_by_id(const char *id);
|
||||||
struct device_d *get_device_by_path(const char *path);
|
struct device_d *get_device_by_name(const char *name);
|
||||||
|
|
||||||
/* Find a free device id from the given template. This is archieved by
|
/* Find a free device id from the given template. This is archieved by
|
||||||
* appending a number to the template. Dynamically created devices should
|
* appending a number to the template. Dynamically created devices should
|
||||||
* use this function rather than filling the id field themselves.
|
* use this function rather than filling the id field themselves.
|
||||||
*/
|
*/
|
||||||
int get_free_deviceid(char *id, const char *id_template);
|
int get_free_deviceid(const char *name_template);
|
||||||
|
|
||||||
char *deviceid_from_spec_str(const char *str, char **endp);
|
char *deviceid_from_spec_str(const char *str, char **endp);
|
||||||
|
|
||||||
|
@ -294,6 +296,7 @@ struct cdev {
|
||||||
void *priv;
|
void *priv;
|
||||||
struct device_d *dev;
|
struct device_d *dev;
|
||||||
struct list_head list;
|
struct list_head list;
|
||||||
|
struct list_head devices_list;
|
||||||
char *name;
|
char *name;
|
||||||
unsigned long offset;
|
unsigned long offset;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
@ -303,6 +306,8 @@ struct cdev {
|
||||||
int devfs_create(struct cdev *);
|
int devfs_create(struct cdev *);
|
||||||
void devfs_remove(struct cdev *);
|
void devfs_remove(struct cdev *);
|
||||||
struct cdev *cdev_by_name(const char *filename);
|
struct cdev *cdev_by_name(const char *filename);
|
||||||
|
ssize_t cdev_read(struct cdev *cdev, void *buf, size_t count, ulong offset, ulong flags);
|
||||||
|
ssize_t cdev_write(struct cdev *cdev, const void *buf, size_t count, ulong offset, ulong flags);
|
||||||
|
|
||||||
#define DEVFS_PARTITION_FIXED (1 << 0)
|
#define DEVFS_PARTITION_FIXED (1 << 0)
|
||||||
#define DEVFS_PARTITION_READONLY (1 << 1)
|
#define DEVFS_PARTITION_READONLY (1 << 1)
|
||||||
|
|
|
@ -88,7 +88,7 @@ struct mtab_entry {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct fs_device_d {
|
struct fs_device_d {
|
||||||
struct device_d *parent; /* the device we are associated with */
|
char *backingstore; /* the device we are associated with */
|
||||||
struct device_d dev; /* our own device */
|
struct device_d dev; /* our own device */
|
||||||
|
|
||||||
struct fs_driver_d *driver;
|
struct fs_driver_d *driver;
|
||||||
|
|
81
lib/driver.c
81
lib/driver.c
|
@ -42,42 +42,31 @@ EXPORT_SYMBOL(driver_list);
|
||||||
|
|
||||||
static LIST_HEAD(active);
|
static LIST_HEAD(active);
|
||||||
|
|
||||||
struct device_d *device_by_name(const char *name)
|
struct device_d *get_device_by_name(const char *name)
|
||||||
{
|
{
|
||||||
struct device_d *dev;
|
struct device_d *dev;
|
||||||
|
char devname[MAX_DRIVER_NAME + 3];
|
||||||
|
|
||||||
for_each_device(dev) {
|
for_each_device(dev) {
|
||||||
if(!strcmp(name, dev->name))
|
sprintf(devname, "%s%d", dev->name, dev->id);
|
||||||
|
if(!strcmp(name, devname))
|
||||||
return dev;
|
return dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct device_d *get_device_by_id(const char *id)
|
int get_free_deviceid(const char *name_template)
|
||||||
{
|
|
||||||
struct device_d *dev;
|
|
||||||
|
|
||||||
for_each_device(dev) {
|
|
||||||
if(!strcmp(id, dev->id))
|
|
||||||
return dev;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
int get_free_deviceid(char *id, const char *id_template)
|
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
char name[MAX_DRIVER_NAME + 3];
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
sprintf(id, "%s%d", id_template, i);
|
sprintf(name, "%s%d", name_template, i);
|
||||||
if (!get_device_by_id(id))
|
if (!get_device_by_name(name))
|
||||||
return 0;
|
return i;
|
||||||
i++;
|
i++;
|
||||||
};
|
};
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int match(struct driver_d *drv, struct device_d *dev)
|
static int match(struct driver_d *drv, struct device_d *dev)
|
||||||
|
@ -106,10 +95,8 @@ int register_device(struct device_d *new_device)
|
||||||
{
|
{
|
||||||
struct driver_d *drv;
|
struct driver_d *drv;
|
||||||
|
|
||||||
if(*new_device->id && get_device_by_id(new_device->id)) {
|
new_device->id = get_free_deviceid(new_device->name);
|
||||||
printf("device %s already exists\n", new_device->id);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
debug ("register_device: %s\n",new_device->name);
|
debug ("register_device: %s\n",new_device->name);
|
||||||
|
|
||||||
if (!new_device->bus) {
|
if (!new_device->bus) {
|
||||||
|
@ -119,6 +106,7 @@ int register_device(struct device_d *new_device)
|
||||||
|
|
||||||
list_add_tail(&new_device->list, &device_list);
|
list_add_tail(&new_device->list, &device_list);
|
||||||
INIT_LIST_HEAD(&new_device->children);
|
INIT_LIST_HEAD(&new_device->children);
|
||||||
|
INIT_LIST_HEAD(&new_device->cdevs);
|
||||||
|
|
||||||
for_each_driver(drv) {
|
for_each_driver(drv) {
|
||||||
if (!match(drv, new_device))
|
if (!match(drv, new_device))
|
||||||
|
@ -175,7 +163,7 @@ struct driver_d *get_driver_by_name(const char *name)
|
||||||
|
|
||||||
static void noinfo(struct device_d *dev)
|
static void noinfo(struct device_d *dev)
|
||||||
{
|
{
|
||||||
printf("no info available for %s\n", dev->id);
|
printf("no info available for %s\n", dev->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void noshortinfo(struct device_d *dev)
|
static void noshortinfo(struct device_d *dev)
|
||||||
|
@ -207,28 +195,6 @@ int register_driver(struct driver_d *drv)
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(register_driver);
|
EXPORT_SYMBOL(register_driver);
|
||||||
|
|
||||||
/* Get a device struct from the beginning of the string. Default to mem if no
|
|
||||||
* device is given, return NULL if a unknown device is given.
|
|
||||||
* If endp is not NULL, this function stores a pointer to the first character
|
|
||||||
* after the device name in *endp.
|
|
||||||
*/
|
|
||||||
struct device_d *get_device_by_path(const char *path)
|
|
||||||
{
|
|
||||||
struct device_d *dev = NULL;
|
|
||||||
char *npath = normalise_path(path);
|
|
||||||
|
|
||||||
if (strncmp(npath, "/dev/", 5))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
dev = get_device_by_id(npath + 5);
|
|
||||||
|
|
||||||
out:
|
|
||||||
free(npath);
|
|
||||||
errno = -ENODEV;
|
|
||||||
return dev;
|
|
||||||
}
|
|
||||||
EXPORT_SYMBOL(get_device_by_path);
|
|
||||||
|
|
||||||
int dev_protect(struct device_d *dev, size_t count, unsigned long offset, int prot)
|
int dev_protect(struct device_d *dev, size_t count, unsigned long offset, int prot)
|
||||||
{
|
{
|
||||||
printf("%s: currently broken\n", __func__);
|
printf("%s: currently broken\n", __func__);
|
||||||
|
@ -264,13 +230,23 @@ EXPORT_SYMBOL(dummy_probe);
|
||||||
static int do_devinfo_subtree(struct device_d *dev, int depth, char edge)
|
static int do_devinfo_subtree(struct device_d *dev, int depth, char edge)
|
||||||
{
|
{
|
||||||
struct device_d *child;
|
struct device_d *child;
|
||||||
|
struct cdev *cdev;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < depth; i++)
|
for (i = 0; i < depth; i++)
|
||||||
printf("| ");
|
printf("| ");
|
||||||
|
|
||||||
if (*dev->id)
|
printf("%c----%s%d", edge, dev->name, dev->id);
|
||||||
printf("%c----%s\n", edge, dev->id);
|
if (!list_empty(&dev->cdevs)) {
|
||||||
|
printf(" (");
|
||||||
|
list_for_each_entry(cdev, &dev->cdevs, devices_list) {
|
||||||
|
printf("%s", cdev->name);
|
||||||
|
if (!list_is_last(&cdev->devices_list, &dev->cdevs))
|
||||||
|
printf(", ");
|
||||||
|
}
|
||||||
|
printf(")");
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
if (!list_empty(&dev->children)) {
|
if (!list_empty(&dev->children)) {
|
||||||
device_for_each_child(dev, child) {
|
device_for_each_child(dev, child) {
|
||||||
|
@ -287,10 +263,7 @@ const char *dev_id(const struct device_d *dev)
|
||||||
{
|
{
|
||||||
static char buf[sizeof(unsigned long) * 2];
|
static char buf[sizeof(unsigned long) * 2];
|
||||||
|
|
||||||
if (strlen(dev->id))
|
sprintf(buf, "%s%d", dev->name, dev->id);
|
||||||
return dev->id;
|
|
||||||
|
|
||||||
sprintf(buf, "0x%08x", dev->map_base);
|
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
@ -325,7 +298,7 @@ static int do_devinfo ( cmd_tbl_t *cmdtp, int argc, char *argv[])
|
||||||
for_each_driver(drv)
|
for_each_driver(drv)
|
||||||
printf("%10s\n",drv->name);
|
printf("%10s\n",drv->name);
|
||||||
} else {
|
} else {
|
||||||
struct device_d *dev = get_device_by_path(argv[1]);
|
struct device_d *dev = get_device_by_name(argv[1]);
|
||||||
|
|
||||||
if (!dev) {
|
if (!dev) {
|
||||||
printf("no such device: %s\n",argv[1]);
|
printf("no such device: %s\n",argv[1]);
|
||||||
|
|
Loading…
Reference in New Issue