wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 1 | /* |
| 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 Simek | dba00ff | 2022-03-01 09:13:20 +0100 | [diff] [blame] | 26 | #define MMU_SECTION_SIZE (1 * 1024 * 1024) |
| 27 | |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 28 | #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 | */ |
| 34 | struct thread_struct; |
| 35 | extern 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 | |
| 43 | |
| 44 | /* Enable/disable interrupts. */ |
| 45 | #define __sti() \ |
| 46 | { \ |
| 47 | register unsigned tmp; \ |
| 48 | __asm__ __volatile__ (" \ |
| 49 | mfs %0, rmsr; \ |
| 50 | ori %0, %0, 2; \ |
| 51 | mts rmsr, %0" \ |
| 52 | : "=r" (tmp) \ |
| 53 | : \ |
| 54 | : "memory"); \ |
| 55 | } |
| 56 | |
| 57 | #define __cli() \ |
| 58 | { \ |
| 59 | register unsigned tmp; \ |
| 60 | __asm__ __volatile__ (" \ |
| 61 | mfs %0, rmsr; \ |
| 62 | andi %0, %0, ~2; \ |
| 63 | mts rmsr, %0" \ |
| 64 | : "=r" (tmp) \ |
| 65 | : \ |
| 66 | : "memory"); \ |
| 67 | } |
| 68 | |
| 69 | #define __save_flags(flags) \ |
| 70 | __asm__ __volatile__ ("mfs %0, rmsr" : "=r" (flags)) |
| 71 | #define __restore_flags(flags) \ |
| 72 | __asm__ __volatile__ ("mts rmsr, %0" :: "r" (flags)) |
| 73 | |
| 74 | #define __save_flags_cli(flags) \ |
| 75 | { \ |
| 76 | register unsigned tmp; \ |
| 77 | __asm__ __volatile__ (" \ |
| 78 | mfs %0, rmsr; \ |
| 79 | andi %1, %0, ~2; \ |
| 80 | mts rmsr, %1;" \ |
| 81 | : "=r" (flags), "=r" (tmp) \ |
| 82 | : \ |
| 83 | : "memory"); \ |
| 84 | } |
| 85 | |
| 86 | #define __save_flags_sti(flags) \ |
| 87 | { \ |
| 88 | register unsigned tmp; \ |
| 89 | __asm__ __volatile__ (" \ |
| 90 | mfs %0, rmsr; \ |
| 91 | ori %1, %0, 2; \ |
| 92 | mts rmsr, %1;" \ |
| 93 | : "=r" (flags) ,"=r" (tmp) \ |
| 94 | : \ |
| 95 | : "memory"); \ |
| 96 | } |
| 97 | |
| 98 | /* For spinlocks etc */ |
| 99 | #define local_irq_save(flags) __save_flags_cli (flags) |
| 100 | #define local_irq_set(flags) __save_flags_sti (flags) |
| 101 | #define local_irq_restore(flags) __restore_flags (flags) |
| 102 | #define local_irq_disable() __cli () |
| 103 | #define local_irq_enable() __sti () |
| 104 | |
| 105 | #define cli() __cli () |
| 106 | #define sti() __sti () |
| 107 | #define save_flags(flags) __save_flags (flags) |
| 108 | #define restore_flags(flags) __restore_flags (flags) |
| 109 | #define save_flags_cli(flags) __save_flags_cli (flags) |
| 110 | |
| 111 | /* |
| 112 | * Force strict CPU ordering. |
| 113 | * Not really required on microblaze... |
| 114 | */ |
| 115 | #define nop() __asm__ __volatile__ ("nop") |
| 116 | #define mb() __asm__ __volatile__ ("nop" ::: "memory") |
| 117 | #define rmb() mb () |
| 118 | #define wmb() mb () |
| 119 | #define set_mb(var, value) do { var = value; mb(); } while (0) |
| 120 | #define set_wmb(var, value) do { var = value; wmb (); } while (0) |
| 121 | |
| 122 | #ifdef CONFIG_SMP |
| 123 | #define smp_mb() mb () |
| 124 | #define smp_rmb() rmb () |
| 125 | #define smp_wmb() wmb () |
| 126 | #else |
| 127 | #define smp_mb() barrier () |
| 128 | #define smp_rmb() barrier () |
| 129 | #define smp_wmb() barrier () |
| 130 | #endif |
| 131 | |
| 132 | #define xchg(ptr, with) \ |
| 133 | ((__typeof__ (*(ptr)))__xchg ((unsigned long)(with), (ptr), sizeof (*(ptr)))) |
| 134 | #define tas(ptr) (xchg ((ptr), 1)) |
| 135 | |
Nathan Rossi | 14c96dc | 2015-11-06 19:25:06 +1000 | [diff] [blame] | 136 | static inline unsigned long __xchg(unsigned long with, |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 137 | __volatile__ void *ptr, int size) |
| 138 | { |
| 139 | unsigned long tmp, flags; |
| 140 | |
| 141 | save_flags_cli (flags); |
| 142 | |
| 143 | switch (size) { |
| 144 | case 1: |
| 145 | tmp = *(unsigned char *)ptr; |
| 146 | *(unsigned char *)ptr = with; |
| 147 | break; |
| 148 | case 2: |
| 149 | tmp = *(unsigned short *)ptr; |
| 150 | *(unsigned short *)ptr = with; |
| 151 | break; |
| 152 | case 4: |
| 153 | tmp = *(unsigned long *)ptr; |
| 154 | *(unsigned long *)ptr = with; |
| 155 | break; |
| 156 | } |
| 157 | |
| 158 | restore_flags (flags); |
| 159 | |
| 160 | return tmp; |
| 161 | } |
| 162 | |
| 163 | #endif /* __MICROBLAZE_SYSTEM_H__ */ |