blob: 952438e81cb215697ee2bf22a668b210d4164ccc [file] [log] [blame]
Wolfgang Denk6cb142f2006-03-12 02:12:27 +01001/*
2 * U-boot - system.h
3 *
Aubrey Li155fd762007-04-05 18:31:18 +08004 * Copyright (c) 2005-2007 Analog Devices Inc.
Wolfgang Denk6cb142f2006-03-12 02:12:27 +01005 *
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 Li155fd762007-04-05 18:31:18 +080021 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
22 * MA 02110-1301 USA
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010023 */
24
25#ifndef _BLACKFIN_SYSTEM_H
26#define _BLACKFIN_SYSTEM_H
27
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010028/*
29 * Interrupt configuring macros.
30 */
31
32extern int irq_flags;
33
Mike Frysingerd4d77302008-02-04 19:26:55 -050034#define local_irq_enable() \
35 __asm__ __volatile__ ( \
36 "sti %0;" \
37 : \
38 : "d" (irq_flags) \
39 )
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010040
Mike Frysingerd4d77302008-02-04 19:26:55 -050041#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 Denk6cb142f2006-03-12 02:12:27 +010049
Mike Frysingerd4d77302008-02-04 19:26:55 -050050# define local_irq_save(x) \
51 __asm__ __volatile__ ( \
52 "cli %0;" \
53 : "=&d" (x) \
54 )
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010055
Mike Frysingerd4d77302008-02-04 19:26:55 -050056#define local_save_flags(x) \
57 __asm__ __volatile__ ( \
58 "cli %0;" \
59 "sti %0;" \
60 : "=d" (x) \
61 )
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010062
Mike Frysingerd4d77302008-02-04 19:26:55 -050063#define irqs_enabled_from_flags(x) ((x) != 0x1f)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010064
Mike Frysingerd4d77302008-02-04 19:26:55 -050065#define local_irq_restore(x) \
66 do { \
67 if (irqs_enabled_from_flags(x)) \
68 local_irq_enable(); \
69 } while (0)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010070
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 Frysingerd4d77302008-02-04 19:26:55 -050082#define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010083
84struct __xchg_dummy {
85 unsigned long a[100];
86};
Mike Frysingerd4d77302008-02-04 19:26:55 -050087#define __xg(x) ((volatile struct __xchg_dummy *)(x))
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010088
89static inline unsigned long __xchg(unsigned long x, volatile void *ptr,
90 int size)
91{
Mike Frysingerd4d77302008-02-04 19:26:55 -050092 unsigned long tmp = 0;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010093 unsigned long flags = 0;
94
Mike Frysingerd4d77302008-02-04 19:26:55 -050095 local_irq_save(flags);
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010096
97 switch (size) {
98 case 1:
Mike Frysingerd4d77302008-02-04 19:26:55 -050099 __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 Denk6cb142f2006-03-12 02:12:27 +0100103 break;
104 case 2:
Mike Frysingerd4d77302008-02-04 19:26:55 -0500105 __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 Denk6cb142f2006-03-12 02:12:27 +0100109 break;
110 case 4:
Mike Frysingerd4d77302008-02-04 19:26:55 -0500111 __asm__ __volatile__
112 ("%0 = %2;\n\t"
113 "%2 = %1;\n\t"
114 : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100115 break;
116 }
Mike Frysingerd4d77302008-02-04 19:26:55 -0500117 local_irq_restore(flags);
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100118 return tmp;
119}
120
Mike Frysinger4638b212010-06-02 04:17:26 -0400121void bfin_reset_boot_spi_cs(unsigned short pin);
122
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100123#endif /* _BLACKFIN_SYSTEM_H */