99#ifndef __SDCA_FUNCTION_H__
1010#define __SDCA_FUNCTION_H__
1111
12+ #include <linux/bitmap.h>
1213#include <linux/bits.h>
1314#include <linux/types.h>
1415#include <linux/hid.h>
@@ -48,6 +49,22 @@ struct sdca_function_desc;
4849 */
4950#define SDCA_MAX_AFFECTED_COUNT 2048
5051
52+ /*
53+ * Sanity limits for the DisCo Behavior Set library, can be expanded if
54+ * needed.
55+ */
56+ #define SDCA_MAX_BEHAVIOR_SET_COUNT 256
57+ #define SDCA_MAX_BEHAVIOR_COUNT 256
58+
59+ /* BitIndex controls use up to 64 Control Number bytes (SDCA 1.0 sec. 7.3.9). */
60+ #define SDCA_MAX_CONTROL_NUMBERS 64
61+ #define SDCA_MAX_BMT_BITS (SDCA_MAX_CONTROL_NUMBERS * BITS_PER_BYTE)
62+
63+ /* Generic BitIndex Mapping Table layout (SDCA 1.0 sec. 7.3.9.2, Fig. 114). */
64+ #define SDCA_BMT_COLS 3
65+ #define SDCA_BMT_BIT 0
66+ #define SDCA_BMT_BEHAVIOR_SET 1
67+
5168/**
5269 * enum sdca_function_type - SDCA Function Type codes
5370 * @SDCA_FUNCTION_TYPE_SMART_AMP: Amplifier with protection features.
@@ -787,6 +804,68 @@ struct sdca_control_range {
787804 u32 * data ;
788805};
789806
807+ /**
808+ * struct sdca_bmt_bits - selected BitIndex bits and their Control Numbers
809+ * @bits: Bitmap of selected bit positions in a BitIndex Mapping Table.
810+ * @control_numbers: Bitmap of Control Numbers containing selected bits.
811+ *
812+ * A BitIndex control is a set of byte controls, with one or more used bits
813+ * in each control. Each group of 8 bits in @bits corresponds to one byte
814+ * control. A bit is set in @bits if that control register bit is part of
815+ * the BMT.
816+ * (SDCA 1.0 Table 178, note 6: each Control Number holds eight BitIndex bits.)
817+ *
818+ * There is one bit in @control_numbers for each control. A bit is set in
819+ * @control_numbers if any of its bits is selected in @bits. This allows
820+ * quick iteration over only the Control Numbers.
821+ */
822+ struct sdca_bmt_bits {
823+ DECLARE_BITMAP (bits , SDCA_MAX_BMT_BITS );
824+ DECLARE_BITMAP (control_numbers , SDCA_MAX_CONTROL_NUMBERS );
825+ };
826+
827+ /**
828+ * sdca_for_each_bmt_control - iterate over Control Numbers selected in a BMT
829+ * @number: Loop variable containing the Control Number.
830+ * @bmt: Pointer to the BMT bitmaps.
831+ */
832+ #define sdca_for_each_bmt_control (number , bmt ) \
833+ for_each_set_bit(number, (bmt)->control_numbers, SDCA_MAX_CONTROL_NUMBERS)
834+
835+ /**
836+ * sdca_bmt_control_mask - get the selected bits for one Control Number
837+ * @bmt: BMT bitmaps containing the selected bits.
838+ * @number: Control Number.
839+ *
840+ * Return: An eight-bit mask of the selected bits in the control byte.
841+ */
842+ static inline u8 sdca_bmt_control_mask (const struct sdca_bmt_bits * bmt , unsigned int number )
843+ {
844+ return bitmap_get_value8 (bmt -> bits , number * BITS_PER_BYTE );
845+ }
846+
847+ /**
848+ * struct sdca_cbns - a list of Class Behavior Numbers
849+ * @cbns: Array of Class Behavior Numbers.
850+ * @num_cbns: Number of entries in @cbns.
851+ */
852+ struct sdca_cbns {
853+ const u32 * cbns ;
854+ int num_cbns ;
855+ };
856+
857+ /**
858+ * struct sdca_behavior_set - one entry in the DisCo Behavior Set library
859+ * @id: Behavior Set identifier.
860+ * @cbns: Class Behavior Numbers in this set.
861+ * @num_cbns: Number of entries in @cbns.
862+ */
863+ struct sdca_behavior_set {
864+ u32 id ;
865+ u32 * cbns ;
866+ int num_cbns ;
867+ };
868+
790869/**
791870 * struct sdca_control - information for one SDCA Control
792871 * @label: Name for the Control, from SDCA Specification v1.0, section 7.1.7.
@@ -1160,6 +1239,15 @@ struct sdca_entity_xu {
11601239 enum sdca_xu_reset_mechanism reset_mechanism ;
11611240};
11621241
1242+ /**
1243+ * struct sdca_entity_smpu - information specific to SMPU Entities
1244+ * @trigger_ready_max_delay: Host Trigger_Ready polling timeout in microseconds,
1245+ * clamped to at least 10 if described, or 0 if not described.
1246+ */
1247+ struct sdca_entity_smpu {
1248+ unsigned int trigger_ready_max_delay ;
1249+ };
1250+
11631251/**
11641252 * struct sdca_entity - information for one SDCA Entity
11651253 * @label: String such as "OT 12".
@@ -1177,6 +1265,7 @@ struct sdca_entity_xu {
11771265 * @ge: Group Entity specific Entity properties.
11781266 * @hide: HIDE Entity specific Entity properties.
11791267 * @xu: XU Entity specific Entity properties.
1268+ * @smpu: SMPU Entity specific Entity properties.
11801269 */
11811270struct sdca_entity {
11821271 const char * label ;
@@ -1195,6 +1284,7 @@ struct sdca_entity {
11951284 struct sdca_entity_ge ge ;
11961285 struct sdca_entity_hide hide ;
11971286 struct sdca_entity_xu xu ;
1287+ struct sdca_entity_smpu smpu ;
11981288 };
11991289};
12001290
@@ -1413,9 +1503,11 @@ struct sdca_function_hid {
14131503 * @init_table: Pointer to a table of initialization writes.
14141504 * @entities: Dynamically allocated array of Entities.
14151505 * @clusters: Dynamically allocated array of Channel Clusters.
1506+ * @behavior_sets: Dynamically allocated array of Behavior Sets.
14161507 * @num_init_table: Number of initialization writes.
14171508 * @num_entities: Number of Entities reported in this Function.
14181509 * @num_clusters: Number of Channel Clusters reported in this Function.
1510+ * @num_behavior_sets: Number of Behavior Sets reported in this Function.
14191511 * @busy_max_delay: Maximum Function busy delay in microseconds, before an
14201512 * error should be reported.
14211513 * @reset_max_delay: Maximum Function reset delay in microseconds, before an
@@ -1429,9 +1521,11 @@ struct sdca_function_data {
14291521 struct sdca_init_write * init_table ;
14301522 struct sdca_entity * entities ;
14311523 struct sdca_cluster * clusters ;
1524+ struct sdca_behavior_set * behavior_sets ;
14321525 int num_init_table ;
14331526 int num_entities ;
14341527 int num_clusters ;
1528+ int num_behavior_sets ;
14351529
14361530 unsigned int busy_max_delay ;
14371531 unsigned int reset_max_delay ;
@@ -1443,7 +1537,7 @@ struct sdca_function_data {
14431537 };
14441538};
14451539
1446- static inline u32 sdca_range (struct sdca_control_range * range ,
1540+ static inline u32 sdca_range (const struct sdca_control_range * range ,
14471541 unsigned int col , unsigned int row )
14481542{
14491543 return range -> data [(row * range -> cols ) + col ];
@@ -1467,10 +1561,10 @@ int sdca_parse_function(struct device *dev, struct sdca_function_data *function)
14671561const char * sdca_find_terminal_name (enum sdca_terminal_type type );
14681562
14691563struct sdca_control * sdca_selector_find_control (struct device * dev ,
1470- struct sdca_entity * entity ,
1564+ const struct sdca_entity * entity ,
14711565 const int sel );
14721566struct sdca_control_range * sdca_control_find_range (struct device * dev ,
1473- struct sdca_entity * entity ,
1567+ const struct sdca_entity * entity ,
14741568 struct sdca_control * control ,
14751569 int cols , int rows );
14761570struct sdca_control_range * sdca_selector_find_range (struct device * dev ,
@@ -1479,7 +1573,14 @@ struct sdca_control_range *sdca_selector_find_range(struct device *dev,
14791573struct sdca_cluster * sdca_id_find_cluster (struct device * dev ,
14801574 struct sdca_function_data * function ,
14811575 const int id );
1482- struct sdca_entity * sdca_find_entity_by_label (struct sdca_function_data * function ,
1483- const char * entity_label );
1576+ struct sdca_entity * sdca_find_entity_by_label (const struct sdca_function_data * function ,
1577+ const char * entity_label );
1578+ struct sdca_behavior_set * sdca_find_behavior_set (const struct sdca_function_data * function ,
1579+ unsigned int id );
1580+ bool sdca_behavior_set_contains_cbn (const struct sdca_behavior_set * set ,
1581+ const struct sdca_cbns * cbns );
1582+ int sdca_lookup_bmt_bits (struct device * dev , const struct sdca_function_data * function ,
1583+ const struct sdca_entity * entity , struct sdca_control * control ,
1584+ const struct sdca_cbns * cbns , struct sdca_bmt_bits * bmt );
14841585
14851586#endif
0 commit comments