Skip to content

Commit dd62695

Browse files
committed
xfree86: ddc: new entry point for EDID parsing
The old ones didn't know the block size, so couldn't deduce the block type version. With upcoming new features, eg. HDR, we need to know the block type version in order to know what we can extract from it. This new function should now be used by all drivers, the old ones shall be phased out. That commit should be backported to 25.0 and 25.1 releases, so drivers can remain compatible with all existing release lines. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
1 parent 8cbf96e commit dd62695

File tree

2 files changed

+47
-7
lines changed

2 files changed

+47
-7
lines changed

hw/xfree86/ddc/interpret_edid.c

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626
#include <xorg-config.h>
2727

28+
#include <stdbool.h>
2829
#include <stdint.h>
2930
#include <string.h>
3031

@@ -188,15 +189,18 @@ encode_aspect_ratio(xf86MonPtr m)
188189
}
189190
}
190191

191-
xf86MonPtr
192-
xf86InterpretEDID(int scrnIndex, uint8_t * block)
192+
static xf86MonPtr parseEDID(int scrnIndex, uint8_t *block, size_t size, bool copy)
193193
{
194-
xf86MonPtr m;
195-
196-
if (!block)
197-
return NULL;
198-
if (!(m = XNFcallocarray(1, sizeof(xf86Monitor))))
194+
xf86MonPtr m = calloc(1, sizeof(xf86Monitor) + (copy ? size : 0));
195+
if (!m)
199196
return NULL;
197+
198+
/* make a copy of the EDID block for later reference */
199+
if (copy) {
200+
memcpy(&(m[1]), block, size);
201+
block = (uint8_t*)&m[1];
202+
}
203+
200204
m->scrnIndex = scrnIndex;
201205
m->rawData = block;
202206

@@ -215,13 +219,36 @@ xf86InterpretEDID(int scrnIndex, uint8_t * block)
215219
handle_edid_quirks(m);
216220
encode_aspect_ratio(m);
217221

222+
if (size > 128)
223+
m->flags |= EDID_COMPLETE_RAWDATA;
224+
225+
/* possibly add more extended parsing here, eg. HDR information */
226+
218227
return m;
219228

220229
error:
221230
free(m);
222231
return NULL;
223232
}
224233

234+
/* new entry point, should be used whenever possible */
235+
xf86MonPtr xf86ParseEDID(ScrnInfoPtr pScrn, uint8_t *block, size_t size)
236+
{
237+
if (!pScrn || !block || !size)
238+
return NULL;
239+
240+
return parseEDID(pScrn->scrnIndex, block, size, true);
241+
}
242+
243+
/* old entry point, deprecated but still needed for backwards compat */
244+
xf86MonPtr xf86InterpretEDID(int scrnIndex, uint8_t *block)
245+
{
246+
if (!block)
247+
return NULL;
248+
249+
return parseEDID(scrnIndex, block, EDID1_LEN, false);
250+
}
251+
225252
static int
226253
get_cea_detail_timing(uint8_t * blk, xf86MonPtr mon,
227254
struct detailed_monitor_section *det_mon)

hw/xfree86/ddc/xf86DDC.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,17 @@ extern _X_EXPORT xf86MonPtr xf86InterpretEEDID(int screenIndex, uint8_t * block)
4242

4343
extern _X_EXPORT Bool xf86SetDDCproperties(ScrnInfoPtr pScreen, xf86MonPtr DDC);
4444

45+
/*
46+
* parse EDID block and return a newly allocated xf86Monitor
47+
*
48+
* the data block will be copied into the structure (actually right after the struct)
49+
* and thus automatically be freed when the returned struct is freed.
50+
*
51+
* @param screenIndex index of the screen, will be recorded in the xf86Monitor
52+
* @param block the EDID block to parse
53+
* @param size size of the EDID block (128 or larger for extended types)
54+
* @return newly allocated xf86MonRec or NULL on failure
55+
*/
56+
_X_EXPORT xf86MonPtr xf86ParseEDID(ScrnInfoPtr pScreen, uint8_t *block, size_t size);
57+
4558
#endif

0 commit comments

Comments
 (0)