abc_hub_bootc.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* abc_hub_bootc.c
  2. *
  3. * Abnormal Behavior Catcher Hub Driver Sub Module(Booting Time Check)
  4. *
  5. * Copyright (C) 2017 Samsung Electronics
  6. *
  7. * Sangsu Ha <[email protected]>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. */
  20. #include <linux/sti/abc_hub.h>
  21. #include <linux/workqueue.h>
  22. #if IS_ENABLED(CONFIG_SEC_KUNIT)
  23. #include <linux/sti/abc_kunit.h>
  24. #endif
  25. char bootc_offset_module[BOOTC_OFFSET_DATA_CNT][BOOTC_OFFSET_STR_MAX] = {"fsck"};
  26. EXPORT_SYMBOL_KUNIT(bootc_offset_module);
  27. __visible_for_testing
  28. int abc_hub_bootc_get_total_offset(struct sub_bootc_pdata *bootc_pdata)
  29. {
  30. int total_offset = 0;
  31. int i;
  32. for (i = 0; i < BOOTC_OFFSET_DATA_CNT; i++)
  33. total_offset += bootc_pdata->offset_data[i].offset;
  34. return total_offset;
  35. }
  36. EXPORT_SYMBOL_KUNIT(abc_hub_bootc_get_total_offset);
  37. static void abc_hub_bootc_work_func(struct work_struct *work)
  38. {
  39. struct sub_bootc_pdata *bootc_pdata = container_of(work, struct sub_bootc_pdata, bootc_work.work);
  40. int fixed_time_spec;
  41. bootc_pdata->time_spec_offset = abc_hub_bootc_get_total_offset(bootc_pdata);
  42. fixed_time_spec = bootc_pdata->time_spec + bootc_pdata->time_spec_offset;
  43. ABC_PRINT("bootc_time : %d, time_spec : %d(%d + %d))",
  44. bootc_pdata->bootc_time, fixed_time_spec,
  45. bootc_pdata->time_spec, bootc_pdata->time_spec_offset);
  46. if (bootc_pdata->bootc_time < 0) {
  47. ABC_PRINT("boot_time_parse fail(%d)", bootc_pdata->bootc_time);
  48. } else {
  49. #if IS_ENABLED(CONFIG_SEC_ABC_MOTTO)
  50. motto_send_bootcheck_info(bootc_pdata->bootc_time / MSEC_PER_SEC);
  51. #endif
  52. if (bootc_pdata->bootc_time > fixed_time_spec) {
  53. ABC_PRINT_KUNIT("booting time is spec out");
  54. #if IS_ENABLED(CONFIG_SEC_FACTORY)
  55. abc_hub_send_event("MODULE=bootc@INFO=boot_time_fail");
  56. #else
  57. abc_hub_send_event("MODULE=bootc@WARN=boot_time_fail");
  58. #endif
  59. }
  60. }
  61. }
  62. int parse_bootc_data(struct device *dev,
  63. struct abc_hub_platform_data *pdata,
  64. struct device_node *np)
  65. {
  66. struct device_node *bootc_np;
  67. bootc_np = of_find_node_by_name(np, "bootc");
  68. #if IS_ENABLED(CONFIG_SEC_FACTORY)
  69. if (of_property_read_u32(bootc_np, "bootc,time_spec_fac", &pdata->bootc_pdata.time_spec)) {
  70. dev_err(dev, "Failed to get bootc,time_spec_fac: node not exist");
  71. return -EINVAL;
  72. }
  73. ABC_PRINT("time_spec(factory binary) - %d", pdata->bootc_pdata.time_spec);
  74. #elif IS_ENABLED(CONFIG_SEC_ABC_HUB_BOOTC_ENG)
  75. if (of_property_read_u32(bootc_np, "bootc,time_spec_eng", &pdata->bootc_pdata.time_spec)) {
  76. dev_err(dev, "Failed to get bootc,time_spec_eng: node not exist");
  77. return -EINVAL;
  78. }
  79. ABC_PRINT("time_spec(user binary eng build) - %d", pdata->bootc_pdata.time_spec);
  80. #else
  81. if (of_property_read_u32(bootc_np, "bootc,time_spec_user", &pdata->bootc_pdata.time_spec)) {
  82. dev_err(dev, "Failed to get bootc,time_spec_user: node not exist");
  83. return -EINVAL;
  84. }
  85. ABC_PRINT("time_spec(user binary user build) - %d", pdata->bootc_pdata.time_spec);
  86. #endif
  87. return 0;
  88. }
  89. void abc_hub_bootc_enable(struct device *dev, int enable)
  90. {
  91. /* common sequence */
  92. abc_hub_pinfo->pdata->bootc_pdata.enabled = enable;
  93. /* custom sequence */
  94. ABC_PRINT("enable(%d)", enable);
  95. if (enable == ABC_HUB_ENABLED)
  96. queue_delayed_work(abc_hub_pinfo->pdata->bootc_pdata.workqueue,
  97. &abc_hub_pinfo->pdata->bootc_pdata.bootc_work, msecs_to_jiffies(2000));
  98. }
  99. int abc_hub_bootc_init_work(void)
  100. {
  101. INIT_DELAYED_WORK(&abc_hub_pinfo->pdata->bootc_pdata.bootc_work, abc_hub_bootc_work_func);
  102. abc_hub_pinfo->pdata->bootc_pdata.workqueue = create_singlethread_workqueue("bootc_wq");
  103. if (!abc_hub_pinfo->pdata->bootc_pdata.workqueue) {
  104. ABC_PRINT("fail");
  105. return -1;
  106. }
  107. return 0;
  108. }
  109. EXPORT_SYMBOL_KUNIT(abc_hub_bootc_init_work);
  110. int abc_hub_bootc_init(struct device *dev)
  111. {
  112. int i;
  113. for (i = 0; i < BOOTC_OFFSET_DATA_CNT; i++) {
  114. strcpy(abc_hub_pinfo->pdata->bootc_pdata.offset_data[i].module, bootc_offset_module[i]);
  115. abc_hub_pinfo->pdata->bootc_pdata.offset_data[i].offset = 0;
  116. }
  117. abc_hub_pinfo->pdata->bootc_pdata.bootc_time = -1;
  118. if (abc_hub_bootc_init_work())
  119. return -1;
  120. ABC_PRINT("success");
  121. return 0;
  122. }
  123. MODULE_DESCRIPTION("Samsung ABC Hub Sub Module(bootc) Driver");
  124. MODULE_AUTHOR("Samsung Electronics");
  125. MODULE_LICENSE("GPL");