Home | History | Annotate | Line # | Download | only in i915
      1  1.4  riastrad /*	$NetBSD: i915_utils.c,v 1.4 2021/12/19 11:37:41 riastradh Exp $	*/
      2  1.1  riastrad 
      3  1.1  riastrad // SPDX-License-Identifier: MIT
      4  1.1  riastrad /*
      5  1.1  riastrad  * Copyright  2019 Intel Corporation
      6  1.1  riastrad  */
      7  1.1  riastrad 
      8  1.1  riastrad #include <sys/cdefs.h>
      9  1.4  riastrad __KERNEL_RCSID(0, "$NetBSD: i915_utils.c,v 1.4 2021/12/19 11:37:41 riastradh Exp $");
     10  1.1  riastrad 
     11  1.1  riastrad #include <drm/drm_drv.h>
     12  1.1  riastrad 
     13  1.1  riastrad #include "i915_drv.h"
     14  1.1  riastrad #include "i915_utils.h"
     15  1.1  riastrad 
     16  1.3  riastrad #ifdef __NetBSD__
     17  1.3  riastrad #define	NBSD_BUG_URL "https://gnats.NetBSD.org/"
     18  1.3  riastrad #define	NBSD_BUG_MSG							      \
     19  1.3  riastrad 	"Please file a bug at " NBSD_BUG_URL " in category kern"	      \
     20  1.3  riastrad 	" providing the dmesg log by booting with debug/verbose"	      \
     21  1.3  riastrad 	" as in `boot -vx'."
     22  1.3  riastrad #else
     23  1.1  riastrad #define FDO_BUG_URL "https://gitlab.freedesktop.org/drm/intel/-/wikis/How-to-file-i915-bugs"
     24  1.1  riastrad #define FDO_BUG_MSG "Please file a bug on drm/i915; see " FDO_BUG_URL " for details."
     25  1.3  riastrad #endif
     26  1.1  riastrad 
     27  1.1  riastrad void
     28  1.1  riastrad __i915_printk(struct drm_i915_private *dev_priv, const char *level,
     29  1.1  riastrad 	      const char *fmt, ...)
     30  1.1  riastrad {
     31  1.3  riastrad #ifdef __NetBSD__
     32  1.3  riastrad 	static volatile unsigned done = 0;
     33  1.3  riastrad 	va_list va;
     34  1.3  riastrad 
     35  1.3  riastrad 	va_start(va, fmt);
     36  1.3  riastrad 	printf("%s: %s ", device_xname(dev_priv->drm.dev), level);
     37  1.3  riastrad 	vprintf(fmt, va);
     38  1.3  riastrad 	va_end(va);
     39  1.3  riastrad 
     40  1.3  riastrad 	if (strncmp(level, KERN_ERR, strlen(KERN_ERR)) == 0 &&
     41  1.3  riastrad 	    atomic_swap_uint(&done, 1) == 0)
     42  1.3  riastrad 		printf("%s\n", NBSD_BUG_MSG);
     43  1.3  riastrad #else
     44  1.1  riastrad 	static bool shown_bug_once;
     45  1.1  riastrad 	struct device *kdev = dev_priv->drm.dev;
     46  1.1  riastrad 	bool is_error = level[1] <= KERN_ERR[1];
     47  1.1  riastrad 	bool is_debug = level[1] == KERN_DEBUG[1];
     48  1.1  riastrad 	struct va_format vaf;
     49  1.1  riastrad 	va_list args;
     50  1.1  riastrad 
     51  1.1  riastrad 	if (is_debug && !drm_debug_enabled(DRM_UT_DRIVER))
     52  1.1  riastrad 		return;
     53  1.1  riastrad 
     54  1.1  riastrad 	va_start(args, fmt);
     55  1.1  riastrad 
     56  1.1  riastrad 	vaf.fmt = fmt;
     57  1.1  riastrad 	vaf.va = &args;
     58  1.1  riastrad 
     59  1.1  riastrad 	if (is_error)
     60  1.1  riastrad 		dev_printk(level, kdev, "%pV", &vaf);
     61  1.1  riastrad 	else
     62  1.1  riastrad 		dev_printk(level, kdev, "[" DRM_NAME ":%ps] %pV",
     63  1.1  riastrad 			   __builtin_return_address(0), &vaf);
     64  1.1  riastrad 
     65  1.1  riastrad 	va_end(args);
     66  1.1  riastrad 
     67  1.1  riastrad 	if (is_error && !shown_bug_once) {
     68  1.1  riastrad 		/*
     69  1.1  riastrad 		 * Ask the user to file a bug report for the error, except
     70  1.1  riastrad 		 * if they may have caused the bug by fiddling with unsafe
     71  1.1  riastrad 		 * module parameters.
     72  1.1  riastrad 		 */
     73  1.1  riastrad 		if (!test_taint(TAINT_USER))
     74  1.1  riastrad 			dev_notice(kdev, "%s", FDO_BUG_MSG);
     75  1.1  riastrad 		shown_bug_once = true;
     76  1.1  riastrad 	}
     77  1.3  riastrad #endif
     78  1.1  riastrad }
     79  1.1  riastrad 
     80  1.1  riastrad #if IS_ENABLED(CONFIG_DRM_I915_DEBUG)
     81  1.1  riastrad static unsigned int i915_probe_fail_count;
     82  1.1  riastrad 
     83  1.1  riastrad int __i915_inject_probe_error(struct drm_i915_private *i915, int err,
     84  1.1  riastrad 			      const char *func, int line)
     85  1.1  riastrad {
     86  1.1  riastrad 	if (i915_probe_fail_count >= i915_modparams.inject_probe_failure)
     87  1.1  riastrad 		return 0;
     88  1.1  riastrad 
     89  1.1  riastrad 	if (++i915_probe_fail_count < i915_modparams.inject_probe_failure)
     90  1.1  riastrad 		return 0;
     91  1.1  riastrad 
     92  1.1  riastrad 	__i915_printk(i915, KERN_INFO,
     93  1.1  riastrad 		      "Injecting failure %d at checkpoint %u [%s:%d]\n",
     94  1.1  riastrad 		      err, i915_modparams.inject_probe_failure, func, line);
     95  1.1  riastrad 	i915_modparams.inject_probe_failure = 0;
     96  1.1  riastrad 	return err;
     97  1.1  riastrad }
     98  1.1  riastrad 
     99  1.1  riastrad bool i915_error_injected(void)
    100  1.1  riastrad {
    101  1.1  riastrad 	return i915_probe_fail_count && !i915_modparams.inject_probe_failure;
    102  1.1  riastrad }
    103  1.1  riastrad 
    104  1.1  riastrad #endif
    105  1.1  riastrad 
    106  1.1  riastrad void cancel_timer(struct timer_list *t)
    107  1.1  riastrad {
    108  1.4  riastrad #ifndef __NetBSD__
    109  1.1  riastrad 	if (!READ_ONCE(t->expires))
    110  1.1  riastrad 		return;
    111  1.4  riastrad #endif
    112  1.1  riastrad 
    113  1.1  riastrad 	del_timer(t);
    114  1.4  riastrad #ifndef __NetBSD__
    115  1.1  riastrad 	WRITE_ONCE(t->expires, 0);
    116  1.4  riastrad #endif
    117  1.1  riastrad }
    118  1.1  riastrad 
    119  1.1  riastrad void set_timer_ms(struct timer_list *t, unsigned long timeout)
    120  1.1  riastrad {
    121  1.1  riastrad 	if (!timeout) {
    122  1.1  riastrad 		cancel_timer(t);
    123  1.1  riastrad 		return;
    124  1.1  riastrad 	}
    125  1.1  riastrad 
    126  1.1  riastrad 	timeout = msecs_to_jiffies_timeout(timeout);
    127  1.1  riastrad 
    128  1.1  riastrad 	/*
    129  1.1  riastrad 	 * Paranoia to make sure the compiler computes the timeout before
    130  1.1  riastrad 	 * loading 'jiffies' as jiffies is volatile and may be updated in
    131  1.1  riastrad 	 * the background by a timer tick. All to reduce the complexity
    132  1.1  riastrad 	 * of the addition and reduce the risk of losing a jiffie.
    133  1.1  riastrad 	 */
    134  1.1  riastrad 	barrier();
    135  1.1  riastrad 
    136  1.1  riastrad 	mod_timer(t, jiffies + timeout);
    137  1.1  riastrad }
    138