thermal_minidump.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #include <linux/module.h>
  6. #include <linux/slab.h>
  7. #include <linux/string.h>
  8. #include <linux/thermal_minidump.h>
  9. #include <trace/events/thermal.h>
  10. /**
  11. * thermal_minidump_update_data - function to update thermal minidump data
  12. *
  13. * @md : The pointer of minidump data
  14. * @type: sensor type to stored
  15. * @temp: temperature to stored
  16. *
  17. * This function gives the ability for driver save temperature
  18. * data into miniudmps
  19. *
  20. * Return:
  21. * zero on success.
  22. * Negative error number on failures.
  23. */
  24. int thermal_minidump_update_data(struct minidump_data *md,
  25. char *type, int *temp)
  26. {
  27. int ret;
  28. unsigned long flags;
  29. spin_lock_irqsave(&md->update_md_lock, flags);
  30. if (md->md_count == MD_NUM)
  31. md->md_count = 0;
  32. strscpy(md->type[md->md_count].sensor_type, type,
  33. THERMAL_NAME_LENGTH);
  34. md->temp[md->md_count] = *temp;
  35. md->md_count++;
  36. ret = msm_minidump_update_region(md->region, &md->md_entry);
  37. spin_unlock_irqrestore(&md->update_md_lock, flags);
  38. if (ret < 0)
  39. pr_err("Failed to update data to minidump, ret:%d\n", ret);
  40. return ret;
  41. }
  42. EXPORT_SYMBOL(thermal_minidump_update_data);
  43. /**
  44. * thermal_minidump_register - function to register thermal data region
  45. * into minidump
  46. *
  47. * @name: The pointer of driver devicetree full name
  48. *
  49. * This function gives the ability for driver register an entry in
  50. * Minidump table
  51. *
  52. * Return:
  53. * md: The pointer of minidump data.
  54. * NULL : thermal minidump register fail.
  55. */
  56. struct minidump_data *thermal_minidump_register(const char *name)
  57. {
  58. struct minidump_data *md;
  59. md = kzalloc(sizeof(*md), GFP_KERNEL);
  60. if (!md)
  61. return NULL;
  62. strscpy(md->md_entry.name, name, sizeof(md->md_entry.name));
  63. md->md_entry.virt_addr = (uintptr_t)md;
  64. md->md_entry.phys_addr = virt_to_phys(md);
  65. md->md_entry.size = sizeof(*md);
  66. md->region = msm_minidump_add_region(&md->md_entry);
  67. if (md->region < 0) {
  68. kfree(md);
  69. md = NULL;
  70. pr_err("Failed to add %s into minidump\n", name);
  71. goto exit;
  72. }
  73. spin_lock_init(&md->update_md_lock);
  74. exit:
  75. return md;
  76. }
  77. EXPORT_SYMBOL(thermal_minidump_register);
  78. /**
  79. * thermal_minidump_unregister - function to unregister thermal data region
  80. * in minidump
  81. *
  82. * @md : The pointer of minidump data
  83. *
  84. * This function gives the ability for driver unregister an entry in
  85. * Minidump table
  86. */
  87. void thermal_minidump_unregister(struct minidump_data *md)
  88. {
  89. if (md) {
  90. msm_minidump_remove_region(&md->md_entry);
  91. kfree(md);
  92. }
  93. }
  94. EXPORT_SYMBOL(thermal_minidump_unregister);
  95. MODULE_DESCRIPTION("Qualcomm Technologies Inc. Thermal minidump driver");
  96. MODULE_LICENSE("GPL");