1 /* $NetBSD: ofw_machdep.c,v 1.13 2002/09/18 01:46:23 chs Exp $ */ 2 3 /* 4 * Copyright (C) 1996 Wolfgang Solfrank. 5 * Copyright (C) 1996 TooLs GmbH. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by TooLs GmbH. 19 * 4. The name of TooLs GmbH may not be used to endorse or promote products 20 * derived from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 28 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 #include <sys/param.h> 34 #include <sys/buf.h> 35 #include <sys/conf.h> 36 #include <sys/device.h> 37 #include <sys/disk.h> 38 #include <sys/disklabel.h> 39 #include <sys/fcntl.h> 40 #include <sys/ioctl.h> 41 #include <sys/malloc.h> 42 #include <sys/stat.h> 43 #include <sys/systm.h> 44 45 #include <dev/ofw/openfirm.h> 46 47 #include <machine/powerpc.h> 48 49 #define OFMEM_REGIONS 32 50 static struct mem_region OFmem[OFMEM_REGIONS + 1], OFavail[OFMEM_REGIONS + 3]; 51 52 /* 53 * This is called during initppc, before the system is really initialized. 54 * It shall provide the total and the available regions of RAM. 55 * Both lists must have a zero-size entry as terminator. 56 * The available regions need not take the kernel into account, but needs 57 * to provide space for two additional entry beyond the terminating one. 58 */ 59 void 60 mem_regions(struct mem_region **memp, struct mem_region **availp) 61 { 62 int phandle, i, cnt; 63 64 /* 65 * Get memory. 66 */ 67 if ((phandle = OF_finddevice("/memory")) == -1) 68 goto error; 69 70 memset(OFmem, 0, sizeof OFmem); 71 cnt = OF_getprop(phandle, "reg", 72 OFmem, sizeof OFmem[0] * OFMEM_REGIONS); 73 if (cnt <= 0) 74 goto error; 75 76 /* Remove zero sized entry in the returned data. */ 77 cnt /= sizeof OFmem[0]; 78 for (i = 0; i < cnt; ) 79 if (OFmem[i].size == 0) { 80 memmove(&OFmem[i], &OFmem[i + 1], 81 (cnt - i) * sizeof OFmem[0]); 82 cnt--; 83 } else 84 i++; 85 86 memset(OFavail, 0, sizeof OFavail); 87 cnt = OF_getprop(phandle, "available", 88 OFavail, sizeof OFavail[0] * OFMEM_REGIONS); 89 if (cnt <= 0) 90 goto error; 91 92 cnt /= sizeof OFavail[0]; 93 for (i = 0; i < cnt; ) 94 if (OFavail[i].size == 0) { 95 memmove(&OFavail[i], &OFavail[i + 1], 96 (cnt - i) * sizeof OFavail[0]); 97 cnt--; 98 } else 99 i++; 100 101 *memp = OFmem; 102 *availp = OFavail; 103 return; 104 105 error: 106 panic("no memory?"); 107 } 108 109 void 110 ppc_exit(void) 111 { 112 OF_exit(); 113 } 114 115 void 116 ppc_boot(char *str) 117 { 118 OF_boot(str); 119 } 120