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