blob: f0c4ae2609410986d07f8fed35b4e74106a2740c [file] [log] [blame]
Wolfgang Denk97caf672006-03-12 02:12:27 +01001/*
Bin Meng75574052016-02-05 19:30:11 -08002 * U-Boot - system.h
Wolfgang Denk97caf672006-03-12 02:12:27 +01003 *
Aubrey Li314d22f2007-04-05 18:31:18 +08004 * Copyright (c) 2005-2007 Analog Devices Inc.
Wolfgang Denk97caf672006-03-12 02:12:27 +01005 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Wolfgang Denk97caf672006-03-12 02:12:27 +01007 */
8
9#ifndef _BLACKFIN_SYSTEM_H
10#define _BLACKFIN_SYSTEM_H
11
Wolfgang Denk97caf672006-03-12 02:12:27 +010012/*
13 * Interrupt configuring macros.
14 */
15
16extern int irq_flags;
17
Mike Frysinger66c4cf42008-02-04 19:26:55 -050018#define local_irq_enable() \
19 __asm__ __volatile__ ( \
20 "sti %0;" \
21 : \
22 : "d" (irq_flags) \
23 )
Wolfgang Denk97caf672006-03-12 02:12:27 +010024
Mike Frysinger66c4cf42008-02-04 19:26:55 -050025#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 Denk97caf672006-03-12 02:12:27 +010033
Mike Frysinger66c4cf42008-02-04 19:26:55 -050034# define local_irq_save(x) \
35 __asm__ __volatile__ ( \
36 "cli %0;" \
37 : "=&d" (x) \
38 )
Wolfgang Denk97caf672006-03-12 02:12:27 +010039
Mike Frysinger66c4cf42008-02-04 19:26:55 -050040#define local_save_flags(x) \
41 __asm__ __volatile__ ( \
42 "cli %0;" \
43 "sti %0;" \
44 : "=d" (x) \
45 )
Wolfgang Denk97caf672006-03-12 02:12:27 +010046
Mike Frysinger66c4cf42008-02-04 19:26:55 -050047#define irqs_enabled_from_flags(x) ((x) != 0x1f)
Wolfgang Denk97caf672006-03-12 02:12:27 +010048
Mike Frysinger66c4cf42008-02-04 19:26:55 -050049#define local_irq_restore(x) \
50 do { \
51 if (irqs_enabled_from_flags(x)) \
52 local_irq_enable(); \
53 } while (0)
Wolfgang Denk97caf672006-03-12 02:12:27 +010054
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 Frysinger66c4cf42008-02-04 19:26:55 -050066#define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
Wolfgang Denk97caf672006-03-12 02:12:27 +010067
68struct __xchg_dummy {
69 unsigned long a[100];
70};
Mike Frysinger66c4cf42008-02-04 19:26:55 -050071#define __xg(x) ((volatile struct __xchg_dummy *)(x))
Wolfgang Denk97caf672006-03-12 02:12:27 +010072
73static inline unsigned long __xchg(unsigned long x, volatile void *ptr,
74 int size)
75{
Mike Frysinger66c4cf42008-02-04 19:26:55 -050076 unsigned long tmp = 0;
Wolfgang Denk97caf672006-03-12 02:12:27 +010077 unsigned long flags = 0;
78
Mike Frysinger66c4cf42008-02-04 19:26:55 -050079 local_irq_save(flags);
Wolfgang Denk97caf672006-03-12 02:12:27 +010080
81 switch (size) {
82 case 1:
Mike Frysinger66c4cf42008-02-04 19:26:55 -050083 __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 Denk97caf672006-03-12 02:12:27 +010087 break;
88 case 2:
Mike Frysinger66c4cf42008-02-04 19:26:55 -050089 __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 Denk97caf672006-03-12 02:12:27 +010093 break;
94 case 4:
Mike Frysinger66c4cf42008-02-04 19:26:55 -050095 __asm__ __volatile__
96 ("%0 = %2;\n\t"
97 "%2 = %1;\n\t"
98 : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
Wolfgang Denk97caf672006-03-12 02:12:27 +010099 break;
100 }
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500101 local_irq_restore(flags);
Wolfgang Denk97caf672006-03-12 02:12:27 +0100102 return tmp;
103}
104
Mike Frysinger83ebf372010-06-02 04:17:26 -0400105void bfin_reset_boot_spi_cs(unsigned short pin);
106
Wolfgang Denk97caf672006-03-12 02:12:27 +0100107#endif /* _BLACKFIN_SYSTEM_H */