blob: f213115d2c0b9e7611e23efeab835cb7f1c67c54 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
2 * Copyright (c) 2014 The Linux Foundation. All rights reserved.
3 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28#if !defined( __CDS_PACK_ALIGN_H )
29#define __CDS_PACK_ALIGN_H
30
31/**=========================================================================
32
33 \file cds_pack_align.h
34
35 \brief Connectivity driver services (CDS) pack and align primitives
36
37 Definitions for platform independent means of packing and aligning
38 data structures
39
40 ========================================================================*/
41
42/*
43
44 Place the macro CDS_PACK_START above a structure declaration to pack. We
45 are not going to allow modifying the pack size because pack size cannot be
46 specified in AMSS and GNU. Place the macro CDS_PACK_END below a structure
47 declaration to stop the pack. This requirement is necessitated by Windows
48 which need pragma based prolog and epilog.
49
50 Pack-size > 1-byte is not supported since gcc and arm do not support that.
51
52 Here are some examples
53
54 1. Pack-size 1-byte foo_t across all platforms
55
56 CDS_PACK_START
57 typedef CDS_PACK_PRE struct foo_s { ... } CDS_PACK_POST foo_t;
58 CDS_PACK_END
59
60 2. 2-byte alignment for foo_t across all platforms
61
62 typedef CDS_ALIGN_PRE(2) struct foo_s { ... } CDS_ALIGN_POST(2) foo_t;
63
64 3. Pack-size 1-byte and 2-byte alignment for foo_t across all platforms
65
66 CDS_PACK_START
67 typedef CDS_PACK_PRE CDS_ALIGN_PRE(2) struct foo_s { ... } CDS_ALIGN_POST(2) CDS_PACK_POST foo_t;
68 CDS_PACK_END
69
70 */
71
72#if defined __GNUC__
73
74#define CDS_PACK_START
75#define CDS_PACK_END
76
77#define CDS_PACK_PRE
78#define CDS_PACK_POST __attribute__((__packed__))
79
80#define CDS_ALIGN_PRE(__value)
81#define CDS_ALIGN_POST(__value) __attribute__((__aligned__(__value)))
82
83#elif defined __arm
84
85#define CDS_PACK_START
86#define CDS_PACK_END
87
88#define CDS_PACK_PRE __packed
89#define CDS_PACK_POST
90
91#define CDS_ALIGN_PRE(__value) __align(__value)
92#define CDS_ALIGN_POST(__value)
93
94#elif defined _MSC_VER
95
96#define CDS_PACK_START __pragma(pack(push,1))
97#define CDS_PACK_END __pragma(pack(pop))
98
99#define CDS_PACK_PRE
100#define CDS_PACK_POST
101
102#define CDS_ALIGN_PRE(__value) __declspec(align(__value))
103#define CDS_ALIGN_POST(__value)
104
105#else
106
107#error Unsupported compiler!!!
108
109#endif
110
111#endif /* __CDS_PACK_ALIGN_H */