hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
From 65b545d762100c4012c2f8176f5c296d5bfcbdc4 Mon Sep 17 00:00:00 2001
From: Jeffy Chen <jeffy.chen@rock-chips.com>
Date: Sat, 15 Dec 2018 12:20:01 +0800
Subject: [PATCH 2/5] modetest: Speed up dumping info
 
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
---
 tests/modetest/modetest.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)
 
diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c
index 8ff6c80..5291ca0 100644
--- a/tests/modetest/modetest.c
+++ b/tests/modetest/modetest.c
@@ -50,6 +50,7 @@
 #include <strings.h>
 #include <errno.h>
 #include <poll.h>
+#include <fcntl.h>
 #include <sys/time.h>
 #if HAVE_SYS_SELECT_H
 #include <sys/select.h>
@@ -71,6 +72,10 @@
 static enum util_fill_pattern primary_fill = UTIL_PATTERN_SMPTE;
 static enum util_fill_pattern secondary_fill = UTIL_PATTERN_TILES;
 
+int encoders = 0, connectors = 0, crtcs = 0, planes = 0, fbs = 0;
+int dump_only;
+#define need_resource(type) (!dump_only || type##s)
+
 struct crtc {
     drmModeCrtc *crtc;
     drmModeObjectProperties *props;
@@ -485,7 +490,7 @@ static void dump_crtcs(struct device *dev)
     printf("\n");
 }
 
-static void dump_framebuffers(struct device *dev)
+static void dump_fbs(struct device *dev)
 {
     drmModeFB *fb;
     int i;
@@ -554,6 +559,7 @@ static void free_resources(struct resources *res)
         return;
 
 #define free_resource(_res, type, Type)                    \
+    if (need_resource(type))                        \
     do {                                    \
         if (!(_res)->type##s)                        \
             break;                            \
@@ -566,6 +572,7 @@ static void free_resources(struct resources *res)
     } while (0)
 
 #define free_properties(_res, type)                    \
+    if (need_resource(type))                        \
     do {                                    \
         for (i = 0; i < (int)(_res)->count_##type##s; ++i) {    \
             unsigned int j;                                        \
@@ -578,10 +585,10 @@ static void free_resources(struct resources *res)
 
     free_properties(res, plane);
     free_resource(res, plane, Plane);
-
     free_properties(res, connector);
     free_properties(res, crtc);
 
+    if (need_resource(connector))
     for (i = 0; i < res->count_connectors; i++)
         free(res->connectors[i].name);
 
@@ -630,6 +637,7 @@ static struct resources *get_resources(struct device *dev)
     }
 
 #define get_resource(_res, __res, type, Type)                    \
+    if (need_resource(type))                        \
     do {                                    \
         for (i = 0; i < (int)(_res)->count_##type##s; ++i) {    \
             uint32_t type##id = (__res)->type##s[i];            \
@@ -650,6 +658,7 @@ static struct resources *get_resources(struct device *dev)
     drmModeFreeResources(_res);
 
     /* Set the name of all connectors based on the type name and the per-type ID. */
+    if (need_resource(connector))
     for (i = 0; i < res->count_connectors; i++) {
         struct connector *connector = &res->connectors[i];
         drmModeConnector *conn = connector->connector;
@@ -663,6 +672,7 @@ static struct resources *get_resources(struct device *dev)
     }
 
 #define get_properties(_res, type, Type)                    \
+    if (need_resource(type))                        \
     do {                                    \
         for (i = 0; i < (int)(_res)->count_##type##s; ++i) {    \
             struct type *obj = &res->type##s[i];            \
@@ -690,6 +700,7 @@ static struct resources *get_resources(struct device *dev)
     get_properties(res, crtc, CRTC);
     get_properties(res, connector, CONNECTOR);
 
+    if (need_resource(crtc))
     for (i = 0; i < res->count_crtcs; ++i)
         res->crtcs[i].mode = &res->crtcs[i].crtc->mode;
 
@@ -2026,7 +2037,6 @@ int main(int argc, char **argv)
     struct device dev;
 
     int c;
-    int encoders = 0, connectors = 0, crtcs = 0, planes = 0, framebuffers = 0;
     int drop_master = 0;
     int test_vsync = 0;
     int test_cursor = 0;
@@ -2070,7 +2080,7 @@ int main(int argc, char **argv)
             encoders = 1;
             break;
         case 'f':
-            framebuffers = 1;
+            fbs = 1;
             break;
         case 'F':
             parse_fill_patterns(optarg);
@@ -2143,7 +2153,7 @@ int main(int argc, char **argv)
 
     /* Dump all the details when no* arguments are provided. */
     if (!args)
-        encoders = connectors = crtcs = planes = framebuffers = 1;
+        encoders = connectors = crtcs = planes = fbs = 1;
 
     if (test_vsync && !count) {
         fprintf(stderr, "page flipping requires at least one -s option.\n");
@@ -2159,7 +2169,11 @@ int main(int argc, char **argv)
         return -1;
     }
 
-    dev.fd = util_open(device, module);
+    dump_only = !count && !plane_count && !prop_count;
+    if (dump_only && !device && !module)
+        dev.fd = open("/dev/dri/card0", O_RDWR);
+    else
+        dev.fd = util_open(device, module);
     if (dev.fd < 0)
         return -1;
 
@@ -2186,7 +2200,7 @@ int main(int argc, char **argv)
     dump_resource(&dev, connectors);
     dump_resource(&dev, crtcs);
     dump_resource(&dev, planes);
-    dump_resource(&dev, framebuffers);
+    dump_resource(&dev, fbs);
 
     for (i = 0; i < prop_count; ++i)
         set_property(&dev, &prop_args[i]);
-- 
2.20.1