Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2004-2007 Freescale Semiconductor, Inc. |
| 4 | * TsiChung Liew (Tsi-Chung.Liew@freescale.com) |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 5 | */ |
| 6 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 7 | #ifndef _M68K_BYTEORDER_H |
| 8 | #define _M68K_BYTEORDER_H |
| 9 | |
| 10 | #include <asm/types.h> |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 11 | |
| 12 | #ifdef __GNUC__ |
Angelo Dureghello | 030bb6e | 2018-08-04 23:02:56 +0200 | [diff] [blame] | 13 | |
| 14 | static inline __u32 __sw32(__u32 x) |
| 15 | { |
| 16 | __u32 v = x; |
| 17 | |
| 18 | return v << 24 | |
| 19 | (v & (__u32)0x0000ff00UL) << 8 | |
| 20 | (v & (__u32)0x00ff0000UL) >> 8 | |
| 21 | v >> 24; |
| 22 | } |
| 23 | |
| 24 | static inline __u16 __sw16(__u16 x) |
| 25 | { |
| 26 | __u16 v = x; |
| 27 | |
| 28 | return (v & (__u16)0x00ffU) << 8 | |
| 29 | (v & (__u16)0xff00U) >> 8; |
| 30 | } |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 31 | |
Måns Rullgård | 4dc3970 | 2015-11-06 12:44:01 +0000 | [diff] [blame] | 32 | static __inline__ unsigned ld_le16(const volatile unsigned short *addr) |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 33 | { |
Angelo Dureghello | 030bb6e | 2018-08-04 23:02:56 +0200 | [diff] [blame] | 34 | return __sw16(*addr); |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 35 | } |
| 36 | |
Måns Rullgård | 4dc3970 | 2015-11-06 12:44:01 +0000 | [diff] [blame] | 37 | static __inline__ void st_le16(volatile unsigned short *addr, |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 38 | const unsigned val) |
| 39 | { |
| 40 | *addr = __sw16(val); |
| 41 | } |
| 42 | |
Måns Rullgård | 4dc3970 | 2015-11-06 12:44:01 +0000 | [diff] [blame] | 43 | static __inline__ unsigned ld_le32(const volatile unsigned *addr) |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 44 | { |
Angelo Dureghello | 030bb6e | 2018-08-04 23:02:56 +0200 | [diff] [blame] | 45 | return __sw32(*addr); |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 46 | } |
| 47 | |
Måns Rullgård | 4dc3970 | 2015-11-06 12:44:01 +0000 | [diff] [blame] | 48 | static __inline__ void st_le32(volatile unsigned *addr, const unsigned val) |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 49 | { |
| 50 | *addr = __sw32(val); |
| 51 | } |
| 52 | |
| 53 | #if 0 |
| 54 | /* alas, egcs sounds like it has a bug in this code that doesn't use the |
| 55 | inline asm correctly, and can cause file corruption. Until I hear that |
| 56 | it's fixed, I can live without the extra speed. I hope. */ |
| 57 | #if !(__GNUC__ >= 2 && __GNUC_MINOR__ >= 90) |
| 58 | #if 0 |
| 59 | # define __arch_swab16(x) ld_le16(&x) |
| 60 | # define __arch_swab32(x) ld_le32(&x) |
| 61 | #else |
| 62 | static __inline__ __attribute__ ((const)) |
| 63 | __u16 ___arch__swab16(__u16 value) |
| 64 | { |
| 65 | return __sw16(value); |
| 66 | } |
| 67 | |
| 68 | static __inline__ __attribute__ ((const)) |
| 69 | __u32 ___arch__swab32(__u32 value) |
| 70 | { |
| 71 | return __sw32(value); |
| 72 | } |
| 73 | |
| 74 | #define __arch__swab32(x) ___arch__swab32(x) |
| 75 | #define __arch__swab16(x) ___arch__swab16(x) |
| 76 | #endif /* 0 */ |
| 77 | |
| 78 | #endif |
| 79 | |
| 80 | /* The same, but returns converted value from the location pointer by addr. */ |
| 81 | #define __arch__swab16p(addr) ld_le16(addr) |
| 82 | #define __arch__swab32p(addr) ld_le32(addr) |
| 83 | |
| 84 | /* The same, but do the conversion in situ, ie. put the value back to addr. */ |
| 85 | #define __arch__swab16s(addr) st_le16(addr,*addr) |
| 86 | #define __arch__swab32s(addr) st_le32(addr,*addr) |
| 87 | #endif |
| 88 | |
| 89 | #endif /* __GNUC__ */ |
| 90 | |
| 91 | #if defined(__GNUC__) && !defined(__STRICT_ANSI__) |
| 92 | #define __BYTEORDER_HAS_U64__ |
| 93 | #endif |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 94 | #include <linux/byteorder/big_endian.h> |
| 95 | |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 96 | #endif /* _M68K_BYTEORDER_H */ |