core.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Tests for the core driver model code
  4. *
  5. * Copyright (c) 2013 Google, Inc
  6. */
  7. #include <common.h>
  8. #include <errno.h>
  9. #include <dm.h>
  10. #include <fdtdec.h>
  11. #include <log.h>
  12. #include <malloc.h>
  13. #include <asm/global_data.h>
  14. #include <dm/device-internal.h>
  15. #include <dm/root.h>
  16. #include <dm/util.h>
  17. #include <dm/test.h>
  18. #include <dm/uclass-internal.h>
  19. #include <test/test.h>
  20. #include <test/ut.h>
  21. DECLARE_GLOBAL_DATA_PTR;
  22. enum {
  23. TEST_INTVAL1 = 0,
  24. TEST_INTVAL2 = 3,
  25. TEST_INTVAL3 = 6,
  26. TEST_INTVAL_MANUAL = 101112,
  27. TEST_INTVAL_PRE_RELOC = 7,
  28. };
  29. static const struct dm_test_pdata test_pdata[] = {
  30. { .ping_add = TEST_INTVAL1, },
  31. { .ping_add = TEST_INTVAL2, },
  32. { .ping_add = TEST_INTVAL3, },
  33. };
  34. static const struct dm_test_pdata test_pdata_manual = {
  35. .ping_add = TEST_INTVAL_MANUAL,
  36. };
  37. static const struct dm_test_pdata test_pdata_pre_reloc = {
  38. .ping_add = TEST_INTVAL_PRE_RELOC,
  39. };
  40. U_BOOT_DRVINFO(dm_test_info1) = {
  41. .name = "test_drv",
  42. .plat = &test_pdata[0],
  43. };
  44. U_BOOT_DRVINFO(dm_test_info2) = {
  45. .name = "test_drv",
  46. .plat = &test_pdata[1],
  47. };
  48. U_BOOT_DRVINFO(dm_test_info3) = {
  49. .name = "test_drv",
  50. .plat = &test_pdata[2],
  51. };
  52. static struct driver_info driver_info_manual = {
  53. .name = "test_manual_drv",
  54. .plat = &test_pdata_manual,
  55. };
  56. static struct driver_info driver_info_pre_reloc = {
  57. .name = "test_pre_reloc_drv",
  58. .plat = &test_pdata_pre_reloc,
  59. };
  60. static struct driver_info driver_info_act_dma = {
  61. .name = "test_act_dma_drv",
  62. };
  63. static struct driver_info driver_info_vital_clk = {
  64. .name = "test_vital_clk_drv",
  65. };
  66. static struct driver_info driver_info_act_dma_vital_clk = {
  67. .name = "test_act_dma_vital_clk_drv",
  68. };
  69. void dm_leak_check_start(struct unit_test_state *uts)
  70. {
  71. uts->start = mallinfo();
  72. if (!uts->start.uordblks)
  73. puts("Warning: Please add '#define DEBUG' to the top of common/dlmalloc.c\n");
  74. }
  75. int dm_leak_check_end(struct unit_test_state *uts)
  76. {
  77. struct mallinfo end;
  78. int id, diff;
  79. /* Don't delete the root class, since we started with that */
  80. for (id = UCLASS_ROOT + 1; id < UCLASS_COUNT; id++) {
  81. struct uclass *uc;
  82. uc = uclass_find(id);
  83. if (!uc)
  84. continue;
  85. ut_assertok(uclass_destroy(uc));
  86. }
  87. end = mallinfo();
  88. diff = end.uordblks - uts->start.uordblks;
  89. if (diff > 0)
  90. printf("Leak: lost %#xd bytes\n", diff);
  91. else if (diff < 0)
  92. printf("Leak: gained %#xd bytes\n", -diff);
  93. ut_asserteq(uts->start.uordblks, end.uordblks);
  94. return 0;
  95. }
  96. /* Test that binding with plat occurs correctly */
  97. static int dm_test_autobind(struct unit_test_state *uts)
  98. {
  99. struct udevice *dev;
  100. /*
  101. * We should have a single class (UCLASS_ROOT) and a single root
  102. * device with no children.
  103. */
  104. ut_assert(uts->root);
  105. ut_asserteq(1, list_count_items(gd->uclass_root));
  106. ut_asserteq(0, list_count_items(&gd->dm_root->child_head));
  107. ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_POST_BIND]);
  108. ut_assertok(dm_scan_plat(false));
  109. /* We should have our test class now at least, plus more children */
  110. ut_assert(1 < list_count_items(gd->uclass_root));
  111. ut_assert(0 < list_count_items(&gd->dm_root->child_head));
  112. /* Our 3 dm_test_infox children should be bound to the test uclass */
  113. ut_asserteq(3, dm_testdrv_op_count[DM_TEST_OP_POST_BIND]);
  114. /* No devices should be probed */
  115. list_for_each_entry(dev, &gd->dm_root->child_head, sibling_node)
  116. ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED));
  117. /* Our test driver should have been bound 3 times */
  118. ut_assert(dm_testdrv_op_count[DM_TEST_OP_BIND] == 3);
  119. return 0;
  120. }
  121. DM_TEST(dm_test_autobind, 0);
  122. /* Test that binding with uclass plat allocation occurs correctly */
  123. static int dm_test_autobind_uclass_pdata_alloc(struct unit_test_state *uts)
  124. {
  125. struct dm_test_perdev_uc_pdata *uc_pdata;
  126. struct udevice *dev;
  127. struct uclass *uc;
  128. ut_assertok(uclass_get(UCLASS_TEST, &uc));
  129. ut_assert(uc);
  130. /**
  131. * Test if test uclass driver requires allocation for the uclass
  132. * platform data and then check the dev->uclass_plat pointer.
  133. */
  134. ut_assert(uc->uc_drv->per_device_plat_auto);
  135. for (uclass_find_first_device(UCLASS_TEST, &dev);
  136. dev;
  137. uclass_find_next_device(&dev)) {
  138. ut_assertnonnull(dev);
  139. uc_pdata = dev_get_uclass_plat(dev);
  140. ut_assert(uc_pdata);
  141. }
  142. return 0;
  143. }
  144. DM_TEST(dm_test_autobind_uclass_pdata_alloc, UT_TESTF_SCAN_PDATA);
  145. /* compare node names ignoring the unit address */
  146. static int dm_test_compare_node_name(struct unit_test_state *uts)
  147. {
  148. ofnode node;
  149. node = ofnode_path("/mmio-bus@0");
  150. ut_assert(ofnode_valid(node));
  151. ut_assert(ofnode_name_eq(node, "mmio-bus"));
  152. return 0;
  153. }
  154. DM_TEST(dm_test_compare_node_name, UT_TESTF_SCAN_PDATA);
  155. /* Test that binding with uclass plat setting occurs correctly */
  156. static int dm_test_autobind_uclass_pdata_valid(struct unit_test_state *uts)
  157. {
  158. struct dm_test_perdev_uc_pdata *uc_pdata;
  159. struct udevice *dev;
  160. /**
  161. * In the test_postbind() method of test uclass driver, the uclass
  162. * platform data should be set to three test int values - test it.
  163. */
  164. for (uclass_find_first_device(UCLASS_TEST, &dev);
  165. dev;
  166. uclass_find_next_device(&dev)) {
  167. ut_assertnonnull(dev);
  168. uc_pdata = dev_get_uclass_plat(dev);
  169. ut_assert(uc_pdata);
  170. ut_assert(uc_pdata->intval1 == TEST_UC_PDATA_INTVAL1);
  171. ut_assert(uc_pdata->intval2 == TEST_UC_PDATA_INTVAL2);
  172. ut_assert(uc_pdata->intval3 == TEST_UC_PDATA_INTVAL3);
  173. }
  174. return 0;
  175. }
  176. DM_TEST(dm_test_autobind_uclass_pdata_valid, UT_TESTF_SCAN_PDATA);
  177. /* Test that autoprobe finds all the expected devices */
  178. static int dm_test_autoprobe(struct unit_test_state *uts)
  179. {
  180. int expected_base_add;
  181. struct udevice *dev;
  182. struct uclass *uc;
  183. int i;
  184. ut_assertok(uclass_get(UCLASS_TEST, &uc));
  185. ut_assert(uc);
  186. ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_INIT]);
  187. ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_PRE_PROBE]);
  188. ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_POST_PROBE]);
  189. /* The root device should not be activated until needed */
  190. ut_assert(dev_get_flags(uts->root) & DM_FLAG_ACTIVATED);
  191. /*
  192. * We should be able to find the three test devices, and they should
  193. * all be activated as they are used (lazy activation, required by
  194. * U-Boot)
  195. */
  196. for (i = 0; i < 3; i++) {
  197. ut_assertok(uclass_find_device(UCLASS_TEST, i, &dev));
  198. ut_assert(dev);
  199. ut_assertf(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED),
  200. "Driver %d/%s already activated", i, dev->name);
  201. /* This should activate it */
  202. ut_assertok(uclass_get_device(UCLASS_TEST, i, &dev));
  203. ut_assert(dev);
  204. ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED);
  205. /* Activating a device should activate the root device */
  206. if (!i)
  207. ut_assert(dev_get_flags(uts->root) & DM_FLAG_ACTIVATED);
  208. }
  209. /*
  210. * Our 3 dm_test_info children should be passed to pre_probe and
  211. * post_probe
  212. */
  213. ut_asserteq(3, dm_testdrv_op_count[DM_TEST_OP_POST_PROBE]);
  214. ut_asserteq(3, dm_testdrv_op_count[DM_TEST_OP_PRE_PROBE]);
  215. /* Also we can check the per-device data */
  216. expected_base_add = 0;
  217. for (i = 0; i < 3; i++) {
  218. struct dm_test_uclass_perdev_priv *priv;
  219. struct dm_test_pdata *pdata;
  220. ut_assertok(uclass_find_device(UCLASS_TEST, i, &dev));
  221. ut_assert(dev);
  222. priv = dev_get_uclass_priv(dev);
  223. ut_assert(priv);
  224. ut_asserteq(expected_base_add, priv->base_add);
  225. pdata = dev_get_plat(dev);
  226. expected_base_add += pdata->ping_add;
  227. }
  228. return 0;
  229. }
  230. DM_TEST(dm_test_autoprobe, UT_TESTF_SCAN_PDATA);
  231. /* Check that we see the correct plat in each device */
  232. static int dm_test_plat(struct unit_test_state *uts)
  233. {
  234. const struct dm_test_pdata *pdata;
  235. struct udevice *dev;
  236. int i;
  237. for (i = 0; i < 3; i++) {
  238. ut_assertok(uclass_find_device(UCLASS_TEST, i, &dev));
  239. ut_assert(dev);
  240. pdata = dev_get_plat(dev);
  241. ut_assert(pdata->ping_add == test_pdata[i].ping_add);
  242. }
  243. return 0;
  244. }
  245. DM_TEST(dm_test_plat, UT_TESTF_SCAN_PDATA);
  246. /* Test that we can bind, probe, remove, unbind a driver */
  247. static int dm_test_lifecycle(struct unit_test_state *uts)
  248. {
  249. int op_count[DM_TEST_OP_COUNT];
  250. struct udevice *dev, *test_dev;
  251. int pingret;
  252. int ret;
  253. memcpy(op_count, dm_testdrv_op_count, sizeof(op_count));
  254. ut_assertok(device_bind_by_name(uts->root, false, &driver_info_manual,
  255. &dev));
  256. ut_assert(dev);
  257. ut_assert(dm_testdrv_op_count[DM_TEST_OP_BIND]
  258. == op_count[DM_TEST_OP_BIND] + 1);
  259. ut_assert(!dev_get_priv(dev));
  260. /* Probe the device - it should fail allocating private data */
  261. uts->force_fail_alloc = 1;
  262. ret = device_probe(dev);
  263. ut_assert(ret == -ENOMEM);
  264. ut_assert(dm_testdrv_op_count[DM_TEST_OP_PROBE]
  265. == op_count[DM_TEST_OP_PROBE] + 1);
  266. ut_assert(!dev_get_priv(dev));
  267. /* Try again without the alloc failure */
  268. uts->force_fail_alloc = 0;
  269. ut_assertok(device_probe(dev));
  270. ut_assert(dm_testdrv_op_count[DM_TEST_OP_PROBE]
  271. == op_count[DM_TEST_OP_PROBE] + 2);
  272. ut_assert(dev_get_priv(dev));
  273. /* This should be device 3 in the uclass */
  274. ut_assertok(uclass_find_device(UCLASS_TEST, 3, &test_dev));
  275. ut_assert(dev == test_dev);
  276. /* Try ping */
  277. ut_assertok(test_ping(dev, 100, &pingret));
  278. ut_assert(pingret == 102);
  279. /* Now remove device 3 */
  280. ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_PRE_REMOVE]);
  281. ut_assertok(device_remove(dev, DM_REMOVE_NORMAL));
  282. ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_PRE_REMOVE]);
  283. ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_UNBIND]);
  284. ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_PRE_UNBIND]);
  285. ut_assertok(device_unbind(dev));
  286. ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_UNBIND]);
  287. ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_PRE_UNBIND]);
  288. return 0;
  289. }
  290. DM_TEST(dm_test_lifecycle, UT_TESTF_SCAN_PDATA | UT_TESTF_PROBE_TEST);
  291. /* Test that we can bind/unbind and the lists update correctly */
  292. static int dm_test_ordering(struct unit_test_state *uts)
  293. {
  294. struct udevice *dev, *dev_penultimate, *dev_last, *test_dev;
  295. int pingret;
  296. ut_assertok(device_bind_by_name(uts->root, false, &driver_info_manual,
  297. &dev));
  298. ut_assert(dev);
  299. /* Bind two new devices (numbers 4 and 5) */
  300. ut_assertok(device_bind_by_name(uts->root, false, &driver_info_manual,
  301. &dev_penultimate));
  302. ut_assert(dev_penultimate);
  303. ut_assertok(device_bind_by_name(uts->root, false, &driver_info_manual,
  304. &dev_last));
  305. ut_assert(dev_last);
  306. /* Now remove device 3 */
  307. ut_assertok(device_remove(dev, DM_REMOVE_NORMAL));
  308. ut_assertok(device_unbind(dev));
  309. /* The device numbering should have shifted down one */
  310. ut_assertok(uclass_find_device(UCLASS_TEST, 3, &test_dev));
  311. ut_assert(dev_penultimate == test_dev);
  312. ut_assertok(uclass_find_device(UCLASS_TEST, 4, &test_dev));
  313. ut_assert(dev_last == test_dev);
  314. /* Add back the original device 3, now in position 5 */
  315. ut_assertok(device_bind_by_name(uts->root, false, &driver_info_manual,
  316. &dev));
  317. ut_assert(dev);
  318. /* Try ping */
  319. ut_assertok(test_ping(dev, 100, &pingret));
  320. ut_assert(pingret == 102);
  321. /* Remove 3 and 4 */
  322. ut_assertok(device_remove(dev_penultimate, DM_REMOVE_NORMAL));
  323. ut_assertok(device_unbind(dev_penultimate));
  324. ut_assertok(device_remove(dev_last, DM_REMOVE_NORMAL));
  325. ut_assertok(device_unbind(dev_last));
  326. /* Our device should now be in position 3 */
  327. ut_assertok(uclass_find_device(UCLASS_TEST, 3, &test_dev));
  328. ut_assert(dev == test_dev);
  329. /* Now remove device 3 */
  330. ut_assertok(device_remove(dev, DM_REMOVE_NORMAL));
  331. ut_assertok(device_unbind(dev));
  332. return 0;
  333. }
  334. DM_TEST(dm_test_ordering, UT_TESTF_SCAN_PDATA);
  335. /* Check that we can perform operations on a device (do a ping) */
  336. int dm_check_operations(struct unit_test_state *uts, struct udevice *dev,
  337. uint32_t base, struct dm_test_priv *priv)
  338. {
  339. int expected;
  340. int pingret;
  341. /* Getting the child device should allocate plat / priv */
  342. ut_assertok(testfdt_ping(dev, 10, &pingret));
  343. ut_assert(dev_get_priv(dev));
  344. ut_assert(dev_get_plat(dev));
  345. expected = 10 + base;
  346. ut_asserteq(expected, pingret);
  347. /* Do another ping */
  348. ut_assertok(testfdt_ping(dev, 20, &pingret));
  349. expected = 20 + base;
  350. ut_asserteq(expected, pingret);
  351. /* Now check the ping_total */
  352. priv = dev_get_priv(dev);
  353. ut_asserteq(DM_TEST_START_TOTAL + 10 + 20 + base * 2,
  354. priv->ping_total);
  355. return 0;
  356. }
  357. /* Check that we can perform operations on devices */
  358. static int dm_test_operations(struct unit_test_state *uts)
  359. {
  360. struct udevice *dev;
  361. int i;
  362. /*
  363. * Now check that the ping adds are what we expect. This is using the
  364. * ping-add property in each node.
  365. */
  366. for (i = 0; i < ARRAY_SIZE(test_pdata); i++) {
  367. uint32_t base;
  368. ut_assertok(uclass_get_device(UCLASS_TEST, i, &dev));
  369. /*
  370. * Get the 'reg' property, which tells us what the ping add
  371. * should be. We don't use the plat because we want
  372. * to test the code that sets that up (testfdt_drv_probe()).
  373. */
  374. base = test_pdata[i].ping_add;
  375. debug("dev=%d, base=%d\n", i, base);
  376. ut_assert(!dm_check_operations(uts, dev, base, dev_get_priv(dev)));
  377. }
  378. return 0;
  379. }
  380. DM_TEST(dm_test_operations, UT_TESTF_SCAN_PDATA);
  381. /* Remove all drivers and check that things work */
  382. static int dm_test_remove(struct unit_test_state *uts)
  383. {
  384. struct udevice *dev;
  385. int i;
  386. for (i = 0; i < 3; i++) {
  387. ut_assertok(uclass_find_device(UCLASS_TEST, i, &dev));
  388. ut_assert(dev);
  389. ut_assertf(dev_get_flags(dev) & DM_FLAG_ACTIVATED,
  390. "Driver %d/%s not activated", i, dev->name);
  391. ut_assertok(device_remove(dev, DM_REMOVE_NORMAL));
  392. ut_assertf(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED),
  393. "Driver %d/%s should have deactivated", i,
  394. dev->name);
  395. ut_assert(!dev_get_priv(dev));
  396. }
  397. return 0;
  398. }
  399. DM_TEST(dm_test_remove, UT_TESTF_SCAN_PDATA | UT_TESTF_PROBE_TEST);
  400. /* Remove and recreate everything, check for memory leaks */
  401. static int dm_test_leak(struct unit_test_state *uts)
  402. {
  403. int i;
  404. for (i = 0; i < 2; i++) {
  405. struct udevice *dev;
  406. int ret;
  407. int id;
  408. dm_leak_check_start(uts);
  409. ut_assertok(dm_scan_plat(false));
  410. ut_assertok(dm_scan_fdt(false));
  411. /* Scanning the uclass is enough to probe all the devices */
  412. for (id = UCLASS_ROOT; id < UCLASS_COUNT; id++) {
  413. for (ret = uclass_first_device(UCLASS_TEST, &dev);
  414. dev;
  415. ret = uclass_next_device(&dev))
  416. ;
  417. ut_assertok(ret);
  418. }
  419. ut_assertok(dm_leak_check_end(uts));
  420. }
  421. return 0;
  422. }
  423. DM_TEST(dm_test_leak, 0);
  424. /* Test uclass init/destroy methods */
  425. static int dm_test_uclass(struct unit_test_state *uts)
  426. {
  427. struct uclass *uc;
  428. ut_assertok(uclass_get(UCLASS_TEST, &uc));
  429. ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_INIT]);
  430. ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_DESTROY]);
  431. ut_assert(uclass_get_priv(uc));
  432. ut_assertok(uclass_destroy(uc));
  433. ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_INIT]);
  434. ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_DESTROY]);
  435. return 0;
  436. }
  437. DM_TEST(dm_test_uclass, 0);
  438. /**
  439. * create_children() - Create children of a parent node
  440. *
  441. * @dms: Test system state
  442. * @parent: Parent device
  443. * @count: Number of children to create
  444. * @key: Key value to put in first child. Subsequence children
  445. * receive an incrementing value
  446. * @child: If not NULL, then the child device pointers are written into
  447. * this array.
  448. * @return 0 if OK, -ve on error
  449. */
  450. static int create_children(struct unit_test_state *uts, struct udevice *parent,
  451. int count, int key, struct udevice *child[])
  452. {
  453. struct udevice *dev;
  454. int i;
  455. for (i = 0; i < count; i++) {
  456. struct dm_test_pdata *pdata;
  457. ut_assertok(device_bind_by_name(parent, false,
  458. &driver_info_manual, &dev));
  459. pdata = calloc(1, sizeof(*pdata));
  460. pdata->ping_add = key + i;
  461. dev_set_plat(dev, pdata);
  462. if (child)
  463. child[i] = dev;
  464. }
  465. return 0;
  466. }
  467. #define NODE_COUNT 10
  468. static int dm_test_children(struct unit_test_state *uts)
  469. {
  470. struct udevice *top[NODE_COUNT];
  471. struct udevice *child[NODE_COUNT];
  472. struct udevice *grandchild[NODE_COUNT];
  473. struct udevice *dev;
  474. int total;
  475. int ret;
  476. int i;
  477. /* We don't care about the numbering for this test */
  478. uts->skip_post_probe = 1;
  479. ut_assert(NODE_COUNT > 5);
  480. /* First create 10 top-level children */
  481. ut_assertok(create_children(uts, uts->root, NODE_COUNT, 0, top));
  482. /* Now a few have their own children */
  483. ut_assertok(create_children(uts, top[2], NODE_COUNT, 2, NULL));
  484. ut_assertok(create_children(uts, top[5], NODE_COUNT, 5, child));
  485. /* And grandchildren */
  486. for (i = 0; i < NODE_COUNT; i++)
  487. ut_assertok(create_children(uts, child[i], NODE_COUNT, 50 * i,
  488. i == 2 ? grandchild : NULL));
  489. /* Check total number of devices */
  490. total = NODE_COUNT * (3 + NODE_COUNT);
  491. ut_asserteq(total, dm_testdrv_op_count[DM_TEST_OP_BIND]);
  492. /* Try probing one of the grandchildren */
  493. ut_assertok(uclass_get_device(UCLASS_TEST,
  494. NODE_COUNT * 3 + 2 * NODE_COUNT, &dev));
  495. ut_asserteq_ptr(grandchild[0], dev);
  496. /*
  497. * This should have probed the child and top node also, for a total
  498. * of 3 nodes.
  499. */
  500. ut_asserteq(3, dm_testdrv_op_count[DM_TEST_OP_PROBE]);
  501. /* Probe the other grandchildren */
  502. for (i = 1; i < NODE_COUNT; i++)
  503. ut_assertok(device_probe(grandchild[i]));
  504. ut_asserteq(2 + NODE_COUNT, dm_testdrv_op_count[DM_TEST_OP_PROBE]);
  505. /* Probe everything */
  506. for (ret = uclass_first_device(UCLASS_TEST, &dev);
  507. dev;
  508. ret = uclass_next_device(&dev))
  509. ;
  510. ut_assertok(ret);
  511. ut_asserteq(total, dm_testdrv_op_count[DM_TEST_OP_PROBE]);
  512. /* Remove a top-level child and check that the children are removed */
  513. ut_assertok(device_remove(top[2], DM_REMOVE_NORMAL));
  514. ut_asserteq(NODE_COUNT + 1, dm_testdrv_op_count[DM_TEST_OP_REMOVE]);
  515. dm_testdrv_op_count[DM_TEST_OP_REMOVE] = 0;
  516. /* Try one with grandchildren */
  517. ut_assertok(uclass_get_device(UCLASS_TEST, 5, &dev));
  518. ut_asserteq_ptr(dev, top[5]);
  519. ut_assertok(device_remove(dev, DM_REMOVE_NORMAL));
  520. ut_asserteq(1 + NODE_COUNT * (1 + NODE_COUNT),
  521. dm_testdrv_op_count[DM_TEST_OP_REMOVE]);
  522. /* Try the same with unbind */
  523. ut_assertok(device_unbind(top[2]));
  524. ut_asserteq(NODE_COUNT + 1, dm_testdrv_op_count[DM_TEST_OP_UNBIND]);
  525. dm_testdrv_op_count[DM_TEST_OP_UNBIND] = 0;
  526. /* Try one with grandchildren */
  527. ut_assertok(uclass_get_device(UCLASS_TEST, 5, &dev));
  528. ut_asserteq_ptr(dev, top[6]);
  529. ut_assertok(device_unbind(top[5]));
  530. ut_asserteq(1 + NODE_COUNT * (1 + NODE_COUNT),
  531. dm_testdrv_op_count[DM_TEST_OP_UNBIND]);
  532. return 0;
  533. }
  534. DM_TEST(dm_test_children, 0);
  535. static int dm_test_device_reparent(struct unit_test_state *uts)
  536. {
  537. struct udevice *top[NODE_COUNT];
  538. struct udevice *child[NODE_COUNT];
  539. struct udevice *grandchild[NODE_COUNT];
  540. struct udevice *dev;
  541. int total;
  542. int ret;
  543. int i;
  544. /* We don't care about the numbering for this test */
  545. uts->skip_post_probe = 1;
  546. ut_assert(NODE_COUNT > 5);
  547. /* First create 10 top-level children */
  548. ut_assertok(create_children(uts, uts->root, NODE_COUNT, 0, top));
  549. /* Now a few have their own children */
  550. ut_assertok(create_children(uts, top[2], NODE_COUNT, 2, NULL));
  551. ut_assertok(create_children(uts, top[5], NODE_COUNT, 5, child));
  552. /* And grandchildren */
  553. for (i = 0; i < NODE_COUNT; i++)
  554. ut_assertok(create_children(uts, child[i], NODE_COUNT, 50 * i,
  555. i == 2 ? grandchild : NULL));
  556. /* Check total number of devices */
  557. total = NODE_COUNT * (3 + NODE_COUNT);
  558. ut_asserteq(total, dm_testdrv_op_count[DM_TEST_OP_BIND]);
  559. /* Probe everything */
  560. for (i = 0; i < total; i++)
  561. ut_assertok(uclass_get_device(UCLASS_TEST, i, &dev));
  562. /* Re-parent top-level children with no grandchildren. */
  563. ut_assertok(device_reparent(top[3], top[0]));
  564. /* try to get devices */
  565. for (ret = uclass_find_first_device(UCLASS_TEST, &dev);
  566. dev;
  567. ret = uclass_find_next_device(&dev)) {
  568. ut_assert(!ret);
  569. ut_assertnonnull(dev);
  570. }
  571. ut_assertok(device_reparent(top[4], top[0]));
  572. /* try to get devices */
  573. for (ret = uclass_find_first_device(UCLASS_TEST, &dev);
  574. dev;
  575. ret = uclass_find_next_device(&dev)) {
  576. ut_assert(!ret);
  577. ut_assertnonnull(dev);
  578. }
  579. /* Re-parent top-level children with grandchildren. */
  580. ut_assertok(device_reparent(top[2], top[0]));
  581. /* try to get devices */
  582. for (ret = uclass_find_first_device(UCLASS_TEST, &dev);
  583. dev;
  584. ret = uclass_find_next_device(&dev)) {
  585. ut_assert(!ret);
  586. ut_assertnonnull(dev);
  587. }
  588. ut_assertok(device_reparent(top[5], top[2]));
  589. /* try to get devices */
  590. for (ret = uclass_find_first_device(UCLASS_TEST, &dev);
  591. dev;
  592. ret = uclass_find_next_device(&dev)) {
  593. ut_assert(!ret);
  594. ut_assertnonnull(dev);
  595. }
  596. /* Re-parent grandchildren. */
  597. ut_assertok(device_reparent(grandchild[0], top[1]));
  598. /* try to get devices */
  599. for (ret = uclass_find_first_device(UCLASS_TEST, &dev);
  600. dev;
  601. ret = uclass_find_next_device(&dev)) {
  602. ut_assert(!ret);
  603. ut_assertnonnull(dev);
  604. }
  605. ut_assertok(device_reparent(grandchild[1], top[1]));
  606. /* try to get devices */
  607. for (ret = uclass_find_first_device(UCLASS_TEST, &dev);
  608. dev;
  609. ret = uclass_find_next_device(&dev)) {
  610. ut_assert(!ret);
  611. ut_assertnonnull(dev);
  612. }
  613. /* Remove re-pareneted devices. */
  614. ut_assertok(device_remove(top[3], DM_REMOVE_NORMAL));
  615. /* try to get devices */
  616. for (ret = uclass_find_first_device(UCLASS_TEST, &dev);
  617. dev;
  618. ret = uclass_find_next_device(&dev)) {
  619. ut_assert(!ret);
  620. ut_assertnonnull(dev);
  621. }
  622. ut_assertok(device_remove(top[4], DM_REMOVE_NORMAL));
  623. /* try to get devices */
  624. for (ret = uclass_find_first_device(UCLASS_TEST, &dev);
  625. dev;
  626. ret = uclass_find_next_device(&dev)) {
  627. ut_assert(!ret);
  628. ut_assertnonnull(dev);
  629. }
  630. ut_assertok(device_remove(top[5], DM_REMOVE_NORMAL));
  631. /* try to get devices */
  632. for (ret = uclass_find_first_device(UCLASS_TEST, &dev);
  633. dev;
  634. ret = uclass_find_next_device(&dev)) {
  635. ut_assert(!ret);
  636. ut_assertnonnull(dev);
  637. }
  638. ut_assertok(device_remove(top[2], DM_REMOVE_NORMAL));
  639. for (ret = uclass_find_first_device(UCLASS_TEST, &dev);
  640. dev;
  641. ret = uclass_find_next_device(&dev)) {
  642. ut_assert(!ret);
  643. ut_assertnonnull(dev);
  644. }
  645. ut_assertok(device_remove(grandchild[0], DM_REMOVE_NORMAL));
  646. /* try to get devices */
  647. for (ret = uclass_find_first_device(UCLASS_TEST, &dev);
  648. dev;
  649. ret = uclass_find_next_device(&dev)) {
  650. ut_assert(!ret);
  651. ut_assertnonnull(dev);
  652. }
  653. ut_assertok(device_remove(grandchild[1], DM_REMOVE_NORMAL));
  654. /* try to get devices */
  655. for (ret = uclass_find_first_device(UCLASS_TEST, &dev);
  656. dev;
  657. ret = uclass_find_next_device(&dev)) {
  658. ut_assert(!ret);
  659. ut_assertnonnull(dev);
  660. }
  661. /* Try the same with unbind */
  662. ut_assertok(device_unbind(top[3]));
  663. ut_assertok(device_unbind(top[4]));
  664. ut_assertok(device_unbind(top[5]));
  665. ut_assertok(device_unbind(top[2]));
  666. ut_assertok(device_unbind(grandchild[0]));
  667. ut_assertok(device_unbind(grandchild[1]));
  668. return 0;
  669. }
  670. DM_TEST(dm_test_device_reparent, 0);
  671. /* Test that pre-relocation devices work as expected */
  672. static int dm_test_pre_reloc(struct unit_test_state *uts)
  673. {
  674. struct udevice *dev;
  675. /* The normal driver should refuse to bind before relocation */
  676. ut_asserteq(-EPERM, device_bind_by_name(uts->root, true,
  677. &driver_info_manual, &dev));
  678. /* But this one is marked pre-reloc */
  679. ut_assertok(device_bind_by_name(uts->root, true,
  680. &driver_info_pre_reloc, &dev));
  681. return 0;
  682. }
  683. DM_TEST(dm_test_pre_reloc, 0);
  684. /*
  685. * Test that removal of devices, either via the "normal" device_remove()
  686. * API or via the device driver selective flag works as expected
  687. */
  688. static int dm_test_remove_active_dma(struct unit_test_state *uts)
  689. {
  690. struct udevice *dev;
  691. ut_assertok(device_bind_by_name(uts->root, false, &driver_info_act_dma,
  692. &dev));
  693. ut_assert(dev);
  694. /* Probe the device */
  695. ut_assertok(device_probe(dev));
  696. /* Test if device is active right now */
  697. ut_asserteq(true, device_active(dev));
  698. /* Remove the device via selective remove flag */
  699. dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL);
  700. /* Test if device is inactive right now */
  701. ut_asserteq(false, device_active(dev));
  702. /* Probe the device again */
  703. ut_assertok(device_probe(dev));
  704. /* Test if device is active right now */
  705. ut_asserteq(true, device_active(dev));
  706. /* Remove the device via "normal" remove API */
  707. ut_assertok(device_remove(dev, DM_REMOVE_NORMAL));
  708. /* Test if device is inactive right now */
  709. ut_asserteq(false, device_active(dev));
  710. /*
  711. * Test if a device without the active DMA flags is not removed upon
  712. * the active DMA remove call
  713. */
  714. ut_assertok(device_unbind(dev));
  715. ut_assertok(device_bind_by_name(uts->root, false, &driver_info_manual,
  716. &dev));
  717. ut_assert(dev);
  718. /* Probe the device */
  719. ut_assertok(device_probe(dev));
  720. /* Test if device is active right now */
  721. ut_asserteq(true, device_active(dev));
  722. /* Remove the device via selective remove flag */
  723. dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL);
  724. /* Test if device is still active right now */
  725. ut_asserteq(true, device_active(dev));
  726. return 0;
  727. }
  728. DM_TEST(dm_test_remove_active_dma, 0);
  729. /* Test removal of 'vital' devices */
  730. static int dm_test_remove_vital(struct unit_test_state *uts)
  731. {
  732. struct udevice *normal, *dma, *vital, *dma_vital;
  733. /* Skip the behaviour in test_post_probe() */
  734. uts->skip_post_probe = 1;
  735. ut_assertok(device_bind_by_name(uts->root, false, &driver_info_manual,
  736. &normal));
  737. ut_assertnonnull(normal);
  738. ut_assertok(device_bind_by_name(uts->root, false, &driver_info_act_dma,
  739. &dma));
  740. ut_assertnonnull(dma);
  741. ut_assertok(device_bind_by_name(uts->root, false,
  742. &driver_info_vital_clk, &vital));
  743. ut_assertnonnull(vital);
  744. ut_assertok(device_bind_by_name(uts->root, false,
  745. &driver_info_act_dma_vital_clk,
  746. &dma_vital));
  747. ut_assertnonnull(dma_vital);
  748. /* Probe the devices */
  749. ut_assertok(device_probe(normal));
  750. ut_assertok(device_probe(dma));
  751. ut_assertok(device_probe(vital));
  752. ut_assertok(device_probe(dma_vital));
  753. /* Check that devices are active right now */
  754. ut_asserteq(true, device_active(normal));
  755. ut_asserteq(true, device_active(dma));
  756. ut_asserteq(true, device_active(vital));
  757. ut_asserteq(true, device_active(dma_vital));
  758. /* Remove active devices via selective remove flag */
  759. dm_remove_devices_flags(DM_REMOVE_NON_VITAL | DM_REMOVE_ACTIVE_ALL);
  760. /*
  761. * Check that this only has an effect on the dma device, since two
  762. * devices are vital and the third does not have active DMA
  763. */
  764. ut_asserteq(true, device_active(normal));
  765. ut_asserteq(false, device_active(dma));
  766. ut_asserteq(true, device_active(vital));
  767. ut_asserteq(true, device_active(dma_vital));
  768. /* Remove active devices via selective remove flag */
  769. ut_assertok(device_probe(dma));
  770. dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL);
  771. /* This should have affected both active-dma devices */
  772. ut_asserteq(true, device_active(normal));
  773. ut_asserteq(false, device_active(dma));
  774. ut_asserteq(true, device_active(vital));
  775. ut_asserteq(false, device_active(dma_vital));
  776. /* Remove non-vital devices */
  777. ut_assertok(device_probe(dma));
  778. ut_assertok(device_probe(dma_vital));
  779. dm_remove_devices_flags(DM_REMOVE_NON_VITAL);
  780. /* This should have affected only non-vital devices */
  781. ut_asserteq(false, device_active(normal));
  782. ut_asserteq(false, device_active(dma));
  783. ut_asserteq(true, device_active(vital));
  784. ut_asserteq(true, device_active(dma_vital));
  785. /* Remove vital devices via normal remove flag */
  786. ut_assertok(device_probe(normal));
  787. ut_assertok(device_probe(dma));
  788. dm_remove_devices_flags(DM_REMOVE_NORMAL);
  789. /* Check that all devices are inactive right now */
  790. ut_asserteq(false, device_active(normal));
  791. ut_asserteq(false, device_active(dma));
  792. ut_asserteq(false, device_active(vital));
  793. ut_asserteq(false, device_active(dma_vital));
  794. return 0;
  795. }
  796. DM_TEST(dm_test_remove_vital, 0);
  797. static int dm_test_uclass_before_ready(struct unit_test_state *uts)
  798. {
  799. struct uclass *uc;
  800. ut_assertok(uclass_get(UCLASS_TEST, &uc));
  801. gd->dm_root = NULL;
  802. gd->dm_root_f = NULL;
  803. memset(&gd->uclass_root, '\0', sizeof(gd->uclass_root));
  804. ut_asserteq_ptr(NULL, uclass_find(UCLASS_TEST));
  805. ut_asserteq(-EDEADLK, uclass_get(UCLASS_TEST, &uc));
  806. return 0;
  807. }
  808. DM_TEST(dm_test_uclass_before_ready, 0);
  809. static int dm_test_uclass_devices_find(struct unit_test_state *uts)
  810. {
  811. struct udevice *dev;
  812. int ret;
  813. for (ret = uclass_find_first_device(UCLASS_TEST, &dev);
  814. dev;
  815. ret = uclass_find_next_device(&dev)) {
  816. ut_assert(!ret);
  817. ut_assertnonnull(dev);
  818. }
  819. ut_assertok(uclass_find_first_device(UCLASS_TEST_DUMMY, &dev));
  820. ut_assertnull(dev);
  821. return 0;
  822. }
  823. DM_TEST(dm_test_uclass_devices_find, UT_TESTF_SCAN_PDATA);
  824. static int dm_test_uclass_devices_find_by_name(struct unit_test_state *uts)
  825. {
  826. struct udevice *finddev;
  827. struct udevice *testdev;
  828. int findret, ret;
  829. /*
  830. * For each test device found in fdt like: "a-test", "b-test", etc.,
  831. * use its name and try to find it by uclass_find_device_by_name().
  832. * Then, on success check if:
  833. * - current 'testdev' name is equal to the returned 'finddev' name
  834. * - current 'testdev' pointer is equal to the returned 'finddev'
  835. *
  836. * We assume that, each uclass's device name is unique, so if not, then
  837. * this will fail on checking condition: testdev == finddev, since the
  838. * uclass_find_device_by_name(), returns the first device by given name.
  839. */
  840. for (ret = uclass_find_first_device(UCLASS_TEST_FDT, &testdev);
  841. testdev;
  842. ret = uclass_find_next_device(&testdev)) {
  843. ut_assertok(ret);
  844. ut_assertnonnull(testdev);
  845. findret = uclass_find_device_by_name(UCLASS_TEST_FDT,
  846. testdev->name,
  847. &finddev);
  848. ut_assertok(findret);
  849. ut_assert(testdev);
  850. ut_asserteq_str(testdev->name, finddev->name);
  851. ut_asserteq_ptr(testdev, finddev);
  852. }
  853. return 0;
  854. }
  855. DM_TEST(dm_test_uclass_devices_find_by_name, UT_TESTF_SCAN_FDT);
  856. static int dm_test_uclass_devices_get(struct unit_test_state *uts)
  857. {
  858. struct udevice *dev;
  859. int ret;
  860. for (ret = uclass_first_device(UCLASS_TEST, &dev);
  861. dev;
  862. ret = uclass_next_device(&dev)) {
  863. ut_assert(!ret);
  864. ut_assert(dev);
  865. ut_assert(device_active(dev));
  866. }
  867. return 0;
  868. }
  869. DM_TEST(dm_test_uclass_devices_get, UT_TESTF_SCAN_PDATA);
  870. static int dm_test_uclass_devices_get_by_name(struct unit_test_state *uts)
  871. {
  872. struct udevice *finddev;
  873. struct udevice *testdev;
  874. int ret, findret;
  875. /*
  876. * For each test device found in fdt like: "a-test", "b-test", etc.,
  877. * use its name and try to get it by uclass_get_device_by_name().
  878. * On success check if:
  879. * - returned finddev' is active
  880. * - current 'testdev' name is equal to the returned 'finddev' name
  881. * - current 'testdev' pointer is equal to the returned 'finddev'
  882. *
  883. * We asserts that the 'testdev' is active on each loop entry, so we
  884. * could be sure that the 'finddev' is activated too, but for sure
  885. * we check it again.
  886. *
  887. * We assume that, each uclass's device name is unique, so if not, then
  888. * this will fail on checking condition: testdev == finddev, since the
  889. * uclass_get_device_by_name(), returns the first device by given name.
  890. */
  891. for (ret = uclass_first_device(UCLASS_TEST_FDT, &testdev);
  892. testdev;
  893. ret = uclass_next_device(&testdev)) {
  894. ut_assertok(ret);
  895. ut_assert(testdev);
  896. ut_assert(device_active(testdev));
  897. findret = uclass_get_device_by_name(UCLASS_TEST_FDT,
  898. testdev->name,
  899. &finddev);
  900. ut_assertok(findret);
  901. ut_assert(finddev);
  902. ut_assert(device_active(finddev));
  903. ut_asserteq_str(testdev->name, finddev->name);
  904. ut_asserteq_ptr(testdev, finddev);
  905. }
  906. return 0;
  907. }
  908. DM_TEST(dm_test_uclass_devices_get_by_name, UT_TESTF_SCAN_FDT);
  909. static int dm_test_device_get_uclass_id(struct unit_test_state *uts)
  910. {
  911. struct udevice *dev;
  912. ut_assertok(uclass_get_device(UCLASS_TEST, 0, &dev));
  913. ut_asserteq(UCLASS_TEST, device_get_uclass_id(dev));
  914. return 0;
  915. }
  916. DM_TEST(dm_test_device_get_uclass_id, UT_TESTF_SCAN_PDATA);
  917. static int dm_test_uclass_names(struct unit_test_state *uts)
  918. {
  919. ut_asserteq_str("test", uclass_get_name(UCLASS_TEST));
  920. ut_asserteq(UCLASS_TEST, uclass_get_by_name("test"));
  921. return 0;
  922. }
  923. DM_TEST(dm_test_uclass_names, UT_TESTF_SCAN_PDATA);
  924. static int dm_test_inactive_child(struct unit_test_state *uts)
  925. {
  926. struct udevice *parent, *dev1, *dev2;
  927. /* Skip the behaviour in test_post_probe() */
  928. uts->skip_post_probe = 1;
  929. ut_assertok(uclass_first_device_err(UCLASS_TEST, &parent));
  930. /*
  931. * Create a child but do not activate it. Calling the function again
  932. * should return the same child.
  933. */
  934. ut_asserteq(-ENODEV, device_find_first_inactive_child(parent,
  935. UCLASS_TEST, &dev1));
  936. ut_assertok(device_bind(parent, DM_DRIVER_GET(test_drv),
  937. "test_child", 0, ofnode_null(), &dev1));
  938. ut_assertok(device_find_first_inactive_child(parent, UCLASS_TEST,
  939. &dev2));
  940. ut_asserteq_ptr(dev1, dev2);
  941. ut_assertok(device_probe(dev1));
  942. ut_asserteq(-ENODEV, device_find_first_inactive_child(parent,
  943. UCLASS_TEST, &dev2));
  944. return 0;
  945. }
  946. DM_TEST(dm_test_inactive_child, UT_TESTF_SCAN_PDATA);
  947. /* Make sure all bound devices have a sequence number */
  948. static int dm_test_all_have_seq(struct unit_test_state *uts)
  949. {
  950. struct udevice *dev;
  951. struct uclass *uc;
  952. list_for_each_entry(uc, gd->uclass_root, sibling_node) {
  953. list_for_each_entry(dev, &uc->dev_head, uclass_node) {
  954. if (dev->seq_ == -1)
  955. printf("Device '%s' has no seq (%d)\n",
  956. dev->name, dev->seq_);
  957. ut_assert(dev->seq_ != -1);
  958. }
  959. }
  960. return 0;
  961. }
  962. DM_TEST(dm_test_all_have_seq, UT_TESTF_SCAN_PDATA);
  963. #if CONFIG_IS_ENABLED(DM_DMA)
  964. static int dm_test_dma_offset(struct unit_test_state *uts)
  965. {
  966. struct udevice *dev;
  967. ofnode node;
  968. /* Make sure the bus's dma-ranges aren't taken into account here */
  969. node = ofnode_path("/mmio-bus@0");
  970. ut_assert(ofnode_valid(node));
  971. ut_assertok(uclass_get_device_by_ofnode(UCLASS_TEST_BUS, node, &dev));
  972. ut_asserteq_64(0, dev->dma_offset);
  973. /* Device behind a bus with dma-ranges */
  974. node = ofnode_path("/mmio-bus@0/subnode@0");
  975. ut_assert(ofnode_valid(node));
  976. ut_assertok(uclass_get_device_by_ofnode(UCLASS_TEST_FDT, node, &dev));
  977. ut_asserteq_64(-0x10000000ULL, dev->dma_offset);
  978. /* This one has no dma-ranges */
  979. node = ofnode_path("/mmio-bus@1");
  980. ut_assert(ofnode_valid(node));
  981. ut_assertok(uclass_get_device_by_ofnode(UCLASS_TEST_BUS, node, &dev));
  982. node = ofnode_path("/mmio-bus@1/subnode@0");
  983. ut_assert(ofnode_valid(node));
  984. ut_assertok(uclass_get_device_by_ofnode(UCLASS_TEST_FDT, node, &dev));
  985. ut_asserteq_64(0, dev->dma_offset);
  986. return 0;
  987. }
  988. DM_TEST(dm_test_dma_offset, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  989. #endif