@@ -17,6 +17,8 @@ struct regmap_test_priv {
1717struct regmap_test_param {
1818 enum regcache_type cache ;
1919 enum regmap_endian val_endian ;
20+
21+ unsigned int from_reg ;
2022};
2123
2224static void get_changed_bytes (void * orig , void * new , size_t size )
@@ -37,7 +39,6 @@ static void get_changed_bytes(void *orig, void *new, size_t size)
3739}
3840
3941static const struct regmap_config test_regmap_config = {
40- .max_register = BLOCK_TEST_SIZE ,
4142 .reg_stride = 1 ,
4243 .val_bits = sizeof (unsigned int ) * 8 ,
4344};
@@ -76,9 +77,10 @@ static const char *regmap_endian_name(enum regmap_endian endian)
7677
7778static void param_to_desc (const struct regmap_test_param * param , char * desc )
7879{
79- snprintf (desc , KUNIT_PARAM_DESC_SIZE , "%s-%s" ,
80+ snprintf (desc , KUNIT_PARAM_DESC_SIZE , "%s-%s @%#x " ,
8081 regcache_type_name (param -> cache ),
81- regmap_endian_name (param -> val_endian ));
82+ regmap_endian_name (param -> val_endian ),
83+ param -> from_reg );
8284}
8385
8486static const struct regmap_test_param regcache_types_list [] = {
@@ -99,8 +101,16 @@ static const struct regmap_test_param real_cache_types_list[] = {
99101KUNIT_ARRAY_PARAM (real_cache_types , real_cache_types_list , param_to_desc );
100102
101103static const struct regmap_test_param sparse_cache_types_list [] = {
102- { .cache = REGCACHE_RBTREE },
103- { .cache = REGCACHE_MAPLE },
104+ { .cache = REGCACHE_RBTREE , .from_reg = 0 },
105+ { .cache = REGCACHE_RBTREE , .from_reg = 0x2001 },
106+ { .cache = REGCACHE_RBTREE , .from_reg = 0x2002 },
107+ { .cache = REGCACHE_RBTREE , .from_reg = 0x2003 },
108+ { .cache = REGCACHE_RBTREE , .from_reg = 0x2004 },
109+ { .cache = REGCACHE_MAPLE , .from_reg = 0 },
110+ { .cache = REGCACHE_MAPLE , .from_reg = 0x2001 },
111+ { .cache = REGCACHE_MAPLE , .from_reg = 0x2002 },
112+ { .cache = REGCACHE_MAPLE , .from_reg = 0x2003 },
113+ { .cache = REGCACHE_MAPLE , .from_reg = 0x2004 },
104114};
105115
106116KUNIT_ARRAY_PARAM (sparse_cache_types , sparse_cache_types_list , param_to_desc );
@@ -113,14 +123,24 @@ static struct regmap *gen_regmap(struct kunit *test,
113123 struct regmap_test_priv * priv = test -> priv ;
114124 unsigned int * buf ;
115125 struct regmap * ret ;
116- size_t size = ( config -> max_register + 1 ) * sizeof ( unsigned int ) ;
126+ size_t size ;
117127 int i ;
118128 struct reg_default * defaults ;
119129
120130 config -> cache_type = param -> cache ;
121131 config -> disable_locking = config -> cache_type == REGCACHE_RBTREE ||
122132 config -> cache_type == REGCACHE_MAPLE ;
123133
134+ if (config -> max_register == 0 ) {
135+ config -> max_register = param -> from_reg ;
136+ if (config -> num_reg_defaults )
137+ config -> max_register += (config -> num_reg_defaults - 1 ) *
138+ config -> reg_stride ;
139+ else
140+ config -> max_register += (BLOCK_TEST_SIZE * config -> reg_stride );
141+ }
142+
143+ size = (config -> max_register + 1 ) * sizeof (unsigned int );
124144 buf = kmalloc (size , GFP_KERNEL );
125145 if (!buf )
126146 return ERR_PTR (- ENOMEM );
@@ -141,8 +161,8 @@ static struct regmap *gen_regmap(struct kunit *test,
141161 config -> reg_defaults = defaults ;
142162
143163 for (i = 0 ; i < config -> num_reg_defaults ; i ++ ) {
144- defaults [i ].reg = i * config -> reg_stride ;
145- defaults [i ].def = buf [i * config -> reg_stride ];
164+ defaults [i ].reg = param -> from_reg + ( i * config -> reg_stride ) ;
165+ defaults [i ].def = buf [param -> from_reg + ( i * config -> reg_stride ) ];
146166 }
147167 }
148168
@@ -832,6 +852,7 @@ static void cache_sync_patch(struct kunit *test)
832852
833853static void cache_drop (struct kunit * test )
834854{
855+ const struct regmap_test_param * param = test -> param_value ;
835856 struct regmap * map ;
836857 struct regmap_config config ;
837858 struct regmap_ram_data * data ;
@@ -848,30 +869,32 @@ static void cache_drop(struct kunit *test)
848869
849870 /* Ensure the data is read from the cache */
850871 for (i = 0 ; i < BLOCK_TEST_SIZE ; i ++ )
851- data -> read [i ] = false;
852- KUNIT_EXPECT_EQ (test , 0 , regmap_bulk_read (map , 0 , rval ,
872+ data -> read [param -> from_reg + i ] = false;
873+ KUNIT_EXPECT_EQ (test , 0 , regmap_bulk_read (map , param -> from_reg , rval ,
853874 BLOCK_TEST_SIZE ));
854875 for (i = 0 ; i < BLOCK_TEST_SIZE ; i ++ ) {
855- KUNIT_EXPECT_FALSE (test , data -> read [i ]);
856- data -> read [i ] = false;
876+ KUNIT_EXPECT_FALSE (test , data -> read [param -> from_reg + i ]);
877+ data -> read [param -> from_reg + i ] = false;
857878 }
858- KUNIT_EXPECT_MEMEQ (test , data -> vals , rval , sizeof (rval ));
879+ KUNIT_EXPECT_MEMEQ (test , & data -> vals [ param -> from_reg ] , rval , sizeof (rval ));
859880
860881 /* Drop some registers */
861- KUNIT_EXPECT_EQ (test , 0 , regcache_drop_region (map , 3 , 5 ));
882+ KUNIT_EXPECT_EQ (test , 0 , regcache_drop_region (map , param -> from_reg + 3 ,
883+ param -> from_reg + 5 ));
862884
863885 /* Reread and check only the dropped registers hit the device. */
864- KUNIT_EXPECT_EQ (test , 0 , regmap_bulk_read (map , 0 , rval ,
886+ KUNIT_EXPECT_EQ (test , 0 , regmap_bulk_read (map , param -> from_reg , rval ,
865887 BLOCK_TEST_SIZE ));
866888 for (i = 0 ; i < BLOCK_TEST_SIZE ; i ++ )
867- KUNIT_EXPECT_EQ (test , data -> read [i ], i >= 3 && i <= 5 );
868- KUNIT_EXPECT_MEMEQ (test , data -> vals , rval , sizeof (rval ));
889+ KUNIT_EXPECT_EQ (test , data -> read [param -> from_reg + i ], i >= 3 && i <= 5 );
890+ KUNIT_EXPECT_MEMEQ (test , & data -> vals [ param -> from_reg ] , rval , sizeof (rval ));
869891
870892 regmap_exit (map );
871893}
872894
873895static void cache_present (struct kunit * test )
874896{
897+ const struct regmap_test_param * param = test -> param_value ;
875898 struct regmap * map ;
876899 struct regmap_config config ;
877900 struct regmap_ram_data * data ;
@@ -886,23 +909,23 @@ static void cache_present(struct kunit *test)
886909 return ;
887910
888911 for (i = 0 ; i < BLOCK_TEST_SIZE ; i ++ )
889- data -> read [i ] = false;
912+ data -> read [param -> from_reg + i ] = false;
890913
891914 /* No defaults so no registers cached. */
892915 for (i = 0 ; i < BLOCK_TEST_SIZE ; i ++ )
893- KUNIT_ASSERT_FALSE (test , regcache_reg_cached (map , i ));
916+ KUNIT_ASSERT_FALSE (test , regcache_reg_cached (map , param -> from_reg + i ));
894917
895918 /* We didn't trigger any reads */
896919 for (i = 0 ; i < BLOCK_TEST_SIZE ; i ++ )
897- KUNIT_ASSERT_FALSE (test , data -> read [i ]);
920+ KUNIT_ASSERT_FALSE (test , data -> read [param -> from_reg + i ]);
898921
899922 /* Fill the cache */
900923 for (i = 0 ; i < BLOCK_TEST_SIZE ; i ++ )
901- KUNIT_EXPECT_EQ (test , 0 , regmap_read (map , i , & val ));
924+ KUNIT_EXPECT_EQ (test , 0 , regmap_read (map , param -> from_reg + i , & val ));
902925
903926 /* Now everything should be cached */
904927 for (i = 0 ; i < BLOCK_TEST_SIZE ; i ++ )
905- KUNIT_ASSERT_TRUE (test , regcache_reg_cached (map , i ));
928+ KUNIT_ASSERT_TRUE (test , regcache_reg_cached (map , param -> from_reg + i ));
906929
907930 regmap_exit (map );
908931}
0 commit comments