Skip to content

Commit

Permalink
drm/i915/bios: abstract child device expected size
Browse files Browse the repository at this point in the history
Add a function to return the expected child device size. Flip the if
ladder around and use the same versions as in documentation to make it
easier to verify. Return an error for unknown versions. No functional
changes.

v2: Move BUILD_BUG_ON() next to the expected sizes

Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240226175854.287871-3-jani.nikula@intel.com
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Tracked-On: OAM-122511
  • Loading branch information
jnikula authored and sysopenci committed Jul 20, 2024
1 parent 47d01b2 commit 49aba19
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions drivers/gpu/drm/i915/display/intel_bios.c
Original file line number Diff line number Diff line change
Expand Up @@ -2785,27 +2785,35 @@ static void parse_ddi_ports(struct drm_i915_private *i915)
}
}

static int child_device_expected_size(u16 version)
{
BUILD_BUG_ON(sizeof(struct child_device_config) < 40);

if (version > 256)
return -ENOENT;
else if (version >= 256)
return 40;
else if (version >= 216)
return 39;
else if (version >= 196)
return 38;
else if (version >= 195)
return 37;
else if (version >= 111)
return LEGACY_CHILD_DEVICE_CONFIG_SIZE;
else if (version >= 106)
return 27;
else
return 22;
}

static bool child_device_size_valid(struct drm_i915_private *i915, int size)
{
int expected_size;

if (i915->display.vbt.version < 106) {
expected_size = 22;
} else if (i915->display.vbt.version < 111) {
expected_size = 27;
} else if (i915->display.vbt.version < 195) {
expected_size = LEGACY_CHILD_DEVICE_CONFIG_SIZE;
} else if (i915->display.vbt.version == 195) {
expected_size = 37;
} else if (i915->display.vbt.version <= 215) {
expected_size = 38;
} else if (i915->display.vbt.version <= 255) {
expected_size = 39;
} else if (i915->display.vbt.version <= 256) {
expected_size = 40;
} else {
expected_size = child_device_expected_size(i915->display.vbt.version);
if (expected_size < 0) {
expected_size = sizeof(struct child_device_config);
BUILD_BUG_ON(sizeof(struct child_device_config) < 40);
drm_dbg(&i915->drm,
"Expected child device config size for VBT version %u not known; assuming %d\n",
i915->display.vbt.version, expected_size);
Expand Down

0 comments on commit 49aba19

Please sign in to comment.