Skip to content

Commit 3c53788

Browse files
agd5fairlied
authored andcommitted
drm/radeon/kms: add support for hardcoded edids in rom (v2)
Some servers hardcode an edid in rom so that they will work properly with KVMs. This is a port of the relevant code from the ddx. [airlied: reworked to validate edid at boot stage - and remove special quirk, if there is a valid EDID in the BIOS rom we'll just try and use it.] Signed-off-by: Alex Deucher <alexdeucher@gmail.com> Signed-off-by: Dave Airlie <airlied@redhat.com>
1 parent 2739d49 commit 3c53788

6 files changed

Lines changed: 71 additions & 17 deletions

File tree

‎drivers/gpu/drm/drm_edid.c‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@
6060
#define EDID_QUIRK_FIRST_DETAILED_PREFERRED (1 << 5)
6161
/* use +hsync +vsync for detailed mode */
6262
#define EDID_QUIRK_DETAILED_SYNC_PP (1 << 6)
63-
/* define the number of Extension EDID block */
64-
#define MAX_EDID_EXT_NUM 4
63+
6564

6665
#define LEVEL_DMT 0
6766
#define LEVEL_GTF 1
@@ -114,14 +113,14 @@ static const u8 edid_header[] = {
114113
};
115114

116115
/**
117-
* edid_is_valid - sanity check EDID data
116+
* drm_edid_is_valid - sanity check EDID data
118117
* @edid: EDID data
119118
*
120119
* Sanity check the EDID block by looking at the header, the version number
121120
* and the checksum. Return 0 if the EDID doesn't check out, or 1 if it's
122121
* valid.
123122
*/
124-
static bool edid_is_valid(struct edid *edid)
123+
bool drm_edid_is_valid(struct edid *edid)
125124
{
126125
int i, score = 0;
127126
u8 csum = 0;
@@ -163,6 +162,7 @@ static bool edid_is_valid(struct edid *edid)
163162
}
164163
return 0;
165164
}
165+
EXPORT_SYMBOL(drm_edid_is_valid);
166166

167167
/**
168168
* edid_vendor - match a string against EDID's obfuscated vendor field
@@ -1069,8 +1069,8 @@ static int add_detailed_info_eedid(struct drm_connector *connector,
10691069
}
10701070

10711071
/* Chose real EDID extension number */
1072-
edid_ext_num = edid->extensions > MAX_EDID_EXT_NUM ?
1073-
MAX_EDID_EXT_NUM : edid->extensions;
1072+
edid_ext_num = edid->extensions > DRM_MAX_EDID_EXT_NUM ?
1073+
DRM_MAX_EDID_EXT_NUM : edid->extensions;
10741074

