1
/* Copyright 2013-2014 IBM Corp.
3
* Licensed under the Apache License, Version 2.0 (the "License");
4
* you may not use this file except in compliance with the License.
5
* You may obtain a copy of the License at
7
* http://www.apache.org/licenses/LICENSE-2.0
9
* Unless required by applicable law or agreed to in writing, software
10
* distributed under the License is distributed on an "AS IS" BASIS,
11
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
22
#include <ccan/endian/endian.h>
24
struct HDIF_common_hdr {
25
__be16 d1f0; /* 0xd1f0 */
26
char id[6]; /* eye catcher string */
27
__be16 instnum; /* instance number */
28
__be16 version; /* version */
29
__be32 total_len; /* total structure length */
30
__be32 hdr_len; /* header length (currently 0x20) */
31
__be32 idptr_off; /* offset to idata pointers */
32
__be16 idptr_count; /* number of idata pointers */
33
__be16 child_count; /* number of child structures */
34
__be32 child_off; /* offset to child structures array */
35
} __packed __align(0x10);
37
struct HDIF_idata_ptr {
40
} __packed __align(0x8);
42
struct HDIF_array_hdr {
47
} __packed __align(0x10);
49
struct HDIF_child_ptr {
55
#define HDIF_HDR_LEN (sizeof(struct HDIF_common_hdr))
56
#define HDIF_ARRAY_OFFSET (sizeof(struct HDIF_array_hdr))
58
#define HDIF_ID(_id) .d1f0 = CPU_TO_BE16(0xd1f0), .id = _id
60
#define HDIF_SIMPLE_HDR(id, vers, type) \
63
.instnum = CPU_TO_BE16(0), \
64
.version = CPU_TO_BE16(vers), \
65
.total_len = CPU_TO_BE32(sizeof(type)), \
66
.hdr_len = CPU_TO_BE32(HDIF_HDR_LEN), \
67
.idptr_off = CPU_TO_BE32(HDIF_HDR_LEN), \
68
.idptr_count = CPU_TO_BE16(1), \
69
.child_count = CPU_TO_BE16(0), \
70
.child_off = CPU_TO_BE32(0), \
73
#define HDIF_IDATA_PTR(_offset, _size) \
75
.offset = CPU_TO_BE32(_offset), \
76
.size = CPU_TO_BE32(_size), \
79
static inline bool HDIF_check(const void *hdif, const char id[])
81
const struct HDIF_common_hdr *hdr = hdif;
83
return hdr->d1f0 == CPU_TO_BE16(0xd1f0) &&
84
memcmp(hdr->id, id, sizeof(hdr->id)) == 0;
87
/* HDIF_get_idata - Get a pointer to internal data block
89
* @hdif : HDIF structure pointer
90
* @di : Index of the idata pointer
91
* @size : Return the data size (or NULL if ignored)
93
extern const void *HDIF_get_idata(const struct HDIF_common_hdr *hdif,
97
/* HDIF_get_iarray - Get a pointer to an elemnt of an internal data array
99
* @hdif : HDIF structure pointer
100
* @di : Index of the idata pointer
101
* @ai : Index in the resulting array
102
* @size : Return the entry actual size (or NULL if ignored)
104
extern const void *HDIF_get_iarray_item(const struct HDIF_common_hdr *hdif,
106
unsigned int ai, unsigned int *size);
108
/* HDIF_get_iarray_size - Get the number of elements of an internal data array
110
* @hdif : HDIF structure pointer
111
* @di : Index of the idata pointer
113
* A negative result means an error
115
extern int HDIF_get_iarray_size(const struct HDIF_common_hdr *hdif,
118
/* HDIF_child_arr - Get a child array from this HDIF.
120
* @hdif : HDIF structure pointer
121
* @idx : the child to get
123
* NULL means an error (not that many children).
125
extern struct HDIF_child_ptr *
126
HDIF_child_arr(const struct HDIF_common_hdr *hdif, unsigned int idx);
128
/* HDIF_child - Deref a child_ptr entry.
130
* @hdif : HDIF structure pointer
131
* @child : the child returned from HDIF_child_arr
132
* @idx : the index of the child to get (< child->count).
133
* @eyecatcher: the 6-char ID expected for this child.
135
* NULL means an error.
137
extern struct HDIF_common_hdr *HDIF_child(const struct HDIF_common_hdr *hdif,
138
const struct HDIF_child_ptr *child,
140
const char *eyecatcher);
141
#endif /* __HDIF_H */