Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp865901pxb; Fri, 22 Apr 2022 13:00:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFy9jpms4EFj/97eJq6RC7Oz/Ub2/RTbvUamZayrVa298benBYS1sAuvqDC5EK9uJgYfgv X-Received: by 2002:a05:6a00:194b:b0:4fb:4ac:de57 with SMTP id s11-20020a056a00194b00b004fb04acde57mr6534162pfk.17.1650657613815; Fri, 22 Apr 2022 13:00:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650657613; cv=none; d=google.com; s=arc-20160816; b=XZXA/mR6tcZLjPWNZxtMssi+vhf2gMqOQOMb/OeartyhgCsbl1HICK5OuM1yl0+rLr B51PbPj1bCypbp6AzUyhrTERtv4gZjQ+R5VJsc5gWMw0+PfS7+txBEcbarbmNvSRqaK1 AQLZTflvRf5hvJGxC5xymCYOSPP2mD37Gtm59RGctVD1yh3RTvKGntW7voclQgJ2WGty PkPNleVZeLfAGU8YtIEWWiafyxgCY3s1bVlhR3D6+vpQySCtA04V5+/JbFiR/iMpfBSy H5xBHe1XYOZjg/c1RsC36avanhWXWdx0ck0YGvkn/LAAWKJINGCeHPnRcRcnB4qsY4Dn COzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ITV+N+0zKejsc3U/xp1Kz9EkmLM2/I64DUATFR3S+dY=; b=ByQBc5UBvW5fTw/77S/RqBrhQsi5Jb+tfxuKqlOA8U9gxjcIncspWeR/6SMAIYnBAr mzWDhMynRQVh0ItLiUTr3ys4NaxsPwoPiuUvQKCUtd5vQb7YaEHxhSV8zoriiZxhCSeh WQyqE+7B7gVQuufFEfFcXvvy6iDYEeQdF9QZb/YwuafjFj+5YjL/rpWSsYXjuMtt/Gcr QOlWrtsJeit79vMOJHh3SROBQoMOvh+xop3l2mf5VHugE3vq/+FxH3tJx44Q/LSJpojy btLBkyAmhgUqWFLGQ3Cx2jnMs4/mUryaN6sIRTjPZ/K7A6PFOrsnTKNbev2amgsvCHHL J0mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=L3LDK4kA; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id s13-20020a170902ea0d00b0015898563942si9746442plg.445.2022.04.22.13.00.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 13:00:13 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=L3LDK4kA; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6F96C189BEB; Fri, 22 Apr 2022 11:58:35 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1391581AbiDUSxI (ORCPT + 99 others); Thu, 21 Apr 2022 14:53:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1391550AbiDUSww (ORCPT ); Thu, 21 Apr 2022 14:52:52 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BC637669 for ; Thu, 21 Apr 2022 11:50:02 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: bbeckett) with ESMTPSA id DDAB01F45E2A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1650567001; bh=xMYv7v3aHxlEQIE2QtkE00E2gW9W0dS8yiKhilZWusw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L3LDK4kA+ymOIUdNUTRi6UZkTRbrTvCeAaMeJbkg0ELpFk7Ck5/dfKmsLbfiVQjUx mWg9B0I7wcDw57NezwYJfr7lB8hApF6bQNKllY1KYSyi/JHta4G8ha4KPTim0ghnOr 9CkPVlKrbtcGzpXX0uosBvWtDhT4soVBW8uFmp7AonvNMRb2h56LFKZ4FCJ47Dq9gZ 3Mts6LNhPH4lZLdZdR1K5QirfIICBJIK29IckQiUq/PdwfWr7DoE1tnmPN3rCsPcP9 SO+4NnyYYQtViuvyi7qjAK2oKHNw3S8P63rDPUm34AvH8LebL/UMMlclhIYkD1QNQ9 YflyE6IJUyKwQ== From: Robert Beckett To: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter Cc: Robert Beckett , Matthew Auld , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , linux-kernel@vger.kernel.org Subject: [PATCH v4 5/6] drm/i915: allow memory region creators to alloc and free the region Date: Thu, 21 Apr 2022 18:49:40 +0000 Message-Id: <20220421184941.428639-6-bob.beckett@collabora.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220421184941.428639-1-bob.beckett@collabora.com> References: <20220421184941.428639-1-bob.beckett@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org add callbacks for alloc and free. this allows region creators to allocate any extra storage they may require. Signed-off-by: Robert Beckett --- drivers/gpu/drm/i915/intel_memory_region.c | 16 +++++++++++++--- drivers/gpu/drm/i915/intel_memory_region.h | 2 ++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/i915/intel_memory_region.c b/drivers/gpu/drm/i915/intel_memory_region.c index e38d2db1c3e3..3da07a712f90 100644 --- a/drivers/gpu/drm/i915/intel_memory_region.c +++ b/drivers/gpu/drm/i915/intel_memory_region.c @@ -231,7 +231,10 @@ intel_memory_region_create(struct drm_i915_private *i915, struct intel_memory_region *mem; int err; - mem = kzalloc(sizeof(*mem), GFP_KERNEL); + if (ops->alloc) + mem = ops->alloc(); + else + mem = kzalloc(sizeof(*mem), GFP_KERNEL); if (!mem) return ERR_PTR(-ENOMEM); @@ -265,7 +268,10 @@ intel_memory_region_create(struct drm_i915_private *i915, if (mem->ops->release) mem->ops->release(mem); err_free: - kfree(mem); + if (mem->ops->free) + mem->ops->free(mem); + else + kfree(mem); return ERR_PTR(err); } @@ -288,7 +294,11 @@ void intel_memory_region_destroy(struct intel_memory_region *mem) GEM_WARN_ON(!list_empty_careful(&mem->objects.list)); mutex_destroy(&mem->objects.lock); - if (!ret) + if (ret) + return; + if (mem->ops->free) + mem->ops->free(mem); + else kfree(mem); } diff --git a/drivers/gpu/drm/i915/intel_memory_region.h b/drivers/gpu/drm/i915/intel_memory_region.h index 3d8378c1b447..048955b5429f 100644 --- a/drivers/gpu/drm/i915/intel_memory_region.h +++ b/drivers/gpu/drm/i915/intel_memory_region.h @@ -61,6 +61,8 @@ struct intel_memory_region_ops { resource_size_t size, resource_size_t page_size, unsigned int flags); + struct intel_memory_region *(*alloc)(void); + void (*free)(struct intel_memory_region *mem); }; struct intel_memory_region { -- 2.25.1