From patchwork Fri Aug 23 16:30:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Winiarski?= X-Patchwork-Id: 13775579 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DEA5CC531DC for ; Fri, 23 Aug 2024 16:32:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8165E10EC7A; Fri, 23 Aug 2024 16:32:05 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="kkx7mb4h"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by gabe.freedesktop.org (Postfix) with ESMTPS id F0CC210EC78; Fri, 23 Aug 2024 16:32:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1724430724; x=1755966724; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=7fTkgV+Z9TYh+yRqhtMM/C+eq/tJJb3CE1MQviaqBJU=; b=kkx7mb4hYsOBzp7zQArAYzaiklrs98eR53vlhjBX3iSteQPayn2inLxF Mi8G9Aq1IskTWhsMJV6cx2m71i79jSioEuEihvslcZ1HhyMDXQIKPETEp oLqwERkqr1Uqo1Bc7hZ1C4MBsZNofNC4W4oHlL/d1VfJMQoAOk+HJjMGo ROg+4YrmNwGInKzeZOu2Xp19fHaqyhoct0/WNhGxhvfzRfc4WcKVLqdaF xICCGpJ1zrVfgW+aL5Vk/tlGr5ChnbqYk/kRm8bXW+taUJcsrqHt/CkTc 5bkSXgl7IvFg9AKJXdJ/+8QoN3NtygIAQzGgmDEAVpJCjZPEpBFw1bguA w==; X-CSE-ConnectionGUID: 2XcqdtIxTaWUo8+qNCyBKA== X-CSE-MsgGUID: o2YTN8EVT3Co20vCQZ7K2Q== X-IronPort-AV: E=McAfee;i="6700,10204,11172"; a="33529982" X-IronPort-AV: E=Sophos;i="6.10,170,1719903600"; d="scan'208";a="33529982" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2024 09:32:03 -0700 X-CSE-ConnectionGUID: WTPl6goQQbOOMm4p0++i/A== X-CSE-MsgGUID: a8QAjgt6TvmcZYat5G+yjA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,170,1719903600"; d="scan'208";a="62556883" Received: from fmsmsx602.amr.corp.intel.com ([10.18.126.82]) by orviesa008.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 23 Aug 2024 09:32:02 -0700 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx602.amr.corp.intel.com (10.18.126.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 23 Aug 2024 09:32:02 -0700 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 23 Aug 2024 09:32:01 -0700 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Fri, 23 Aug 2024 09:32:01 -0700 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.40) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Fri, 23 Aug 2024 09:32:01 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=SDTYFfd3qldI7846GrPfYhBUjNLWS1Do1qk1W01DwyL2ZyuKWdi4jZjJMayWPAz2Jkiyy5vYxduepCFHvVJdphyrTVHbIq3XNlu9APSO6XGgyub/0bgHgYkY31cMJ8nhSLbnEkBXFFn0BnrBUXNLQ6Dk8rKJ64X6h3QF9oUQb0VX8aiKYzSNvMYQP5O5S6R7tSAfJhR/Mpv1BI5Rtdly/uJBqKN/CAsWj8BBQWQ757OPIp3ahehI5dmZJxFZr2NZy9bBiInoJilMRqZBcCWDNOdQCTwV9ZgCEdTkqLPtQcD8aUwFoK4QTyI2tHYZRf0B+k+pmEWQbsqBba2k1Q+Yaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4ap+mBmSTQvDiL/lSL9o88sncBL3vR1DL+KqhJK3zag=; b=vET3anfr+yv5hwNvzKIUGyp1BaiXLEqyAxNq4+RWYeLtRUggB9HPn0bH5YnpbqsJREHeDGsOw5uggO6nY3mx65u0RHOcn72qlkAV9OyypUXDJKzYzLBGbjBNH3vFGTdbCiRaUIBPrY5IABrHSWfyQ58d3XyUGP59PuI5S6RhPQwXXQiQjgyzHRgszOJJgN++LKl14gDrVtdOuMj1CqX0PKcraNEgZf18WA2dcSeyuoIAj7/QRuCHxXvIavuZ77T4edvRymhh5RHV6ByatuCqF+23KFrcBRWSBj00inU94xtWP8xNNarnJkGEqHT/DyzRvd3AzUVt2kiGpH9HeMYYcQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) by BL1PR11MB6026.namprd11.prod.outlook.com (2603:10b6:208:391::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.19; Fri, 23 Aug 2024 16:31:59 +0000 Received: from DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::927a:9c08:26f7:5b39]) by DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::927a:9c08:26f7:5b39%4]) with mapi id 15.20.7897.014; Fri, 23 Aug 2024 16:31:59 +0000 From: =?utf-8?q?Micha=C5=82_Winiarski?= To: , , , CC: David Airlie , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Simon Ser , Matthew Wilcox , Oded Gabbay , =?utf-8?q?Christian_K=C3=B6nig?= , James Zhu , Pekka Paalanen , Emil Velikov , Alex Deucher , =?utf-8?q?Micha=C5=82_Winiarski?= Subject: [PATCH v7 2/3] accel: Use XArray instead of IDR for minors Date: Fri, 23 Aug 2024 18:30:47 +0200 Message-ID: <20240823163048.2676257-3-michal.winiarski@intel.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240823163048.2676257-1-michal.winiarski@intel.com> References: <20240823163048.2676257-1-michal.winiarski@intel.com> X-ClientProxiedBy: WA2P291CA0016.POLP291.PROD.OUTLOOK.COM (2603:10a6:1d0:1e::12) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR11MB5373:EE_|BL1PR11MB6026:EE_ X-MS-Office365-Filtering-Correlation-Id: 9b78aa7c-4d30-4d61-7f83-08dcc3911c1c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|366016|1800799024; X-Microsoft-Antispam-Message-Info: =?utf-8?q?LmAEeD+4BwtPWeQtoBJWc8ePi0JPjYA?= =?utf-8?q?UMPX38ad5d/10//9RuTefbIz4nBVcDypRgcEa4/p7uGNyS6z8CwUbkwRkmfrua8RS?= =?utf-8?q?lhsi/3fAmlHDITaKIwUD2DU1egyj5zDXVrZWkilMlSbcjKveCId9HxH6PPUborfFE?= =?utf-8?q?ae57FcbZgaifcV7fyf9vfRGYzUrO/8M3hqc+Np59czy1oz+sKhDgZyK+1AUvox/F8?= =?utf-8?q?VME2iYigUo1Zdq4SlRSCcnUs69vguJq2yg9T6Q8zeVRj8YbV58GVyUNt/uoVSsUQD?= =?utf-8?q?AtZotC8x5d/bURDRu+wINC+ssPmVLj6RHqIMNFaw46r7f4lMw/Sh9A43BIH2k2QDr?= =?utf-8?q?3VZlI8/0YGykOA8OI3FdClrX7ZpmsKy0Xw5kw+JMkZ0vlmBuPqcyMFkr/pk8BKTZw?= =?utf-8?q?Rppm4WBdlH1HqTEjJjq+IQjO4Kv8ytFvhh1G3M0/dDhsxumWzsAU24kHxuZR4gTeV?= =?utf-8?q?g5H3+EPgthJgGiADzlyDh5QZzYMObncJf+/DLXuZW+u9Bkt+COtavE+eVnY5sbJDC?= =?utf-8?q?Ocbh7Clo4w43+pVc+l+C8xwbztl1V0ym+6+NyAP9dEzoWWEyoNZlJM4keGrgZyHOz?= =?utf-8?q?M+kpC0r6HWJDkttouGAhe6vnRxTtfFlPS0sTEVKEkWT2qOCrRamUGJhHvlluntQPy?= =?utf-8?q?QgP1fqGOwk1mOxMn2AIop0CxUkgkcFo0eZflgGjzCBqGyUJXJ7UR18Anww1nf/yoN?= =?utf-8?q?jQQDJ6y0dr545dn+qTBsFxi8Alt2Sh8Mp1FYzeiKCG07ZuZUhMQH6HnbsBCWp6XW9?= =?utf-8?q?h4wVk5heetjKLIgh26L/t8TWF7oL0J8JwC2k/AlYpN2peo8ImAt2+BJCYo9duA2Ax?= =?utf-8?q?UkSORCONevKx4cK0C98WiG/p2QkcItM3vOxD+Glu1bWtfZtLC4LG+0HgIzLA+wdIs?= =?utf-8?q?4yqa2bNGjxCuQS0NCMCU1zoz6lFmsCnIdD733kufDezh37XV3D7fE2zB3ajrWlrle?= =?utf-8?q?tk8TpRq0cKYS8sJMCNyVG17E+bsBK+BCRd4Pr0dPrzB5X6JcohjTIQ2Jx1RieDLyj?= =?utf-8?q?5cy6xLA+s2QnM7MUcOZTmeVtNpRNHnaFcXm74LwOKQlXI6ctKeTJPRezjVOwtjqry?= =?utf-8?q?poeCCWm03VdekJl568mz6ky1yCoTlv4D6jlXsYMNmXDHpMHtBzlmbc/aNoCr7kc1C?= =?utf-8?q?8+ts2fZ5bI605+Kp1wu3RqKId0aVj5ZU/NBF/vyLDqs6b1m4UXGgWKm1KtjuBuzbK?= =?utf-8?q?bZAH8iRGPQ+nNA47uo1UER0yku3Ich7cCaJ3FwAZMLyrMR8hxAfHPWBfBematvHoM?= =?utf-8?q?xP2P+G5yHqKy3Q18aQHZ3PoWD0lFMd4qvIg=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR11MB5373.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(7416014)(366016)(1800799024); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?LiAuNZGV9D1xosQns0IVXvfdBsjt?= =?utf-8?q?QIL6KG8QKNu+C33ew9YBy/u5CRvO00MX8zZnB2RNik1pDL1OglHLBGvNV1psllHdT?= =?utf-8?q?xwTA8JiY1Su1VfimovpKDKUbGWh0oZ6LmOMj2zd080cDSbSkdkj3J/OV9rTY/d++I?= =?utf-8?q?z+IUonF+IVTOPtp33j5mSn7T2eQQyhQKVvwW0f6glxynrGfe6J2Z5XtNk7NTwijXU?= =?utf-8?q?+ipw6yyHOUOSvHupdtCVwGWN4JGiWvTolTI93YTBAe4o5hhQ+YLl0NlwIL9fGTt6n?= =?utf-8?q?hBGvJwrrxXH7tSiSxWqJyNdiI526yfjq7NsA7zECGxCNvl5z2gl4R0oWow6T0VxR6?= =?utf-8?q?HsAOVDYnMaMal/3D6ALfB86MjrHod/6rsSnX/Ij8zXm5E1AKAc6uPjCiCCUZcu/SE?= =?utf-8?q?0hhwvkgQGgeMXdpSAP2fH1FhGH5pOs/Ts8+hN9l20b3iobSNB8898pHPSvQdRijwD?= =?utf-8?q?W8qWGDeUw3nj+mHMjyKsEl1Kp3iNMUMDMKzQJdVtTv+nE1DootJWmRJD4TxLSPq3g?= =?utf-8?q?rctKOIBCBqItpS/BpfNOCLhlAdzJDbrJJTzeEftqe/rkUlL6Yd7L6FzVihMVBCUO1?= =?utf-8?q?7IC2lvJzL1/foExoBALoXLBCh6iKeDu3qEfpMv6gYj6mKmXcJ7HZoj7MWSzRtlKPZ?= =?utf-8?q?Q0QXoeSlHGUO8eIlboGmyVISsaPJscJyOCmCkpKDwc/d1uERiRkMt+ScXBK1GiTHL?= =?utf-8?q?LJTStWETBEbrLqvIW27vSrLz54AkIvze9QBmmx7enBDbiNJlHloS9XXbb4zD+XzA/?= =?utf-8?q?jyKYN6tlqzQet49xMhZdL1HyCTpR1mHkhsdmscIWENMJXydbYySq2TabO/DpJWjpl?= =?utf-8?q?rezrRpxVxlpdj1U43AQclroIW5xrCpNt3SRP2Z/nDFGG7rkMxPO0UvmIhllc5OV4N?= =?utf-8?q?3IK0h8HxPQDLlZUTskAov315DnIL3iHFZYDvnHtqp3fgIdxrj+/x864XwkCEzpI0O?= =?utf-8?q?vudK3CFVan9s0MIHYXvfGLz3pb3sz52olACuV/EsKLt68YFZb5cSNsg7lC1qz7tdq?= =?utf-8?q?jiUApVePVHY0MWKEp88vvYXJsam/U0cASGdXiQR2/3akNus2Bfu6JTxvvUnL1lj0c?= =?utf-8?q?qY+ga2Fkqj70Ncf95SbtVtAIyWwioLsaIfM2KHERSOdIw5tP2TORXSsjfOq3CTbsE?= =?utf-8?q?iz2qox+f+zs9aTSIIVwp/bCD9O55lj6Yi+6i79pMeJKp+OWOAQ3wwobcESCfOkK98?= =?utf-8?q?2A0qRgGlLt9s7zkyhAOYF8N6IeU9ktV3vAZpyzPBGR53RoL4oyLdDW61CpiupM60Q?= =?utf-8?q?Jt6RsiELkjtuRjcKjzZBrqwPuioH75UVo22HtxbEMkm4T0eUn/pdkqi1Q4dq1B3dh?= =?utf-8?q?eXfExeLfxuLEo3eV18MBjliKKB/uN/cGIpvC6f2ZveLiXmBgXhhRznXmIm/QczHVy?= =?utf-8?q?HRQbg/1u6APjnM8Fe2iKN4z4Ov/i29ZA3DrVKZYKvtg92Kzy0i7RnoQ8czTZR7Uzr?= =?utf-8?q?vQ0FIit1kmWrc5k5w8PozRHK/R2cd6RwVBNXeW1pYNMv/R6M7p5js6Rn6rzLCGmEm?= =?utf-8?q?ciUF9FwTH0C7pkB2NbFKNM5p4ZwkTOfGiw=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 9b78aa7c-4d30-4d61-7f83-08dcc3911c1c X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2024 16:31:59.1501 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 5YJXRjQd6R4+KI5myZ5RYGTo0IgzIoDKqxbkKvMn8InqvonpKjBOjDeXE6nl+wkku70JhRnedXuF2kYhIdlcPNaW0AsRghvvsaDJlbGHNss= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR11MB6026 X-OriginatorOrg: intel.com X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Accel minor management is based on DRM (and is also using struct drm_minor internally), since DRM is using XArray for minors, it makes sense to also convert accel. As the two implementations are identical (only difference being the underlying xarray), move the accel_minor_* functionality to DRM. Acked-by: James Zhu Signed-off-by: Michał Winiarski --- drivers/accel/drm_accel.c | 110 +++------------------------------ drivers/gpu/drm/drm_drv.c | 66 ++++++++++---------- drivers/gpu/drm/drm_file.c | 2 +- drivers/gpu/drm/drm_internal.h | 4 -- include/drm/drm_accel.h | 18 +----- include/drm/drm_file.h | 5 ++ 6 files changed, 47 insertions(+), 158 deletions(-) diff --git a/drivers/accel/drm_accel.c b/drivers/accel/drm_accel.c index 16c3edb8c46ee..aa826033b0ceb 100644 --- a/drivers/accel/drm_accel.c +++ b/drivers/accel/drm_accel.c @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include @@ -18,8 +18,7 @@ #include #include -static DEFINE_SPINLOCK(accel_minor_lock); -static struct idr accel_minors_idr; +DEFINE_XARRAY_ALLOC(accel_minors_xa); static struct dentry *accel_debugfs_root; @@ -117,99 +116,6 @@ void accel_set_device_instance_params(struct device *kdev, int index) kdev->type = &accel_sysfs_device_minor; } -/** - * accel_minor_alloc() - Allocates a new accel minor - * - * This function access the accel minors idr and allocates from it - * a new id to represent a new accel minor - * - * Return: A new id on success or error code in case idr_alloc failed - */ -int accel_minor_alloc(void) -{ - unsigned long flags; - int r; - - spin_lock_irqsave(&accel_minor_lock, flags); - r = idr_alloc(&accel_minors_idr, NULL, 0, ACCEL_MAX_MINORS, GFP_NOWAIT); - spin_unlock_irqrestore(&accel_minor_lock, flags); - - return r; -} - -/** - * accel_minor_remove() - Remove an accel minor - * @index: The minor id to remove. - * - * This function access the accel minors idr and removes from - * it the member with the id that is passed to this function. - */ -void accel_minor_remove(int index) -{ - unsigned long flags; - - spin_lock_irqsave(&accel_minor_lock, flags); - idr_remove(&accel_minors_idr, index); - spin_unlock_irqrestore(&accel_minor_lock, flags); -} - -/** - * accel_minor_replace() - Replace minor pointer in accel minors idr. - * @minor: Pointer to the new minor. - * @index: The minor id to replace. - * - * This function access the accel minors idr structure and replaces the pointer - * that is associated with an existing id. Because the minor pointer can be - * NULL, we need to explicitly pass the index. - * - * Return: 0 for success, negative value for error - */ -void accel_minor_replace(struct drm_minor *minor, int index) -{ - unsigned long flags; - - spin_lock_irqsave(&accel_minor_lock, flags); - idr_replace(&accel_minors_idr, minor, index); - spin_unlock_irqrestore(&accel_minor_lock, flags); -} - -/* - * Looks up the given minor-ID and returns the respective DRM-minor object. The - * refence-count of the underlying device is increased so you must release this - * object with accel_minor_release(). - * - * The object can be only a drm_minor that represents an accel device. - * - * As long as you hold this minor, it is guaranteed that the object and the - * minor->dev pointer will stay valid! However, the device may get unplugged and - * unregistered while you hold the minor. - */ -static struct drm_minor *accel_minor_acquire(unsigned int minor_id) -{ - struct drm_minor *minor; - unsigned long flags; - - spin_lock_irqsave(&accel_minor_lock, flags); - minor = idr_find(&accel_minors_idr, minor_id); - if (minor) - drm_dev_get(minor->dev); - spin_unlock_irqrestore(&accel_minor_lock, flags); - - if (!minor) { - return ERR_PTR(-ENODEV); - } else if (drm_dev_is_unplugged(minor->dev)) { - drm_dev_put(minor->dev); - return ERR_PTR(-ENODEV); - } - - return minor; -} - -static void accel_minor_release(struct drm_minor *minor) -{ - drm_dev_put(minor->dev); -} - /** * accel_open - open method for ACCEL file * @inode: device inode @@ -227,7 +133,7 @@ int accel_open(struct inode *inode, struct file *filp) struct drm_minor *minor; int retcode; - minor = accel_minor_acquire(iminor(inode)); + minor = drm_minor_acquire(&accel_minors_xa, iminor(inode)); if (IS_ERR(minor)) return PTR_ERR(minor); @@ -246,7 +152,7 @@ int accel_open(struct inode *inode, struct file *filp) err_undo: atomic_dec(&dev->open_count); - accel_minor_release(minor); + drm_minor_release(minor); return retcode; } EXPORT_SYMBOL_GPL(accel_open); @@ -257,7 +163,7 @@ static int accel_stub_open(struct inode *inode, struct file *filp) struct drm_minor *minor; int err; - minor = accel_minor_acquire(iminor(inode)); + minor = drm_minor_acquire(&accel_minors_xa, iminor(inode)); if (IS_ERR(minor)) return PTR_ERR(minor); @@ -274,7 +180,7 @@ static int accel_stub_open(struct inode *inode, struct file *filp) err = 0; out: - accel_minor_release(minor); + drm_minor_release(minor); return err; } @@ -290,15 +196,13 @@ void accel_core_exit(void) unregister_chrdev(ACCEL_MAJOR, "accel"); debugfs_remove(accel_debugfs_root); accel_sysfs_destroy(); - idr_destroy(&accel_minors_idr); + WARN_ON(!xa_empty(&accel_minors_xa)); } int __init accel_core_init(void) { int ret; - idr_init(&accel_minors_idr); - ret = accel_sysfs_init(); if (ret < 0) { DRM_ERROR("Cannot create ACCEL class: %d\n", ret); diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index ae675a588a1df..7e0fa5a2a3182 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -55,7 +55,7 @@ MODULE_AUTHOR("Gareth Hughes, Leif Delgass, José Fonseca, Jon Smirl"); MODULE_DESCRIPTION("DRM shared core routines"); MODULE_LICENSE("GPL and additional rights"); -static DEFINE_XARRAY_ALLOC(drm_minors_xa); +DEFINE_XARRAY_ALLOC(drm_minors_xa); /* * If the drm core fails to init for whatever reason, @@ -83,6 +83,18 @@ DEFINE_STATIC_SRCU(drm_unplug_srcu); * registered and unregistered dynamically according to device-state. */ +static struct xarray *drm_minor_get_xa(enum drm_minor_type type) +{ + if (type == DRM_MINOR_PRIMARY || type == DRM_MINOR_RENDER) + return &drm_minors_xa; +#if IS_ENABLED(CONFIG_DRM_ACCEL) + else if (type == DRM_MINOR_ACCEL) + return &accel_minors_xa; +#endif + else + return ERR_PTR(-EOPNOTSUPP); +} + static struct drm_minor **drm_minor_get_slot(struct drm_device *dev, enum drm_minor_type type) { @@ -106,18 +118,18 @@ static void drm_minor_alloc_release(struct drm_device *dev, void *data) put_device(minor->kdev); - if (minor->type == DRM_MINOR_ACCEL) - accel_minor_remove(minor->index); - else - xa_erase(&drm_minors_xa, minor->index); + xa_erase(drm_minor_get_xa(minor->type), minor->index); } -#define DRM_MINOR_LIMIT(t) ({ typeof(t) _t = (t); XA_LIMIT(64 * _t, 64 * _t + 63); }) +#define DRM_MINOR_LIMIT(t) ({ \ + typeof(t) _t = (t); \ + _t == DRM_MINOR_ACCEL ? XA_LIMIT(0, ACCEL_MAX_MINORS) : XA_LIMIT(64 * _t, 64 * _t + 63); \ +}) static int drm_minor_alloc(struct drm_device *dev, enum drm_minor_type type) { struct drm_minor *minor; - int index, r; + int r; minor = drmm_kzalloc(dev, sizeof(*minor), GFP_KERNEL); if (!minor) @@ -126,18 +138,11 @@ static int drm_minor_alloc(struct drm_device *dev, enum drm_minor_type type) minor->type = type; minor->dev = dev; - if (type == DRM_MINOR_ACCEL) { - r = accel_minor_alloc(); - index = r; - } else { - r = xa_alloc(&drm_minors_xa, &index, NULL, DRM_MINOR_LIMIT(type), GFP_KERNEL); - } - + r = xa_alloc(drm_minor_get_xa(type), &minor->index, + NULL, DRM_MINOR_LIMIT(type), GFP_KERNEL); if (r < 0) return r; - minor->index = index; - r = drmm_add_action_or_reset(dev, drm_minor_alloc_release, minor); if (r) return r; @@ -176,16 +181,12 @@ static int drm_minor_register(struct drm_device *dev, enum drm_minor_type type) goto err_debugfs; /* replace NULL with @minor so lookups will succeed from now on */ - if (minor->type == DRM_MINOR_ACCEL) { - accel_minor_replace(minor, minor->index); - } else { - entry = xa_store(&drm_minors_xa, minor->index, minor, GFP_KERNEL); - if (xa_is_err(entry)) { - ret = xa_err(entry); - goto err_debugfs; - } - WARN_ON(entry); + entry = xa_store(drm_minor_get_xa(type), minor->index, minor, GFP_KERNEL); + if (xa_is_err(entry)) { + ret = xa_err(entry); + goto err_debugfs; } + WARN_ON(entry); DRM_DEBUG("new minor registered %d\n", minor->index); return 0; @@ -204,10 +205,7 @@ static void drm_minor_unregister(struct drm_device *dev, enum drm_minor_type typ return; /* replace @minor with NULL so lookups will fail from now on */ - if (minor->type == DRM_MINOR_ACCEL) - accel_minor_replace(NULL, minor->index); - else - xa_store(&drm_minors_xa, minor->index, NULL, GFP_KERNEL); + xa_store(drm_minor_get_xa(type), minor->index, NULL, GFP_KERNEL); device_del(minor->kdev); dev_set_drvdata(minor->kdev, NULL); /* safety belt */ @@ -223,15 +221,15 @@ static void drm_minor_unregister(struct drm_device *dev, enum drm_minor_type typ * minor->dev pointer will stay valid! However, the device may get unplugged and * unregistered while you hold the minor. */ -struct drm_minor *drm_minor_acquire(unsigned int minor_id) +struct drm_minor *drm_minor_acquire(struct xarray *minor_xa, unsigned int minor_id) { struct drm_minor *minor; - xa_lock(&drm_minors_xa); - minor = xa_load(&drm_minors_xa, minor_id); + xa_lock(minor_xa); + minor = xa_load(minor_xa, minor_id); if (minor) drm_dev_get(minor->dev); - xa_unlock(&drm_minors_xa); + xa_unlock(minor_xa); if (!minor) { return ERR_PTR(-ENODEV); @@ -1024,7 +1022,7 @@ static int drm_stub_open(struct inode *inode, struct file *filp) DRM_DEBUG("\n"); - minor = drm_minor_acquire(iminor(inode)); + minor = drm_minor_acquire(&drm_minors_xa, iminor(inode)); if (IS_ERR(minor)) return PTR_ERR(minor); diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c index e8a841e709342..dab8c8623eb07 100644 --- a/drivers/gpu/drm/drm_file.c +++ b/drivers/gpu/drm/drm_file.c @@ -356,7 +356,7 @@ int drm_open(struct inode *inode, struct file *filp) struct drm_minor *minor; int retcode; - minor = drm_minor_acquire(iminor(inode)); + minor = drm_minor_acquire(&drm_minors_xa, iminor(inode)); if (IS_ERR(minor)) return PTR_ERR(minor); diff --git a/drivers/gpu/drm/drm_internal.h b/drivers/gpu/drm/drm_internal.h index 23c99803af44c..1705bfc90b1e7 100644 --- a/drivers/gpu/drm/drm_internal.h +++ b/drivers/gpu/drm/drm_internal.h @@ -80,10 +80,6 @@ void drm_prime_destroy_file_private(struct drm_prime_file_private *prime_fpriv); void drm_prime_remove_buf_handle(struct drm_prime_file_private *prime_fpriv, uint32_t handle); -/* drm_drv.c */ -struct drm_minor *drm_minor_acquire(unsigned int minor_id); -void drm_minor_release(struct drm_minor *minor); - /* drm_managed.c */ void drm_managed_release(struct drm_device *dev); void drmm_add_final_kfree(struct drm_device *dev, void *container); diff --git a/include/drm/drm_accel.h b/include/drm/drm_accel.h index f4d3784b1dce0..8867ce0be94cd 100644 --- a/include/drm/drm_accel.h +++ b/include/drm/drm_accel.h @@ -51,11 +51,10 @@ #if IS_ENABLED(CONFIG_DRM_ACCEL) +extern struct xarray accel_minors_xa; + void accel_core_exit(void); int accel_core_init(void); -void accel_minor_remove(int index); -int accel_minor_alloc(void); -void accel_minor_replace(struct drm_minor *minor, int index); void accel_set_device_instance_params(struct device *kdev, int index); int accel_open(struct inode *inode, struct file *filp); void accel_debugfs_init(struct drm_device *dev); @@ -73,19 +72,6 @@ static inline int __init accel_core_init(void) return 0; } -static inline void accel_minor_remove(int index) -{ -} - -static inline int accel_minor_alloc(void) -{ - return -EOPNOTSUPP; -} - -static inline void accel_minor_replace(struct drm_minor *minor, int index) -{ -} - static inline void accel_set_device_instance_params(struct device *kdev, int index) { } diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h index ab230d3af138d..8c0030c773081 100644 --- a/include/drm/drm_file.h +++ b/include/drm/drm_file.h @@ -45,6 +45,8 @@ struct drm_printer; struct device; struct file; +extern struct xarray drm_minors_xa; + /* * FIXME: Not sure we want to have drm_minor here in the end, but to avoid * header include loops we need it here for now. @@ -434,6 +436,9 @@ static inline bool drm_is_accel_client(const struct drm_file *file_priv) void drm_file_update_pid(struct drm_file *); +struct drm_minor *drm_minor_acquire(struct xarray *minors_xa, unsigned int minor_id); +void drm_minor_release(struct drm_minor *minor); + int drm_open(struct inode *inode, struct file *filp); int drm_open_helper(struct file *filp, struct drm_minor *minor); ssize_t drm_read(struct file *filp, char __user *buffer,