summaryrefslogtreecommitdiff
path: root/include/usb_pd_vdo.h
diff options
context:
space:
mode:
authorDiana Z <dzigterman@chromium.org>2020-08-26 16:31:42 -0600
committerCommit Bot <commit-bot@chromium.org>2020-09-02 20:32:56 +0000
commitca54ec42cbf8b3164529ed4e4425879fa774004b (patch)
tree0d26b0f36f9a4fc49b3efd362b4e8f89d84d2b0e /include/usb_pd_vdo.h
parente74f988385e6f7cad5db96e939c41fb1efc001d8 (diff)
downloadchrome-ec-ca54ec42cbf8b3164529ed4e4425879fa774004b.tar.gz
TCPM: Correct VDO structures
When defined bit fields for a unit8_t cross byte boundaries, this can cause unexpected packing. In this case, all of the VDO unions were actually of size 8, rather than size 4. This change alters the fields to be defined in a uint32_t, and adds build asserts to ensure the unions remain the correct size. BRANCH=None BUG=None TEST=make -j buildall Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: Ia3d585820dcb3e825c02f8732791b53fbdff96af Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2379992 Reviewed-by: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'include/usb_pd_vdo.h')
-rw-r--r--include/usb_pd_vdo.h104
1 files changed, 53 insertions, 51 deletions
diff --git a/include/usb_pd_vdo.h b/include/usb_pd_vdo.h
index d43c92d144..2cecec5d84 100644
--- a/include/usb_pd_vdo.h
+++ b/include/usb_pd_vdo.h
@@ -162,18 +162,18 @@ enum usb_vbus_cur {
union passive_cable_vdo_rev30 {
struct {
enum usb_rev30_ss ss: 3;
- uint8_t reserved0 : 2;
+ uint32_t reserved0 : 2;
enum usb_vbus_cur vbus_cur : 2;
- uint8_t reserved1 : 2;
- uint8_t vbus_max : 2;
- uint8_t termination : 2;
- uint8_t latency : 4;
- uint8_t reserved2 : 1;
- uint8_t connector : 2;
- uint8_t reserved3 : 1;
- uint8_t vdo_version : 3;
- uint8_t fw_version : 4;
- uint8_t hw_version : 4;
+ uint32_t reserved1 : 2;
+ uint32_t vbus_max : 2;
+ uint32_t termination : 2;
+ uint32_t latency : 4;
+ uint32_t reserved2 : 1;
+ uint32_t connector : 2;
+ uint32_t reserved3 : 1;
+ uint32_t vdo_version : 3;
+ uint32_t fw_version : 4;
+ uint32_t hw_version : 4;
};
uint32_t raw_value;
};
@@ -246,20 +246,20 @@ union passive_cable_vdo_rev30 {
union active_cable_vdo1_rev30 {
struct {
enum usb_rev30_ss ss: 3;
- uint8_t sop_p_p : 1;
- uint8_t vbus_cable : 1;
+ uint32_t sop_p_p : 1;
+ uint32_t vbus_cable : 1;
enum usb_vbus_cur vbus_cur : 2;
- uint8_t sbu_type : 1;
- uint8_t sbu_support : 1;
- uint8_t vbus_max : 2;
- uint8_t termination : 2;
- uint8_t latency : 4;
- uint8_t reserved0 : 1;
- uint8_t connector : 2;
- uint8_t reserved1 : 1;
- uint8_t vdo_version : 3;
- uint8_t fw_version : 4;
- uint8_t hw_version : 4;
+ uint32_t sbu_type : 1;
+ uint32_t sbu_support : 1;
+ uint32_t vbus_max : 2;
+ uint32_t termination : 2;
+ uint32_t latency : 4;
+ uint32_t reserved0 : 1;
+ uint32_t connector : 2;
+ uint32_t reserved1 : 1;
+ uint32_t vdo_version : 3;
+ uint32_t fw_version : 4;
+ uint32_t hw_version : 4;
};
uint32_t raw_value;
};
@@ -594,20 +594,20 @@ enum usb_rev20_ss {
union passive_cable_vdo_rev20 {
struct {
enum usb_rev20_ss ss: 3;
- uint8_t reserved0 : 1;
- uint8_t vbus_cable : 1;
+ uint32_t reserved0 : 1;
+ uint32_t vbus_cable : 1;
enum usb_vbus_cur vbus_cur : 2;
- uint8_t ssrx2 : 1;
- uint8_t ssrx1 : 1;
- uint8_t sstx2 : 1;
- uint8_t sstx1 : 1;
- uint8_t termination : 2;
- uint8_t latency : 4;
- uint8_t reserved1 : 1;
- uint8_t connector : 2;
- uint8_t reserved2 : 4;
- uint8_t fw_version : 4;
- uint8_t hw_version : 4;
+ uint32_t ssrx2 : 1;
+ uint32_t ssrx1 : 1;
+ uint32_t sstx2 : 1;
+ uint32_t sstx1 : 1;
+ uint32_t termination : 2;
+ uint32_t latency : 4;
+ uint32_t reserved1 : 1;
+ uint32_t connector : 2;
+ uint32_t reserved2 : 4;
+ uint32_t fw_version : 4;
+ uint32_t hw_version : 4;
};
uint32_t raw_value;
};
@@ -677,21 +677,21 @@ union passive_cable_vdo_rev20 {
union active_cable_vdo_rev20 {
struct {
enum usb_rev20_ss ss: 3;
- uint8_t sop_p_p : 1;
- uint8_t vbus_cable : 1;
+ uint32_t sop_p_p : 1;
+ uint32_t vbus_cable : 1;
enum usb_vbus_cur vbus_cur : 2;
- uint8_t ssrx2 : 1;
- uint8_t ssrx1 : 1;
- uint8_t sstx2 : 1;
- uint8_t sstx1 : 1;
- uint8_t termination : 2;
- uint8_t latency : 4;
- uint8_t reserved0 : 1;
- uint8_t connector : 2;
- uint8_t reserved1 : 1;
- uint8_t vdo_version : 3;
- uint8_t fw_version : 4;
- uint8_t hw_version : 4;
+ uint32_t ssrx2 : 1;
+ uint32_t ssrx1 : 1;
+ uint32_t sstx2 : 1;
+ uint32_t sstx1 : 1;
+ uint32_t termination : 2;
+ uint32_t latency : 4;
+ uint32_t reserved0 : 1;
+ uint32_t connector : 2;
+ uint32_t reserved1 : 1;
+ uint32_t vdo_version : 3;
+ uint32_t fw_version : 4;
+ uint32_t hw_version : 4;
};
uint32_t raw_value;
};
@@ -862,11 +862,13 @@ union product_type_vdo1 {
uint32_t raw_value;
};
+BUILD_ASSERT(sizeof(uint32_t) == sizeof(union product_type_vdo1));
union product_type_vdo2 {
union active_cable_vdo2_rev30 a2_rev30;
uint32_t raw_value;
};
+BUILD_ASSERT(sizeof(uint32_t) == sizeof(union product_type_vdo2));
#endif /* __CROS_EC_USB_PD_VDO_H */