18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Xtensa IRQ flags handling functions 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public 58c2ecf20Sopenharmony_ci * License. See the file "COPYING" in the main directory of this archive 68c2ecf20Sopenharmony_ci * for more details. 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * Copyright (C) 2001 - 2005 Tensilica Inc. 98c2ecf20Sopenharmony_ci * Copyright (C) 2015 Cadence Design Systems Inc. 108c2ecf20Sopenharmony_ci */ 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#ifndef _XTENSA_IRQFLAGS_H 138c2ecf20Sopenharmony_ci#define _XTENSA_IRQFLAGS_H 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include <linux/stringify.h> 168c2ecf20Sopenharmony_ci#include <linux/types.h> 178c2ecf20Sopenharmony_ci#include <asm/processor.h> 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_cistatic inline unsigned long arch_local_save_flags(void) 208c2ecf20Sopenharmony_ci{ 218c2ecf20Sopenharmony_ci unsigned long flags; 228c2ecf20Sopenharmony_ci asm volatile("rsr %0, ps" : "=a" (flags)); 238c2ecf20Sopenharmony_ci return flags; 248c2ecf20Sopenharmony_ci} 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_cistatic inline unsigned long arch_local_irq_save(void) 278c2ecf20Sopenharmony_ci{ 288c2ecf20Sopenharmony_ci unsigned long flags; 298c2ecf20Sopenharmony_ci#if XTENSA_FAKE_NMI 308c2ecf20Sopenharmony_ci#if defined(CONFIG_DEBUG_MISC) && (LOCKLEVEL | TOPLEVEL) >= XCHAL_DEBUGLEVEL 318c2ecf20Sopenharmony_ci unsigned long tmp; 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci asm volatile("rsr %0, ps\t\n" 348c2ecf20Sopenharmony_ci "extui %1, %0, 0, 4\t\n" 358c2ecf20Sopenharmony_ci "bgei %1, "__stringify(LOCKLEVEL)", 1f\t\n" 368c2ecf20Sopenharmony_ci "rsil %0, "__stringify(LOCKLEVEL)"\n" 378c2ecf20Sopenharmony_ci "1:" 388c2ecf20Sopenharmony_ci : "=a" (flags), "=a" (tmp) :: "memory"); 398c2ecf20Sopenharmony_ci#else 408c2ecf20Sopenharmony_ci asm volatile("rsr %0, ps\t\n" 418c2ecf20Sopenharmony_ci "or %0, %0, %1\t\n" 428c2ecf20Sopenharmony_ci "xsr %0, ps\t\n" 438c2ecf20Sopenharmony_ci "rsync" 448c2ecf20Sopenharmony_ci : "=&a" (flags) : "a" (LOCKLEVEL) : "memory"); 458c2ecf20Sopenharmony_ci#endif 468c2ecf20Sopenharmony_ci#else 478c2ecf20Sopenharmony_ci asm volatile("rsil %0, "__stringify(LOCKLEVEL) 488c2ecf20Sopenharmony_ci : "=a" (flags) :: "memory"); 498c2ecf20Sopenharmony_ci#endif 508c2ecf20Sopenharmony_ci return flags; 518c2ecf20Sopenharmony_ci} 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_cistatic inline void arch_local_irq_disable(void) 548c2ecf20Sopenharmony_ci{ 558c2ecf20Sopenharmony_ci arch_local_irq_save(); 568c2ecf20Sopenharmony_ci} 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_cistatic inline void arch_local_irq_enable(void) 598c2ecf20Sopenharmony_ci{ 608c2ecf20Sopenharmony_ci unsigned long flags; 618c2ecf20Sopenharmony_ci asm volatile("rsil %0, 0" : "=a" (flags) :: "memory"); 628c2ecf20Sopenharmony_ci} 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_cistatic inline void arch_local_irq_restore(unsigned long flags) 658c2ecf20Sopenharmony_ci{ 668c2ecf20Sopenharmony_ci asm volatile("wsr %0, ps; rsync" 678c2ecf20Sopenharmony_ci :: "a" (flags) : "memory"); 688c2ecf20Sopenharmony_ci} 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_cistatic inline bool arch_irqs_disabled_flags(unsigned long flags) 718c2ecf20Sopenharmony_ci{ 728c2ecf20Sopenharmony_ci#if XCHAL_EXCM_LEVEL < LOCKLEVEL || (1 << PS_EXCM_BIT) < LOCKLEVEL 738c2ecf20Sopenharmony_ci#error "XCHAL_EXCM_LEVEL and 1<<PS_EXCM_BIT must be no less than LOCKLEVEL" 748c2ecf20Sopenharmony_ci#endif 758c2ecf20Sopenharmony_ci return (flags & (PS_INTLEVEL_MASK | (1 << PS_EXCM_BIT))) >= LOCKLEVEL; 768c2ecf20Sopenharmony_ci} 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_cistatic inline bool arch_irqs_disabled(void) 798c2ecf20Sopenharmony_ci{ 808c2ecf20Sopenharmony_ci return arch_irqs_disabled_flags(arch_local_save_flags()); 818c2ecf20Sopenharmony_ci} 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci#endif /* _XTENSA_IRQFLAGS_H */ 84