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 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef _BLACKFIN_SYSTEM_H |
| 10 | #define _BLACKFIN_SYSTEM_H |
| 11 | |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 12 | /* |
| 13 | * Interrupt configuring macros. |
| 14 | */ |
| 15 | |
| 16 | extern int irq_flags; |
| 17 | |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 18 | #define local_irq_enable() \ |
| 19 | __asm__ __volatile__ ( \ |
| 20 | "sti %0;" \ |
| 21 | : \ |
| 22 | : "d" (irq_flags) \ |
| 23 | ) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 24 | |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 25 | #define local_irq_disable() \ |
| 26 | do { \ |
| 27 | int __tmp_dummy; \ |
| 28 | __asm__ __volatile__ ( \ |
| 29 | "cli %0;" \ |
| 30 | : "=d" (__tmp_dummy) \ |
| 31 | ); \ |
| 32 | } while (0) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 33 | |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 34 | # define local_irq_save(x) \ |
| 35 | __asm__ __volatile__ ( \ |
| 36 | "cli %0;" \ |
| 37 | : "=&d" (x) \ |
| 38 | ) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 39 | |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 40 | #define local_save_flags(x) \ |
| 41 | __asm__ __volatile__ ( \ |
| 42 | "cli %0;" \ |
| 43 | "sti %0;" \ |
| 44 | : "=d" (x) \ |
| 45 | ) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 46 | |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 47 | #define irqs_enabled_from_flags(x) ((x) != 0x1f) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 48 | |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 49 | #define local_irq_restore(x) \ |
| 50 | do { \ |
| 51 | if (irqs_enabled_from_flags(x)) \ |
| 52 | local_irq_enable(); \ |
| 53 | } while (0) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 54 | |
| 55 | /* |
| 56 | * Force strict CPU ordering. |
| 57 | */ |
| 58 | #define nop() asm volatile ("nop;\n\t"::) |
| 59 | #define mb() asm volatile ("" : : :"memory") |
| 60 | #define rmb() asm volatile ("" : : :"memory") |
| 61 | #define wmb() asm volatile ("" : : :"memory") |
| 62 | #define set_rmb(var, value) do { xchg(&var, value); } while (0) |
| 63 | #define set_mb(var, value) set_rmb(var, value) |
| 64 | #define set_wmb(var, value) do { var = value; wmb(); } while (0) |
| 65 | |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 66 | #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] | 67 | |
| 68 | struct __xchg_dummy { |
| 69 | unsigned long a[100]; |
| 70 | }; |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 71 | #define __xg(x) ((volatile struct __xchg_dummy *)(x)) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 72 | |
| 73 | static inline unsigned long __xchg(unsigned long x, volatile void *ptr, |
| 74 | int size) |
| 75 | { |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 76 | unsigned long tmp = 0; |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 77 | unsigned long flags = 0; |
| 78 | |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 79 | local_irq_save(flags); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 80 | |
| 81 | switch (size) { |
| 82 | case 1: |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 83 | __asm__ __volatile__ |
| 84 | ("%0 = b%2 (z);\n\t" |
| 85 | "b%2 = %1;\n\t" |
| 86 | : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory"); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 87 | break; |
| 88 | case 2: |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 89 | __asm__ __volatile__ |
| 90 | ("%0 = w%2 (z);\n\t" |
| 91 | "w%2 = %1;\n\t" |
| 92 | : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory"); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 93 | break; |
| 94 | case 4: |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 95 | __asm__ __volatile__ |
| 96 | ("%0 = %2;\n\t" |
| 97 | "%2 = %1;\n\t" |
| 98 | : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory"); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 99 | break; |
| 100 | } |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 101 | local_irq_restore(flags); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 102 | return tmp; |
| 103 | } |
| 104 | |
Mike Frysinger | 4638b21 | 2010-06-02 04:17:26 -0400 | [diff] [blame] | 105 | void bfin_reset_boot_spi_cs(unsigned short pin); |
| 106 | |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 107 | #endif /* _BLACKFIN_SYSTEM_H */ |