xref: /dragonfly/sys/dev/drm/include/asm/unaligned.h (revision dbb5897c)
1*dbb5897cSFrançois Tigeot /*	$NetBSD: unaligned.h,v 1.4 2016/02/06 00:31:58 riastradh Exp $	*/
2*dbb5897cSFrançois Tigeot 
3*dbb5897cSFrançois Tigeot /*-
4*dbb5897cSFrançois Tigeot  * Copyright (c) 2014 The NetBSD Foundation, Inc.
5*dbb5897cSFrançois Tigeot  * All rights reserved.
6*dbb5897cSFrançois Tigeot  *
7*dbb5897cSFrançois Tigeot  * This code is derived from software contributed to The NetBSD Foundation
8*dbb5897cSFrançois Tigeot  * by Taylor R. Campbell.
9*dbb5897cSFrançois Tigeot  *
10*dbb5897cSFrançois Tigeot  * Redistribution and use in source and binary forms, with or without
11*dbb5897cSFrançois Tigeot  * modification, are permitted provided that the following conditions
12*dbb5897cSFrançois Tigeot  * are met:
13*dbb5897cSFrançois Tigeot  * 1. Redistributions of source code must retain the above copyright
14*dbb5897cSFrançois Tigeot  *    notice, this list of conditions and the following disclaimer.
15*dbb5897cSFrançois Tigeot  * 2. Redistributions in binary form must reproduce the above copyright
16*dbb5897cSFrançois Tigeot  *    notice, this list of conditions and the following disclaimer in the
17*dbb5897cSFrançois Tigeot  *    documentation and/or other materials provided with the distribution.
18*dbb5897cSFrançois Tigeot  *
19*dbb5897cSFrançois Tigeot  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*dbb5897cSFrançois Tigeot  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*dbb5897cSFrançois Tigeot  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*dbb5897cSFrançois Tigeot  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*dbb5897cSFrançois Tigeot  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*dbb5897cSFrançois Tigeot  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*dbb5897cSFrançois Tigeot  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*dbb5897cSFrançois Tigeot  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*dbb5897cSFrançois Tigeot  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*dbb5897cSFrançois Tigeot  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*dbb5897cSFrançois Tigeot  * POSSIBILITY OF SUCH DAMAGE.
30*dbb5897cSFrançois Tigeot  */
31*dbb5897cSFrançois Tigeot 
32*dbb5897cSFrançois Tigeot #ifndef _ASM_UNALIGNED_H_
33*dbb5897cSFrançois Tigeot #define _ASM_UNALIGNED_H_
34*dbb5897cSFrançois Tigeot 
35*dbb5897cSFrançois Tigeot #include <sys/endian.h>
36*dbb5897cSFrançois Tigeot 
37*dbb5897cSFrançois Tigeot static inline uint16_t
get_unaligned_le16(const void * p)38*dbb5897cSFrançois Tigeot get_unaligned_le16(const void *p)
39*dbb5897cSFrançois Tigeot {
40*dbb5897cSFrançois Tigeot 
41*dbb5897cSFrançois Tigeot 	return le16dec(p);
42*dbb5897cSFrançois Tigeot }
43*dbb5897cSFrançois Tigeot 
44*dbb5897cSFrançois Tigeot static inline void
put_unaligned_le16(uint16_t v,void * p)45*dbb5897cSFrançois Tigeot put_unaligned_le16(uint16_t v, void *p)
46*dbb5897cSFrançois Tigeot {
47*dbb5897cSFrançois Tigeot 
48*dbb5897cSFrançois Tigeot 	le16enc(p, v);
49*dbb5897cSFrançois Tigeot }
50*dbb5897cSFrançois Tigeot 
51*dbb5897cSFrançois Tigeot static inline uint32_t
get_unaligned_le32(const void * p)52*dbb5897cSFrançois Tigeot get_unaligned_le32(const void *p)
53*dbb5897cSFrançois Tigeot {
54*dbb5897cSFrançois Tigeot 
55*dbb5897cSFrançois Tigeot 	return le32dec(p);
56*dbb5897cSFrançois Tigeot }
57*dbb5897cSFrançois Tigeot 
58*dbb5897cSFrançois Tigeot static inline void
put_unaligned_le32(uint32_t v,void * p)59*dbb5897cSFrançois Tigeot put_unaligned_le32(uint32_t v, void *p)
60*dbb5897cSFrançois Tigeot {
61*dbb5897cSFrançois Tigeot 
62*dbb5897cSFrançois Tigeot 	le32enc(p, v);
63*dbb5897cSFrançois Tigeot }
64*dbb5897cSFrançois Tigeot 
65*dbb5897cSFrançois Tigeot #endif  /* _ASM_UNALIGNED_H_ */
66