]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/memdev.c
789249397c7a2ae3c049044e0eb644364449be87
[apple/xnu.git] / bsd / dev / memdev.c
1 /*
2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /*
24 * Copyright (c) 1988 University of Utah.
25 * Copyright (c) 1990, 1993
26 * The Regents of the University of California. All rights reserved.
27 *
28 * This code is derived from software contributed to Berkeley by
29 * the Systems Programming Group of the University of Utah Computer
30 * Science Department.
31 *
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
34 * are met:
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. All advertising materials mentioning features or use of this software
41 * must display the following acknowledgement:
42 * This product includes software developed by the University of
43 * California, Berkeley and its contributors.
44 * 4. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE.
59 *
60 * from: Utah Hdr: vn.c 1.13 94/04/02
61 *
62 * from: @(#)vn.c 8.6 (Berkeley) 4/1/94
63 * $FreeBSD: src/sys/dev/vn/vn.c,v 1.105.2.4 2001/11/18 07:11:00 dillon Exp $
64 */
65
66 /*
67 * RAM disk driver.
68 *
69 * Block interface to a ramdisk.
70 *
71 */
72
73 #include <sys/param.h>
74 #include <sys/kernel.h>
75 #include <sys/mount.h>
76 #include <sys/namei.h>
77 #include <sys/proc.h>
78 #include <sys/buf.h>
79 #include <sys/malloc.h>
80 #include <sys/mount.h>
81 #include <sys/fcntl.h>
82 #include <sys/conf.h>
83 #include <sys/disk.h>
84 #include <sys/stat.h>
85 #include <sys/vm.h>
86 #include <sys/uio_internal.h>
87 #include <libkern/libkern.h>
88
89 #include <vm/pmap.h>
90 #include <vm/vm_pager.h>
91 #include <mach/memory_object_types.h>
92
93 #include <miscfs/devfs/devfs.h>
94
95
96 void mdevinit(int the_cnt);
97
98 static open_close_fcn_t mdevopen;
99 static open_close_fcn_t mdevclose;
100 static psize_fcn_t mdevsize;
101 static strategy_fcn_t mdevstrategy;
102 static int mdevbioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p);
103 static int mdevcioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p);
104 static int mdevrw(dev_t dev, struct uio *uio, int ioflag);
105 static char * nonspace(char *pos, char *end);
106 static char * getspace(char *pos, char *end);
107 static char * cvtnum(char *pos, char *end, unsigned int *num);
108
109 extern void bcopy_phys(addr64_t from, addr64_t to, vm_size_t bytes);
110 extern void mapping_set_mod(ppnum_t pn);
111 extern ppnum_t pmap_find_phys(pmap_t pmap, addr64_t va);
112
113
114 /*
115 * cdevsw
116 * D_DISK we want to look like a disk
117 * D_CANFREE We support B_FREEBUF
118 */
119
120 static struct bdevsw mdevbdevsw = {
121 /* open */ mdevopen,
122 /* close */ mdevclose,
123 /* strategy */ mdevstrategy,
124 /* ioctl */ mdevbioctl,
125 /* dump */ eno_dump,
126 /* psize */ mdevsize,
127 /* flags */ D_DISK,
128 };
129
130 static struct cdevsw mdevcdevsw = {
131 /* open */ mdevopen,
132 /* close */ mdevclose,
133 /* read */ mdevrw,
134 /* write */ mdevrw,
135 /* ioctl */ mdevcioctl,
136 /* stop */ eno_stop,
137 /* reset */ eno_reset,
138 /* ttys */ 0,
139 /* select */ eno_select,
140 /* mmap */ eno_mmap,
141 /* strategy */ eno_strat,
142 /* getc */ eno_getc,
143 /* putc */ eno_putc,
144 /* flags */ D_DISK,
145 };
146
147 struct mdev {
148 vm_offset_t mdBase; /* file size in bytes */
149 uint32_t mdSize; /* file size in bytes */
150 int mdFlags; /* flags */
151 int mdSecsize; /* sector size */
152 int mdBDev; /* Block device number */
153 int mdCDev; /* Character device number */
154 void * mdbdevb;
155 void * mdcdevb;
156 } mdev[16];
157
158 /* mdFlags */
159 #define mdInited 0x01 /* This device defined */
160 #define mdRO 0x02 /* This device is read-only */
161 #define mdPhys 0x04 /* This device is in physical memory */
162
163 int mdevBMajor = -1;
164 int mdevCMajor = -1;
165
166 static int mdevioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p, int is_char);
167 dev_t mdevadd(int devid, ppnum_t base, unsigned int size, int phys);
168 dev_t mdevlookup(int devid);
169
170 static int mdevclose(__unused dev_t dev, __unused int flags,
171 __unused int devtype, __unused struct proc *p) {
172
173 return (0);
174 }
175
176 static int mdevopen(dev_t dev, int flags, __unused int devtype, __unused struct proc *p) {
177
178 int devid;
179
180 devid = minor(dev); /* Get minor device number */
181
182 if (devid > 16) return (ENXIO); /* Not valid */
183
184 if ((flags & FWRITE) && (mdev[devid].mdFlags & mdRO)) return (EACCES); /* Currently mounted RO */
185
186 return(0);
187 }
188
189 static int mdevrw(dev_t dev, struct uio *uio, __unused int ioflag) {
190 int status;
191 addr64_t mdata;
192 int devid;
193 enum uio_seg saveflag;
194
195 devid = minor(dev); /* Get minor device number */
196
197 if (devid > 16) return (ENXIO); /* Not valid */
198 if (!(mdev[devid].mdFlags & mdInited)) return (ENXIO); /* Have we actually been defined yet? */
199
200 mdata = ((addr64_t)mdev[devid].mdBase << 12) + uio->uio_offset; /* Point to the area in "file" */
201
202 saveflag = uio->uio_segflg; /* Remember what the request is */
203 #if LP64_DEBUG
204 if (IS_VALID_UIO_SEGFLG(uio->uio_segflg) == 0) {
205 panic("mdevrw - invalid uio_segflg\n");
206 }
207 #endif /* LP64_DEBUG */
208 /* Make sure we are moving from physical ram if physical device */
209 if (mdev[devid].mdFlags & mdPhys) {
210 if (uio->uio_segflg == UIO_USERSPACE64)
211 uio->uio_segflg = UIO_PHYS_USERSPACE64;
212 else if (uio->uio_segflg == UIO_USERSPACE32)
213 uio->uio_segflg = UIO_PHYS_USERSPACE32;
214 else
215 uio->uio_segflg = UIO_PHYS_USERSPACE;
216 }
217 status = uiomove64(mdata, uio_resid(uio), uio); /* Move the data */
218 uio->uio_segflg = saveflag; /* Restore the flag */
219
220 return (status);
221 }
222
223 static void mdevstrategy(struct buf *bp) {
224 unsigned int left, lop, csize;
225 vm_offset_t vaddr, blkoff;
226 int devid;
227 addr64_t paddr, fvaddr;
228 ppnum_t pp;
229
230 devid = minor(buf_device(bp)); /* Get minor device number */
231
232 if ((mdev[devid].mdFlags & mdInited) == 0) { /* Have we actually been defined yet? */
233 buf_seterror(bp, ENXIO);
234 buf_biodone(bp);
235 return;
236 }
237
238 buf_setresid(bp, buf_count(bp)); /* Set byte count */
239
240 blkoff = buf_blkno(bp) * mdev[devid].mdSecsize; /* Get offset into file */
241
242 /*
243 * Note that reading past end is an error, but reading at end is an EOF. For these
244 * we just return with resid == count.
245 */
246
247 if (blkoff >= (mdev[devid].mdSize << 12)) { /* Are they trying to read/write at/after end? */
248 if(blkoff != (mdev[devid].mdSize << 12)) { /* Are we trying to read after EOF? */
249 buf_seterror(bp, EINVAL); /* Yeah, this is an error */
250 }
251 buf_biodone(bp); /* Return */
252 return;
253 }
254
255 if ((blkoff + buf_count(bp)) > (mdev[devid].mdSize << 12)) { /* Will this read go past end? */
256 buf_setcount(bp, ((mdev[devid].mdSize << 12) - blkoff)); /* Yes, trim to max */
257 }
258 /*
259 * make sure the buffer's data area is
260 * accessible
261 */
262 if (buf_map(bp, (caddr_t *)&vaddr))
263 panic("ramstrategy: buf_map failed\n");
264
265 fvaddr = (mdev[devid].mdBase << 12) + blkoff; /* Point to offset into ram disk */
266
267 if (buf_flags(bp) & B_READ) { /* Is this a read? */
268 if(!(mdev[devid].mdFlags & mdPhys)) { /* Physical mapped disk? */
269 bcopy((void *)((uintptr_t)fvaddr),
270 (void *)vaddr, (size_t)buf_count(bp)); /* This is virtual, just get the data */
271 }
272 else {
273 left = buf_count(bp); /* Init the amount left to copy */
274 while(left) { /* Go until it is all copied */
275
276 lop = min((4096 - (vaddr & 4095)), (4096 - (fvaddr & 4095))); /* Get smallest amount left on sink and source */
277 csize = min(lop, left); /* Don't move more than we need to */
278
279 pp = pmap_find_phys(kernel_pmap, (addr64_t)((unsigned int)vaddr)); /* Get the sink physical address */
280 if(!pp) { /* Not found, what gives? */
281 panic("mdevstrategy: sink address %016llX not mapped\n", (addr64_t)((unsigned int)vaddr));
282 }
283 paddr = (addr64_t)(((addr64_t)pp << 12) | (addr64_t)(vaddr & 4095)); /* Get actual address */
284 bcopy_phys(fvaddr, paddr, csize); /* Copy this on in */
285 mapping_set_mod(paddr >> 12); /* Make sure we know that it is modified */
286
287 left = left - csize; /* Calculate what is left */
288 vaddr = vaddr + csize; /* Move to next sink address */
289 fvaddr = fvaddr + csize; /* Bump to next physical address */
290 }
291 }
292 }
293 else { /* This is a write */
294 if(!(mdev[devid].mdFlags & mdPhys)) { /* Physical mapped disk? */
295 bcopy((void *)vaddr, (void *)((uintptr_t)fvaddr),
296 (size_t)buf_count(bp)); /* This is virtual, just put the data */
297 }
298 else {
299 left = buf_count(bp); /* Init the amount left to copy */
300 while(left) { /* Go until it is all copied */
301
302 lop = min((4096 - (vaddr & 4095)), (4096 - (fvaddr & 4095))); /* Get smallest amount left on sink and source */
303 csize = min(lop, left); /* Don't move more than we need to */
304
305 pp = pmap_find_phys(kernel_pmap, (addr64_t)((unsigned int)vaddr)); /* Get the source physical address */
306 if(!pp) { /* Not found, what gives? */
307 panic("mdevstrategy: source address %016llX not mapped\n", (addr64_t)((unsigned int)vaddr));
308 }
309 paddr = (addr64_t)(((addr64_t)pp << 12) | (addr64_t)(vaddr & 4095)); /* Get actual address */
310
311 bcopy_phys(paddr, fvaddr, csize); /* Move this on out */
312
313 left = left - csize; /* Calculate what is left */
314 vaddr = vaddr + csize; /* Move to next sink address */
315 fvaddr = fvaddr + csize; /* Bump to next physical address */
316 }
317 }
318 }
319 /*
320 * buf_unmap takes care of all the cases
321 * it will unmap the buffer from kernel
322 * virtual space if that was the state
323 * when we mapped it.
324 */
325 buf_unmap(bp);
326
327 buf_setresid(bp, 0); /* Nothing more to do */
328 buf_biodone(bp); /* Say we've finished */
329 }
330
331 static int mdevbioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) {
332 return (mdevioctl(dev, cmd, data, flag, p, 0));
333 }
334
335 static int mdevcioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) {
336 return (mdevioctl(dev, cmd, data, flag, p, 1));
337 }
338
339 static int mdevioctl(dev_t dev, u_long cmd, caddr_t data, __unused int flag,
340 struct proc *p, int is_char) {
341 int error;
342 u_long *f;
343 u_int64_t *o;
344 int devid;
345
346 devid = minor(dev); /* Get minor device number */
347
348 if (devid > 16) return (ENXIO); /* Not valid */
349
350 error = proc_suser(p); /* Are we superman? */
351 if (error) return (error); /* Nope... */
352
353 f = (u_long*)data;
354 o = (u_int64_t *)data;
355
356 switch (cmd) {
357
358 case DKIOCGETMAXBLOCKCOUNTREAD:
359 *o = 32;
360 break;
361
362 case DKIOCGETMAXBLOCKCOUNTWRITE:
363 *o = 32;
364 break;
365
366 case DKIOCGETMAXSEGMENTCOUNTREAD:
367 *o = 32;
368 break;
369
370 case DKIOCGETMAXSEGMENTCOUNTWRITE:
371 *o = 32;
372 break;
373
374 case DKIOCGETBLOCKSIZE:
375 *f = mdev[devid].mdSecsize;
376 break;
377
378 case DKIOCSETBLOCKSIZE:
379 if (is_char) return (ENODEV); /* We can only do this for a block */
380
381 if (*f < DEV_BSIZE) return (EINVAL); /* Too short? */
382
383 mdev[devid].mdSecsize = *f; /* set the new block size */
384 break;
385
386 case DKIOCISWRITABLE:
387 *f = 1;
388 break;
389
390 case DKIOCGETBLOCKCOUNT32:
391 if(!(mdev[devid].mdFlags & mdInited)) return (ENXIO);
392 *f = ((mdev[devid].mdSize << 12) + mdev[devid].mdSecsize - 1) / mdev[devid].mdSecsize;
393 break;
394
395 case DKIOCGETBLOCKCOUNT:
396 if(!(mdev[devid].mdFlags & mdInited)) return (ENXIO);
397 *o = ((mdev[devid].mdSize << 12) + mdev[devid].mdSecsize - 1) / mdev[devid].mdSecsize;
398 break;
399
400 default:
401 error = ENOTTY;
402 break;
403 }
404 return(error);
405 }
406
407
408 static int mdevsize(dev_t dev) {
409
410 int devid;
411
412 devid = minor(dev); /* Get minor device number */
413 if (devid > 16) return (ENXIO); /* Not valid */
414
415 if ((mdev[devid].mdFlags & mdInited) == 0) return(-1); /* Not inited yet */
416
417 return(mdev[devid].mdSecsize);
418 }
419
420 #include <pexpert/pexpert.h>
421
422 void mdevinit(__unused int the_cnt) {
423
424 int devid, phys;
425 ppnum_t base;
426 unsigned int size;
427 char *ba, *lp;
428 dev_t dev;
429
430
431 ba = PE_boot_args(); /* Get the boot arguments */
432 lp = ba + 256; /* Point to the end */
433
434 while(1) { /* Step through, looking for our keywords */
435 phys = 0; /* Assume virtual memory device */
436 ba = nonspace(ba, lp); /* Find non-space */
437 if(ba >= lp) return; /* We are done if no more... */
438 if(((ba[0] != 'v') && (ba[0] != 'p'))
439 || (ba[1] != 'm') || (ba[2] != 'd') || (ba[4] != '=')
440 || (ba[3] < '0') || (ba[3] > 'f')
441 || ((ba[3] > '9') && (ba[3] < 'a'))) { /* Is this of form "vmdx=" or "pmdx=" where x is hex digit? */
442
443 ba = getspace(ba, lp); /* Find next white space or end */
444 continue; /* Start looking for the next one */
445 }
446
447 if(ba[0] == 'p') phys = 1; /* Set physical memory disk */
448
449 devid = ba[3] & 0xF; /* Assume digit */
450 if(ba[3] > '9') devid += 9; /* Adjust for hex digits */
451
452 ba = &ba[5]; /* Step past keyword */
453 ba = cvtnum(ba, lp, &base); /* Convert base of memory disk */
454 if(ba >= lp) return; /* Malformed one at the end, leave */
455 if(ba[0] != '.') continue; /* If not length separater, try next... */
456 if(base & 0xFFF) continue; /* Only allow page aligned stuff */
457
458 ba++; /* Step past '.' */
459 ba = cvtnum(ba, lp, &size); /* Try to convert it */
460 if(!size || (size & 0xFFF)) continue; /* Allow only non-zer page size multiples */
461 if(ba < lp) { /* If we are not at end, check end character */
462 if((ba[0] != ' ') && (ba[0] != 0)) continue; /* End must be null or space */
463 }
464
465 dev = mdevadd(devid, base >> 12, size >> 12, phys); /* Go add the device */
466 }
467
468 return;
469
470 }
471
472 char *nonspace(char *pos, char *end) { /* Find next non-space in string */
473
474 if(pos >= end) return end; /* Don't go past end */
475 if(pos[0] == 0) return end; /* If at null, make end */
476
477 while(1) { /* Keep going */
478 if(pos[0] != ' ') return pos; /* Leave if we found one */
479 pos++; /* Stop */
480 if(pos >= end) return end; /* Quit if we run off end */
481 }
482 }
483
484 char *getspace(char *pos, char *end) { /* Find next non-space in string */
485
486 while(1) { /* Keep going */
487 if(pos >= end) return end; /* Don't go past end */
488 if(pos[0] == 0) return end; /* Leave if we hit null */
489 if(pos[0] == ' ') return pos; /* Leave if we found one */
490 pos++; /* Stop */
491 }
492 }
493
494 char *cvtnum(char *pos, char *end, unsigned int *num) { /* Convert to a number */
495
496 int rad, dig;
497
498 *num = 0; /* Set answer to 0 to start */
499 rad = 10;
500
501 if(pos >= end) return end; /* Don't go past end */
502 if(pos[0] == 0) return end; /* If at null, make end */
503
504 if(pos[0] == '0' && ((pos[1] == 'x') || (pos[1] == 'x'))) { /* A hex constant? */
505 rad = 16;
506 pos += 2; /* Point to the number */
507 }
508
509 while(1) { /* Convert it */
510
511 if(pos >= end) return end; /* Don't go past end */
512 if(pos[0] == 0) return end; /* If at null, make end */
513 if(pos[0] < '0') return pos; /* Leave if non-digit */
514 dig = pos[0] & 0xF; /* Extract digit */
515 if(pos[0] > '9') { /* Is it bigger than 9? */
516 if(rad == 10) return pos; /* Leave if not base 10 */
517 if(!(((pos[0] >= 'A') && (pos[0] <= 'F'))
518 || ((pos[0] >= 'a') && (pos[0] <= 'f')))) return pos; /* Leave if bogus char */
519 dig = dig + 9; /* Adjust for character */
520 }
521 *num = (*num * rad) + dig; /* Accumulate the number */
522 pos++; /* Step on */
523 }
524 }
525
526 dev_t mdevadd(int devid, ppnum_t base, unsigned int size, int phys) {
527
528 int i;
529
530 if(devid < 0) {
531
532 devid = -1;
533 for(i = 0; i < 16; i++) { /* Search all known memory devices */
534 if(!(mdev[i].mdFlags & mdInited)) { /* Is this a free one? */
535 if(devid < 0)devid = i; /* Remember first free one */
536 continue; /* Skip check */
537 }
538 if(!(((base + size -1 ) < mdev[i].mdBase) || ((mdev[i].mdBase + mdev[i].mdSize - 1) < base))) { /* Is there any overlap? */
539 panic("mdevadd: attempt to add overlapping memory device at %08X-%08X\n", mdev[i].mdBase, mdev[i].mdBase + mdev[i].mdSize - 1);
540 }
541 }
542 if(devid < 0) { /* Do we have free slots? */
543 panic("mdevadd: attempt to add more than 16 memory devices\n");
544 }
545 }
546 else {
547 if(devid >= 16) { /* Giving us something bogus? */
548 panic("mdevadd: attempt to explicitly add a bogus memory device: &08X\n", devid);
549 }
550 if(mdev[devid].mdFlags &mdInited) { /* Already there? */
551 panic("mdevadd: attempt to explicitly add a previously defined memory device: &08X\n", devid);
552 }
553 }
554
555 if(mdevBMajor < 0) { /* Have we gotten a major number yet? */
556 mdevBMajor = bdevsw_add(-1, &mdevbdevsw); /* Add to the table and figure out a major number */
557 if (mdevBMajor < 0) {
558 printf("mdevadd: error - bdevsw_add() returned %d\n", mdevBMajor);
559 return -1;
560 }
561 }
562
563 if(mdevCMajor < 0) { /* Have we gotten a major number yet? */
564 mdevCMajor = cdevsw_add_with_bdev(-1, &mdevcdevsw, mdevBMajor); /* Add to the table and figure out a major number */
565 if (mdevCMajor < 0) {
566 printf("ramdevice_init: error - cdevsw_add() returned %d\n", mdevCMajor);
567 return -1;
568 }
569 }
570
571 mdev[devid].mdBDev = makedev(mdevBMajor, devid); /* Get the device number */
572 mdev[devid].mdbdevb = devfs_make_node(mdev[devid].mdBDev, DEVFS_BLOCK, /* Make the node */
573 UID_ROOT, GID_OPERATOR,
574 0600, "md%d", devid);
575 if (mdev[devid].mdbdevb == NULL) { /* Did we make one? */
576 printf("mdevadd: devfs_make_node for block failed!\n");
577 return -1; /* Nope... */
578 }
579
580 mdev[devid].mdCDev = makedev(mdevCMajor, devid); /* Get the device number */
581 mdev[devid].mdcdevb = devfs_make_node(mdev[devid].mdCDev, DEVFS_CHAR, /* Make the node */
582 UID_ROOT, GID_OPERATOR,
583 0600, "rmd%d", devid);
584 if (mdev[devid].mdcdevb == NULL) { /* Did we make one? */
585 printf("mdevadd: devfs_make_node for character failed!\n");
586 return -1; /* Nope... */
587 }
588
589 mdev[devid].mdBase = base; /* Set the base address of ram disk */
590 mdev[devid].mdSize = size; /* Set the length of the ram disk */
591 mdev[devid].mdSecsize = DEV_BSIZE; /* Set starting block size */
592 if(phys) mdev[devid].mdFlags |= mdPhys; /* Show that we are in physical memory */
593 mdev[devid].mdFlags |= mdInited; /* Show we are all set up */
594 printf("Added memory device md%x/rmd%x (%08X/%08X) at %08X for %08X\n",
595 devid, devid, mdev[devid].mdBDev, mdev[devid].mdCDev, base << 12, size << 12);
596 return mdev[devid].mdBDev;
597 }
598
599
600 dev_t mdevlookup(int devid) {
601
602 if((devid < 0) || (devid > 15)) return -1; /* Filter any bogus requests */
603 if(!(mdev[devid].mdFlags & mdInited)) return -1; /* This one hasn't been defined */
604 return mdev[devid].mdBDev; /* Return the device number */
605 }