xref: /linux/drivers/gpu/drm/drm_panic_internal.h (revision cb8fef4b07f71da01843457b66e579ad248a625e)
1 /* SPDX-License-Identifier: GPL-2.0 or MIT */
2 
3 /*
4  * Copyright (c) 2024 Intel
5  * Copyright (c) 2024 Red Hat
6  */
7 
8 #ifndef __DRM_PANIC_INTERNAL_H__
9 #define __DRM_PANIC_INTERNAL_H__
10 
11 #include <linux/spinlock.h>
12 
13 struct drm_device;
14 
15 #ifdef CONFIG_DRM_PANIC
16 
17 /**
18  * drm_panic_lock - protect panic printing relevant state
19  * @dev: struct drm_device
20  * @flags: unsigned long irq flags you need to pass to the unlock() counterpart
21  *
22  * This function must be called to protect software and hardware state that the
23  * panic printing code must be able to rely on. The protected sections must be
24  * as small as possible. It uses the irqsave/irqrestore variant, and can be
25  * called from irq handler. Examples include:
26  *
27  * - Access to peek/poke or other similar registers, if that is the way the
28  *   driver prints the pixels into the scanout buffer at panic time.
29  *
30  * - Updates to pointers like &drm_plane.state, allowing the panic handler to
31  *   safely deference these. This is done in drm_atomic_helper_swap_state().
32  *
33  * - An state that isn't invariant and that the driver must be able to access
34  *   during panic printing.
35  */
36 #define drm_panic_lock(dev, flags) \
37 	raw_spin_lock_irqsave(&(dev)->mode_config.panic_lock, flags)
38 
39 /**
40  * drm_panic_unlock - end of the panic printing critical section
41  * @dev: struct drm_device
42  * @flags: irq flags that were returned when acquiring the lock
43  *
44  * Unlocks the raw spinlock acquired by either drm_panic_lock() or
45  * drm_panic_trylock().
46  */
47 #define drm_panic_unlock(dev, flags) \
48 	raw_spin_unlock_irqrestore(&(dev)->mode_config.panic_lock, flags)
49 
50 #else
51 static inline void drm_panic_lock(struct drm_device *dev, unsigned long flags) {}
52 static inline void drm_panic_unlock(struct drm_device *dev, unsigned long flags) {}
53 #endif
54 
55 #if IS_ENABLED(CONFIG_DRM_PANIC_HELPER)
56 /* drm_panic_helper.c */
57 int __init drm_panic_helper_init(void);
58 void __exit drm_panic_helper_exit(void);
59 #else
60 static inline int __init drm_panic_helper_init(void)
61 {
62 	return 0;
63 }
64 
65 static inline void __exit drm_panic_helper_exit(void)
66 { }
67 #endif
68 
69 #endif /* __DRM_PANIC_INTERNAL_H__ */
70