From patchwork Fri Mar 31 05:13:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sukadev Bhattiprolu X-Patchwork-Id: 745500 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 ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vvVKm6qRRz9s0Z for ; Fri, 31 Mar 2017 16:24:12 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3vvVKm5ykRzDqy4 for ; Fri, 31 Mar 2017 16:24:12 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from ozlabs.org (ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3vvV6P42MczDqHJ for ; Fri, 31 Mar 2017 16:14:21 +1100 (AEDT) Received: from ozlabs.org (ozlabs.org [103.22.144.67]) by bilbo.ozlabs.org (Postfix) with ESMTP id 3vvV6P21Btz8sxx for ; Fri, 31 Mar 2017 16:14:21 +1100 (AEDT) Received: by ozlabs.org (Postfix) id 3vvV6P14Rcz9s0Z; Fri, 31 Mar 2017 16:14:21 +1100 (AEDT) Delivered-To: linuxppc-dev@ozlabs.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vvV6N59V8z9s4s for ; Fri, 31 Mar 2017 16:14:20 +1100 (AEDT) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v2V5DoDp043863 for ; Fri, 31 Mar 2017 01:14:17 -0400 Received: from e37.co.us.ibm.com (e37.co.us.ibm.com [32.97.110.158]) by mx0a-001b2d01.pphosted.com with ESMTP id 29hf2xcca1-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 31 Mar 2017 01:14:16 -0400 Received: from localhost by e37.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 30 Mar 2017 23:14:15 -0600 Received: from b03cxnp07028.gho.boulder.ibm.com (9.17.130.15) by e37.co.us.ibm.com (192.168.1.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 30 Mar 2017 23:14:11 -0600 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v2V5E1Zh17302004; Thu, 30 Mar 2017 22:14:01 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5F210C6037; Thu, 30 Mar 2017 23:14:01 -0600 (MDT) Received: from suka-w540.usor.ibm.com (unknown [9.70.94.25]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP id D3A98C603C; Thu, 30 Mar 2017 23:14:00 -0600 (MDT) From: Sukadev Bhattiprolu To: Michael Ellerman Subject: [PATCH v4 07/11] VAS: Define helpers to alloc/free windows Date: Thu, 30 Mar 2017 22:13:40 -0700 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490937224-29149-1-git-send-email-sukadev@linux.vnet.ibm.com> References: <1490937224-29149-1-git-send-email-sukadev@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17033105-0024-0000-0000-00001628412B X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006875; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000206; SDB=6.00841048; UDB=6.00414062; IPR=6.00619112; BA=6.00005248; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00014869; XFM=3.00000013; UTC=2017-03-31 05:14:14 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17033105-0025-0000-0000-000049E15FA6 Message-Id: <1490937224-29149-8-git-send-email-sukadev@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-03-31_04:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1703310047 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: stewart@linux.vnet.ibm.com, linuxppc-dev@ozlabs.org, linux-kernel@vger.kernel.org, apopple@au1.ibm.com, oohall@gmail.com, michael.neuling@au1.ibm.com Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Define helpers to allocate/free VAS window objects. These will be used in follow-on patches when opening/closing windows. Signed-off-by: Sukadev Bhattiprolu --- arch/powerpc/platforms/powernv/vas-window.c | 63 ++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/platforms/powernv/vas-window.c b/arch/powerpc/platforms/powernv/vas-window.c index 5ddcb63..0c178fe 100644 --- a/arch/powerpc/platforms/powernv/vas-window.c +++ b/arch/powerpc/platforms/powernv/vas-window.c @@ -120,7 +120,7 @@ static void unmap_wc_mmio_bars(struct vas_window *window) * OS/User Window Context (UWC) MMIO Base Address Region for the given window. * Map these bus addresses and save the mapped kernel addresses in @window. */ -int map_wc_mmio_bars(struct vas_window *window) +static int map_wc_mmio_bars(struct vas_window *window) { int len; uint64_t start; @@ -437,6 +437,67 @@ int init_winctx_regs(struct vas_window *window, struct vas_winctx *winctx) return 0; } +DEFINE_SPINLOCK(vas_ida_lock); + +void vas_release_window_id(struct ida *ida, int winid) +{ + spin_lock(&vas_ida_lock); + ida_remove(ida, winid); + spin_unlock(&vas_ida_lock); +} + +int vas_assign_window_id(struct ida *ida) +{ + int rc, winid; + + rc = ida_pre_get(ida, GFP_KERNEL); + if (!rc) + return -EAGAIN; + + spin_lock(&vas_ida_lock); + rc = ida_get_new_above(ida, 0, &winid); + spin_unlock(&vas_ida_lock); + + if (rc) + return rc; + + if (winid > VAS_MAX_WINDOWS_PER_CHIP) { + pr_err("VAS: Too many (%d) open windows\n", winid); + vas_release_window_id(ida, winid); + return -EAGAIN; + } + + return winid; +} + +void vas_window_free(struct vas_window *window) +{ + unmap_wc_mmio_bars(window); + kfree(window->paste_addr_name); + kfree(window); +} + +struct vas_window *vas_window_alloc(struct vas_instance *vinst, int id) +{ + struct vas_window *window; + + window = kzalloc(sizeof(*window), GFP_KERNEL); + if (!window) + return NULL; + + window->vinst = vinst; + window->winid = id; + + if (map_wc_mmio_bars(window)) + goto out_free; + + return window; + +out_free: + kfree(window); + return NULL; +} + /* stub for now */ int vas_win_close(struct vas_window *window) {