From patchwork Tue Oct 20 22:30:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinghai Lu X-Patchwork-Id: 533534 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id E6DA714110C for ; Wed, 21 Oct 2015 09:31:12 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=jUuop/3N; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752548AbbJTWav (ORCPT ); Tue, 20 Oct 2015 18:30:51 -0400 Received: from mail-vk0-f65.google.com ([209.85.213.65]:34075 "EHLO mail-vk0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753405AbbJTWaq (ORCPT ); Tue, 20 Oct 2015 18:30:46 -0400 Received: by vkat63 with SMTP id t63so1648075vka.1; Tue, 20 Oct 2015 15:30:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=vhYwUP9kr85cC0NNKtzCWkVWu12/3WzG+it/P19B4zw=; b=jUuop/3NWsYpXnQuyj3jCAExm/uZv47PR7gkvNNzsCxQmWDoPXukFb1uiZZAO2IWy8 XLvq+SW+sPOQE8aGOxyPme1LDrizZoMydfx3DMS4LwAT3Ixu5QnoT4YqOdFioM6h3VbD NuV7Cxn6mduU87hykjYoOrbunNY7l+YVvfxassocQnAoUyFw7UZgjzJCml/+x6xDFLGW RCByEdgSPHmDgFbpJH+1DIVCcVfiqP1eXwayzA2L6q3GPuNBfxCo421Ox2D6vI1Nlyi8 CiVRctsdEjO/t4GfY/i92uVjmGELH8qMEmPAewOE9n2t2HvlROAckSGiiz1APKcqtgDO bJLg== MIME-Version: 1.0 X-Received: by 10.31.157.6 with SMTP id g6mr3839948vke.24.1445380244338; Tue, 20 Oct 2015 15:30:44 -0700 (PDT) Received: by 10.103.45.15 with HTTP; Tue, 20 Oct 2015 15:30:44 -0700 (PDT) In-Reply-To: References: <1444340359-8011-1-git-send-email-yinghai@kernel.org> <1444340359-8011-4-git-send-email-yinghai@kernel.org> <20151020215714.GI8224@localhost> Date: Tue, 20 Oct 2015 15:30:44 -0700 X-Google-Sender-Auth: EQpTyvGcXcNlxzW0kPhP3SJ6hZY Message-ID: Subject: Re: [PATCH v7 03/60] sparc/PCI: Unify pci_register_region() From: Yinghai Lu To: Bjorn Helgaas Cc: Bjorn Helgaas , David Miller , Benjamin Herrenschmidt , Wei Yang , TJ , Yijing Wang , Khalid Aziz , "linux-pci@vger.kernel.org" , Linux Kernel Mailing List Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org On Tue, Oct 20, 2015 at 3:16 PM, Yinghai Lu wrote: > On Tue, Oct 20, 2015 at 2:57 PM, Bjorn Helgaas wrote: >> On Thu, Oct 08, 2015 at 02:38:22PM -0700, Yinghai Lu wrote: >>> We register regions for legacy and iommu and all have open code. >>> >>> Unify them to pci_register_region() and call it accordingly. >>> >>> + if (!mem_res->flags) >>> return; >>> >>> - p->name = "Video RAM area"; >>> - p->start = mem_res->start + 0xa0000UL; >>> - p->end = p->start + 0x1ffffUL; >>> - p->flags = IORESOURCE_BUSY; >>> - request_resource(mem_res, p); >>> + mem_rstart = mem_res->start - offset; >>> + mem_rend = mem_res->end - offset; >> >> This is essentially doing pcibios_bus_to_resource(), except in an >> unnecessarily arch-dependent way. Can you rework it to use >> pcibios_bus_to_resource()? I think you'll have to do >> pci_register_legacy_regions() in pci_scan_one_pbm() instead of in >> pci_determine_mem_io_space(), so that you have a struct pci_bus to >> use, but your next patch does that anyway. >> >>> >>> - p = kzalloc(sizeof(*p), GFP_KERNEL); >>> - if (!p) >>> + /* contain checking */ >>> + if (!(mem_rstart <= rstart && mem_rend >= rend)) >>> return; > > Difference is here. > > pcibios_bus_to_resource() would return resource even region is not contained. > >>> + res->name = name; >>> + res->flags = IORESOURCE_MEM | IORESOURCE_BUSY; >>> + res->start = rstart + offset; >>> + res->end = rend + offset; >>> + conflict = request_resource_conflict(mem_res, res); >>> + if (conflict) { >>> + printk(KERN_DEBUG "PCI: %s can't claim %s %pR: address conflict with %s %pR\n", >>> + pbm->name, res->name, res, conflict->name, conflict); >>> + kfree(res); >>> + } > > also we will need to get parent resource to use request_resource_conflict. so do you agree following change to pcibios_bus_to_resource() ? then we can use __pcibios_bus_resource(). void pcibios_scan_specific_bus(int busn); --- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/pci/host-bridge.c b/drivers/pci/host-bridge.c index 5f4a2e0..6c73327 100644 --- a/drivers/pci/host-bridge.c +++ b/drivers/pci/host-bridge.c @@ -70,12 +70,15 @@ static bool region_contains(struct pci_bus_region *region1, return region1->start <= region2->start && region1->end >= region2->end; } -void pcibios_bus_to_resource(struct pci_bus *bus, struct resource *res, - struct pci_bus_region *region) +int __pcibios_bus_to_resource(struct pci_bus *bus, struct resource *res, + struct pci_bus_region *region, + struct resource **res_ret, + resource_size *off_ret) { struct pci_host_bridge *bridge = pci_find_host_bridge(bus); struct resource_entry *window; resource_size_t offset = 0; + int found = 0; resource_list_for_each_entry(window, &bridge->windows) { struct pci_bus_region bus_region; @@ -88,11 +91,23 @@ void pcibios_bus_to_resource(struct pci_bus *bus, struct resource *res, if (region_contains(&bus_region, region)) { offset = window->offset; + if (off_ret) + *off_ret = offset; + if (res_ret) + *res_ret = window->res; + found = 1; break; } } res->start = region->start + offset; res->end = region->end + offset; + + return found; +} +void pcibios_bus_to_resource(struct pci_bus *bus, struct resource *res, + struct pci_bus_region *region) +{ + __pcibios_bus_to_resource(bus, res, region, NULL, NULL); } EXPORT_SYMBOL(pcibios_bus_to_resource); diff --git a/include/linux/pci.h b/include/linux/pci.h index b54fbf1..bec3eed 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -781,6 +781,10 @@ void pci_fixup_cardbus(struct pci_bus *); void pcibios_resource_to_bus(struct pci_bus *bus, struct pci_bus_region *region, struct resource *res); +int __pcibios_bus_to_resource(struct pci_bus *bus, struct resource *res, + struct pci_bus_region *region, + struct resource **res_ret, + resource_size *off_ret); void pcibios_bus_to_resource(struct pci_bus *bus, struct resource *res, struct pci_bus_region *region);