forked from luck/tmp_suning_uos_patched
da4458bda2
Change RomFS so that it can use MTD devices directly - without the intercession of the block layer - as well as using block devices. This permits RomFS: (1) to use the MTD direct mapping facility available under NOMMU conditions if the underlying device is directly accessible by the CPU (including XIP); (2) and thus to be used when the block layer is disabled. RomFS can be configured with support just for MTD devices, just for Block devices or for both. If RomFS is configured for both, then it will treat mtdblock device files as MTD backing stores, not block layer backing stores. I tested this using a CONFIG_MMU=n CONFIG_BLOCK=n kernel running on my FRV board with a RomFS image installed on the mtdram test device. I see my test program being run XIP: # cat /proc/maps ... c0c000b0-c0c01f8c r-xs 00000000 1f:00 144 /mnt/doshm ... GDB on the kernel can be used to show that these addresses are within the set-aside RAM space. Signed-off-by: David Howells <dhowells@redhat.com> Tested-by: Bernd Schmidt <bernd.schmidt@analog.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
76 lines
2.1 KiB
C
76 lines
2.1 KiB
C
/* NOMMU mmap support for RomFS on MTD devices
|
|
*
|
|
* Copyright © 2007 Red Hat, Inc. All Rights Reserved.
|
|
* Written by David Howells (dhowells@redhat.com)
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
#include <linux/mm.h>
|
|
#include <linux/mtd/super.h>
|
|
#include "internal.h"
|
|
|
|
/*
|
|
* try to determine where a shared mapping can be made
|
|
* - only supported for NOMMU at the moment (MMU can't doesn't copy private
|
|
* mappings)
|
|
* - attempts to map through to the underlying MTD device
|
|
*/
|
|
static unsigned long romfs_get_unmapped_area(struct file *file,
|
|
unsigned long addr,
|
|
unsigned long len,
|
|
unsigned long pgoff,
|
|
unsigned long flags)
|
|
{
|
|
struct inode *inode = file->f_mapping->host;
|
|
struct mtd_info *mtd = inode->i_sb->s_mtd;
|
|
unsigned long isize, offset;
|
|
|
|
if (!mtd)
|
|
goto cant_map_directly;
|
|
|
|
isize = i_size_read(inode);
|
|
offset = pgoff << PAGE_SHIFT;
|
|
if (offset > isize || len > isize || offset > isize - len)
|
|
return (unsigned long) -EINVAL;
|
|
|
|
/* we need to call down to the MTD layer to do the actual mapping */
|
|
if (mtd->get_unmapped_area) {
|
|
if (addr != 0)
|
|
return (unsigned long) -EINVAL;
|
|
|
|
if (len > mtd->size || pgoff >= (mtd->size >> PAGE_SHIFT))
|
|
return (unsigned long) -EINVAL;
|
|
|
|
offset += ROMFS_I(inode)->i_dataoffset;
|
|
if (offset > mtd->size - len)
|
|
return (unsigned long) -EINVAL;
|
|
|
|
return mtd->get_unmapped_area(mtd, len, offset, flags);
|
|
}
|
|
|
|
cant_map_directly:
|
|
return (unsigned long) -ENOSYS;
|
|
}
|
|
|
|
/*
|
|
* permit a R/O mapping to be made directly through onto an MTD device if
|
|
* possible
|
|
*/
|
|
static int romfs_mmap(struct file *file, struct vm_area_struct *vma)
|
|
{
|
|
return vma->vm_flags & (VM_SHARED | VM_MAYSHARE) ? 0 : -ENOSYS;
|
|
}
|
|
|
|
const struct file_operations romfs_ro_fops = {
|
|
.llseek = generic_file_llseek,
|
|
.read = do_sync_read,
|
|
.aio_read = generic_file_aio_read,
|
|
.splice_read = generic_file_splice_read,
|
|
.mmap = romfs_mmap,
|
|
.get_unmapped_area = romfs_get_unmapped_area,
|
|
};
|