From 9ba736aecc2a3cb34a2aeec8d417f66390e0c82b Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Wed, 27 Sep 2017 16:24:31 +0300 Subject: tools/intel_vbt_decode: abstract child devices printing more MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Unify the common code for current and legacy blocks. Acked-by: Ville Syrjälä Signed-off-by: Jani Nikula --- tools/intel_vbt_decode.c | 70 +++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 39 deletions(-) (limited to 'tools/intel_vbt_decode.c') diff --git a/tools/intel_vbt_decode.c b/tools/intel_vbt_decode.c index ed9f43b8..9d90c69d 100644 --- a/tools/intel_vbt_decode.c +++ b/tools/intel_vbt_decode.c @@ -483,25 +483,12 @@ static void dump_child_device(struct context *context, } } -static void dump_general_definitions(struct context *context, - const struct bdb_block *block) + +static void dump_child_devices(struct context *context, const uint8_t *devices, + uint8_t child_dev_num, uint8_t child_dev_size) { - const struct bdb_general_definitions *defs = block->data; struct child_device_config *child; int i; - int child_device_num; - - printf("\tCRT DDC GMBUS addr: 0x%02x\n", defs->crt_ddc_gmbus_pin); - printf("\tUse ACPI DPMS CRT power states: %s\n", - YESNO(defs->dpms_acpi)); - printf("\tSkip CRT detect at boot: %s\n", - YESNO(defs->skip_boot_crt_detect)); - printf("\tUse DPMS on AIM devices: %s\n", YESNO(defs->dpms_aim)); - printf("\tBoot display type: 0x%02x%02x\n", defs->boot_display[1], - defs->boot_display[0]); - printf("\tChild device size: %d\n", defs->child_dev_size); - child_device_num = (block->size - sizeof(*defs)) / - defs->child_dev_size; /* * Use a temp buffer so dump_child_device() doesn't have to worry about @@ -510,9 +497,9 @@ static void dump_general_definitions(struct context *context, */ child = calloc(1, sizeof(*child)); - for (i = 0; i < child_device_num; i++) { - memcpy(child, &defs->devices[i * defs->child_dev_size], - min(sizeof(*child), defs->child_dev_size)); + for (i = 0; i < child_dev_num; i++) { + memcpy(child, devices + i * child_dev_size, + min(sizeof(*child), child_dev_size)); dump_child_device(context, child); } @@ -520,33 +507,38 @@ static void dump_general_definitions(struct context *context, free(child); } -static void dump_legacy_child_devices(struct context *context, - const struct bdb_block *block) +static void dump_general_definitions(struct context *context, + const struct bdb_block *block) { - const struct bdb_legacy_child_devices *defs = block->data; - struct child_device_config *child; - int i; - int child_device_num; + const struct bdb_general_definitions *defs = block->data; + int child_dev_num; + printf("\tCRT DDC GMBUS addr: 0x%02x\n", defs->crt_ddc_gmbus_pin); + printf("\tUse ACPI DPMS CRT power states: %s\n", + YESNO(defs->dpms_acpi)); + printf("\tSkip CRT detect at boot: %s\n", + YESNO(defs->skip_boot_crt_detect)); + printf("\tUse DPMS on AIM devices: %s\n", YESNO(defs->dpms_aim)); + printf("\tBoot display type: 0x%02x%02x\n", defs->boot_display[1], + defs->boot_display[0]); printf("\tChild device size: %d\n", defs->child_dev_size); - child_device_num = (block->size - sizeof(*defs)) / - defs->child_dev_size; - /* - * Use a temp buffer so dump_child_device() doesn't have to worry about - * accessing the struct beyond child_dev_size. The tail, if any, remains - * initialized to zero. - */ - child = calloc(1, sizeof(*child)); + child_dev_num = (block->size - sizeof(*defs)) / defs->child_dev_size; + dump_child_devices(context, defs->devices, + child_dev_num, defs->child_dev_size); +} - for (i = 0; i < child_device_num; i++) { - memcpy(child, &defs->devices[i * defs->child_dev_size], - min(sizeof(*child), defs->child_dev_size)); +static void dump_legacy_child_devices(struct context *context, + const struct bdb_block *block) +{ + const struct bdb_legacy_child_devices *defs = block->data; + int child_dev_num; - dump_child_device(context, child); - } + printf("\tChild device size: %d\n", defs->child_dev_size); - free(child); + child_dev_num = (block->size - sizeof(*defs)) / defs->child_dev_size; + dump_child_devices(context, defs->devices, + child_dev_num, defs->child_dev_size); } static void dump_lvds_options(struct context *context, -- cgit v1.2.3