diff options
-rw-r--r-- | board/amenia/board.h | 3 | ||||
-rw-r--r-- | board/chell/board.h | 3 | ||||
-rw-r--r-- | board/elm/board.h | 3 | ||||
-rw-r--r-- | board/glados/board.h | 3 | ||||
-rw-r--r-- | board/kevin/board.h | 3 | ||||
-rw-r--r-- | board/kunimitsu/board.h | 3 | ||||
-rw-r--r-- | board/lars/board.h | 3 | ||||
-rw-r--r-- | board/oak/board.h | 3 | ||||
-rw-r--r-- | board/plankton/board.h | 3 | ||||
-rw-r--r-- | board/rambi/board.h | 3 | ||||
-rw-r--r-- | board/ryu/board.h | 4 | ||||
-rw-r--r-- | board/samus/board.h | 3 | ||||
-rw-r--r-- | board/samus_pd/board.h | 4 | ||||
-rw-r--r-- | board/strago/board.h | 3 | ||||
-rw-r--r-- | board/wheatley/board.h | 3 | ||||
-rw-r--r-- | chip/g/config_chip.h | 3 | ||||
-rw-r--r-- | chip/host/config_chip.h | 3 | ||||
-rw-r--r-- | chip/it83xx/config_chip.h | 3 | ||||
-rw-r--r-- | chip/lm4/config_chip.h | 3 | ||||
-rw-r--r-- | chip/mec1322/config_chip.h | 3 | ||||
-rw-r--r-- | chip/npcx/config_chip.h | 3 | ||||
-rw-r--r-- | chip/nrf51/config_chip.h | 3 | ||||
-rw-r--r-- | chip/stm32/config_chip.h | 3 | ||||
-rw-r--r-- | common/hooks.c | 18 | ||||
-rw-r--r-- | core/cortex-m/ec.lds.S | 16 | ||||
-rw-r--r-- | core/cortex-m0/ec.lds.S | 16 | ||||
-rw-r--r-- | core/host/host_exe.lds | 11 | ||||
-rw-r--r-- | core/nds32/ec.lds.S | 17 | ||||
-rw-r--r-- | include/hooks.h | 3 | ||||
-rw-r--r-- | include/link_defs.h | 4 |
30 files changed, 56 insertions, 100 deletions
diff --git a/board/amenia/board.h b/board/amenia/board.h index a6c6c3cc5e..8df5715165 100644 --- a/board/amenia/board.h +++ b/board/amenia/board.h @@ -141,9 +141,6 @@ /* Modules we want to exclude */ #undef CONFIG_PECI -#undef DEFERRABLE_MAX_COUNT -#define DEFERRABLE_MAX_COUNT 15 - #ifndef __ASSEMBLER__ #include "gpio_signal.h" diff --git a/board/chell/board.h b/board/chell/board.h index 66e360555d..8f34a955d4 100644 --- a/board/chell/board.h +++ b/board/chell/board.h @@ -136,9 +136,6 @@ #undef CONFIG_CMD_TIMERINFO #undef CONFIG_CONSOLE_CMDHELP -#undef DEFERRABLE_MAX_COUNT -#define DEFERRABLE_MAX_COUNT 16 - #ifndef __ASSEMBLER__ #include "gpio_signal.h" diff --git a/board/elm/board.h b/board/elm/board.h index c475da8224..29569d5d36 100644 --- a/board/elm/board.h +++ b/board/elm/board.h @@ -107,9 +107,6 @@ #define CONFIG_USB_SWITCH_PI3USB9281 #define CONFIG_USB_SWITCH_PI3USB9281_CHIP_COUNT 1 -#undef DEFERRABLE_MAX_COUNT -#define DEFERRABLE_MAX_COUNT 14 - /* Optional features */ #define CONFIG_CMD_HOSTCMD diff --git a/board/glados/board.h b/board/glados/board.h index b10d6238ea..88efe47cdf 100644 --- a/board/glados/board.h +++ b/board/glados/board.h @@ -144,9 +144,6 @@ #undef CONFIG_CMD_TIMERINFO #undef CONFIG_CONSOLE_CMDHELP -#undef DEFERRABLE_MAX_COUNT -#define DEFERRABLE_MAX_COUNT 17 - #ifndef __ASSEMBLER__ #include "gpio_signal.h" diff --git a/board/kevin/board.h b/board/kevin/board.h index f70617af77..1e955e3f99 100644 --- a/board/kevin/board.h +++ b/board/kevin/board.h @@ -86,9 +86,6 @@ #undef CONFIG_PSTORE #undef CONFIG_LOW_POWER_IDLE /* Deep Sleep Support */ -#undef DEFERRABLE_MAX_COUNT -#define DEFERRABLE_MAX_COUNT 10 - #define I2C_PORT_TCPC0 NPCX_I2C_PORT0_0 #define I2C_PORT_TCPC1 NPCX_I2C_PORT0_1 #define I2C_PORT_CHARGER NPCX_I2C_PORT2 diff --git a/board/kunimitsu/board.h b/board/kunimitsu/board.h index 8e7d7b2225..2d4b644888 100644 --- a/board/kunimitsu/board.h +++ b/board/kunimitsu/board.h @@ -134,9 +134,6 @@ #define I2C_PORT_PMIC MEC1322_I2C0_0 #define I2C_PORT_USB_CHARGER_2 MEC1322_I2C0_0 -#undef DEFERRABLE_MAX_COUNT -#define DEFERRABLE_MAX_COUNT 17 - #define CONFIG_ALS #define CONFIG_ALS_OPT3001 #define OPT3001_I2C_ADDR OPT3001_I2C_ADDR1 diff --git a/board/lars/board.h b/board/lars/board.h index e79ef88f54..e286c72fd9 100644 --- a/board/lars/board.h +++ b/board/lars/board.h @@ -129,9 +129,6 @@ #define I2C_PORT_CHARGER MEC1322_I2C3 #define I2C_PORT_THERMAL MEC1322_I2C3 -#undef DEFERRABLE_MAX_COUNT -#define DEFERRABLE_MAX_COUNT 15 - /* Modules we want to exclude */ #undef CONFIG_CMD_ACCEL_INFO #undef CONFIG_CMD_ACCELS diff --git a/board/oak/board.h b/board/oak/board.h index 5905d3aa0d..6480c0e8c4 100644 --- a/board/oak/board.h +++ b/board/oak/board.h @@ -118,9 +118,6 @@ #undef CONFIG_UART_TX_DMA #undef CONFIG_UART_RX_DMA -#undef DEFERRABLE_MAX_COUNT -#define DEFERRABLE_MAX_COUNT 13 - /* * Allow dangerous commands. * TODO: Remove this config before production. diff --git a/board/plankton/board.h b/board/plankton/board.h index 1fc193d35d..1c900d4851 100644 --- a/board/plankton/board.h +++ b/board/plankton/board.h @@ -52,9 +52,6 @@ */ #define CONFIG_SYSTEM_UNLOCKED -#undef DEFERRABLE_MAX_COUNT -#define DEFERRABLE_MAX_COUNT 9 - #ifndef __ASSEMBLER__ /* Timer selection */ diff --git a/board/rambi/board.h b/board/rambi/board.h index 76ba1691f2..6a7a4be26d 100644 --- a/board/rambi/board.h +++ b/board/rambi/board.h @@ -50,9 +50,6 @@ #define CONFIG_WIRELESS_SUSPEND \ (EC_WIRELESS_SWITCH_WLAN | EC_WIRELESS_SWITCH_WLAN_POWER) -#undef DEFERRABLE_MAX_COUNT -#define DEFERRABLE_MAX_COUNT 8 - #ifndef __ASSEMBLER__ /* I2C ports */ diff --git a/board/ryu/board.h b/board/ryu/board.h index e4dc8401c8..3c5be953ba 100644 --- a/board/ryu/board.h +++ b/board/ryu/board.h @@ -194,10 +194,6 @@ /* Depends on how fast the AP boots and typical ODRs */ #define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 3) -/* Maximum number of deferrable functions */ -#undef DEFERRABLE_MAX_COUNT -#define DEFERRABLE_MAX_COUNT 16 - #ifndef __ASSEMBLER__ int board_get_version(void); diff --git a/board/samus/board.h b/board/samus/board.h index a9221f2de9..09d8987ca3 100644 --- a/board/samus/board.h +++ b/board/samus/board.h @@ -86,9 +86,6 @@ (EC_WIRELESS_SWITCH_WLAN | EC_WIRELESS_SWITCH_WLAN_POWER) /* Do we want EC_WIRELESS_SWITCH_WWAN as well? */ -#undef DEFERRABLE_MAX_COUNT -#define DEFERRABLE_MAX_COUNT 9 - #ifndef __ASSEMBLER__ /* I2C ports */ diff --git a/board/samus_pd/board.h b/board/samus_pd/board.h index e0a7b4e929..6d1859db50 100644 --- a/board/samus_pd/board.h +++ b/board/samus_pd/board.h @@ -88,10 +88,6 @@ #define CONFIG_HOSTCMD_I2C_SLAVE_ADDR CONFIG_USB_PD_I2C_SLAVE_ADDR #endif -/* Maximum number of deferrable functions */ -#undef DEFERRABLE_MAX_COUNT -#define DEFERRABLE_MAX_COUNT 10 - #ifndef __ASSEMBLER__ /* Timer selection */ diff --git a/board/strago/board.h b/board/strago/board.h index 2fd14e0ad6..aa3d6d57c8 100644 --- a/board/strago/board.h +++ b/board/strago/board.h @@ -94,9 +94,6 @@ /* Number of buttons */ #define CONFIG_BUTTON_COUNT 2 -#undef DEFERRABLE_MAX_COUNT -#define DEFERRABLE_MAX_COUNT 13 - #define CONFIG_ADC /* Modules we want to exclude */ diff --git a/board/wheatley/board.h b/board/wheatley/board.h index 6b3c6462a7..62b4efa777 100644 --- a/board/wheatley/board.h +++ b/board/wheatley/board.h @@ -146,9 +146,6 @@ #undef CONFIG_CMD_TIMERINFO #undef CONFIG_CONSOLE_CMDHELP -#undef DEFERRABLE_MAX_COUNT -#define DEFERRABLE_MAX_COUNT 15 - #ifndef __ASSEMBLER__ #include "gpio_signal.h" diff --git a/chip/g/config_chip.h b/chip/g/config_chip.h index 688ccb5582..938f3fdb1b 100644 --- a/chip/g/config_chip.h +++ b/chip/g/config_chip.h @@ -57,9 +57,6 @@ /* Larger task stack size, for hook task */ #define LARGER_TASK_STACK_SIZE 640 -/* Maximum number of deferrable functions */ -#define DEFERRABLE_MAX_COUNT 8 - /* Magic for gpio.inc */ #define GPIO_PIN(port, index) (port), (1 << (index)) #define GPIO_PIN_MASK(port, mask) (port), (mask) diff --git a/chip/host/config_chip.h b/chip/host/config_chip.h index 17bd46cf88..37ea9a9f44 100644 --- a/chip/host/config_chip.h +++ b/chip/host/config_chip.h @@ -32,9 +32,6 @@ extern char __host_flash[CONFIG_FLASH_SIZE]; /* Compute the rest of the flash params from these */ #include "config_std_internal_flash.h" -/* Maximum number of deferrable functions */ -#define DEFERRABLE_MAX_COUNT 8 - /* Interval between HOOK_TICK notifications */ #define HOOK_TICK_INTERVAL_MS 250 #define HOOK_TICK_INTERVAL (HOOK_TICK_INTERVAL_MS * MSEC) diff --git a/chip/it83xx/config_chip.h b/chip/it83xx/config_chip.h index e66ee01181..d0691ce98f 100644 --- a/chip/it83xx/config_chip.h +++ b/chip/it83xx/config_chip.h @@ -16,9 +16,6 @@ #define HOOK_TICK_INTERVAL_MS 500 #define HOOK_TICK_INTERVAL (HOOK_TICK_INTERVAL_MS * MSEC) -/* Maximum number of deferrable functions */ -#define DEFERRABLE_MAX_COUNT 8 - /* Default PLL frequency. */ #define PLL_CLOCK 48000000 diff --git a/chip/lm4/config_chip.h b/chip/lm4/config_chip.h index 6157aa5ac6..0037fac515 100644 --- a/chip/lm4/config_chip.h +++ b/chip/lm4/config_chip.h @@ -23,9 +23,6 @@ #define HOOK_TICK_INTERVAL_MS 250 #define HOOK_TICK_INTERVAL (HOOK_TICK_INTERVAL_MS * MSEC) -/* Maximum number of deferrable functions */ -#define DEFERRABLE_MAX_COUNT 8 - /* Number of I2C ports */ #define I2C_PORT_COUNT 6 diff --git a/chip/mec1322/config_chip.h b/chip/mec1322/config_chip.h index 6758c6cf3f..d06c1e78d3 100644 --- a/chip/mec1322/config_chip.h +++ b/chip/mec1322/config_chip.h @@ -20,9 +20,6 @@ #define HOOK_TICK_INTERVAL_MS 250 #define HOOK_TICK_INTERVAL (HOOK_TICK_INTERVAL_MS * MSEC) -/* Maximum number of deferrable functions */ -#define DEFERRABLE_MAX_COUNT 8 - /* * Number of I2C controllers. Controller 0 has 2 ports, so the chip has one * additional port. diff --git a/chip/npcx/config_chip.h b/chip/npcx/config_chip.h index f581aaf2bd..480b6c4e3b 100644 --- a/chip/npcx/config_chip.h +++ b/chip/npcx/config_chip.h @@ -26,9 +26,6 @@ #define HOOK_TICK_INTERVAL_MS 200 #define HOOK_TICK_INTERVAL (HOOK_TICK_INTERVAL_MS * MSEC) -/* Maximum number of deferrable functions */ -#define DEFERRABLE_MAX_COUNT 8 - /* * Number of I2C controllers. Controller 0 has 2 ports, so the chip has one * additional port. diff --git a/chip/nrf51/config_chip.h b/chip/nrf51/config_chip.h index 82ac548477..f14f292f77 100644 --- a/chip/nrf51/config_chip.h +++ b/chip/nrf51/config_chip.h @@ -24,9 +24,6 @@ #define HOOK_TICK_INTERVAL_MS 500 #define HOOK_TICK_INTERVAL (HOOK_TICK_INTERVAL_MS * MSEC) -/* Maximum number of deferrable functions */ -#define DEFERRABLE_MAX_COUNT 8 - /* Number of I2C ports */ #define I2C_PORT_COUNT 2 diff --git a/chip/stm32/config_chip.h b/chip/stm32/config_chip.h index 3246f5038e..f0d1fa85d1 100644 --- a/chip/stm32/config_chip.h +++ b/chip/stm32/config_chip.h @@ -78,9 +78,6 @@ #define HOOK_TICK_INTERVAL_MS 500 #define HOOK_TICK_INTERVAL (HOOK_TICK_INTERVAL_MS * MSEC) -/* Maximum number of deferrable functions */ -#define DEFERRABLE_MAX_COUNT 8 - /* Number of I2C ports */ #define I2C_PORT_COUNT 2 diff --git a/common/hooks.c b/common/hooks.c index 1a1a1aa819..b6eb019b7c 100644 --- a/common/hooks.c +++ b/common/hooks.c @@ -52,7 +52,6 @@ static const struct hook_ptrs hook_list[] = { }; /* Times for deferrable functions */ -static uint64_t defer_until[DEFERRABLE_MAX_COUNT]; static int defer_new_call; static int hook_task_started; @@ -141,10 +140,10 @@ int hook_call_deferred(const struct deferred_data *data, int us) if (us == -1) { /* Cancel */ - defer_until[i] = 0; + __deferred_until[i] = 0; } else { /* Set alarm */ - defer_until[i] = get_time().val + us; + __deferred_until[i] = get_time().val + us; /* * Flag that hook_call_deferred() has been called. If the hook * task is already active, this will allow it to go through the @@ -181,14 +180,14 @@ void hook_task(void) /* Handle deferred routines */ for (i = 0; i < DEFERRED_FUNCS_COUNT; i++) { - if (defer_until[i] && defer_until[i] < t) { + if (__deferred_until[i] && __deferred_until[i] < t) { CPRINTS("hook call deferred 0x%p", __deferred_funcs[i].routine); /* * Call deferred function. Clear timer first, * so it can request itself be called later. */ - defer_until[i] = 0; + __deferred_until[i] = 0; __deferred_funcs[i].routine(); } } @@ -220,14 +219,15 @@ void hook_task(void) /* Wake earlier if needed by a deferred routine */ defer_new_call = 0; + for (i = 0; i < DEFERRED_FUNCS_COUNT && next > 0; i++) { - if (!defer_until[i]) + if (!__deferred_until[i]) continue; - if (defer_until[i] < t) + if (__deferred_until[i] < t) next = 0; - else if (defer_until[i] - t < next) - next = defer_until[i] - t; + else if (__deferred_until[i] - t < next) + next = __deferred_until[i] - t; } /* diff --git a/core/cortex-m/ec.lds.S b/core/cortex-m/ec.lds.S index 24f3030354..6beb007dba 100644 --- a/core/cortex-m/ec.lds.S +++ b/core/cortex-m/ec.lds.S @@ -225,11 +225,6 @@ SECTIONS #endif __ro_end = . ; - __deferred_funcs_count = - (__deferred_funcs_end - __deferred_funcs) / 4; - ASSERT(__deferred_funcs_count <= DEFERRABLE_MAX_COUNT, - "Increase DEFERRABLE_MAX_COUNT") - .bss : { /* * Align to 512 bytes. This is convenient when some memory block @@ -244,6 +239,17 @@ SECTIONS *(.bss.system_stack) /* Rest of .bss takes care of its own alignment */ *(.bss) + + /* + * Reserve space for deferred function firing times. Each time is a + * uint64_t, each func is a 32-bit pointer, thus the scaling factor of + * two. The 8 byte alignment of uint64_t is required by the ARM ABI. + */ + . = ALIGN(8); + __deferred_until = .; + . += (__deferred_funcs_end - __deferred_funcs) * (8 / 4); + __deferred_until_end = .; + #ifdef CONFIG_REPLACE_LOADER_WITH_BSS_SLOW . = ALIGN(4); __bss_end = .; diff --git a/core/cortex-m0/ec.lds.S b/core/cortex-m0/ec.lds.S index 6596b5e05d..602374404a 100644 --- a/core/cortex-m0/ec.lds.S +++ b/core/cortex-m0/ec.lds.S @@ -174,11 +174,6 @@ SECTIONS } > FLASH __ro_end = . ; - __deferred_funcs_count = - (__deferred_funcs_end - __deferred_funcs) / 4; - ASSERT(__deferred_funcs_count <= DEFERRABLE_MAX_COUNT, - "Increase DEFERRABLE_MAX_COUNT") - .bss : { /* * Vector table must be at the beginning of bss section. The vector @@ -194,6 +189,17 @@ SECTIONS /* Rest of .bss takes care of its own alignment */ *(.bss) *(.bss.slow) + + /* + * Reserve space for deferred function firing times. Each time is a + * uint64_t, each func is a 32-bit pointer, thus the scaling factor of + * two. The 8 byte alignment of uint64_t is required by the ARM ABI. + */ + . = ALIGN(8); + __deferred_until = .; + . += (__deferred_funcs_end - __deferred_funcs) * (8 / 4); + __deferred_until_end = .; + . = ALIGN(4); __bss_end = .; } > IRAM diff --git a/core/host/host_exe.lds b/core/host/host_exe.lds index 1f508e5795..3ea0a706e4 100644 --- a/core/host/host_exe.lds +++ b/core/host/host_exe.lds @@ -98,3 +98,14 @@ SECTIONS { } } INSERT BEFORE .rodata; + +SECTIONS { + .bss.ec_sections : { + /* Symbols defined here are declared in link_defs.h */ + . = ALIGN(8); + __deferred_until = .; + . += (__deferred_funcs_end - __deferred_funcs) * (8 / 4); + __deferred_until_end = .; + } +} +INSERT BEFORE .bss; diff --git a/core/nds32/ec.lds.S b/core/nds32/ec.lds.S index eaf5510ceb..4f217d66b3 100644 --- a/core/nds32/ec.lds.S +++ b/core/nds32/ec.lds.S @@ -174,12 +174,6 @@ SECTIONS } > IRAM AT>FLASH - - __deferred_funcs_count = - (__deferred_funcs_end - __deferred_funcs) / 4; - ASSERT(__deferred_funcs_count <= DEFERRABLE_MAX_COUNT, - "Increase DEFERRABLE_MAX_COUNT") - .bss : { /* Stacks must be 64-bit aligned */ . = ALIGN(8); @@ -191,6 +185,17 @@ SECTIONS /* Rest of .bss takes care of its own alignment */ *(.bss) *(.bss.slow) + + /* + * Reserve space for deferred function firing times. Each time is a + * uint64_t, each func is a 32-bit pointer, thus the scaling factor of + * two. + */ + . = ALIGN(8); + __deferred_until = .; + . += (__deferred_funcs_end - __deferred_funcs) * (8 / 4); + __deferred_until_end = .; + . = ALIGN(4); __bss_end = .; diff --git a/include/hooks.h b/include/hooks.h index 142926e6a9..5c28401c8a 100644 --- a/include/hooks.h +++ b/include/hooks.h @@ -246,9 +246,6 @@ int hook_call_deferred(const struct deferred_data *data, int us); /** * 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. * diff --git a/include/link_defs.h b/include/link_defs.h index 95fec83fff..91950811d2 100644 --- a/include/link_defs.h +++ b/include/link_defs.h @@ -59,9 +59,11 @@ extern const struct hook_data __hooks_tick_end[]; extern const struct hook_data __hooks_second[]; extern const struct hook_data __hooks_second_end[]; -/* Deferrable functions */ +/* Deferrable functions and firing times*/ extern const struct deferred_data __deferred_funcs[]; extern const struct deferred_data __deferred_funcs_end[]; +extern uint64_t __deferred_until[]; +extern uint64_t __deferred_until_end[]; /* I2C fake devices for unit testing */ extern const struct test_i2c_xfer __test_i2c_xfer[]; |