From patchwork Mon Apr 1 07:47:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 161520 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp134990jan; Mon, 1 Apr 2019 00:47:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqwTqWBaT53np3IwES7F4NWsNxsbklKlm1aCF8rP2AZa9zDdRZC1BQTDCjG9BByHS6y4Lcux X-Received: by 2002:a17:902:123:: with SMTP id 32mr62322977plb.187.1554104868694; Mon, 01 Apr 2019 00:47:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554104868; cv=none; d=google.com; s=arc-20160816; b=DoDPbTLNWV0NoPKdX6Z4R0yEUydZe1tG1g1pCIIcU24ZWvydKtJUHSMOT37ym6awtF Ka2Sxurv9o1cJ+Db8s8jGU1JrOljIDI5uiOvY5+696tsGvZk1/671cOPMq8p/Bb44wbR El/r8g89jYeUe9AMyW8njSDYJn4YWYngi74NpfB/Ya0DgWzgJcokTbh++jjTb0ckQI44 DXXN16+P+aPQKPlVIv2g2VLXDA5HhITWW6Ra0uB+Ojrf0esvQPDnNGHWPRZpQYEu+Lmo cT8jrADKlXjLrVf1x78F+9RhOwKLodSlVCpbUZ9YvPOGaMlfTr41oLKrEyqSYNUI6Vfj naMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Iqmyy0frGc7sVDuV1g+OXCIxMaTZ6r2+cyJVIwUF4BQ=; b=JQ29+KmtYyIJqpYXBJGC7mmRLqmUHDk2n4GfiJ9PjYsU9xmP2+sXsk0OSE+iBttdhB L1hMpz+mcAfIWrh+Lg+MAK1lgHAY9zMB7ZbgGmzBsshbHR5e5vjetyhv+S4CORabuYNf mZ7kbVGdtvn8DuDUVh+ny9+35qw03sSl5e5qNSWh3Q8RIPeerAfhDwivEVA+x7oVvHrj 8wOEzqg5DMKXIqb62KDoctD7PoZL3CNP8w/I92PV6UzBhzNNGgzzHq4+ZFVoVyMsbG0h EtC5DuOSGg1ow3n7J/4cwZ90tpseKbKLoaxLjeWYpAdanduCPkfeOPITaKNRTtgKjFWJ x30A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j133si8225763pgc.543.2019.04.01.00.47.48; Mon, 01 Apr 2019 00:47:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732064AbfDAHrr (ORCPT + 31 others); Mon, 1 Apr 2019 03:47:47 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:44439 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731769AbfDAHrq (ORCPT ); Mon, 1 Apr 2019 03:47:46 -0400 Received: by mail-pg1-f194.google.com with SMTP id i2so4312603pgj.11 for ; Mon, 01 Apr 2019 00:47:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Iqmyy0frGc7sVDuV1g+OXCIxMaTZ6r2+cyJVIwUF4BQ=; b=ofkWJAOs4CkUExVBHou6lKMTgrjBuH/H+hX3gAZC556UzSStvvm2ptPl7NV697OElA B9wM0flqMXv1GhUaPVuGApAIe4kuPMVouh/c7URFB9LGAF+jzzL7YG2suoKqFzNOGV+x xgW9OEZMY5YAB1Ou8PUlODRt0Emjd6UiwDHsxvVLLWLjGe0/I1wtQlHnle9AwZxfB3vW uA5FeFdt1e8qlli+Hp0EYvNz4s70xFsYgpU4v9w6qaaR/fkIiAag64skKsg6gYGvB/Dg 4Ytv8OPEVpqIjc7jY9HBFTydduEUvTpgfSiB/E5yYZCrcVHKWPYcf5DvPPJkf3vB6QEn idfA== X-Gm-Message-State: APjAAAUyUMtYAIToX+jppfUAX9AyheMiN4m9GhzvhgqpbJMCRAMLSoT0 tS8XpI7tignPSDuXjXyDrt33AvmwaQ== X-Received: by 2002:a63:cc0a:: with SMTP id x10mr46904845pgf.179.1554104865837; Mon, 01 Apr 2019 00:47:45 -0700 (PDT) Received: from xps15.imgcgcw.net ([147.50.13.10]) by smtp.googlemail.com with ESMTPSA id o5sm33428950pfa.135.2019.04.01.00.47.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Apr 2019 00:47:45 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Will Deacon , Robin Murphy , Joerg Roedel , iommu@lists.linux-foundation.org, Maarten Lankhorst , Maxime Ripard , Sean Paul , David Airlie , Daniel Vetter , Alyssa Rosenzweig , Lyude Paul , Eric Anholt , Neil Armstrong Subject: [PATCH v2 2/3] drm: Add a drm_gem_objects_lookup helper Date: Mon, 1 Apr 2019 02:47:29 -0500 Message-Id: <20190401074730.12241-3-robh@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190401074730.12241-1-robh@kernel.org> References: <20190401074730.12241-1-robh@kernel.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Similar to the single handle drm_gem_object_lookup(), drm_gem_objects_lookup() takes an array of handles and returns an array of GEM objects. Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: Sean Paul Cc: David Airlie Cc: Daniel Vetter Signed-off-by: Rob Herring --- drivers/gpu/drm/drm_gem.c | 46 +++++++++++++++++++++++++++++++-------- include/drm/drm_gem.h | 2 ++ 2 files changed, 39 insertions(+), 9 deletions(-) -- 2.19.1 Reviewed-by: Daniel Vetter diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 388b3742e562..5c9bff45e5e1 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -663,6 +663,42 @@ void drm_gem_put_pages(struct drm_gem_object *obj, struct page **pages, } EXPORT_SYMBOL(drm_gem_put_pages); +/** + * drm_gem_objects_lookup - look up GEM objects from an array of handles + * @filp: DRM file private date + * @handle: pointer to array of userspace handle + * @count: size of handle array + * @objs: pointer to array of drm_gem_object pointers + * + * Returns: + * + * @objs filled in with GEM object pointers. -ENOENT is returned on a lookup + * failure. 0 is returned on success. + */ +int drm_gem_objects_lookup(struct drm_file *filp, u32 *handle, int count, + struct drm_gem_object **objs) +{ + int i, ret = 0; + struct drm_gem_object *obj; + + spin_lock(&filp->table_lock); + + for (i = 0; i < count; i++) { + /* Check if we currently have a reference on the object */ + obj = idr_find(&filp->object_idr, handle[i]); + if (!obj) { + ret = -ENOENT; + break; + } + drm_gem_object_get(obj); + objs[i] = obj; + } + spin_unlock(&filp->table_lock); + + return ret; +} +EXPORT_SYMBOL(drm_gem_objects_lookup); + /** * drm_gem_object_lookup - look up a GEM object from its handle * @filp: DRM file private date @@ -678,15 +714,7 @@ drm_gem_object_lookup(struct drm_file *filp, u32 handle) { struct drm_gem_object *obj; - spin_lock(&filp->table_lock); - - /* Check if we currently have a reference on the object */ - obj = idr_find(&filp->object_idr, handle); - if (obj) - drm_gem_object_get(obj); - - spin_unlock(&filp->table_lock); - + drm_gem_objects_lookup(filp, &handle, 1, &obj); return obj; } EXPORT_SYMBOL(drm_gem_object_lookup); diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h index 2955aaab3dca..5404225e0194 100644 --- a/include/drm/drm_gem.h +++ b/include/drm/drm_gem.h @@ -381,6 +381,8 @@ struct page **drm_gem_get_pages(struct drm_gem_object *obj); void drm_gem_put_pages(struct drm_gem_object *obj, struct page **pages, bool dirty, bool accessed); +int drm_gem_objects_lookup(struct drm_file *filp, u32 *handle, int count, + struct drm_gem_object **objs); struct drm_gem_object *drm_gem_object_lookup(struct drm_file *filp, u32 handle); long drm_gem_reservation_object_wait(struct drm_file *filep, u32 handle, bool wait_all, unsigned long timeout);