WIP FPC-III support
[linux/fpc-iii.git] / drivers / soc / qcom / kryo-l2-accessors.c
blob7886af4fd7267dd9de579ce489200024a2057fba
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2018, The Linux Foundation. All rights reserved.
4 */
6 #include <linux/spinlock.h>
7 #include <asm/barrier.h>
8 #include <asm/sysreg.h>
9 #include <soc/qcom/kryo-l2-accessors.h>
11 #define L2CPUSRSELR_EL1 sys_reg(3, 3, 15, 0, 6)
12 #define L2CPUSRDR_EL1 sys_reg(3, 3, 15, 0, 7)
14 static DEFINE_RAW_SPINLOCK(l2_access_lock);
16 /**
17 * kryo_l2_set_indirect_reg() - write value to an L2 register
18 * @reg: Address of L2 register.
19 * @val: Value to be written to register.
21 * Use architecturally required barriers for ordering between system register
22 * accesses, and system registers with respect to device memory
24 void kryo_l2_set_indirect_reg(u64 reg, u64 val)
26 unsigned long flags;
28 raw_spin_lock_irqsave(&l2_access_lock, flags);
29 write_sysreg_s(reg, L2CPUSRSELR_EL1);
30 isb();
31 write_sysreg_s(val, L2CPUSRDR_EL1);
32 isb();
33 raw_spin_unlock_irqrestore(&l2_access_lock, flags);
35 EXPORT_SYMBOL(kryo_l2_set_indirect_reg);
37 /**
38 * kryo_l2_get_indirect_reg() - read an L2 register value
39 * @reg: Address of L2 register.
41 * Use architecturally required barriers for ordering between system register
42 * accesses, and system registers with respect to device memory
44 u64 kryo_l2_get_indirect_reg(u64 reg)
46 u64 val;
47 unsigned long flags;
49 raw_spin_lock_irqsave(&l2_access_lock, flags);
50 write_sysreg_s(reg, L2CPUSRSELR_EL1);
51 isb();
52 val = read_sysreg_s(L2CPUSRDR_EL1);
53 raw_spin_unlock_irqrestore(&l2_access_lock, flags);
55 return val;
57 EXPORT_SYMBOL(kryo_l2_get_indirect_reg);