xref: /optee_os/core/drivers/stm32_shared_io.c (revision 9f34db38245c9b3a4e6e7e63eb78a75e23ab2da3)
1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3  * Copyright (c) 2017-2022, STMicroelectronics
4  */
5 
6 #include <drivers/stm32_shared_io.h>
7 #include <io.h>
8 #include <kernel/spinlock.h>
9 #include <stm32_util.h>
10 
11 static unsigned int shregs_lock = SPINLOCK_UNLOCK;
12 
13 static uint32_t lock_stm32shregs(void)
14 {
15 	return may_spin_lock(&shregs_lock);
16 }
17 
18 static void unlock_stm32shregs(uint32_t exceptions)
19 {
20 	may_spin_unlock(&shregs_lock, exceptions);
21 }
22 
23 void io_mask32_stm32shregs(vaddr_t va, uint32_t value, uint32_t mask)
24 {
25 	uint32_t exceptions = lock_stm32shregs();
26 
27 	io_mask32(va, value, mask);
28 
29 	unlock_stm32shregs(exceptions);
30 }
31 
32 void io_clrsetbits32_stm32shregs(vaddr_t va, uint32_t clr, uint32_t set)
33 {
34 	uint32_t exceptions = lock_stm32shregs();
35 
36 	io_clrsetbits32(va, clr, set);
37 
38 	unlock_stm32shregs(exceptions);
39 }
40