@@ -17,6 +17,8 @@ struct regmap_test_priv {
17
17
struct regmap_test_param {
18
18
enum regcache_type cache ;
19
19
enum regmap_endian val_endian ;
20
+
21
+ unsigned int from_reg ;
20
22
};
21
23
22
24
static 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)
37
39
}
38
40
39
41
static const struct regmap_config test_regmap_config = {
40
- .max_register = BLOCK_TEST_SIZE ,
41
42
.reg_stride = 1 ,
42
43
.val_bits = sizeof (unsigned int ) * 8 ,
43
44
};
@@ -76,9 +77,10 @@ static const char *regmap_endian_name(enum regmap_endian endian)
76
77
77
78
static void param_to_desc (const struct regmap_test_param * param , char * desc )
78
79
{
79
- snprintf (desc , KUNIT_PARAM_DESC_SIZE , "%s-%s" ,
80
+ snprintf (desc , KUNIT_PARAM_DESC_SIZE , "%s-%s @%#x " ,
80
81
regcache_type_name (param -> cache ),
81
- regmap_endian_name (param -> val_endian ));
82
+ regmap_endian_name (param -> val_endian ),
83
+ param -> from_reg );
82
84
}
83
85
84
86
static const struct regmap_test_param regcache_types_list [] = {
@@ -99,8 +101,16 @@ static const struct regmap_test_param real_cache_types_list[] = {
99
101
KUNIT_ARRAY_PARAM (real_cache_types , real_cache_types_list , param_to_desc );
100
102
101
103
static 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 },
104
114
};
105
115
106
116
KUNIT_ARRAY_PARAM (sparse_cache_types , sparse_cache_types_list , param_to_desc );
@@ -113,14 +123,24 @@ static struct regmap *gen_regmap(struct kunit *test,
113
123
struct regmap_test_priv * priv = test -> priv ;
114
124
unsigned int * buf ;
115
125
struct regmap * ret ;
116
- size_t size = ( config -> max_register + 1 ) * sizeof ( unsigned int ) ;
126
+ size_t size ;
117
127
int i ;
118
128
struct reg_default * defaults ;
119
129
120
130
config -> cache_type = param -> cache ;
121
131
config -> disable_locking = config -> cache_type == REGCACHE_RBTREE ||
122
132
config -> cache_type == REGCACHE_MAPLE ;
123
133
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 );
124
144
buf = kmalloc (size , GFP_KERNEL );
125
145
if (!buf )
126
146
return ERR_PTR (- ENOMEM );
@@ -141,8 +161,8 @@ static struct regmap *gen_regmap(struct kunit *test,
141
161
config -> reg_defaults = defaults ;
142
162
143
163
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 ) ];
146
166
}
147
167
}
148
168
@@ -832,6 +852,7 @@ static void cache_sync_patch(struct kunit *test)
832
852
833
853
static void cache_drop (struct kunit * test )
834
854
{
855
+ const struct regmap_test_param * param = test -> param_value ;
835
856
struct regmap * map ;
836
857
struct regmap_config config ;
837
858
struct regmap_ram_data * data ;
@@ -848,30 +869,32 @@ static void cache_drop(struct kunit *test)
848
869
849
870
/* Ensure the data is read from the cache */
850
871
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 ,
853
874
BLOCK_TEST_SIZE ));
854
875
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;
857
878
}
858
- KUNIT_EXPECT_MEMEQ (test , data -> vals , rval , sizeof (rval ));
879
+ KUNIT_EXPECT_MEMEQ (test , & data -> vals [ param -> from_reg ] , rval , sizeof (rval ));
859
880
860
881
/* 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 ));
862
884
863
885
/* 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 ,
865
887
BLOCK_TEST_SIZE ));
866
888
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 ));
869
891
870
892
regmap_exit (map );
871
893
}
872
894
873
895
static void cache_present (struct kunit * test )
874
896
{
897
+ const struct regmap_test_param * param = test -> param_value ;
875
898
struct regmap * map ;
876
899
struct regmap_config config ;
877
900
struct regmap_ram_data * data ;
@@ -886,23 +909,23 @@ static void cache_present(struct kunit *test)
886
909
return ;
887
910
888
911
for (i = 0 ; i < BLOCK_TEST_SIZE ; i ++ )
889
- data -> read [i ] = false;
912
+ data -> read [param -> from_reg + i ] = false;
890
913
891
914
/* No defaults so no registers cached. */
892
915
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 ));
894
917
895
918
/* We didn't trigger any reads */
896
919
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 ]);
898
921
899
922
/* Fill the cache */
900
923
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 ));
902
925
903
926
/* Now everything should be cached */
904
927
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 ));
906
929
907
930
regmap_exit (map );
908
931
}
0 commit comments