[ARM] 4780/1: S3C2412: Allow for seperate DMA channels for TX and RX
[linux-2.6/openmoko-kernel/knife-kernel.git] / mm / tiny-shmem.c
blobd436a9c82db7739618dee05886c0088aaea7728a
1 /*
2 * tiny-shmem.c: simple shmemfs and tmpfs using ramfs code
4 * Matt Mackall <mpm@selenic.com> January, 2004
5 * derived from mm/shmem.c and fs/ramfs/inode.c
7 * This is intended for small system where the benefits of the full
8 * shmem code (swap-backed and resource-limited) are outweighed by
9 * their complexity. On systems without swap this code should be
10 * effectively equivalent, but much lighter weight.
13 #include <linux/fs.h>
14 #include <linux/init.h>
15 #include <linux/vfs.h>
16 #include <linux/mount.h>
17 #include <linux/file.h>
18 #include <linux/mm.h>
19 #include <linux/module.h>
20 #include <linux/swap.h>
21 #include <linux/ramfs.h>
23 static struct file_system_type tmpfs_fs_type = {
24 .name = "tmpfs",
25 .get_sb = ramfs_get_sb,
26 .kill_sb = kill_litter_super,
29 static struct vfsmount *shm_mnt;
31 static int __init init_tmpfs(void)
33 BUG_ON(register_filesystem(&tmpfs_fs_type) != 0);
35 shm_mnt = kern_mount(&tmpfs_fs_type);
36 BUG_ON(IS_ERR(shm_mnt));
38 return 0;
40 module_init(init_tmpfs)
43 * shmem_file_setup - get an unlinked file living in tmpfs
45 * @name: name for dentry (to be seen in /proc/<pid>/maps
46 * @size: size to be set for the file
49 struct file *shmem_file_setup(char *name, loff_t size, unsigned long flags)
51 int error;
52 struct file *file;
53 struct inode *inode;
54 struct dentry *dentry, *root;
55 struct qstr this;
57 if (IS_ERR(shm_mnt))
58 return (void *)shm_mnt;
60 error = -ENOMEM;
61 this.name = name;
62 this.len = strlen(name);
63 this.hash = 0; /* will go */
64 root = shm_mnt->mnt_root;
65 dentry = d_alloc(root, &this);
66 if (!dentry)
67 goto put_memory;
69 error = -ENOSPC;
70 inode = ramfs_get_inode(root->d_sb, S_IFREG | S_IRWXUGO, 0);
71 if (!inode)
72 goto put_dentry;
74 d_instantiate(dentry, inode);
75 error = -ENFILE;
76 file = alloc_file(shm_mnt, dentry, FMODE_WRITE | FMODE_READ,
77 &ramfs_file_operations);
78 if (!file)
79 goto put_dentry;
81 inode->i_nlink = 0; /* It is unlinked */
83 /* notify everyone as to the change of file size */
84 error = do_truncate(dentry, size, 0, file);
85 if (error < 0)
86 goto close_file;
88 return file;
90 close_file:
91 put_filp(file);
92 put_dentry:
93 dput(dentry);
94 put_memory:
95 return ERR_PTR(error);
99 * shmem_zero_setup - setup a shared anonymous mapping
101 * @vma: the vma to be mmapped is prepared by do_mmap_pgoff
103 int shmem_zero_setup(struct vm_area_struct *vma)
105 struct file *file;
106 loff_t size = vma->vm_end - vma->vm_start;
108 file = shmem_file_setup("dev/zero", size, vma->vm_flags);
109 if (IS_ERR(file))
110 return PTR_ERR(file);
112 if (vma->vm_file)
113 fput(vma->vm_file);
114 vma->vm_file = file;
115 vma->vm_ops = &generic_file_vm_ops;
116 return 0;
119 int shmem_unuse(swp_entry_t entry, struct page *page)
121 return 0;
124 #if 0
125 int shmem_mmap(struct file *file, struct vm_area_struct *vma)
127 file_accessed(file);
128 #ifndef CONFIG_MMU
129 return ramfs_nommu_mmap(file, vma);
130 #else
131 return 0;
132 #endif
134 #endif /* 0 */
136 #ifndef CONFIG_MMU
137 unsigned long shmem_get_unmapped_area(struct file *file,
138 unsigned long addr,
139 unsigned long len,
140 unsigned long pgoff,
141 unsigned long flags)
143 return ramfs_nommu_get_unmapped_area(file, addr, len, pgoff, flags);
145 #endif