From patchwork Tue Aug 9 17:45:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Noralf_Tr=C3=B8nnes?= X-Patchwork-Id: 9271971 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 63F296075A for ; Tue, 9 Aug 2016 17:46:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A3A128364 for ; Tue, 9 Aug 2016 17:46:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F0B32838C; Tue, 9 Aug 2016 17:46:06 +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=-4.2 required=2.0 tests=BAYES_00, 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 1159228364 for ; Tue, 9 Aug 2016 17:46:06 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C672A6E61E; Tue, 9 Aug 2016 17:46:02 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from smtp.domeneshop.no (smtp.domeneshop.no [IPv6:2a01:5b40:0:3005::1]) by gabe.freedesktop.org (Postfix) with ESMTPS id C2E176E60D for ; Tue, 9 Aug 2016 17:45:59 +0000 (UTC) Received: from 211.81-166-168.customer.lyse.net ([81.166.168.211]:7996 helo=localhost.localdomain) by smtp.domeneshop.no with esmtpsa (TLS1.1:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1bXB6E-0002JN-7X; Tue, 09 Aug 2016 19:45:58 +0200 From: =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= To: dri-devel@lists.freedesktop.org Subject: [RFC 1/3] drm: Add a way to iterate over minors Date: Tue, 9 Aug 2016 19:45:40 +0200 Message-Id: <1470764742-20323-2-git-send-email-noralf@tronnes.org> X-Mailer: git-send-email 2.8.2 In-Reply-To: <1470764742-20323-1-git-send-email-noralf@tronnes.org> References: <1470764742-20323-1-git-send-email-noralf@tronnes.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP This adds a way for in-kernel users to iterate over the available DRM minors. The implementation is oops safe so the panic code can safely use it. Signed-off-by: Noralf Trønnes --- drivers/gpu/drm/drm_drv.c | 30 ++++++++++++++++++++++++++++++ include/drm/drmP.h | 13 +++++++++++++ 2 files changed, 43 insertions(+) diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index be27ed3..3b14366 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -292,6 +292,36 @@ void drm_minor_release(struct drm_minor *minor) } /** + * drm_minor_lookup - Lookup DRM minor + * @minor_id: Minor ID of the DRM-minor + * + * Looks up the given minor-ID and returns the respective DRM-minor object. + * No reference is taken on the underlying device. + * See drm_minor_for_each() for iterating over all minors. + * + * Returns: + * Pointer to minor-object or NULL. + */ +struct drm_minor *drm_minor_lookup(unsigned int minor_id) +{ + struct drm_minor *minor; + unsigned long flags; + int locked = 1; + + if (oops_in_progress) + locked = spin_trylock_irqsave(&drm_minor_lock, flags); + else + spin_lock_irqsave(&drm_minor_lock, flags); + + minor = idr_find(&drm_minors_idr, minor_id); + + if (locked) + spin_unlock_irqrestore(&drm_minor_lock, flags); + + return minor; +} + +/** * DOC: driver instance overview * * A device instance for a drm driver is represented by struct &drm_device. This diff --git a/include/drm/drmP.h b/include/drm/drmP.h index d377865..bc7006e 100644 --- a/include/drm/drmP.h +++ b/include/drm/drmP.h @@ -974,6 +974,19 @@ void drm_dev_unregister(struct drm_device *dev); struct drm_minor *drm_minor_acquire(unsigned int minor_id); void drm_minor_release(struct drm_minor *minor); +struct drm_minor *drm_minor_lookup(unsigned int minor_id); + +/** + * drm_minor_for_each - Iterate over DRM minors + * @minor: DRM minor handle + * @type: DRM minor type to iterate over + * @id: id handle + * + * Iterate over the registered DRM minors of a given type. + */ +#define drm_minor_for_each(minor, type, id) \ + for ((id) = 0; (id) < 64; (id)++) \ + if (((minor) = drm_minor_lookup((id) + (type) * 64))) /*@}*/