Commit cef1d00c authored by Mark Kettenis's avatar Mark Kettenis Committed by Alex Deucher

drm/radeon: fix combios tables on older cards

Noticed that my old Radeon 7500 hung after printing

   drm: GPU not posted. posting now...

when it wasn't selected as the primary card the BIOS.  Some digging
revealed that it was hanging in combios_parse_mmio_table() while
parsing the ASIC INIT 3 table.  Looking at the BIOS ROM for the card,
it becomes obvious that there is no ASIC INIT 3 table in the BIOS.
The code is just processing random garbage.  No surprise it hangs!

Why do I say that there is no ASIC INIT 3 table is the BIOS?  This
table is found through the MISC INFO table.  The MISC INFO table can
be found at offset 0x5e in the COMBIOS header.  But the header is
smaller than that.  The COMBIOS header starts at offset 0x126.  The
standard PCI Data Structure (the bit that starts with 'PCIR') lives at
offset 0x180.  That means that the COMBIOS header can not be larger
than 0x5a bytes and therefore cannot contain a MISC INFO table.

I looked at a dozen or so BIOS images, some my own, some downloaded from:

    <http://www.techpowerup.com/vgabios/index.php?manufacturer=ATI&page=1>

It is fairly obvious that the size of the COMBIOS header can be found
at offset 0x6 of the header.  Not sure if it is a 16-bit number or
just an 8-bit number, but that doesn't really matter since the tables
seems to be always smaller than 256 bytes.

So I think combios_get_table_offset() should check if the requested
table is present.  This can be done by checking the offset against the
size of the header.  See the diff below.  The diff is against the WIP
OpenBSD codebase that roughly corresponds to Linux 3.8.13 at this
point.  But I don't think this bit of the code changed much since
then.

