cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

kryo-l2-accessors.c (1545B)


      1// SPDX-License-Identifier: GPL-2.0
      2/*
      3 * Copyright (c) 2018, The Linux Foundation. All rights reserved.
      4 */
      5
      6#include <linux/spinlock.h>
      7#include <asm/barrier.h>
      8#include <asm/sysreg.h>
      9#include <soc/qcom/kryo-l2-accessors.h>
     10
     11#define L2CPUSRSELR_EL1         sys_reg(3, 3, 15, 0, 6)
     12#define L2CPUSRDR_EL1           sys_reg(3, 3, 15, 0, 7)
     13
     14static DEFINE_RAW_SPINLOCK(l2_access_lock);
     15
     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.
     20 *
     21 * Use architecturally required barriers for ordering between system register
     22 * accesses, and system registers with respect to device memory
     23 */
     24void kryo_l2_set_indirect_reg(u64 reg, u64 val)
     25{
     26	unsigned long flags;
     27
     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);
     34}
     35EXPORT_SYMBOL(kryo_l2_set_indirect_reg);
     36
     37/**
     38 * kryo_l2_get_indirect_reg() - read an L2 register value
     39 * @reg: Address of L2 register.
     40 *
     41 * Use architecturally required barriers for ordering between system register
     42 * accesses, and system registers with respect to device memory
     43 */
     44u64 kryo_l2_get_indirect_reg(u64 reg)
     45{
     46	u64 val;
     47	unsigned long flags;
     48
     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);
     54
     55	return val;
     56}
     57EXPORT_SYMBOL(kryo_l2_get_indirect_reg);