From patchwork Thu Feb 16 11:39:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Nicolai_H=C3=A4hnle?= X-Patchwork-Id: 9576895 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 01D47600C5 for ; Thu, 16 Feb 2017 11:40:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EAD0A201F3 for ; Thu, 16 Feb 2017 11:40:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DFBDB285BE; Thu, 16 Feb 2017 11:40: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.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID 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 7CAE9201F3 for ; Thu, 16 Feb 2017 11:40:06 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 21D226EAC5; Thu, 16 Feb 2017 11:40:04 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x242.google.com (mail-wm0-x242.google.com [IPv6:2a00:1450:400c:c09::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2AEAB6EAB8; Thu, 16 Feb 2017 11:40:00 +0000 (UTC) Received: by mail-wm0-x242.google.com with SMTP id v77so2691729wmv.0; Thu, 16 Feb 2017 03:40:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KEB87ewuRLUjMPBoLhgWB+3zikSacQSAzAa6fdxQFkU=; b=TZOUbZyxLzAnr+xY8sWPoDnCoOOV95JiITOMjAt98P1tqLR4TtpyT0Mef9B43RoNFH ZNhwZUho4XU3X8PB0rZEV2GAFJr/rmDV6RKBjs1TDPJbKPzopxJ8nqEoYQJNp7mCwJM9 ryLVWbHPDOBaqtx2gC2/yiEzQLhJYdvy1ShQkzwOcJTgY9tjuSyKh8YQQyw98YBGzn0p /46SRm2rSVAfoycdItNo0b1WusEzftWpkhh42/hOgnlT7X862c0EpeH6Y/wbqtrvpEgz asNVP0R8bgcNiSkvtxF7l944sfNshEcjvOdwHqXASUIf/Vnal2Yot9TuC0oAXvkOHBFp rNFQ== 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=KEB87ewuRLUjMPBoLhgWB+3zikSacQSAzAa6fdxQFkU=; b=gMI1OWJhLhlasGZTJVofwDLvHE9IP6aEeIQbLIPW4h8XgS2PI5n2o5kjOGb56AmRIe seJ1MClzf5KcPxvGJdQpBzmVqs2G4mZtqf3Pnq7HK8EPTIvQWKY6sKClAaxZTyzSSQ+i KCAj8cCnSQ2al/h8FyZfe2H4i0X9N+h+anX7idv4Hh6cxgdanQWchHkBlXmBuXT9fP0x bdXLoLSmC59dDfpsKLrMVWMj49ExamTiw6N2t7QuRzUikv3LSRHomCu7W4mOhPJOaBPf 2uSQiG5vGy/BLdAUsbjTVQJftKf7QqDpNhaQq0ZsOlFquj3Dml0bwgUzXM4q66eT4flI Qcuw== X-Gm-Message-State: AMke39lY37zTaKNDj+ycTHclZ5PO6V9Xvb+fKZCk+JWISC3O5aFvrVb4zcJBYt+aOqJAqg== X-Received: by 10.28.210.139 with SMTP id j133mr11927366wmg.67.1487245198780; Thu, 16 Feb 2017 03:39:58 -0800 (PST) Received: from capella.localdomain (x55b544e3.dyn.telefonica.de. [85.181.68.227]) by smtp.gmail.com with ESMTPSA id c202sm3167038wmd.10.2017.02.16.03.39.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Feb 2017 03:39:58 -0800 (PST) From: =?UTF-8?q?Nicolai=20H=C3=A4hnle?= To: amd-gfx@lists.freedesktop.org Subject: [PATCH v3 2/3] drm/ttm: add ttm_bo_init_reserved Date: Thu, 16 Feb 2017 12:39:45 +0100 Message-Id: <20170216113946.22046-2-nhaehnle@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170216113946.22046-1-nhaehnle@gmail.com> References: <20170216113946.22046-1-nhaehnle@gmail.com> MIME-Version: 1.0 Cc: =?UTF-8?q?Nicolai=20H=C3=A4hnle?= , dri-devel@lists.freedesktop.org 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 From: Nicolai Hähnle This variant of ttm_bo_init returns the validated buffer object with the reservation lock held when resv == NULL. This is convenient for callers that want to use the BO immediately, e.g. for initializing its contents. Signed-off-by: Nicolai Hähnle --- drivers/gpu/drm/ttm/ttm_bo.c | 59 +++++++++++++++++++++++++++++++++----------- include/drm/ttm/ttm_bo_api.h | 54 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index c438b04..989b98b 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -1119,18 +1119,18 @@ int ttm_bo_validate(struct ttm_buffer_object *bo, } EXPORT_SYMBOL(ttm_bo_validate); -int ttm_bo_init(struct ttm_bo_device *bdev, - struct ttm_buffer_object *bo, - unsigned long size, - enum ttm_bo_type type, - struct ttm_placement *placement, - uint32_t page_alignment, - bool interruptible, - struct file *persistent_swap_storage, - size_t acc_size, - struct sg_table *sg, - struct reservation_object *resv, - void (*destroy) (struct ttm_buffer_object *)) +int ttm_bo_init_reserved(struct ttm_bo_device *bdev, + struct ttm_buffer_object *bo, + unsigned long size, + enum ttm_bo_type type, + struct ttm_placement *placement, + uint32_t page_alignment, + bool interruptible, + struct file *persistent_swap_storage, + size_t acc_size, + struct sg_table *sg, + struct reservation_object *resv, + void (*destroy) (struct ttm_buffer_object *)) { int ret = 0; unsigned long num_pages; @@ -1214,10 +1214,10 @@ int ttm_bo_init(struct ttm_bo_device *bdev, if (likely(!ret)) ret = ttm_bo_validate(bo, placement, interruptible, false); - if (!resv) - ttm_bo_unreserve(bo); - if (unlikely(ret)) { + if (!resv) + ttm_bo_unreserve(bo); + ttm_bo_unref(&bo); return ret; } @@ -1230,6 +1230,35 @@ int ttm_bo_init(struct ttm_bo_device *bdev, return ret; } +EXPORT_SYMBOL(ttm_bo_init_reserved); + +int ttm_bo_init(struct ttm_bo_device *bdev, + struct ttm_buffer_object *bo, + unsigned long size, + enum ttm_bo_type type, + struct ttm_placement *placement, + uint32_t page_alignment, + bool interruptible, + struct file *persistent_swap_storage, + size_t acc_size, + struct sg_table *sg, + struct reservation_object *resv, + void (*destroy) (struct ttm_buffer_object *)) +{ + int ret; + + ret = ttm_bo_init_reserved(bdev, bo, size, type, placement, + page_alignment, interruptible, + persistent_swap_storage, acc_size, + sg, resv, destroy); + if (ret) + return ret; + + if (!resv) + ttm_bo_unreserve(bo); + + return 0; +} EXPORT_SYMBOL(ttm_bo_init); size_t ttm_bo_acc_size(struct ttm_bo_device *bdev, diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h index c0ebbd6..2d0f63e 100644 --- a/include/drm/ttm/ttm_bo_api.h +++ b/include/drm/ttm/ttm_bo_api.h @@ -453,6 +453,60 @@ size_t ttm_bo_dma_acc_size(struct ttm_bo_device *bdev, unsigned struct_size); /** + * ttm_bo_init_reserved + * + * @bdev: Pointer to a ttm_bo_device struct. + * @bo: Pointer to a ttm_buffer_object to be initialized. + * @size: Requested size of buffer object. + * @type: Requested type of buffer object. + * @flags: Initial placement flags. + * @page_alignment: Data alignment in pages. + * @interruptible: If needing to sleep to wait for GPU resources, + * sleep interruptible. + * @persistent_swap_storage: Usually the swap storage is deleted for buffers + * pinned in physical memory. If this behaviour is not desired, this member + * holds a pointer to a persistent shmem object. Typically, this would + * point to the shmem object backing a GEM object if TTM is used to back a + * GEM user interface. + * @acc_size: Accounted size for this object. + * @resv: Pointer to a reservation_object, or NULL to let ttm allocate one. + * @destroy: Destroy function. Use NULL for kfree(). + * + * This function initializes a pre-allocated struct ttm_buffer_object. + * As this object may be part of a larger structure, this function, + * together with the @destroy function, + * enables driver-specific objects derived from a ttm_buffer_object. + * + * On successful return, the caller owns an object kref to @bo. The kref and + * list_kref are usually set to 1, but note that in some situations, other + * tasks may already be holding references to @bo as well. + * Furthermore, if resv == NULL, the buffer's reservation lock will be held, + * and it is the caller's responsibility to call ttm_bo_unreserve. + * + * If a failure occurs, the function will call the @destroy function, or + * kfree() if @destroy is NULL. Thus, after a failure, dereferencing @bo is + * illegal and will likely cause memory corruption. + * + * Returns + * -ENOMEM: Out of memory. + * -EINVAL: Invalid placement flags. + * -ERESTARTSYS: Interrupted by signal while sleeping waiting for resources. + */ + +extern int ttm_bo_init_reserved(struct ttm_bo_device *bdev, + struct ttm_buffer_object *bo, + unsigned long size, + enum ttm_bo_type type, + struct ttm_placement *placement, + uint32_t page_alignment, + bool interrubtible, + struct file *persistent_swap_storage, + size_t acc_size, + struct sg_table *sg, + struct reservation_object *resv, + void (*destroy) (struct ttm_buffer_object *)); + +/** * ttm_bo_init * * @bdev: Pointer to a ttm_bo_device struct.