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