diff --git a/arch/sandbox/board/hostfile.c b/arch/sandbox/board/hostfile.c index 3e64359..c1a2643 100644 --- a/arch/sandbox/board/hostfile.c +++ b/arch/sandbox/board/hostfile.c @@ -27,8 +27,11 @@ #include #include +#include + struct hf_priv { struct cdev cdev; + const char *filename; int fd; }; @@ -56,9 +59,9 @@ static void hf_info(struct device_d *dev) { - struct hf_platform_data *hf = dev->platform_data; + struct hf_priv *priv = dev->priv; - printf("file: %s\n", hf->filename); + printf("file: %s\n", priv->filename); } static struct file_operations hf_fops = { @@ -69,53 +72,87 @@ static int hf_probe(struct device_d *dev) { - struct hf_platform_data *hf = dev->platform_data; struct hf_priv *priv = xzalloc(sizeof(*priv)); struct resource *res; + int err; res = dev_get_resource(dev, IORESOURCE_MEM, 0); if (IS_ERR(res)) return PTR_ERR(res); - priv->fd = hf->fd; - priv->cdev.name = hf->devname; priv->cdev.size = resource_size(res); + + if (!dev->device_node) + return -ENODEV; + + err = of_property_read_u32(dev->device_node, "barebox,fd", &priv->fd); + if (err) + return err; + + err = of_property_read_string(dev->device_node, "barebox,filename", + &priv->filename); + if (err) + return err; + + priv->cdev.name = dev->device_node->name; priv->cdev.dev = dev; priv->cdev.ops = &hf_fops; priv->cdev.priv = priv; dev->info = hf_info; + dev->priv = priv; -#ifdef CONFIG_FS_DEVFS - devfs_create(&priv->cdev); -#endif - - return 0; + return devfs_create(&priv->cdev); } +static __maybe_unused struct of_device_id hostfile_dt_ids[] = { + { + .compatible = "barebox,hostfile", + }, { + /* sentinel */ + } +}; + static struct driver_d hf_drv = { .name = "hostfile", + .of_compatible = DRV_OF_COMPAT(hostfile_dt_ids), .probe = hf_probe, }; coredevice_platform_driver(hf_drv); -int barebox_register_filedev(struct hf_platform_data *hf) +static int of_hostfile_fixup(struct device_node *root, void *ctx) { - struct device_d *dev; - struct resource *res; + struct hf_info *hf = ctx; + struct device_node *node; + uint32_t reg[] = { + hf->base >> 32, + hf->base, + hf->size + }; + int ret; - dev = xzalloc(sizeof(*dev)); - strcpy(dev->name, "hostfile"); - dev->id = DEVICE_ID_DYNAMIC; - dev->platform_data = hf; + node = of_new_node(root, hf->devname); - res = xzalloc(sizeof(struct resource)); - res[0].start = hf->base; - res[0].end = hf->base + hf->size - 1; - res[0].flags = IORESOURCE_MEM; + ret = of_set_property(node, "compatible", hostfile_dt_ids->compatible, + strlen(hostfile_dt_ids->compatible) + 1, 1); + if (ret) + return ret; - dev->resource = res; - dev->num_resources = 1; + ret = of_property_write_u32_array(node, "reg", reg, ARRAY_SIZE(reg)); + if (ret) + return ret; - return sandbox_add_device(dev); + ret = of_property_write_u32(node, "barebox,fd", hf->fd); + if (ret) + return ret; + + ret = of_set_property(node, "barebox,filename", hf->filename, + strlen(hf->filename) + 1, 1); + + return ret; +} + +int barebox_register_filedev(struct hf_info *hf) +{ + return of_register_fixup(of_hostfile_fixup, hf); } diff --git a/arch/sandbox/mach-sandbox/include/mach/hostfile.h b/arch/sandbox/mach-sandbox/include/mach/hostfile.h index 7470631..627fe28 100644 --- a/arch/sandbox/mach-sandbox/include/mach/hostfile.h +++ b/arch/sandbox/mach-sandbox/include/mach/hostfile.h @@ -1,15 +1,14 @@ #ifndef __ASM_ARCH_HOSTFILE_H #define __ASM_ARCH_HOSTFILE_H -struct hf_platform_data { +struct hf_info { int fd; - size_t size; unsigned long base; - char *filename; - char *devname; + size_t size; + const char *devname; + const char *filename; }; -int barebox_register_filedev(struct hf_platform_data *hf); +int barebox_register_filedev(struct hf_info *hf); #endif /* __ASM_ARCH_HOSTFILE_H */ - diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c index 7aa0f5d..d627391 100644 --- a/arch/sandbox/os/common.c +++ b/arch/sandbox/os/common.c @@ -208,13 +208,13 @@ static int add_image(char *str, char *devname_template, int *devname_number) { + struct hf_info *hf = malloc(sizeof(struct hf_info)); char *filename, *devname; char tmp[16]; int readonly = 0; struct stat s; char *opt; int fd, ret; - struct hf_platform_data *hf = malloc(sizeof(struct hf_platform_data)); if (!hf) return -1;