Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/sys/dev/bhnd/bhnd_match.h
39507 views
1
/*-
2
* SPDX-License-Identifier: BSD-2-Clause
3
*
4
* Copyright (c) 2015-2016 Landon Fuller <[email protected]>
5
* All rights reserved.
6
*
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions
9
* are met:
10
* 1. Redistributions of source code must retain the above copyright
11
* notice, this list of conditions and the following disclaimer,
12
* without modification.
13
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
14
* similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
15
* redistribution must be conditioned upon including a substantially
16
* similar Disclaimer requirement for further binary redistribution.
17
*
18
* NO WARRANTY
19
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
* LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
22
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23
* THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
24
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
27
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29
* THE POSSIBILITY OF SUCH DAMAGES.
30
*
31
*/
32
33
#ifndef _BHND_BHND_MATCH_H_
34
#define _BHND_BHND_MATCH_H_
35
36
#include "bhnd_types.h"
37
38
/**
39
* A hardware revision match descriptor.
40
*/
41
struct bhnd_hwrev_match {
42
uint16_t start; /**< first revision, or BHND_HWREV_INVALID
43
to match on any revision. */
44
uint16_t end; /**< last revision, or BHND_HWREV_INVALID
45
to match on any revision. */
46
};
47
48
/* Copy match field @p _name from @p _src */
49
#define _BHND_COPY_MATCH_FIELD(_src, _name) \
50
.m.match._name = (_src)->m.match._name, \
51
._name = (_src)->_name
52
53
/* Set match field @p _name with @p _value */
54
#define _BHND_SET_MATCH_FIELD(_name, _value) \
55
.m.match._name = 1, ._name = _value
56
57
/**
58
* Wildcard hardware revision match descriptor.
59
*/
60
#define BHND_HWREV_ANY { BHND_HWREV_INVALID, BHND_HWREV_INVALID }
61
#define BHND_HWREV_IS_ANY(_m) \
62
((_m)->start == BHND_HWREV_INVALID && (_m)->end == BHND_HWREV_INVALID)
63
64
/**
65
* Hardware revision match descriptor for an inclusive range.
66
*
67
* @param _start The first applicable hardware revision.
68
* @param _end The last applicable hardware revision, or BHND_HWREV_INVALID
69
* to match on any revision.
70
*/
71
#define BHND_HWREV_RANGE(_start, _end) { _start, _end }
72
73
/**
74
* Hardware revision match descriptor for a single revision.
75
*
76
* @param _hwrev The hardware revision to match on.
77
*/
78
#define BHND_HWREV_EQ(_hwrev) BHND_HWREV_RANGE(_hwrev, _hwrev)
79
80
/**
81
* Hardware revision match descriptor for any revision equal to or greater
82
* than @p _start.
83
*
84
* @param _start The first hardware revision to match on.
85
*/
86
#define BHND_HWREV_GTE(_start) BHND_HWREV_RANGE(_start, BHND_HWREV_INVALID)
87
88
/**
89
* Hardware revision match descriptor for any revision equal to or less
90
* than @p _end.
91
*
92
* @param _end The last hardware revision to match on.
93
*/
94
#define BHND_HWREV_LTE(_end) BHND_HWREV_RANGE(0, _end)
95
96
/**
97
* A bhnd(4) core match descriptor.
98
*/
99
struct bhnd_core_match {
100
/** Select fields to be matched */
101
union {
102
uint8_t match_flags;
103
struct {
104
uint8_t
105
core_vendor:1,
106
core_id:1,
107
core_rev:1,
108
core_class:1,
109
core_idx:1,
110
core_unit:1,
111
flags_unused:2;
112
} match;
113
} m;
114
115
uint16_t core_vendor; /**< required JEP106 device vendor */
116
uint16_t core_id; /**< required core ID */
117
struct bhnd_hwrev_match core_rev; /**< matching core revisions. */
118
bhnd_devclass_t core_class; /**< required bhnd class */
119
u_int core_idx; /**< required core index */
120
int core_unit; /**< required core unit */
121
};
122
123
#define _BHND_CORE_MATCH_COPY(_src) \
124
_BHND_COPY_MATCH_FIELD(_src, core_vendor), \
125
_BHND_COPY_MATCH_FIELD(_src, core_id), \
126
_BHND_COPY_MATCH_FIELD(_src, core_rev), \
127
_BHND_COPY_MATCH_FIELD(_src, core_class), \
128
_BHND_COPY_MATCH_FIELD(_src, core_idx), \
129
_BHND_COPY_MATCH_FIELD(_src, core_unit) \
130
131
#define BHND_MATCH_CORE_VENDOR(_v) _BHND_SET_MATCH_FIELD(core_vendor, _v)
132
#define BHND_MATCH_CORE_ID(_id) _BHND_SET_MATCH_FIELD(core_id, _id)
133
#define BHND_MATCH_CORE_REV(_rev) _BHND_SET_MATCH_FIELD(core_rev, \
134
BHND_ ## _rev)
135
#define BHND_MATCH_CORE_CLASS(_cls) _BHND_SET_MATCH_FIELD(core_class, _cls)
136
#define BHND_MATCH_CORE_IDX(_idx) _BHND_SET_MATCH_FIELD(core_idx, _idx)
137
#define BHND_MATCH_CORE_UNIT(_unit) _BHND_SET_MATCH_FIELD(core_unit, _unit)
138
139
/**
140
* Match against the given @p _vendor and @p _id,
141
*/
142
#define BHND_MATCH_CORE(_vendor, _id) \
143
BHND_MATCH_CORE_VENDOR(_vendor), \
144
BHND_MATCH_CORE_ID(_id)
145
146
/**
147
* A bhnd(4) chip match descriptor.
148
*/
149
struct bhnd_chip_match {
150
/** Select fields to be matched */
151
union {
152
uint8_t match_flags;
153
struct {
154
uint8_t
155
chip_id:1,
156
chip_rev:1,
157
chip_pkg:1,
158
chip_type:1,
159
flags_unused:4;
160
} match;
161
162
} m;
163
164
uint16_t chip_id; /**< required chip id */
165
struct bhnd_hwrev_match chip_rev; /**< matching chip revisions */
166
uint8_t chip_pkg; /**< required package */
167
uint8_t chip_type; /**< required chip type (BHND_CHIPTYPE_*) */
168
};
169
170
#define _BHND_CHIP_MATCH_COPY(_src) \
171
_BHND_COPY_MATCH_FIELD(_src, chip_id), \
172
_BHND_COPY_MATCH_FIELD(_src, chip_rev), \
173
_BHND_COPY_MATCH_FIELD(_src, chip_pkg), \
174
_BHND_COPY_MATCH_FIELD(_src, chip_type),\
175
176
/** Set the required chip ID within a bhnd match descriptor */
177
#define BHND_MATCH_CHIP_ID(_cid) _BHND_SET_MATCH_FIELD(chip_id, \
178
BHND_CHIPID_ ## _cid)
179
180
/** Set the required chip revision range within a bhnd match descriptor */
181
#define BHND_MATCH_CHIP_REV(_rev) _BHND_SET_MATCH_FIELD(chip_rev, \
182
BHND_ ## _rev)
183
184
/** Set the required package ID within a bhnd match descriptor */
185
#define BHND_MATCH_CHIP_PKG(_pkg) _BHND_SET_MATCH_FIELD(chip_pkg, \
186
BHND_PKGID_ ## _pkg)
187
188
/** Set the required chip type within a bhnd match descriptor */
189
#define BHND_MATCH_CHIP_TYPE(_type) _BHND_SET_MATCH_FIELD(chip_type, \
190
BHND_CHIPTYPE_ ## _type)
191
192
/** Set the required chip and package ID within a bhnd match descriptor */
193
#define BHND_MATCH_CHIP_IP(_cid, _pkg) \
194
BHND_MATCH_CHIP_ID(_cid), BHND_MATCH_CHIP_PKG(_pkg)
195
196
/** Set the required chip ID, package ID, and revision within a bhnd_device_match
197
* instance */
198
#define BHND_MATCH_CHIP_IPR(_cid, _pkg, _rev) \
199
BHND_MATCH_CHIP_ID(_cid), \
200
BHND_MATCH_CHIP_PKG(_pkg), \
201
BHND_MATCH_CHIP_REV(_rev)
202
203
/** Set the required chip ID and revision within a bhnd_device_match
204
* instance */
205
#define BHND_MATCH_CHIP_IR(_cid, _rev) \
206
BHND_MATCH_CHIP_ID(_cid), BHND_MATCH_CHIP_REV(_rev)
207
208
/**
209
* A bhnd(4) board match descriptor.
210
*/
211
struct bhnd_board_match {
212
/** Select fields to be matched */
213
union {
214
uint8_t match_flags;
215
struct {
216
uint8_t
217
board_vendor:1,
218
board_type:1,
219
board_devid:1,
220
board_rev:1,
221
board_srom_rev:1,
222
flags_unused:3;
223
} match;
224
} m;
225
226
uint16_t board_vendor; /**< required board vendor */
227
uint16_t board_type; /**< required board type */
228
uint16_t board_devid; /**< required board devid */
229
struct bhnd_hwrev_match board_rev; /**< matching board revisions */
230
struct bhnd_hwrev_match board_srom_rev; /**< matching board srom revisions */
231
};
232
233
#define _BHND_BOARD_MATCH_COPY(_src) \
234
_BHND_COPY_MATCH_FIELD(_src, board_vendor), \
235
_BHND_COPY_MATCH_FIELD(_src, board_type), \
236
_BHND_COPY_MATCH_FIELD(_src, board_devid), \
237
_BHND_COPY_MATCH_FIELD(_src, board_rev), \
238
_BHND_COPY_MATCH_FIELD(_src, board_srom_rev)
239
240
/** Set the required board vendor within a bhnd match descriptor */
241
#define BHND_MATCH_BOARD_VENDOR(_v) _BHND_SET_MATCH_FIELD(board_vendor, _v)
242
243
/** Set the required board type within a bhnd match descriptor */
244
#define BHND_MATCH_BOARD_TYPE(_type) _BHND_SET_MATCH_FIELD(board_type, \
245
BHND_BOARD_ ## _type)
246
247
/** Set the required board devid within a bhnd match descriptor */
248
#define BHND_MATCH_BOARD_DEVID(_devid) _BHND_SET_MATCH_FIELD(board_devid, \
249
(_devid))
250
251
/** Set the required SROM revision range within a bhnd match descriptor */
252
#define BHND_MATCH_SROMREV(_rev) _BHND_SET_MATCH_FIELD(board_srom_rev, \
253
BHND_HWREV_ ## _rev)
254
255
/** Set the required board revision range within a bhnd match descriptor */
256
#define BHND_MATCH_BOARD_REV(_rev) _BHND_SET_MATCH_FIELD(board_rev, \
257
BHND_ ## _rev)
258
259
/** Set the required board vendor and type within a bhnd match descriptor */
260
#define BHND_MATCH_BOARD(_vend, _type) \
261
BHND_MATCH_BOARD_VENDOR(_vend), BHND_MATCH_BOARD_TYPE(_type)
262
263
/**
264
* A bhnd(4) device match descriptor.
265
*
266
* @warning Matching on board attributes relies on NVRAM access, and will
267
* fail if a valid NVRAM device cannot be found, or is not yet attached.
268
*/
269
struct bhnd_device_match {
270
/** Select fields to be matched */
271
union {
272
uint32_t match_flags;
273
struct {
274
uint32_t
275
core_vendor:1,
276
core_id:1,
277
core_rev:1,
278
core_class:1,
279
core_idx:1,
280
core_unit:1,
281
chip_id:1,
282
chip_rev:1,
283
chip_pkg:1,
284
chip_type:1,
285
board_vendor:1,
286
board_type:1,
287
board_devid:1,
288
board_rev:1,
289
board_srom_rev:1,
290
flags_unused:15;
291
} match;
292
} m;
293
294
uint16_t core_vendor; /**< required JEP106 device vendor */
295
uint16_t core_id; /**< required core ID */
296
struct bhnd_hwrev_match core_rev; /**< matching core revisions. */
297
bhnd_devclass_t core_class; /**< required bhnd class */
298
u_int core_idx; /**< required core index */
299
int core_unit; /**< required core unit */
300
301
uint16_t chip_id; /**< required chip id */
302
struct bhnd_hwrev_match chip_rev; /**< matching chip revisions */
303
uint8_t chip_pkg; /**< required package */
304
uint8_t chip_type; /**< required chip type (BHND_CHIPTYPE_*) */
305
306
uint16_t board_vendor; /**< required board vendor */
307
uint16_t board_type; /**< required board type */
308
uint16_t board_devid; /**< required board devid */
309
struct bhnd_hwrev_match board_rev; /**< matching board revisions */
310
struct bhnd_hwrev_match board_srom_rev; /**< matching board srom revisions */
311
};
312
313
/** Define a wildcard match requirement (matches on any device). */
314
#define BHND_MATCH_ANY .m.match_flags = 0
315
#define BHND_MATCH_IS_ANY(_m) \
316
((_m)->m.match_flags == 0)
317
318
#endif /* _BHND_BHND_MATCH_H_ */
319
320