Home | History | Annotate | Line # | Download | only in i915
      1  1.8       mrg /*	$NetBSD: i915_gem.h,v 1.8 2023/08/08 06:59:40 mrg Exp $	*/
      2  1.1  riastrad 
      3  1.1  riastrad /*
      4  1.1  riastrad  * Copyright  2016 Intel Corporation
      5  1.1  riastrad  *
      6  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
      7  1.1  riastrad  * copy of this software and associated documentation files (the "Software"),
      8  1.1  riastrad  * to deal in the Software without restriction, including without limitation
      9  1.1  riastrad  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     10  1.1  riastrad  * and/or sell copies of the Software, and to permit persons to whom the
     11  1.1  riastrad  * Software is furnished to do so, subject to the following conditions:
     12  1.1  riastrad  *
     13  1.1  riastrad  * The above copyright notice and this permission notice (including the next
     14  1.1  riastrad  * paragraph) shall be included in all copies or substantial portions of the
     15  1.1  riastrad  * Software.
     16  1.1  riastrad  *
     17  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     18  1.1  riastrad  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     19  1.1  riastrad  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     20  1.1  riastrad  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     21  1.1  riastrad  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     22  1.1  riastrad  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
     23  1.1  riastrad  * IN THE SOFTWARE.
     24  1.1  riastrad  *
     25  1.1  riastrad  */
     26  1.1  riastrad 
     27  1.1  riastrad #ifndef __I915_GEM_H__
     28  1.1  riastrad #define __I915_GEM_H__
     29  1.1  riastrad 
     30  1.1  riastrad #include <linux/bug.h>
     31  1.1  riastrad #include <linux/interrupt.h>
     32  1.4  riastrad #include <linux/stringify.h>
     33  1.1  riastrad 
     34  1.1  riastrad #include <drm/drm_drv.h>
     35  1.1  riastrad 
     36  1.1  riastrad #include "i915_utils.h"
     37  1.1  riastrad 
     38  1.1  riastrad struct drm_i915_private;
     39  1.1  riastrad 
     40  1.1  riastrad #ifdef CONFIG_DRM_I915_DEBUG_GEM
     41  1.1  riastrad 
     42  1.1  riastrad #define GEM_SHOW_DEBUG() drm_debug_enabled(DRM_UT_DRIVER)
     43  1.1  riastrad 
     44  1.1  riastrad #define GEM_BUG_ON(condition) do { if (unlikely((condition))) {	\
     45  1.1  riastrad 		GEM_TRACE_ERR("%s:%d GEM_BUG_ON(%s)\n", \
     46  1.1  riastrad 			      __func__, __LINE__, __stringify(condition)); \
     47  1.1  riastrad 		GEM_TRACE_DUMP(); \
     48  1.1  riastrad 		BUG(); \
     49  1.1  riastrad 		} \
     50  1.1  riastrad 	} while(0)
     51  1.1  riastrad #define GEM_WARN_ON(expr) WARN_ON(expr)
     52  1.1  riastrad 
     53  1.1  riastrad #define GEM_DEBUG_DECL(var) var
     54  1.1  riastrad #define GEM_DEBUG_EXEC(expr) expr
     55  1.1  riastrad #define GEM_DEBUG_BUG_ON(expr) GEM_BUG_ON(expr)
     56  1.1  riastrad #define GEM_DEBUG_WARN_ON(expr) GEM_WARN_ON(expr)
     57  1.1  riastrad 
     58  1.1  riastrad #else
     59  1.1  riastrad 
     60  1.1  riastrad #define GEM_SHOW_DEBUG() (0)
     61  1.1  riastrad 
     62  1.1  riastrad #define GEM_BUG_ON(expr) BUILD_BUG_ON_INVALID(expr)
     63  1.1  riastrad #define GEM_WARN_ON(expr) ({ unlikely(!!(expr)); })
     64  1.1  riastrad 
     65  1.1  riastrad #define GEM_DEBUG_DECL(var)
     66  1.1  riastrad #define GEM_DEBUG_EXEC(expr) do { } while (0)
     67  1.1  riastrad #define GEM_DEBUG_BUG_ON(expr)
     68  1.1  riastrad #define GEM_DEBUG_WARN_ON(expr) ({ BUILD_BUG_ON_INVALID(expr); 0; })
     69  1.1  riastrad #endif
     70  1.1  riastrad 
     71  1.1  riastrad #if IS_ENABLED(CONFIG_DRM_I915_TRACE_GEM)
     72  1.1  riastrad #define GEM_TRACE(...) trace_printk(__VA_ARGS__)
     73  1.1  riastrad #define GEM_TRACE_ERR(...) do {						\
     74  1.1  riastrad 	pr_err(__VA_ARGS__);						\
     75  1.1  riastrad 	trace_printk(__VA_ARGS__);					\
     76  1.1  riastrad } while (0)
     77  1.1  riastrad #define GEM_TRACE_DUMP() \
     78  1.1  riastrad 	do { ftrace_dump(DUMP_ALL); add_taint_for_CI(TAINT_WARN); } while (0)
     79  1.1  riastrad #define GEM_TRACE_DUMP_ON(expr) \
     80  1.1  riastrad 	do { if (expr) GEM_TRACE_DUMP(); } while (0)
     81  1.1  riastrad #else
     82  1.1  riastrad #define GEM_TRACE(...) do { } while (0)
     83  1.1  riastrad #define GEM_TRACE_ERR(...) do { } while (0)
     84  1.1  riastrad #define GEM_TRACE_DUMP() do { } while (0)
     85  1.1  riastrad #define GEM_TRACE_DUMP_ON(expr) BUILD_BUG_ON_INVALID(expr)
     86  1.1  riastrad #endif
     87  1.1  riastrad 
     88  1.1  riastrad #define I915_GEM_IDLE_TIMEOUT (HZ / 5)
     89  1.1  riastrad 
     90  1.1  riastrad static inline void tasklet_lock(struct tasklet_struct *t)
     91  1.1  riastrad {
     92  1.1  riastrad 	while (!tasklet_trylock(t))
     93  1.1  riastrad 		cpu_relax();
     94  1.1  riastrad }
     95  1.1  riastrad 
     96  1.5  riastrad #ifndef __NetBSD__
     97  1.5  riastrad 
     98  1.1  riastrad static inline bool tasklet_is_locked(const struct tasklet_struct *t)
     99  1.1  riastrad {
    100  1.1  riastrad 	return test_bit(TASKLET_STATE_RUN, &t->state);
    101  1.1  riastrad }
    102  1.1  riastrad 
    103  1.1  riastrad static inline void __tasklet_disable_sync_once(struct tasklet_struct *t)
    104  1.1  riastrad {
    105  1.1  riastrad 	if (!atomic_fetch_inc(&t->count))
    106  1.1  riastrad 		tasklet_unlock_wait(t);
    107  1.1  riastrad }
    108  1.1  riastrad 
    109  1.1  riastrad static inline bool __tasklet_is_enabled(const struct tasklet_struct *t)
    110  1.1  riastrad {
    111  1.1  riastrad 	return !atomic_read(&t->count);
    112  1.1  riastrad }
    113  1.1  riastrad 
    114  1.1  riastrad static inline bool __tasklet_enable(struct tasklet_struct *t)
    115  1.1  riastrad {
    116  1.1  riastrad 	return atomic_dec_and_test(&t->count);
    117  1.1  riastrad }
    118  1.1  riastrad 
    119  1.1  riastrad static inline bool __tasklet_is_scheduled(struct tasklet_struct *t)
    120  1.1  riastrad {
    121  1.1  riastrad 	return test_bit(TASKLET_STATE_SCHED, &t->state);
    122  1.1  riastrad }
    123  1.1  riastrad 
    124  1.5  riastrad #endif
    125  1.5  riastrad 
    126  1.1  riastrad #endif /* __I915_GEM_H__ */
    127