Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: MIT */
0002 
0003 /*
0004  * Copyright © 2019 Intel Corporation
0005  */
0006 
0007 #ifndef I915_SW_FENCE_WORK_H
0008 #define I915_SW_FENCE_WORK_H
0009 
0010 #include <linux/dma-fence.h>
0011 #include <linux/spinlock.h>
0012 #include <linux/workqueue.h>
0013 
0014 #include "i915_sw_fence.h"
0015 
0016 struct dma_fence_work;
0017 
0018 struct dma_fence_work_ops {
0019     const char *name;
0020     void (*work)(struct dma_fence_work *f);
0021     void (*release)(struct dma_fence_work *f);
0022 };
0023 
0024 struct dma_fence_work {
0025     struct dma_fence dma;
0026     spinlock_t lock;
0027 
0028     struct i915_sw_fence chain;
0029     struct i915_sw_dma_fence_cb cb;
0030 
0031     struct work_struct work;
0032     const struct dma_fence_work_ops *ops;
0033 };
0034 
0035 enum {
0036     DMA_FENCE_WORK_IMM = DMA_FENCE_FLAG_USER_BITS,
0037 };
0038 
0039 void dma_fence_work_init(struct dma_fence_work *f,
0040              const struct dma_fence_work_ops *ops);
0041 int dma_fence_work_chain(struct dma_fence_work *f, struct dma_fence *signal);
0042 
0043 static inline void dma_fence_work_commit(struct dma_fence_work *f)
0044 {
0045     i915_sw_fence_commit(&f->chain);
0046 }
0047 
0048 /**
0049  * dma_fence_work_commit_imm: Commit the fence, and if possible execute locally.
0050  * @f: the fenced worker
0051  *
0052  * Instead of always scheduling a worker to execute the callback (see
0053  * dma_fence_work_commit()), we try to execute the callback immediately in
0054  * the local context. It is required that the fence be committed before it
0055  * is published, and that no other threads try to tamper with the number
0056  * of asynchronous waits on the fence (or else the callback will be
0057  * executed in the wrong context, i.e. not the callers).
0058  */
0059 static inline void dma_fence_work_commit_imm(struct dma_fence_work *f)
0060 {
0061     if (atomic_read(&f->chain.pending) <= 1)
0062         __set_bit(DMA_FENCE_WORK_IMM, &f->dma.flags);
0063 
0064     dma_fence_work_commit(f);
0065 }
0066 
0067 #endif /* I915_SW_FENCE_WORK_H */