From patchwork Tue Dec 5 01:22:08 2023 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: 13479277 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 84239C4167B for ; Tue, 5 Dec 2023 01:22:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0D79A10E457; Tue, 5 Dec 2023 01:22:48 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0F5C710E45B; Tue, 5 Dec 2023 01:22:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701739366; x=1733275366; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=QycBI7Kt9PgTyJxaiH/+LWXtKXKuLCo9OVwQRLqdWtI=; b=gSp6JM2rsgP7JkjG/9Zz4pfsxBaNRI7wjJ+rjwaA8plHTxQm7P3u6uXi N3+bSHqdRoPmJw6YkxgkL+Gwwytvqpd/5FQH4NO2b7d42eZW1VaIBzBKJ 0+6traldpRtdEfBwRLlryHrWoFF/Q4lT161iHVCJraswzVYumWFeBLl+2 KGvXVhOeXArgJTSlDuLws052aRMbl7FJhnyG+vZpD4pYcGneuVjmeFfDa 7brz/rwF739eVQbVManm2QkIUmZnKx5/fVkS7US912gD2SoQEWwPaqQCD SanUrYjuNKwgRsmkKNMEEsLLy1kS9yJLVbsFlamb2CkMuPVBAZhimv72F w==; X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="393558948" X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="scan'208";a="393558948" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2023 17:22:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="scan'208";a="12157625" Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by orviesa002.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 04 Dec 2023 17:22:45 -0800 Received: from fmsmsx612.amr.corp.intel.com (10.18.126.92) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Mon, 4 Dec 2023 17:22:44 -0800 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx612.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Mon, 4 Dec 2023 17:22:44 -0800 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) 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.34 via Frontend Transport; Mon, 4 Dec 2023 17:22:44 -0800 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (104.47.59.169) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.34; Mon, 4 Dec 2023 17:22:43 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=F7nja0BmgCNTAti3zneL+cpjtBNKMXX15raGYyVQSMHjiy53RAJ5gzBRVCT8aGJDj0skEm536fFXbl9SqBVcVfDWwKtAPneAg+I7Onr6Kl0DIQCoNjZnzeoqiHrmztfHabeJSSfbVchn5ibj4KmPE2N3+qoX0m7WvxgvcR84IfWav/UA4t+MKvyKc8qGqXNsJwrRtO7M27dUM51uVfA+n7c6ANmv/yp8x0cetm6Mvtv4G4DT2O2IDiJ+fwF0XxsdvOr62BJDk518uITS92/1DMaSiVxlPk2MiUwa3sGKvNsYES0cMoxLt00CchJq4PXI/ntxwra4cx31WUtaS7RdtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=ZmFrd6XZVfmcX6t5o754wGjAQjnYdG1Cx10L3HP9BJc=; b=Q4EUpqX6kWRLGuvt3/KUYwyGKQvU0YLyHf6vhlm6XVXnKDn0x6U2UbWkxKrPbR69jjFb+QhTqvAPq11DVcQ/15j5lYd6HMM87Vw4LvazkSGP36DkLhBTsPYyiBpx9xSpGVaJaMu2O9A7LW6V8kTS5FR6wqohcs3RWumJ6BDRvV+6oEcUEegq4XWYTKDWe2tJ68Ra4QV25yyfkzQtcMMu0TS7kR2xFCnVl4keOtNWRbLYBqJTPud3xlDKayGxmtqEGJxCyPrUSuNZZZUuILYX5qpn1Tctr9vjyAf18x9F0Dh4OXEADFU/mEMKFG979O+dg0GHBKC/LD2j+/WMTOgpHw== 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 SJ2PR11MB7618.namprd11.prod.outlook.com (2603:10b6:a03:4cc::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.33; Tue, 5 Dec 2023 01:22:42 +0000 Received: from DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::f105:47dd:6794:6821]) by DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::f105:47dd:6794:6821%4]) with mapi id 15.20.7046.033; Tue, 5 Dec 2023 01:22:42 +0000 From: =?utf-8?q?Micha=C5=82_Winiarski?= To: , , Subject: [PATCH v2 1/3] drm/managed: Add drmm_release_action Date: Tue, 5 Dec 2023 02:22:08 +0100 Message-ID: <20231205012210.1491532-2-michal.winiarski@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231205012210.1491532-1-michal.winiarski@intel.com> References: <20231205012210.1491532-1-michal.winiarski@intel.com> X-ClientProxiedBy: FR0P281CA0001.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:15::6) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR11MB5373:EE_|SJ2PR11MB7618:EE_ X-MS-Office365-Filtering-Correlation-Id: e817bebe-8eed-4671-5363-08dbf530ad58 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6bu8NWCaOVbUsb+fY2BiwyUXmPvzdaTUEEBFzyra2XZI9GpXJFgor9Ri0/94RpgF1PaPrtuH8NLbpcV1lWZ6JhLbvkLDbU3hjTGVlHcyPtyNqlZbntv5aEBSkMusb5y7plI979DI0wkC1dTzytrty1Zb9jfQJAu2DrB9GknL5jdk06nHZ74xEe81NuBTxUtc4DKor/Ho46qyhMPhfFhQWv6h6OYXkkgxAFTTXK5cmc/kV29U3jtUbz5dMoRfkxaplbOcLv5P9wZ8YtHHecSzUIiRsDDh6PYC4v7PmIN/t5GonaEgy0uHB8heJHfoVsS30ipP8i5GkNeMepHDIXcwCVioBTWPelVASCmpKDKY8VqMVSEdKPrz8S/u45yz4D4Bha0s+kL5I4FFtuh+VWCJVVVAjIR4jgCL+usv1AoLivs8rF0fMjdHE6XlCIQc1aI4gHrJfxCQSu0CoZ6Zx3KY2Sm9x6VbzJYQTwUnbuHthIrbIHWfUupFBu3PAobRiXismvNl54WxEeeGxA0YASgOkoaLafiFO4wS89lQTp3ZbmXlkXU+asG9BuB8fBiRXaj9 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:(13230031)(136003)(396003)(39860400002)(346002)(376002)(366004)(230922051799003)(451199024)(64100799003)(186009)(1800799012)(5660300002)(86362001)(4326008)(8676002)(8936002)(2906002)(7416002)(41300700001)(6512007)(36756003)(1076003)(6506007)(2616005)(82960400001)(6666004)(83380400001)(6486002)(478600001)(26005)(38100700002)(316002)(54906003)(66476007)(66556008)(66946007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?FXfWYd/UXCAsyix+EBirta8DfilQ?= =?utf-8?q?P5VTwaaP6wblnWppQcyrUP0BE5/RZ6wxgRyiK6xSci1PZIqXIzgzjX7xzr/GTxZ0P?= =?utf-8?q?NBmSsfbn5O+Noy4G9rFSIhGLiDrJuTb5KgBxQI5wz3YzxMM1LbjzuvIbrS7XRlSRW?= =?utf-8?q?36vDHfBspuPVrsvqlmd4G8Z4cf4vQQoqw5HQvEi0BwiYa6wBncqXKOmZhuIcWLWxs?= =?utf-8?q?96Ami4TK2Hiua2+d/Zxk2rnC13f01B+tnky0Br47pdGJpqhZ0BoXrrMzoRFYjcU2+?= =?utf-8?q?ljyxHgtyeategxTQpYWLdDogju/R9DZCi0wgQd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5WRkN4wcnn?= =?utf-8?q?QpZXXt6ojc/dmY7RWYkiYWVDMoL3Z5Vv/hO/LaFO1r4qI46JQAKtKZpoLkudD6prE?= =?utf-8?q?OseebuOrrzz63CV/eppR/zzWuvlFt+XP2iOLh+Lc43/Dr8z5dUcAgU8T547SuqlFe?= =?utf-8?q?ujygiLunvA00+PL61T+Ll6h5hqHPDarpc5WLJLaJmpFndO+dzXP7qPgUJ/WtUuy1j?= =?utf-8?q?L9P3IBFkbTAlf7hN3gaeVaDJ4RuP5cgR8oAovOls/kZ0U9yhxNmqtwyUy1dfpM6XL?= =?utf-8?q?z2JAcMHKeH0jT/aJTbH4j0tnHgX+yR9qkzk7rT7vPcPXZPHQXBHdcwBjf3jtO9+yE?= =?utf-8?q?nph0efITcW4xQIo1f2c/gCRD6RLgJ1Y+UQ=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: e817bebe-8eed-4671-5363-08dbf530ad58 X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Dec 2023 01:22:41.9900 (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: stmUWHLHEIj1LzVZW/RIG/Xc/pQte28+MPBdEtctp5RaHGOelqjQIONDUBo9UrCTwMnNrd5/fKP9pkBUfYKoFoqK5e4FKj0jeJzD7GFa1Lw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR11MB7618 X-OriginatorOrg: intel.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Micha=C5=82_Winiarski?= , =?utf-8?q?Ma=C3=ADra_Canal?= , Javier Martinez Canillas , Maxime Ripard , Thomas Zimmermann , Rodrigo Vivi , Michal Wajdeczko Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Similar to devres equivalent, it allows to call the "release" action directly and remove the resource from the managed resources list. Signed-off-by: MichaƂ Winiarski --- drivers/gpu/drm/drm_managed.c | 39 +++++++++++++++++++++++++++++++++++ include/drm/drm_managed.h | 4 ++++ 2 files changed, 43 insertions(+) diff --git a/drivers/gpu/drm/drm_managed.c b/drivers/gpu/drm/drm_managed.c index bcd111404b128..7646f67bda4e4 100644 --- a/drivers/gpu/drm/drm_managed.c +++ b/drivers/gpu/drm/drm_managed.c @@ -176,6 +176,45 @@ int __drmm_add_action_or_reset(struct drm_device *dev, } EXPORT_SYMBOL(__drmm_add_action_or_reset); +/** + * drmm_release_action - release a managed action from a &drm_device + * @dev: DRM device + * @action: function which would be called when @dev is released + * @data: opaque pointer, passed to @action + * + * This function calls the @action previously added by drmm_add_action() + * immediately. + * The @action is removed from the list of cleanup actions for @dev, + * which means that it won't be called in the final drm_dev_put(). + */ +void drmm_release_action(struct drm_device *dev, + drmres_release_t action, + void *data) +{ + struct drmres *dr_match = NULL, *dr; + unsigned long flags; + + spin_lock_irqsave(&dev->managed.lock, flags); + list_for_each_entry_reverse(dr, &dev->managed.resources, node.entry) { + if (dr->node.release == action) { + if (!data || (data && *(void **)dr->data == data)) { + dr_match = dr; + del_dr(dev, dr_match); + break; + } + } + } + spin_unlock_irqrestore(&dev->managed.lock, flags); + + if (WARN_ON(!dr_match)) + return; + + action(dev, data); + + free_dr(dr_match); +} +EXPORT_SYMBOL(drmm_release_action); + /** * drmm_kmalloc - &drm_device managed kmalloc() * @dev: DRM device diff --git a/include/drm/drm_managed.h b/include/drm/drm_managed.h index ad08f834af408..f547b09ca0239 100644 --- a/include/drm/drm_managed.h +++ b/include/drm/drm_managed.h @@ -45,6 +45,10 @@ int __must_check __drmm_add_action_or_reset(struct drm_device *dev, drmres_release_t action, void *data, const char *name); +void drmm_release_action(struct drm_device *dev, + drmres_release_t action, + void *data); + void *drmm_kmalloc(struct drm_device *dev, size_t size, gfp_t gfp) __malloc; /**