From patchwork Mon Apr 11 14:42:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Linus Torvalds X-Patchwork-Id: 698321 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p3BEh3Zd008786 for ; Mon, 11 Apr 2011 14:43:06 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752874Ab1DKOnD (ORCPT ); Mon, 11 Apr 2011 10:43:03 -0400 Received: from smtp1.linux-foundation.org ([140.211.169.13]:37139 "EHLO smtp1.linux-foundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751375Ab1DKOnC (ORCPT ); Mon, 11 Apr 2011 10:43:02 -0400 Received: from mail-iw0-f174.google.com (mail-iw0-f174.google.com [209.85.214.174]) (authenticated bits=0) by smtp1.linux-foundation.org (8.14.2/8.13.5/Debian-3ubuntu1.1) with ESMTP id p3BEgXR1012567 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=FAIL); Mon, 11 Apr 2011 07:42:33 -0700 Received: by iwn34 with SMTP id 34so5684762iwn.19 for ; Mon, 11 Apr 2011 07:42:33 -0700 (PDT) Received: by 10.43.69.7 with SMTP id ya7mr7891509icb.364.1302532953234; Mon, 11 Apr 2011 07:42:33 -0700 (PDT) MIME-Version: 1.0 Received: by 10.231.33.199 with HTTP; Mon, 11 Apr 2011 07:42:13 -0700 (PDT) In-Reply-To: <4DA2FFB6.3040209@gaisler.com> References: <4DA2FFB6.3040209@gaisler.com> From: Linus Torvalds Date: Mon, 11 Apr 2011 07:42:13 -0700 Message-ID: Subject: Re: [PATCH 1/4] PCI: refactor io size calculation code To: Daniel Hellstrom Cc: Ram Pai , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Clemens Ladisch , Yinghai Lu , Kristoffer Glembo X-Spam-Status: No, hits=-103.484 required=5 tests=AWL, BAYES_00, OSDL_HEADER_SUBJECT_BRACKETED, USER_IN_WHITELIST X-Spam-Checker-Version: SpamAssassin 3.2.4-osdl_revision__1.47__ X-MIMEDefang-Filter: lf$Revision: 1.188 $ X-Scanned-By: MIMEDefang 2.63 on 140.211.169.13 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 11 Apr 2011 14:43:06 +0000 (UTC) On Mon, Apr 11, 2011 at 6:18 AM, Daniel Hellstrom wrote: >In commit 13583b16592a ("PCI: refactor io size calculation code"): >> >> refactor  code  that  calculates  the  io  size in pbus_size_io() >> and pbus_mem_io() into separate functions. >> >> Signed-off-by: Ram Pai >> --- >> drivers/pci/setup-bus.c |   66 >> ++++++++++++++++++++++++++++++----------------- >> 1 files changed, 42 insertions(+), 24 deletions(-) >> >> diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c >> index 66cb8f4..2121215 100644 >> --- a/drivers/pci/setup-bus.c >> +++ b/drivers/pci/setup-bus.c >> @@ -404,6 +404,43 @@ static struct resource *find_free_bus_resource(struct >> pci_bus *bus, unsigned lon >>        return NULL; >> } >> > ... > >> + >> +static resource_size_t calculate_memsize(resource_size_t size, >> +               resource_size_t min_size, >> +               resource_size_t size1, >> +               resource_size_t old_size, >> +               resource_size_t align) >> +{ >> +       if (size < min_size) >> +               size = min_size; >> +       if (old_size == 1 ) >> +               old_size = 0; >> +       if (size < old_size) >> +               size = old_size; >> +       size = ALIGN(size + size1, align); >> +       return size; >> +} >> + >> /* Sizing the IO windows of the PCI-PCI bridge is trivial, >>   since these windows have 4K granularity and the IO ranges >>   of non-bridge PCI devices are limited to 256 bytes. >> >> > > ... > >> @@ -516,14 +542,6 @@ static int pbus_size_mem(struct pci_bus *bus, >> unsigned long mask, >>                        mem64_mask &= r->flags & IORESOURCE_MEM_64; >>                } >>        } >> -       if (size < min_size) >> -               size = min_size; >> -       old_size = resource_size(b_res); >> -       if (old_size == 1) >> -               old_size = 0; >> -       if (size < old_size) >> -               size = old_size; >> - >>        align = 0; >>        min_align = 0; >>        for (order = 0; order <= max_order; order++) { >> @@ -537,7 +555,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned >> long mask, >>                        min_align = align1 >> 1; >>                align += aligns[order]; >>        } >> -       size = ALIGN(size, min_align); >> +       size = calculate_memsize(size, min_size, 0, resource_size(b_res), >> align); >> > > On my SPARC32/LEON4 PCI system I get overlapped areas, double mapped > resources. Some BARs on PCIBUS0 are in the same non-prefetchable memory > range as the secondary bus PCIBUS1. Changing align to min_align in the above > call to calculate_memsize() fixes the problem, and the memory allocation is > the same as with 2.6.36.4 kernel. > > I belive this is just a typo. It does seem that way. The original code used 'min_align' and 'align' itself is meaningless in that place. Can you confirm that the patch you talk about as fixing things is the attached? Linus drivers/pci/setup-bus.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 89d0a6a88df7..ebf51ad1b714 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -676,10 +676,10 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, min_align = align1 >> 1; align += aligns[order]; } - size0 = calculate_memsize(size, min_size, 0, resource_size(b_res), align); + size0 = calculate_memsize(size, min_size, 0, resource_size(b_res), min_align); size1 = !add_size ? size : calculate_memsize(size, min_size+add_size, 0, - resource_size(b_res), align); + resource_size(b_res), min_align); if (!size0 && !size1) { if (b_res->start || b_res->end) dev_info(&bus->self->dev, "disabling bridge window "