16a484265SFrançois Tigeot /*
254e9b9a4SFrançois Tigeot * Copyright (c) 2015-2020 François Tigeot <ftigeot@wolfpond.org>
36a484265SFrançois Tigeot * All rights reserved.
46a484265SFrançois Tigeot *
56a484265SFrançois Tigeot * Redistribution and use in source and binary forms, with or without
66a484265SFrançois Tigeot * modification, are permitted provided that the following conditions
76a484265SFrançois Tigeot * are met:
86a484265SFrançois Tigeot * 1. Redistributions of source code must retain the above copyright
96a484265SFrançois Tigeot * notice unmodified, this list of conditions, and the following
106a484265SFrançois Tigeot * disclaimer.
116a484265SFrançois Tigeot * 2. Redistributions in binary form must reproduce the above copyright
126a484265SFrançois Tigeot * notice, this list of conditions and the following disclaimer in the
136a484265SFrançois Tigeot * documentation and/or other materials provided with the distribution.
146a484265SFrançois Tigeot *
156a484265SFrançois Tigeot * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
166a484265SFrançois Tigeot * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
176a484265SFrançois Tigeot * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
186a484265SFrançois Tigeot * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
196a484265SFrançois Tigeot * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
206a484265SFrançois Tigeot * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
216a484265SFrançois Tigeot * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
226a484265SFrançois Tigeot * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
236a484265SFrançois Tigeot * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
246a484265SFrançois Tigeot * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
256a484265SFrançois Tigeot */
266a484265SFrançois Tigeot
276a484265SFrançois Tigeot #ifndef _LINUX_IRQFLAGS_H_
286a484265SFrançois Tigeot #define _LINUX_IRQFLAGS_H_
296a484265SFrançois Tigeot
302cecdd68SFrançois Tigeot #include <linux/typecheck.h>
312cecdd68SFrançois Tigeot
32a85cb24fSFrançois Tigeot static inline void
local_irq_disable(void)33a85cb24fSFrançois Tigeot local_irq_disable(void)
34a85cb24fSFrançois Tigeot {
35a85cb24fSFrançois Tigeot __asm __volatile("cli": : :"memory");
36a85cb24fSFrançois Tigeot }
37a85cb24fSFrançois Tigeot
38a85cb24fSFrançois Tigeot static inline void
local_irq_enable(void)39a85cb24fSFrançois Tigeot local_irq_enable(void)
40a85cb24fSFrançois Tigeot {
41a85cb24fSFrançois Tigeot __asm __volatile("sti": : :"memory");
42a85cb24fSFrançois Tigeot }
43056b029cSFrançois Tigeot
44056b029cSFrançois Tigeot static inline bool
irqs_disabled(void)45056b029cSFrançois Tigeot irqs_disabled(void)
46056b029cSFrançois Tigeot {
4754e9b9a4SFrançois Tigeot return !(read_rflags() & 0x200UL);
48056b029cSFrançois Tigeot }
49056b029cSFrançois Tigeot
50*3f2dd94aSFrançois Tigeot #define local_irq_save(flags) \
51*3f2dd94aSFrançois Tigeot ({ \
52*3f2dd94aSFrançois Tigeot flags = read_rflags(); \
53*3f2dd94aSFrançois Tigeot local_irq_disable(); \
54*3f2dd94aSFrançois Tigeot })
55*3f2dd94aSFrançois Tigeot
56*3f2dd94aSFrançois Tigeot static inline void
local_irq_restore(unsigned long flags)57*3f2dd94aSFrançois Tigeot local_irq_restore(unsigned long flags)
58*3f2dd94aSFrançois Tigeot {
59*3f2dd94aSFrançois Tigeot write_rflags(flags);
60*3f2dd94aSFrançois Tigeot }
61*3f2dd94aSFrançois Tigeot
626a484265SFrançois Tigeot #endif /* _LINUX_IRQFLAGS_H_ */
63