Setting up repository
[linux-libre-firmware.git] / ath9k_htc / sboot / magpie_1_1 / sboot / athos / src / xtos / intlevel-setmin.S
1 // intlevel-setmin.S - Interrupt related assembler code - _xtos_set_min_intlevel
2
3 // Copyright (c) 2004-2010 Tensilica Inc.
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining
6 // a copy of this software and associated documentation files (the
7 // "Software"), to deal in the Software without restriction, including
8 // without limitation the rights to use, copy, modify, merge, publish,
9 // distribute, sublicense, and/or sell copies of the Software, and to
10 // permit persons to whom the Software is furnished to do so, subject to
11 // the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included
14 // in all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
24 #include <xtensa/coreasm.h>
25 #include <xtensa/config/specreg.h>
26 #include "xtos-internal.h"
27
28
29 /***************************************************************************
30  *  unsigned  _xtos_set_min_intlevel(int intlevel);
31  *
32  *  _xtos_set_min_intlevel() is identical to _xtos_set_intlevel() except
33  *  that it will not lower the current interrupt level.  Instead,
34  *  it ensures that the current interrupt level is at least as high
35  *  as specified.
36  *
37  *  NOTE:  This version allows the 'intlevel' parameter to be computed
38  *  at run-time, and thus is longer.  It is much more efficient, and
39  *  highly recommented, to use the XTOS_SET_MIN_INTLEVEL(intlevel) macro instead
40  *  (which requires a constant intlevel).
41  */
42
43         .text
44         .align 4
45         .global _xtos_set_min_intlevel
46         .type   _xtos_set_min_intlevel,@function
47 _xtos_set_min_intlevel:
48         abi_entry
49 #if XCHAL_HAVE_INTERRUPTS
50 # if XCHAL_HAVE_XEA2
51         /*  In XEA2, we can simply safely set PS.INTLEVEL directly:  */
52         rsr     a3, PS          // get old (current) PS.INTLEVEL
53         movi    a4, ~0xF
54         extui   a2, a2, 0, 4    // keep only INTLEVEL bits of parameter
55         extui   a5, a3, 0, 4    // look at old PS.INTLEVEL
56         sub     a5, a2, a5      // new.intlevel - old.intlevel
57         and     a4, a4, a3      // mask out PS.INTLEVEL
58         or      a4, a4, a2      // insert requested INTLEVEL
59         movltz  a4, a3, a5      // keep same PS if already higher than requested
60         wsr     a4, PS          // update PS.INTLEVEL
61         extui   a2, a3, 0, 4    // return only old PS.INTLEVEL field
62         rsync                   // wait for WSR to PS to complete
63 # else
64         /*  In XEA1, we have to rely on INTENABLE register virtualization:  */
65         movi    a4, Xthal_intlevel_andbelow_mask
66         extui   a3, a2, 0, 4    // keep only INTLEVEL bits of parameter
67         addx4   a5, a3, a4      // index mask to use
68         l32i    a3, a5, 0       // get mask of interrupts at requested intlevel and below
69         movi    a5, -1          // all 1's
70         movi    a4, _xtos_intstruct
71         xor     a3, a3, a5      // mask of interrupts at intlevels above the requested one (to enable)
72         xtos_lock       a7      // MUST USE highest address register of function to avoid window overflows in critical section
73         l32i    a2, a4, XTOS_VPRI_ENABLED_OFS   // return old xtos_vpri_enabled (current vpri)
74         l32i    a5, a4, XTOS_ENABLED_OFS        // a5 = xtos_enabled
75         and     a3, a3, a2                      // make sure we don't enable any new interrupts
76         s32i    a3, a4, XTOS_VPRI_ENABLED_OFS   // set new xtos_vpri_enabled (current vpri)
77         and     a5, a5, a3                      // a5 = xtos_enabled & xtos_vpri_enabled
78         wsr     a5, INTENABLE
79         xtos_unlock     a7
80 # endif
81 #endif /*XCHAL_HAVE_INTERRUPTS*/
82         abi_return
83
84         .size   _xtos_set_min_intlevel, . - _xtos_set_min_intlevel
85