From patchwork Mon Aug 26 14:57:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 11114823 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5BA4F14DB for ; Mon, 26 Aug 2019 14:58:06 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4411E23406 for ; Mon, 26 Aug 2019 14:58:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4411E23406 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 42EC06E096; Mon, 26 Aug 2019 14:58:05 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by gabe.freedesktop.org (Postfix) with ESMTPS id D56D889F8E for ; Mon, 26 Aug 2019 14:57:38 +0000 (UTC) Received: by mail-wm1-x343.google.com with SMTP id o4so15787475wmh.2 for ; Mon, 26 Aug 2019 07:57:38 -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:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dory6iMos9l+mdyEwGPbTiqUtowdJaD3gd9QEEFvwxI=; b=lY2NGVvb9gU9nTonYWnkddj/QgcLvHJBJm0jNjXUkVvLzjFN9YMCbV/TzoDHqkiX/6 jzK/h79xoLRVNkxchjnyZkRWyOQiCXlNr6lVLohsPfTwcsRdIqLkmzD1q5gChkG6tikW 7wYYPQ1K8gWsFiE7UeDb7Ziz0jahwaZNENlvZOPFRo1DaC/CZW0GOkx/h54O5x3Wz5iz +ugBt4EfxgMwWECj7X5xY1KAUbE6rFb/aqsHyOl89KngS3b+flQy0PVLkzEHgapQV9KJ W2HwKtXxm25Nav9iycJ1GO142r8ZySvvybLlN3a611x/KMjiGkV11Z5qBvsEhQJHrSBJ PDQQ== X-Gm-Message-State: APjAAAW5El++dHQRyBHfV36jYVnZJOS2jKegZl0qZA/t2AMCC1oZxRPt v7QhcbRv2+waTKQmJAoTbgPwPTNz X-Google-Smtp-Source: APXvYqwhXrTJtyZKIS2GL7rEowiF10SZQSZs0Rr1NkojMwT7jKVx37M8QtLeMudXLnJlEvK3Ga8Seg== X-Received: by 2002:a1c:8187:: with SMTP id c129mr21955469wmd.32.1566831457359; Mon, 26 Aug 2019 07:57:37 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:b0e3:7a12:98e5:ca6]) by smtp.gmail.com with ESMTPSA id z8sm9865624wmi.7.2019.08.26.07.57.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2019 07:57:36 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: dri-devel@lists.freedesktop.org, chris@chris-wilson.co.uk, daniel.vetter@ffwll.ch, sumit.semwal@linaro.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org Subject: [PATCH 5/9] dma-buf: add dma_fence_array_for_each Date: Mon, 26 Aug 2019 16:57:27 +0200 Message-Id: <20190826145731.1725-6-christian.koenig@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190826145731.1725-1-christian.koenig@amd.com> References: <20190826145731.1725-1-christian.koenig@amd.com> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=dory6iMos9l+mdyEwGPbTiqUtowdJaD3gd9QEEFvwxI=; b=m2Dhh3HuJShfKJ+CSaiYIChS8UGnuawoazbndF/CBXdeo2+PL9MBXpgmhSA40SIsz1 ajNjVWaUKOAVxzmKlLB/rLXgxImiCO2WmJ74Kwq2rNoo5I2znpQt0EVEpTXBKfrnKO4k 5oYhr8FJheeUyrNK67GJmnfytJn8WQ/UnraMMPRcSpnVXi06yDe1fIcLjoAHk9zCkO3v 2LntgiS8MqF5852UKLT9wPNHRcW1jaAv77zu/iiHZfrMlQfOb71+uTaF/fHpRjyGK6kr 1H6IFeMXlq0NKBSYGk9UEFWxe9BP00Y5jOyzcI5Cynu/SB/rUHNipTIp8o9bby9Gc7kJ /gIw== 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Makes it easier to extract the fences in a dma_fence_array. Signed-off-by: Christian König --- drivers/dma-buf/dma-fence-array.c | 42 +++++++++++++++++++++++++++++++ include/linux/dma-fence-array.h | 24 ++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/drivers/dma-buf/dma-fence-array.c b/drivers/dma-buf/dma-fence-array.c index ea7713b40514..3bc2663a3f30 100644 --- a/drivers/dma-buf/dma-fence-array.c +++ b/drivers/dma-buf/dma-fence-array.c @@ -276,3 +276,45 @@ bool dma_fence_match_context(struct dma_fence *fence, u64 context) return true; } EXPORT_SYMBOL(dma_fence_match_context); + +/** + * dma_fence_array_first - return the first fence in an array + * @cursor: cursor for the current position + * @array: array with the fences + * + * Returns the first fence in the array or NULL if the array is empty. + * If the array parameter isn't a dma_fence_array return it unmodified. + */ +struct dma_fence *dma_fence_array_first(struct dma_fence_array_cursor *cursor, + struct dma_fence *array) +{ + cursor->array = to_dma_fence_array(array); + if (!cursor->array) + return array; + + if (!cursor->array->num_fences) + return NULL; + + cursor->index = 0; + return cursor->array->fences[cursor->index++]; + +} +EXPORT_SYMBOL(dma_fence_array_first); + +/** + * dma_fence_array_next - return the next fence in the array + * @cursor: cursor for the current position + * + * Returns the next fence from the array or NULL if we don't have any more + */ +struct dma_fence *dma_fence_array_next(struct dma_fence_array_cursor *cursor) +{ + if (!cursor->array) + return NULL; + + if (cursor->index >= cursor->array->num_fences) + return NULL; + + return cursor->array->fences[cursor->index++]; +} +EXPORT_SYMBOL(dma_fence_array_next); diff --git a/include/linux/dma-fence-array.h b/include/linux/dma-fence-array.h index 35d1d1e7c93b..2a71fd003dfa 100644 --- a/include/linux/dma-fence-array.h +++ b/include/linux/dma-fence-array.h @@ -124,4 +124,28 @@ dma_fence_array_create(int num_fences, struct dma_fence **fences, u64 context, bool dma_fence_match_context(struct dma_fence *fence, u64 context); +/** + * struct dma_fence_array_cursor - cursor for the fences in an array + */ +struct dma_fence_array_cursor { + struct dma_fence_array *array; + unsigned int index; +}; + +struct dma_fence *dma_fence_array_first(struct dma_fence_array_cursor *cursor, + struct dma_fence *array); +struct dma_fence *dma_fence_array_next(struct dma_fence_array_cursor *cursor); + +/** + * dma_fence_array_for_each - walk over all fences in a fence array + * @fence: the current fence + * @cursor: cursor for the walk + * @array: potentitally fence array + * + * Walk over all the fences in the array. + */ +#define dma_fence_array_for_each(fence, cursor, array) \ + for (fence = dma_fence_array_first(&(cursor), array); \ + fence; fence = dma_fence_array_next(&(cursor))) + #endif /* __LINUX_DMA_FENCE_ARRAY_H */