Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933127AbdCaFPV (ORCPT ); Fri, 31 Mar 2017 01:15:21 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:40517 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932807AbdCaFOS (ORCPT ); Fri, 31 Mar 2017 01:14:18 -0400 From: Sukadev Bhattiprolu To: Michael Ellerman Cc: Benjamin Herrenschmidt , michael.neuling@au1.ibm.com, stewart@linux.vnet.ibm.com, apopple@au1.ibm.com, hbabu@us.ibm.com, oohall@gmail.com, bsingharora@gmail.com, linuxppc-dev@ozlabs.org, 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 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2243 Lines: 91 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) { -- 2.7.4