From 4f7cd7509d7a02b1d5f3f0fd3885202350b576f1 Mon Sep 17 00:00:00 2001 From: Dawid Niedzwiecki Date: Mon, 29 Nov 2021 11:08:48 +0100 Subject: atomic: use atomic_t where it is possible There are several places where atomic_t can be a type variables that are use with atomic_* operation, so use it. It sometimes has an impact on the asm code, but it is not significant. The change will be useful for incoming commits related to modifying atomic_t caused by a change in Zephyr upstream (atomic_t from int to long). BUG=b:207082842 TEST=make buildall && zmake testall BRANCH=main Signed-off-by: Dawid Niedzwiecki Change-Id: I5c7fa6b74b84454b22074a2a00b5f10003ee9843 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3306358 Reviewed-by: Jack Rosenthal Reviewed-by: Keith Short Reviewed-by: Tom Hughes Commit-Queue: Dawid Niedzwiecki --- baseboard/dedede/baseboard.c | 2 +- baseboard/dedede/baseboard.h | 3 ++- baseboard/hatch/baseboard.c | 2 +- chip/ish/uart_defs.h | 3 ++- chip/mt_scp/rv32i_common/ipi.c | 2 +- chip/npcx/cec.c | 2 +- chip/stm32/pwm.c | 2 +- common/button.c | 2 +- common/device_event.c | 8 ++++---- common/dptf.c | 4 ++-- common/fpsensor/fpsensor_state.c | 3 ++- common/host_event_commands.c | 4 ++-- common/motion_sense.c | 2 +- common/peripheral_charger.c | 2 +- cts/interrupt/dut.c | 2 +- driver/charger/sm5803.c | 2 +- driver/ppc/aoz1380.c | 4 ++-- driver/ppc/nx20p348x.c | 2 +- driver/ppc/sn5s330.c | 2 +- driver/tcpm/tcpci.c | 4 ++-- driver/usb_mux/usb_mux.c | 2 +- include/fpsensor_state.h | 4 +++- include/motion_sense.h | 3 ++- include/peripheral_charger.h | 3 ++- 24 files changed, 38 insertions(+), 31 deletions(-) diff --git a/baseboard/dedede/baseboard.c b/baseboard/dedede/baseboard.c index 54c7a6a24a..7b68b755ae 100644 --- a/baseboard/dedede/baseboard.c +++ b/baseboard/dedede/baseboard.c @@ -118,7 +118,7 @@ __override void board_check_extpower(void) last_extpower_present = extpower_present; } -uint32_t pp3300_a_pgood; +atomic_t pp3300_a_pgood; __override int intel_x86_get_pg_ec_dsw_pwrok(void) { /* diff --git a/baseboard/dedede/baseboard.h b/baseboard/dedede/baseboard.h index 529e011f32..c17eee71fe 100644 --- a/baseboard/dedede/baseboard.h +++ b/baseboard/dedede/baseboard.h @@ -241,6 +241,7 @@ #ifndef __ASSEMBLER__ +#include "atomic_t.h" #include "common.h" #include "gpio_signal.h" @@ -265,7 +266,7 @@ void board_reset_pd_mcu(void); * Bit to indicate if the PP3000_A rail's power is good. Will be updated by ADC * interrupt. */ -extern uint32_t pp3300_a_pgood; +extern atomic_t pp3300_a_pgood; #endif /* !__ASSEMBLER__ */ #endif /* __CROS_EC_BASEBOARD_H */ diff --git a/baseboard/hatch/baseboard.c b/baseboard/hatch/baseboard.c index 58ae6032eb..683df43251 100644 --- a/baseboard/hatch/baseboard.c +++ b/baseboard/hatch/baseboard.c @@ -384,7 +384,7 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, #ifdef USB_PD_PORT_TCPC_MST void baseboard_mst_enable_control(enum mst_source src, int level) { - static uint32_t mst_input_levels; + static atomic_t mst_input_levels; if (level) atomic_or(&mst_input_levels, 1 << src); diff --git a/chip/ish/uart_defs.h b/chip/ish/uart_defs.h index b573ef7710..5bfc7b9a6b 100644 --- a/chip/ish/uart_defs.h +++ b/chip/ish/uart_defs.h @@ -10,6 +10,7 @@ #include #include +#include "atomic.h" #define UART_ERROR -1 #define UART_BUSY -2 @@ -354,7 +355,7 @@ struct uart_ctx { uint32_t id; uint32_t base; uint32_t addr_interval; - uint32_t uart_state; + atomic_t uart_state; uint32_t is_open; uint32_t baud_rate; uint32_t input_freq; diff --git a/chip/mt_scp/rv32i_common/ipi.c b/chip/mt_scp/rv32i_common/ipi.c index cba5c65d0b..a7fc720d42 100644 --- a/chip/mt_scp/rv32i_common/ipi.c +++ b/chip/mt_scp/rv32i_common/ipi.c @@ -28,7 +28,7 @@ static struct ipc_shared_obj *const ipi_recv_buf = (struct ipc_shared_obj *)(CONFIG_IPC_SHARED_OBJ_ADDR + sizeof(struct ipc_shared_obj)); -static uint32_t disable_irq_count, saved_int_mask; +static atomic_t disable_irq_count, saved_int_mask; void ipi_disable_irq(void) { diff --git a/chip/npcx/cec.c b/chip/npcx/cec.c index e7cd0ae7b9..eb1cfefa0f 100644 --- a/chip/npcx/cec.c +++ b/chip/npcx/cec.c @@ -251,7 +251,7 @@ static int cap_charge; static uint8_t cec_addr = UINT8_MAX; /* Events to send to AP */ -static uint32_t cec_events; +static atomic_t cec_events; /* APB1 frequency. Store divided by 10k to avoid some runtime divisions */ static uint32_t apb1_freq_div_10k; diff --git a/chip/stm32/pwm.c b/chip/stm32/pwm.c index 0b339399c9..aadbde08c2 100644 --- a/chip/stm32/pwm.c +++ b/chip/stm32/pwm.c @@ -17,7 +17,7 @@ #include "util.h" /* Bitmap of currently active PWM channels. 1 bit per channel. */ -static uint32_t using_pwm; +static atomic_t using_pwm; void pwm_set_duty(enum pwm_channel ch, int percent) { diff --git a/common/button.c b/common/button.c index d30115066d..e63fdb8103 100644 --- a/common/button.c +++ b/common/button.c @@ -43,7 +43,7 @@ static uint64_t next_deferred_time; /* Bitmask to keep track of simulated state of each button. * Bit numbers are aligned to enum button. */ -static int sim_button_state; +static atomic_t sim_button_state; /* * Flip state of associated button type in sim_button_state bitmask. diff --git a/common/device_event.c b/common/device_event.c index f7944ae930..748a98ae8f 100644 --- a/common/device_event.c +++ b/common/device_event.c @@ -17,8 +17,8 @@ #define CPUTS(outstr) cputs(CC_EVENTS, outstr) #define CPRINTS(format, args...) cprints(CC_EVENTS, format, ## args) -static uint32_t device_current_events; -static uint32_t device_enabled_events; +static atomic_t device_current_events; +static atomic_t device_enabled_events; uint32_t device_get_current_events(void) { @@ -40,7 +40,7 @@ void device_set_events(uint32_t mask) /* Ignore events that are not enabled */ mask &= device_enabled_events; - if ((device_current_events & mask) != mask) { + if (((uint32_t)device_current_events & mask) != mask) { CPRINTS("device event set 0x%08x", mask); } else { /* @@ -64,7 +64,7 @@ void device_set_events(uint32_t mask) void device_clear_events(uint32_t mask) { /* Only print if something's about to change */ - if (device_current_events & mask) + if ((uint32_t)device_current_events & mask) CPRINTS("device event clear 0x%08x", mask); atomic_clear_bits(&device_current_events, mask); diff --git a/common/dptf.c b/common/dptf.c index 12864d8367..06937bf71d 100644 --- a/common/dptf.c +++ b/common/dptf.c @@ -45,14 +45,14 @@ static void dptf_init(void) DECLARE_HOOK(HOOK_INIT, dptf_init, HOOK_PRIO_DEFAULT); /* Keep track of which triggered sensor thresholds the AP has seen */ -static uint32_t dptf_seen; +static atomic_t dptf_seen; int dptf_query_next_sensor_event(void) { int id; for (id = 0; id < TEMP_SENSOR_COUNT; id++) - if (dptf_seen & BIT(id)) { /* atomic? */ + if ((uint32_t)dptf_seen & BIT(id)) { atomic_clear_bits(&dptf_seen, BIT(id)); return id; } diff --git a/common/fpsensor/fpsensor_state.c b/common/fpsensor/fpsensor_state.c index db64110b56..bd907e2c00 100644 --- a/common/fpsensor/fpsensor_state.c +++ b/common/fpsensor/fpsensor_state.c @@ -3,6 +3,7 @@ * found in the LICENSE file. */ +#include "atomic.h" #include "common.h" #include "cryptoc/util.h" #include "ec_commands.h" @@ -51,7 +52,7 @@ uint8_t tpm_seed[FP_CONTEXT_TPM_BYTES]; /* Status of the FP encryption engine. */ static uint32_t fp_encryption_status; -uint32_t fp_events; +atomic_t fp_events; uint32_t sensor_mode; diff --git a/common/host_event_commands.c b/common/host_event_commands.c index 1856c88c37..532cfe3be3 100644 --- a/common/host_event_commands.c +++ b/common/host_event_commands.c @@ -264,7 +264,7 @@ static struct lazy_wake_masks { static void host_events_atomic_or(host_event_t *e, host_event_t m) { - uint32_t *ptr = (uint32_t *)e; + atomic_t *ptr = (atomic_t *)e; atomic_or(ptr, (uint32_t)m); #ifdef CONFIG_HOST_EVENT64 @@ -274,7 +274,7 @@ static void host_events_atomic_or(host_event_t *e, host_event_t m) static void host_events_atomic_clear(host_event_t *e, host_event_t m) { - uint32_t *ptr = (uint32_t *)e; + atomic_t *ptr = (atomic_t *)e; atomic_clear_bits(ptr, (uint32_t)m); #ifdef CONFIG_HOST_EVENT64 diff --git a/common/motion_sense.c b/common/motion_sense.c index a9b15fd071..afffb02e78 100644 --- a/common/motion_sense.c +++ b/common/motion_sense.c @@ -73,7 +73,7 @@ STATIC_IF(CONFIG_MOTION_FILL_LPC_SENSE_DATA) void update_sense_data( uint8_t *lpc_status, int *psample_id); /* Flags to control whether to send an ODR change event for a sensor */ -static uint32_t odr_event_required; +static atomic_t odr_event_required; /* Whether or not the FIFO interrupt should be enabled (set from the AP). */ __maybe_unused static int fifo_int_enabled; diff --git a/common/peripheral_charger.c b/common/peripheral_charger.c index 0a597ad6bd..9ed8d8394d 100644 --- a/common/peripheral_charger.c +++ b/common/peripheral_charger.c @@ -22,7 +22,7 @@ #define CPRINTS(fmt, args...) cprints(CC_PCHG, "PCHG: " fmt, ##args) /* Currently only used for FW update. */ -static uint32_t pchg_host_events; +static atomic_t pchg_host_events; static void pchg_queue_event(struct pchg *ctx, enum pchg_event event) { diff --git a/cts/interrupt/dut.c b/cts/interrupt/dut.c index 3c83e5701f..a479918c5f 100644 --- a/cts/interrupt/dut.c +++ b/cts/interrupt/dut.c @@ -66,7 +66,7 @@ void cts_irq2(enum gpio_signal signal) void clean_state(void) { - uint32_t *event; + atomic_t *event; interrupt_enable(); got_interrupt = 0; diff --git a/driver/charger/sm5803.c b/driver/charger/sm5803.c index 43a54d798b..36c4e705c2 100644 --- a/driver/charger/sm5803.c +++ b/driver/charger/sm5803.c @@ -48,7 +48,7 @@ static const struct charger_info sm5803_charger_info = { .input_current_step = INPUT_I_STEP, }; -static uint32_t irq_pending; /* Bitmask of chips with interrupts pending */ +static atomic_t irq_pending; /* Bitmask of chips with interrupts pending */ static struct mutex flow1_access_lock[CHARGER_NUM]; static struct mutex flow2_access_lock[CHARGER_NUM]; diff --git a/driver/ppc/aoz1380.c b/driver/ppc/aoz1380.c index 935503b593..726f626caf 100644 --- a/driver/ppc/aoz1380.c +++ b/driver/ppc/aoz1380.c @@ -25,12 +25,12 @@ #define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args) #define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args) -static uint32_t irq_pending; /* Bitmask of ports signaling an interrupt. */ +static atomic_t irq_pending; /* Bitmask of ports signaling an interrupt. */ #define AOZ1380_FLAGS_SOURCE_ENABLED BIT(0) #define AOZ1380_FLAGS_SINK_ENABLED BIT(1) #define AOZ1380_FLAGS_INT_ON_DISCONNECT BIT(2) -static uint32_t flags[CONFIG_USB_PD_PORT_MAX_COUNT]; +static atomic_t flags[CONFIG_USB_PD_PORT_MAX_COUNT]; #define AOZ1380_SET_FLAG(port, flag) atomic_or(&flags[port], (flag)) #define AOZ1380_CLR_FLAG(port, flag) atomic_clear_bits(&flags[port], (flag)) diff --git a/driver/ppc/nx20p348x.c b/driver/ppc/nx20p348x.c index b582259e04..130678d512 100644 --- a/driver/ppc/nx20p348x.c +++ b/driver/ppc/nx20p348x.c @@ -22,7 +22,7 @@ #define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args) #define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args) -static uint32_t irq_pending; /* Bitmask of ports signaling an interrupt. */ +static atomic_t irq_pending; /* Bitmask of ports signaling an interrupt. */ #define NX20P348X_DB_EXIT_FAIL_THRESHOLD 10 static int db_exit_fail_count[CONFIG_USB_PD_PORT_MAX_COUNT]; diff --git a/driver/ppc/sn5s330.c b/driver/ppc/sn5s330.c index c45340250d..0e5934533e 100644 --- a/driver/ppc/sn5s330.c +++ b/driver/ppc/sn5s330.c @@ -26,7 +26,7 @@ #define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args) #define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args) -static uint32_t irq_pending; /* Bitmask of ports signaling an interrupt. */ +static atomic_t irq_pending; /* Bitmask of ports signaling an interrupt. */ static int source_enabled[CONFIG_USB_PD_PORT_MAX_COUNT]; static int read_reg(uint8_t port, int reg, int *regval) diff --git a/driver/tcpm/tcpci.c b/driver/tcpm/tcpci.c index 359cb04d30..b04d7be1af 100644 --- a/driver/tcpm/tcpci.c +++ b/driver/tcpm/tcpci.c @@ -877,12 +877,12 @@ struct queue { * Head points to the index of the first empty slot to put a new RX * message. Must be masked before used in lookup. */ - uint32_t head; + atomic_t head; /* * Tail points to the index of the first message for the PD task to * consume. Must be masked before used in lookup. */ - uint32_t tail; + atomic_t tail; struct cached_tcpm_message buffer[CACHE_DEPTH]; }; static struct queue cached_messages[CONFIG_USB_PD_PORT_MAX_COUNT]; diff --git a/driver/usb_mux/usb_mux.c b/driver/usb_mux/usb_mux.c index c53a21ce65..4095846c30 100644 --- a/driver/usb_mux/usb_mux.c +++ b/driver/usb_mux/usb_mux.c @@ -32,7 +32,7 @@ static int enable_debug_prints; * Flags will reset to 0 after sysjump; This works for current flags as LPM will * get reset in the init method which is called during PD task startup. */ -static uint32_t flags[CONFIG_USB_PD_PORT_MAX_COUNT]; +static atomic_t flags[CONFIG_USB_PD_PORT_MAX_COUNT]; /* Device is in low power mode. */ #define USB_MUX_FLAG_IN_LPM BIT(0) diff --git a/include/fpsensor_state.h b/include/fpsensor_state.h index 6b752bc86d..98d5b63783 100644 --- a/include/fpsensor_state.h +++ b/include/fpsensor_state.h @@ -10,6 +10,8 @@ #include #include + +#include "atomic.h" #include "common.h" #include "ec_commands.h" #include "link_defs.h" @@ -64,7 +66,7 @@ extern uint32_t user_id[FP_CONTEXT_USERID_WORDS]; /* Part of the IKM used to derive encryption keys received from the TPM. */ extern uint8_t tpm_seed[FP_CONTEXT_TPM_BYTES]; -extern uint32_t fp_events; +extern atomic_t fp_events; extern uint32_t sensor_mode; diff --git a/include/motion_sense.h b/include/motion_sense.h index e507a3c799..6d176cd79d 100644 --- a/include/motion_sense.h +++ b/include/motion_sense.h @@ -8,6 +8,7 @@ #ifndef __CROS_EC_MOTION_SENSE_H #define __CROS_EC_MOTION_SENSE_H +#include "atomic.h" #include "chipset.h" #include "common.h" #include "ec_commands.h" @@ -215,7 +216,7 @@ struct motion_sensor_t { intv3_t spoof_xyz; /* How many flush events are pending */ - uint32_t flush_pending; + atomic_t flush_pending; /* * Allow EC to request an higher frequency for the sensors than the AP. diff --git a/include/peripheral_charger.h b/include/peripheral_charger.h index b1f82bb1f3..58fbf1482b 100644 --- a/include/peripheral_charger.h +++ b/include/peripheral_charger.h @@ -6,6 +6,7 @@ #ifndef __CROS_EC_PERIPHERAL_CHARGER_H #define __CROS_EC_PERIPHERAL_CHARGER_H +#include "atomic.h" #include "common.h" #include "ec_commands.h" #include "gpio.h" @@ -196,7 +197,7 @@ struct pchg { /* Event queue mutex */ struct mutex mtx; /* 1:Pending IRQ 0:No pending IRQ */ - uint32_t irq; + atomic_t irq; /* Event currently being handled */ enum pchg_event event; /* Error (enum pchg_error). Port is disabled until it's cleared. */ -- cgit v1.2.1