xref: /linux/drivers/gpu/drm/vc4/tests/vc4_mock.h (revision 249ebf3f65f8530beb2cbfb91bff1d83ba88d23c)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 #ifndef VC4_MOCK_H_
4 #define VC4_MOCK_H_
5 
6 #include "../vc4_drv.h"
7 
8 static inline
9 struct drm_crtc *vc4_find_crtc_for_encoder(struct kunit *test,
10 					   struct drm_device *drm,
11 					   struct drm_encoder *encoder)
12 {
13 	struct drm_crtc *crtc;
14 
15 	KUNIT_ASSERT_EQ(test, hweight32(encoder->possible_crtcs), 1);
16 
17 	drm_for_each_crtc(crtc, drm)
18 		if (encoder->possible_crtcs & drm_crtc_mask(crtc))
19 			return crtc;
20 
21 	return NULL;
22 }
23 
24 struct vc4_dummy_plane {
25 	struct vc4_plane plane;
26 };
27 
28 struct vc4_dummy_plane *vc4_dummy_plane(struct kunit *test,
29 					struct drm_device *drm,
30 					enum drm_plane_type type);
31 
32 struct vc4_dummy_crtc {
33 	struct vc4_crtc crtc;
34 };
35 
36 struct vc4_dummy_crtc *vc4_mock_pv(struct kunit *test,
37 				   struct drm_device *drm,
38 				   struct drm_plane *plane,
39 				   const struct vc4_crtc_data *data);
40 
41 struct vc4_dummy_output {
42 	struct vc4_encoder encoder;
43 	struct drm_connector connector;
44 };
45 
46 #define encoder_to_vc4_dummy_output(_enc)				\
47 	container_of_const(_enc, struct vc4_dummy_output, encoder.base)
48 
49 struct vc4_dummy_output *vc4_dummy_output(struct kunit *test,
50 					  struct drm_device *drm,
51 					  struct drm_crtc *crtc,
52 					  enum vc4_encoder_type vc4_encoder_type,
53 					  unsigned int kms_encoder_type,
54 					  unsigned int connector_type);
55 
56 struct vc4_dev *vc4_mock_device(struct kunit *test);
57 struct vc4_dev *vc5_mock_device(struct kunit *test);
58 
59 int vc4_mock_atomic_add_output(struct kunit *test,
60 			       struct drm_atomic_state *state,
61 			       enum vc4_encoder_type type);
62 int vc4_mock_atomic_del_output(struct kunit *test,
63 			       struct drm_atomic_state *state,
64 			       enum vc4_encoder_type type);
65 
66 #endif // VC4_MOCK_H_
67