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_unit:1, 109 flags_unused:3; 110 } match; 111 } m; 112 113 uint16_t core_vendor; /**< required JEP106 device vendor */ 114 uint16_t core_id; /**< required core ID */ 115 struct bhnd_hwrev_match core_rev; /**< matching core revisions. */ 116 bhnd_devclass_t core_class; /**< required bhnd class */ 117 int core_unit; /**< required core unit */ 118 }; 119 120 #define _BHND_CORE_MATCH_COPY(_src) \ 121 _BHND_COPY_MATCH_FIELD(_src, core_vendor), \ 122 _BHND_COPY_MATCH_FIELD(_src, core_id), \ 123 _BHND_COPY_MATCH_FIELD(_src, core_rev), \ 124 _BHND_COPY_MATCH_FIELD(_src, core_class), \ 125 _BHND_COPY_MATCH_FIELD(_src, core_unit) \ 126 127 #define BHND_MATCH_CORE_VENDOR(_v) _BHND_SET_MATCH_FIELD(core_vendor, _v) 128 #define BHND_MATCH_CORE_ID(_id) _BHND_SET_MATCH_FIELD(core_id, _id) 129 #define BHND_MATCH_CORE_REV(_rev) _BHND_SET_MATCH_FIELD(core_rev, \ 130 BHND_ ## _rev) 131 #define BHND_MATCH_CORE_CLASS(_cls) _BHND_SET_MATCH_FIELD(core_class, _cls) 132 #define BHND_MATCH_CORE_UNIT(_unit) _BHND_SET_MATCH_FIELD(core_unit, _unit) 133 134 /** 135 * Match against the given @p _vendor and @p _id, 136 */ 137 #define BHND_MATCH_CORE(_vendor, _id) \ 138 BHND_MATCH_CORE_VENDOR(_vendor), \ 139 BHND_MATCH_CORE_ID(_id) 140 141 /** 142 * A bhnd(4) chip match descriptor. 143 */ 144 struct bhnd_chip_match { 145 /** Select fields to be matched */ 146 union { 147 uint8_t match_flags; 148 struct { 149 uint8_t 150 chip_id:1, 151 chip_rev:1, 152 chip_pkg:1, 153 flags_unused:5; 154 } match; 155 156 } m; 157 158 uint16_t chip_id; /**< required chip id */ 159 struct bhnd_hwrev_match chip_rev; /**< matching chip revisions */ 160 uint8_t chip_pkg; /**< required package */ 161 }; 162 163 #define _BHND_CHIP_MATCH_COPY(_src) \ 164 _BHND_COPY_MATCH_FIELD(_src, chip_id), \ 165 _BHND_COPY_MATCH_FIELD(_src, chip_rev), \ 166 _BHND_COPY_MATCH_FIELD(_src, chip_pkg) \ 167 168 /** Set the required chip ID within a bhnd match descriptor */ 169 #define BHND_CHIP_ID(_cid) _BHND_SET_MATCH_FIELD(chip_id, \ 170 BHND_CHIPID_ ## _cid) 171 172 /** Set the required chip revision range within a bhnd match descriptor */ 173 #define BHND_CHIP_REV(_rev) _BHND_SET_MATCH_FIELD(chip_rev, \ 174 BHND_ ## _rev) 175 176 /** Set the required package ID within a bhnd match descriptor */ 177 #define BHND_CHIP_PKG(_pkg) _BHND_SET_MATCH_FIELD(chip_pkg, \ 178 BHND_PKGID_ ## _pkg) 179 180 /** Set the required chip and package ID within a bhnd match descriptor */ 181 #define BHND_CHIP_IP(_cid, _pkg) \ 182 BHND_CHIP_ID(_cid), BHND_CHIP_PKG(_pkg) 183 184 /** Set the required chip ID, package ID, and revision within a bhnd_device_match 185 * instance */ 186 #define BHND_CHIP_IPR(_cid, _pkg, _rev) \ 187 BHND_CHIP_ID(_cid), BHND_CHIP_PKG(_pkg), BHND_CHIP_REV(_rev) 188 189 /** Set the required chip ID and revision within a bhnd_device_match 190 * instance */ 191 #define BHND_CHIP_IR(_cid, _rev) \ 192 BHND_CHIP_ID(_cid), BHND_CHIP_REV(_rev) 193 194 /** 195 * A bhnd(4) board match descriptor. 196 */ 197 struct bhnd_board_match { 198 /** Select fields to be matched */ 199 union { 200 uint8_t match_flags; 201 struct { 202 uint8_t 203 board_vendor:1, 204 board_type:1, 205 board_rev:1, 206 board_srom_rev:1, 207 flags_unused:4; 208 } match; 209 } m; 210 211 uint16_t board_vendor; /**< required board vendor */ 212 uint16_t board_type; /**< required board type */ 213 struct bhnd_hwrev_match board_rev; /**< matching board revisions */ 214 struct bhnd_hwrev_match board_srom_rev; /**< matching board srom revisions */ 215 }; 216 217 #define _BHND_BOARD_MATCH_COPY(_src) \ 218 _BHND_COPY_MATCH_FIELD(_src, board_vendor), \ 219 _BHND_COPY_MATCH_FIELD(_src, board_type), \ 220 _BHND_COPY_MATCH_FIELD(_src, board_rev), \ 221 _BHND_COPY_MATCH_FIELD(_src, board_srom_rev) 222 223 /** Set the required board vendor within a bhnd match descriptor */ 224 #define BHND_MATCH_BOARD_VENDOR(_v) _BHND_SET_MATCH_FIELD(board_vendor, _v) 225 226 /** Set the required board type within a bhnd match descriptor */ 227 #define BHND_MATCH_BOARD_TYPE(_type) _BHND_SET_MATCH_FIELD(board_type, \ 228 BHND_BOARD_ ## _type) 229 /** Set the required SROM revision range within a bhnd match descriptor */ 230 #define BHND_MATCH_SROMREV(_rev) _BHND_SET_MATCH_FIELD(board_srom_rev, \ 231 BHND_HWREV_ ## _rev) 232 233 /** Set the required board revision range within a bhnd match descriptor */ 234 #define BHND_MATCH_BOARD_REV(_rev) _BHND_SET_MATCH_FIELD(board_rev, \ 235 BHND_ ## _rev) 236 237 /** Set the required board vendor and type within a bhnd match descriptor */ 238 #define BHND_MATCH_BOARD(_vend, _type) \ 239 BHND_MATCH_BOARD_VENDOR(_vend), BHND_MATCH_BOARD_TYPE(_type) 240 241 242 /** 243 * A bhnd(4) device match descriptor. 244 * 245 * @warning Matching on board attributes relies on NVRAM access, and will 246 * fail if a valid NVRAM device cannot be found, or is not yet attached. 247 */ 248 struct bhnd_device_match { 249 /** Select fields to be matched */ 250 union { 251 uint16_t match_flags; 252 struct { 253 uint16_t 254 core_vendor:1, 255 core_id:1, 256 core_rev:1, 257 core_class:1, 258 core_unit:1, 259 chip_id:1, 260 chip_rev:1, 261 chip_pkg:1, 262 board_vendor:1, 263 board_type:1, 264 board_rev:1, 265 board_srom_rev:1, 266 flags_unused:2; 267 } match; 268 } m; 269 270 uint16_t core_vendor; /**< required JEP106 device vendor */ 271 uint16_t core_id; /**< required core ID */ 272 struct bhnd_hwrev_match core_rev; /**< matching core revisions. */ 273 bhnd_devclass_t core_class; /**< required bhnd class */ 274 int core_unit; /**< required core unit */ 275 276 uint16_t chip_id; /**< required chip id */ 277 struct bhnd_hwrev_match chip_rev; /**< matching chip revisions */ 278 uint8_t chip_pkg; /**< required package */ 279 280 uint16_t board_vendor; /**< required board vendor */ 281 uint16_t board_type; /**< required board type */ 282 struct bhnd_hwrev_match board_rev; /**< matching board revisions */ 283 struct bhnd_hwrev_match board_srom_rev; /**< matching board srom revisions */ 284 }; 285 286 /** Define a wildcard match requirement (matches on any device). */ 287 #define BHND_MATCH_ANY .m.match_flags = 0 288 #define BHND_MATCH_IS_ANY(_m) \ 289 ((_m)->m.match_flags == 0) 290 291 #endif /* _BHND_BHND_MATCH_H_ */ 292