Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3541205iob; Sun, 1 May 2022 22:02:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxl4VrnTKHCQMcvrjfHPjeVx0hua2nM1ffKGiv3DDKiSy9uCbjjiTh4w0tEzARcDz+2ZyXm X-Received: by 2002:a17:90a:fa01:b0:1d9:4008:cffc with SMTP id cm1-20020a17090afa0100b001d94008cffcmr16332550pjb.141.1651467755929; Sun, 01 May 2022 22:02:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651467755; cv=none; d=google.com; s=arc-20160816; b=DCKGGojehv9DyaUlmvDgjywFgFaZ7h5l/+jMD/7uktFOfG/f9qps4CQoQvya9KjelA 48R13sCO9YZUhvy94E7CQQw4lyKX5KVEt2BgQXcyiq2j4J4arVVJ5KJOtZGoYfV3uNRg mgg5XfRyEj7Z0t4Bb0H9hy4BF+7Yh4ehsFbRjviXZRYKe/sazG6YU9kAyw//35ziz/Gd 4l13hQ1bOEBwoRS54D04mzvuOaOcPQGSJd36V47MCSFgd118rWHBbbxm0frXsjPCQCeE dDHkRaNTeI6KKsTwkza7fdUiZcEYyEUMSuhzc6YoPEHpnhUe0hizrwOuJ0owwqk47ta+ IcyQ== 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=R8YYWXGoBxbgCbsvWclZuIa9qz8orvBUSewVpMOTK5pyLUToAue3B/u0FtZ25pJwM6 CHbhezmZHKXOAkn64J7r/kQQ24xm6sW0LpFfM+0++zo0euojs/cByAZvla2tSe0W5qwX hy+KQeZ3LqJH76CzOrvLdmUsOWvZYlk/Nl4c2mT25mOqP/0mZzNc+ZEcknhqvQpKuc9E xoBKyQEb1ZDpazYjO80W0+ys06CZPAs1Nzy0LdSrBOQAqED5tMSr1uDabYaQfknOPjeI zDpSVMQzj4GgitKCi09pmGH9MvmHmz7splDC5GhbGOLJlTKQVHa3oao9opyh0aSr64MQ bdCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=GHE62b0z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e7-20020a170903240700b0015e6330c0ecsi10834871plo.330.2022.05.01.22.02.19; Sun, 01 May 2022 22:02:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=GHE62b0z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351738AbiD1UP4 (ORCPT + 99 others); Thu, 28 Apr 2022 16:15:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237519AbiD1UPq (ORCPT ); Thu, 28 Apr 2022 16:15:46 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB327C0D07 for ; Thu, 28 Apr 2022 13:12:30 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: bbeckett) with ESMTPSA id 731041F45C29 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1651176749; bh=xMYv7v3aHxlEQIE2QtkE00E2gW9W0dS8yiKhilZWusw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GHE62b0zXG9Zbb01yXl/9o1jKD7eRLGa7fZ8AoXiSWo8oc7nPRV2/oPeJhwcmcq/R MLDytWP8JD2Ht6ntoGla4eQf5SvTE6I3mYkP9Z+XYsPKWJ75BjAxK0dX2X9EWav+Oz rvrB1YRRD4SIgn5Elruhi4AOZ92Encsxdq1OzvKu6JWdLRQC+XC34bmozfekVFs/n+ pFY//SzkT8KabXz8Va6mEHqXWhLrCe3i712zSU7YM+Ws6lEHEzOjI438eAlIKbTdcm cEJDVNTPyVhd0EiH6aOS+MLDn9z4mPT5uq/XwC7h9Hfr/dKcTil+9Kbpnlby5FW2tf /MDmdaiTQ+Ogg== 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 v5 5/6] drm/i915: allow memory region creators to alloc and free the region Date: Thu, 28 Apr 2022 20:11:24 +0000 Message-Id: <20220428201125.412896-6-bob.beckett@collabora.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220428201125.412896-1-bob.beckett@collabora.com> References: <20220428201125.412896-1-bob.beckett@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, UNPARSEABLE_RELAY autolearn=ham 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