For what it is worth:
Signed-off-by: default avatarMark Kettenis <kettenis@openbsd.org>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
Cc: stable@vger.kernel.org
parent 03ed8cf9
...@@ -147,7 +147,7 @@ static uint16_t combios_get_table_offset(struct drm_device *dev, ...@@ -147,7 +147,7 @@ static uint16_t combios_get_table_offset(struct drm_device *dev,
enum radeon_combios_table_offset table) enum radeon_combios_table_offset table)
{ {
struct radeon_device *rdev = dev->dev_private; struct radeon_device *rdev = dev->dev_private;
int rev; int rev, size;
uint16_t offset = 0, check_offset; uint16_t offset = 0, check_offset;
if (!rdev->bios) if (!rdev->bios)
...@@ -156,174 +156,106 @@ static uint16_t combios_get_table_offset(struct drm_device *dev, ...@@ -156,174 +156,106 @@ static uint16_t combios_get_table_offset(struct drm_device *dev,
switch (table) { switch (table) {
/* absolute offset tables */ /* absolute offset tables */
case COMBIOS_ASIC_INIT_1_TABLE: case COMBIOS_ASIC_INIT_1_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0xc); check_offset = 0xc;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_BIOS_SUPPORT_TABLE: case COMBIOS_BIOS_SUPPORT_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x14); check_offset = 0x14;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_DAC_PROGRAMMING_TABLE: case COMBIOS_DAC_PROGRAMMING_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x2a); check_offset = 0x2a;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_MAX_COLOR_DEPTH_TABLE: case COMBIOS_MAX_COLOR_DEPTH_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x2c); check_offset = 0x2c;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_CRTC_INFO_TABLE: case COMBIOS_CRTC_INFO_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x2e); check_offset = 0x2e;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_PLL_INFO_TABLE: case COMBIOS_PLL_INFO_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x30); check_offset = 0x30;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_TV_INFO_TABLE: case COMBIOS_TV_INFO_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x32); check_offset = 0x32;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_DFP_INFO_TABLE: case COMBIOS_DFP_INFO_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x34); check_offset = 0x34;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_HW_CONFIG_INFO_TABLE: case COMBIOS_HW_CONFIG_INFO_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x36); check_offset = 0x36;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_MULTIMEDIA_INFO_TABLE: case COMBIOS_MULTIMEDIA_INFO_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x38); check_offset = 0x38;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_TV_STD_PATCH_TABLE: case COMBIOS_TV_STD_PATCH_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x3e); check_offset = 0x3e;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_LCD_INFO_TABLE: case COMBIOS_LCD_INFO_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x40); check_offset = 0x40;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_MOBILE_INFO_TABLE: case COMBIOS_MOBILE_INFO_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x42); check_offset = 0x42;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_PLL_INIT_TABLE: case COMBIOS_PLL_INIT_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x46); check_offset = 0x46;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_MEM_CONFIG_TABLE: case COMBIOS_MEM_CONFIG_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x48); check_offset = 0x48;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_SAVE_MASK_TABLE: case COMBIOS_SAVE_MASK_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x4a); check_offset = 0x4a;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_HARDCODED_EDID_TABLE: case COMBIOS_HARDCODED_EDID_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x4c); check_offset = 0x4c;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_ASIC_INIT_2_TABLE: case COMBIOS_ASIC_INIT_2_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x4e); check_offset = 0x4e;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_CONNECTOR_INFO_TABLE: case COMBIOS_CONNECTOR_INFO_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x50); check_offset = 0x50;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_DYN_CLK_1_TABLE: case COMBIOS_DYN_CLK_1_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x52); check_offset = 0x52;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_RESERVED_MEM_TABLE: case COMBIOS_RESERVED_MEM_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x54); check_offset = 0x54;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_EXT_TMDS_INFO_TABLE: case COMBIOS_EXT_TMDS_INFO_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x58); check_offset = 0x58;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_MEM_CLK_INFO_TABLE: case COMBIOS_MEM_CLK_INFO_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x5a); check_offset = 0x5a;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_EXT_DAC_INFO_TABLE: case COMBIOS_EXT_DAC_INFO_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x5c); check_offset = 0x5c;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_MISC_INFO_TABLE: case COMBIOS_MISC_INFO_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x5e); check_offset = 0x5e;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_CRT_INFO_TABLE: case COMBIOS_CRT_INFO_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x60); check_offset = 0x60;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_INTEGRATED_SYSTEM_INFO_TABLE: case COMBIOS_INTEGRATED_SYSTEM_INFO_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x62); check_offset = 0x62;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_COMPONENT_VIDEO_INFO_TABLE: case COMBIOS_COMPONENT_VIDEO_INFO_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x64); check_offset = 0x64;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_FAN_SPEED_INFO_TABLE: case COMBIOS_FAN_SPEED_INFO_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x66); check_offset = 0x66;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_OVERDRIVE_INFO_TABLE: case COMBIOS_OVERDRIVE_INFO_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x68); check_offset = 0x68;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_OEM_INFO_TABLE: case COMBIOS_OEM_INFO_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x6a); check_offset = 0x6a;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_DYN_CLK_2_TABLE: case COMBIOS_DYN_CLK_2_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x6c); check_offset = 0x6c;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_POWER_CONNECTOR_INFO_TABLE: case COMBIOS_POWER_CONNECTOR_INFO_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x6e); check_offset = 0x6e;
if (check_offset)
offset = check_offset;
break; break;
case COMBIOS_I2C_INFO_TABLE: case COMBIOS_I2C_INFO_TABLE:
check_offset = RBIOS16(rdev->bios_header_start + 0x70); check_offset = 0x70;
if (check_offset)
offset = check_offset;
break; break;
/* relative offset tables */ /* relative offset tables */
case COMBIOS_ASIC_INIT_3_TABLE: /* offset from misc info */ case COMBIOS_ASIC_INIT_3_TABLE: /* offset from misc info */
...@@ -439,11 +371,16 @@ static uint16_t combios_get_table_offset(struct drm_device *dev, ...@@ -439,11 +371,16 @@ static uint16_t combios_get_table_offset(struct drm_device *dev,
} }
break; break;
default: default:
check_offset = 0;
break; break;
} }
return offset; size = RBIOS8(rdev->bios_header_start + 0x6);
/* check absolute offset tables */
if (table < COMBIOS_ASIC_INIT_3_TABLE && check_offset && check_offset < size)
offset = RBIOS16(rdev->bios_header_start + check_offset);
return offset;
} }
bool radeon_combios_check_hardcoded_edid(struct radeon_device *rdev) bool radeon_combios_check_hardcoded_edid(struct radeon_device *rdev)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment