~pmdj/ubuntu/trusty/qemu/2.9+applesmc+fadtv3

« back to all changes in this revision

Viewing changes to roms/skiboot/hdata/hdif.h

  • Committer: Phil Dennis-Jordan
  • Date: 2017-07-21 08:03:43 UTC
  • mfrom: (1.1.1)
  • Revision ID: phil@philjordan.eu-20170721080343-2yr2vdj7713czahv
New upstream release 2.9.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2013-2014 IBM Corp.
 
2
 *
 
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
 
6
 *
 
7
 *      http://www.apache.org/licenses/LICENSE-2.0
 
8
 *
 
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
 
12
 * implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
#ifndef __HDIF_H
 
18
#define __HDIF_H
 
19
 
 
20
#include <skiboot.h>
 
21
#include <types.h>
 
22
#include <ccan/endian/endian.h>
 
23
 
 
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);
 
36
 
 
37
struct HDIF_idata_ptr {
 
38
        __be32  offset;
 
39
        __be32  size;
 
40
} __packed __align(0x8);
 
41
 
 
42
struct HDIF_array_hdr {
 
43
        __be32  offset;
 
44
        __be32  ecnt;
 
45
        __be32  esize;
 
46
        __be32  eactsz;
 
47
} __packed __align(0x10);
 
48
 
 
49
struct HDIF_child_ptr {
 
50
        __be32  offset;
 
51
        __be32  size;
 
52
        __be32  count;
 
53
} __packed;
 
54
 
 
55
#define HDIF_HDR_LEN            (sizeof(struct HDIF_common_hdr))
 
56
#define HDIF_ARRAY_OFFSET       (sizeof(struct HDIF_array_hdr))
 
57
 
 
58
#define HDIF_ID(_id)            .d1f0 = CPU_TO_BE16(0xd1f0), .id = _id
 
59
 
 
60
#define HDIF_SIMPLE_HDR(id, vers, type)                 \
 
61
{                                                       \
 
62
        HDIF_ID(id),                                    \
 
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),               \
 
71
}
 
72
 
 
73
#define HDIF_IDATA_PTR(_offset, _size)                  \
 
74
{                                                       \
 
75
        .offset = CPU_TO_BE32(_offset),                 \
 
76
        .size   = CPU_TO_BE32(_size),                   \
 
77
}
 
78
 
 
79
static inline bool HDIF_check(const void *hdif, const char id[])
 
80
{
 
81
        const struct HDIF_common_hdr *hdr = hdif;
 
82
 
 
83
        return hdr->d1f0 == CPU_TO_BE16(0xd1f0) &&
 
84
                memcmp(hdr->id, id, sizeof(hdr->id)) == 0;
 
85
}
 
86
 
 
87
/* HDIF_get_idata - Get a pointer to internal data block
 
88
 *
 
89
 * @hdif  : HDIF structure pointer
 
90
 * @di    : Index of the idata pointer
 
91
 * @size  : Return the data size (or NULL if ignored)
 
92
 */
 
93
extern const void *HDIF_get_idata(const struct HDIF_common_hdr *hdif,
 
94
                                  unsigned int di,
 
95
                                  unsigned int *size);
 
96
 
 
97
/* HDIF_get_iarray - Get a pointer to an elemnt of an internal data array
 
98
 *
 
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)
 
103
 */
 
104
extern const void *HDIF_get_iarray_item(const struct HDIF_common_hdr *hdif,
 
105
                                        unsigned int di,
 
106
                                        unsigned int ai, unsigned int *size);
 
107
 
 
108
/* HDIF_get_iarray_size - Get the number of elements of an internal data array
 
109
 *
 
110
 * @hdif  : HDIF structure pointer
 
111
 * @di    : Index of the idata pointer
 
112
 *
 
113
 * A negative result means an error
 
114
 */
 
115
extern int HDIF_get_iarray_size(const struct HDIF_common_hdr *hdif,
 
116
                                unsigned int di);
 
117
 
 
118
/* HDIF_child_arr - Get a child array from this HDIF.
 
119
 *
 
120
 * @hdif  : HDIF structure pointer
 
121
 * @idx   : the child to get
 
122
 *
 
123
 * NULL means an error (not that many children).
 
124
 */
 
125
extern struct HDIF_child_ptr *
 
126
HDIF_child_arr(const struct HDIF_common_hdr *hdif, unsigned int idx);
 
127
 
 
128
/* HDIF_child - Deref a child_ptr entry.
 
129
 *
 
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.
 
134
 *
 
135
 * NULL means an error.
 
136
 */
 
137
extern struct HDIF_common_hdr *HDIF_child(const struct HDIF_common_hdr *hdif,
 
138
                                          const struct HDIF_child_ptr *child,
 
139
                                          unsigned int idx,
 
140
                                          const char *eyecatcher);
 
141
#endif /* __HDIF_H */