From patchwork Tue Aug 16 09:15:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Westerberg X-Patchwork-Id: 659564 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 3sD6FT15WRz9t2N for ; Tue, 16 Aug 2016 19:17:17 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753204AbcHPJPk (ORCPT ); Tue, 16 Aug 2016 05:15:40 -0400 Received: from mga04.intel.com ([192.55.52.120]:46156 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751532AbcHPJPG (ORCPT ); Tue, 16 Aug 2016 05:15:06 -0400 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga104.fm.intel.com with ESMTP; 16 Aug 2016 02:15:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,529,1464678000"; d="scan'208";a="1015127673" Received: from lahna.fi.intel.com (HELO lahna) ([10.237.72.157]) by orsmga001.jf.intel.com with SMTP; 16 Aug 2016 02:15:02 -0700 Received: by lahna (sSMTP sendmail emulation); Tue, 16 Aug 2016 12:15:02 +0300 Date: Tue, 16 Aug 2016 12:15:02 +0300 From: Mika Westerberg To: Aaron Durbin Cc: "Rafael J. Wysocki" , Bjorn Helgaas , "Rafael J. Wysocki" , ACPI Devel Maling List , Linux PCI , Andy Shevchenko Subject: Re: ACPI device using sub-resource of PCI device Message-ID: <20160816091502.GB1751@lahna.fi.intel.com> References: <3103060.86QBTjSLk3@vostro.rjw.lan> <3861743.KWBechkp08@vostro.rjw.lan> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.6.2 (2016-07-01) Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org On Fri, Aug 12, 2016 at 11:45:30AM -0500, Aaron Durbin wrote: > Was anyone able to take a look into a solution for the current > problem? Again, please feel free to ask if anyone would like help > testing potential solutions. Below is one proposal for fixing the issue. It is just a prototype and I'm not sure if it takes everything needed into account. Would you be able to try it out and let us know if it works for you? --- 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/acpi/acpi_platform.c b/drivers/acpi/acpi_platform.c index 159f7f19abce..72068415f806 100644 --- a/drivers/acpi/acpi_platform.c +++ b/drivers/acpi/acpi_platform.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "internal.h" @@ -30,6 +31,35 @@ static const struct acpi_device_id forbidden_id_list[] = { {"", 0}, }; +static struct resource *acpi_find_parent_resource(struct acpi_device *adev, + struct resource *res) +{ + struct device *parent; + + parent = acpi_get_first_physical_node(adev->parent); + if (!parent) + return NULL; + +#if IS_ENABLED(CONFIG_PCI) + if (dev_is_pci(parent)) { + struct pci_dev *pdev = to_pci_dev(parent); + + if (!pci_is_bridge(pdev)) { + int i; + + for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { + struct resource *r = &pdev->resource[i]; + + if (r->start && resource_contains(r, res)) + return r; + } + } + } +#endif + + return NULL; +} + /** * acpi_create_platform_device - Create platform device for ACPI device node * @adev: ACPI device node to create a platform device for. @@ -69,8 +99,17 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev) return ERR_PTR(-ENOMEM); } count = 0; - list_for_each_entry(rentry, &resource_list, node) - resources[count++] = *rentry->res; + list_for_each_entry(rentry, &resource_list, node) { + struct resource *res = &resources[count++]; + + *res = *rentry->res; + /* + * If the device has parent we need to take its + * resources into account as well because this + * device might consume part of those. + */ + res->parent = acpi_find_parent_resource(adev, res); + } acpi_dev_free_resource_list(&resource_list); }