From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1Ic584-00058u-OL for mharc-grub-devel@gnu.org; Sun, 30 Sep 2007 16:11:04 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Ic583-00058p-B8 for grub-devel@gnu.org; Sun, 30 Sep 2007 16:11:03 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Ic582-00058A-OW for grub-devel@gnu.org; Sun, 30 Sep 2007 16:11:03 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ic582-000583-M4 for grub-devel@gnu.org; Sun, 30 Sep 2007 16:11:02 -0400 Received: from aybabtu.com ([69.60.117.155]) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Ic582-0000tj-AO for grub-devel@gnu.org; Sun, 30 Sep 2007 16:11:02 -0400 Received: from [192.168.10.6] (helo=thorin) by aybabtu.com with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1Ic57z-0001KO-Jm; Sun, 30 Sep 2007 22:11:00 +0200 Received: from rmh by thorin with local (Exim 4.63) (envelope-from ) id 1Ic57b-0003HS-6L; Sun, 30 Sep 2007 22:10:35 +0200 Date: Sun, 30 Sep 2007 22:10:35 +0200 From: Robert Millan To: The development of GRUB 2 Message-ID: <20070930201035.GA12468@thorin> References: <20070727103310.GA1539@powerlinux.fr> <20070727191514.GA3461@aragorn> <20070729193011.GA7033@aragorn> <20070730201138.GA27359@aragorn> <20070731143823.GA16557@aragorn> <20070731194232.GA19385@aragorn> <20070801182716.GA12782@aragorn> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="oyUTqETQ0mS9luUI" Content-Disposition: inline In-Reply-To: <20070801182716.GA12782@aragorn> Organization: free as in freedom X-Message-Flag: Microsoft discourages use of Outlook. X-Debbugs-No-Ack: true User-Agent: Mutt/1.5.13 (2006-08-11) X-Detected-Kernel: Genre and OS details not recognized. Cc: Marcin Kurek Subject: [PATCH] fix memory management on efika/pegasos X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 30 Sep 2007 20:11:03 -0000 --oyUTqETQ0mS9luUI Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Finally, I think I got this right now. My efika boots and all the other setups should be happy as well. Please, review/test this and report. -- Robert Millan I know my rights; I want my phone call! What use is a phone call, if you are unable to speak? (as seen on /.) --oyUTqETQ0mS9luUI Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="efika.diff" 2007-09-30 Robert Millan * kern/powerpc/ieee1275/init.c: Rename HEAP_LIMIT to HEAP_MAX_ADDR, and make it easier to figure out. Add HEAP_MIN_SIZE and HEAP_MAX_ADDR definitions. (grub_claim_heap): Use HEAP_MAX_ADDR rather than taking a parameter. Do not avoid claiming a region above HEAP_MAX_ADDR if that would leave us with less than HEAP_MIN_SIZE total heap. Avoid our total amount of heap to surpass HEAP_MAX_SIZE. diff -ur grub2/kern/powerpc/ieee1275/init.c grub2.efika/kern/powerpc/ieee1275/init.c --- grub2/kern/powerpc/ieee1275/init.c 2007-07-22 01:32:27.000000000 +0200 +++ grub2.efika/kern/powerpc/ieee1275/init.c 2007-09-30 21:54:19.000000000 +0200 @@ -33,7 +33,15 @@ #include #include -#define HEAP_LIMIT (4<<20) /* 4 MiB */ +/* The minimal heap size we can live with. */ +#define HEAP_MIN_SIZE (unsigned long) (2 * 1024 * 1024) + +/* The maximum heap size we're going to claim */ +#define HEAP_MAX_SIZE (unsigned long) (4 * 1024 * 1024) + +/* If possible, we will avoid claiming heap above this address, because it + seems to cause relocation problems with OSes that link at 4 MiB */ +#define HEAP_MAX_ADDR (unsigned long) (4 * 1024 * 1024) extern char _start[]; extern char _end[]; @@ -113,16 +121,24 @@ } /* Claim some available memory in the first /memory node. */ -static void grub_claim_heap (unsigned long heaplimit) +static void grub_claim_heap () { + unsigned long total = 0; + auto int heap_init (grub_uint64_t addr, grub_uint64_t len); int heap_init (grub_uint64_t addr, grub_uint64_t len) { len -= 1; /* Required for some firmware. */ - /* Don't claim anything above `heaplimit'. */ - if (addr + len > heaplimit) - len = heaplimit - addr; + /* Never exceed HEAP_MAX_SIZE */ + if (total + len > HEAP_MAX_SIZE) + len = HEAP_MAX_SIZE - total; + + /* Avoid claiming anything above HEAP_MAX_ADDR, if possible. */ + if ((addr < HEAP_MAX_ADDR) && /* if it's too late, don't bother */ + (addr + len > HEAP_MAX_ADDR) && /* if it wasn't available anyway, don't bother */ + (total + (HEAP_MAX_ADDR - addr) > HEAP_MIN_SIZE)) /* only limit ourselves when we can afford to */ + len = HEAP_MAX_ADDR - addr; if (len) { @@ -134,6 +150,10 @@ grub_mm_init_region ((void *) (grub_addr_t) addr, len); } + total += len; + if (total >= HEAP_MAX_SIZE) + return 1; + return 0; } @@ -147,7 +167,7 @@ int actual; grub_console_init (); - grub_claim_heap (HEAP_LIMIT); + grub_claim_heap (); grub_ofdisk_init (); /* Process commandline. */ --oyUTqETQ0mS9luUI--