cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

byteorder.h (1530B)


      1/* SPDX-License-Identifier: GPL-2.0 */
      2/*
      3 * Follows implementation found in linux/virtio_byteorder.h
      4 */
      5#ifndef _LINUX_RPMSG_BYTEORDER_H
      6#define _LINUX_RPMSG_BYTEORDER_H
      7#include <linux/types.h>
      8#include <uapi/linux/rpmsg_types.h>
      9
     10static inline bool rpmsg_is_little_endian(void)
     11{
     12#ifdef __LITTLE_ENDIAN
     13	return true;
     14#else
     15	return false;
     16#endif
     17}
     18
     19static inline u16 __rpmsg16_to_cpu(bool little_endian, __rpmsg16 val)
     20{
     21	if (little_endian)
     22		return le16_to_cpu((__force __le16)val);
     23	else
     24		return be16_to_cpu((__force __be16)val);
     25}
     26
     27static inline __rpmsg16 __cpu_to_rpmsg16(bool little_endian, u16 val)
     28{
     29	if (little_endian)
     30		return (__force __rpmsg16)cpu_to_le16(val);
     31	else
     32		return (__force __rpmsg16)cpu_to_be16(val);
     33}
     34
     35static inline u32 __rpmsg32_to_cpu(bool little_endian, __rpmsg32 val)
     36{
     37	if (little_endian)
     38		return le32_to_cpu((__force __le32)val);
     39	else
     40		return be32_to_cpu((__force __be32)val);
     41}
     42
     43static inline __rpmsg32 __cpu_to_rpmsg32(bool little_endian, u32 val)
     44{
     45	if (little_endian)
     46		return (__force __rpmsg32)cpu_to_le32(val);
     47	else
     48		return (__force __rpmsg32)cpu_to_be32(val);
     49}
     50
     51static inline u64 __rpmsg64_to_cpu(bool little_endian, __rpmsg64 val)
     52{
     53	if (little_endian)
     54		return le64_to_cpu((__force __le64)val);
     55	else
     56		return be64_to_cpu((__force __be64)val);
     57}
     58
     59static inline __rpmsg64 __cpu_to_rpmsg64(bool little_endian, u64 val)
     60{
     61	if (little_endian)
     62		return (__force __rpmsg64)cpu_to_le64(val);
     63	else
     64		return (__force __rpmsg64)cpu_to_be64(val);
     65}
     66
     67#endif /* _LINUX_RPMSG_BYTEORDER_H */