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 if (x86 > 3 && vma->vm_offset >= high_memory)
91 vma->vm_page_prot |= PAGE_PCD;
92 if (remap_page_range(vma->vm_start, vma->vm_offset, vma->vm_end - vma->vm_start, vma->vm_page_prot))
93 return -EAGAIN;
94 vma->vm_inode = inode;
95 inode->i_count++;
96 return 0;
97 }
98
99 static int read_kmem(struct inode *inode, struct file *file, char *buf, int count)
100 {
101 int read1, read2;
102
103 read1 = read_mem(inode, file, buf, count);
104 if (read1 < 0)
105 return read1;
106 read2 = vread(buf + read1, (char *) ((unsigned long) file->f_pos), count - read1);
107 if (read2 < 0)
108 return read2;
109 file->f_pos += read2;
110 return read1 + read2;
111 }
112
113 static int read_port(struct inode * inode,struct file * file,char * buf, int count)
114 {
115 unsigned int i = file->f_pos;
116 char * tmp = buf;
117
118 while (count-- > 0 && i < 65536) {
119 put_fs_byte(inb(i),tmp);
120 i++;
121 tmp++;
122 }
123 file->f_pos = i;
124 return tmp-buf;
125 }
126
127 static int write_port(struct inode * inode,struct file * file,char * buf, int count)
128 {
129 unsigned int i = file->f_pos;
130 char * tmp = buf;
131
132 while (count-- > 0 && i < 65536) {
133 outb(get_fs_byte(tmp),i);
134 i++;
135 tmp++;
136 }
137 file->f_pos = i;
138 return tmp-buf;
139 }
140
141 static int read_null(struct inode * node,struct file * file,char * buf,int count)
142 {
143 return 0;
144 }
145
146 static int write_null(struct inode * inode,struct file * file,char * buf, int count)
147 {
148 return count;
149 }
150
151 static int read_zero(struct inode * node,struct file * file,char * buf,int count)
152 {
153 int left;
154
155 for (left = count; left > 0; left--) {
156 put_fs_byte(0,buf);
157 buf++;
158 }
159 return count;
160 }
161
162 static int mmap_zero(struct inode * inode, struct file * file, struct vm_area_struct * vma)
163 {
164 if (vma->vm_page_prot & PAGE_RW)
165 return -EINVAL;
166 if (zeromap_page_range(vma->vm_start, vma->vm_end - vma->vm_start, vma->vm_page_prot))
167 return -EAGAIN;
168 return 0;
169 }
170
171 static int read_full(struct inode * node,struct file * file,char * buf,int count)
172 {
173 return count;
174 }
175
176 static int write_full(struct inode * inode,struct file * file,char * buf, int count)
177 {
178 return -ENOSPC;
179 }
180
181
182
183
184
185
186 static int null_lseek(struct inode * inode, struct file * file, off_t offset, int orig)
187 {
188 return file->f_pos=0;
189 }
190
191
192
193
194
195
196
197
198 static int memory_lseek(struct inode * inode, struct file * file, off_t offset, int orig)
199 {
200 switch (orig) {
201 case 0:
202 file->f_pos = offset;
203 return file->f_pos;
204 case 1:
205 file->f_pos += offset;
206 return file->f_pos;
207 default:
208 return -EINVAL;
209 }
210 if (file->f_pos < 0)
211 return 0;
212 return file->f_pos;
213 }
214
215 #define write_kmem write_mem
216 #define mmap_kmem mmap_mem
217 #define zero_lseek null_lseek
218 #define write_zero write_null
219
220 static struct file_operations ram_fops = {
221 memory_lseek,
222 read_ram,
223 write_ram,
224 NULL,
225 NULL,
226 NULL,
227 NULL,
228 NULL,
229 NULL,
230 NULL
231 };
232
233 static struct file_operations mem_fops = {
234 memory_lseek,
235 read_mem,
236 write_mem,
237 NULL,
238 NULL,
239 NULL,
240 mmap_mem,
241 NULL,
242 NULL,
243 NULL
244 };
245
246 static struct file_operations kmem_fops = {
247 memory_lseek,
248 read_kmem,
249 write_kmem,
250 NULL,
251 NULL,
252 NULL,
253 mmap_kmem,
254 NULL,
255 NULL,
256 NULL
257 };
258
259 static struct file_operations null_fops = {
260 null_lseek,
261 read_null,
262 write_null,
263 NULL,
264 NULL,
265 NULL,
266 NULL,
267 NULL,
268 NULL,
269 NULL
270 };
271
272 static struct file_operations port_fops = {
273 memory_lseek,
274 read_port,
275 write_port,
276 NULL,
277 NULL,
278 NULL,
279 NULL,
280 NULL,
281 NULL,
282 NULL
283 };
284
285 static struct file_operations zero_fops = {
286 zero_lseek,
287 read_zero,
288 write_zero,
289 NULL,
290 NULL,
291 NULL,
292 mmap_zero,
293 NULL,
294 NULL
295 };
296
297 static struct file_operations full_fops = {
298 memory_lseek,
299 read_full,
300 write_full,
301 NULL,
302 NULL,
303 NULL,
304 NULL,
305 NULL,
306 NULL
307 };
308
309 static int memory_open(struct inode * inode, struct file * filp)
310 {
311 switch (MINOR(inode->i_rdev)) {
312 case 0:
313 filp->f_op = &ram_fops;
314 break;
315 case 1:
316 filp->f_op = &mem_fops;
317 break;
318 case 2:
319 filp->f_op = &kmem_fops;
320 break;
321 case 3:
322 filp->f_op = &null_fops;
323 break;
324 case 4:
325 filp->f_op = &port_fops;
326 break;
327 case 5:
328 filp->f_op = &zero_fops;
329 break;
330 case 7:
331 filp->f_op = &full_fops;
332 break;
333 default:
334 return -ENODEV;
335 }
336 if (filp->f_op && filp->f_op->open)
337 return filp->f_op->open(inode,filp);
338 return 0;
339 }
340
341 static struct file_operations memory_fops = {
342 NULL,
343 NULL,
344 NULL,
345 NULL,
346 NULL,
347 NULL,
348 NULL,
349 memory_open,
350 NULL,
351 NULL
352 };
353
354 #ifdef CONFIG_FTAPE
355 char* ftape_big_buffer;
356 #endif
357
358 long chr_dev_init(long mem_start, long mem_end)
359 {
360 if (register_chrdev(MEM_MAJOR,"mem",&memory_fops))
361 printk("unable to get major %d for memory devs\n", MEM_MAJOR);
362 mem_start = tty_init(mem_start);
363 #ifdef CONFIG_PRINTER
364 mem_start = lp_init(mem_start);
365 #endif
366 #if defined (CONFIG_BUSMOUSE) || defined (CONFIG_82C710_MOUSE) || \
367 defined (CONFIG_PSMOUSE) || defined (CONFIG_MS_BUSMOUSE) || \
368 defined (CONFIG_ATIXL_BUSMOUSE)
369 mem_start = mouse_init(mem_start);
370 #endif
371 #ifdef CONFIG_SOUND
372 mem_start = soundcard_init(mem_start);
373 #endif
374 #if CONFIG_QIC02_TAPE
375 mem_start = qic02_tape_init(mem_start);
376 #endif
377
378
379
380 #ifdef CONFIG_FTAPE
381
382 ftape_big_buffer= (char*) ((mem_start + 0x7fff) & ~0x7fff);
383 printk( "ftape: allocated %d buffers aligned at: %p\n",
384 NR_FTAPE_BUFFERS, ftape_big_buffer);
385 mem_start = (long) ftape_big_buffer + NR_FTAPE_BUFFERS * 0x8000;
386 #endif
387 return mem_start;
388 }