Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 1 | /* |
| 2 | * U-boot - system.h |
| 3 | * |
Aubrey Li | 155fd76 | 2007-04-05 18:31:18 +0800 | [diff] [blame] | 4 | * Copyright (c) 2005-2007 Analog Devices Inc. |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 5 | * |
| 6 | * See file CREDITS for list of people who contributed to this |
| 7 | * project. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of |
| 12 | * the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
Aubrey Li | 155fd76 | 2007-04-05 18:31:18 +0800 | [diff] [blame] | 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
| 22 | * MA 02110-1301 USA |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 23 | */ |
| 24 | |
| 25 | #ifndef _BLACKFIN_SYSTEM_H |
| 26 | #define _BLACKFIN_SYSTEM_H |
| 27 | |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 28 | /* |
| 29 | * Interrupt configuring macros. |
| 30 | */ |
| 31 | |
| 32 | extern int irq_flags; |
| 33 | |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 34 | #define local_irq_enable() \ |
| 35 | __asm__ __volatile__ ( \ |
| 36 | "sti %0;" \ |
| 37 | : \ |
| 38 | : "d" (irq_flags) \ |
| 39 | ) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 40 | |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 41 | #define local_irq_disable() \ |
| 42 | do { \ |
| 43 | int __tmp_dummy; \ |
| 44 | __asm__ __volatile__ ( \ |
| 45 | "cli %0;" \ |
| 46 | : "=d" (__tmp_dummy) \ |
| 47 | ); \ |
| 48 | } while (0) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 49 | |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 50 | # define local_irq_save(x) \ |
| 51 | __asm__ __volatile__ ( \ |
| 52 | "cli %0;" \ |
| 53 | : "=&d" (x) \ |
| 54 | ) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 55 | |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 56 | #define local_save_flags(x) \ |
| 57 | __asm__ __volatile__ ( \ |
| 58 | "cli %0;" \ |
| 59 | "sti %0;" \ |
| 60 | : "=d" (x) \ |
| 61 | ) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 62 | |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 63 | #define irqs_enabled_from_flags(x) ((x) != 0x1f) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 64 | |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 65 | #define local_irq_restore(x) \ |
| 66 | do { \ |
| 67 | if (irqs_enabled_from_flags(x)) \ |
| 68 | local_irq_enable(); \ |
| 69 | } while (0) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 70 | |
| 71 | /* |
| 72 | * Force strict CPU ordering. |
| 73 | */ |
| 74 | #define nop() asm volatile ("nop;\n\t"::) |
| 75 | #define mb() asm volatile ("" : : :"memory") |
| 76 | #define rmb() asm volatile ("" : : :"memory") |
| 77 | #define wmb() asm volatile ("" : : :"memory") |
| 78 | #define set_rmb(var, value) do { xchg(&var, value); } while (0) |
| 79 | #define set_mb(var, value) set_rmb(var, value) |
| 80 | #define set_wmb(var, value) do { var = value; wmb(); } while (0) |
| 81 | |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 82 | #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr)))) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 83 | |
| 84 | struct __xchg_dummy { |
| 85 | unsigned long a[100]; |
| 86 | }; |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 87 | #define __xg(x) ((volatile struct __xchg_dummy *)(x)) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 88 | |
| 89 | static inline unsigned long __xchg(unsigned long x, volatile void *ptr, |
| 90 | int size) |
| 91 | { |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 92 | unsigned long tmp = 0; |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 93 | unsigned long flags = 0; |
| 94 | |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 95 | local_irq_save(flags); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 96 | |
| 97 | switch (size) { |
| 98 | case 1: |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 99 | __asm__ __volatile__ |
| 100 | ("%0 = b%2 (z);\n\t" |
| 101 | "b%2 = %1;\n\t" |
| 102 | : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory"); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 103 | break; |
| 104 | case 2: |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 105 | __asm__ __volatile__ |
| 106 | ("%0 = w%2 (z);\n\t" |
| 107 | "w%2 = %1;\n\t" |
| 108 | : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory"); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 109 | break; |
| 110 | case 4: |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 111 | __asm__ __volatile__ |
| 112 | ("%0 = %2;\n\t" |
| 113 | "%2 = %1;\n\t" |
| 114 | : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory"); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 115 | break; |
| 116 | } |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 117 | local_irq_restore(flags); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 118 | return tmp; |
| 119 | } |
| 120 | |
Mike Frysinger | 4638b21 | 2010-06-02 04:17:26 -0400 | [diff] [blame] | 121 | void bfin_reset_boot_spi_cs(unsigned short pin); |
| 122 | |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 123 | #endif /* _BLACKFIN_SYSTEM_H */ |