10751075
/* Find CEA extension */
10761076
for (i = 0; i < edid_ext_num; i++) {
@@ -1152,7 +1152,7 @@ static int drm_ddc_read_edid(struct drm_connector *connector,
11521152
for (i = 0; i < 4; i++) {
11531153
if (drm_do_probe_ddc_edid(adapter, buf, len))
11541154
return -1;
1155-
if (edid_is_valid((struct edid *)buf))
1155+
if (drm_edid_is_valid((struct edid *)buf))
11561156
return 0;
11571157
}
11581158

@@ -1177,7 +1177,7 @@ struct edid *drm_get_edid(struct drm_connector *connector,
11771177
int ret;
11781178
struct edid *edid;
11791179

1180-
edid = kmalloc(EDID_LENGTH * (MAX_EDID_EXT_NUM + 1),
1180+
edid = kmalloc(EDID_LENGTH * (DRM_MAX_EDID_EXT_NUM + 1),
11811181
GFP_KERNEL);
11821182
if (edid == NULL) {
11831183
dev_warn(&connector->dev->pdev->dev,
@@ -1195,14 +1195,14 @@ struct edid *drm_get_edid(struct drm_connector *connector,
11951195
if (edid->extensions != 0) {
11961196
int edid_ext_num = edid->extensions;
11971197

1198-
if (edid_ext_num > MAX_EDID_EXT_NUM) {
1198+
if (edid_ext_num > DRM_MAX_EDID_EXT_NUM) {
11991199
dev_warn(&connector->dev->pdev->dev,
12001200
"The number of extension(%d) is "
12011201
"over max (%d), actually read number (%d)\n",
1202-
edid_ext_num, MAX_EDID_EXT_NUM,
1203-
MAX_EDID_EXT_NUM);
1202+
edid_ext_num, DRM_MAX_EDID_EXT_NUM,
1203+
DRM_MAX_EDID_EXT_NUM);
12041204
/* Reset EDID extension number to be read */
1205-
edid_ext_num = MAX_EDID_EXT_NUM;
1205+
edid_ext_num = DRM_MAX_EDID_EXT_NUM;
12061206
}
12071207
/* Read EDID including extensions too */
12081208
ret = drm_ddc_read_edid(connector, adapter, (char *)edid,
@@ -1245,8 +1245,8 @@ bool drm_detect_hdmi_monitor(struct edid *edid)
12451245
goto end;
12461246

12471247
/* Chose real EDID extension number */
1248-
edid_ext_num = edid->extensions > MAX_EDID_EXT_NUM ?
1249-
MAX_EDID_EXT_NUM : edid->extensions;
1248+
edid_ext_num = edid->extensions > DRM_MAX_EDID_EXT_NUM ?
1249+
DRM_MAX_EDID_EXT_NUM : edid->extensions;
12501250

12511251
/* Find CEA extension */
12521252
for (i = 0; i < edid_ext_num; i++) {
@@ -1303,7 +1303,7 @@ int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid)
13031303
if (edid == NULL) {
13041304
return 0;
13051305
}
1306-
if (!edid_is_valid(edid)) {
1306+
if (!drm_edid_is_valid(edid)) {
13071307
dev_warn(&connector->dev->pdev->dev, "%s: EDID invalid.\n",
13081308
drm_get_connector_name(connector));
13091309
return 0;

‎drivers/gpu/drm/radeon/radeon_combios.c‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,39 @@ static uint16_t combios_get_table_offset(struct drm_device *dev,
443443

444444
}
445445

446+
bool radeon_combios_check_hardcoded_edid(struct radeon_device *rdev)
447+
{
448+
int edid_info;
449+
struct edid *edid;
450+
edid_info = combios_get_table_offset(rdev->ddev, COMBIOS_HARDCODED_EDID_TABLE);
451+
if (!edid_info)
452+
return false;
453+
454+
edid = kmalloc(EDID_LENGTH * (DRM_MAX_EDID_EXT_NUM + 1),
455+
GFP_KERNEL);
456+
if (edid == NULL)
457+
return false;
458+
459+
memcpy((unsigned char *)edid,
460+
(unsigned char *)(rdev->bios + edid_info), EDID_LENGTH);
461+
462+
if (!drm_edid_is_valid(edid)) {
463+
kfree(edid);
464+
return false;
465+
}
466+
467+
rdev->mode_info.bios_hardcoded_edid = edid;
468+
return true;
469+
}
470+
471+
struct edid *
472+
radeon_combios_get_hardcoded_edid(struct radeon_device *rdev)
473+
{
474+
if (rdev->mode_info.bios_hardcoded_edid)
475+
return rdev->mode_info.bios_hardcoded_edid;
476+
return NULL;
477+
}
478+
446479
static struct radeon_i2c_bus_rec combios_setup_i2c_bus(struct radeon_device *rdev,
447480
int ddc_line)
448481
{

‎drivers/gpu/drm/radeon/radeon_display.c‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@ static bool radeon_setup_enc_conn(struct drm_device *dev)
352352

353353
int radeon_ddc_get_modes(struct radeon_connector *radeon_connector)
354354
{
355+
struct drm_device *dev = radeon_connector->base.dev;
356+
struct radeon_device *rdev = dev->dev_private;
355357
int ret = 0;
356358

357359
if ((radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_DisplayPort) ||
@@ -366,7 +368,9 @@ int radeon_ddc_get_modes(struct radeon_connector *radeon_connector)
366368
if (!radeon_connector->edid) {
367369
radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
368370
}
369-
371+
/* some servers provide a hardcoded edid in rom for KVMs */
372+
if (!radeon_connector->edid)
373+
radeon_connector->edid = radeon_combios_get_hardcoded_edid(rdev);
370374
if (radeon_connector->edid) {
371375
drm_mode_connector_update_edid_property(&radeon_connector->base, radeon_connector->edid);
372376
ret = drm_add_edid_modes(&radeon_connector->base, radeon_connector->edid);
@@ -829,6 +833,12 @@ int radeon_modeset_init(struct radeon_device *rdev)
829833
return ret;
830834
}
831835

836+
/* check combios for a valid hardcoded EDID - Sun servers */
837+
if (!rdev->is_atom_bios) {
838+
/* check for hardcoded EDID in BIOS */
839+
radeon_combios_check_hardcoded_edid(rdev);
840+
}
841+
832842
if (rdev->flags & RADEON_SINGLE_CRTC)
833843
num_crtc = 1;
834844

@@ -850,6 +860,8 @@ int radeon_modeset_init(struct radeon_device *rdev)
850860

851861
void radeon_modeset_fini(struct radeon_device *rdev)
852862
{
863+
kfree(rdev->mode_info.bios_hardcoded_edid);
864+
853865
if (rdev->mode_info.mode_config_initialized) {
854866
radeon_hpd_fini(rdev);
855867
drm_mode_config_cleanup(rdev->ddev);

‎drivers/gpu/drm/radeon/radeon_mode.h‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ struct radeon_mode_info {
207207
struct drm_property *tv_std_property;
208208
/* legacy TMDS PLL detect */
209209
struct drm_property *tmds_pll_property;
210-
210+
/* hardcoded DFP edid from BIOS */
211+
struct edid *bios_hardcoded_edid;
211212
};
212213

213214
#define MAX_H_CODE_TIMING_LEN 32
@@ -479,6 +480,9 @@ extern int radeon_crtc_cursor_set(struct drm_crtc *crtc,
479480
extern int radeon_crtc_cursor_move(struct drm_crtc *crtc,
480481
int x, int y);
481482

483+
extern bool radeon_combios_check_hardcoded_edid(struct radeon_device *rdev);
484+
extern struct edid *
485+
radeon_combios_get_hardcoded_edid(struct radeon_device *rdev);
482486
extern bool radeon_atom_get_clock_info(struct drm_device *dev);
483487
extern bool radeon_combios_get_clock_info(struct drm_device *dev);
484488
extern struct radeon_encoder_atom_dig *

‎include/drm/drm_crtc.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,4 +801,6 @@ extern struct drm_display_mode *drm_gtf_mode(struct drm_device *dev,
801801
bool interlaced, int margins);
802802
extern int drm_add_modes_noedid(struct drm_connector *connector,
803803
int hdisplay, int vdisplay);
804+
805+
extern bool drm_edid_is_valid(struct edid *edid);
804806
#endif /* __DRM_CRTC_H__ */

‎include/drm/drm_edid.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,7 @@ struct edid {
201201

202202
#define EDID_PRODUCT_ID(e) ((e)->prod_code[0] | ((e)->prod_code[1] << 8))
203203

204+
/* define the number of Extension EDID block */
205+
#define DRM_MAX_EDID_EXT_NUM 4
206+
204207
#endif /* __DRM_EDID_H__ */

0 commit comments

Comments
 (0)