diff options
author | Denis Brockus <dbrockus@google.com> | 2020-10-25 19:47:41 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-10-26 23:18:54 +0000 |
commit | c72f41c9519251a6873be92b4d0be88a470239c8 (patch) | |
tree | 7bc24b9007f30147fcad5f758e0a3ac10d17c7ce | |
parent | d8981b12aa07219a2ed8ad23141d3bc11176325c (diff) | |
download | chrome-ec-c72f41c9519251a6873be92b4d0be88a470239c8.tar.gz |
genvif: Update VIF generator to v3.0.0.1+
This upgrade gives a generator that produces the latest
spec's XML output. More work can be done on this to
produce more complete VIF files, but this is a good
starting point.
BUG=b:170646602
BRANCH=none
TEST=verify generated VIF files
Signed-off-by: Denis Brockus <dbrockus@google.com>
Change-Id: Ie7a3c174a5e433c04dc168a39857cc2fcb6c28ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2497612
Tested-by: Denis Brockus <dbrockus@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
Commit-Queue: Jett Rink <jettrink@chromium.org>
Auto-Submit: Denis Brockus <dbrockus@chromium.org>
-rw-r--r-- | util/genvif.c | 1823 | ||||
-rw-r--r-- | util/genvif.h | 399 |
2 files changed, 1412 insertions, 810 deletions
diff --git a/util/genvif.c b/util/genvif.c index 919b81c64f..f9ee1bd037 100644 --- a/util/genvif.c +++ b/util/genvif.c @@ -1,4 +1,4 @@ -/* Copyright 2017 The Chromium OS Authors. All rights reserved. +/* Copyright 2020 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ @@ -7,6 +7,7 @@ #include <errno.h> #include <stdarg.h> +#include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <string.h> @@ -21,802 +22,1122 @@ #include "charge_manager.h" #include "system.h" -/* - * Vendor Info File Generator - * Revision 1.40, Version 1.0 - */ +#include "genvif.h" -#define GENVIF_TITLE "EC GENVIF, Version 1.40" -#define VIF_SPEC "Revision 1.40, Version 1.0" -#define VENDOR_NAME "Google" - -enum spec_rev { - PD_REV_2_0 = 1, - PD_REV_3_0 -}; - -enum field { - INTRO = 0, - PRODUCT, - GENERAL, - USB, - DEVICE, - SOURCE, - SINK, - DUAL_ROLE, - SOP, - BC12, -}; +const uint32_t *src_pdo; +uint32_t src_pdo_cnt; +/* + * local type to make decisions on the output for Source, Sink and DRP + */ enum dtype { SRC = 0, SNK, DRP }; -enum vif_product_type { - PORT = 0, - CABLE, - RE_TIMER -}; - -enum conn_type { - TYPE_A = 0, - TYPE_B, - TYPE_C, - MICRO_AB -}; - -enum port_type { - PT_CONSUMER = 0, - PT_CONSUMER_PROVIDER, - PT_PROVIDER_CONSUMER, - PT_PROVIDER, - PT_DRP, - PT_EMARKER -}; - -enum bc_1_2_support { - BC_NONE = 0, - BC_PORTABLE_DEVICE, - BC_CHARGING_PORT, - BC_BOTH -}; - -enum power_source { - PS_EXT_POWERED = 0, - PS_UFP_POWERED, - PS_BOTH -}; - +/* + * Device_Speed options, defined in the VIF specification + */ enum usb_speed { - USB_2, - USB_GEN11, - USB_GEN21, - USB_GEN12, - USB_GEN22 + USB_2 = 0, + USB_GEN11 = 1, + USB_GEN21 = 2, + USB_GEN12 = 3, + USB_GEN22 = 4 }; -const uint32_t *src_pdo; -uint32_t src_pdo_cnt; -char *yes_no(int val) +/***************************************************************************** + * Generic Helper Functions + */ +static bool is_src(void) { - return val ? "YES" : "NO"; + return src_pdo_cnt; } - -enum ec_image system_get_image_copy(void) +static bool is_snk(void) { - return EC_IMAGE_RW; + return (IS_ENABLED(CONFIG_USB_PD_DUAL_ROLE)) ? pd_snk_pdo_cnt : 0; } - -static void write_title(FILE *vif) +static bool is_drp(void) { - fprintf(vif, ";\r\n"); - fprintf(vif, "; %s \r\n", GENVIF_TITLE); - fprintf(vif, ";\r\n"); + if (is_src()) + return !!(src_pdo[0] & PDO_FIXED_DUAL_ROLE); + return false; } -static void write_field(FILE *vif, enum field t) +static void init_src_pdos(void) { - if (!vif) - return; - - fprintf(vif, "\r\n%s\r\n", - ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"); - switch (t) { - case INTRO: - fprintf(vif, "; Intro Fields\r\n"); - break; - case PRODUCT: - fprintf(vif, "; VIF Product Fields\r\n"); - break; - case GENERAL: - fprintf(vif, "; General PD Fields\r\n"); - break; - case USB: - fprintf(vif, "; USB Type-C Fields\r\n"); - break; - case DEVICE: - fprintf(vif, "; USB Device Fields\r\n"); - break; - case SOURCE: - fprintf(vif, "; PD Source Fields\r\n"); - break; - case SINK: - fprintf(vif, "; PD Sink Fields\r\n"); - break; - case DUAL_ROLE: - fprintf(vif, "; PD Dual Role Fields\r\n"); - break; - case SOP: - fprintf(vif, "; SOP Discovery Fields\r\n"); - break; - case BC12: - fprintf(vif, ": Battery Charging 1.2 Fields\r\n"); - break; - + if (IS_ENABLED(CONFIG_USB_PD_DYNAMIC_SRC_CAP)) + src_pdo_cnt = charge_manager_get_source_pdo(&src_pdo, 0); + else { + src_pdo_cnt = pd_src_pdo_cnt; + src_pdo = pd_src_pdo; } - fprintf(vif, "%s\r\n", - ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"); } -static void init_src_pdos(void) +static bool vif_fields_present(struct vif_field_t *vif_fields, int count) { -#ifdef CONFIG_USB_PD_DYNAMIC_SRC_CAP - src_pdo_cnt = charge_manager_get_source_pdo(&src_pdo, 0); -#else - src_pdo_cnt = pd_src_pdo_cnt; - src_pdo = pd_src_pdo; -#endif + int index; + + for (index = 0; index < count; ++index) { + if (vif_fields[index].str_value || + vif_fields[index].tag_value) { + return true; + } + } + return false; } -static int is_src(void) + +/***************************************************************************** + * VIF XML Output Functions + */ +static void vif_out_str(FILE *vif_file, int level, char *str) { - return src_pdo_cnt; + while (level-- > 0) + fprintf(vif_file, " "); + fprintf(vif_file, "%s\r\n", str); } -static int is_snk(void) +static void vif_out_field(FILE *vif_file, int level, + struct vif_field_t *vif_field) { -#ifdef CONFIG_USB_PD_DUAL_ROLE - return pd_snk_pdo_cnt; -#else - return 0; -#endif + if (vif_field->str_value || vif_field->tag_value) { + while (level-- > 0) + fprintf(vif_file, " "); + + fprintf(vif_file, "<%s", vif_field->name); + if (vif_field->tag_value) + fprintf(vif_file, " value=\"%s\"", + vif_field->tag_value); + if (vif_field->str_value) + fprintf(vif_file, ">%s</%s>\r\n", + vif_field->str_value, + vif_field->name); + else + fprintf(vif_file, "/>\r\n"); + } } -static int is_drp(void) +static void vif_out_fields_range(FILE *vif_file, int level, + struct vif_field_t *vif_fields, + int start, int count) { - if (is_src()) - return !!(src_pdo[0] & PDO_FIXED_DUAL_ROLE); - else - return 0; + int index; + + for (index = start; index < count; ++index) + vif_out_field(vif_file, level, &vif_fields[index]); } -/* Application exits on failure */ -__attribute__((__format__(__printf__, 2, 3))) -static void append(char **buf, const char *fmt, ...) +static void vif_out_fields(FILE *vif_file, int level, + struct vif_field_t *vif_fields, int count) { - va_list ap1, ap2; - int n; - static int offset; + vif_out_fields_range(vif_file, level, vif_fields, 0, count); +} - va_start(ap1, fmt); - va_copy(ap2, ap1); - n = vsnprintf(NULL, 0, fmt, ap1) + 1; - if (*buf == NULL) - offset = 0; +static void vif_output_vif_component_cable_svid_mode_list(FILE *vif_file, + struct vif_cableSVIDList_t *svid_list, int level) +{ + int index; - *buf = (char *)realloc(*buf, offset + n); + if (!vif_fields_present(svid_list->CableSVIDModeList[0].vif_field, + CableSVID_Mode_Indexes)) + return; - if (*buf) { - vsnprintf(*buf + offset, n, fmt, ap2); - } else { - fprintf(stderr, "ERROR: Out of memory.\n"); - exit(EXIT_FAILURE); - } + vif_out_str(vif_file, level++, "<CableSVIDModeList>"); + for (index = 0; index < MAX_NUM_CABLE_SVID_MODES; ++index) { + struct vif_cableSVIDModeList_t *mode_list = + &svid_list->CableSVIDModeList[index]; - /* Overwrite NULL terminator the next time through. */ - offset += (n-1); + if (!vif_fields_present(mode_list->vif_field, + CableSVID_Mode_Indexes)) + break; - va_end(ap1); - va_end(ap2); + vif_out_str(vif_file, level++, "<SOPSVIDMode>"); + vif_out_fields(vif_file, level, + mode_list->vif_field, CableSVID_Mode_Indexes); + vif_out_str(vif_file, --level, "</SOPSVIDMode>"); + } + vif_out_str(vif_file, --level, "</CableSVIDModeList>"); } -static int32_t write_pdo_to_buf(char **buf, uint32_t pdo, - enum dtype type, uint32_t pnum) +static void vif_output_vif_component_cable_svid_list(FILE *vif_file, + struct vif_Component_t *component, int level) { - int32_t power; + int index; - if ((pdo & PDO_TYPE_MASK) == PDO_TYPE_FIXED) { - uint32_t current = pdo & 0x3ff; - uint32_t voltage = (pdo >> 10) & 0x3ff; + if (!vif_fields_present(component->CableSVIDList[0].vif_field, + CableSVID_Indexes)) + return; - power = ((current * 10) * (voltage * 50)) / 1000; + vif_out_str(vif_file, level++, "<CableSVIDList>"); + for (index = 0; index < MAX_NUM_CABLE_SVIDS; ++index) { + struct vif_cableSVIDList_t *svid_list = + &component->CableSVIDList[index]; - append(buf, "\t%s_PDO_Supply_Type%d: 0\r\n", - (type == SRC) ? "Src" : "Snk", pnum); + if (!vif_fields_present(svid_list->vif_field, + CableSVID_Indexes)) + break; - if (type == SRC) - append(buf, "\tSrc_PDO_Peak_Current%d: 0\r\n", pnum); + vif_out_str(vif_file, level++, "<CableSVID>"); + vif_out_fields(vif_file, level, + svid_list->vif_field, CableSVID_Indexes); + vif_output_vif_component_cable_svid_mode_list(vif_file, + svid_list, level); + vif_out_str(vif_file, --level, "</CableSVID>"); + } + vif_out_str(vif_file, --level, "</CableSVIDList>"); +} - append(buf, "\t%s_PDO_Voltage%d: %d\r\n", - (type == SRC) ? "Src" : "Snk", pnum, voltage); +static void vif_output_vif_component_sop_svid_mode_list(FILE *vif_file, + struct vif_sopSVIDList_t *svid_list, int level) +{ + int index; - if (type == SRC) - append(buf, "\tSrc_PDO_Max_Current%d: %d\r\n", pnum, - current); - else - append(buf, "\tSnk_PDO_Op_Current%d: %d\r\n", pnum, - current); + if (!vif_fields_present(svid_list->SOPSVIDModeList[0].vif_field, + SopSVID_Mode_Indexes)) + return; - } else if ((pdo & PDO_TYPE_MASK) == PDO_TYPE_BATTERY) { - uint32_t max_voltage = (pdo >> 20) & 0x3ff; - uint32_t min_voltage = (pdo >> 10) & 0x3ff; + vif_out_str(vif_file, level++, "<SOPSVIDModeList>"); + for (index = 0; index < MAX_NUM_SOP_SVID_MODES; ++index) { + struct vif_sopSVIDModeList_t *mode_list = + &svid_list->SOPSVIDModeList[index]; - power = pdo & 0x3ff; + if (!vif_fields_present(mode_list->vif_field, + SopSVID_Mode_Indexes)) + break; - append(buf, "\t%s_PDO_Supply_Type%d: 1\r\n", - (type == SRC) ? "Src" : "Snk", pnum); + vif_out_str(vif_file, level++, "<SOPSVIDMode>"); + vif_out_fields(vif_file, level, + mode_list->vif_field, SopSVID_Mode_Indexes); + vif_out_str(vif_file, --level, "</SOPSVIDMode>"); + } + vif_out_str(vif_file, --level, "</SOPSVIDModeList>"); +} - append(buf, "\t%s_PDO_Min_Voltage%d: %d\r\n", - (type == SRC) ? "Src" : "Snk", pnum, min_voltage); +static void vif_output_vif_component_sop_svid_list(FILE *vif_file, + struct vif_Component_t *component, int level) +{ + int index; - append(buf, "\t%s_PDO_Max_Voltage%d: %d\r\n", - (type == SRC) ? "Src" : "Snk", pnum, max_voltage); + if (!vif_fields_present(component->SOPSVIDList[0].vif_field, + SopSVID_Indexes)) + return; - if (type == SRC) - append(buf, "\tSrc_PDO_Max_Power%d: %d\r\n", pnum, - power); - else - append(buf, "\tSnk_PDO_Op_Power%d: %d\r\n", pnum, - power); + vif_out_str(vif_file, level++, "<SOPSVIDList>"); + for (index = 0; index < MAX_NUM_SOP_SVIDS; ++index) { + struct vif_sopSVIDList_t *svid_list = + &component->SOPSVIDList[index]; - } else if ((pdo & PDO_TYPE_MASK) == PDO_TYPE_VARIABLE) { - uint32_t max_voltage = (pdo >> 20) & 0x3ff; - uint32_t min_voltage = (pdo >> 10) & 0x3ff; - uint32_t current = pdo & 0x3ff; + if (!vif_fields_present(svid_list->vif_field, + SopSVID_Indexes)) + break; - power = ((current * 10) * (max_voltage * 50)) / 1000; + vif_out_str(vif_file, level++, "<SOPSVID>"); + vif_out_fields(vif_file, level, + svid_list->vif_field, SopSVID_Indexes); + vif_output_vif_component_sop_svid_mode_list(vif_file, + svid_list, level); + vif_out_str(vif_file, --level, "</SOPSVID>"); + } + vif_out_str(vif_file, --level, "</SOPSVIDList>"); +} - append(buf, "\t%s_PDO_Supply_Type%d: 2\r\n", - (type == SRC) ? "Src" : "Snk", pnum); +static void vif_output_vif_component_snk_pdo_list(FILE *vif_file, + struct vif_Component_t *component, int level) +{ + int index; - if (type == SRC) - append(buf, "\tSrc_PDO_Peak_Current%d: 0\r\n", pnum); + if (!vif_fields_present(component->SnkPdoList[0].vif_field, + Snk_PDO_Indexes)) + return; - append(buf, "\t%s_PDO_Min_Voltage%d: %d\r\n", - (type == SRC) ? "Src" : "Snk", pnum, min_voltage); + vif_out_str(vif_file, level++, "<SnkPdoList>"); + for (index = 0; index < MAX_NUM_SNK_PDOS; ++index) { + struct vif_snkPdoList_t *pdo_list = + &component->SnkPdoList[index]; - append(buf, "\t%s_PDO_Max_Voltage%d: %d\r\n", - (type == SRC) ? "Src" : "Snk", pnum, max_voltage); + if (!vif_fields_present(pdo_list->vif_field, + Snk_PDO_Indexes)) + break; - if (type == SRC) - append(buf, "\tSrc_PDO_Max_Current%d: %d\r\n", pnum, - current); - else - append(buf, "\tSnk_PDO_Op_Current%d: %d\r\n", pnum, - current); - } else if ((pdo & PDO_TYPE_MASK) == PDO_TYPE_AUGMENTED) { - uint32_t pps = (pdo >> 28) & 3; - uint32_t pps_max_voltage = (pdo >> 17) & 0xff; - uint32_t pps_min_voltage = (pdo >> 8) & 0xff; - uint32_t pps_current = pdo & 0x7f; + vif_out_str(vif_file, level++, "<SnkPDO>"); + vif_out_fields(vif_file, level, + pdo_list->vif_field, Snk_PDO_Indexes); + vif_out_str(vif_file, --level, "</SnkPDO>"); + } + vif_out_str(vif_file, --level, "</SnkPdoList>"); +} - if (pps) { - fprintf(stderr, "ERROR: Invalid PDO_TYPE %d.\n", pdo); - return -1; - } +static void vif_output_vif_component_src_pdo_list(FILE *vif_file, + struct vif_Component_t *component, int level) +{ + int index; - append(buf, "\t%s_PDO_Supply_Type%d: 3\r\n", - (type == SRC) ? "Src" : "Snk", pnum); + if (!vif_fields_present(component->SrcPdoList[0].vif_field, + Src_PDO_Indexes)) + return; - if (type == SRC) - append(buf, "\tSrc_PDO_Max_Current%d: %d\r\n", pnum, - pps_current); - else - append(buf, "\tSnk_PDO_Op_Current%d: %d\r\n", pnum, - pps_current); + vif_out_str(vif_file, level++, "<SrcPdoList>"); + for (index = 0; index < MAX_NUM_SRC_PDOS; ++index) { + struct vif_srcPdoList_t *pdo_list = + &component->SrcPdoList[index]; - append(buf, "\t%s_PDO_Min_Voltage%d: %d\r\n", - (type == SRC) ? "Src" : "Snk", pnum, pps_min_voltage); + if (!vif_fields_present(pdo_list->vif_field, + Src_PDO_Indexes)) + break; - append(buf, "\t%s_PDO_Max_Voltage%d: %d\r\n", - (type == SRC) ? "Src" : "Snk", pnum, pps_max_voltage); - } else { - fprintf(stderr, "ERROR: Invalid PDO_TYPE %d.\n", pdo); - return -1; + vif_out_str(vif_file, level++, "<SrcPDO>"); + vif_out_fields(vif_file, level, + pdo_list->vif_field, Src_PDO_Indexes); + vif_out_str(vif_file, --level, "</SrcPDO>"); + } + vif_out_str(vif_file, --level, "</SrcPdoList>"); +} + +static void vif_output_vif_component(FILE *vif_file, + struct vif_t *vif, int level) +{ + int index; + + for (index = 0; index < MAX_NUM_COMPONENTS; ++index) { + struct vif_Component_t *component = &vif->Component[index]; + + if (!vif_fields_present(component->vif_field, + Component_Indexes)) + return; + + vif_out_str(vif_file, level++, "<Component>"); + vif_out_fields(vif_file, level, + component->vif_field, Component_Indexes); + vif_output_vif_component_snk_pdo_list(vif_file, + component, + level); + vif_output_vif_component_src_pdo_list(vif_file, + component, + level); + vif_output_vif_component_sop_svid_list(vif_file, + component, + level); + vif_output_vif_component_cable_svid_list(vif_file, + component, + level); + vif_out_str(vif_file, --level, "</Component>"); } - - append(buf, "\r\n"); - - return power; } -/* - * Intro Fields - */ - -static void write_vif_specification(FILE *vif) +static void vif_output_vif_product_usb4router_endpoint(FILE *vif_file, + struct vif_Usb4RouterListType_t *router, int level) { - fprintf(vif, "$VIF_Specification: \"%s\"\r\n", VIF_SPEC); -} + int index; -static void write_vif_producer(FILE *vif, const char *vp) -{ - fprintf(vif, "$VIF_Producer: \"%s\"\r\n", vp); -} + if (!vif_fields_present(router->PCIeEndpointList[0].vif_field, + PCIe_Endpoint_Indexes)) + return; -static void write_vendor_name(FILE *vif) -{ - fprintf(vif, "$Vendor_Name: \"%s\"\r\n", VENDOR_NAME); -} + vif_out_str(vif_file, level++, "<PCIeEndpointList>"); + for (index = 0; index < MAX_NUM_PCIE_ENDPOINTS; ++index) { + struct vif_PCIeEndpointListType_t *endpont = + &router->PCIeEndpointList[index]; -static void write_model_part_number(FILE *vif) -{ -#ifdef CONFIG_USB_PD_MODEL_PART_NUMBER - fprintf(vif, "$Model_Part_Number: \"%s\"\r\n", - CONFIG_USB_PD_MODEL_PART_NUMBER); -#endif -} + if (!vif_fields_present(endpont->vif_field, + PCIe_Endpoint_Indexes)) + break; -static void write_product_revision(FILE *vif) -{ -#ifdef CONFIG_USB_PD_PRODUCT_REVISION - fprintf(vif, "$Model_Part_Number: \"%s\"\r\n", - CONFIG_USB_PD_PRODUCT_REVISION); -#endif + vif_out_str(vif_file, level++, "<PCIeEndpoint>"); + vif_out_fields(vif_file, level, + endpont->vif_field, PCIe_Endpoint_Indexes); + vif_out_str(vif_file, --level, "</PCIeEndpoint>"); + } + vif_out_str(vif_file, --level, "</PCIeEndpointList>"); } -static void write_tid(FILE *vif) +static void vif_output_vif_product_usb4router(FILE *vif_file, + struct vif_t *vif, int level) { -#ifdef CONFIG_USB_PD_TID - fprintf(vif, "$TID: \"%s\"\r\n", CONFIG_USB_PD_TID); -#endif -} + int index; -/* - * VIF Product Fields - */ + if (!vif_fields_present(vif->Product.USB4RouterList[0].vif_field, + USB4_Router_Indexes)) + return; -static void write_vif_product_type(FILE *vif) -{ - fprintf(vif, "VIF_Product_Type: %d\r\n", PORT); -} + vif_out_str(vif_file, level++, "<USB4RouterList>"); + for (index = 0; index < MAX_NUM_USB4_ROUTERS; ++index) { + struct vif_Usb4RouterListType_t *router = + &vif->Product.USB4RouterList[index]; -static void write_port_label(FILE *vif) -{ -#ifdef CONFIG_USB_PD_PORT_LABEL - fprintf(vif, "$Port_Label: %s\r\n", CONFIG_USB_PD_PORT_LABEL); -#endif -} + if (!vif_fields_present(router->vif_field, + USB4_Router_Indexes)) + break; -static void write_connector_type(FILE *vif) -{ - fprintf(vif, "Connector_Type: %d\r\n", TYPE_C); + vif_out_str(vif_file, level++, "<USB4Router>"); + vif_out_fields(vif_file, level, + router->vif_field, USB4_Router_Indexes); + vif_output_vif_product_usb4router_endpoint(vif_file, + router, + level); + vif_out_str(vif_file, --level, "</USB4Router>"); + } + vif_out_str(vif_file, --level, "</USB4RouterList>"); } -static void write_usb_pd_support(FILE *vif) +static void vif_output_vif_product(FILE *vif_file, + struct vif_t *vif, int level) { - char *yn = "NO"; - -#if defined(CONFIG_USB_PRL_SM) || defined(CONFIG_USB_POWER_DELIVERY) - yn = "YES"; -#endif + if (!vif_fields_present(vif->Product.vif_field, Product_Indexes)) + return; - fprintf(vif, "USB_PD_Support: %s\n", yn); + vif_out_str(vif_file, level++, "<Product>"); + vif_out_fields(vif_file, level, + vif->Product.vif_field, Product_Indexes); + vif_output_vif_product_usb4router(vif_file, vif, level); + vif_out_str(vif_file, --level, "</Product>"); } -static void write_pd_port_type(FILE *vif, enum dtype type) - +static void vif_output_vif_xml(FILE *vif_file, struct vif_t *vif, int level) { - enum port_type pt; + vif_out_field(vif_file, level, &vif->vif_field[VIF_Specification]); - switch (type) { - case SNK: - pt = PT_CONSUMER; - break; - case SRC: - pt = PT_PROVIDER; - break; - case DRP: - pt = PT_DRP; - break; - } + vif_out_str(vif_file, level++, "<VIF_App>"); + vif_out_field(vif_file, level, &vif->vif_field[VIF_App_Vendor]); + vif_out_field(vif_file, level, &vif->vif_field[VIF_App_Name]); + vif_out_field(vif_file, level, &vif->vif_field[VIF_App_Version]); + vif_out_str(vif_file, --level, "</VIF_App>"); - fprintf(vif, "PD_Port_Type: %d\r\n", pt); + vif_out_fields_range(vif_file, level, + vif->vif_field, Vendor_Name, VIF_Indexes); } -static void write_type_c_state_machine(FILE *vif, enum dtype type) +static void vif_output_xml(FILE *vif_file, struct vif_t *vif) { - fprintf(vif, "Type_C_State_Machine: %d\r\n", type); -} + int level = 0; -static void write_captive_cable(FILE *vif) -{ - fprintf(vif, "Captive_Cable: NO\r\n"); -} + vif_out_str(vif_file, level++, + "<VIF xmlns=\"http://usb.org/VendorInfoFile.xsd\">"); -static void write_port_battery_powered(FILE *vif) -{ -#ifdef CONFIG_BATTERY - fprintf(vif, "Port_Battery_Powered: YES\r\n"); -#else - fprintf(vif, "Port_Battery_Powered: NO\r\n"); -#endif -} + vif_output_vif_xml(vif_file, vif, level); + vif_output_vif_product(vif_file, vif, level); + vif_output_vif_component(vif_file, vif, level); -static void write_bc_1_2_support(FILE *vif, enum dtype type) -{ - enum bc_1_2_support bc = BC_NONE; - - fprintf(vif, "BC_1_2_Support: %d\r\n", bc); + vif_out_str(vif_file, --level, "</VIF>"); } - /* - * General PD Fields + * VIF XML Output Functions + *****************************************************************************/ + + +/***************************************************************************** + * VIF Structure Initialization Helper Functions */ +static void set_vif_field(struct vif_field_t *vif_field, + char *name, + char *tag_value, + char *str_value) +{ + char *ptr; -static void write_pd_spec_rev(FILE *vif) + if (name) { + ptr = malloc(strlen(name)+1); + strcpy(ptr, name); + vif_field->name = ptr; + } + if (str_value) { + ptr = malloc(strlen(str_value)+1); + strcpy(ptr, str_value); + vif_field->str_value = ptr; + } + if (tag_value) { + ptr = malloc(strlen(tag_value)+1); + strcpy(ptr, tag_value); + vif_field->tag_value = ptr; + } +} +__maybe_unused static void set_vif_field_b(struct vif_field_t *vif_field, + char *name, + bool val) { - enum spec_rev rev; - -#if defined(CONFIG_USB_PD_REV30) || defined(CONFIG_USB_PRL_SM) - rev = PD_REV_3_0; -#else - rev = PD_REV_2_0; -#endif - fprintf(vif, "PD_Specification_Revision: %d\r\n", rev); + if (val) + set_vif_field(vif_field, name, "true", "YES"); + else + set_vif_field(vif_field, name, "false", "NO"); } - -static void write_usb_comms_capable(FILE *vif) +__maybe_unused static void set_vif_field_stis(struct vif_field_t *vif_field, + char *name, + char *tag_value, + int str_value) { - char *yn = "YES"; + char str_str[80]; -#if defined(CONFIG_USB_VPD) || defined(CONFIG_USB_CTVPD) - yn = "NO"; -#endif - fprintf(vif, "USB_Comms_Capable: %s\r\n", yn); + sprintf(str_str, "%d", str_value); + set_vif_field(vif_field, name, tag_value, str_str); } - -static void write_dr_swap_to_dfp_supported(FILE *vif) +__maybe_unused static void set_vif_field_itss(struct vif_field_t *vif_field, + char *name, + int tag_value, + char *str_value) { - char *yn = "NO"; - - if (is_src() && (src_pdo[0] & PDO_FIXED_DATA_SWAP)) - yn = yes_no(pd_check_data_swap(0, PD_ROLE_DFP)); + char str_tag[80]; - fprintf(vif, "DR_Swap_To_DFP_Supported: %s\r\n", yn); + sprintf(str_tag, "%d", tag_value); + set_vif_field(vif_field, name, str_tag, str_value); } - -static void write_dr_swap_to_ufp_supported(FILE *vif) +__maybe_unused static void set_vif_field_itis(struct vif_field_t *vif_field, + char *name, + int tag_value, + int str_value) { - char *yn = "NO"; - - if (is_src() && (src_pdo[0] & PDO_FIXED_DATA_SWAP)) - yn = yes_no(pd_check_data_swap(0, PD_ROLE_UFP)); - + char str_tag[80]; + char str_str[80]; - fprintf(vif, "DR_Swap_To_UFP_Supported: %s\r\n", yn); + sprintf(str_tag, "%d", tag_value); + sprintf(str_str, "%d", str_value); + set_vif_field(vif_field, name, str_tag, str_str); } +/* + * VIF Structure Initialization Helper Functions + *****************************************************************************/ + -static void write_unconstrained_power(FILE *vif) +/***************************************************************************** + * VIF Structure Initialization from Config Functions + */ +__maybe_unused static int32_t set_vif_snk_pdo(struct vif_snkPdoList_t *snkPdo, + uint32_t pdo) { - int yn = 0; + int32_t power; - if (is_src()) - yn = !!(src_pdo[0] & PDO_FIXED_UNCONSTRAINED); + if ((pdo & PDO_TYPE_MASK) == PDO_TYPE_FIXED) { + uint32_t current = pdo & 0x3ff; + uint32_t voltage = (pdo >> 10) & 0x3ff; - fprintf(vif, "Unconstrained_Power: %s\r\n", yes_no(yn)); -} + power = ((current * 10) * (voltage * 50)) / 1000; -static void write_vconn_swap_to_on_supported(FILE *vif) -{ - char *yn = "NO"; + set_vif_field(&snkPdo->vif_field[Snk_PDO_Supply_Type], + "Snk_PDO_Supply_Type", + "0", NULL); + set_vif_field_itss(&snkPdo->vif_field[Snk_PDO_Voltage], + "Snk_PDO_Voltage", + voltage, NULL); + set_vif_field_itss(&snkPdo->vif_field[Snk_PDO_Op_Current], + "Snk_PDO_Op_Current", + current, NULL); -#ifdef CONFIG_USBC_VCONN_SWAP - yn = "YES"; -#endif + } else if ((pdo & PDO_TYPE_MASK) == PDO_TYPE_BATTERY) { + uint32_t max_voltage = (pdo >> 20) & 0x3ff; + uint32_t min_voltage = (pdo >> 10) & 0x3ff; - fprintf(vif, "VCONN_Swap_To_On_Supported: %s\r\n", yn); -} + power = pdo & 0x3ff; -static void write_vconn_swap_to_off_supported(FILE *vif) -{ - char *yn = "NO"; + set_vif_field(&snkPdo->vif_field[Snk_PDO_Supply_Type], + "Snk_PDO_Supply_Type", + "1", NULL); + set_vif_field_itss(&snkPdo->vif_field[Snk_PDO_Min_Voltage], + "Snk_PDO_Min_Voltage", + min_voltage, NULL); + set_vif_field_itss(&snkPdo->vif_field[Snk_PDO_Max_Voltage], + "Snk_PDO_Max_Voltage", + max_voltage, NULL); + set_vif_field_itss(&snkPdo->vif_field[Snk_PDO_Op_Power], + "Snk_PDO_Op_Power", + power, NULL); -#ifdef CONFIG_USBC_VCONN_SWAP - yn = "YES"; -#endif + } else if ((pdo & PDO_TYPE_MASK) == PDO_TYPE_VARIABLE) { + uint32_t max_voltage = (pdo >> 20) & 0x3ff; + uint32_t min_voltage = (pdo >> 10) & 0x3ff; + uint32_t current = pdo & 0x3ff; - fprintf(vif, "VCONN_Swap_To_Off_Supported: %s\r\n", yn); -} + power = ((current * 10) * (max_voltage * 50)) / 1000; -static void write_responds_to_discov_sop_ufp(FILE *vif) -{ - fprintf(vif, "Responds_To_Discov_SOP_UFP: NO\r\n"); -} + set_vif_field(&snkPdo->vif_field[Snk_PDO_Supply_Type], + "Snk_PDO_Supply_Type", + "2", NULL); + set_vif_field_itss(&snkPdo->vif_field[Snk_PDO_Min_Voltage], + "Snk_PDO_Min_Voltage", + min_voltage, NULL); + set_vif_field_itss(&snkPdo->vif_field[Snk_PDO_Max_Voltage], + "Snk_PDO_Max_Voltage", + max_voltage, NULL); + set_vif_field_itss(&snkPdo->vif_field[Snk_PDO_Op_Current], + "Snk_PDO_Op_Current", + current, NULL); -static void write_responds_to_discov_sop_dfp(FILE *vif) -{ - fprintf(vif, "Responds_To_Discov_SOP_DFP: NO\r\n"); -} + } else if ((pdo & PDO_TYPE_MASK) == PDO_TYPE_AUGMENTED) { + uint32_t pps = (pdo >> 28) & 3; + uint32_t pps_max_voltage = (pdo >> 17) & 0xff; + uint32_t pps_min_voltage = (pdo >> 8) & 0xff; + uint32_t pps_current = pdo & 0x7f; -static void write_attempts_discov_sop(FILE *vif, enum dtype type) -{ - char *yn = "YES"; + if (pps) { + fprintf(stderr, "ERROR: Invalid PDO_TYPE %d.\n", pdo); + return -1; + } -#ifdef CONFIG_USB_PD_SIMPLE_DFP - if (type == SRC) - yn = "NO"; - else - yn = "YES"; -#endif + set_vif_field(&snkPdo->vif_field[Snk_PDO_Supply_Type], + "Snk_PDO_Supply_Type", + "3", NULL); + set_vif_field_itss(&snkPdo->vif_field[Snk_PDO_Op_Current], + "Snk_PDO_Op_Current", + pps_current, NULL); + set_vif_field_itss(&snkPdo->vif_field[Snk_PDO_Min_Voltage], + "Snk_PDO_Min_Voltage", + pps_min_voltage, NULL); + set_vif_field_itss(&snkPdo->vif_field[Snk_PDO_Max_Voltage], + "Snk_PDO_Max_Voltage", + pps_max_voltage, NULL); + } else { + fprintf(stderr, "ERROR: Invalid PDO_TYPE %d.\n", pdo); + return -1; + } - fprintf(vif, "Attempts_Discov_SOP: %s\r\n", yn); + return power; } -static void write_chunking_implemented_sop(FILE *vif) +__maybe_unused static int32_t set_vif_src_pdo(struct vif_srcPdoList_t *srcPdo, + uint32_t pdo) { - char *yn = "NO"; + int32_t power; -#if defined(CONFIG_USB_PD_REV30) && defined(CONFIG_USB_PRL_SM) - yn = "YES"; -#endif + if ((pdo & PDO_TYPE_MASK) == PDO_TYPE_FIXED) { + uint32_t current = pdo & 0x3ff; + uint32_t voltage = (pdo >> 10) & 0x3ff; - fprintf(vif, "Chunking_Implemented_SOP: %s\r\n", yn); -} + power = ((current * 10) * (voltage * 50)) / 1000; -static void write_unchunked_extended_messages_supported(FILE *vif) -{ - fprintf(vif, "Unchunked_Extended_Messages_Supported: NO\r\n"); -} + set_vif_field(&srcPdo->vif_field[Src_PDO_Supply_Type], + "Src_PDO_Supply_Type", + "0", NULL); + set_vif_field(&srcPdo->vif_field[Src_PDO_Peak_Current], + "Src_PDO_Peak_Current", + "0", NULL); + set_vif_field_itss(&srcPdo->vif_field[Src_PDO_Voltage], + "Src_PDO_Voltage", + voltage, NULL); + set_vif_field_itss(&srcPdo->vif_field[Src_PDO_Max_Current], + "Src_PDO_Max_Current", + current, NULL); -static void write_manufacturer_info_supported_port(FILE *vif) -{ - char *yn = "NO"; + } else if ((pdo & PDO_TYPE_MASK) == PDO_TYPE_BATTERY) { + uint32_t max_voltage = (pdo >> 20) & 0x3ff; + uint32_t min_voltage = (pdo >> 10) & 0x3ff; -#ifdef CONFIG_USB_PD_MANUFACTURER_INFO - yn = "YES"; -#endif + power = pdo & 0x3ff; - fprintf(vif, "Manufacturer_Info_Supported_Port: %s\r\n", yn); -} + set_vif_field(&srcPdo->vif_field[Src_PDO_Supply_Type], + "Src_PDO_Supply_Type", + "1", NULL); + set_vif_field_itss(&srcPdo->vif_field[Src_PDO_Min_Voltage], + "Src_PDO_Min_Voltage", + min_voltage, NULL); + set_vif_field_itss(&srcPdo->vif_field[Src_PDO_Max_Voltage], + "Src_PDO_Max_Voltage", + max_voltage, NULL); + set_vif_field_itss(&srcPdo->vif_field[Src_PDO_Max_Power], + "Src_PDO_Max_Power", + power, NULL); -static void write_manufacturer_info_pid_port(FILE *vif) -{ -#ifdef USB_PID_GOOGLE - fprintf(vif, "Manufacturer_Info_PID_Port: 0x%04x\r\n", USB_PID_GOOGLE); -#endif -} + } else if ((pdo & PDO_TYPE_MASK) == PDO_TYPE_VARIABLE) { + uint32_t max_voltage = (pdo >> 20) & 0x3ff; + uint32_t min_voltage = (pdo >> 10) & 0x3ff; + uint32_t current = pdo & 0x3ff; -static void write_security_msgs_supported_sop(FILE *vif) -{ - char *yn = "NO"; + power = ((current * 10) * (max_voltage * 50)) / 1000; -#ifdef CONFIG_USB_PD_SECURITY_MSGS - yn = "YES"; -#endif + set_vif_field(&srcPdo->vif_field[Src_PDO_Supply_Type], + "Src_PDO_Supply_Type", + "2", NULL); + set_vif_field(&srcPdo->vif_field[Src_PDO_Peak_Current], + "Src_PDO_Peak_Current", + "0", NULL); + set_vif_field_itss(&srcPdo->vif_field[Src_PDO_Min_Voltage], + "Src_PDO_Min_Voltage", + min_voltage, NULL); + set_vif_field_itss(&srcPdo->vif_field[Src_PDO_Max_Voltage], + "Src_PDO_Max_Voltage", + max_voltage, NULL); + set_vif_field_itss(&srcPdo->vif_field[Src_PDO_Max_Current], + "Src_PDO_Max_Current", + current, NULL); - fprintf(vif, "Security_Msgs_Supported_SOP: %s\r\n", yn); -} + } else if ((pdo & PDO_TYPE_MASK) == PDO_TYPE_AUGMENTED) { + uint32_t pps = (pdo >> 28) & 3; + uint32_t pps_max_voltage = (pdo >> 17) & 0xff; + uint32_t pps_min_voltage = (pdo >> 8) & 0xff; + uint32_t pps_current = pdo & 0x7f; -static void write_num_fixed_batteries(FILE *vif) -{ - int num = 1; + if (pps) { + fprintf(stderr, "ERROR: Invalid PDO_TYPE %d.\n", pdo); + return -1; + } -#ifdef CONFIG_NUM_FIXED_BATTERIES - num = CONFIG_NUM_FIXED_BATTERIES; -#else -#if defined(CONFIG_USB_CTVPD) || defined(CONFIG_USB_VPD) - num = 0; -#endif -#endif + set_vif_field(&srcPdo->vif_field[Src_PDO_Supply_Type], + "Src_PDO_Supply_Type", + "3", NULL); + set_vif_field_itss(&srcPdo->vif_field[Src_PDO_Max_Current], + "Src_PDO_Max_Current", + pps_current, NULL); + set_vif_field_itss(&srcPdo->vif_field[Src_PDO_Min_Voltage], + "Src_PDO_Min_Voltage", + pps_min_voltage, NULL); + set_vif_field_itss(&srcPdo->vif_field[Src_PDO_Min_Voltage], + "Src_PDO_Min_Voltage", + pps_max_voltage, NULL); - fprintf(vif, "Num_Fixed_Batteries: %d\r\n", num); -} + } else { + fprintf(stderr, "ERROR: Invalid PDO_TYPE %d.\n", pdo); + return -1; + } -static void write_num_swappable_battery_slots(FILE *vif) -{ - fprintf(vif, "Num_Swappable_Battery_Slots: 0\r\n"); + return power; } -static void write_sop_capable(FILE *vif) +static int gen_vif(const char *name, + const char *board, + const char *vif_producer) { - char *yn = "YES"; - -#if defined(CONFIG_USB_CTVPD) || defined(CONFIG_USB_VPD) - yn = "NO"; -#endif + FILE *vif_file; + enum dtype type; + struct vif_t vif; + struct vif_field_t *vif_fields; - fprintf(vif, "SOP_Capable: %s\r\n", yn); -} + /* Determine if we are DRP, SRC or SNK */ + if (is_drp()) + type = DRP; + else if (is_src() && is_snk()) + /* No DRP with SRC and SNK PDOs detected. So ignore. */ + /* ie. Twinkie or Plankton */ + return 0; + else if (is_src()) + type = SRC; + else if (is_snk()) + type = SNK; + else + return 1; -static void write_sop_p_capable(FILE *vif) -{ - char *yn = "NO"; + /* Start with an empty vif */ + memset(&vif, 0, sizeof(struct vif_t)); + + /* VIF */ + vif_fields = vif.vif_field; + + set_vif_field(&vif_fields[VIF_Specification], + "VIF_Specification", + NULL, + "Version 3.12"); + + set_vif_field(&vif_fields[VIF_App_Vendor], + "Vendor", + NULL, + "Google"); + + set_vif_field(&vif_fields[VIF_App_Name], + "Name", + NULL, + (char *)vif_producer); + + set_vif_field(&vif_fields[VIF_App_Version], + "Version", + NULL, + "3.0.0.2"); + + set_vif_field(&vif_fields[Vendor_Name], + "Vendor_Name", + NULL, + "Google"); + + #if defined(CONFIG_USB_PD_MODEL_PART_NUMBER) + set_vif_field_stis(&vif_fields[Model_Part_Number], + "Model_Part_Number", + NULL, + CONFIG_USB_PD_MODEL_PART_NUMBER); + #endif -#if defined(CONFIG_USB_CTVPD) || defined(CONFIG_USB_VPD) - yn = "YES"; -#endif + #if defined(CONFIG_USB_PD_PRODUCT_REVISION) + set_vif_field_stis(&vif_fields[Product_Revision], + "Product_Revision", + NULL, + CONFIG_USB_PD_PRODUCT_REVISION); + #endif - fprintf(vif, "SOP_P_Capable: %s\r\n", yn); -} + #if defined(CONFIG_USB_PD_TID) + set_vif_field_stis(&vif_fields[TID], + "TID", + NULL, + CONFIG_USB_PD_TID); + #endif -static void write_sop_pp_capable(FILE *vif) -{ - fprintf(vif, "SOP_PP_Capable: NO\r\n"); -} + set_vif_field(&vif_fields[VIF_Product_Type], + "VIF_Product_Type", + "0", + "Port Product"); -static void write_sop_p_debug_capable(FILE *vif) -{ - fprintf(vif, "SOP_P_Debug_Capable: NO\r\n"); -} + set_vif_field(&vif_fields[Certification_Type], + "Certification_Type", + "1", + "Reference Platform"); -static void write_sop_pp_debug_capable(FILE *vif) -{ - fprintf(vif, "SOP_PP_Debug_Capable: NO\r\n"); -} + /* VIF/Product */ + vif_fields = vif.Product.vif_field; -/* - * USB Type-C Fields - */ + #if defined(CONFIG_USB_PD_PORT_LABEL) + set_vif_field_stis(&vif_fields[Port_Label], + "Port_Label", + NULL, + CONFIG_USB_PD_PORT_LABEL); + #endif -static void write_type_c_implements_try_src(FILE *vif) -{ - char *yn = "NO"; + /* VIF/Component[0] */ + vif_fields = vif.Component[0].vif_field; -#ifdef CONFIG_USB_PD_TRY_SRC - yn = "YES"; -#endif + set_vif_field(&vif_fields[Connector_Type], + "Connector_Type", + "2", + "USB Type-C"); - fprintf(vif, "Type_C_Implements_Try_SRC: %s\r\n", yn); -} + set_vif_field_b(&vif_fields[USB_PD_Support], + "USB_PD_Support", + (IS_ENABLED(CONFIG_USB_PRL_SM) || + IS_ENABLED(CONFIG_USB_POWER_DELIVERY))); -static void write_type_c_implements_try_snk(FILE *vif) -{ - fprintf(vif, "Type_C_Implements_Try_SNK: NO\r\n"); -} + switch (type) { + case SNK: + set_vif_field(&vif_fields[PD_Port_Type], + "PD_Port_Type", + "0", + "Consumer Only"); + set_vif_field(&vif_fields[Type_C_State_Machine], + "Type_C_State_Machine", + "1", + "SNK"); + break; + case SRC: + set_vif_field(&vif_fields[PD_Port_Type], + "PD_Port_Type", + "3", + "Provider Only"); + set_vif_field(&vif_fields[Type_C_State_Machine], + "Type_C_State_Machine", + "0", + "SRC"); + break; + case DRP: + set_vif_field(&vif_fields[PD_Port_Type], + "PD_Port_Type", + "4", + "DRP"); + set_vif_field(&vif_fields[Type_C_State_Machine], + "Type_C_State_Machine", + "2", + "DRP"); + break; + } -static void write_rp_value(FILE *vif) -{ - /* - * 0 - Default - * 1 - 1.5A - * 2 - 3A - */ - int rp = CONFIG_USB_PD_PULLUP; - -#ifdef CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT - rp = CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT; -#endif - - fprintf(vif, "Rp_Value: %d\r\n", rp); -} + set_vif_field_b(&vif_fields[Captive_Cable], + "Captive_Cable", + false); -static void write_type_c_supports_vconn_powered_accessory(FILE *vif) -{ - fprintf(vif, "Type_C_Supports_VCONN_Powered_Accessory: NO\r\n"); -} + set_vif_field_b(&vif_fields[Port_Battery_Powered], + "Port_Battery_Powered", + IS_ENABLED(CONFIG_BATTERY)); -static void write_type_c_is_debug_target_src(FILE *vif) -{ - fprintf(vif, "Type_C_Is_Debug_Target_SRC: YES\r\n"); -} + set_vif_field_b(&vif_fields[BC_1_2_Support], + "BC_1_2_Support", + false); -static void write_type_c_is_debug_target_snk(FILE *vif) -{ - fprintf(vif, "Type_C_Is_Debug_Target_SNK: YES\r\n"); -} + if (IS_ENABLED(CONFIG_USB_PD_REV30) || IS_ENABLED(CONFIG_USB_PRL_SM)) + set_vif_field(&vif_fields[PD_Specification_Revision], + "PD_Specification_Revision", + "2", + "Revision 3.0"); + else + set_vif_field(&vif_fields[PD_Specification_Revision], + "PD_Specification_Revision", + "1", + "Revision 2.0"); -static void write_type_c_can_act_as_host(FILE *vif) -{ - char *yn = "YES"; + set_vif_field_b(&vif_fields[USB_Comms_Capable], + "USB_Comms_Capable", + (!(IS_ENABLED(CONFIG_USB_VPD) || + IS_ENABLED(CONFIG_USB_CTVPD)))); - #if defined(CONFIG_USB_CTVPD) || defined(CONFIG_USB_VPD) - yn = "NO"; - #endif + if (is_src() && (src_pdo[0] & PDO_FIXED_DATA_SWAP)) + set_vif_field_b(&vif_fields[DR_Swap_To_DFP_Supported], + "DR_Swap_To_DFP_Supported", + pd_check_data_swap(0, PD_ROLE_DFP)); + else + set_vif_field_b(&vif_fields[DR_Swap_To_DFP_Supported], + "DR_Swap_To_DFP_Supported", + false); - fprintf(vif, "Type_C_Can_Act_As_Host: %s\r\n", yn); -} + if (is_src() && (src_pdo[0] & PDO_FIXED_DATA_SWAP)) + set_vif_field_b(&vif_fields[DR_Swap_To_UFP_Supported], + "DR_Swap_To_UFP_Supported", + pd_check_data_swap(0, PD_ROLE_UFP)); + else + set_vif_field_b(&vif_fields[DR_Swap_To_UFP_Supported], + "DR_Swap_To_UFP_Supported", + false); -static void write_type_c_is_alt_mode_controller(FILE *vif) -{ - fprintf(vif, "Type_C_Is_Alt_Mode_Controller: NO\r\n"); -} + if (is_src()) + set_vif_field_b(&vif_fields[Unconstrained_Power], + "Unconstrained_Power", + src_pdo[0] & PDO_FIXED_UNCONSTRAINED); + else + set_vif_field_b(&vif_fields[Unconstrained_Power], + "Unconstrained_Power", + false); + + set_vif_field_b(&vif_fields[VCONN_Swap_To_On_Supported], + "VCONN_Swap_To_On_Supported", + IS_ENABLED(CONFIG_USBC_VCONN_SWAP)); + + set_vif_field_b(&vif_fields[VCONN_Swap_To_Off_Supported], + "VCONN_Swap_To_Off_Supported", + IS_ENABLED(CONFIG_USBC_VCONN_SWAP)); + + set_vif_field_b(&vif_fields[Responds_To_Discov_SOP_UFP], + "Responds_To_Discov_SOP_UFP", + false); + + set_vif_field_b(&vif_fields[Responds_To_Discov_SOP_DFP], + "Responds_To_Discov_SOP_DFP", + false); + + set_vif_field_b(&vif_fields[Attempts_Discov_SOP], + "Attempts_Discov_SOP", + ((!IS_ENABLED(CONFIG_USB_PD_SIMPLE_DFP)) || + (type != SRC))); + + set_vif_field_b(&vif_fields[Chunking_Implemented_SOP], + "Chunking_Implemented_SOP", + (IS_ENABLED(CONFIG_USB_PD_REV30) && + IS_ENABLED(CONFIG_USB_PRL_SM))); + + set_vif_field_b(&vif_fields[Unchunked_Extended_Messages_Supported], + "Unchunked_Extended_Messages_Supported", + false); + + set_vif_field_b(&vif_fields[Manufacturer_Info_Supported_Port], + "Manufacturer_Info_Supported_Port", + IS_ENABLED(CONFIG_USB_PD_MANUFACTURER_INFO)); + + #if defined(USB_PID_GOOGLE) + { + char hex_str[10]; + + sprintf(hex_str, "0x%04X", USB_PID_GOOGLE); + set_vif_field(&vif_fields[Manufacturer_Info_PID_Port], + "Manufacturer_Info_PID_Port", + hex_str, hex_str); + } + #endif -static void write_type_c_can_act_as_device(FILE *vif) -{ - char *yn = "NO"; + set_vif_field_b(&vif_fields[Security_Msgs_Supported_SOP], + "Security_Msgs_Supported_SOP", + IS_ENABLED(CONFIG_USB_PD_SECURITY_MSGS)); + + #if defined(CONFIG_NUM_FIXED_BATTERIES) + set_vif_field_itss(&vif_fields[Num_Fixed_Batteries], + "Num_Fixed_Batteries", + CONFIG_NUM_FIXED_BATTERIES, NULL); + #elif defined(CONFIG_USB_CTVPD) || defined(CONFIG_USB_VPD) + set_vif_field(&vif_fields[Num_Fixed_Batteries], + "Num_Fixed_Batteries", + "0", NULL); + #else + set_vif_field(&vif_fields[Num_Fixed_Batteries], + "Num_Fixed_Batteries", + "1", NULL); + #endif -#if defined(USB_DEV_CLASS) && defined(USB_CLASS_BILLBOARD) - if (USB_DEV_CLASS == USB_CLASS_BILLBOARD) - yn = "YES"; -#endif + set_vif_field(&vif_fields[Num_Swappable_Battery_Slots], + "Num_Swappable_Battery_Slots", + "0", NULL); - fprintf(vif, "Type_C_Can_Act_As_Device: %s\r\n", yn); -} + set_vif_field_b(&vif_fields[SOP_Capable], + "SOP_Capable", + (!(IS_ENABLED(CONFIG_USB_CTVPD) || + IS_ENABLED(CONFIG_USB_VPD)))); -static void write_type_c_is_alt_mode_adapter(FILE *vif) -{ - char *yn = "NO"; + set_vif_field_b(&vif_fields[SOP_P_Capable], + "SOP_P_Capable", + (IS_ENABLED(CONFIG_USB_CTVPD) || + IS_ENABLED(CONFIG_USB_VPD))); - if (IS_ENABLED(CONFIG_USB_ALT_MODE_ADAPTER)) - yn = "YES"; + set_vif_field_b(&vif_fields[SOP_PP_Capable], + "SOP_PP_Capable", + false); - fprintf(vif, "Type_C_Is_Alt_Mode_Adapter: %s\r\n", yn); -} + set_vif_field_b(&vif_fields[SOP_P_Debug_Capable], + "SOP_P_Debug_Capable", + false); -static void write_type_c_power_source(FILE *vif) -{ - /* - * 0 - Externally Powered - * 1 - USB-powered - * 2 - Both - */ - int ps = 1; + set_vif_field_b(&vif_fields[SOP_PP_Debug_Capable], + "SOP_PP_Debug_Capable", + false); - if (CONFIG_DEDICATED_CHARGE_PORT_COUNT == 1) - ps = 0; + set_vif_field_b(&vif_fields[Type_C_Implements_Try_SRC], + "Type_C_Implements_Try_SRC", + IS_ENABLED(CONFIG_USB_PD_TRY_SRC)); - fprintf(vif, "Type_C_Power_Source: %d\r\n", ps); -} + set_vif_field_b(&vif_fields[Type_C_Implements_Try_SNK], + "Type_C_Implements_Try_SNK", + false); -static void write_type_c_port_on_hub(FILE *vif) -{ - fprintf(vif, "Type_C_Port_On_Hub: NO\r\n"); -} + { + int rp = CONFIG_USB_PD_PULLUP; -static void write_type_c_supports_audio_accessory(FILE *vif) -{ - fprintf(vif, "Type_C_Supports_Audio_Accessory: NO\r\n"); -} + #if defined(CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT) + rp = CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT; + #endif -static void write_type_c_sources_vconn(FILE *vif) -{ - char *yn = "NO"; + switch (rp) { + case 0: + set_vif_field(&vif_fields[RP_Value], + "RP_Value", + "0", "Default"); + break; + case 1: + set_vif_field(&vif_fields[RP_Value], + "RP_Value", + "1", "1.5A"); + break; + case 2: + set_vif_field(&vif_fields[RP_Value], + "RP_Value", + "2", "3A"); + break; + default: + set_vif_field_itss(&vif_fields[RP_Value], + "RP_Value", + rp, NULL); + } + } -#ifdef CONFIG_USBC_VCONN - yn = "YES"; -#endif + set_vif_field_b(&vif_fields[Type_C_Supports_VCONN_Powered_Accessory], + "Type_C_Supports_VCONN_Powered_Accessory", + false); + set_vif_field_b(&vif_fields[Type_C_Is_Debug_Target_SRC], + "Type_C_Is_Debug_Target_SRC", + true); + set_vif_field_b(&vif_fields[Type_C_Is_Debug_Target_SNK], + "Type_C_Is_Debug_Target_SNK", + true); + + set_vif_field_b(&vif_fields[Type_C_Can_Act_As_Host], + "Type_C_Can_Act_As_Host", + (!(IS_ENABLED(CONFIG_USB_CTVPD) || + IS_ENABLED(CONFIG_USB_VPD)))); + + set_vif_field_b(&vif_fields[Type_C_Is_Alt_Mode_Controller], + "Type_C_Is_Alt_Mode_Controller", + false); + + #if defined(USB_DEV_CLASS) && defined(USB_CLASS_BILLBOARD) + set_vif_field_b(&vif_fields[Type_C_Can_Act_As_Device], + "Type_C_Can_Act_As_Device", + (USB_DEV_CLASS == USB_CLASS_BILLBOARD)); + #else + set_vif_field_b(&vif_fields[Type_C_Can_Act_As_Device], + "Type_C_Can_Act_As_Device", + false); + #endif - fprintf(vif, "Type_C_Source_Vconn: %s\r\n", yn); -} + set_vif_field_b(&vif_fields[Type_C_Is_Alt_Mode_Adapter], + "Type_C_Is_Alt_Mode_Adapter", + (IS_ENABLED(CONFIG_USB_ALT_MODE_ADAPTER))); -/* - * USB Device Fields - */ + { + int ps = 1; -static void write_device_speed(FILE *vif) -{ - /* - * TODO(shurst): USB_2 might not be true for all boards and will need - * changing for future board that implement USB_GENx. - */ - enum usb_speed speed = USB_2; + #if defined(CONFIG_DEDICATED_CHARGE_PORT_COUNT) + if (CONFIG_DEDICATED_CHARGE_PORT_COUNT == 1) + ps = 0; + #endif - fprintf(vif, "Device_Speed: %d\r\n", speed); -} + switch (ps) { + case 0: + set_vif_field(&vif_fields[Type_C_Power_Source], + "Type_C_Power_Source", + "0", "Externally Powered"); + break; + case 1: + set_vif_field(&vif_fields[Type_C_Power_Source], + "Type_C_Power_Source", + "1", "USB-powered"); + break; + case 2: + set_vif_field(&vif_fields[Type_C_Power_Source], + "Type_C_Power_Source", + "2", "Both"); + break; + default: + set_vif_field_itss(&vif_fields[Type_C_Power_Source], + "Type_C_Power_Source", + ps, NULL); + } + } -/* - * PD Source Fields - */ -static int write_pd_source_fields(FILE *vif, enum dtype type) -{ - uint32_t max_power = 0; - char *pdo_buf = NULL; - int i; - int32_t pwr; + set_vif_field_b(&vif_fields[Type_C_Port_On_Hub], + "Type_C_Port_On_Hub", + false); + set_vif_field_b(&vif_fields[Type_C_Supports_Audio_Accessory], + "Type_C_Supports_Audio_Accessory", + false); + + set_vif_field_b(&vif_fields[Type_C_Sources_VCONN], + "Type_C_Sources_VCONN", + IS_ENABLED(CONFIG_USBC_VCONN)); + + { + int ds = USB_2; + + switch (ds) { + case USB_2: + set_vif_field_itss(&vif_fields[Device_Speed], + "Device_Speed", + USB_2, "USB 2"); + break; + case USB_GEN11: + set_vif_field_itss(&vif_fields[Device_Speed], + "Device_Speed", + USB_GEN11, "USB 3.2 GEN 1x1"); + break; + case USB_GEN21: + set_vif_field_itss(&vif_fields[Device_Speed], + "Device_Speed", + USB_GEN21, "USB 3.2 GEN 2x1"); + break; + case USB_GEN12: + set_vif_field_itss(&vif_fields[Device_Speed], + "Device_Speed", + USB_GEN12, "USB 3.2 GEN 1x2"); + break; + case USB_GEN22: + set_vif_field_itss(&vif_fields[Device_Speed], + "Device_Speed", + USB_GEN22, "USB 3.2 GEN 2x2"); + break; + default: + set_vif_field_itss(&vif_fields[Device_Speed], + "Device_Speed", + ds, NULL); + } + } if (type == DRP || type == SRC) { + uint32_t max_power = 0; + int i; + int32_t pwr; + /* Source PDOs */ for (i = 0; i < src_pdo_cnt; i++) { - pwr = write_pdo_to_buf(&pdo_buf, src_pdo[i], SRC, i+1); + pwr = set_vif_src_pdo(&vif.Component[0].SrcPdoList[i], + src_pdo[i]); if (pwr < 0) { - fprintf(stderr, "ERROR: Out of memory.\n"); - fclose(vif); + fprintf(stderr, "ERROR: Setting SRC PDO.\n"); return 1; } @@ -825,57 +1146,71 @@ static int write_pd_source_fields(FILE *vif, enum dtype type) } /* Source Fields */ - fprintf(vif, "PD_Power_as_Source: %d\r\n", max_power); - fprintf(vif, "USB_Suspend_May_Be_Cleared: YES\r\n"); - fprintf(vif, "Sends_Pings: NO\r\n"); - fprintf(vif, "Num_Src_PDOs: %d\r\n", src_pdo_cnt); + set_vif_field_itss(&vif_fields[PD_Power_As_Source], + "PD_Power_As_Source", + max_power, NULL); + set_vif_field_b(&vif_fields[USB_Suspend_May_Be_Cleared], + "USB_Suspend_May_Be_Cleared", + true); + set_vif_field_b(&vif_fields[Sends_Pings], + "Sends_Pings", + false); + set_vif_field_itss(&vif_fields[Num_Src_PDOs], + "Num_Src_PDOs", + src_pdo_cnt, NULL); if (IS_ENABLED(CONFIG_USBC_PPC)) { - /* - * 0 – Over-Current Response - * 1 – Under-Voltage Response - * 2 – Both - */ int resp = 0; - fprintf(vif, "PD_OC_Protection: YES\r\n"); - fprintf(vif, "PD_OCP_Method: %d\r\n", resp); + set_vif_field_b(&vif_fields[PD_OC_Protection], + "PD_OC_Protection", + true); + + switch (resp) { + case 0: + set_vif_field(&vif_fields[PD_OCP_Method], + "PD_OCP_Method", + "0", "Over-Current Response"); + break; + case 1: + set_vif_field(&vif_fields[PD_OCP_Method], + "PD_OCP_Method", + "1", "Under-Voltage Response"); + break; + case 2: + set_vif_field(&vif_fields[PD_OCP_Method], + "PD_OCP_Method", + "2", "Both"); + break; + default: + set_vif_field_itss(&vif_fields[PD_OCP_Method], + "PD_OCP_Method", + resp, NULL); + } } else { - fprintf(vif, "PD_OC_Protection: NO\r\n"); + set_vif_field_b(&vif_fields[PD_OC_Protection], + "PD_OC_Protection", + false); } - - fprintf(vif, "\r\n%s\r\n", pdo_buf); - free(pdo_buf); } - return 0; -} + if (IS_ENABLED(CONFIG_USB_PD_DUAL_ROLE) && + (type == DRP || type == SNK)) { + uint32_t max_power = 0; + int32_t pwr; + int i; + bool giveback = false; + + if (IS_ENABLED(CONFIG_USB_PD_GIVE_BACK)) + giveback = true; -/* - * PD Sink Fields - */ -static int write_pd_sink_fields(FILE *vif, enum dtype type) -{ -#ifdef CONFIG_USB_PD_DUAL_ROLE - uint32_t max_power = 0; - char *pdo_buf = NULL; - int32_t pwr; - int i; - char *giveback = "NO"; - -#ifdef CONFIG_USB_PD_GIVE_BACK - giveback = "YES"; -#endif - - if (type == DRP || type == SNK) { /* Sink PDOs */ for (i = 0; i < pd_snk_pdo_cnt; i++) { - pwr = write_pdo_to_buf(&pdo_buf, - pd_snk_pdo[i], SNK, i+1); + pwr = set_vif_snk_pdo(&vif.Component[0].SnkPdoList[i], + pd_snk_pdo[i]); if (pwr < 0) { - fprintf(stderr, "ERROR: Out of memory.\n"); - fclose(vif); + fprintf(stderr, "ERROR: Setting SNK PDO.\n"); return 1; } @@ -884,183 +1219,51 @@ static int write_pd_sink_fields(FILE *vif, enum dtype type) } /* Sink Fields */ - fprintf(vif, "PD_Power_as_Sink: %d\r\n", max_power); - fprintf(vif, "No_USB_Suspend_May_Be_Set: YES\r\n"); - fprintf(vif, "GiveBack_May_Be_Set: %s\r\n", giveback); - fprintf(vif, "Higher_Capability_Set: NO\r\n"); - fprintf(vif, "Num_Snk_PDOs: %d\r\n", pd_snk_pdo_cnt); - fprintf(vif, "\r\n%s\r\n", pdo_buf); - free(pdo_buf); + set_vif_field_itss(&vif_fields[PD_Power_As_Sink], + "PD_Power_As_Sink", + max_power, NULL); + set_vif_field_b(&vif_fields[No_USB_Suspend_May_Be_Set], + "No_USB_Suspend_May_Be_Set", + true); + set_vif_field_b(&vif_fields[GiveBack_May_Be_Set], + "GiveBack_May_Be_Set", + giveback); + set_vif_field_b(&vif_fields[Higher_Capability_Set], + "Higher_Capability_Set", + false); + set_vif_field_itss(&vif_fields[Num_Snk_PDOs], + "Num_Snk_PDOs", + pd_snk_pdo_cnt, NULL); } -#endif - return 0; -} -/* - * PD Dual Role Fields - */ -static void write_pd_drp_fields(FILE *vif, enum dtype type) -{ -#ifdef CONFIG_USB_PD_DUAL_ROLE - if (type == DRP) { - /* Dual Role Fields */ - fprintf(vif, "Accepts_PR_Swap_As_Src: YES\r\n"); - fprintf(vif, "Accepts_PR_Swap_As_Snk: YES\r\n"); - fprintf(vif, "Requests_PR_Swap_As_Src: YES\r\n"); - fprintf(vif, "FR_Swap_Supported_As_Initial_Sink: NO\r\n"); + if (IS_ENABLED(CONFIG_USB_PD_DUAL_ROLE) && type == DRP) { + set_vif_field_b(&vif_fields[Accepts_PR_Swap_As_Src], + "Accepts_PR_Swap_As_Src", + true); + set_vif_field_b(&vif_fields[Accepts_PR_Swap_As_Snk], + "Accepts_PR_Swap_As_Snk", + true); + set_vif_field_b(&vif_fields[Requests_PR_Swap_As_Src], + "Requests_PR_Swap_As_Src", + true); + set_vif_field_b(&vif_fields[FR_Swap_Supported_As_Initial_Sink], + "FR_Swap_Supported_As_Initial_Sink", + false); } -#endif -} - -/** - * Carriage and line feed, '\r\n', is needed because the file is processed - * on a Windows machine. - */ -static int gen_vif(const char *name, const char *board, - const char *vif_producer) -{ - FILE *vif; - enum dtype type; - if (is_drp()) - type = DRP; - else if (is_src() && is_snk()) - /* No DRP with SRC and SNK PDOs detected. So ignore. */ - /* ie. Twinkie or Plankton */ - return 0; - else if (is_src()) - type = SRC; - else if (is_snk()) - type = SNK; - else + /* Format the structure in XML */ + vif_file = fopen(name, "w+"); + if (vif_file == NULL) return 1; - /* - * Create VIF - */ - vif = fopen(name, "w+"); - if (vif == NULL) - return 1; + vif_output_xml(vif_file, &vif); + fclose(vif_file); - /* - * Write VIF Title - */ - write_title(vif); - - /* - * Write Intro Fields comment - */ - write_field(vif, INTRO); - - write_vif_specification(vif); - write_vif_producer(vif, vif_producer); - write_vendor_name(vif); - write_model_part_number(vif); - write_product_revision(vif); - write_tid(vif); - - /* - * Write VIF Product Fields - */ - write_field(vif, PRODUCT); - - write_vif_product_type(vif); - write_port_label(vif); - write_connector_type(vif); - write_usb_pd_support(vif); - write_pd_port_type(vif, type); - write_type_c_state_machine(vif, type); - write_captive_cable(vif); - write_port_battery_powered(vif); - write_bc_1_2_support(vif, type); - - - /* - * Write General PD Fields - */ - write_field(vif, GENERAL); - - write_pd_spec_rev(vif); - write_usb_comms_capable(vif); - write_dr_swap_to_dfp_supported(vif); - write_dr_swap_to_ufp_supported(vif); - write_unconstrained_power(vif); - write_vconn_swap_to_on_supported(vif); - write_vconn_swap_to_off_supported(vif); - write_responds_to_discov_sop_ufp(vif); - write_responds_to_discov_sop_dfp(vif); - write_attempts_discov_sop(vif, type); - write_chunking_implemented_sop(vif); - write_unchunked_extended_messages_supported(vif); - write_manufacturer_info_supported_port(vif); - write_manufacturer_info_pid_port(vif); - write_security_msgs_supported_sop(vif); - write_num_fixed_batteries(vif); - write_num_swappable_battery_slots(vif); - write_sop_capable(vif); - write_sop_p_capable(vif); - write_sop_pp_capable(vif); - write_sop_p_debug_capable(vif); - write_sop_pp_debug_capable(vif); - - /* - * Write USB Type-C Fields - */ - write_field(vif, USB); - - write_type_c_implements_try_src(vif); - write_type_c_implements_try_snk(vif); - write_rp_value(vif); - write_type_c_supports_vconn_powered_accessory(vif); - write_type_c_is_debug_target_src(vif); - write_type_c_is_debug_target_snk(vif); - write_type_c_can_act_as_host(vif); - write_type_c_is_alt_mode_controller(vif); - write_type_c_can_act_as_device(vif); - write_type_c_is_alt_mode_adapter(vif); - write_type_c_power_source(vif); - write_type_c_port_on_hub(vif); - write_type_c_supports_audio_accessory(vif); - write_type_c_sources_vconn(vif); - - - /* - * Write USB Device Fields - */ - write_field(vif, DEVICE); - - write_device_speed(vif); - - /* - * Write PD Source Fields - */ - write_field(vif, SOURCE); - - write_pd_source_fields(vif, type); - - /* - * Write PD Sink Fields - */ - write_field(vif, SINK); - - write_pd_sink_fields(vif, type); - - - /* - * Write DRP Fields - */ - write_field(vif, DUAL_ROLE); - - write_pd_drp_fields(vif, type); - - /* - * Battery Charging 1.2 Fields - */ - write_field(vif, BC12); - - fclose(vif); return 0; } +/* + * VIF Structure Initialization from Config Functions + *****************************************************************************/ int main(int argc, char **argv) { diff --git a/util/genvif.h b/util/genvif.h new file mode 100644 index 0000000000..84c8c2d221 --- /dev/null +++ b/util/genvif.h @@ -0,0 +1,399 @@ +/* Copyright 2020 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#ifndef __GENVIF_H__ +#define __GENVIF_H__ + +#define MAX_NUM_CABLE_SVIDS 10 +#define MAX_NUM_CABLE_SVID_MODES 10 +#define MAX_NUM_COMPONENTS 10 +#define MAX_NUM_PCIE_ENDPOINTS 10 +#define MAX_NUM_SNK_PDOS 10 +#define MAX_NUM_SRC_PDOS 10 +#define MAX_NUM_SOP_SVIDS 10 +#define MAX_NUM_SOP_SVID_MODES 10 +#define MAX_NUM_USB4_ROUTERS 16 + + +struct vif_field_t { + char *name; + char *tag_value; + char *str_value; +}; + + +enum vif_cableSVIDModeList_indexes { + SVID_Mode_Enter, /* booleanFieldType */ + SVID_Mode_Recog_Mask, /* numericFieldType */ + SVID_Mode_Recog_Value, /* numericFieldType */ + CableSVID_Mode_Indexes +}; +struct vif_cableSVIDModeList_t { + struct vif_field_t vif_field[CableSVID_Mode_Indexes]; +}; + + +enum vif_cableSVIDList_indexes { + SVID, /* numericFieldType */ + SVID_Modes_Fixed, /* booleanFieldType */ + SVID_Num_Modes_Min, /* numericFieldType */ + SVID_Num_Modes_Max, /* numericFieldType */ + CableSVID_Indexes +}; +struct vif_cableSVIDList_t { + struct vif_field_t vif_field[CableSVID_Indexes]; + + struct vif_cableSVIDModeList_t + CableSVIDModeList[MAX_NUM_CABLE_SVID_MODES]; +}; + + +enum vif_sopSVIDModeList_indexes { + SVID_Mode_Enter_SOP, /* booleanFieldType */ + SVID_Mode_Recog_Mask_SOP, /* numericFieldType */ + SVID_Mode_Recog_Value_SOP, /* numericFieldType */ + SopSVID_Mode_Indexes +}; +struct vif_sopSVIDModeList_t { + struct vif_field_t vif_field[SopSVID_Mode_Indexes]; +}; + + +enum vif_sopSVIDList_indexes { + SVID_SOP, /* numericFieldType */ + SVID_Modes_Fixed_SOP, /* booleanFieldType */ + SVID_Num_Modes_Min_SOP, /* numericFieldType */ + SVID_Num_Modes_Max_SOP, /* numericFieldType */ + SopSVID_Indexes +}; +struct vif_sopSVIDList_t { + struct vif_field_t vif_field[SopSVID_Indexes]; + + struct vif_sopSVIDModeList_t + SOPSVIDModeList[MAX_NUM_SOP_SVID_MODES]; +}; + + +enum vif_snkPdoList_indexes { + Snk_PDO_Supply_Type, /* numericFieldType */ + Snk_PDO_Voltage, /* numericFieldType */ + Snk_PDO_Op_Power, /* numericFieldType */ + Snk_PDO_Min_Voltage, /* numericFieldType */ + Snk_PDO_Max_Voltage, /* numericFieldType */ + Snk_PDO_Op_Current, /* numericFieldType */ + Snk_PDO_Indexes +}; +struct vif_snkPdoList_t { + struct vif_field_t vif_field[Snk_PDO_Indexes]; +}; + + +enum vif_srcPdoList_indexes { + Src_PDO_Supply_Type, /* numericFieldType */ + Src_PDO_Peak_Current, /* numericFieldType */ + Src_PDO_Voltage, /* numericFieldType */ + Src_PDO_Max_Current, /* numericFieldType */ + Src_PDO_Min_Voltage, /* numericFieldType */ + Src_PDO_Max_Voltage, /* numericFieldType */ + Src_PDO_Max_Power, /* numericFieldType */ + Src_PD_OCP_OC_Debounce, /* numericFieldType */ + Src_PD_OCP_OC_Threshold, /* numericFieldType */ + Src_PD_OCP_UV_Debounce, /* numericFieldType */ + Src_PD_OCP_UV_Threshold_Type, /* numericFieldType */ + Src_PD_OCP_UV_Threshold, /* numericFieldType */ + Src_PDO_Indexes +}; +struct vif_srcPdoList_t { + struct vif_field_t vif_field[Src_PDO_Indexes]; +}; + + +enum vif_PCIeEndpointListType_indexes { + USB4_PCIe_Endpoint_Vendor_ID, /* numericFieldType */ + USB4_PCIe_Endpoint_Device_ID, /* numericFieldType */ + USB4_PCIe_Endpoint_Class_Code, /* numericFieldType */ + PCIe_Endpoint_Indexes +}; +struct vif_PCIeEndpointListType_t { + struct vif_field_t vif_field[PCIe_Endpoint_Indexes]; +}; + + +enum vif_Usb4RouterListType_indexes { + USB4_Router_ID, /* numericFieldType */ + USB4_Silicon_VID, /* numericFieldType */ + USB4_Num_Lane_Adapters, /* numericFieldType */ + USB4_Num_USB3_DN_Adapters, /* numericFieldType */ + USB4_Num_DP_IN_Adapters, /* numericFieldType */ + USB4_Num_DP_OUT_Adapters, /* numericFieldType */ + USB4_Num_PCIe_DN_Adapters, /* numericFieldType */ + USB4_TBT3_Not_Supported, /* numericFieldType */ + USB4_PCIe_Wake_Supported, /* booleanFieldType */ + USB4_USB3_Wake_Supported, /* booleanFieldType */ + USB4_Num_Unused_Adapters, /* numericFieldType */ + USB4_TBT3_VID, /* numericFieldType */ + USB4_PCIe_Switch_Vendor_ID, /* numericFieldType */ + USB4_PCIe_Switch_Device_ID, /* numericFieldType */ + USB4_Num_PCIe_Endpoints, /* numericFieldType */ + USB4_Router_Indexes +}; +struct vif_Usb4RouterListType_t { + struct vif_field_t vif_field[USB4_Router_Indexes]; + + struct vif_PCIeEndpointListType_t + PCIeEndpointList[MAX_NUM_PCIE_ENDPOINTS]; +}; + + +enum vif_Component_indexes { + Port_Label, /* nonEmptyString */ + Connector_Type, /* numericFieldType */ + USB4_Supported, /* booleanFieldType */ + USB_PD_Support, /* booleanFieldType */ + PD_Port_Type, /* numericFieldType */ + Type_C_State_Machine, /* numericFieldType */ + Port_Battery_Powered, /* booleanFieldType */ + BC_1_2_Support, /* numericFieldType */ + PD_Spec_Revision_Major, /* numericFieldType */ + PD_Spec_Revision_Minor, /* numericFieldType */ + PD_Spec_Version_Major, /* numericFieldType */ + PD_Spec_Version_Minor, /* numericFieldType */ + PD_Specification_Revision, /* numericFieldType */ + SOP_Capable, /* booleanFieldType */ + SOP_P_Capable, /* booleanFieldType */ + SOP_PP_Capable, /* booleanFieldType */ + SOP_P_Debug_Capable, /* booleanFieldType */ + SOP_PP_Debug_Capable, /* booleanFieldType */ + Manufacturer_Info_Supported_Port, /* booleanFieldType */ + Manufacturer_Info_VID_Port, /* numericFieldType */ + Manufacturer_Info_PID_Port, /* numericFieldType */ + USB_Comms_Capable, /* booleanFieldType */ + DR_Swap_To_DFP_Supported, /* booleanFieldType */ + DR_Swap_To_UFP_Supported, /* booleanFieldType */ + Unconstrained_Power, /* booleanFieldType */ + VCONN_Swap_To_On_Supported, /* booleanFieldType */ + VCONN_Swap_To_Off_Supported, /* booleanFieldType */ + Responds_To_Discov_SOP_UFP, /* booleanFieldType */ + Responds_To_Discov_SOP_DFP, /* booleanFieldType */ + Attempts_Discov_SOP, /* booleanFieldType */ + Chunking_Implemented_SOP, /* booleanFieldType */ + Unchunked_Extended_Messages_Supported, /* booleanFieldType */ + Security_Msgs_Supported_SOP, /* booleanFieldType */ + Num_Fixed_Batteries, /* numericFieldType */ + Num_Swappable_Battery_Slots, /* numericFieldType */ + ID_Header_Connector_Type_SOP, /* numericFieldType */ + Type_C_Can_Act_As_Host, /* booleanFieldType */ + Type_C_Can_Act_As_Device, /* booleanFieldType */ + Type_C_Implements_Try_SRC, /* booleanFieldType */ + Type_C_Implements_Try_SNK, /* booleanFieldType */ + Type_C_Supports_Audio_Accessory, /* booleanFieldType */ + Type_C_Supports_VCONN_Powered_Accessory,/* booleanFieldType */ + Type_C_Is_VCONN_Powered_Accessory, /* booleanFieldType */ + Type_C_Is_Debug_Target_SRC, /* booleanFieldType */ + Type_C_Is_Debug_Target_SNK, /* booleanFieldType */ + Captive_Cable, /* booleanFieldType */ + RP_Value, /* numericFieldType */ + Type_C_Port_On_Hub, /* booleanFieldType */ + Type_C_Power_Source, /* numericFieldType */ + Type_C_Sources_VCONN, /* booleanFieldType */ + Type_C_Is_Alt_Mode_Controller, /* booleanFieldType */ + Type_C_Is_Alt_Mode_Adapter, /* booleanFieldType */ + USB4_Router_Index, /* numericFieldType */ + USB4_Lane_0_Adapter, /* numericFieldType */ + USB4_Max_Speed, /* numericFieldType */ + USB4_DFP_Supported, /* booleanFieldType */ + USB4_UFP_Supported, /* booleanFieldType */ + USB4_USB3_Tunneling_Supported, /* booleanFieldType */ + USB4_DP_Tunneling_Supported, /* booleanFieldType */ + USB4_PCIe_Tunneling_Supported, /* booleanFieldType */ + USB4_TBT3_Compatibility_Supported, /* booleanFieldType */ + USB4_CL1_State_Supported, /* booleanFieldType */ + USB4_CL2_State_Supported, /* booleanFieldType */ + USB4_Num_Retimers, /* numericFieldType */ + USB4_DP_Bit_Rate, /* numericFieldType */ + USB4_Num_DP_Lanes, /* numericFieldType */ + Host_Supports_USB_Data, /* booleanFieldType */ + Host_Speed, /* numericFieldType */ + Host_Contains_Captive_Retimer, /* booleanFieldType */ + Host_Truncates_DP_For_tDHPResponse, /* booleanFieldType */ + Host_Gen1x1_tLinkTurnaround, /* numericFieldType */ + Host_Gen2x1_tLinkTurnaround, /* numericFieldType */ + Host_Is_Embedded, /* booleanFieldType */ + Host_Suspend_Supported, /* booleanFieldType */ + Is_DFP_On_Hub, /* booleanFieldType */ + Hub_Port_Number, /* numericFieldType */ + Device_Supports_USB_Data, /* booleanFieldType */ + Device_Speed, /* numericFieldType */ + Device_Contains_Captive_Retimer, /* booleanFieldType */ + Device_Truncates_DP_For_tDHPResponse, /* booleanFieldType */ + Device_Gen1x1_tLinkTurnaround, /* numericFieldType */ + Device_Gen2x1_tLinkTurnaround, /* numericFieldType */ + BC_1_2_Charging_Port_Type, /* numericFieldType */ + PD_Power_As_Source, /* numericFieldType */ + USB_Suspend_May_Be_Cleared, /* booleanFieldType */ + Sends_Pings, /* booleanFieldType */ + FR_Swap_Type_C_Current_Capability_As_Initial_Sink,/* numericFieldType */ + Master_Port, /* booleanFieldType */ + Num_Src_PDOs, /* numericFieldType */ + PD_OC_Protection, /* booleanFieldType */ + PD_OCP_Method, /* numericFieldType */ + PD_Power_As_Sink, /* numericFieldType */ + No_USB_Suspend_May_Be_Set, /* booleanFieldType */ + GiveBack_May_Be_Set, /* booleanFieldType */ + Higher_Capability_Set, /* booleanFieldType */ + FR_Swap_Reqd_Type_C_Current_As_Initial_Source,/* numericFieldType */ + Num_Snk_PDOs, /* numericFieldType */ + Accepts_PR_Swap_As_Src, /* booleanFieldType */ + Accepts_PR_Swap_As_Snk, /* booleanFieldType */ + Requests_PR_Swap_As_Src, /* booleanFieldType */ + Requests_PR_Swap_As_Snk, /* booleanFieldType */ + FR_Swap_Supported_As_Initial_Sink, /* booleanFieldType */ + XID_SOP, /* numericFieldType */ + Data_Capable_As_USB_Host_SOP, /* booleanFieldType */ + Data_Capable_As_USB_Device_SOP, /* booleanFieldType */ + Product_Type_UFP_SOP, /* numericFieldType */ + Product_Type_DFP_SOP, /* numericFieldType */ + DFP_VDO_Port_Number, /* numericFieldType */ + Modal_Operation_Supported_SOP, /* booleanFieldType */ + USB_VID_SOP, /* numericFieldType */ + PID_SOP, /* numericFieldType */ + bcdDevice_SOP, /* numericFieldType */ + SVID_Fixed_SOP, /* booleanFieldType */ + Num_SVIDs_Min_SOP, /* numericFieldType */ + Num_SVIDs_Max_SOP, /* numericFieldType */ + AMA_HW_Vers, /* numericFieldType */ + AMA_FW_Vers, /* numericFieldType */ + AMA_VCONN_Reqd, /* booleanFieldType */ + AMA_VCONN_Power, /* booleanFieldType */ + AMA_VBUS_Reqd, /* booleanFieldType */ + AMA_Superspeed_Support, /* numericFieldType */ + Product_Total_Source_Power_mW, /* numericFieldType */ + Port_Source_Power_Type, /* numericFieldType */ + Port_Source_Power_Gang, /* nonEmptyString */ + Port_Source_Power_Gang_Max_Power, /* numericFieldType */ + XID, /* numericFieldType */ + Data_Capable_As_USB_Host, /* booleanFieldType */ + Data_Capable_As_USB_Device, /* booleanFieldType */ + Product_Type, /* numericFieldType */ + Modal_Operation_Supported, /* booleanFieldType */ + USB_VID, /* numericFieldType */ + PID, /* numericFieldType */ + bcdDevice, /* numericFieldType */ + Cable_HW_Vers, /* numericFieldType */ + Cable_FW_Vers, /* numericFieldType */ + Type_C_To_Type_A_B_C, /* numericFieldType */ + Type_C_To_Type_C_Capt_Vdm_V2, /* numericFieldType */ + Cable_Latency, /* numericFieldType */ + Cable_Termination_Type, /* numericFieldType */ + VBUS_Through_Cable, /* booleanFieldType */ + Cable_VBUS_Current, /* numericFieldType */ + Cable_Superspeed_Support, /* numericFieldType */ + Cable_USB_Highest_Speed, /* numericFieldType */ + Max_VBUS_Voltage_Vdm_V2, /* numericFieldType */ + Manufacturer_Info_Supported, /* booleanFieldType */ + Manufacturer_Info_VID, /* numericFieldType */ + Manufacturer_Info_PID, /* numericFieldType */ + Chunking_Implemented, /* booleanFieldType */ + Security_Msgs_Supported, /* booleanFieldType */ + ID_Header_Connector_Type, /* numericFieldType */ + SVID_Fixed, /* booleanFieldType */ + Cable_Num_SVIDs_Min, /* numericFieldType */ + Cable_Num_SVIDs_Max, /* numericFieldType */ + VPD_HW_Vers, /* numericFieldType */ + VPD_FW_Vers, /* numericFieldType */ + VPD_Max_VBUS_Voltage, /* numericFieldType */ + VPD_Charge_Through_Support, /* booleanFieldType */ + VPD_Charge_Through_Current, /* numericFieldType */ + VPD_VBUS_Impedance, /* numericFieldType */ + VPD_Ground_Impedance, /* numericFieldType */ + Cable_SOP_PP_Controller, /* booleanFieldType */ + SBU_Supported, /* booleanFieldType */ + SBU_Type, /* numericFieldType */ + Active_Cable_Operating_Temp_Support, /* booleanFieldType */ + Active_Cable_Max_Operating_Temp, /* numericFieldType */ + Active_Cable_Shutdown_Temp_Support, /* booleanFieldType */ + Active_Cable_Shutdown_Temp, /* numericFieldType */ + Active_Cable_U3_CLd_Power, /* numericFieldType */ + Active_Cable_U3_U0_Trans_Mode, /* numericFieldType */ + Active_Cable_Physical_Connection, /* numericFieldType */ + Active_Cable_Active_Element, /* numericFieldType */ + Active_Cable_USB4_Support, /* booleanFieldType */ + Active_Cable_USB2_Hub_Hops_Consumed, /* numericFieldType */ + Active_Cable_USB2_Supported, /* booleanFieldType */ + Active_Cable_USB32_Supported, /* booleanFieldType */ + Active_Cable_USB_Lanes, /* numericFieldType */ + Active_Cable_Optically_Isolated, /* booleanFieldType */ + Active_Cable_USB_Gen, /* numericFieldType */ + Repeater_One_Type, /* numericFieldType */ + Repeater_Two_Type, /* numericFieldType */ + Component_Indexes +}; +struct vif_Component_t { + struct vif_field_t vif_field[Component_Indexes]; + + struct vif_srcPdoList_t SrcPdoList[MAX_NUM_SRC_PDOS]; + struct vif_snkPdoList_t SnkPdoList[MAX_NUM_SNK_PDOS]; + struct vif_sopSVIDList_t SOPSVIDList[MAX_NUM_SOP_SVIDS]; + struct vif_cableSVIDList_t CableSVIDList[MAX_NUM_CABLE_SVIDS]; + + + /* + * The following fields are deprecated. They should not be written + * to file in this version or any later version of the schema. + * + * Deprecated in VIF Version 3.10 + * vif_numericFieldType_t type_c_to_plug_receptacle; + * vif_numericFieldType_t retimer_type; + * Deprecated in VIF Version 3.12 + * vif_numericFieldType_t active_cable_usb2_hub_hops_supported; + * vif_booleanFieldType_t active_cable_optically_isololated; + */ +}; + + +enum vif_Product_indexes { + Product_VID, /* numericFieldType */ + USB4_Dock, /* booleanFieldType */ + USB4_Num_Internal_Host_Controllers, /* numericFieldType */ + USB4_Num_PCIe_DN_Bridges, /* numericFieldType */ + USB4_Audio_Supported, /* booleanFieldType */ + USB4_HID_Supported, /* booleanFieldType */ + USB4_Printer_Supported, /* booleanFieldType */ + USB4_Mass_Storage_Supported, /* booleanFieldType */ + USB4_Video_Supported, /* booleanFieldType */ + USB4_Comms_Networking_Supported, /* booleanFieldType */ + USB4_Media_Transfer_Protocol_Supported, /* booleanFieldType */ + USB4_Smart_Card_Supported, /* booleanFieldType */ + USB4_Still_Image_Capture_Supported, /* booleanFieldType */ + USB4_Monitor_Device_Supported, /* booleanFieldType */ + Product_Indexes +}; +struct vif_Product_t { + struct vif_field_t vif_field[Product_Indexes]; + + struct vif_Usb4RouterListType_t USB4RouterList[MAX_NUM_USB4_ROUTERS]; +}; + + +enum vif_indexes { + VIF_Specification, /* version */ + VIF_App_Vendor, /* nonEmptyString */ + VIF_App_Name, /* nonEmptyString */ + VIF_App_Version, /* version */ + Vendor_Name, /* nonEmptyString */ + Model_Part_Number, /* nonEmptyString */ + Product_Revision, /* nonEmptyString */ + TID, /* nonEmptyString */ + VIF_Product_Type, /* numericFieldType */ + Certification_Type, /* numericFieldType */ + VIF_Indexes +}; +struct vif_t { + struct vif_field_t vif_field[VIF_Indexes]; + + struct vif_Product_t Product; + struct vif_Component_t Component[MAX_NUM_COMPONENTS]; +}; + +#endif /* __GENVIF_H__ */ |