xref: /openbmc/u-boot/include/bootcount.h (revision ecd4551f)
1 /*
2  * (C) Copyright 2012
3  * Stefan Roese, DENX Software Engineering, sr@denx.de.
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  */
18 
19 #include <common.h>
20 #include <asm/io.h>
21 #include <asm/byteorder.h>
22 
23 #if !defined(CONFIG_SYS_BOOTCOUNT_LE) && !defined(CONFIG_SYS_BOOTCOUNT_BE)
24 # if __BYTE_ORDER == __LITTLE_ENDIAN
25 #  define CONFIG_SYS_BOOTCOUNT_LE
26 # else
27 #  define CONFIG_SYS_BOOTCOUNT_BE
28 # endif
29 #endif
30 
31 #ifdef CONFIG_SYS_BOOTCOUNT_LE
32 static inline void raw_bootcount_store(volatile u32 *addr, u32 data)
33 {
34 	out_le32(addr, data);
35 }
36 
37 static inline u32 raw_bootcount_load(volatile u32 *addr)
38 {
39 	return in_le32(addr);
40 }
41 #else
42 static inline void raw_bootcount_store(volatile u32 *addr, u32 data)
43 {
44 	out_be32(addr, data);
45 }
46 
47 static inline u32 raw_bootcount_load(volatile u32 *addr)
48 {
49 	return in_be32(addr);
50 }
51 #endif
52