2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2015-2016 Landon Fuller <landon@landonf.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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.
34 #ifndef _BHND_BHND_MATCH_H_
35 #define _BHND_BHND_MATCH_H_
37 #include "bhnd_types.h"
40 * A hardware revision match descriptor.
42 struct bhnd_hwrev_match {
43 uint16_t start; /**< first revision, or BHND_HWREV_INVALID
44 to match on any revision. */
45 uint16_t end; /**< last revision, or BHND_HWREV_INVALID
46 to match on any revision. */
49 /* Copy match field @p _name from @p _src */
50 #define _BHND_COPY_MATCH_FIELD(_src, _name) \
51 .m.match._name = (_src)->m.match._name, \
52 ._name = (_src)->_name
54 /* Set match field @p _name with @p _value */
55 #define _BHND_SET_MATCH_FIELD(_name, _value) \
56 .m.match._name = 1, ._name = _value
59 * Wildcard hardware revision match descriptor.
61 #define BHND_HWREV_ANY { BHND_HWREV_INVALID, BHND_HWREV_INVALID }
62 #define BHND_HWREV_IS_ANY(_m) \
63 ((_m)->start == BHND_HWREV_INVALID && (_m)->end == BHND_HWREV_INVALID)
66 * Hardware revision match descriptor for an inclusive range.
68 * @param _start The first applicable hardware revision.
69 * @param _end The last applicable hardware revision, or BHND_HWREV_INVALID
70 * to match on any revision.
72 #define BHND_HWREV_RANGE(_start, _end) { _start, _end }
75 * Hardware revision match descriptor for a single revision.
77 * @param _hwrev The hardware revision to match on.
79 #define BHND_HWREV_EQ(_hwrev) BHND_HWREV_RANGE(_hwrev, _hwrev)
82 * Hardware revision match descriptor for any revision equal to or greater
85 * @param _start The first hardware revision to match on.
87 #define BHND_HWREV_GTE(_start) BHND_HWREV_RANGE(_start, BHND_HWREV_INVALID)
90 * Hardware revision match descriptor for any revision equal to or less
93 * @param _end The last hardware revision to match on.
95 #define BHND_HWREV_LTE(_end) BHND_HWREV_RANGE(0, _end)
98 * A bhnd(4) core match descriptor.
100 struct bhnd_core_match {
101 /** Select fields to be matched */
116 uint16_t core_vendor; /**< required JEP106 device vendor */
117 uint16_t core_id; /**< required core ID */
118 struct bhnd_hwrev_match core_rev; /**< matching core revisions. */
119 bhnd_devclass_t core_class; /**< required bhnd class */
120 u_int core_idx; /**< required core index */
121 int core_unit; /**< required core unit */
124 #define _BHND_CORE_MATCH_COPY(_src) \
125 _BHND_COPY_MATCH_FIELD(_src, core_vendor), \
126 _BHND_COPY_MATCH_FIELD(_src, core_id), \
127 _BHND_COPY_MATCH_FIELD(_src, core_rev), \
128 _BHND_COPY_MATCH_FIELD(_src, core_class), \
129 _BHND_COPY_MATCH_FIELD(_src, core_idx), \
130 _BHND_COPY_MATCH_FIELD(_src, core_unit) \
132 #define BHND_MATCH_CORE_VENDOR(_v) _BHND_SET_MATCH_FIELD(core_vendor, _v)
133 #define BHND_MATCH_CORE_ID(_id) _BHND_SET_MATCH_FIELD(core_id, _id)
134 #define BHND_MATCH_CORE_REV(_rev) _BHND_SET_MATCH_FIELD(core_rev, \
136 #define BHND_MATCH_CORE_CLASS(_cls) _BHND_SET_MATCH_FIELD(core_class, _cls)
137 #define BHND_MATCH_CORE_IDX(_idx) _BHND_SET_MATCH_FIELD(core_idx, _idx)
138 #define BHND_MATCH_CORE_UNIT(_unit) _BHND_SET_MATCH_FIELD(core_unit, _unit)
141 * Match against the given @p _vendor and @p _id,
143 #define BHND_MATCH_CORE(_vendor, _id) \
144 BHND_MATCH_CORE_VENDOR(_vendor), \
145 BHND_MATCH_CORE_ID(_id)
148 * A bhnd(4) chip match descriptor.
150 struct bhnd_chip_match {
151 /** Select fields to be matched */
165 uint16_t chip_id; /**< required chip id */
166 struct bhnd_hwrev_match chip_rev; /**< matching chip revisions */
167 uint8_t chip_pkg; /**< required package */
168 uint8_t chip_type; /**< required chip type (BHND_CHIPTYPE_*) */
171 #define _BHND_CHIP_MATCH_COPY(_src) \
172 _BHND_COPY_MATCH_FIELD(_src, chip_id), \
173 _BHND_COPY_MATCH_FIELD(_src, chip_rev), \
174 _BHND_COPY_MATCH_FIELD(_src, chip_pkg), \
175 _BHND_COPY_MATCH_FIELD(_src, chip_type),\
177 /** Set the required chip ID within a bhnd match descriptor */
178 #define BHND_MATCH_CHIP_ID(_cid) _BHND_SET_MATCH_FIELD(chip_id, \
179 BHND_CHIPID_ ## _cid)
181 /** Set the required chip revision range within a bhnd match descriptor */
182 #define BHND_MATCH_CHIP_REV(_rev) _BHND_SET_MATCH_FIELD(chip_rev, \
185 /** Set the required package ID within a bhnd match descriptor */
186 #define BHND_MATCH_CHIP_PKG(_pkg) _BHND_SET_MATCH_FIELD(chip_pkg, \
189 /** Set the required chip type within a bhnd match descriptor */
190 #define BHND_MATCH_CHIP_TYPE(_type) _BHND_SET_MATCH_FIELD(chip_type, \
191 BHND_CHIPTYPE_ ## _type)
193 /** Set the required chip and package ID within a bhnd match descriptor */
194 #define BHND_MATCH_CHIP_IP(_cid, _pkg) \
195 BHND_MATCH_CHIP_ID(_cid), BHND_MATCH_CHIP_PKG(_pkg)
197 /** Set the required chip ID, package ID, and revision within a bhnd_device_match
199 #define BHND_MATCH_CHIP_IPR(_cid, _pkg, _rev) \
200 BHND_MATCH_CHIP_ID(_cid), \
201 BHND_MATCH_CHIP_PKG(_pkg), \
202 BHND_MATCH_CHIP_REV(_rev)
204 /** Set the required chip ID and revision within a bhnd_device_match
206 #define BHND_MATCH_CHIP_IR(_cid, _rev) \
207 BHND_MATCH_CHIP_ID(_cid), BHND_MATCH_CHIP_REV(_rev)
210 * A bhnd(4) board match descriptor.
212 struct bhnd_board_match {
213 /** Select fields to be matched */
227 uint16_t board_vendor; /**< required board vendor */
228 uint16_t board_type; /**< required board type */
229 uint16_t board_devid; /**< required board devid */
230 struct bhnd_hwrev_match board_rev; /**< matching board revisions */
231 struct bhnd_hwrev_match board_srom_rev; /**< matching board srom revisions */
234 #define _BHND_BOARD_MATCH_COPY(_src) \
235 _BHND_COPY_MATCH_FIELD(_src, board_vendor), \
236 _BHND_COPY_MATCH_FIELD(_src, board_type), \
237 _BHND_COPY_MATCH_FIELD(_src, board_devid), \
238 _BHND_COPY_MATCH_FIELD(_src, board_rev), \
239 _BHND_COPY_MATCH_FIELD(_src, board_srom_rev)
241 /** Set the required board vendor within a bhnd match descriptor */
242 #define BHND_MATCH_BOARD_VENDOR(_v) _BHND_SET_MATCH_FIELD(board_vendor, _v)
244 /** Set the required board type within a bhnd match descriptor */
245 #define BHND_MATCH_BOARD_TYPE(_type) _BHND_SET_MATCH_FIELD(board_type, \
246 BHND_BOARD_ ## _type)
248 /** Set the required board devid within a bhnd match descriptor */
249 #define BHND_MATCH_BOARD_DEVID(_devid) _BHND_SET_MATCH_FIELD(board_devid, \
252 /** Set the required SROM revision range within a bhnd match descriptor */
253 #define BHND_MATCH_SROMREV(_rev) _BHND_SET_MATCH_FIELD(board_srom_rev, \
256 /** Set the required board revision range within a bhnd match descriptor */
257 #define BHND_MATCH_BOARD_REV(_rev) _BHND_SET_MATCH_FIELD(board_rev, \
260 /** Set the required board vendor and type within a bhnd match descriptor */
261 #define BHND_MATCH_BOARD(_vend, _type) \
262 BHND_MATCH_BOARD_VENDOR(_vend), BHND_MATCH_BOARD_TYPE(_type)
265 * A bhnd(4) device match descriptor.
267 * @warning Matching on board attributes relies on NVRAM access, and will
268 * fail if a valid NVRAM device cannot be found, or is not yet attached.
270 struct bhnd_device_match {
271 /** Select fields to be matched */
273 uint32_t match_flags;
295 uint16_t core_vendor; /**< required JEP106 device vendor */
296 uint16_t core_id; /**< required core ID */
297 struct bhnd_hwrev_match core_rev; /**< matching core revisions. */
298 bhnd_devclass_t core_class; /**< required bhnd class */
299 u_int core_idx; /**< required core index */
300 int core_unit; /**< required core unit */
302 uint16_t chip_id; /**< required chip id */
303 struct bhnd_hwrev_match chip_rev; /**< matching chip revisions */
304 uint8_t chip_pkg; /**< required package */
305 uint8_t chip_type; /**< required chip type (BHND_CHIPTYPE_*) */
307 uint16_t board_vendor; /**< required board vendor */
308 uint16_t board_type; /**< required board type */
309 uint16_t board_devid; /**< required board devid */
310 struct bhnd_hwrev_match board_rev; /**< matching board revisions */
311 struct bhnd_hwrev_match board_srom_rev; /**< matching board srom revisions */
314 /** Define a wildcard match requirement (matches on any device). */
315 #define BHND_MATCH_ANY .m.match_flags = 0
316 #define BHND_MATCH_IS_ANY(_m) \
317 ((_m)->m.match_flags == 0)
319 #endif /* _BHND_BHND_MATCH_H_ */