sysreset.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (C) 2015 Google, Inc
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <sysreset.h>
  9. #include <asm/state.h>
  10. #include <asm/test.h>
  11. #include <dm/test.h>
  12. #include <test/ut.h>
  13. /* Test that we can use particular sysreset devices */
  14. static int dm_test_sysreset_base(struct unit_test_state *uts)
  15. {
  16. struct sandbox_state *state = state_get_current();
  17. struct udevice *dev;
  18. /* Device 0 is the platform data device - it should never respond */
  19. ut_assertok(uclass_get_device(UCLASS_SYSRESET, 0, &dev));
  20. ut_asserteq(-ENODEV, sysreset_request(dev, SYSRESET_WARM));
  21. ut_asserteq(-ENODEV, sysreset_request(dev, SYSRESET_COLD));
  22. ut_asserteq(-ENODEV, sysreset_request(dev, SYSRESET_POWER));
  23. /* Device 1 is the warm sysreset device */
  24. ut_assertok(uclass_get_device(UCLASS_SYSRESET, 1, &dev));
  25. ut_asserteq(-EACCES, sysreset_request(dev, SYSRESET_WARM));
  26. ut_asserteq(-ENOSYS, sysreset_request(dev, SYSRESET_COLD));
  27. ut_asserteq(-ENOSYS, sysreset_request(dev, SYSRESET_POWER));
  28. state->sysreset_allowed[SYSRESET_WARM] = true;
  29. ut_asserteq(-EINPROGRESS, sysreset_request(dev, SYSRESET_WARM));
  30. state->sysreset_allowed[SYSRESET_WARM] = false;
  31. /* Device 2 is the cold sysreset device */
  32. ut_assertok(uclass_get_device(UCLASS_SYSRESET, 2, &dev));
  33. ut_asserteq(-ENOSYS, sysreset_request(dev, SYSRESET_WARM));
  34. ut_asserteq(-EACCES, sysreset_request(dev, SYSRESET_COLD));
  35. state->sysreset_allowed[SYSRESET_POWER] = false;
  36. ut_asserteq(-EACCES, sysreset_request(dev, SYSRESET_POWER));
  37. state->sysreset_allowed[SYSRESET_POWER] = true;
  38. return 0;
  39. }
  40. DM_TEST(dm_test_sysreset_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
  41. /* Test that we can walk through the sysreset devices */
  42. static int dm_test_sysreset_walk(struct unit_test_state *uts)
  43. {
  44. struct sandbox_state *state = state_get_current();
  45. /* If we generate a power sysreset, we will exit sandbox! */
  46. state->sysreset_allowed[SYSRESET_POWER] = false;
  47. ut_asserteq(-EACCES, sysreset_walk(SYSRESET_WARM));
  48. ut_asserteq(-EACCES, sysreset_walk(SYSRESET_COLD));
  49. ut_asserteq(-EACCES, sysreset_walk(SYSRESET_POWER));
  50. /*
  51. * Enable cold system reset - this should make cold system reset work,
  52. * plus a warm system reset should be promoted to cold, since this is
  53. * the next step along.
  54. */
  55. state->sysreset_allowed[SYSRESET_COLD] = true;
  56. ut_asserteq(-EINPROGRESS, sysreset_walk(SYSRESET_WARM));
  57. ut_asserteq(-EINPROGRESS, sysreset_walk(SYSRESET_COLD));
  58. ut_asserteq(-EACCES, sysreset_walk(SYSRESET_POWER));
  59. state->sysreset_allowed[SYSRESET_COLD] = false;
  60. state->sysreset_allowed[SYSRESET_POWER] = true;
  61. return 0;
  62. }
  63. DM_TEST(dm_test_sysreset_walk, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);