From patchwork Fri Nov 25 10:57:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 9447341 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5D16260778 for ; Fri, 25 Nov 2016 10:57:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 60AE427D13 for ; Fri, 25 Nov 2016 10:57:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 556BB2807E; Fri, 25 Nov 2016 10:57:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 703C127FB6 for ; Fri, 25 Nov 2016 10:57:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751515AbcKYK51 (ORCPT ); Fri, 25 Nov 2016 05:57:27 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:35457 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750801AbcKYK50 (ORCPT ); Fri, 25 Nov 2016 05:57:26 -0500 Received: by mail-pg0-f66.google.com with SMTP id p66so5316180pga.2; Fri, 25 Nov 2016 02:57:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=igL+6POfEsLCflLvIMRMfyPVFKvZae06CUZ+jNm+Xw4=; b=t1UmRfXAcxWiSaTyfq59PRrgomT6knBu/80C8JQQZat9aNRsNl1v2LfM+a2FE5xsDg fnd6+2Q7jFatmaPLtTN3Cdqd+brI8mqN9qCCUOpxjCsdmR+X5k59iSO2gmvGEF0eRPtP zuHFmd9QjLvBj+VhGFkX257UJTmAdlzGP9Miie3JtcZkKSFAT4NUsT4unGT2AXrzDHpK z7eBB8dGZ92wR/pBRrJrssBOKlbyrA9v5ZVlgpt5i0oFWwyrttgj6rrVrSZxhzxsV6Ch 39QZeoytURVuheZKpuFQK1JJ8SycadHfajywb4lZEW6Acg508TQiUZ7vc78gBbBc7WwB rDMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=igL+6POfEsLCflLvIMRMfyPVFKvZae06CUZ+jNm+Xw4=; b=CuFNZkT4ysg3+bE5Ez7z88lk4zSb7PpzpHFMosu+bWZY9UqJhVA7HApsLj+0Y4d+/B 9lRpoLjTx/YF3d92eKB6uOfd4UmE1pYbIrgo832Q9TF/eb+c04mAAc9d+kJS1Wt4jZnZ 7IOxMiO0BWSzuonURjsNrpLfe9Hvm9lR7QUrgs3HAdT2hhO7nljJHCdx+2m+MIytlsfV V4m6wGdAvqngLs1DJI6VtZDRCe4b6GORS65+ooLWHwwjN6RehB+lQBiDgWzYeNI+VLhY 6e2BIgXqwYi6OCRmsLbSKWTOzzlOmNrSAoGcWE/ayH7xryGJVZ5i2j/N1HTxd7RNwC6O ZiAg== X-Gm-Message-State: AKaTC03nRDN0RBUglUz5WC7vRW6lfPUFUn/yORi4n8jIQmSOLQ2rQhKkkr8EAgDkNhbu6g== X-Received: by 10.99.19.65 with SMTP id 1mr12939245pgt.71.1480071445833; Fri, 25 Nov 2016 02:57:25 -0800 (PST) Received: from localhost (port-2820.pppoe.wtnet.de. [84.46.11.15]) by smtp.gmail.com with ESMTPSA id b126sm66964119pfg.90.2016.11.25.02.57.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 25 Nov 2016 02:57:24 -0800 (PST) From: Thierry Reding To: Bjorn Helgaas Cc: Arnd Bergmann , Tomasz Nowicki , Liviu Dudau , Lorenzo Pieralisi , Vidya Sagar , linux-pci@vger.kernel.org, linux-tegra@vger.kernel.org Subject: [PATCH v4 02/10] PCI: Allow driver-specific data in host bridge Date: Fri, 25 Nov 2016 11:57:10 +0100 Message-Id: <20161125105718.3866-2-thierry.reding@gmail.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161125105718.3866-1-thierry.reding@gmail.com> References: <20161125105718.3866-1-thierry.reding@gmail.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Thierry Reding Provide a way to allocate driver-specific data along with a PCI host bridge structure. The bridge's ->private field points to this data. Changes in v4: - use zero-sized, cache-aligned structure field to store private data - provide static inline functions to obtain private data and upcast from private data to struct pci_host_bridge Signed-off-by: Thierry Reding --- drivers/pci/probe.c | 6 +++--- include/linux/pci.h | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 99f503c3ab81..912b22ed96dd 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -521,11 +521,11 @@ static void pci_release_host_bridge_dev(struct device *dev) kfree(bridge); } -static struct pci_host_bridge *pci_alloc_host_bridge(void) +static struct pci_host_bridge *pci_alloc_host_bridge(size_t priv) { struct pci_host_bridge *bridge; - bridge = kzalloc(sizeof(*bridge), GFP_KERNEL); + bridge = kzalloc(sizeof(*bridge) + priv, GFP_KERNEL); if (!bridge) return NULL; @@ -2279,7 +2279,7 @@ static struct pci_bus *pci_create_root_bus_msi(struct device *parent, int error; struct pci_host_bridge *bridge; - bridge = pci_alloc_host_bridge(); + bridge = pci_alloc_host_bridge(0); if (!bridge) return NULL; diff --git a/include/linux/pci.h b/include/linux/pci.h index ff16e44d8f84..e9ba95cbfd62 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -434,10 +434,21 @@ struct pci_host_bridge { resource_size_t start, resource_size_t size, resource_size_t align); + unsigned long private[0] ____cacheline_aligned; }; #define to_pci_host_bridge(n) container_of(n, struct pci_host_bridge, dev) +static inline void *pci_host_bridge_priv(struct pci_host_bridge *bridge) +{ + return (void *)bridge->private; +} + +static inline struct pci_host_bridge *pci_host_bridge_from_priv(void *priv) +{ + return container_of(priv, struct pci_host_bridge, private); +} + struct pci_host_bridge *pci_find_host_bridge(struct pci_bus *bus); void pci_set_host_bridge_release(struct pci_host_bridge *bridge,