Skip to content

Commit e167e0d

Browse files
Josh-TsaiJohnAZoidberg
authored andcommitted
fwk: ucsi: modified the condition to avoid the wrong pointer
The commit 60f3eb1 we used the active_pd_chip_count to avoid the PD which is no power, also do the UCSI communication. But if the no-power PD chip is the higher priority one, the index will be wrong and point to the wrong address cause the "Precise data bus error". [85.411800 Resend: P1 CCI: 0x20000008 Port4, Acknowledge ] ec:~> E: ***** BUS FAULT ***** E: Precise data bus error E: BFAR Address: 0xaaaaaaaa E: r0/a1: 0x200c4791 r1/a2: 0xaaaaaaaa r2/a3: 0xaaaaaacc E: r3/a4: 0x200c4790 r12/ip: 0x200c11a0 r14/lr: 0x100943e5 E: xpsr: 0x81000000 E: r4/v1: 0x200c1b08 r5/v2: 0x200c1f94 r6/v3: 0x00000000 E: r7/v4: 0x00000000 r8/v5: 0x00000022 r9/v6: 0x00000000 E: r10/v7: 0x00000171 r11/v8: 0x200c1f94 psp: 0x200c6718 E: EXC_RETURN: 0xfffffffd E: Faulting instruction address (r15/pc): 0x100a4338 E: >>> ZEPHYR FATAL ERROR 25: Unknown error on CPU 0 E: Current thread: 0x200c2388 (CYPD) This change modifies the condition to solve this issue and ensure the UCSI use the correct index in the higher priority PD chip is no power. BRANCH=fwk-main BUG=Wrong index cause the "Precise data bus error" TEST=Set the PD0 to no-power and PD1 to ready. Enter standby mode and then plug-in the USB storage. Wake up the system does not happen "Precise data bus error" TEST=Do not need to run the HLK, because if two PD chips state are ready, the logic does not be changed. [104.553200 Fan 0 stalled!] [105.110000 Resend: P1 CCI: 0x20000008 Port4, Acknowledge ] [105.114800 RESERVE Complete] [105.115500 CCI (Host): 0x20000008 Port4, Acknowledge ] [105.161500 PL1:28, PL2:46, PL4:80, PSYSPL2:57 updated suc Signed-off-by: Josh Tsai <Josh_Tsai@compal.com> (cherry picked from commit b4171256ff0cc436bf16d59df3fe37a185285b1c)
1 parent e9b421b commit e167e0d

1 file changed

Lines changed: 29 additions & 8 deletions

File tree

  • zephyr/program/framework/src

zephyr/program/framework/src/ucsi.c

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ int ucsi_write_tunnel(void)
120120
CPRINTS("UCSI PPM_RESET");
121121
}
122122

123-
for (int i = 0; i < active_pd_chip_count; i++)
123+
for (int i = 0; i < PD_CHIP_COUNT; i++)
124124
pd_chip_ucsi_info[i].read_tunnel_complete = 0;
125125

126126
/* The connector number offset is 24 bits in GET_ALTERNATE_MODES command */
@@ -158,7 +158,11 @@ int ucsi_write_tunnel(void)
158158
}
159159

160160
if (cmd_need_broadcast) {
161-
for (int i = 0; i < active_pd_chip_count; i++) {
161+
for (int i = 0; i < PD_CHIP_COUNT; i++) {
162+
163+
/* If PD chip state is CCG_STATE_NO_POWER, ignore the UCSI event */
164+
if (!cypd_contoller_is_powered(i))
165+
continue;
162166

163167
/**
164168
* If the controller does not needs to respond ACK,
@@ -300,7 +304,11 @@ static int ucsi_check_all_pd_status(int operator)
300304

301305
/* or operator = 0; and operator = 1 */
302306
if (operator) {
303-
for (controller = 0; controller < active_pd_chip_count; controller++) {
307+
for (controller = 0; controller < PD_CHIP_COUNT; controller++) {
308+
309+
if (!cypd_contoller_is_powered(controller))
310+
continue;
311+
304312
/**
305313
* In the and operator condition,
306314
* if one pd chip does not complete the read tunnel, return false
@@ -313,7 +321,11 @@ static int ucsi_check_all_pd_status(int operator)
313321
return true;
314322
}
315323

316-
for (controller = 0; controller < active_pd_chip_count; controller++) {
324+
for (controller = 0; controller < PD_CHIP_COUNT; controller++) {
325+
326+
if (!cypd_contoller_is_powered(controller))
327+
continue;
328+
317329
/**
318330
* In the or operator condition,
319331
* if one pd chip has completed the read tunnel, return true
@@ -508,7 +520,10 @@ void check_ucsi_event_from_host(void)
508520
/* If the UCSI interface previously was busy then
509521
* poll to see if the busy bit cleared
510522
*/
511-
for (i = 0; i < active_pd_chip_count; i++) {
523+
for (i = 0; i < PD_CHIP_COUNT; i++) {
524+
if (!cypd_contoller_is_powered(i))
525+
continue;
526+
512527
if (pd_chip_ucsi_info[i].cci & CCI_BUSY_FLAG) {
513528
ucsi_read_tunnel(i);
514529
}
@@ -536,7 +551,10 @@ void check_ucsi_event_from_host(void)
536551
if (read_complete) {
537552

538553
/* The highest priority of the PD chip is pd 0 */
539-
for (i = (active_pd_chip_count - 1); i >= 0; i--) {
554+
for (i = (PD_CHIP_COUNT - 1); i >= 0; i--) {
555+
if (!cypd_contoller_is_powered(i))
556+
continue;
557+
540558
if (pd_chip_ucsi_info[i].read_tunnel_complete) {
541559
message_in = pd_chip_ucsi_info[i].message_in;
542560
cci = &pd_chip_ucsi_info[i].cci;
@@ -552,7 +570,10 @@ void check_ucsi_event_from_host(void)
552570
* both controllers
553571
*/
554572
if (ucsi_check_all_pd_status(OPERATOR_AND)) {
555-
for (i = 0; i < active_pd_chip_count; i++) {
573+
for (i = 0; i <= PD_CHIP_COUNT; i++) {
574+
if (!cypd_contoller_is_powered(i))
575+
continue;
576+
556577
if (command == UCSI_CMD_GET_ERROR_STATUS) {
557578
uint16_t error_information =
558579
(pd_chip_ucsi_info[i].message_in[1] << 8) |
@@ -621,7 +642,7 @@ void check_ucsi_event_from_host(void)
621642
if (command == UCSI_CMD_GET_CAPABILITY)
622643
*host_get_memmap(message_in_offset + 4) = valid_ucsi_port_count;
623644

624-
for (i = 0; i < active_pd_chip_count; i++)
645+
for (i = 0; i < PD_CHIP_COUNT; i++)
625646
pd_chip_ucsi_info[i].read_tunnel_complete = 0;
626647

627648
/* clear the UCSI command if busy flag is not set */

0 commit comments

Comments
 (0)