This source file includes following definitions.
- read_ram
- write_ram
- read_mem
- write_mem
- mmap_mem
- read_kmem
- read_port
- write_port
- read_null
- write_null
- read_zero
- mmap_zero
- read_full
- write_full
- null_lseek
- memory_lseek
- memory_open
- chr_dev_init
1
2
3
4
5
6
7 #include <linux/config.h>
8 #include <linux/types.h>
9 #include <linux/errno.h>
10 #include <linux/sched.h>
11 #include <linux/kernel.h>
12 #include <linux/major.h>
13 #include <linux/tty.h>
14 #include <linux/mouse.h>
15 #include <linux/tpqic02.h>
16 #include <linux/malloc.h>
17 #include <linux/mman.h>
18
19 #include <asm/segment.h>
20 #include <asm/io.h>
21
22 #ifdef CONFIG_SOUND
23 extern long soundcard_init(long mem_start);
24 #endif
25
26 static int read_ram(struct inode * inode, struct file * file,char * buf, int count)
27 {
28 return -EIO;
29 }
30
31 static int write_ram(struct inode * inode, struct file * file,char * buf, int count)
32 {
33 return -EIO;
34 }
35
36 static int read_mem(struct inode * inode, struct file * file,char * buf, int count)
37 {
38 unsigned long p = file->f_pos;
39 int read;
40
41 if (count < 0)
42 return -EINVAL;
43 if (p >= high_memory)
44 return 0;
45 if (count > high_memory - p)
46 count = high_memory - p;
47 read = 0;
48 while (p < PAGE_SIZE && count > 0) {
49 put_fs_byte(0,buf);
50 buf++;
51 p++;
52 count--;
53 read++;
54 }
55 memcpy_tofs(buf,(void *) p,count);
56 read += count;
57 file->f_pos += read;
58 return read;
59 }
60
61 static int write_mem(struct inode * inode, struct file * file,char * buf, int count)
62 {
63 unsigned long p = file->f_pos;
64 int written;
65
66 if (count < 0)
67 return -EINVAL;
68 if (p >= high_memory)
69 return 0;
70 if (count > high_memory - p)
71 count = high_memory - p;
72 written = 0;
73 while (p < PAGE_SIZE && count > 0) {
74
75 buf++;
76 p++;
77 count--;
78 written++;
79 }
80 memcpy_fromfs((void *) p,buf,count);
81 written += count;
82 file->f_pos += written;
83 return count;
84 }
85
86 static int mmap_mem(struct inode * inode, struct file * file, struct vm_area_struct * vma)
87 {
88 if (vma->vm_offset & ~PAGE_MASK)
89 return -ENXIO;
90 #ifdef __i386__
91 if (x86 > 3 && vma->vm_offset >= high_memory)
92 vma->vm_page_prot |= PAGE_PCD;
93 #endif
94 if (remap_page_range(vma->vm_start, vma->vm_offset, vma->vm_end - vma->vm_start, vma->vm_page_prot))
95 return -EAGAIN;
96 vma->vm_inode = inode;
97 inode->i_count++;
98 return 0;
99 }
100
101 static int read_kmem(struct inode *inode, struct file *file, char *buf, int count)
102 {
103 int read1, read2;
104
105 read1 = read_mem(inode, file, buf, count);
106 if (read1 < 0)
107 return read1;
108 read2 = vread(buf + read1, (char *) ((unsigned long) file->f_pos), count - read1);
109 if (read2 < 0)
110 return read2;
111 file->f_pos += read2;
112 return read1 + read2;
113 }
114
115 static int read_port(struct inode * inode,struct file * file,char * buf, int count)
116 {
117 unsigned int i = file->f_pos;
118 char * tmp = buf;
119
120 while (count-- > 0 && i < 65536) {
121 put_fs_byte(inb(i),tmp);
122 i++;
123 tmp++;
124 }
125 file->f_pos = i;
126 return tmp-buf;
127 }
128
129 static int write_port(struct inode * inode,struct file * file,char * buf, int count)
130 {
131 unsigned int i = file->f_pos;
132 char * tmp = buf;
133
134 while (count-- > 0 && i < 65536) {
135 outb(get_fs_byte(tmp),i);
136 i++;
137 tmp++;
138 }
139 file->f_pos = i;
140 return tmp-buf;
141 }
142
143 static int read_null(struct inode * node,struct file * file,char * buf,int count)
144 {
145 return 0;
146 }
147
148 static int write_null(struct inode * inode,struct file * file,char * buf, int count)
149 {
150 return count;
151 }
152
153 static int read_zero(struct inode * node,struct file * file,char * buf,int count)
154 {
155 int left;
156
157 for (left = count; left > 0; left--) {
158 put_fs_byte(0,buf);
159 buf++;
160 }
161 return count;
162 }
163
164 static int mmap_zero(struct inode * inode, struct file * file, struct vm_area_struct * vma)
165 {
166 if (vma->vm_page_prot & PAGE_RW)
167 return -EINVAL;
168 if (zeromap_page_range(vma->vm_start, vma->vm_end - vma->vm_start, vma->vm_page_prot))
169 return -EAGAIN;
170 return 0;
171 }
172
173 static int read_full(struct inode * node,struct file * file,char * buf,int count)
174 {
175 return count;
176 }
177
178 static int write_full(struct inode * inode,struct file * file,char * buf, int count)
179 {
180 return -ENOSPC;
181 }
182
183
184
185
186
187
188 static int null_lseek(struct inode * inode, struct file * file, off_t offset, int orig)
189 {
190 return file->f_pos=0;
191 }
192
193
194
195
196
197
198
199
200 static int memory_lseek(struct inode * inode, struct file * file, off_t offset, int orig)
201 {
202 switch (orig) {
203 case 0:
204 file->f_pos = offset;
205 return file->f_pos;
206 case 1:
207 file->f_pos += offset;
208 return file->f_pos;
209 default:
210 return -EINVAL;
211 }
212 if (file->f_pos < 0)
213 return 0;
214 return file->f_pos;
215 }
216
217 #define write_kmem write_mem
218 #define mmap_kmem mmap_mem
219 #define zero_lseek null_lseek
220 #define write_zero write_null
221
222 static struct file_operations ram_fops = {
223 memory_lseek,
224 read_ram,
225 write_ram,
226 NULL,
227 NULL,
228 NULL,
229 NULL,
230 NULL,
231 NULL,
232 NULL
233 };
234
235 static struct file_operations mem_fops = {
236 memory_lseek,
237 read_mem,
238 write_mem,
239 NULL,
240 NULL,
241 NULL,
242 mmap_mem,
243 NULL,
244 NULL,
245 NULL
246 };
247
248 static struct file_operations kmem_fops = {
249 memory_lseek,
250 read_kmem,
251 write_kmem,
252 NULL,
253 NULL,
254 NULL,
255 mmap_kmem,
256 NULL,
257 NULL,
258 NULL
259 };
260
261 static struct file_operations null_fops = {
262 null_lseek,
263 read_null,
264 write_null,
265 NULL,
266 NULL,
267 NULL,
268 NULL,
269 NULL,
270 NULL,
271 NULL
272 };
273
274 static struct file_operations port_fops = {
275 memory_lseek,
276 read_port,
277 write_port,
278 NULL,
279 NULL,
280 NULL,
281 NULL,
282 NULL,
283 NULL,
284 NULL
285 };
286
287 static struct file_operations zero_fops = {
288 zero_lseek,
289 read_zero,
290 write_zero,
291 NULL,
292 NULL,
293 NULL,
294 mmap_zero,
295 NULL,
296 NULL
297 };
298
299 static struct file_operations full_fops = {
300 memory_lseek,
301 read_full,
302 write_full,
303 NULL,
304 NULL,
305 NULL,
306 NULL,
307 NULL,
308 NULL
309 };
310
311 static int memory_open(struct inode * inode, struct file * filp)
312 {
313 switch (MINOR(inode->i_rdev)) {
314 case 0:
315 filp->f_op = &ram_fops;
316 break;
317 case 1:
318 filp->f_op = &mem_fops;
319 break;
320 case 2:
321 filp->f_op = &kmem_fops;
322 break;
323 case 3:
324 filp->f_op = &null_fops;
325 break;
326 case 4:
327 filp->f_op = &port_fops;
328 break;
329 case 5:
330 filp->f_op = &zero_fops;
331 break;
332 case 7:
333 filp->f_op = &full_fops;
334 break;
335 default:
336 return -ENODEV;
337 }
338 if (filp->f_op && filp->f_op->open)
339 return filp->f_op->open(inode,filp);
340 return 0;
341 }
342
343 static struct file_operations memory_fops = {
344 NULL,
345 NULL,
346 NULL,
347 NULL,
348 NULL,
349 NULL,
350 NULL,
351 memory_open,
352 NULL,
353 NULL
354 };
355
356 #ifdef CONFIG_FTAPE
357 char* ftape_big_buffer;
358 #endif
359
360 long chr_dev_init(long mem_start, long mem_end)
361 {
362 if (register_chrdev(MEM_MAJOR,"mem",&memory_fops))
363 printk("unable to get major %d for memory devs\n", MEM_MAJOR);
364 mem_start = tty_init(mem_start);
365 #ifdef CONFIG_PRINTER
366 mem_start = lp_init(mem_start);
367 #endif
368 #if defined (CONFIG_BUSMOUSE) || defined (CONFIG_82C710_MOUSE) || \
369 defined (CONFIG_PSMOUSE) || defined (CONFIG_MS_BUSMOUSE) || \
370 defined (CONFIG_ATIXL_BUSMOUSE)
371 mem_start = mouse_init(mem_start);
372 #endif
373 #ifdef CONFIG_SOUND
374 mem_start = soundcard_init(mem_start);
375 #endif
376 #if CONFIG_QIC02_TAPE
377 mem_start = qic02_tape_init(mem_start);
378 #endif
379
380
381
382 #ifdef CONFIG_FTAPE
383
384 ftape_big_buffer= (char*) ((mem_start + 0x7fff) & ~0x7fff);
385 printk( "ftape: allocated %d buffers aligned at: %p\n",
386 NR_FTAPE_BUFFERS, ftape_big_buffer);
387 mem_start = (long) ftape_big_buffer + NR_FTAPE_BUFFERS * 0x8000;
388 #endif
389 return mem_start;
390 }