From patchwork Fri Mar 17 03:33:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sukadev Bhattiprolu X-Patchwork-Id: 740132 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vkrjq1jFqz9rxl for ; Fri, 17 Mar 2017 14:41:35 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3vkrjq0sz7zDqmw for ; Fri, 17 Mar 2017 14:41:35 +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 3vkrYq0bKKzDqcY for ; Fri, 17 Mar 2017 14:34:39 +1100 (AEDT) Received: from ozlabs.org (ozlabs.org [103.22.144.67]) by bilbo.ozlabs.org (Postfix) with ESMTP id 3vkrYp6vnKz8swR for ; Fri, 17 Mar 2017 14:34:38 +1100 (AEDT) Received: by ozlabs.org (Postfix) id 3vkrYp6jKMz9s2s; Fri, 17 Mar 2017 14:34:38 +1100 (AEDT) Delivered-To: linuxppc-dev@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 ozlabs.org (Postfix) with ESMTPS id 3vkrYp35Zbz9rxl for ; Fri, 17 Mar 2017 14:34:38 +1100 (AEDT) Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v2H3TcG4077816 for ; Thu, 16 Mar 2017 23:34:36 -0400 Received: from e19.ny.us.ibm.com (e19.ny.us.ibm.com [129.33.205.209]) by mx0b-001b2d01.pphosted.com with ESMTP id 297pv3psxe-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Mar 2017 23:34:36 -0400 Received: from localhost by e19.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Mar 2017 23:34:35 -0400 Received: from b01cxnp22033.gho.pok.ibm.com (9.57.198.23) by e19.ny.us.ibm.com (146.89.104.206) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 16 Mar 2017 23:34:31 -0400 Received: from b01ledav002.gho.pok.ibm.com (b01ledav002.gho.pok.ibm.com [9.57.199.107]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v2H3YLaF40698026; Fri, 17 Mar 2017 03:34:21 GMT Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BC57A12403D; Thu, 16 Mar 2017 23:34:17 -0400 (EDT) Received: from suka-w540.usor.ibm.com (unknown [9.70.94.25]) by b01ledav002.gho.pok.ibm.com (Postfix) with ESMTP id E1A32124035; Thu, 16 Mar 2017 23:34:16 -0400 (EDT) From: Sukadev Bhattiprolu To: Michael Ellerman Subject: [PATCH v3 06/10] VAS: Define helpers to alloc/free windows Date: Thu, 16 Mar 2017 20:33:58 -0700 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1489721642-5657-1-git-send-email-sukadev@linux.vnet.ibm.com> References: <1489721642-5657-1-git-send-email-sukadev@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17031703-0056-0000-0000-00000311FE91 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006796; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000206; SDB=6.00834936; UDB=6.00410084; IPR=6.00612591; BA=6.00005215; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00014685; XFM=3.00000013; UTC=2017-03-17 03:34:33 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17031703-0057-0000-0000-00000747FEF8 Message-Id: <1489721642-5657-7-git-send-email-sukadev@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-03-17_01:, , 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-1703170028 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, 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 --- drivers/misc/vas/vas-window.c | 74 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/drivers/misc/vas/vas-window.c b/drivers/misc/vas/vas-window.c index edf5c9f..9233bf5 100644 --- a/drivers/misc/vas/vas-window.c +++ b/drivers/misc/vas/vas-window.c @@ -119,7 +119,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; @@ -472,8 +472,78 @@ int init_winctx_regs(struct vas_window *window, struct vas_winctx *winctx) return 0; } -/* stub for now */ +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; +} + +static void vas_window_free(struct vas_window *window) +{ + unmap_wc_mmio_bars(window); + kfree(window->paste_addr_name); + kfree(window); +} + +static 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; +} + int vas_window_reset(struct vas_instance *vinst, int winid) { + struct vas_window *window; + + window = vas_window_alloc(vinst, winid); + if (!window) + return -ENOMEM; + + reset_window_regs(window); + + vas_window_free(window); + return 0; }