e2e5f52cafef520e19cd4ffad389c90d176b9403
[src/drm-lease-manager.git] / drm-lease-manager / test / test-drm-device.h
1 /* Copyright 2020-2021 IGEL Co., Ltd.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #ifndef TEST_DRM_DEVICE_H
17 #define TEST_DRM_DEVICE_H
18
19 #include <xf86drmMode.h>
20
21 /* TEST_DRM_DEVICE can be the path to any
22  * file that can be opened.
23  */
24 #define TEST_DRM_DEVICE "/dev/null"
25
26 struct drm_device {
27         drmModeRes resources;
28         drmModePlaneRes plane_resources;
29         struct {
30                 drmModeConnector *connectors;
31                 drmModeEncoder *encoders;
32                 drmModePlane *planes;
33                 bool free_on_reset;
34         } layout;
35
36         struct {
37                 int count;
38                 uint32_t *lessee_ids;
39                 int count_lessee_ids;
40         } leases;
41 };
42
43 extern struct drm_device test_device;
44
45 bool setup_drm_test_device(int crtcs, int connectors, int encoders, int planes);
46 void setup_test_device_layout(drmModeConnector *connectors,
47                               drmModeEncoder *encoders, drmModePlane *planes);
48 void setup_layout_simple_test_device(int connectors, int planes);
49 void reset_drm_test_device(void);
50
51 drmModeConnectorPtr get_connector(int fd, uint32_t id);
52 drmModeEncoderPtr get_encoder(int fd, uint32_t id);
53 drmModePlanePtr get_plane(int fd, uint32_t id);
54 int create_lease(int fd, const uint32_t *objects, int num_objects, int flags,
55                  uint32_t *lessee_id);
56
57 #define TEST_DEVICE_RESOURCES (&test_device.resources)
58 #define TEST_DEVICE_PLANE_RESOURCES (&test_device.plane_resources)
59
60 #define CRTC_ID(x) (test_device.resources.crtcs[x])
61 #define CONNECTOR_ID(x) (test_device.resources.connectors[x])
62 #define ENCODER_ID(x) (test_device.resources.encoders[x])
63 #define PLANE_ID(x) (test_device.plane_resources.planes[x])
64 #define LESSEE_ID(x) (test_device.leases.lessee_ids[x])
65
66 #define CONNECTOR(cid, eid, encs, enc_cnt)                   \
67         {                                                    \
68                 .connector_id = cid, .encoder_id = eid,      \
69                 .count_encoders = enc_cnt, .encoders = encs, \
70         }
71
72 #define ENCODER(eid, crtc, crtc_mask)               \
73         {                                           \
74                 .encoder_id = eid, .crtc_id = crtc, \
75                 .possible_crtcs = crtc_mask,        \
76         }
77
78 #define PLANE(pid, crtc_mask)                                 \
79         {                                                     \
80                 .plane_id = pid, .possible_crtcs = crtc_mask, \
81         }
82
83 #endif