Path: blob/main/sys/compat/linuxkpi/common/include/asm/unaligned.h
39604 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2020,2023 The FreeBSD Foundation4*5* This software was developed by Björn Zeeb under sponsorship from6* the FreeBSD Foundation.7*8* Redistribution and use in source and binary forms, with or without9* modification, are permitted provided that the following conditions10* are met:11* 1. Redistributions of source code must retain the above copyright12* notice, this list of conditions and the following disclaimer.13* 2. Redistributions in binary form must reproduce the above copyright14* notice, this list of conditions and the following disclaimer in the15* documentation and/or other materials provided with the distribution.16*17* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND18* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE19* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE20* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE21* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL22* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS23* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)24* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT25* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY26* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF27* SUCH DAMAGE.28*/2930#ifndef _LINUXKPI_ASM_UNALIGNED_H31#define _LINUXKPI_ASM_UNALIGNED_H3233#include <linux/types.h>34#include <asm/byteorder.h>3536static __inline uint16_t37get_unaligned_le16(const void *p)38{3940return (le16_to_cpup((const __le16 *)p));41}4243static __inline uint32_t44get_unaligned_le32(const void *p)45{4647return (le32_to_cpup((const __le32 *)p));48}4950static __inline void51put_unaligned_le16(__le16 v, void *p)52{53__le16 x;5455x = cpu_to_le16(v);56memcpy(p, &x, sizeof(x));57}5859static __inline void60put_unaligned_le32(__le32 v, void *p)61{62__le32 x;6364x = cpu_to_le32(v);65memcpy(p, &x, sizeof(x));66}6768static __inline void69put_unaligned_le64(__le64 v, void *p)70{71__le64 x;7273x = cpu_to_le64(v);74memcpy(p, &x, sizeof(x));75}7677static __inline uint16_t78get_unaligned_be16(const void *p)79{8081return (be16_to_cpup((const __be16 *)p));82}8384static __inline uint32_t85get_unaligned_be32(const void *p)86{8788return (be32_to_cpup((const __be32 *)p));89}9091static __inline uint64_t92get_unaligned_be64(const void *p)93{9495return (be64_to_cpup((const __be64 *)p));96}9798#endif /* _LINUXKPI_ASM_UNALIGNED_H */99100101