From patchwork Wed Aug 10 00:44:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauricio Faria de Oliveira X-Patchwork-Id: 657560 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3s8CBr6wbDz9t0M for ; Wed, 10 Aug 2016 10:46:28 +1000 (AEST) Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3s8CBr62ZmzDrQV for ; Wed, 10 Aug 2016 10:46:28 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3s8C8K3CGszDqQq for ; Wed, 10 Aug 2016 10:44:17 +1000 (AEST) Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u7A0hQFO094033 for ; Tue, 9 Aug 2016 20:44:15 -0400 Received: from e24smtp03.br.ibm.com (e24smtp03.br.ibm.com [32.104.18.24]) by mx0b-001b2d01.pphosted.com with ESMTP id 24qm9puwd5-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 09 Aug 2016 20:44:15 -0400 Received: from localhost by e24smtp03.br.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 9 Aug 2016 21:44:13 -0300 Received: from d24dlp02.br.ibm.com (9.18.248.206) by e24smtp03.br.ibm.com (10.172.0.139) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 9 Aug 2016 21:44:11 -0300 X-IBM-Helo: d24dlp02.br.ibm.com X-IBM-MailFrom: mauricfo@linux.vnet.ibm.com X-IBM-RcptTo: linuxppc-dev@lists.ozlabs.org Received: from d24relay02.br.ibm.com (d24relay02.br.ibm.com [9.13.184.26]) by d24dlp02.br.ibm.com (Postfix) with ESMTP id 2A72D1DC006D for ; Tue, 9 Aug 2016 20:44:02 -0400 (EDT) Received: from d24av02.br.ibm.com (d24av02.br.ibm.com [9.8.31.93]) by d24relay02.br.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u7A0iBTW32440618 for ; Tue, 9 Aug 2016 21:44:11 -0300 Received: from d24av02.br.ibm.com (localhost [127.0.0.1]) by d24av02.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u7A0iAdS006336 for ; Tue, 9 Aug 2016 21:44:10 -0300 Received: from t440.ibm.com ([9.80.238.101]) by d24av02.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u7A0i4UZ006262; Tue, 9 Aug 2016 21:44:08 -0300 From: Mauricio Faria de Oliveira To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH v2 1/2] powerpc: add refcount to struct pci_controller Date: Tue, 9 Aug 2016 21:44:03 -0300 X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1470789844-16401-1-git-send-email-mauricfo@linux.vnet.ibm.com> References: <1470789844-16401-1-git-send-email-mauricfo@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16081000-0024-0000-0000-000000EFC647 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16081000-0025-0000-0000-00001579A44B Message-Id: <1470789844-16401-2-git-send-email-mauricfo@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-08-09_11:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1608100005 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" This commit introduces the 'refcount' field in struct pci_controller, along with the corresponding functions 'controller_(get|put|free)()'. The functions 'pcibios_(alloc|free)_controller()' are modified to use that in a backwards compatible manner. (i.e., kfree(phb) is performed when pcibios_free_controller() is called.) So, this patch adds the infrastructure with no functional differences to current users of pcibios_(alloc|free)_controller(). Notably, only the pseries platform calls pcibios_free_controller() for some purpose other than to release the pci_controller in case of errors just after the call to pcibios_alloc_controller() (i.e., 'goto error' scenarios). Signed-off-by: Mauricio Faria de Oliveira --- arch/powerpc/include/asm/pci-bridge.h | 15 +++++++++++ arch/powerpc/kernel/pci-common.c | 47 ++++++++++++++++++++++++++++++++--- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/include/asm/pci-bridge.h b/arch/powerpc/include/asm/pci-bridge.h index b5e88e4..6fde0a9 100644 --- a/arch/powerpc/include/asm/pci-bridge.h +++ b/arch/powerpc/include/asm/pci-bridge.h @@ -10,6 +10,7 @@ #include #include #include +#include struct device_node; @@ -128,9 +129,23 @@ struct pci_controller { struct pci_dn *pci_data; #endif /* CONFIG_PPC64 */ + /* + * Reference counting for the structures: + * - TODO pci_dev + * - TODO pci_bus + * - TODO pci_dn + * - TODO eeh_pe + * - TODO eeh_dev + */ + struct kref refcount; + void *private_data; }; +void controller_get(struct pci_controller *phb); +void controller_put(struct pci_controller *phb); +void controller_free(struct kref *kref); + /* These are used for config access before all the PCI probing has been done. */ extern int early_read_config_byte(struct pci_controller *hose, int bus, diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c index 08afddf..29b37d3 100644 --- a/arch/powerpc/kernel/pci-common.c +++ b/arch/powerpc/kernel/pci-common.c @@ -114,6 +114,8 @@ struct pci_controller *pcibios_alloc_controller(struct device_node *dev) phb = zalloc_maybe_bootmem(sizeof(struct pci_controller), GFP_KERNEL); if (phb == NULL) return NULL; + + kref_init(&phb->refcount); /* use first reference for hose_list entry */ spin_lock(&hose_spinlock); phb->global_number = get_phb_number(dev); list_add_tail(&phb->list_node, &hose_list); @@ -130,12 +132,53 @@ struct pci_controller *pcibios_alloc_controller(struct device_node *dev) PHB_SET_NODE(phb, nid); } #endif + + pr_debug("PCI domain %d, phb %p, phb->is_dynamic %d\n", + phb->global_number, phb, phb->is_dynamic); + return phb; } EXPORT_SYMBOL_GPL(pcibios_alloc_controller); +void controller_get(struct pci_controller *phb) +{ + if (unlikely(!phb)) { + pr_warn("%s: null PHB; refcount bug!\n", __func__); + WARN_ON(1); + } else { + pr_debug("PCI domain %d, phb %p\n", phb->global_number, phb); + kref_get(&phb->refcount); + } +} + +void controller_put(struct pci_controller *phb) +{ + if (unlikely(!phb)) { + pr_warn("%s: null PHB; refcount bug!\n", __func__); + WARN_ON(1); + } else { + pr_debug("PCI domain %d, phb %p\n", phb->global_number, phb); + kref_put(&phb->refcount, controller_free); + } +} + +void controller_free(struct kref *kref) +{ + struct pci_controller *phb = container_of(kref, struct pci_controller, + refcount); + + pr_info("%s: PCI domain: %d, phb %p, phb->is_dynamic %d\n", + __func__, phb->global_number, phb, phb->is_dynamic); + + if (phb->is_dynamic) + kfree(phb); +} + void pcibios_free_controller(struct pci_controller *phb) { + pr_debug("PCI domain %d, phb %p, phb->is_dynamic %d\n", + phb->global_number, phb, phb->is_dynamic); + spin_lock(&hose_spinlock); /* Clear bit of phb_bitmap to allow reuse of this PHB number. */ @@ -143,10 +186,8 @@ void pcibios_free_controller(struct pci_controller *phb) clear_bit(phb->global_number, phb_bitmap); list_del(&phb->list_node); + controller_put(phb); spin_unlock(&hose_spinlock); - - if (phb->is_dynamic) - kfree(phb); } EXPORT_SYMBOL_GPL(pcibios_free_controller);