diff options
author | Adrian Chadd <adrian@FreeBSD.org> | 2016-04-19 15:56:39 +0000 |
---|---|---|
committer | Adrian Chadd <adrian@FreeBSD.org> | 2016-04-19 15:56:39 +0000 |
commit | 36e4410ab0aa435639556b39dac37fb9f90cd962 (patch) | |
tree | 719fc09d561193dbb55ff9d9b8ca4bcba654f7ae /sys/dev/bhnd/bhnd.h | |
parent | 386fb140a6ffdae9b5229269456897816809fbf3 (diff) | |
download | src-36e4410ab0aa435639556b39dac37fb9f90cd962.tar.gz src-36e4410ab0aa435639556b39dac37fb9f90cd962.zip |
[bhnd] Standardize bhnd device tables and quirk matching.
This add a bhnd device table mechanism that standardizes matching of
devices on the bhnd(4) bus, discovery of device quirk flags, and should
be pluggable into the new PNPINFO machinery.
Submitted by: Landon Fuller <landonf@landonf.org>
Differential Revision: https://reviews.freebsd.org/D5759
Notes
Notes:
svn path=/head/; revision=298278
Diffstat (limited to 'sys/dev/bhnd/bhnd.h')
-rw-r--r-- | sys/dev/bhnd/bhnd.h | 128 |
1 files changed, 84 insertions, 44 deletions
diff --git a/sys/dev/bhnd/bhnd.h b/sys/dev/bhnd/bhnd.h index 7548c8a4dbce..5a3e9926f00c 100644 --- a/sys/dev/bhnd/bhnd.h +++ b/sys/dev/bhnd/bhnd.h @@ -167,72 +167,104 @@ struct bhnd_hwrev_match { /** * Wildcard hardware revision match descriptor. */ -#define BHND_HWREV_MATCH_ANY { BHND_HWREV_INVALID, BHND_HWREV_INVALID } - - -/** A core match descriptor. */ -struct bhnd_core_match { - uint16_t vendor; /**< required JEP106 device vendor or BHND_MFGID_INVALID. */ - uint16_t device; /**< required core ID or BHND_COREID_INVALID */ - struct bhnd_hwrev_match hwrev; /**< matching revisions. */ - bhnd_devclass_t class; /**< required class or BHND_DEVCLASS_INVALID */ - int unit; /**< required core unit, or -1 */ -}; - - -/** - * Revision-specific hardware quirk descriptor. - * - * Defines a set of quirk flags applicable to a range of hardware - * revisions. - */ -struct bhnd_device_quirk { - struct bhnd_hwrev_match hwrev; /**< applicable hardware revisions */ - uint32_t quirks; /**< applicable quirk flags */ -}; +#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) /** - * Define a bhnd_device_quirk over a range of hardware revisions. + * 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. - * @param _quirks Quirk flags applicable to this revision range. */ -#define BHND_QUIRK_HWREV_RANGE(_start, _end, _quirks) \ - { .hwrev = { _start, _end }, .quirks = _quirks } +#define BHND_HWREV_RANGE(_start, _end) { _start, _end } /** - * Define a bhnd_device_quirk for a specific hardware revision. + * Hardware revision match descriptor for a single revision. * * @param _hwrev The hardware revision to match on. - * @param _quirks Quirk flags applicable to this revision. */ -#define BHND_QUIRK_HWREV_EQ(_hwrev, _quirks) \ - BHND_QUIRK_HWREV_RANGE(_hwrev, _hwrev, _quirks) +#define BHND_HWREV_EQ(_hwrev) BHND_HWREV_RANGE(_hwrev, _hwrev) /** - * Define a bhnd_device_quirk for any hardware revision equal or greater + * Hardware revision match descriptor for any revision equal to or greater * than @p _start. * * @param _start The first hardware revision to match on. - * @param _quirks Quirk flags applicable to this revision. */ -#define BHND_QUIRK_HWREV_GTE(_start, _quirks) \ - BHND_QUIRK_HWREV_RANGE(_start, BHND_HWREV_INVALID, _quirks) +#define BHND_HWREV_GTE(_start) BHND_HWREV_RANGE(_start, BHND_HWREV_INVALID) /** - * Define a bhnd_device_quirk for any hardware revision equal or less + * Hardware revision match descriptor for any revision equal to or less * than @p _end. * * @param _end The last hardware revision to match on. - * @param _quirks Quirk flags applicable to this revision. */ -#define BHND_QUIRK_HWREV_LTE(_end, _quirks) \ - BHND_QUIRK_HWREV_RANGE(0, _end, _quirks) +#define BHND_HWREV_LTE(_end) BHND_HWREV_RANGE(0, _end) -/** Mark the end of a bhnd_device_quirk table. */ -#define BHND_QUIRK_HWREV_END { BHND_HWREV_MATCH_ANY, 0 } + +/** A core match descriptor. */ +struct bhnd_core_match { + uint16_t vendor; /**< required JEP106 device vendor or BHND_MFGID_INVALID. */ + uint16_t device; /**< required core ID or BHND_COREID_INVALID */ + struct bhnd_hwrev_match hwrev; /**< matching revisions. */ + bhnd_devclass_t class; /**< required class or BHND_DEVCLASS_INVALID */ + int unit; /**< required core unit, or -1 */ +}; + +/** + * Core match descriptor matching against the given @p _vendor, @p _device, + * and @p _hwrev match descriptors. + */ +#define BHND_CORE_MATCH(_vendor, _device, _hwrev) \ + { _vendor, _device, _hwrev, BHND_DEVCLASS_INVALID, -1 } + +/** + * Wildcard core match descriptor. + */ +#define BHND_CORE_MATCH_ANY \ + { \ + .vendor = BHND_MFGID_INVALID, \ + .device = BHND_COREID_INVALID, \ + .hwrev = BHND_HWREV_ANY, \ + .class = BHND_DEVCLASS_INVALID, \ + .unit = -1 \ + } + +/** + * Device quirk table descriptor. + */ +struct bhnd_device_quirk { + struct bhnd_hwrev_match hwrev; /**< applicable hardware revisions */ + uint32_t quirks; /**< quirk flags */ +}; +#define BHND_DEVICE_QUIRK_END { BHND_HWREV_ANY, 0 } +#define BHND_DEVICE_QUIRK_IS_END(_q) \ + (BHND_HWREV_IS_ANY(&(_q)->hwrev) && (_q)->quirks == 0) + +enum { + BHND_DF_ANY = 0, + BHND_DF_HOSTB = (1<<0) /**< core is serving as the bus' + * host bridge */ +}; + +/** Device probe table descriptor */ +struct bhnd_device { + const struct bhnd_core_match core; /**< core match descriptor */ + const char *desc; /**< device description, or NULL. */ + const struct bhnd_device_quirk *quirks_table; /**< quirks table for this device, or NULL */ + uint32_t device_flags; /**< required BHND_DF_* flags */ +}; + +#define _BHND_DEVICE(_device, _desc, _quirks, _flags, ...) \ + { BHND_CORE_MATCH(BHND_MFGID_BCM, BHND_COREID_ ## _device, \ + BHND_HWREV_ANY), _desc, _quirks, _flags } + +#define BHND_DEVICE(_device, _desc, _quirks, ...) \ + _BHND_DEVICE(_device, _desc, _quirks, ## __VA_ARGS__, 0) + +#define BHND_DEVICE_END { BHND_CORE_MATCH_ANY, NULL, NULL, 0 } const char *bhnd_vendor_name(uint16_t vendor); const char *bhnd_port_type_name(bhnd_port_type port_type); @@ -271,6 +303,14 @@ bool bhnd_hwrev_matches(uint16_t hwrev, bool bhnd_device_matches(device_t dev, const struct bhnd_core_match *desc); +const struct bhnd_device *bhnd_device_lookup(device_t dev, + const struct bhnd_device *table, + size_t entry_size); + +uint32_t bhnd_device_quirks(device_t dev, + const struct bhnd_device *table, + size_t entry_size); + struct bhnd_core_info bhnd_get_core_info(device_t dev); @@ -290,9 +330,9 @@ int bhnd_read_chipid(device_t dev, bus_size_t chipc_offset, struct bhnd_chipid *result); -void bhnd_set_generic_core_desc(device_t dev); - - +void bhnd_set_custom_core_desc(device_t dev, + const char *name); +void bhnd_set_default_core_desc(device_t dev); bool bhnd_bus_generic_is_hostb_device(device_t dev, |