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: 10879273 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7A3F313B5 for ; Mon, 1 Apr 2019 07:47:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 687D8285BE for ; Mon, 1 Apr 2019 07:47:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5CD0728745; Mon, 1 Apr 2019 07:47:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E9CD5285BE for ; Mon, 1 Apr 2019 07:47:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 27C756E092; Mon, 1 Apr 2019 07:47:48 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by gabe.freedesktop.org (Postfix) with ESMTPS id AAD886E092 for ; Mon, 1 Apr 2019 07:47:46 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id z9so4315797pgu.10 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=ZOIZubGpqONNGob/PsPaE51Dh7kGQjCLsb9xCjs7A87WNv4eNtVjRzKxJ5Ybj8RFL9 obEdiBPo5W1qGDhq+Ix5RPbLW/X7gmHX8Aq+5uFpwM8hL10rRyG9mREKnVfUdMRO88O9 /CepvFlYoPW9N1kRA4A4W/KyzNZ/13hOk+pHvBs55PcCvD5BuvLMgc9v7IQXXy1jQkUo Dc3qM8HGHTtWXLeuK6zKImpBr48hJGJUXX1oCGVvoY1fpGeIj+tLOCDY63BOcO3bcfeF hxJjYnADuhTUC541jJAans3y4NPU+p/7AOi+jfAUGd95O3qKp41p2WAthxiXA63lR5m8 gjxw== X-Gm-Message-State: APjAAAWjMibq3zRUjOuN/x6VIeAa/ZjshYf/nyz0wtVn4ScfsSXMNyV5 CI+MQVFmLUq0pLHqZQbhqi/AyiZcwA== X-Google-Smtp-Source: APXvYqz7MENmRRrkE03JASOKsXJ+6kkupc/Jn18X9B+MoC48eypHb0NDW9ByNJ8QQvRVSH1sjg+FXQ== 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 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 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sean Paul , Maxime Ripard , Neil Armstrong , Will Deacon , linux-kernel@vger.kernel.org, David Airlie , iommu@lists.linux-foundation.org, Alyssa Rosenzweig , Robin Murphy , linux-arm-kernel@lists.infradead.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Daniel Vetter --- drivers/gpu/drm/drm_gem.c | 46 +++++++++++++++++++++++++++++++-------- include/drm/drm_gem.h | 2 ++ 2 files changed, 39 insertions(+), 9 deletions(-) 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);