/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2015-2016 Landon Fuller <[email protected]>4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer,11* without modification.12* 2. Redistributions in binary form must reproduce at minimum a disclaimer13* similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any14* redistribution must be conditioned upon including a substantially15* similar Disclaimer requirement for further binary redistribution.16*17* NO WARRANTY18* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS19* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT20* LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY21* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL22* THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,23* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF24* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS25* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER26* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)27* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF28* THE POSSIBILITY OF SUCH DAMAGES.29*30*/3132#ifndef _BHND_BHND_MATCH_H_33#define _BHND_BHND_MATCH_H_3435#include "bhnd_types.h"3637/**38* A hardware revision match descriptor.39*/40struct bhnd_hwrev_match {41uint16_t start; /**< first revision, or BHND_HWREV_INVALID42to match on any revision. */43uint16_t end; /**< last revision, or BHND_HWREV_INVALID44to match on any revision. */45};4647/* 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)->_name5152/* Set match field @p _name with @p _value */53#define _BHND_SET_MATCH_FIELD(_name, _value) \54.m.match._name = 1, ._name = _value5556/**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)6263/**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_INVALID68* to match on any revision.69*/70#define BHND_HWREV_RANGE(_start, _end) { _start, _end }7172/**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)7879/**80* Hardware revision match descriptor for any revision equal to or greater81* 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)8687/**88* Hardware revision match descriptor for any revision equal to or less89* 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)9495/**96* A bhnd(4) core match descriptor.97*/98struct bhnd_core_match {99/** Select fields to be matched */100union {101uint8_t match_flags;102struct {103uint8_t104core_vendor:1,105core_id:1,106core_rev:1,107core_class:1,108core_idx:1,109core_unit:1,110flags_unused:2;111} match;112} m;113114uint16_t core_vendor; /**< required JEP106 device vendor */115uint16_t core_id; /**< required core ID */116struct bhnd_hwrev_match core_rev; /**< matching core revisions. */117bhnd_devclass_t core_class; /**< required bhnd class */118u_int core_idx; /**< required core index */119int core_unit; /**< required core unit */120};121122#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) \129130#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, \133BHND_ ## _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)137138/**139* Match against the given @p _vendor and @p _id,140*/141#define BHND_MATCH_CORE(_vendor, _id) \142BHND_MATCH_CORE_VENDOR(_vendor), \143BHND_MATCH_CORE_ID(_id)144145/**146* A bhnd(4) chip match descriptor.147*/148struct bhnd_chip_match {149/** Select fields to be matched */150union {151uint8_t match_flags;152struct {153uint8_t154chip_id:1,155chip_rev:1,156chip_pkg:1,157chip_type:1,158flags_unused:4;159} match;160161} m;162163uint16_t chip_id; /**< required chip id */164struct bhnd_hwrev_match chip_rev; /**< matching chip revisions */165uint8_t chip_pkg; /**< required package */166uint8_t chip_type; /**< required chip type (BHND_CHIPTYPE_*) */167};168169#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),\174175/** Set the required chip ID within a bhnd match descriptor */176#define BHND_MATCH_CHIP_ID(_cid) _BHND_SET_MATCH_FIELD(chip_id, \177BHND_CHIPID_ ## _cid)178179/** Set the required chip revision range within a bhnd match descriptor */180#define BHND_MATCH_CHIP_REV(_rev) _BHND_SET_MATCH_FIELD(chip_rev, \181BHND_ ## _rev)182183/** Set the required package ID within a bhnd match descriptor */184#define BHND_MATCH_CHIP_PKG(_pkg) _BHND_SET_MATCH_FIELD(chip_pkg, \185BHND_PKGID_ ## _pkg)186187/** Set the required chip type within a bhnd match descriptor */188#define BHND_MATCH_CHIP_TYPE(_type) _BHND_SET_MATCH_FIELD(chip_type, \189BHND_CHIPTYPE_ ## _type)190191/** Set the required chip and package ID within a bhnd match descriptor */192#define BHND_MATCH_CHIP_IP(_cid, _pkg) \193BHND_MATCH_CHIP_ID(_cid), BHND_MATCH_CHIP_PKG(_pkg)194195/** Set the required chip ID, package ID, and revision within a bhnd_device_match196* instance */197#define BHND_MATCH_CHIP_IPR(_cid, _pkg, _rev) \198BHND_MATCH_CHIP_ID(_cid), \199BHND_MATCH_CHIP_PKG(_pkg), \200BHND_MATCH_CHIP_REV(_rev)201202/** Set the required chip ID and revision within a bhnd_device_match203* instance */204#define BHND_MATCH_CHIP_IR(_cid, _rev) \205BHND_MATCH_CHIP_ID(_cid), BHND_MATCH_CHIP_REV(_rev)206207/**208* A bhnd(4) board match descriptor.209*/210struct bhnd_board_match {211/** Select fields to be matched */212union {213uint8_t match_flags;214struct {215uint8_t216board_vendor:1,217board_type:1,218board_devid:1,219board_rev:1,220board_srom_rev:1,221flags_unused:3;222} match;223} m;224225uint16_t board_vendor; /**< required board vendor */226uint16_t board_type; /**< required board type */227uint16_t board_devid; /**< required board devid */228struct bhnd_hwrev_match board_rev; /**< matching board revisions */229struct bhnd_hwrev_match board_srom_rev; /**< matching board srom revisions */230};231232#define _BHND_BOARD_MATCH_COPY(_src) \233_BHND_COPY_MATCH_FIELD(_src, board_vendor), \234_BHND_COPY_MATCH_FIELD(_src, board_type), \235_BHND_COPY_MATCH_FIELD(_src, board_devid), \236_BHND_COPY_MATCH_FIELD(_src, board_rev), \237_BHND_COPY_MATCH_FIELD(_src, board_srom_rev)238239/** Set the required board vendor within a bhnd match descriptor */240#define BHND_MATCH_BOARD_VENDOR(_v) _BHND_SET_MATCH_FIELD(board_vendor, _v)241242/** Set the required board type within a bhnd match descriptor */243#define BHND_MATCH_BOARD_TYPE(_type) _BHND_SET_MATCH_FIELD(board_type, \244BHND_BOARD_ ## _type)245246/** Set the required board devid within a bhnd match descriptor */247#define BHND_MATCH_BOARD_DEVID(_devid) _BHND_SET_MATCH_FIELD(board_devid, \248(_devid))249250/** Set the required SROM revision range within a bhnd match descriptor */251#define BHND_MATCH_SROMREV(_rev) _BHND_SET_MATCH_FIELD(board_srom_rev, \252BHND_HWREV_ ## _rev)253254/** Set the required board revision range within a bhnd match descriptor */255#define BHND_MATCH_BOARD_REV(_rev) _BHND_SET_MATCH_FIELD(board_rev, \256BHND_ ## _rev)257258/** Set the required board vendor and type within a bhnd match descriptor */259#define BHND_MATCH_BOARD(_vend, _type) \260BHND_MATCH_BOARD_VENDOR(_vend), BHND_MATCH_BOARD_TYPE(_type)261262/**263* A bhnd(4) device match descriptor.264*265* @warning Matching on board attributes relies on NVRAM access, and will266* fail if a valid NVRAM device cannot be found, or is not yet attached.267*/268struct bhnd_device_match {269/** Select fields to be matched */270union {271uint32_t match_flags;272struct {273uint32_t274core_vendor:1,275core_id:1,276core_rev:1,277core_class:1,278core_idx:1,279core_unit:1,280chip_id:1,281chip_rev:1,282chip_pkg:1,283chip_type:1,284board_vendor:1,285board_type:1,286board_devid:1,287board_rev:1,288board_srom_rev:1,289flags_unused:15;290} match;291} m;292293uint16_t core_vendor; /**< required JEP106 device vendor */294uint16_t core_id; /**< required core ID */295struct bhnd_hwrev_match core_rev; /**< matching core revisions. */296bhnd_devclass_t core_class; /**< required bhnd class */297u_int core_idx; /**< required core index */298int core_unit; /**< required core unit */299300uint16_t chip_id; /**< required chip id */301struct bhnd_hwrev_match chip_rev; /**< matching chip revisions */302uint8_t chip_pkg; /**< required package */303uint8_t chip_type; /**< required chip type (BHND_CHIPTYPE_*) */304305uint16_t board_vendor; /**< required board vendor */306uint16_t board_type; /**< required board type */307uint16_t board_devid; /**< required board devid */308struct bhnd_hwrev_match board_rev; /**< matching board revisions */309struct bhnd_hwrev_match board_srom_rev; /**< matching board srom revisions */310};311312/** Define a wildcard match requirement (matches on any device). */313#define BHND_MATCH_ANY .m.match_flags = 0314#define BHND_MATCH_IS_ANY(_m) \315((_m)->m.match_flags == 0)316317#endif /* _BHND_BHND_MATCH_H_ */318319320