From patchwork Thu Jan 21 06:28:05 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinghai Lu X-Patchwork-Id: 74236 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.2) with ESMTP id o0L6UEJd011561 for ; Thu, 21 Jan 2010 06:30:14 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754707Ab0AUG32 (ORCPT ); Thu, 21 Jan 2010 01:29:28 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754695Ab0AUG31 (ORCPT ); Thu, 21 Jan 2010 01:29:27 -0500 Received: from sca-es-mail-2.Sun.COM ([192.18.43.133]:38821 "EHLO sca-es-mail-2.sun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754528Ab0AUG3X (ORCPT ); Thu, 21 Jan 2010 01:29:23 -0500 Received: from fe-sfbay-09.sun.com ([192.18.43.129]) by sca-es-mail-2.sun.com (8.13.7+Sun/8.12.9) with ESMTP id o0L6TMKx014463; Wed, 20 Jan 2010 22:29:22 -0800 (PST) MIME-version: 1.0 Content-transfer-encoding: 7BIT Content-type: TEXT/PLAIN Received: from conversion-daemon.fe-sfbay-09.sun.com by fe-sfbay-09.sun.com (Sun Java(tm) System Messaging Server 7u2-7.04 64bit (built Jul 2 2009)) id <0KWL00600396VF00@fe-sfbay-09.sun.com>; Wed, 20 Jan 2010 22:29:22 -0800 (PST) Received: from localhost.localdomain ([unknown] [75.36.251.46]) by fe-sfbay-09.sun.com (Sun Java(tm) System Messaging Server 7u2-7.04 64bit (built Jul 2 2009)) with ESMTPSA id <0KWL003MR3C23V10@fe-sfbay-09.sun.com>; Wed, 20 Jan 2010 22:29:12 -0800 (PST) Date: Wed, 20 Jan 2010 22:28:05 -0800 From: Yinghai Lu Subject: [PATCH 18/36] x86: add find_early_area_size In-reply-to: <1264055303-15123-1-git-send-email-yinghai@kernel.org> To: Ingo Molnar , Thomas Gleixner , "H. Peter Anvin" , Andrew Morton , Jesse Barnes , Christoph Lameter Cc: Linus Torvalds , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Yinghai Lu Message-id: <1264055303-15123-19-git-send-email-yinghai@kernel.org> X-Mailer: git-send-email 1.6.4.2 References: <1264055303-15123-1-git-send-email-yinghai@kernel.org> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org diff --git a/arch/x86/kernel/early_res.c b/arch/x86/kernel/early_res.c index 3ae0051..aba02f2 100644 --- a/arch/x86/kernel/early_res.c +++ b/arch/x86/kernel/early_res.c @@ -476,6 +476,29 @@ out: return -1ULL; } +u64 __init find_early_area_size(u64 ei_start, u64 ei_last, u64 start, + u64 *sizep, u64 align) +{ + u64 addr, last; + + addr = round_up(ei_start, align); + if (addr < start) + addr = round_up(start, align); + if (addr >= ei_last) + goto out; + *sizep = ei_last - addr; + while (bad_addr_size(&addr, sizep, align) && addr + *sizep <= ei_last) + ; + last = addr + *sizep; + if (last > ei_last) + goto out; + + return addr; + +out: + return -1ULL; +} + /* * Find a free area with specified alignment in a specific range. */ @@ -513,24 +536,20 @@ u64 __init find_e820_area_size(u64 start, u64 *sizep, u64 align) for (i = 0; i < e820.nr_map; i++) { struct e820entry *ei = &e820.map[i]; - u64 addr, last; - u64 ei_last; + u64 addr; + u64 ei_start, ei_last; if (ei->type != E820_RAM) continue; - addr = round_up(ei->addr, align); + ei_last = ei->addr + ei->size; - if (addr < start) - addr = round_up(start, align); - if (addr >= ei_last) - continue; - *sizep = ei_last - addr; - while (bad_addr_size(&addr, sizep, align) && - addr + *sizep <= ei_last) - ; - last = addr + *sizep; - if (last > ei_last) + ei_start = ei->addr; + addr = find_early_area_size(ei_start, ei_last, start, + sizep, align); + + if (addr == -1ULL) continue; + return addr; }