xref: /netbsd-src/sys/arch/acorn32/dev/md_hooks.c (revision 23c8222edbfb0f0932d88a8351d3a0cf817dfb9e)
1 /*	$NetBSD: md_hooks.c,v 1.5 2003/07/14 22:48:24 lukem 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 <sys/cdefs.h>
31 __KERNEL_RCSID(0, "$NetBSD: md_hooks.c,v 1.5 2003/07/14 22:48:24 lukem Exp $");
32 
33 #include "opt_md.h"
34 
35 #include <sys/param.h>
36 #include <sys/reboot.h>
37 #include <sys/device.h>
38 #include <sys/systm.h>
39 
40 #include <uvm/uvm_extern.h>
41 
42 #include <dev/md.h>
43 
44 #ifdef	MEMORY_DISK_ROOT_SIZE
45 #define ROOTBYTES (MEMORY_DISK_ROOT_SIZE << DEV_BSHIFT)
46 
47 /*
48  * This array will be patched to contain a file-system image.
49  * See the program:  src/distrib/sun3/common/rdsetroot.c
50  */
51 size_t md_root_size = ROOTBYTES;
52 char md_root_image[ROOTBYTES] = "|This is the root ramdisk!\n";
53 
54 #else	/* MEMORY_DISK_ROOT_SIZE */
55 
56 size_t md_root_size = 0;		/* set by machdep.c */
57 static struct md_conf *bootmd = NULL;
58 
59 extern int load_memory_disc_from_floppy __P((struct md_conf *md, dev_t dev));
60 
61 #include "fdc.h"
62 #endif	/* MEMORY_DISK_ROOT_SIZE */
63 
64 void
65 md_attach_hook(unit, md)
66 	int unit;
67 	struct md_conf *md;
68 {
69 	if (unit == 0) {
70 #ifdef MEMORY_DISK_ROOT_SIZE
71 		/* Setup root ramdisk */
72 		md->md_addr = (caddr_t) md_root_image;
73 		md->md_size = (size_t)  md_root_size;
74 		md->md_type = MD_KMEM_FIXED;
75 #else	/* MEMORY_DISK_ROOT_SIZE */
76 #ifdef OLD_MEMORY_DISK_SIZE
77 		if (md_root_size == 0 && OLD_MEMORY_DISK_SIZE)
78 			md_root_size = (OLD_MEMORY_DISK_SIZE << DEV_BSHIFT);
79 #endif	/* OLD_MEMORY_DISK_SIZE */
80 		if (md_root_size != 0) {
81 			md->md_size = round_page(md_root_size);
82 			md->md_addr = (caddr_t)uvm_km_zalloc(kernel_map, md_root_size);
83 			md->md_type = MD_KMEM_FIXED;
84 			bootmd = md;
85 		}
86 #endif	/* MEMORY_DISK_ROOT_SIZE */
87 		printf("md%d: allocated %ldK (%ld blocks)\n", unit, (long)md->md_size / 1024, (long)md->md_size / DEV_BSIZE);
88 	}
89 }
90 
91 
92 /*
93  * This is called during open (i.e. mountroot)
94  */
95 
96 void
97 md_open_hook(unit, md)
98 	int unit;
99 	struct md_conf *md;
100 {
101 	if (unit == 0) {
102 		/* The root memory disk only works single-user. */
103 		boothowto |= RB_SINGLE;
104 #if !defined(MEMORY_DISK_ROOT_SIZE) && NFDC > 0
105 		load_memory_disc_from_floppy(bootmd, makedev(17, 1));	/* XXX 1.44MB FD */
106 #endif
107 	}
108 }
109