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

irqflags.h (1733B)


      1/* SPDX-License-Identifier: GPL-2.0 */
      2/*
      3 * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
      4 */
      5#ifndef _ASM_IRQFLAGS_H
      6#define _ASM_IRQFLAGS_H
      7
      8#ifndef __ASSEMBLY__
      9
     10#include <linux/compiler.h>
     11#include <linux/stringify.h>
     12#include <asm/compiler.h>
     13#include <asm/loongarch.h>
     14
     15static inline void arch_local_irq_enable(void)
     16{
     17	u32 flags = CSR_CRMD_IE;
     18	__asm__ __volatile__(
     19		"csrxchg %[val], %[mask], %[reg]\n\t"
     20		: [val] "+r" (flags)
     21		: [mask] "r" (CSR_CRMD_IE), [reg] "i" (LOONGARCH_CSR_CRMD)
     22		: "memory");
     23}
     24
     25static inline void arch_local_irq_disable(void)
     26{
     27	u32 flags = 0;
     28	__asm__ __volatile__(
     29		"csrxchg %[val], %[mask], %[reg]\n\t"
     30		: [val] "+r" (flags)
     31		: [mask] "r" (CSR_CRMD_IE), [reg] "i" (LOONGARCH_CSR_CRMD)
     32		: "memory");
     33}
     34
     35static inline unsigned long arch_local_irq_save(void)
     36{
     37	u32 flags = 0;
     38	__asm__ __volatile__(
     39		"csrxchg %[val], %[mask], %[reg]\n\t"
     40		: [val] "+r" (flags)
     41		: [mask] "r" (CSR_CRMD_IE), [reg] "i" (LOONGARCH_CSR_CRMD)
     42		: "memory");
     43	return flags;
     44}
     45
     46static inline void arch_local_irq_restore(unsigned long flags)
     47{
     48	__asm__ __volatile__(
     49		"csrxchg %[val], %[mask], %[reg]\n\t"
     50		: [val] "+r" (flags)
     51		: [mask] "r" (CSR_CRMD_IE), [reg] "i" (LOONGARCH_CSR_CRMD)
     52		: "memory");
     53}
     54
     55static inline unsigned long arch_local_save_flags(void)
     56{
     57	u32 flags;
     58	__asm__ __volatile__(
     59		"csrrd %[val], %[reg]\n\t"
     60		: [val] "=r" (flags)
     61		: [reg] "i" (LOONGARCH_CSR_CRMD)
     62		: "memory");
     63	return flags;
     64}
     65
     66static inline int arch_irqs_disabled_flags(unsigned long flags)
     67{
     68	return !(flags & CSR_CRMD_IE);
     69}
     70
     71static inline int arch_irqs_disabled(void)
     72{
     73	return arch_irqs_disabled_flags(arch_local_save_flags());
     74}
     75
     76#endif /* #ifndef __ASSEMBLY__ */
     77
     78#endif /* _ASM_IRQFLAGS_H */