diff options
58 files changed, 230 insertions, 195 deletions
diff --git a/board/amenia/board.c b/board/amenia/board.c index 767a491883..670ceb2870 100644 --- a/board/amenia/board.c +++ b/board/amenia/board.c @@ -85,10 +85,11 @@ void usb1_evt(enum gpio_signal signal) * state of GPIOs, so its definition must reside after including gpio_list. */ static void enable_input_devices(void); +DECLARE_DEFERRED(enable_input_devices); void tablet_mode_interrupt(enum gpio_signal signal) { - hook_call_deferred(enable_input_devices, 0); + hook_call_deferred(&enable_input_devices_data, 0); } #include "gpio_list.h" @@ -301,19 +302,18 @@ static void enable_input_devices(void) keyboard_scan_enable(kb_enable, KB_SCAN_DISABLE_LID_ANGLE); gpio_set_level(GPIO_ENABLE_TOUCHPAD, tp_enable); } -DECLARE_DEFERRED(enable_input_devices); /* Called on AP S5 -> S3 transition */ static void board_chipset_startup(void) { - hook_call_deferred(enable_input_devices, 0); + hook_call_deferred(&enable_input_devices_data, 0); } DECLARE_HOOK(HOOK_CHIPSET_STARTUP, board_chipset_startup, HOOK_PRIO_DEFAULT); /* Called on AP S3 -> S5 transition */ static void board_chipset_shutdown(void) { - hook_call_deferred(enable_input_devices, 0); + hook_call_deferred(&enable_input_devices_data, 0); } DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, board_chipset_shutdown, HOOK_PRIO_DEFAULT); diff --git a/board/amenia/usb_pd_policy.c b/board/amenia/usb_pd_policy.c index f2fbced24e..803dfecef2 100644 --- a/board/amenia/usb_pd_policy.c +++ b/board/amenia/usb_pd_policy.c @@ -303,8 +303,9 @@ static void hpd1_irq_deferred(void) DECLARE_DEFERRED(hpd0_irq_deferred); DECLARE_DEFERRED(hpd1_irq_deferred); -#define PORT_TO_HPD_IRQ_DEFERRED(port) ((port) ? hpd1_irq_deferred : \ - hpd0_irq_deferred) +#define PORT_TO_HPD_IRQ_DEFERRED(port) ((port) ? \ + &hpd1_irq_deferred_data : \ + &hpd0_irq_deferred_data) static int svdm_dp_attention(int port, uint32_t *payload) { diff --git a/board/chell/usb_pd_policy.c b/board/chell/usb_pd_policy.c index cc2c87d239..cf57b09345 100644 --- a/board/chell/usb_pd_policy.c +++ b/board/chell/usb_pd_policy.c @@ -308,8 +308,9 @@ static void hpd1_irq_deferred(void) DECLARE_DEFERRED(hpd0_irq_deferred); DECLARE_DEFERRED(hpd1_irq_deferred); -#define PORT_TO_HPD_IRQ_DEFERRED(port) ((port) ? hpd1_irq_deferred : \ - hpd0_irq_deferred) +#define PORT_TO_HPD_IRQ_DEFERRED(port) ((port) ? \ + &hpd1_irq_deferred_data : \ + &hpd0_irq_deferred_data) static int svdm_dp_attention(int port, uint32_t *payload) { diff --git a/board/dingdong/board.c b/board/dingdong/board.c index 5091494dfb..ae79cb5b6b 100644 --- a/board/dingdong/board.c +++ b/board/dingdong/board.c @@ -74,7 +74,7 @@ void hpd_event(enum gpio_signal signal) hpd_prev_ts = now.val; /* All previous hpd level events need to be re-triggered */ - hook_call_deferred(hpd_lvl_deferred, -1); + hook_call_deferred(&hpd_lvl_deferred_data, -1); /* It's a glitch. Previous time moves but level is the same. */ if (cur_delta < HPD_USTREAM_DEBOUNCE_IRQ) @@ -83,9 +83,10 @@ void hpd_event(enum gpio_signal signal) if ((!hpd_prev_level && level) && (cur_delta < HPD_USTREAM_DEBOUNCE_LVL)) /* It's an irq */ - hook_call_deferred(hpd_irq_deferred, 0); + hook_call_deferred(&hpd_irq_deferred_data, 0); else if (cur_delta >= HPD_USTREAM_DEBOUNCE_LVL) - hook_call_deferred(hpd_lvl_deferred, HPD_USTREAM_DEBOUNCE_LVL); + hook_call_deferred(&hpd_lvl_deferred_data, + HPD_USTREAM_DEBOUNCE_LVL); hpd_prev_level = level; } diff --git a/board/elm/board.c b/board/elm/board.c index 8d02e76dca..ee2d6275c0 100644 --- a/board/elm/board.c +++ b/board/elm/board.c @@ -171,23 +171,25 @@ static struct mutex dp_hw_lock; * Reset PD MCU * ANX7688 needs a reset pulse of 50ms after power enable. */ +void deferred_reset_pd_mcu(void); +DECLARE_DEFERRED(deferred_reset_pd_mcu); + void deferred_reset_pd_mcu(void) { if (!gpio_get_level(GPIO_USB_C0_RST)) { gpio_set_level(GPIO_USB_C0_RST, 1); - hook_call_deferred(deferred_reset_pd_mcu, 50 * MSEC); + hook_call_deferred(&deferred_reset_pd_mcu_data, 50 * MSEC); } else { gpio_set_level(GPIO_USB_C0_RST, 0); } } -DECLARE_DEFERRED(deferred_reset_pd_mcu); void board_reset_pd_mcu(void) { /* Perform ANX7688 startup sequence */ gpio_set_level(GPIO_USB_C0_PWR_EN_L, 0); gpio_set_level(GPIO_USB_C0_RST, 0); - hook_call_deferred(deferred_reset_pd_mcu, 0); + hook_call_deferred(&deferred_reset_pd_mcu_data, 0); } /** @@ -357,7 +359,7 @@ void board_typec_dp_on(int port) board_typec_set_dp_hpd(port, 1); } else { board_typec_set_dp_hpd(port, 0); - hook_call_deferred(hpd_irq_deferred, + hook_call_deferred(&hpd_irq_deferred_data, HPD_DSTREAM_DEBOUNCE_IRQ); } } @@ -431,7 +433,7 @@ DECLARE_DEFERRED(tmp432_set_power_deferred); static void board_extpower(void) { board_extpower_buffer_to_soc(); - hook_call_deferred(tmp432_set_power_deferred, 0); + hook_call_deferred(&tmp432_set_power_deferred_data, 0); } DECLARE_HOOK(HOOK_AC_CHANGE, board_extpower, HOOK_PRIO_DEFAULT); @@ -454,14 +456,14 @@ DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, board_chipset_shutdown, HOOK_PRIO_DEFAULT); /* Called on AP S3 -> S0 transition */ static void board_chipset_resume(void) { - hook_call_deferred(tmp432_set_power_deferred, 0); + hook_call_deferred(&tmp432_set_power_deferred_data, 0); } DECLARE_HOOK(HOOK_CHIPSET_RESUME, board_chipset_resume, HOOK_PRIO_DEFAULT); /* Called on AP S0 -> S3 transition */ static void board_chipset_suspend(void) { - hook_call_deferred(tmp432_set_power_deferred, 0); + hook_call_deferred(&tmp432_set_power_deferred_data, 0); } DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, board_chipset_suspend, HOOK_PRIO_DEFAULT); diff --git a/board/glados/board.c b/board/glados/board.c index 08ed832fa6..8855ae9518 100644 --- a/board/glados/board.c +++ b/board/glados/board.c @@ -88,10 +88,11 @@ void usb1_evt(enum gpio_signal signal) * state of GPIOs, so its definition must reside after including gpio_list. */ static void enable_input_devices(void); +DECLARE_DEFERRED(enable_input_devices); void tablet_mode_interrupt(enum gpio_signal signal) { - hook_call_deferred(enable_input_devices, 0); + hook_call_deferred(&enable_input_devices_data, 0); } #include "gpio_list.h" @@ -380,14 +381,13 @@ static void enable_input_devices(void) keyboard_scan_enable(kb_enable, KB_SCAN_DISABLE_LID_ANGLE); gpio_set_level(GPIO_ENABLE_TOUCHPAD, tp_enable); } -DECLARE_DEFERRED(enable_input_devices); /* Called on AP S5 -> S3 transition */ static void board_chipset_startup(void) { gpio_set_level(GPIO_USB1_ENABLE, 1); gpio_set_level(GPIO_USB2_ENABLE, 1); - hook_call_deferred(enable_input_devices, 0); + hook_call_deferred(&enable_input_devices_data, 0); } DECLARE_HOOK(HOOK_CHIPSET_STARTUP, board_chipset_startup, HOOK_PRIO_DEFAULT); @@ -396,7 +396,7 @@ static void board_chipset_shutdown(void) { gpio_set_level(GPIO_USB1_ENABLE, 0); gpio_set_level(GPIO_USB2_ENABLE, 0); - hook_call_deferred(enable_input_devices, 0); + hook_call_deferred(&enable_input_devices_data, 0); } DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, board_chipset_shutdown, HOOK_PRIO_DEFAULT); diff --git a/board/glados/usb_pd_policy.c b/board/glados/usb_pd_policy.c index e07454e887..d50450d557 100644 --- a/board/glados/usb_pd_policy.c +++ b/board/glados/usb_pd_policy.c @@ -304,8 +304,9 @@ static void hpd1_irq_deferred(void) DECLARE_DEFERRED(hpd0_irq_deferred); DECLARE_DEFERRED(hpd1_irq_deferred); -#define PORT_TO_HPD_IRQ_DEFERRED(port) ((port) ? hpd1_irq_deferred : \ - hpd0_irq_deferred) +#define PORT_TO_HPD_IRQ_DEFERRED(port) ((port) ? \ + &hpd1_irq_deferred_data : \ + &hpd0_irq_deferred_data) static int svdm_dp_attention(int port, uint32_t *payload) { diff --git a/board/glados_pd/board.c b/board/glados_pd/board.c index 230cc1ea2d..930f3eb66d 100644 --- a/board/glados_pd/board.c +++ b/board/glados_pd/board.c @@ -141,7 +141,7 @@ static int ec_status_host_cmd(struct host_cmd_handler_args *args) /* Have the PD follow the EC into hibernate. */ if (p->status & EC_STATUS_HIBERNATING) - hook_call_deferred(system_hibernate_deferred, 0); + hook_call_deferred(&system_hibernate_deferred_data, 0); /* * If the source of the EC int line was HOST_EVENT, it has diff --git a/board/hoho/board.c b/board/hoho/board.c index 93329a4001..e6258f19b4 100644 --- a/board/hoho/board.c +++ b/board/hoho/board.c @@ -76,7 +76,7 @@ void hpd_event(enum gpio_signal signal) hpd_prev_ts = now.val; /* All previous hpd level events need to be re-triggered */ - hook_call_deferred(hpd_lvl_deferred, -1); + hook_call_deferred(&hpd_lvl_deferred_data, -1); /* It's a glitch. Previous time moves but level is the same. */ if (cur_delta < HPD_USTREAM_DEBOUNCE_IRQ) @@ -85,9 +85,10 @@ void hpd_event(enum gpio_signal signal) if ((!hpd_prev_level && level) && (cur_delta < HPD_USTREAM_DEBOUNCE_LVL)) /* It's an irq */ - hook_call_deferred(hpd_irq_deferred, 0); + hook_call_deferred(&hpd_irq_deferred_data, 0); else if (cur_delta >= HPD_USTREAM_DEBOUNCE_LVL) - hook_call_deferred(hpd_lvl_deferred, HPD_USTREAM_DEBOUNCE_LVL); + hook_call_deferred(&hpd_lvl_deferred_data, + HPD_USTREAM_DEBOUNCE_LVL); hpd_prev_level = level; } @@ -167,7 +168,7 @@ static void board_init(void) gpio_set_level(GPIO_STM_READY, 1); /* factory test only */ /* Delay needed to allow HDMI MCU to boot. */ - hook_call_deferred(factory_validation_deferred, 200*MSEC); + hook_call_deferred(&factory_validation_deferred_data, 200*MSEC); } DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT); diff --git a/board/honeybuns/board.c b/board/honeybuns/board.c index 3315418fc2..7c23b39ef1 100644 --- a/board/honeybuns/board.c +++ b/board/honeybuns/board.c @@ -81,7 +81,7 @@ void hpd_event(enum gpio_signal signal) hpd_prev_ts = now.val; /* All previous hpd level events need to be re-triggered */ - hook_call_deferred(hpd_lvl_deferred, -1); + hook_call_deferred(&hpd_lvl_deferred_data, -1); /* It's a glitch. Previous time moves but level is the same. */ if (cur_delta < HPD_USTREAM_DEBOUNCE_IRQ) @@ -90,9 +90,10 @@ void hpd_event(enum gpio_signal signal) if ((!hpd_prev_level && level) && (cur_delta < HPD_USTREAM_DEBOUNCE_LVL)) /* It's an irq */ - hook_call_deferred(hpd_irq_deferred, 0); + hook_call_deferred(&hpd_irq_deferred_data, 0); else if (cur_delta >= HPD_USTREAM_DEBOUNCE_LVL) - hook_call_deferred(hpd_lvl_deferred, HPD_USTREAM_DEBOUNCE_LVL); + hook_call_deferred(&hpd_lvl_deferred_data, + HPD_USTREAM_DEBOUNCE_LVL); hpd_prev_level = level; } diff --git a/board/kunimitsu/usb_pd_policy.c b/board/kunimitsu/usb_pd_policy.c index e07454e887..d50450d557 100644 --- a/board/kunimitsu/usb_pd_policy.c +++ b/board/kunimitsu/usb_pd_policy.c @@ -304,8 +304,9 @@ static void hpd1_irq_deferred(void) DECLARE_DEFERRED(hpd0_irq_deferred); DECLARE_DEFERRED(hpd1_irq_deferred); -#define PORT_TO_HPD_IRQ_DEFERRED(port) ((port) ? hpd1_irq_deferred : \ - hpd0_irq_deferred) +#define PORT_TO_HPD_IRQ_DEFERRED(port) ((port) ? \ + &hpd1_irq_deferred_data : \ + &hpd0_irq_deferred_data) static int svdm_dp_attention(int port, uint32_t *payload) { diff --git a/board/lars/usb_pd_policy.c b/board/lars/usb_pd_policy.c index 3010df52fb..c4c071a121 100644 --- a/board/lars/usb_pd_policy.c +++ b/board/lars/usb_pd_policy.c @@ -311,7 +311,8 @@ static int svdm_dp_attention(int port, uint32_t *payload) if (irq & cur_lvl) { gpio_set_level(GPIO_USB_C0_DP_HPD, 0); - hook_call_deferred(hpd0_irq_deferred, HPD_DSTREAM_DEBOUNCE_IRQ); + hook_call_deferred(&hpd0_irq_deferred_data, + HPD_DSTREAM_DEBOUNCE_IRQ); } else if (irq & !cur_lvl) { CPRINTF("ERR:HPD:IRQ&LOW\n"); return 0; /* nak */ diff --git a/board/lars_pd/board.c b/board/lars_pd/board.c index 1354e03b24..e3bbd46598 100644 --- a/board/lars_pd/board.c +++ b/board/lars_pd/board.c @@ -135,7 +135,7 @@ static int ec_status_host_cmd(struct host_cmd_handler_args *args) /* Have the PD follow the EC into hibernate. */ if (p->status & EC_STATUS_HIBERNATING) - hook_call_deferred(system_hibernate_deferred, 0); + hook_call_deferred(&system_hibernate_deferred_data, 0); /* * If the source of the EC int line was HOST_EVENT, it has diff --git a/board/lucid/board.c b/board/lucid/board.c index a396f0b547..f5f03e2895 100644 --- a/board/lucid/board.c +++ b/board/lucid/board.c @@ -105,7 +105,8 @@ void vbus_evt(enum gpio_signal signal) * lucid only has one port and charging is always enabled. */ - hook_call_deferred(usb_charger_bc12_detect, USB_CHG_DETECT_DELAY_US); + hook_call_deferred(&usb_charger_bc12_detect_data, + USB_CHG_DETECT_DELAY_US); update_vbus_supplier(gpio_get_level(signal)); task_wake(TASK_ID_PD_C0); diff --git a/board/oak/board.c b/board/oak/board.c index 9f770d8865..f66c35acee 100644 --- a/board/oak/board.c +++ b/board/oak/board.c @@ -396,8 +396,8 @@ void board_typec_dp_on(int port) board_typec_set_dp_hpd(port, 1); } else { board_typec_set_dp_hpd(port, 0); - hook_call_deferred(hpd_irq_deferred, - HPD_DSTREAM_DEBOUNCE_IRQ); + hook_call_deferred(&hpd_irq_deferred_data, + HPD_DSTREAM_DEBOUNCE_IRQ); } } @@ -589,7 +589,7 @@ static void board_extpower(void) { board_extpower_buffer_to_soc(); #ifdef CONFIG_TEMP_SENSOR_TMP432 - hook_call_deferred(tmp432_set_power_deferred, 0); + hook_call_deferred(&tmp432_set_power_deferred_data, 0); #endif } DECLARE_HOOK(HOOK_AC_CHANGE, board_extpower, HOOK_PRIO_DEFAULT); @@ -625,7 +625,7 @@ DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, board_chipset_shutdown, HOOK_PRIO_DEFAULT); static void board_chipset_resume(void) { #ifdef CONFIG_TEMP_SENSOR_TMP432 - hook_call_deferred(tmp432_set_power_deferred, 0); + hook_call_deferred(&tmp432_set_power_deferred_data, 0); #endif } DECLARE_HOOK(HOOK_CHIPSET_RESUME, board_chipset_resume, HOOK_PRIO_DEFAULT); @@ -634,7 +634,7 @@ DECLARE_HOOK(HOOK_CHIPSET_RESUME, board_chipset_resume, HOOK_PRIO_DEFAULT); static void board_chipset_suspend(void) { #ifdef CONFIG_TEMP_SENSOR_TMP432 - hook_call_deferred(tmp432_set_power_deferred, 0); + hook_call_deferred(&tmp432_set_power_deferred_data, 0); #endif } DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, board_chipset_suspend, HOOK_PRIO_DEFAULT); diff --git a/board/plankton/board.c b/board/plankton/board.c index d52f94bca5..a0cd041724 100644 --- a/board/plankton/board.c +++ b/board/plankton/board.c @@ -104,7 +104,8 @@ void hpd_event(enum gpio_signal signal) hpd_prev_ts = now.val; /* All previous hpd level events need to be re-triggered */ - hook_call_deferred(hpd_lvl_deferred, HPD_USTREAM_DEBOUNCE_LVL); + hook_call_deferred(&hpd_lvl_deferred_data, + HPD_USTREAM_DEBOUNCE_LVL); } /* Debounce time for voltage buttons */ @@ -177,13 +178,17 @@ static void set_active_cc(int cc) * is detected. If a type-C connection can be made in both polarities, then we * have a double CC cable, otherwise we have a single CC cable. */ +static void detect_cc_cable(void); +DECLARE_DEFERRED(detect_cc_cable); + static void detect_cc_cable(void) { /* * Delay long enough to guarantee a type-C disconnect will be seen and * a new connection will be made made. */ - hook_call_deferred(detect_cc_cable, PD_T_CC_DEBOUNCE + PD_T_SAFE_0V); + hook_call_deferred(&detect_cc_cable_data, + PD_T_CC_DEBOUNCE + PD_T_SAFE_0V); switch (cable) { case TYPEC_CABLE_NONE: @@ -210,7 +215,6 @@ static void detect_cc_cable(void) break; } } -DECLARE_DEFERRED(detect_cc_cable); static void fake_disconnect_end(void) { @@ -218,14 +222,14 @@ static void fake_disconnect_end(void) board_pd_set_host_mode(fake_pd_host_mode); /* Restart CC cable detection */ - hook_call_deferred(detect_cc_cable, 500*MSEC); + hook_call_deferred(&detect_cc_cable_data, 500*MSEC); } DECLARE_DEFERRED(fake_disconnect_end); static void fake_disconnect_start(void) { /* Cancel detection of CC cable */ - hook_call_deferred(detect_cc_cable, -1); + hook_call_deferred(&detect_cc_cable_data, -1); /* Record the current host mode */ fake_pd_host_mode = !gpio_get_level(GPIO_USBC_CHARGE_EN); @@ -241,7 +245,7 @@ static void fake_disconnect_start(void) fake_pd_disconnected = 1; - hook_call_deferred(fake_disconnect_end, + hook_call_deferred(&fake_disconnect_end_data, fake_pd_disconnect_duration_us); } DECLARE_DEFERRED(fake_disconnect_start); @@ -261,7 +265,7 @@ static void update_usbc_dual_role(int dual_role) * since both CC lines are used and SRC/SNK changes are dictated * by the USB PD protocol state machine. */ - hook_call_deferred(detect_cc_cable, -1); + hook_call_deferred(&detect_cc_cable_data, -1); /* Need to make sure both CC lines are set for SNK or SRC. */ set_active_cc(host_mode); /* Ensure that PD communication is enabled. */ @@ -272,7 +276,7 @@ static void update_usbc_dual_role(int dual_role) * Dualrole mode is not active, resume cable detect function * which controls which CC line is active. */ - hook_call_deferred(detect_cc_cable, 0); + hook_call_deferred(&detect_cc_cable_data, 0); } /* Update dual role setting used in USB PD protocol state machine */ pd_set_dual_role(dual_role); @@ -335,10 +339,10 @@ static void set_usbc_action(enum usbc_action act) * Fake a disconnection for long enough to guarantee * that we disconnect. */ - hook_call_deferred(fake_disconnect_start, -1); - hook_call_deferred(fake_disconnect_end, -1); + hook_call_deferred(&fake_disconnect_start_data, -1); + hook_call_deferred(&fake_disconnect_end_data, -1); fake_pd_disconnect_duration_us = PD_T_SAFE_0V; - hook_call_deferred(fake_disconnect_start, 0); + hook_call_deferred(&fake_disconnect_start_data, 0); set_active_cc(!active_cc); } break; @@ -370,10 +374,13 @@ static void set_usbc_action(enum usbc_action act) /* has Pull-up */ static int prev_dbg20v = 1; + static void button_dbg20v_deferred(void); +DECLARE_DEFERRED(button_dbg20v_deferred); + static void enable_dbg20v_poll(void) { - hook_call_deferred(button_dbg20v_deferred, 10 * MSEC); + hook_call_deferred(&button_dbg20v_deferred_data, 10 * MSEC); } /* Handle debounced button press */ @@ -427,7 +434,7 @@ void button_event(enum gpio_signal signal) { button_pressed = signal; /* reset debounce time */ - hook_call_deferred(button_deferred, BUTTON_DEBOUNCE_US); + hook_call_deferred(&button_deferred_data, BUTTON_DEBOUNCE_US); } static void button_dbg20v_deferred(void) @@ -437,7 +444,6 @@ static void button_dbg20v_deferred(void) else enable_dbg20v_poll(); } -DECLARE_DEFERRED(button_dbg20v_deferred); void vbus_event(enum gpio_signal signal) { @@ -729,10 +735,11 @@ static void board_init(void) /* Initialize USB hub */ if (system_get_reset_flags() & RESET_FLAG_POWER_ON) - hook_call_deferred(board_usb_hub_reset_no_return, 500 * MSEC); + hook_call_deferred(&board_usb_hub_reset_no_return_data, + 500 * MSEC); /* Start detecting CC cable type */ - hook_call_deferred(detect_cc_cable, SECOND); + hook_call_deferred(&detect_cc_cable_data, SECOND); } DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT); @@ -752,11 +759,11 @@ static int cmd_fake_disconnect(int argc, char *argv[]) return EC_ERROR_PARAM2; /* Cancel any pending function calls */ - hook_call_deferred(fake_disconnect_start, -1); - hook_call_deferred(fake_disconnect_end, -1); + hook_call_deferred(&fake_disconnect_start_data, -1); + hook_call_deferred(&fake_disconnect_end_data, -1); fake_pd_disconnect_duration_us = duration_ms * MSEC; - hook_call_deferred(fake_disconnect_start, delay_ms * MSEC); + hook_call_deferred(&fake_disconnect_start_data, delay_ms * MSEC); ccprintf("Fake disconnect for %d ms starting in %d ms.\n", duration_ms, delay_ms); @@ -779,7 +786,7 @@ static int cmd_trigger_dfu(int argc, char *argv[]) ccprintf("Asserting CASE_CLOSE_DFU_L.\n"); ccprintf("If you expect to see DFU debug but it doesn't show up,\n"); ccprintf("try flipping the USB type-C cable.\n"); - hook_call_deferred(trigger_dfu_release, 1500 * MSEC); + hook_call_deferred(&trigger_dfu_release_data, 1500 * MSEC); return EC_SUCCESS; } DECLARE_CONSOLE_COMMAND(dfu, cmd_trigger_dfu, NULL, NULL, NULL); diff --git a/board/ryu/usb_pd_policy.c b/board/ryu/usb_pd_policy.c index b600edb427..e4b45bece0 100644 --- a/board/ryu/usb_pd_policy.c +++ b/board/ryu/usb_pd_policy.c @@ -331,7 +331,7 @@ static int svdm_dp_attention(int port, uint32_t *payload) if (irq & cur_lvl) { gpio_set_level(GPIO_USBC_DP_HPD, 0); - hook_call_deferred(hpd_irq_deferred, + hook_call_deferred(&hpd_irq_deferred_data, HPD_DSTREAM_DEBOUNCE_IRQ); } else if (irq & !cur_lvl) { CPRINTF("ERR:HPD:IRQ&LOW\n"); diff --git a/board/samus/extpower.c b/board/samus/extpower.c index b842f7d3ea..e54cb52a80 100644 --- a/board/samus/extpower.c +++ b/board/samus/extpower.c @@ -177,7 +177,7 @@ DECLARE_DEFERRED(allow_min_charging); static void extpower_board_hacks(int extpower, int extpower_prev) { /* Cancel deferred attempt to enable max charge request */ - hook_call_deferred(allow_max_request, -1); + hook_call_deferred(&allow_max_request_data, -1); /* * When AC is detected, delay briefly before allowing PD @@ -197,7 +197,7 @@ static void extpower_board_hacks(int extpower, int extpower_prev) if (extpower && !extpower_prev) { /* AC connected */ charger_disable(0); - hook_call_deferred(allow_max_request, 500*MSEC); + hook_call_deferred(&allow_max_request_data, 500*MSEC); set_pp5000_in_g3(PP5000_IN_G3_AC, 1); } else if (extpower && extpower_prev) { /* @@ -213,7 +213,7 @@ static void extpower_board_hacks(int extpower, int extpower_prev) charger_disable(1); - hook_call_deferred(allow_min_charging, 100*MSEC); + hook_call_deferred(&allow_min_charging_data, 100*MSEC); set_pp5000_in_g3(PP5000_IN_G3_AC, 0); } extpower_prev = extpower; diff --git a/board/samus/panel.c b/board/samus/panel.c index e29d0b9e60..970197b9c8 100644 --- a/board/samus/panel.c +++ b/board/samus/panel.c @@ -163,7 +163,7 @@ void backlight_interrupt(enum gpio_signal signal) * PCH indicates it is turning on backlight so we should * attempt to put the backlight controller into PWM mode. */ - hook_call_deferred(lp8555_enable_pwm_mode, 0); + hook_call_deferred(&lp8555_enable_pwm_mode_data, 0); } /** @@ -177,7 +177,7 @@ static void update_backlight(void) */ gpio_set_level(GPIO_ENABLE_BACKLIGHT, lid_is_open()); if (lid_is_open()) - hook_call_deferred(lp8555_enable_pwm_mode, 0); + hook_call_deferred(&lp8555_enable_pwm_mode_data, 0); } DECLARE_HOOK(HOOK_LID_CHANGE, update_backlight, HOOK_PRIO_DEFAULT); diff --git a/board/samus_pd/board.c b/board/samus_pd/board.c index 270c82e7e9..80e99dd9da 100644 --- a/board/samus_pd/board.c +++ b/board/samus_pd/board.c @@ -178,7 +178,7 @@ DECLARE_DEFERRED(pch_evt_deferred); void pch_evt(enum gpio_signal signal) { - hook_call_deferred(pch_evt_deferred, 0); + hook_call_deferred(&pch_evt_deferred_data, 0); } void board_config_pre_init(void) diff --git a/board/samus_pd/usb_pd_policy.c b/board/samus_pd/usb_pd_policy.c index 18b5ff8f20..7b51e3e38e 100644 --- a/board/samus_pd/usb_pd_policy.c +++ b/board/samus_pd/usb_pd_policy.c @@ -319,8 +319,9 @@ static void hpd1_irq_deferred(void) DECLARE_DEFERRED(hpd0_irq_deferred); DECLARE_DEFERRED(hpd1_irq_deferred); -#define PORT_TO_HPD_IRQ_DEFERRED(port) ((port) ? hpd1_irq_deferred : \ - hpd0_irq_deferred) +#define PORT_TO_HPD_IRQ_DEFERRED(port) ((port) ? \ + &hpd1_irq_deferred_data : \ + &hpd0_irq_deferred_data) static int svdm_dp_attention(int port, uint32_t *payload) { diff --git a/board/strago/usb_pd_policy.c b/board/strago/usb_pd_policy.c index 6be4c83417..162c8a0d5e 100644 --- a/board/strago/usb_pd_policy.c +++ b/board/strago/usb_pd_policy.c @@ -301,7 +301,7 @@ static int svdm_dp_attention(int port, uint32_t *payload) if (irq & cur_lvl) { gpio_set_level(hpd, 0); - hook_call_deferred(hpd0_irq_deferred, + hook_call_deferred(&hpd0_irq_deferred_data, HPD_DSTREAM_DEBOUNCE_IRQ); } else if (irq & !cur_lvl) { CPRINTF("ERR:HPD:IRQ&LOW\n"); diff --git a/board/twinkie/sniffer.c b/board/twinkie/sniffer.c index 77eefb20f9..64e0060010 100644 --- a/board/twinkie/sniffer.c +++ b/board/twinkie/sniffer.c @@ -119,7 +119,7 @@ static void vbus_vol_read_deferred(void) vbus_vol_tail = (flag_started == 0) ? 1 : vbus_vol_tail + 1; } - hook_call_deferred(vbus_vol_read_deferred, DEFERRED_READ_TIME_US); + hook_call_deferred(&vbus_vol_read_deferred_data, DEFERRED_READ_TIME_US); } DECLARE_DEFERRED(vbus_vol_read_deferred); @@ -149,7 +149,8 @@ static void vbus_curr_read_deferred(void) vbus_curr_tail = (flag_started == 0) ? 1 : vbus_curr_tail + 1; } - hook_call_deferred(vbus_curr_read_deferred, DEFERRED_READ_TIME_US); + hook_call_deferred(&vbus_curr_read_deferred_data, + DEFERRED_READ_TIME_US); } DECLARE_DEFERRED(vbus_curr_read_deferred); #endif @@ -364,8 +365,8 @@ void sniffer_init(void) /* whether the sniffer task have started sending packet */ flag_started = 0; - hook_call_deferred(vbus_vol_read_deferred, 0); - hook_call_deferred(vbus_curr_read_deferred, 0); + hook_call_deferred(&vbus_vol_read_deferred_data, 0); + hook_call_deferred(&vbus_curr_read_deferred_data, 0); #endif /* remap TIM1 CH1/2/3 to DMA channel 6 */ diff --git a/board/wheatley/board.c b/board/wheatley/board.c index ba6fce0f7f..f8754eae0c 100644 --- a/board/wheatley/board.c +++ b/board/wheatley/board.c @@ -88,10 +88,11 @@ void usb1_evt(enum gpio_signal signal) * state of GPIOs, so its definition must reside after including gpio_list. */ static void enable_input_devices(void); +DECLARE_DEFERRED(enable_input_devices); void tablet_mode_interrupt(enum gpio_signal signal) { - hook_call_deferred(enable_input_devices, 0); + hook_call_deferred(&enable_input_devices_data, 0); } #include "gpio_list.h" @@ -328,14 +329,13 @@ static void enable_input_devices(void) keyboard_scan_enable(kb_enable, KB_SCAN_DISABLE_LID_ANGLE); gpio_set_level(GPIO_ENABLE_TOUCHPAD, tp_enable); } -DECLARE_DEFERRED(enable_input_devices); /* Called on AP S5 -> S3 transition */ static void board_chipset_startup(void) { gpio_set_level(GPIO_USB1_ENABLE, 1); gpio_set_level(GPIO_USB2_ENABLE, 1); - hook_call_deferred(enable_input_devices, 0); + hook_call_deferred(&enable_input_devices_data, 0); } DECLARE_HOOK(HOOK_CHIPSET_STARTUP, board_chipset_startup, HOOK_PRIO_DEFAULT); @@ -344,7 +344,7 @@ static void board_chipset_shutdown(void) { gpio_set_level(GPIO_USB1_ENABLE, 0); gpio_set_level(GPIO_USB2_ENABLE, 0); - hook_call_deferred(enable_input_devices, 0); + hook_call_deferred(&enable_input_devices_data, 0); } DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, board_chipset_shutdown, HOOK_PRIO_DEFAULT); diff --git a/board/wheatley/usb_pd_policy.c b/board/wheatley/usb_pd_policy.c index ff88ede3bc..5f0f8c5761 100644 --- a/board/wheatley/usb_pd_policy.c +++ b/board/wheatley/usb_pd_policy.c @@ -299,8 +299,9 @@ static void hpd1_irq_deferred(void) DECLARE_DEFERRED(hpd0_irq_deferred); DECLARE_DEFERRED(hpd1_irq_deferred); -#define PORT_TO_HPD_IRQ_DEFERRED(port) ((port) ? hpd1_irq_deferred : \ - hpd0_irq_deferred) +#define PORT_TO_HPD_IRQ_DEFERRED(port) ((port) ? \ + &hpd1_irq_deferred_data : \ + &hpd0_irq_deferred_data) static int svdm_dp_attention(int port, uint32_t *payload) { diff --git a/chip/g/usb-stream.h b/chip/g/usb-stream.h index a79d530035..b789c65925 100644 --- a/chip/g/usb-stream.h +++ b/chip/g/usb-stream.h @@ -31,8 +31,8 @@ struct usb_stream_config { /* * Deferred function to call to handle USB and Queue request. */ - void (*deferred_tx)(void); - void (*deferred_rx)(void); + const struct deferred_data *deferred_tx; + const struct deferred_data *deferred_rx; int tx_size; int rx_size; @@ -109,14 +109,16 @@ extern struct producer_ops const usb_stream_producer_ops; static uint8_t CONCAT2(NAME, _buf_tx_)[TX_SIZE]; \ static int CONCAT2(NAME, _is_reset_); \ static void CONCAT2(NAME, _deferred_tx_)(void); \ + DECLARE_DEFERRED(CONCAT2(NAME, _deferred_tx_)); \ static void CONCAT2(NAME, _deferred_rx_)(void); \ + DECLARE_DEFERRED(CONCAT2(NAME, _deferred_rx_)); \ struct usb_stream_config const NAME = { \ .endpoint = ENDPOINT, \ .is_reset = &CONCAT2(NAME, _is_reset_), \ .in_desc = &CONCAT2(NAME, _in_desc_), \ .out_desc = &CONCAT2(NAME, _out_desc_), \ - .deferred_tx = CONCAT2(NAME, _deferred_tx_), \ - .deferred_rx = CONCAT2(NAME, _deferred_rx_), \ + .deferred_tx = &CONCAT2(NAME, _deferred_tx__data), \ + .deferred_rx = &CONCAT2(NAME, _deferred_rx__data), \ .tx_size = TX_SIZE, \ .rx_size = RX_SIZE, \ .tx_ram = CONCAT2(NAME, _buf_tx_), \ @@ -162,10 +164,8 @@ extern struct producer_ops const usb_stream_producer_ops; }; \ static void CONCAT2(NAME, _deferred_tx_)(void) \ { tx_stream_handler(&NAME); } \ - DECLARE_DEFERRED(CONCAT2(NAME, _deferred_tx_)); \ static void CONCAT2(NAME, _deferred_rx_)(void) \ { rx_stream_handler(&NAME); } \ - DECLARE_DEFERRED(CONCAT2(NAME, _deferred_rx_)); \ static void CONCAT2(NAME, _ep_tx)(void) \ { \ usb_stream_tx(&NAME); \ diff --git a/chip/g/usb_console.c b/chip/g/usb_console.c index 27a8d15b95..41f98251fa 100644 --- a/chip/g/usb_console.c +++ b/chip/g/usb_console.c @@ -156,7 +156,7 @@ DECLARE_DEFERRED(rx_fifo_handler); static void con_ep_rx(void) { /* Wake up the Rx FIFO handler */ - hook_call_deferred(rx_fifo_handler, 0); + hook_call_deferred(&rx_fifo_handler_data, 0); /* clear the RX/OUT interrupts */ GR_USB_DOEPINT(USB_EP_CONSOLE) = 0xffffffff; @@ -189,14 +189,14 @@ DECLARE_DEFERRED(tx_fifo_handler); static void handle_output(void) { /* Wake up the Tx FIFO handler */ - hook_call_deferred(tx_fifo_handler, 0); + hook_call_deferred(&tx_fifo_handler_data, 0); } /* Tx/IN interrupt handler */ static void con_ep_tx(void) { /* Wake up the Tx FIFO handler */ - hook_call_deferred(tx_fifo_handler, 0); + hook_call_deferred(&tx_fifo_handler_data, 0); /* clear the Tx/IN interrupts */ GR_USB_DIEPINT(USB_EP_CONSOLE) = 0xffffffff; @@ -223,8 +223,8 @@ static void ep_reset(void) is_reset = 1; /* Flush any queued data */ - hook_call_deferred(tx_fifo_handler, 0); - hook_call_deferred(rx_fifo_handler, 0); + hook_call_deferred(&tx_fifo_handler_data, 0); + hook_call_deferred(&rx_fifo_handler_data, 0); } diff --git a/chip/lm4/lpc.c b/chip/lm4/lpc.c index 4c27425273..646ad30150 100644 --- a/chip/lm4/lpc.c +++ b/chip/lm4/lpc.c @@ -657,7 +657,7 @@ void lpc_interrupt(void) #ifdef CONFIG_CHIPSET_RESET_HOOK /* Notify HOOK_CHIPSET_RESET */ - hook_call_deferred(lpc_chipset_reset, MSEC); + hook_call_deferred(&lpc_chipset_reset_data, MSEC); #endif } diff --git a/chip/mec1322/clock.c b/chip/mec1322/clock.c index 8a5fb73047..6a1674891e 100644 --- a/chip/mec1322/clock.c +++ b/chip/mec1322/clock.c @@ -80,18 +80,20 @@ void clock_init(void) * Speed through boot + vboot hash calculation, dropping our processor clock * only after vboot hashing is completed. */ +static void clock_turbo_disable(void); +DECLARE_DEFERRED(clock_turbo_disable); + static void clock_turbo_disable(void) { #ifdef CONFIG_VBOOT_HASH if (vboot_hash_in_progress()) - hook_call_deferred(clock_turbo_disable, 100 * MSEC); + hook_call_deferred(&clock_turbo_disable_data, 100 * MSEC); else #endif /* Use 12 MHz processor clock for power savings */ MEC1322_PCR_PROC_CLK_CTL = 4; } DECLARE_HOOK(HOOK_INIT, clock_turbo_disable, HOOK_PRIO_INIT_VBOOT_HASH + 1); -DECLARE_DEFERRED(clock_turbo_disable); #ifdef CONFIG_LOW_POWER_IDLE /** diff --git a/chip/mec1322/lpc.c b/chip/mec1322/lpc.c index c97b74760c..df40f563a9 100644 --- a/chip/mec1322/lpc.c +++ b/chip/mec1322/lpc.c @@ -357,7 +357,7 @@ void girq19_interrupt(void) #ifdef CONFIG_CHIPSET_RESET_HOOK /* Notify HOOK_CHIPSET_RESET */ - hook_call_deferred(lpc_chipset_reset, MSEC); + hook_call_deferred(&lpc_chipset_reset_data, MSEC); #endif } diff --git a/chip/npcx/lpc.c b/chip/npcx/lpc.c index 03cb684e5a..af945c820a 100644 --- a/chip/npcx/lpc.c +++ b/chip/npcx/lpc.c @@ -774,7 +774,7 @@ void lpc_lreset_pltrst_handler(void) #ifdef CONFIG_CHIPSET_RESET_HOOK if (lpc_get_pltrst_asserted()) { /* Notify HOOK_CHIPSET_RESET */ - hook_call_deferred(lpc_chipset_reset, MSEC); + hook_call_deferred(&lpc_chipset_reset_data, MSEC); } #endif } diff --git a/chip/stm32/usb-stream.h b/chip/stm32/usb-stream.h index 5379d20f48..926100a14c 100644 --- a/chip/stm32/usb-stream.h +++ b/chip/stm32/usb-stream.h @@ -57,7 +57,7 @@ struct usb_stream_config { /* * Deferred function to call to handle USB and Queue request. */ - void (*deferred)(void); + const struct deferred_data *deferred; size_t rx_size; size_t tx_size; @@ -130,10 +130,11 @@ extern struct producer_ops const usb_stream_producer_ops; static usb_uint CONCAT2(NAME, _ep_tx_buffer)[TX_SIZE / 2] __usb_ram; \ static struct usb_stream_state CONCAT2(NAME, _state); \ static void CONCAT2(NAME, _deferred_)(void); \ + DECLARE_DEFERRED(CONCAT2(NAME, _deferred_)); \ struct usb_stream_config const NAME = { \ .state = &CONCAT2(NAME, _state), \ .endpoint = ENDPOINT, \ - .deferred = CONCAT2(NAME, _deferred_), \ + .deferred = &CONCAT2(NAME, _deferred__data), \ .rx_size = RX_SIZE, \ .tx_size = TX_SIZE, \ .rx_ram = CONCAT2(NAME, _ep_rx_buffer), \ @@ -194,8 +195,7 @@ extern struct producer_ops const usb_stream_producer_ops; CONCAT2(NAME, _ep_rx), \ CONCAT2(NAME, _ep_reset)); \ static void CONCAT2(NAME, _deferred_)(void) \ - { usb_stream_deferred(&NAME); } \ - DECLARE_DEFERRED(CONCAT2(NAME, _deferred_)); + { usb_stream_deferred(&NAME); } /* * Handle USB and Queue request in a deferred callback. diff --git a/chip/stm32/usb_i2c.h b/chip/stm32/usb_i2c.h index f9b3d54faa..34e2da7b2a 100644 --- a/chip/stm32/usb_i2c.h +++ b/chip/stm32/usb_i2c.h @@ -82,7 +82,7 @@ struct usb_i2c_config { /* * Deferred function to call to handle I2C request. */ - void (*deferred)(void); + const struct deferred_data *deferred; /* * Pointers to USB packet RAM and bounce buffer. @@ -114,10 +114,11 @@ struct usb_i2c_config { static usb_uint CONCAT2(NAME, _ep_tx_buffer_) \ [USB_MAX_PACKET_SIZE / 2] __usb_ram; \ static void CONCAT2(NAME, _deferred_)(void); \ + DECLARE_DEFERRED(CONCAT2(NAME, _deferred_)); \ struct usb_i2c_config const NAME = { \ .interface = INTERFACE, \ .endpoint = ENDPOINT, \ - .deferred = CONCAT2(NAME, _deferred_), \ + .deferred = &CONCAT2(NAME, _deferred__data), \ .buffer = CONCAT2(NAME, _buffer_), \ .rx_ram = CONCAT2(NAME, _ep_rx_buffer_), \ .tx_ram = CONCAT2(NAME, _ep_tx_buffer_), \ @@ -163,8 +164,7 @@ struct usb_i2c_config { CONCAT2(NAME, _ep_rx_), \ CONCAT2(NAME, _ep_reset_)); \ static void CONCAT2(NAME, _deferred_)(void) \ - { usb_i2c_deferred(&NAME); } \ - DECLARE_DEFERRED(CONCAT2(NAME, _deferred_)); + { usb_i2c_deferred(&NAME); } /* * Handle I2C request in a deferred callback. diff --git a/chip/stm32/usb_spi.h b/chip/stm32/usb_spi.h index 5395e9530f..9a061af0c3 100644 --- a/chip/stm32/usb_spi.h +++ b/chip/stm32/usb_spi.h @@ -111,7 +111,7 @@ struct usb_spi_config { /* * Deferred function to call to handle SPI request. */ - void (*deferred)(void); + const struct deferred_data *deferred; /* * Pointers to USB packet RAM and bounce buffer. @@ -140,6 +140,7 @@ struct usb_spi_config { static usb_uint CONCAT2(NAME, _ep_rx_buffer_)[USB_MAX_PACKET_SIZE / 2] __usb_ram; \ static usb_uint CONCAT2(NAME, _ep_tx_buffer_)[USB_MAX_PACKET_SIZE / 2] __usb_ram; \ static void CONCAT2(NAME, _deferred_)(void); \ + DECLARE_DEFERRED(CONCAT2(NAME, _deferred_)); \ struct usb_spi_state CONCAT2(NAME, _state_) = { \ .enabled_host = 0, \ .enabled_device = 0, \ @@ -149,7 +150,7 @@ struct usb_spi_config { .state = &CONCAT2(NAME, _state_), \ .interface = INTERFACE, \ .endpoint = ENDPOINT, \ - .deferred = CONCAT2(NAME, _deferred_), \ + .deferred = &CONCAT2(NAME, _deferred__data), \ .buffer = CONCAT2(NAME, _buffer_), \ .rx_ram = CONCAT2(NAME, _ep_rx_buffer_), \ .tx_ram = CONCAT2(NAME, _ep_tx_buffer_), \ @@ -197,8 +198,7 @@ struct usb_spi_config { USB_DECLARE_IFACE(INTERFACE, \ CONCAT2(NAME, _interface_)); \ static void CONCAT2(NAME, _deferred_)(void) \ - { usb_spi_deferred(&NAME); } \ - DECLARE_DEFERRED(CONCAT2(NAME, _deferred_)); + { usb_spi_deferred(&NAME); } /* * Handle SPI request in a deferred callback. diff --git a/common/acpi.c b/common/acpi.c index 904c6fe055..58bb658a84 100644 --- a/common/acpi.c +++ b/common/acpi.c @@ -254,7 +254,7 @@ int acpi_ap_to_ec(int is_cmd, uint8_t value, uint8_t *resultptr) * Disable from deferred function in case burst mode is enabled * for an extremely long time (ex. kernel bug / crash). */ - hook_call_deferred(acpi_disable_burst_deferred, 1*SECOND); + hook_call_deferred(&acpi_disable_burst_deferred_data, 1*SECOND); /* ACPI 5.0-12.3.3: Burst ACK */ *resultptr = 0x90; @@ -263,7 +263,7 @@ int acpi_ap_to_ec(int is_cmd, uint8_t value, uint8_t *resultptr) acpi_read_cache.enabled = 0; /* Leave burst mode */ - hook_call_deferred(acpi_disable_burst_deferred, -1); + hook_call_deferred(&acpi_disable_burst_deferred_data, -1); lpc_clear_acpi_status_mask(EC_LPC_STATUS_BURST_MODE); } diff --git a/common/ap_hang_detect.c b/common/ap_hang_detect.c index 2957365211..08bcff036a 100644 --- a/common/ap_hang_detect.c +++ b/common/ap_hang_detect.c @@ -28,6 +28,9 @@ static int timeout_will_reboot; /* Will the deferred call reboot the AP? */ /** * Handle the hang detect timer expiring. */ +static void hang_detect_deferred(void); +DECLARE_DEFERRED(hang_detect_deferred); + static void hang_detect_deferred(void) { /* If we're no longer active, nothing to do */ @@ -51,7 +54,7 @@ static void hang_detect_deferred(void) if (hdparams.warm_reboot_timeout_msec) { CPRINTS("hang detect continuing (for reboot)"); timeout_will_reboot = 1; - hook_call_deferred(hang_detect_deferred, + hook_call_deferred(&hang_detect_deferred_data, (hdparams.warm_reboot_timeout_msec - hdparams.host_event_timeout_msec) * MSEC); } else { @@ -59,7 +62,6 @@ static void hang_detect_deferred(void) active = 0; } } -DECLARE_DEFERRED(hang_detect_deferred); /** * Start the hang detect timers. @@ -74,13 +76,13 @@ static void hang_detect_start(const char *why) CPRINTS("hang detect started on %s (for event)", why); timeout_will_reboot = 0; active = 1; - hook_call_deferred(hang_detect_deferred, + hook_call_deferred(&hang_detect_deferred_data, hdparams.host_event_timeout_msec * MSEC); } else if (hdparams.warm_reboot_timeout_msec) { CPRINTS("hang detect started on %s (for reboot)", why); timeout_will_reboot = 1; active = 1; - hook_call_deferred(hang_detect_deferred, + hook_call_deferred(&hang_detect_deferred_data, hdparams.warm_reboot_timeout_msec * MSEC); } } diff --git a/common/battery.c b/common/battery.c index 408ae92c46..ae3d548676 100644 --- a/common/battery.c +++ b/common/battery.c @@ -294,7 +294,7 @@ static void clear_pending_cutoff(void) { if (extpower_is_present()) { battery_cutoff_state = BATTERY_CUTOFF_STATE_NORMAL; - hook_call_deferred(pending_cutoff_deferred, -1); + hook_call_deferred(&pending_cutoff_deferred_data, -1); } } DECLARE_HOOK(HOOK_AC_CHANGE, clear_pending_cutoff, HOOK_PRIO_DEFAULT); @@ -331,7 +331,7 @@ static void check_pending_cutoff(void) if (battery_cutoff_state == BATTERY_CUTOFF_STATE_PENDING) { CPRINTF("[%T Cutting off battery in %d second(s)]\n", CONFIG_BATTERY_CUTOFF_DELAY_US / SECOND); - hook_call_deferred(pending_cutoff_deferred, + hook_call_deferred(&pending_cutoff_deferred_data, CONFIG_BATTERY_CUTOFF_DELAY_US); } } diff --git a/common/button.c b/common/button.c index 89e6d409e2..38f5a61403 100644 --- a/common/button.c +++ b/common/button.c @@ -57,6 +57,10 @@ DECLARE_HOOK(HOOK_INIT, button_init, HOOK_PRIO_DEFAULT); /* * Handle debounced button changing state. */ + +static void button_change_deferred(void); +DECLARE_DEFERRED(button_change_deferred); + static void button_change_deferred(void) { int i; @@ -99,11 +103,10 @@ static void button_change_deferred(void) if (soonest_debounce_time != 0) { next_deferred_time = soonest_debounce_time; - hook_call_deferred(button_change_deferred, + hook_call_deferred(&button_change_deferred_data, next_deferred_time - time_now); } } -DECLARE_DEFERRED(button_change_deferred); /* * Handle a button interrupt. @@ -121,7 +124,7 @@ void button_interrupt(enum gpio_signal signal) if (next_deferred_time <= time_now || next_deferred_time > state[i].debounce_time) { next_deferred_time = state[i].debounce_time; - hook_call_deferred(button_change_deferred, + hook_call_deferred(&button_change_deferred_data, next_deferred_time - time_now); } break; diff --git a/common/capsense.c b/common/capsense.c index 95703931bd..bc54d5aae3 100644 --- a/common/capsense.c +++ b/common/capsense.c @@ -73,7 +73,7 @@ static void capsense_change_deferred(void) } if (cur_val) - hook_call_deferred(capsense_change_deferred, + hook_call_deferred(&capsense_change_deferred_data, CAPSENSE_POLL_INTERVAL); } DECLARE_DEFERRED(capsense_change_deferred); @@ -83,5 +83,5 @@ DECLARE_DEFERRED(capsense_change_deferred); */ void capsense_interrupt(enum gpio_signal signal) { - hook_call_deferred(capsense_change_deferred, 0); + hook_call_deferred(&capsense_change_deferred_data, 0); } diff --git a/common/charge_manager.c b/common/charge_manager.c index 7063d0540f..fa015086da 100644 --- a/common/charge_manager.c +++ b/common/charge_manager.c @@ -662,9 +662,7 @@ static void charge_manager_make_change(enum charge_manager_change_type change, override_port = OVERRIDE_OFF; if (delayed_override_port != OVERRIDE_OFF) { delayed_override_port = OVERRIDE_OFF; - hook_call_deferred( - charge_override_timeout, - -1); + hook_call_deferred(&charge_override_timeout_data, -1); } } @@ -682,7 +680,7 @@ static void charge_manager_make_change(enum charge_manager_change_type change, * just sent due to the power change on another port. */ if (charge->current > 0) - hook_call_deferred(charger_detect_debounced, + hook_call_deferred(&charger_detect_debounced_data, CHARGE_DETECT_DELAY); /* @@ -693,7 +691,7 @@ static void charge_manager_make_change(enum charge_manager_change_type change, pd_get_role(delayed_override_port) == PD_ROLE_SINK && get_time().val < delayed_override_deadline.val) { delayed_override_port = OVERRIDE_OFF; - hook_call_deferred(charge_override_timeout, -1); + hook_call_deferred(&charge_override_timeout_data, -1); charge_manager_set_override(port); } } @@ -705,7 +703,7 @@ static void charge_manager_make_change(enum charge_manager_change_type change, * attached. */ if (charge_manager_is_seeded()) - hook_call_deferred(charge_manager_refresh, 0); + hook_call_deferred(&charge_manager_refresh_data, 0); } /** @@ -762,7 +760,7 @@ void charge_manager_set_ceil(int port, enum ceil_requestor requestor, int ceil) if (charge_ceil[port][requestor] != ceil) { charge_ceil[port][requestor] = ceil; if (port == charge_port && charge_manager_is_seeded()) - hook_call_deferred(charge_manager_refresh, 0); + hook_call_deferred(&charge_manager_refresh_data, 0); } } @@ -798,7 +796,8 @@ int charge_manager_set_override(int port) if (override_port != port) { override_port = port; if (charge_manager_is_seeded()) - hook_call_deferred(charge_manager_refresh, 0); + hook_call_deferred( + &charge_manager_refresh_data, 0); } } /* @@ -810,9 +809,8 @@ int charge_manager_set_override(int port) delayed_override_deadline.val = get_time().val + POWER_SWAP_TIMEOUT; delayed_override_port = port; - hook_call_deferred( - charge_override_timeout, - POWER_SWAP_TIMEOUT); + hook_call_deferred(&charge_override_timeout_data, + POWER_SWAP_TIMEOUT); pd_request_power_swap(port); /* Can't charge from requested port -- return error. */ } else diff --git a/common/extpower_gpio.c b/common/extpower_gpio.c index b73d748701..569d674157 100644 --- a/common/extpower_gpio.c +++ b/common/extpower_gpio.c @@ -45,7 +45,7 @@ DECLARE_DEFERRED(extpower_deferred); void extpower_interrupt(enum gpio_signal signal) { /* Trigger deferred notification of external power change */ - hook_call_deferred(extpower_deferred, EXTPOWER_DEBOUNCE_US); + hook_call_deferred(&extpower_deferred_data, EXTPOWER_DEBOUNCE_US); } static void extpower_init(void) diff --git a/common/hooks.c b/common/hooks.c index f8e368c36d..1a1a1aa819 100644 --- a/common/hooks.c +++ b/common/hooks.c @@ -132,21 +132,13 @@ void hook_notify(enum hook_type type) #endif } -int hook_call_deferred(void (*routine)(void), int us) +int hook_call_deferred(const struct deferred_data *data, int us) { - const struct deferred_data *p; - int i; + int i = data - __deferred_funcs; - /* Find the index of the routine */ - for (p = __deferred_funcs; p < __deferred_funcs_end; p++) { - if (p->routine == routine) - break; - } - if (p >= __deferred_funcs_end) + if (data < __deferred_funcs || data >= __deferred_funcs_end) return EC_ERROR_INVAL; /* Routine not registered */ - i = p - __deferred_funcs; - if (us == -1) { /* Cancel */ defer_until[i] = 0; diff --git a/common/inductive_charging.c b/common/inductive_charging.c index 8b92394c8c..793f535afe 100644 --- a/common/inductive_charging.c +++ b/common/inductive_charging.c @@ -73,8 +73,9 @@ void inductive_charging_interrupt(enum gpio_signal signal) * looking at CHARGE_DONE. */ if (!monitor_charge_done) - hook_call_deferred(inductive_charging_monitor_charge, - SECOND); + hook_call_deferred( + &inductive_charging_monitor_charge_data, + SECOND); } } @@ -93,7 +94,8 @@ static void inductive_charging_lid_update(void) * unaligned. Delay here to give the coils time to align before * we try to clear CHARGE_DONE. */ - hook_call_deferred(inductive_charging_deferred_update, 5 * SECOND); + hook_call_deferred(&inductive_charging_deferred_update_data, + 5 * SECOND); } DECLARE_HOOK(HOOK_LID_CHANGE, inductive_charging_lid_update, HOOK_PRIO_DEFAULT); diff --git a/common/lid_switch.c b/common/lid_switch.c index eefd2bdfa1..f5af903936 100644 --- a/common/lid_switch.c +++ b/common/lid_switch.c @@ -113,7 +113,7 @@ DECLARE_DEFERRED(lid_change_deferred); void lid_interrupt(enum gpio_signal signal) { /* Reset lid debounce time */ - hook_call_deferred(lid_change_deferred, LID_DEBOUNCE_US); + hook_call_deferred(&lid_change_deferred_data, LID_DEBOUNCE_US); } static int command_lidopen(int argc, char **argv) @@ -147,7 +147,7 @@ static int hc_force_lid_open(struct host_cmd_handler_args *args) forced_lid_open = p->enabled ? 1 : 0; /* Make this take effect immediately; no debounce time */ - hook_call_deferred(lid_change_deferred, 0); + hook_call_deferred(&lid_change_deferred_data, 0); return EC_RES_SUCCESS; } diff --git a/common/power_button.c b/common/power_button.c index e2914bc362..747be2381e 100644 --- a/common/power_button.c +++ b/common/power_button.c @@ -156,7 +156,8 @@ void power_button_interrupt(enum gpio_signal signal) /* Reset power button debounce time */ power_button_is_stable = 0; - hook_call_deferred(power_button_change_deferred, PWRBTN_DEBOUNCE_US); + hook_call_deferred(&power_button_change_deferred_data, + PWRBTN_DEBOUNCE_US); } /*****************************************************************************/ @@ -176,14 +177,14 @@ static int command_powerbtn(int argc, char **argv) ccprintf("Simulating %d ms power button press.\n", ms); simulate_power_pressed = 1; power_button_is_stable = 0; - hook_call_deferred(power_button_change_deferred, 0); + hook_call_deferred(&power_button_change_deferred_data, 0); msleep(ms); ccprintf("Simulating power button release.\n"); simulate_power_pressed = 0; power_button_is_stable = 0; - hook_call_deferred(power_button_change_deferred, 0); + hook_call_deferred(&power_button_change_deferred_data, 0); return EC_SUCCESS; } diff --git a/common/switch.c b/common/switch.c index fb854f63e9..811e4f7d2d 100644 --- a/common/switch.c +++ b/common/switch.c @@ -98,7 +98,7 @@ DECLARE_HOOK(HOOK_INIT, switch_init, HOOK_PRIO_DEFAULT); void switch_interrupt(enum gpio_signal signal) { - hook_call_deferred(switch_update, 0); + hook_call_deferred(&switch_update_data, 0); } static int command_mmapinfo(int argc, char **argv) diff --git a/common/uart_buffering.c b/common/uart_buffering.c index 949c3968d6..c750a1ef6e 100644 --- a/common/uart_buffering.c +++ b/common/uart_buffering.c @@ -167,6 +167,9 @@ void uart_process_output(void) #ifdef CONFIG_UART_RX_DMA +void uart_process_input(void); +DECLARE_DEFERRED(uart_process_input); + void uart_process_input(void) { static int fast_rechecks; @@ -208,11 +211,11 @@ void uart_process_input(void) */ if (fast_rechecks) { fast_rechecks--; - hook_call_deferred(uart_process_input, RX_DMA_RECHECK_INTERVAL); + hook_call_deferred(&uart_process_input_data, + RX_DMA_RECHECK_INTERVAL); } } DECLARE_HOOK(HOOK_TICK, uart_process_input, HOOK_PRIO_DEFAULT); -DECLARE_DEFERRED(uart_process_input); #else /* !CONFIG_UART_RX_DMA */ diff --git a/common/usb_pd_policy.c b/common/usb_pd_policy.c index a071f8b767..074d07dc00 100644 --- a/common/usb_pd_policy.c +++ b/common/usb_pd_policy.c @@ -783,7 +783,7 @@ int pd_vdm(int port, int cnt, uint32_t *payload, uint32_t **rpayload) } #endif /* !CONFIG_USB_PD_CUSTOM_VDM */ -void pd_usb_billboard_deferred(void) +static void pd_usb_billboard_deferred(void) { #if defined(CONFIG_USB_PD_ALT_MODE) && !defined(CONFIG_USB_PD_ALT_MODE_DFP) \ && !defined(CONFIG_USB_PD_SIMPLE_DFP) && defined(CONFIG_USB_BOS) diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index e8540d9dca..276698710d 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -2095,9 +2095,8 @@ void pd_task(void) PD_FLAGS_DATA_SWAPPED; set_state(port, PD_STATE_SNK_DISCOVERY); timeout = 10*MSEC; - hook_call_deferred( - pd_usb_billboard_deferred, - PD_T_AME); + hook_call_deferred(&pd_usb_billboard_deferred_data, + PD_T_AME); break; case PD_STATE_SNK_HARD_RESET_RECOVER: if (pd[port].last_state != pd[port].task_state) diff --git a/common/vboot_hash.c b/common/vboot_hash.c index 01af769ebf..0a70b006b9 100644 --- a/common/vboot_hash.c +++ b/common/vboot_hash.c @@ -63,9 +63,10 @@ void vboot_hash_abort(void) } } -#ifndef CONFIG_MAPPED_STORAGE - static void vboot_hash_next_chunk(void); +DECLARE_DEFERRED(vboot_hash_next_chunk); + +#ifndef CONFIG_MAPPED_STORAGE static int read_and_hash_chunk(int offset, int size) { @@ -78,7 +79,8 @@ static int read_and_hash_chunk(int offset, int size) rv = shared_mem_acquire(size, &buf); if (rv == EC_ERROR_BUSY) { /* Couldn't update hash right now; try again later */ - hook_call_deferred(vboot_hash_next_chunk, WORK_INTERVAL_US); + hook_call_deferred(&vboot_hash_next_chunk_data, + WORK_INTERVAL_US); return rv; } else if (rv != EC_SUCCESS) { vboot_hash_abort(); @@ -138,9 +140,8 @@ static void vboot_hash_next_chunk(void) } /* If we're still here, more work to do; come back later */ - hook_call_deferred(vboot_hash_next_chunk, WORK_INTERVAL_US); + hook_call_deferred(&vboot_hash_next_chunk_data, WORK_INTERVAL_US); } -DECLARE_DEFERRED(vboot_hash_next_chunk); /** * Start computing a hash of <size> bytes of data at flash offset <offset>. @@ -178,7 +179,7 @@ static int vboot_hash_start(uint32_t offset, uint32_t size, if (nonce_size) SHA256_update(&ctx, nonce, nonce_size); - hook_call_deferred(vboot_hash_next_chunk, 0); + hook_call_deferred(&vboot_hash_next_chunk_data, 0); return EC_SUCCESS; } diff --git a/driver/battery/bq20z453.c b/driver/battery/bq20z453.c index d15496b6d5..161a21213e 100644 --- a/driver/battery/bq20z453.c +++ b/driver/battery/bq20z453.c @@ -27,7 +27,7 @@ int battery_command_cut_off(struct host_cmd_handler_args *args) * transaction and release the I2C bus before we'll be abl eto send the * cutoff command. */ - hook_call_deferred(cutoff, 1000); + hook_call_deferred(&cutoff_data, 1000); return EC_RES_SUCCESS; } diff --git a/include/hooks.h b/include/hooks.h index 3a7af06f3c..142926e6a9 100644 --- a/include/hooks.h +++ b/include/hooks.h @@ -190,22 +190,26 @@ struct hook_data { */ void hook_notify(enum hook_type type); +struct deferred_data { + /* Deferred function pointer */ + void (*routine)(void); +}; + /** * Start a timer to call a deferred routine. * * The routine will be called after at least the specified delay, in the * context of the hook task. * - * @param routine Routine to call; must have been declared with - * DECLARE_DEFERRED(). - * @param us Delay in microseconds until routine will be called. - * If the routine is already pending, subsequent calls - * will change the delay. Pass us=0 to call as soon as - * possible, or -1 to cancel the deferred call. + * @param data The deferred_data struct created by invoking DECLARE_DEFERRED(). + * @param us Delay in microseconds until routine will be called. If the + * routine is already pending, subsequent calls will change the + * delay. Pass us=0 to call as soon as possible, or -1 to cancel + * the deferred call. * * @return non-zero if error. */ -int hook_call_deferred(void (*routine)(void), int us); +int hook_call_deferred(const struct deferred_data *data, int us); #ifdef CONFIG_COMMON_RUNTIME /** @@ -239,18 +243,20 @@ int hook_call_deferred(void (*routine)(void), int us); __attribute__((section(".rodata." STRINGIFY(hooktype)))) \ = {routine, priority} - -struct deferred_data { - /* Deferred function pointer */ - void (*routine)(void); -}; - /** * Register a deferred function call. * * Note that if you declare a bunch of these, you may need to override * DEFERRABLE_MAX_COUNT in your board.h. * + * DECLARE_DEFERRED creates a new deferred_data struct with a name constructed + * by concatenating _data to the name of the routine passed. + * + * To call a deferred routine defined as: + * DECLARE_DEFERRED(foo) + * You would call + * hook_call_deferred(&foo_data, delay_in_microseconds); + * * NOTE: Deferred function call routines must be careful not to leave resources * locked which may be needed by other hook routines or deferred function * calls. This can cause a deadlock, because most hooks and all deferred @@ -260,7 +266,7 @@ struct deferred_data { * @param routine Function pointer, with prototype void routine(void) */ #define DECLARE_DEFERRED(routine) \ - const struct deferred_data __keep CONCAT2(__deferred_, routine) \ + const struct deferred_data __keep CONCAT2(routine, _data) \ __attribute__((section(".rodata.deferred"))) \ = {routine} diff --git a/include/usb_pd.h b/include/usb_pd.h index 4b7faa9f0a..7d125051fa 100644 --- a/include/usb_pd.h +++ b/include/usb_pd.h @@ -1238,7 +1238,7 @@ void pd_send_hpd(int port, enum hpd_event hpd); /** * Enable USB Billboard Device. */ -void pd_usb_billboard_deferred(void); +extern const struct deferred_data pd_usb_billboard_deferred_data; /* --- Physical layer functions : chip specific --- */ /* Packet preparation/retrieval */ diff --git a/power/common.c b/power/common.c index f455b3a3b3..696fed1fb0 100644 --- a/power/common.c +++ b/power/common.c @@ -473,7 +473,7 @@ static void siglog_add(enum gpio_signal signal) siglog[siglog_entries].level = gpio_get_level(signal); siglog_entries++; - hook_call_deferred(siglog_deferred, SECOND); + hook_call_deferred(&siglog_deferred_data, SECOND); } #define SIGLOG(S) siglog_add(S) diff --git a/power/gaia.c b/power/gaia.c index 161cf14553..a5e0ff0fd7 100644 --- a/power/gaia.c +++ b/power/gaia.c @@ -281,7 +281,7 @@ void power_signal_interrupt(enum gpio_signal signal) { if (signal == GPIO_SUSPEND_L) { /* Handle suspend events in the hook task */ - hook_call_deferred(gaia_suspend_deferred, 0); + hook_call_deferred(&gaia_suspend_deferred_data, 0); } else { /* All other events are handled in the chipset task */ task_wake(TASK_ID_CHIPSET); diff --git a/power/mediatek.c b/power/mediatek.c index bf4f0e5cc1..1ac5066712 100644 --- a/power/mediatek.c +++ b/power/mediatek.c @@ -613,7 +613,8 @@ static void power_on(void) /* Push the power button */ set_pmic_pwron(1); - hook_call_deferred(release_pmic_pwron_deferred, PMIC_PWRON_PRESS_TIME); + hook_call_deferred(&release_pmic_pwron_deferred_data, + PMIC_PWRON_PRESS_TIME); /* enable interrupt */ gpio_set_flags(GPIO_SUSPEND_L, INT_BOTH_PULL_UP); @@ -645,7 +646,7 @@ void chipset_reset(int is_cold) usleep(PMIC_COLD_RESET_L_HOLD_TIME); /* Press the PMIC power button */ set_pmic_pwron(1); - hook_call_deferred(release_pmic_pwron_deferred, + hook_call_deferred(&release_pmic_pwron_deferred_data, PMIC_PWRON_PRESS_TIME); } else { CPRINTS("EC triggered warm reboot"); diff --git a/power/skylake.c b/power/skylake.c index 58f2d58f12..d59f5a7349 100644 --- a/power/skylake.c +++ b/power/skylake.c @@ -465,7 +465,7 @@ void power_signal_interrupt_S0(enum gpio_signal signal) { if (gpio_get_level(GPIO_PCH_SLP_S0_L)) { slp_s0_debounce.required = 1; - hook_call_deferred(slp_s0_assertion_deferred, 3 * MSEC); + hook_call_deferred(&slp_s0_assertion_deferred_data, 3 * MSEC); } else if (slp_s0_debounce.required == 0) { slp_s0_debounce.done = 0; diff --git a/test/hooks.c b/test/hooks.c index b3bcbd9e41..4fba1406ae 100644 --- a/test/hooks.c +++ b/test/hooks.c @@ -62,6 +62,10 @@ static void non_deferred_func(void) deferred_call_count++; } +static const struct deferred_data non_deferred_func_data = { + non_deferred_func +}; + static int test_init_hook(void) { TEST_ASSERT(init_hook_count == 1); @@ -104,25 +108,25 @@ static int test_priority(void) static int test_deferred(void) { deferred_call_count = 0; - hook_call_deferred(deferred_func, 50 * MSEC); + hook_call_deferred(&deferred_func_data, 50 * MSEC); usleep(100 * MSEC); TEST_ASSERT(deferred_call_count == 1); - hook_call_deferred(deferred_func, 50 * MSEC); + hook_call_deferred(&deferred_func_data, 50 * MSEC); usleep(25 * MSEC); - hook_call_deferred(deferred_func, -1); + hook_call_deferred(&deferred_func_data, -1); usleep(75 * MSEC); TEST_ASSERT(deferred_call_count == 1); - hook_call_deferred(deferred_func, 50 * MSEC); + hook_call_deferred(&deferred_func_data, 50 * MSEC); usleep(25 * MSEC); - hook_call_deferred(deferred_func, -1); + hook_call_deferred(&deferred_func_data, -1); usleep(15 * MSEC); - hook_call_deferred(deferred_func, 25 * MSEC); + hook_call_deferred(&deferred_func_data, 25 * MSEC); usleep(50 * MSEC); TEST_ASSERT(deferred_call_count == 2); - TEST_ASSERT(hook_call_deferred(non_deferred_func, 50 * MSEC) != + TEST_ASSERT(hook_call_deferred(&non_deferred_func_data, 50 * MSEC) != EC_SUCCESS); usleep(100 * MSEC); TEST_ASSERT(deferred_call_count == 2); |