Home | History | Annotate | Line # | Download | only in linux
dma-resv.h revision 1.7
      1  1.7  riastrad /*	$NetBSD: dma-resv.h,v 1.7 2021/12/19 10:37:47 riastradh Exp $	*/
      2  1.5  riastrad 
      3  1.5  riastrad /*-
      4  1.5  riastrad  * Copyright (c) 2018 The NetBSD Foundation, Inc.
      5  1.5  riastrad  * All rights reserved.
      6  1.5  riastrad  *
      7  1.5  riastrad  * This code is derived from software contributed to The NetBSD Foundation
      8  1.5  riastrad  * by Taylor R. Campbell.
      9  1.5  riastrad  *
     10  1.5  riastrad  * Redistribution and use in source and binary forms, with or without
     11  1.5  riastrad  * modification, are permitted provided that the following conditions
     12  1.5  riastrad  * are met:
     13  1.5  riastrad  * 1. Redistributions of source code must retain the above copyright
     14  1.5  riastrad  *    notice, this list of conditions and the following disclaimer.
     15  1.5  riastrad  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.5  riastrad  *    notice, this list of conditions and the following disclaimer in the
     17  1.5  riastrad  *    documentation and/or other materials provided with the distribution.
     18  1.5  riastrad  *
     19  1.5  riastrad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.5  riastrad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.5  riastrad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.5  riastrad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.5  riastrad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.5  riastrad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.5  riastrad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.5  riastrad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.5  riastrad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.5  riastrad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.5  riastrad  * POSSIBILITY OF SUCH DAMAGE.
     30  1.2  riastrad  */
     31  1.2  riastrad 
     32  1.5  riastrad #ifndef	_LINUX_DMA_RESV_H_
     33  1.5  riastrad #define	_LINUX_DMA_RESV_H_
     34  1.5  riastrad 
     35  1.2  riastrad #include <linux/dma-fence.h>
     36  1.5  riastrad #include <linux/rcupdate.h>
     37  1.3  riastrad #include <linux/seqlock.h>
     38  1.5  riastrad #include <linux/ww_mutex.h>
     39  1.3  riastrad 
     40  1.3  riastrad struct dma_resv {
     41  1.5  riastrad 	struct ww_mutex				lock;
     42  1.5  riastrad 	struct seqcount				seq;
     43  1.5  riastrad 	struct dma_fence __rcu			*fence_excl;
     44  1.5  riastrad 	struct dma_resv_list __rcu		*fence;
     45  1.3  riastrad 
     46  1.5  riastrad 	struct dma_resv_list __rcu		*robj_prealloc;
     47  1.3  riastrad };
     48  1.3  riastrad 
     49  1.5  riastrad struct dma_resv_list {
     50  1.5  riastrad 	struct rcu_head		rol_rcu;
     51  1.3  riastrad 
     52  1.5  riastrad 	uint32_t		shared_count;
     53  1.5  riastrad 	uint32_t		shared_max;
     54  1.5  riastrad 	struct dma_fence __rcu	*shared[];
     55  1.5  riastrad };
     56  1.3  riastrad 
     57  1.5  riastrad /* NetBSD addition */
     58  1.5  riastrad struct dma_resv_poll {
     59  1.5  riastrad 	kmutex_t		rp_lock;
     60  1.5  riastrad 	struct selinfo		rp_selq;
     61  1.5  riastrad 	struct dma_fence_cb		rp_fcb;
     62  1.5  riastrad 	bool			rp_claimed;
     63  1.5  riastrad };
     64  1.3  riastrad 
     65  1.5  riastrad #define	dma_resv_add_excl_fence		linux_dma_resv_add_excl_fence
     66  1.5  riastrad #define	dma_resv_add_shared_fence	linux_dma_resv_add_shared_fence
     67  1.5  riastrad #define	dma_resv_assert_held		linux_dma_resv_assert_held
     68  1.5  riastrad #define	dma_resv_copy_fences		linux_dma_resv_copy_fences
     69  1.5  riastrad #define	dma_resv_do_poll		linux_dma_resv_do_poll
     70  1.5  riastrad #define	dma_resv_fini			linux_dma_resv_fini
     71  1.5  riastrad #define	dma_resv_get_excl		linux_dma_resv_get_excl
     72  1.5  riastrad #define	dma_resv_get_excl_rcu		linux_dma_resv_get_excl_rcu
     73  1.5  riastrad #define	dma_resv_get_fences_rcu		linux_dma_resv_get_fences_rcu
     74  1.5  riastrad #define	dma_resv_get_list		linux_dma_resv_get_list
     75  1.5  riastrad #define	dma_resv_held			linux_dma_resv_held
     76  1.5  riastrad #define	dma_resv_init			linux_dma_resv_init
     77  1.5  riastrad #define	dma_resv_kqfilter		linux_dma_resv_kqfilter
     78  1.5  riastrad #define	dma_resv_lock			linux_dma_resv_lock
     79  1.5  riastrad #define	dma_resv_lock_interruptible	linux_dma_resv_lock_interruptible
     80  1.6  riastrad #define	dma_resv_lock_slow		linux_dma_resv_lock_slow
     81  1.6  riastrad #define	dma_resv_lock_slow_interruptible linux_dma_resv_lock_slow_interruptible
     82  1.5  riastrad #define	dma_resv_reserve_shared		linux_dma_resv_reserve_shared
     83  1.5  riastrad #define	dma_resv_test_signaled_rcu	linux_dma_resv_test_signaled_rcu
     84  1.5  riastrad #define	dma_resv_trylock		linux_dma_resv_trylock
     85  1.5  riastrad #define	dma_resv_unlock			linux_dma_resv_unlock
     86  1.5  riastrad #define	dma_resv_wait_timeout_rcu	linux_dma_resv_wait_timeout_rcu
     87  1.5  riastrad #define	dma_resv_poll_fini		linux_dma_resv_poll_fini
     88  1.5  riastrad #define	dma_resv_poll_init		linux_dma_resv_poll_init
     89  1.5  riastrad #define	reservation_ww_class		linux_reservation_ww_class
     90  1.5  riastrad 
     91  1.5  riastrad extern struct ww_class	reservation_ww_class;
     92  1.5  riastrad 
     93  1.5  riastrad void	dma_resv_init(struct dma_resv *);
     94  1.5  riastrad void	dma_resv_fini(struct dma_resv *);
     95  1.5  riastrad int	dma_resv_lock(struct dma_resv *,
     96  1.5  riastrad 	    struct ww_acquire_ctx *);
     97  1.6  riastrad void	dma_resv_lock_slow(struct dma_resv *,
     98  1.6  riastrad 	    struct ww_acquire_ctx *);
     99  1.5  riastrad int	dma_resv_lock_interruptible(struct dma_resv *,
    100  1.5  riastrad 	    struct ww_acquire_ctx *);
    101  1.6  riastrad int	dma_resv_lock_slow_interruptible(struct dma_resv *,
    102  1.6  riastrad 	    struct ww_acquire_ctx *);
    103  1.5  riastrad bool	dma_resv_trylock(struct dma_resv *) __must_check;
    104  1.5  riastrad void	dma_resv_unlock(struct dma_resv *);
    105  1.5  riastrad bool	dma_resv_held(struct dma_resv *);
    106  1.5  riastrad void	dma_resv_assert_held(struct dma_resv *);
    107  1.5  riastrad struct dma_fence *
    108  1.5  riastrad 	dma_resv_get_excl(struct dma_resv *);
    109  1.5  riastrad struct dma_resv_list *
    110  1.5  riastrad 	dma_resv_get_list(struct dma_resv *);
    111  1.7  riastrad int	dma_resv_reserve_shared(struct dma_resv *, unsigned int);
    112  1.5  riastrad void	dma_resv_add_excl_fence(struct dma_resv *,
    113  1.5  riastrad 	    struct dma_fence *);
    114  1.5  riastrad void	dma_resv_add_shared_fence(struct dma_resv *,
    115  1.5  riastrad 	    struct dma_fence *);
    116  1.5  riastrad 
    117  1.5  riastrad struct dma_fence *
    118  1.5  riastrad 	dma_resv_get_excl_rcu(const struct dma_resv *);
    119  1.5  riastrad int	dma_resv_get_fences_rcu(const struct dma_resv *,
    120  1.5  riastrad 	    struct dma_fence **, unsigned *, struct dma_fence ***);
    121  1.5  riastrad 
    122  1.5  riastrad int	dma_resv_copy_fences(struct dma_resv *,
    123  1.5  riastrad 	    const struct dma_resv *);
    124  1.5  riastrad 
    125  1.5  riastrad bool	dma_resv_test_signaled_rcu(const struct dma_resv *,
    126  1.5  riastrad 	    bool);
    127  1.5  riastrad long	dma_resv_wait_timeout_rcu(const struct dma_resv *,
    128  1.5  riastrad 	    bool, bool, unsigned long);
    129  1.5  riastrad 
    130  1.5  riastrad /* NetBSD additions */
    131  1.5  riastrad void	dma_resv_poll_init(struct dma_resv_poll *);
    132  1.5  riastrad void	dma_resv_poll_fini(struct dma_resv_poll *);
    133  1.5  riastrad int	dma_resv_do_poll(const struct dma_resv *, int,
    134  1.5  riastrad 	    struct dma_resv_poll *);
    135  1.5  riastrad int	dma_resv_kqfilter(const struct dma_resv *,
    136  1.5  riastrad 	    struct knote *, struct dma_resv_poll *);
    137  1.3  riastrad 
    138  1.5  riastrad static inline bool
    139  1.5  riastrad dma_resv_has_excl_fence(const struct dma_resv *robj)
    140  1.3  riastrad {
    141  1.5  riastrad 	return robj->fence_excl != NULL;
    142  1.3  riastrad }
    143  1.3  riastrad 
    144  1.5  riastrad #endif	/* _LINUX_DMA_RESV_H_ */
    145