@@ -1186,6 +1186,82 @@ static void __init of_unittest_reg(void)
1186
1186
of_node_put (np );
1187
1187
}
1188
1188
1189
+ struct of_unittest_expected_res {
1190
+ int index ;
1191
+ struct resource res ;
1192
+ };
1193
+
1194
+ static void __init of_unittest_check_addr (const char * node_path ,
1195
+ const struct of_unittest_expected_res * tab_exp ,
1196
+ unsigned int tab_exp_count )
1197
+ {
1198
+ const struct of_unittest_expected_res * expected ;
1199
+ struct device_node * np ;
1200
+ struct resource res ;
1201
+ unsigned int count ;
1202
+ int ret ;
1203
+
1204
+ if (!IS_ENABLED (CONFIG_OF_ADDRESS ))
1205
+ return ;
1206
+
1207
+ np = of_find_node_by_path (node_path );
1208
+ if (!np ) {
1209
+ pr_err ("missing testcase data (%s)\n" , node_path );
1210
+ return ;
1211
+ }
1212
+
1213
+ expected = tab_exp ;
1214
+ count = tab_exp_count ;
1215
+ while (count -- ) {
1216
+ ret = of_address_to_resource (np , expected -> index , & res );
1217
+ unittest (!ret , "of_address_to_resource(%pOF, %d) returned error %d\n" ,
1218
+ np , expected -> index , ret );
1219
+ unittest (resource_type (& res ) == resource_type (& expected -> res ) &&
1220
+ res .start == expected -> res .start &&
1221
+ resource_size (& res ) == resource_size (& expected -> res ),
1222
+ "of_address_to_resource(%pOF, %d) wrong resource %pR, expected %pR\n" ,
1223
+ np , expected -> index , & res , & expected -> res );
1224
+ expected ++ ;
1225
+ }
1226
+
1227
+ of_node_put (np );
1228
+ }
1229
+
1230
+ static const struct of_unittest_expected_res of_unittest_reg_2cell_expected_res [] = {
1231
+ {.index = 0 , .res = DEFINE_RES_MEM (0xa0a01000 , 0x100 ) },
1232
+ {.index = 1 , .res = DEFINE_RES_MEM (0xa0a02000 , 0x100 ) },
1233
+ {.index = 2 , .res = DEFINE_RES_MEM (0xc0c01000 , 0x100 ) },
1234
+ {.index = 3 , .res = DEFINE_RES_MEM (0xd0d01000 , 0x100 ) },
1235
+ };
1236
+
1237
+ static const struct of_unittest_expected_res of_unittest_reg_3cell_expected_res [] = {
1238
+ {.index = 0 , .res = DEFINE_RES_MEM (0xa0a01000 , 0x100 ) },
1239
+ {.index = 1 , .res = DEFINE_RES_MEM (0xa0b02000 , 0x100 ) },
1240
+ {.index = 2 , .res = DEFINE_RES_MEM (0xc0c01000 , 0x100 ) },
1241
+ {.index = 3 , .res = DEFINE_RES_MEM (0xc0c09000 , 0x100 ) },
1242
+ {.index = 4 , .res = DEFINE_RES_MEM (0xd0d01000 , 0x100 ) },
1243
+ };
1244
+
1245
+ static const struct of_unittest_expected_res of_unittest_reg_pci_expected_res [] = {
1246
+ {.index = 0 , .res = DEFINE_RES_MEM (0xe8001000 , 0x1000 ) },
1247
+ {.index = 1 , .res = DEFINE_RES_MEM (0xea002000 , 0x2000 ) },
1248
+ };
1249
+
1250
+ static void __init of_unittest_translate_addr (void )
1251
+ {
1252
+ of_unittest_check_addr ("/testcase-data/address-tests2/bus-2cell@10000000/device@100000" ,
1253
+ of_unittest_reg_2cell_expected_res ,
1254
+ ARRAY_SIZE (of_unittest_reg_2cell_expected_res ));
1255
+
1256
+ of_unittest_check_addr ("/testcase-data/address-tests2/bus-3cell@20000000/local-bus@100000/device@f1001000" ,
1257
+ of_unittest_reg_3cell_expected_res ,
1258
+ ARRAY_SIZE (of_unittest_reg_3cell_expected_res ));
1259
+
1260
+ of_unittest_check_addr ("/testcase-data/address-tests2/pcie@d1070000/pci@0,0/dev@0,0/local-bus@0/dev@e0000000" ,
1261
+ of_unittest_reg_pci_expected_res ,
1262
+ ARRAY_SIZE (of_unittest_reg_pci_expected_res ));
1263
+ }
1264
+
1189
1265
static void __init of_unittest_parse_interrupts (void )
1190
1266
{
1191
1267
struct device_node * np ;
@@ -4034,6 +4110,7 @@ static int __init of_unittest(void)
4034
4110
of_unittest_bus_ranges ();
4035
4111
of_unittest_bus_3cell_ranges ();
4036
4112
of_unittest_reg ();
4113
+ of_unittest_translate_addr ();
4037
4114
of_unittest_match_node ();
4038
4115
of_unittest_platform_populate ();
4039
4116
of_unittest_overlay ();
0 commit comments