9
0
Fork 0

implement memmap().

With this function we can get a pointer to directly memory mapped
devices like nor flash or RAM. Useful for bootm where we save one
memcopy when the image is mappable
This commit is contained in:
Sascha Hauer 2007-07-15 13:50:04 +02:00
parent 9b3761c445
commit 665291e693
8 changed files with 79 additions and 0 deletions

View File

@ -41,6 +41,7 @@ static void dev_del_partitions(struct device_d *physdev)
dev = device_from_spec_str(buf, NULL);
if (dev) {
struct partition *part = dev->type_data;
printf("unregister %s %s\n", dev->name, dev->id);
unregister_device(dev);
free(part);
} else

View File

@ -44,6 +44,22 @@ static int part_erase(struct device_d *dev, size_t count, unsigned long offset)
return -1;
}
static int part_memmap(struct device_d *dev, void **map, int flags)
{
struct partition *part = dev->type_data;
int ret;
if (part->physdev->driver->memmap) {
ret = part->physdev->driver->memmap(part->physdev, map, flags);
if (ret)
return ret;
*map = (void *)((unsigned long)*map + part->offset);
return 0;
}
return -1;
}
static ssize_t part_read(struct device_d *dev, void *buf, size_t count, unsigned long offset, ulong flags)
{
struct partition *part = dev->type_data;
@ -82,6 +98,7 @@ struct driver_d part_driver = {
.read = part_read,
.write = part_write,
.erase = part_erase,
.memmap = part_memmap,
};
static int partition_init(void)

View File

@ -518,6 +518,7 @@ static struct driver_d cfi_driver = {
.read = mem_read,
.write = cfi_write,
.erase = cfi_erase,
.memmap = generic_memmap_ro,
.info = cfi_info,
};

View File

@ -50,6 +50,13 @@ static int devfs_erase(struct device_d *_dev, FILE *f, size_t count, unsigned lo
return dev_erase(dev, count, offset);
}
static int devfs_memmap(struct device_d *_dev, FILE *f, void **map, int flags)
{
struct device_d *dev = f->inode;
return dev_memmap(dev, map, flags);
}
static int devfs_open(struct device_d *_dev, FILE *file, const char *filename)
{
struct device_d *dev = get_device_by_id(filename + 1);
@ -146,6 +153,7 @@ static struct fs_driver_d devfs_driver = {
.closedir = devfs_closedir,
.stat = devfs_stat,
.erase = devfs_erase,
.memmap = devfs_memmap,
.flags = FS_DRIVER_NO_DEV,
.drv = {
.type = DEVICE_TYPE_FS,

19
fs/fs.c
View File

@ -516,6 +516,25 @@ int erase(int fd, size_t count, unsigned long offset)
return errno;
}
void *memmap(int fd, int flags)
{
struct device_d *dev;
struct fs_driver_d *fsdrv;
FILE *f = &files[fd];
void *ret = NULL;
dev = f->dev;
fsdrv = (struct fs_driver_d *)dev->driver->type_data;
if (fsdrv->memmap)
errno = fsdrv->memmap(dev, f, &ret, flags);
else
errno = -EINVAL;
return ret;
}
int close(int fd)
{
struct device_d *dev;

View File

@ -53,6 +53,7 @@ struct driver_d {
ssize_t (*read) (struct device_d*, void* buf, size_t count, ulong offset, ulong flags);
ssize_t (*write) (struct device_d*, const void* buf, size_t count, ulong offset, ulong flags);
ssize_t (*erase) (struct device_d*, size_t count, unsigned long offset);
int (*memmap)(struct device_d*, void **map, int flags);
void (*info) (struct device_d *);
void (*shortinfo) (struct device_d *);
@ -100,6 +101,7 @@ struct driver_d *get_driver_by_name(const char *name);
ssize_t dev_read(struct device_d *dev, void *buf, size_t count, ulong offset, ulong flags);
ssize_t dev_write(struct device_d *dev, const void *buf, size_t count, ulong offset, ulong flags);
ssize_t dev_erase(struct device_d *dev, size_t count, unsigned long offset);
int dev_memmap(struct device_d *dev, void **map, int flags);
/* These are used by drivers which work with direct memory accesses */
ssize_t mem_read(struct device_d *dev, void *buf, size_t count, ulong offset, ulong flags);
@ -108,5 +110,8 @@ ssize_t mem_write(struct device_d *dev, const void *buf, size_t count, ulong off
/* Use this if you have nothing to do in your drivers probe function */
int dummy_probe(struct device_d *);
int generic_memmap_ro(struct device_d *dev, void **map, int flags);
int generic_memmap_rw(struct device_d *dev, void **map, int flags);
#endif /* DRIVER_H */

View File

@ -67,6 +67,8 @@ struct fs_driver_d {
int (*erase)(struct device_d *dev, FILE *f, size_t count,
unsigned long offset);
int (*memmap)(struct device_d *dev, FILE *f, void **map, int flags);
struct driver_d drv;
unsigned long flags;
@ -110,6 +112,10 @@ int umount(const char *pathname);
/* not-so-standard erase */
int erase(int fd, size_t count, unsigned long offset);
void *memmap(int fd, int flags);
#define PROT_READ 1
#define PROT_WRITE 2
#define LS_RECURSIVE 1
#define LS_SHOWARG 2

View File

@ -292,6 +292,28 @@ ssize_t dev_erase(struct device_d *dev, size_t count, unsigned long offset)
return -ENOSYS;
}
ssize_t dev_memmap(struct device_d *dev, void **map, int flags)
{
if (dev->driver->memmap)
return dev->driver->memmap(dev, map, flags);
errno = -ENOSYS;
return -ENOSYS;
}
int generic_memmap_ro(struct device_d *dev, void **map, int flags)
{
if (flags & PROT_WRITE)
return -EACCES;
*map = (void *)dev->map_base;
return 0;
}
int generic_memmap_rw(struct device_d *dev, void **map, int flags)
{
*map = (void *)dev->map_base;
return 0;
}
int dummy_probe(struct device_d *dev)
{
return 0;