xref: /netbsd/sys/arch/acorn32/dev/md_hooks.c (revision bf9ec67e)
1 /*	$NetBSD: md_hooks.c,v 1.4 2002/05/06 21:18:25 jdolecek Exp $	*/
2 
3 /*
4  * Copyright (c) 1995 Gordon W. Ross
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include "opt_md.h"
31 
32 #include <sys/param.h>
33 #include <sys/reboot.h>
34 #include <sys/device.h>
35 #include <sys/systm.h>
36 
37 #include <uvm/uvm_extern.h>
38 
39 #include <dev/md.h>
40 
41 #ifdef	MEMORY_DISK_ROOT_SIZE
42 #define ROOTBYTES (MEMORY_DISK_ROOT_SIZE << DEV_BSHIFT)
43 
44 /*
45  * This array will be patched to contain a file-system image.
46  * See the program:  src/distrib/sun3/common/rdsetroot.c
47  */
48 size_t md_root_size = ROOTBYTES;
49 char md_root_image[ROOTBYTES] = "|This is the root ramdisk!\n";
50 
51 #else	/* MEMORY_DISK_ROOT_SIZE */
52 
53 size_t md_root_size = 0;		/* set by machdep.c */
54 static struct md_conf *bootmd = NULL;
55 
56 extern int load_memory_disc_from_floppy __P((struct md_conf *md, dev_t dev));
57 
58 #include "fdc.h"
59 #endif	/* MEMORY_DISK_ROOT_SIZE */
60 
61 void
62 md_attach_hook(unit, md)
63 	int unit;
64 	struct md_conf *md;
65 {
66 	if (unit == 0) {
67 #ifdef MEMORY_DISK_ROOT_SIZE
68 		/* Setup root ramdisk */
69 		md->md_addr = (caddr_t) md_root_image;
70 		md->md_size = (size_t)  md_root_size;
71 		md->md_type = MD_KMEM_FIXED;
72 #else	/* MEMORY_DISK_ROOT_SIZE */
73 #ifdef OLD_MEMORY_DISK_SIZE
74 		if (md_root_size == 0 && OLD_MEMORY_DISK_SIZE)
75 			md_root_size = (OLD_MEMORY_DISK_SIZE << DEV_BSHIFT);
76 #endif	/* OLD_MEMORY_DISK_SIZE */
77 		if (md_root_size != 0) {
78 			md->md_size = round_page(md_root_size);
79 			md->md_addr = (caddr_t)uvm_km_zalloc(kernel_map, md_root_size);
80 			md->md_type = MD_KMEM_FIXED;
81 			bootmd = md;
82 		}
83 #endif	/* MEMORY_DISK_ROOT_SIZE */
84 		printf("md%d: allocated %ldK (%ld blocks)\n", unit, (long)md->md_size / 1024, (long)md->md_size / DEV_BSIZE);
85 	}
86 }
87 
88 
89 /*
90  * This is called during open (i.e. mountroot)
91  */
92 
93 void
94 md_open_hook(unit, md)
95 	int unit;
96 	struct md_conf *md;
97 {
98 	if (unit == 0) {
99 		/* The root memory disk only works single-user. */
100 		boothowto |= RB_SINGLE;
101 #if !defined(MEMORY_DISK_ROOT_SIZE) && NFDC > 0
102 		load_memory_disc_from_floppy(bootmd, makedev(17, 1));	/* XXX 1.44MB FD */
103 #endif
104 	}
105 }
106