1 /*
2  * Copyright (C) 2006-2017 Oracle Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef __HGSMI_DEFS_H__
24 #define __HGSMI_DEFS_H__
25 
26 /* Buffer sequence type mask. */
27 #define HGSMI_BUFFER_HEADER_F_SEQ_MASK     0x03
28 /* Single buffer, not a part of a sequence. */
29 #define HGSMI_BUFFER_HEADER_F_SEQ_SINGLE   0x00
30 /* The first buffer in a sequence. */
31 #define HGSMI_BUFFER_HEADER_F_SEQ_START    0x01
32 /* A middle buffer in a sequence. */
33 #define HGSMI_BUFFER_HEADER_F_SEQ_CONTINUE 0x02
34 /* The last buffer in a sequence. */
35 #define HGSMI_BUFFER_HEADER_F_SEQ_END      0x03
36 
37 /* 16 bytes buffer header. */
38 struct hgsmi_buffer_header {
39 	u32 data_size;		/* Size of data that follows the header. */
40 	u8 flags;		/* HGSMI_BUFFER_HEADER_F_* */
41 	u8 channel;		/* The channel the data must be routed to. */
42 	u16 channel_info;	/* Opaque to the HGSMI, used by the channel. */
43 
44 	union {
45 		/* Opaque placeholder to make the union 8 bytes. */
46 		u8 header_data[8];
47 
48 		/* HGSMI_BUFFER_HEADER_F_SEQ_SINGLE */
49 		struct {
50 			u32 reserved1;	/* A reserved field, initialize to 0. */
51 			u32 reserved2;	/* A reserved field, initialize to 0. */
52 		} buffer;
53 
54 		/* HGSMI_BUFFER_HEADER_F_SEQ_START */
55 		struct {
56 			/* Must be the same for all buffers in the sequence. */
57 			u32 sequence_number;
58 			/* The total size of the sequence. */
59 			u32 sequence_size;
60 		} sequence_start;
61 
62 		/*
63 		 * HGSMI_BUFFER_HEADER_F_SEQ_CONTINUE and
64 		 * HGSMI_BUFFER_HEADER_F_SEQ_END
65 		 */
66 		struct {
67 			/* Must be the same for all buffers in the sequence. */
68 			u32 sequence_number;
69 			/* Data offset in the entire sequence. */
70 			u32 sequence_offset;
71 		} sequence_continue;
72 	} u;
73 } __packed;
74 
75 /* 8 bytes buffer tail. */
76 struct hgsmi_buffer_tail {
77 	/* Reserved, must be initialized to 0. */
78 	u32 reserved;
79 	/*
80 	 * One-at-a-Time Hash: http://www.burtleburtle.net/bob/hash/doobs.html
81 	 * Over the header, offset and for first 4 bytes of the tail.
82 	 */
83 	u32 checksum;
84 } __packed;
85 
86 /*
87  * The size of the array of channels. Array indexes are u8.
88  * Note: the value must not be changed.
89  */
90 #define HGSMI_NUMBER_OF_CHANNELS 0x100
91 
92 #endif
93