xref: /linux/drivers/gpu/drm/arm/malidp_drv.h (revision 7ae9fb1b7ecbb5d85d07857943f677fd1a559b18)
1e559355aSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2ad49f860SLiviu Dudau /*
3ad49f860SLiviu Dudau  * (C) COPYRIGHT 2016 ARM Limited. All rights reserved.
4ad49f860SLiviu Dudau  * Author: Liviu Dudau <Liviu.Dudau@arm.com>
5ad49f860SLiviu Dudau  *
6ad49f860SLiviu Dudau  * ARM Mali DP500/DP550/DP650 KMS/DRM driver structures
7ad49f860SLiviu Dudau  */
8ad49f860SLiviu Dudau 
9ad49f860SLiviu Dudau #ifndef __MALIDP_DRV_H__
10ad49f860SLiviu Dudau #define __MALIDP_DRV_H__
11ad49f860SLiviu Dudau 
12ad49f860SLiviu Dudau #include <linux/mutex.h>
13ad49f860SLiviu Dudau #include <linux/wait.h>
14613c5c7fSAlexandru Gheorghe #include <linux/spinlock.h>
15535d1b94SSam Ravnborg 
16535d1b94SSam Ravnborg #include <drm/drm_writeback.h>
17535d1b94SSam Ravnborg #include <drm/drm_encoder.h>
18535d1b94SSam Ravnborg 
19ad49f860SLiviu Dudau #include "malidp_hw.h"
20ad49f860SLiviu Dudau 
211cb3cbe7SLiviu Dudau #define MALIDP_CONFIG_VALID_INIT	0
221cb3cbe7SLiviu Dudau #define MALIDP_CONFIG_VALID_DONE	1
231cb3cbe7SLiviu Dudau #define MALIDP_CONFIG_START		0xd0
241cb3cbe7SLiviu Dudau 
25613c5c7fSAlexandru Gheorghe struct malidp_error_stats {
26613c5c7fSAlexandru Gheorghe 	s32 num_errors;
27613c5c7fSAlexandru Gheorghe 	u32 last_error_status;
28613c5c7fSAlexandru Gheorghe 	s64 last_error_vblank;
29613c5c7fSAlexandru Gheorghe };
30613c5c7fSAlexandru Gheorghe 
31ad49f860SLiviu Dudau struct malidp_drm {
32aefae871SDanilo Krummrich 	struct drm_device base;
33ad49f860SLiviu Dudau 	struct malidp_hw_device *dev;
34ad49f860SLiviu Dudau 	struct drm_crtc crtc;
358cbc5cafSBrian Starkey 	struct drm_writeback_connector mw_connector;
36ad49f860SLiviu Dudau 	wait_queue_head_t wq;
37d862b2d6SLiviu Dudau 	struct drm_pending_vblank_event *event;
38ad49f860SLiviu Dudau 	atomic_t config_valid;
3950c7512fSLiviu Dudau 	u32 core_id;
40613c5c7fSAlexandru Gheorghe #ifdef CONFIG_DEBUG_FS
41613c5c7fSAlexandru Gheorghe 	struct malidp_error_stats de_errors;
42613c5c7fSAlexandru Gheorghe 	struct malidp_error_stats se_errors;
43613c5c7fSAlexandru Gheorghe 	/* Protects errors stats */
44613c5c7fSAlexandru Gheorghe 	spinlock_t errors_lock;
45613c5c7fSAlexandru Gheorghe #endif
46ad49f860SLiviu Dudau };
47ad49f860SLiviu Dudau 
48*1b93d3cbSDanilo Krummrich #define drm_to_malidp(x) container_of(x, struct malidp_drm, base)
49ad49f860SLiviu Dudau #define crtc_to_malidp_device(x) container_of(x, struct malidp_drm, crtc)
50ad49f860SLiviu Dudau 
51ad49f860SLiviu Dudau struct malidp_plane {
52ad49f860SLiviu Dudau 	struct drm_plane base;
53ad49f860SLiviu Dudau 	struct malidp_hw_device *hwdev;
54ad49f860SLiviu Dudau 	const struct malidp_layer *layer;
55ad49f860SLiviu Dudau };
56ad49f860SLiviu Dudau 
571f23a56aSJamie Fox enum mmu_prefetch_mode {
581f23a56aSJamie Fox 	MALIDP_PREFETCH_MODE_NONE,
591f23a56aSJamie Fox 	MALIDP_PREFETCH_MODE_PARTIAL,
601f23a56aSJamie Fox 	MALIDP_PREFETCH_MODE_FULL,
611f23a56aSJamie Fox };
621f23a56aSJamie Fox 
63ad49f860SLiviu Dudau struct malidp_plane_state {
64ad49f860SLiviu Dudau 	struct drm_plane_state base;
65ad49f860SLiviu Dudau 
66ad49f860SLiviu Dudau 	/* size of the required rotation memory if plane is rotated */
67ad49f860SLiviu Dudau 	u32 rotmem_size;
6870c94a3cSBrian Starkey 	/* internal format ID */
6970c94a3cSBrian Starkey 	u8 format;
7070c94a3cSBrian Starkey 	u8 n_planes;
711f23a56aSJamie Fox 	enum mmu_prefetch_mode mmu_prefetch_mode;
721f23a56aSJamie Fox 	u32 mmu_prefetch_pgsize;
73ad49f860SLiviu Dudau };
74ad49f860SLiviu Dudau 
75ad49f860SLiviu Dudau #define to_malidp_plane(x) container_of(x, struct malidp_plane, base)
76ad49f860SLiviu Dudau #define to_malidp_plane_state(x) container_of(x, struct malidp_plane_state, base)
77ad49f860SLiviu Dudau 
7899665d07SMihail Atanassov struct malidp_crtc_state {
7999665d07SMihail Atanassov 	struct drm_crtc_state base;
8002725d31SMihail Atanassov 	u32 gamma_coeffs[MALIDP_COEFFTAB_NUM_COEFFS];
816954f245SMihail Atanassov 	u32 coloradj_coeffs[MALIDP_COLORADJ_NUM_COEFFS];
8228ce675bSMihail Atanassov 	struct malidp_se_config scaler_config;
8328ce675bSMihail Atanassov 	/* Bitfield of all the planes that have requested a scaled output. */
8428ce675bSMihail Atanassov 	u8 scaled_planes_mask;
8599665d07SMihail Atanassov };
8699665d07SMihail Atanassov 
8799665d07SMihail Atanassov #define to_malidp_crtc_state(x) container_of(x, struct malidp_crtc_state, base)
8899665d07SMihail Atanassov 
89ad49f860SLiviu Dudau int malidp_de_planes_init(struct drm_device *drm);
90ad49f860SLiviu Dudau int malidp_crtc_init(struct drm_device *drm);
91ad49f860SLiviu Dudau 
925e290226SAyan Kumar Halder bool malidp_hw_format_is_linear_only(u32 format);
935e290226SAyan Kumar Halder bool malidp_hw_format_is_afbc_only(u32 format);
945e290226SAyan Kumar Halder 
955e290226SAyan Kumar Halder bool malidp_format_mod_supported(struct drm_device *drm,
965e290226SAyan Kumar Halder 				 u32 format, u64 modifier);
975e290226SAyan Kumar Halder 
98613c5c7fSAlexandru Gheorghe #ifdef CONFIG_DEBUG_FS
99613c5c7fSAlexandru Gheorghe void malidp_error(struct malidp_drm *malidp,
100613c5c7fSAlexandru Gheorghe 		  struct malidp_error_stats *error_stats, u32 status,
101613c5c7fSAlexandru Gheorghe 		  u64 vblank);
102613c5c7fSAlexandru Gheorghe #endif
103613c5c7fSAlexandru Gheorghe 
104ad49f860SLiviu Dudau /* often used combination of rotational bits */
105c2c446adSRobert Foss #define MALIDP_ROTATED_MASK	(DRM_MODE_ROTATE_90 | DRM_MODE_ROTATE_270)
106ad49f860SLiviu Dudau 
107ad49f860SLiviu Dudau #endif  /* __MALIDP_DRV_H__ */
108