summaryrefslogtreecommitdiffstats
path: root/sys/dev/bhnd/bhnd_match.h
blob: f5b01302fb65fb82eda07d94f8c7c32a241f0693 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/*-
 * Copyright (c) 2015-2016 Landon Fuller <landon@landonf.org>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer,
 *    without modification.
 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
 *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
 *    redistribution must be conditioned upon including a substantially
 *    similar Disclaimer requirement for further binary redistribution.
 *
 * NO WARRANTY
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGES.
 * 
 * $FreeBSD$
 */

#ifndef _BHND_BHND_MATCH_H_
#define _BHND_BHND_MATCH_H_

#include "bhnd_types.h"

/**
 * A hardware revision match descriptor.
 */
struct bhnd_hwrev_match {
	uint16_t	start;	/**< first revision, or BHND_HWREV_INVALID
					     to match on any revision. */
	uint16_t	end;	/**< last revision, or BHND_HWREV_INVALID
					     to match on any revision. */
};

/* Copy match field @p _name from @p _src */
#define	_BHND_COPY_MATCH_FIELD(_src, _name)	\
	.m.match._name = (_src)->m.match._name,	\
	._name = (_src)->_name
	
/* Set match field @p _name with @p _value */
#define	_BHND_SET_MATCH_FIELD(_name, _value)	\
	.m.match._name = 1, ._name = _value

/** 
 * Wildcard hardware revision match descriptor.
 */
#define	BHND_HWREV_ANY		{ BHND_HWREV_INVALID, BHND_HWREV_INVALID }
#define	BHND_HWREV_IS_ANY(_m)	\
	((_m)->start == BHND_HWREV_INVALID && (_m)->end == BHND_HWREV_INVALID)

/**
 * Hardware revision match descriptor for an inclusive range.
 * 
 * @param _start The first applicable hardware revision.
 * @param _end The last applicable hardware revision, or BHND_HWREV_INVALID
 * to match on any revision.
 */
#define	BHND_HWREV_RANGE(_start, _end)	{ _start, _end }

/**
 * Hardware revision match descriptor for a single revision.
 * 
 * @param _hwrev The hardware revision to match on.
 */
#define	BHND_HWREV_EQ(_hwrev)	BHND_HWREV_RANGE(_hwrev, _hwrev)

/**
 * Hardware revision match descriptor for any revision equal to or greater
 * than @p _start.
 * 
 * @param _start The first hardware revision to match on.
 */
#define	BHND_HWREV_GTE(_start)	BHND_HWREV_RANGE(_start, BHND_HWREV_INVALID)

/**
 * Hardware revision match descriptor for any revision equal to or less
 * than @p _end.
 * 
 * @param _end The last hardware revision to match on.
 */
#define	BHND_HWREV_LTE(_end)	BHND_HWREV_RANGE(0, _end)

/**
 * A bhnd(4) core match descriptor.
 */
struct bhnd_core_match {
	/** Select fields to be matched */
	union {
		uint8_t match_flags;
		struct {
			uint8_t
			    core_vendor:1,
			    core_id:1,
			    core_rev:1,
			    core_class:1,
			    core_unit:1,
			    flags_unused:3;
		} match;
	} m;
	
	uint16_t		core_vendor;	/**< required JEP106 device vendor */
	uint16_t		core_id;	/**< required core ID */
	struct bhnd_hwrev_match	core_rev;	/**< matching core revisions. */
	bhnd_devclass_t		core_class;	/**< required bhnd class */
	int			core_unit;	/**< required core unit */
};

#define	_BHND_CORE_MATCH_COPY(_src)			\
	_BHND_COPY_MATCH_FIELD(_src, core_vendor),	\
	_BHND_COPY_MATCH_FIELD(_src, core_id),		\
	_BHND_COPY_MATCH_FIELD(_src, core_rev),		\
	_BHND_COPY_MATCH_FIELD(_src, core_class),	\
	_BHND_COPY_MATCH_FIELD(_src, core_unit)		\

#define	BHND_MATCH_CORE_VENDOR(_v)	_BHND_SET_MATCH_FIELD(core_vendor, _v)
#define	BHND_MATCH_CORE_ID(_id)		_BHND_SET_MATCH_FIELD(core_id, _id)
#define	BHND_MATCH_CORE_REV(_rev)	_BHND_SET_MATCH_FIELD(core_rev,	\
					    BHND_ ## _rev)
#define	BHND_MATCH_CORE_CLASS(_cls)	_BHND_SET_MATCH_FIELD(core_class, _cls)
#define	BHND_MATCH_CORE_UNIT(_unit)	_BHND_SET_MATCH_FIELD(core_unit, _unit)

/**
 * Match against the given @p _vendor and @p _id,
 */
#define	BHND_MATCH_CORE(_vendor, _id)		\
	BHND_MATCH_CORE_VENDOR(_vendor),	\
	BHND_MATCH_CORE_ID(_id)

/**
 * A bhnd(4) chip match descriptor.
 */
struct bhnd_chip_match {
	/** Select fields to be matched */
	union {
		uint8_t match_flags;
		struct {
			uint8_t
			    chip_id:1,
			    chip_rev:1,
			    chip_pkg:1,
			    flags_unused:5;
		} match;

	} m;

	uint16_t		chip_id;	/**< required chip id */
	struct bhnd_hwrev_match	chip_rev;	/**< matching chip revisions */
	uint8_t			chip_pkg;	/**< required package */
};

