1/* SPDX-License-Identifier: MIT */
2/* Copyright (C) 2006-2017 Oracle Corporation */
3
4#ifndef __HGSMI_DEFS_H__
5#define __HGSMI_DEFS_H__
6
7/* Buffer sequence type mask. */
8#define HGSMI_BUFFER_HEADER_F_SEQ_MASK     0x03
9/* Single buffer, not a part of a sequence. */
10#define HGSMI_BUFFER_HEADER_F_SEQ_SINGLE   0x00
11/* The first buffer in a sequence. */
12#define HGSMI_BUFFER_HEADER_F_SEQ_START    0x01
13/* A middle buffer in a sequence. */
14#define HGSMI_BUFFER_HEADER_F_SEQ_CONTINUE 0x02
15/* The last buffer in a sequence. */
16#define HGSMI_BUFFER_HEADER_F_SEQ_END      0x03
17
18/* 16 bytes buffer header. */
19struct hgsmi_buffer_header {
20	u32 data_size;		/* Size of data that follows the header. */
21	u8 flags;		/* HGSMI_BUFFER_HEADER_F_* */
22	u8 channel;		/* The channel the data must be routed to. */
23	u16 channel_info;	/* Opaque to the HGSMI, used by the channel. */
24
25	union {
26		/* Opaque placeholder to make the union 8 bytes. */
27		u8 header_data[8];
28
29		/* HGSMI_BUFFER_HEADER_F_SEQ_SINGLE */
30		struct {
31			u32 reserved1;	/* A reserved field, initialize to 0. */
32			u32 reserved2;	/* A reserved field, initialize to 0. */
33		} buffer;
34
35		/* HGSMI_BUFFER_HEADER_F_SEQ_START */
36		struct {
37			/* Must be the same for all buffers in the sequence. */
38			u32 sequence_number;
39			/* The total size of the sequence. */
40			u32 sequence_size;
41		} sequence_start;
42
43		/*
44		 * HGSMI_BUFFER_HEADER_F_SEQ_CONTINUE and
45		 * HGSMI_BUFFER_HEADER_F_SEQ_END
46		 */
47		struct {
48			/* Must be the same for all buffers in the sequence. */
49			u32 sequence_number;
50			/* Data offset in the entire sequence. */
51			u32 sequence_offset;
52		} sequence_continue;
53	} u;
54} __packed;
55
56/* 8 bytes buffer tail. */
57struct hgsmi_buffer_tail {
58	/* Reserved, must be initialized to 0. */
59	u32 reserved;
60	/*
61	 * One-at-a-Time Hash: https://www.burtleburtle.net/bob/hash/doobs.html
62	 * Over the header, offset and for first 4 bytes of the tail.
63	 */
64	u32 checksum;
65} __packed;
66
67/*
68 * The size of the array of channels. Array indexes are u8.
69 * Note: the value must not be changed.
70 */
71#define HGSMI_NUMBER_OF_CHANNELS 0x100
72
73#endif
74