blob: 4e31206436db824a0a62cdee2057211f764cfe65 [file] [log] [blame]
wdenk12490652004-04-18 21:13:41 +00001/*
2 * include/asm-microblaze/system.h -- Low-level interrupt/thread ops
3 *
4 * Copyright (C) 2003 John Williams (jwilliams@itee.uq.edu.au)
5 * based upon microblaze version
6 * Copyright (C) 2001 NEC Corporation
7 * Copyright (C) 2001 Miles Bader <miles@gnu.org>
8 *
9 * This file is subject to the terms and conditions of the GNU General
10 * Public License. See the file COPYING in the main directory of this
11 * archive for more details.
12 *
13 * Written by Miles Bader <miles@gnu.org>
14 * Microblaze port by John Williams
15 * Microblaze port by John Williams
16 */
17
18#ifndef __MICROBLAZE_SYSTEM_H__
19#define __MICROBLAZE_SYSTEM_H__
20
21#if 0
22#include <linux/linkage.h>
23#endif
24#include <asm/ptrace.h>
25
Michal Simekdba00ff2022-03-01 09:13:20 +010026#define MMU_SECTION_SIZE (1 * 1024 * 1024)
27
wdenk12490652004-04-18 21:13:41 +000028#define prepare_to_switch() do { } while (0)
29
30/*
31 * switch_to(n) should switch tasks to task ptr, first checking that
32 * ptr isn't the current task, in which case it does nothing.
33 */
34struct thread_struct;
35extern void *switch_thread (struct thread_struct *last,
36 struct thread_struct *next);
37#define switch_to(prev,next,last) do { \
38 if (prev != next) { \
39 (last) = switch_thread (&prev->thread, &next->thread); \
40 } \
41} while (0)
42
wdenk12490652004-04-18 21:13:41 +000043/* Enable/disable interrupts. */
44#define __sti() \
45{ \
46 register unsigned tmp; \
47 __asm__ __volatile__ (" \
48 mfs %0, rmsr; \
49 ori %0, %0, 2; \
50 mts rmsr, %0" \
51 : "=r" (tmp) \
52 : \
53 : "memory"); \
54}
55
56#define __cli() \
57{ \
58 register unsigned tmp; \
59 __asm__ __volatile__ (" \
60 mfs %0, rmsr; \
61 andi %0, %0, ~2; \
62 mts rmsr, %0" \
63 : "=r" (tmp) \
64 : \
65 : "memory"); \
66}
67
68#define __save_flags(flags) \
69 __asm__ __volatile__ ("mfs %0, rmsr" : "=r" (flags))
70#define __restore_flags(flags) \
71 __asm__ __volatile__ ("mts rmsr, %0" :: "r" (flags))
72
73#define __save_flags_cli(flags) \
74{ \
75 register unsigned tmp; \
76 __asm__ __volatile__ (" \
77 mfs %0, rmsr; \
78 andi %1, %0, ~2; \
79 mts rmsr, %1;" \
80 : "=r" (flags), "=r" (tmp) \
81 : \
82 : "memory"); \
83}
84
85#define __save_flags_sti(flags) \
86{ \
87 register unsigned tmp; \
88 __asm__ __volatile__ (" \
89 mfs %0, rmsr; \
90 ori %1, %0, 2; \
91 mts rmsr, %1;" \
92 : "=r" (flags) ,"=r" (tmp) \
93 : \
94 : "memory"); \
95}
96
97/* For spinlocks etc */
98#define local_irq_save(flags) __save_flags_cli (flags)
99#define local_irq_set(flags) __save_flags_sti (flags)
100#define local_irq_restore(flags) __restore_flags (flags)
101#define local_irq_disable() __cli ()
102#define local_irq_enable() __sti ()
103
104#define cli() __cli ()
105#define sti() __sti ()
106#define save_flags(flags) __save_flags (flags)
107#define restore_flags(flags) __restore_flags (flags)
108#define save_flags_cli(flags) __save_flags_cli (flags)
109
110/*
111 * Force strict CPU ordering.
112 * Not really required on microblaze...
113 */
114#define nop() __asm__ __volatile__ ("nop")
115#define mb() __asm__ __volatile__ ("nop" ::: "memory")
116#define rmb() mb ()
117#define wmb() mb ()
118#define set_mb(var, value) do { var = value; mb(); } while (0)
119#define set_wmb(var, value) do { var = value; wmb (); } while (0)
120
121#ifdef CONFIG_SMP
122#define smp_mb() mb ()
123#define smp_rmb() rmb ()
124#define smp_wmb() wmb ()
125#else
126#define smp_mb() barrier ()
127#define smp_rmb() barrier ()
128#define smp_wmb() barrier ()
129#endif
130
131#define xchg(ptr, with) \
132 ((__typeof__ (*(ptr)))__xchg ((unsigned long)(with), (ptr), sizeof (*(ptr))))
133#define tas(ptr) (xchg ((ptr), 1))
134
Nathan Rossi14c96dc2015-11-06 19:25:06 +1000135static inline unsigned long __xchg(unsigned long with,
wdenk12490652004-04-18 21:13:41 +0000136 __volatile__ void *ptr, int size)
137{
138 unsigned long tmp, flags;
139
140 save_flags_cli (flags);
141
142 switch (size) {
143 case 1:
144 tmp = *(unsigned char *)ptr;
145 *(unsigned char *)ptr = with;
146 break;
147 case 2:
148 tmp = *(unsigned short *)ptr;
149 *(unsigned short *)ptr = with;
150 break;
151 case 4:
152 tmp = *(unsigned long *)ptr;
153 *(unsigned long *)ptr = with;
154 break;
155 }
156
157 restore_flags (flags);
158
159 return tmp;
160}
161
162#endif /* __MICROBLAZE_SYSTEM_H__ */