#define	_BHND_CHIP_MATCH_COPY(_src)		\
	_BHND_COPY_MATCH_FIELD(_src, chip_id),	\
	_BHND_COPY_MATCH_FIELD(_src, chip_rev),	\
	_BHND_COPY_MATCH_FIELD(_src, chip_pkg)	\

/** Set the required chip ID within a bhnd match descriptor */
#define	BHND_CHIP_ID(_cid)	_BHND_SET_MATCH_FIELD(chip_id,	\
					    BHND_CHIPID_ ## _cid)

/** Set the required chip revision range within a bhnd match descriptor */
#define	BHND_CHIP_REV(_rev)	_BHND_SET_MATCH_FIELD(chip_rev,	\
					    BHND_ ## _rev)

/** Set the required package ID within a bhnd match descriptor */
#define	BHND_CHIP_PKG(_pkg)	_BHND_SET_MATCH_FIELD(chip_pkg,	\
					    BHND_PKGID_ ## _pkg)

/** Set the required chip and package ID within a bhnd match descriptor */
#define	BHND_CHIP_IP(_cid, _pkg)	\
    BHND_CHIP_ID(_cid), BHND_CHIP_PKG(_pkg)

/** Set the required chip ID, package ID, and revision within a bhnd_device_match
 *  instance */
#define	BHND_CHIP_IPR(_cid, _pkg, _rev)	\
    BHND_CHIP_ID(_cid), BHND_CHIP_PKG(_pkg), BHND_CHIP_REV(_rev)

/** Set the required chip ID and revision within a bhnd_device_match
 *  instance */
#define	BHND_CHIP_IR(_cid, _rev)	\
    BHND_CHIP_ID(_cid), BHND_CHIP_REV(_rev)

/**
 * A bhnd(4) board match descriptor.
 */
struct bhnd_board_match {
	/** Select fields to be matched */
	union {
		uint8_t match_flags;
		struct {
			uint8_t
			    board_vendor:1,
			    board_type:1,
			    board_rev:1,
			    board_srom_rev:1,
			    flags_unused:4;
		} match;
	} m;

	uint16_t		board_vendor;	/**< required board vendor */
	uint16_t		board_type;	/**< required board type */
	struct bhnd_hwrev_match	board_rev;	/**< matching board revisions */
	struct bhnd_hwrev_match	board_srom_rev;	/**< matching board srom revisions */
};

#define	_BHND_BOARD_MATCH_COPY(_src)			\
	_BHND_COPY_MATCH_FIELD(_src, board_vendor),	\
	_BHND_COPY_MATCH_FIELD(_src, board_type),	\
	_BHND_COPY_MATCH_FIELD(_src, board_rev),	\
	_BHND_COPY_MATCH_FIELD(_src, board_srom_rev)

/** Set the required board vendor within a bhnd match descriptor */
#define	BHND_MATCH_BOARD_VENDOR(_v)	_BHND_SET_MATCH_FIELD(board_vendor, _v)

/** Set the required board type within a bhnd match descriptor */
#define	BHND_MATCH_BOARD_TYPE(_type)	_BHND_SET_MATCH_FIELD(board_type, \
					    BHND_BOARD_ ## _type)
/** Set the required SROM revision range within a bhnd match descriptor */
#define	BHND_MATCH_SROMREV(_rev)	_BHND_SET_MATCH_FIELD(board_srom_rev, \
					    BHND_HWREV_ ## _rev)

/** Set the required board revision range within a bhnd match descriptor */
#define	BHND_MATCH_BOARD_REV(_rev)	_BHND_SET_MATCH_FIELD(board_rev, \
					    BHND_ ## _rev)

/** Set the required board vendor and type within a bhnd match descriptor */
#define	BHND_MATCH_BOARD(_vend, _type)	\
	BHND_MATCH_BOARD_VENDOR(_vend), BHND_MATCH_BOARD_TYPE(_type)


/**
 * A bhnd(4) device match descriptor.
 *
 * @warning Matching on board attributes relies on NVRAM access, and will
 * fail if a valid NVRAM device cannot be found, or is not yet attached.
 */
struct bhnd_device_match {
	/** Select fields to be matched */
	union {
		uint16_t match_flags;
		struct {
			uint16_t
			core_vendor:1,
			core_id:1,
			core_rev:1,
			core_class:1,
			core_unit:1,
			chip_id:1,
			chip_rev:1,
			chip_pkg:1,
			board_vendor:1,
			board_type:1,
			board_rev:1,
			board_srom_rev:1,
			flags_unused:2;
		} match;
	} m;
	
	uint16_t		core_vendor;	/**< required JEP106 device vendor */
	uint16_t		core_id;	/**< required core ID */
	struct bhnd_hwrev_match	core_rev;	/**< matching core revisions. */
	bhnd_devclass_t		core_class;	/**< required bhnd class */
	int			core_unit;	/**< required core unit */

	uint16_t		chip_id;	/**< required chip id */
	struct bhnd_hwrev_match	chip_rev;	/**< matching chip revisions */
	uint8_t			chip_pkg;	/**< required package */

	uint16_t		board_vendor;	/**< required board vendor */
	uint16_t		board_type;	/**< required board type */
	struct bhnd_hwrev_match	board_rev;	/**< matching board revisions */
	struct bhnd_hwrev_match	board_srom_rev;	/**< matching board srom revisions */
};

/** Define a wildcard match requirement (matches on any device). */
#define	BHND_MATCH_ANY		.m.match_flags = 0
#define	BHND_MATCH_IS_ANY(_m)	\
	((_m)->m.match_flags == 0)

#endif /* _BHND_BHND_MATCH_H_ */
OpenPOWER on IntegriCloud