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