cpuss_dump.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* Copyright (c) 2014-2017, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. */
  13. #include <linux/module.h>
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/of.h>
  17. #include <linux/of_device.h>
  18. #include <linux/dma-mapping.h>
  19. #include <linux/slab.h>
  20. #include <soc/qcom/memory_dump.h>
  21. static int cpuss_dump_probe(struct platform_device *pdev)
  22. {
  23. struct device_node *child_node, *dump_node;
  24. const struct device_node *node = pdev->dev.of_node;
  25. static dma_addr_t dump_addr;
  26. static void *dump_vaddr;
  27. struct msm_dump_data *dump_data;
  28. struct msm_dump_entry dump_entry;
  29. int ret;
  30. u32 size, id;
  31. for_each_available_child_of_node(node, child_node) {
  32. dump_node = of_parse_phandle(child_node, "qcom,dump-node", 0);
  33. if (!dump_node) {
  34. dev_err(&pdev->dev, "Unable to find node for %s\n",
  35. child_node->name);
  36. continue;
  37. }
  38. ret = of_property_read_u32(dump_node, "qcom,dump-size", &size);
  39. if (ret) {
  40. dev_err(&pdev->dev, "Unable to find size for %s\n",
  41. dump_node->name);
  42. continue;
  43. }
  44. ret = of_property_read_u32(child_node, "qcom,dump-id", &id);
  45. if (ret) {
  46. dev_err(&pdev->dev, "Unable to find id for %s\n",
  47. child_node->name);
  48. continue;
  49. }
  50. dump_vaddr = (void *) dma_alloc_coherent(&pdev->dev, size,
  51. &dump_addr, GFP_KERNEL);
  52. if (!dump_vaddr) {
  53. dev_err(&pdev->dev, "Couldn't get memory for dumping\n");
  54. continue;
  55. }
  56. memset(dump_vaddr, 0x0, size);
  57. dump_data = devm_kzalloc(&pdev->dev,
  58. sizeof(struct msm_dump_data), GFP_KERNEL);
  59. if (!dump_data) {
  60. dma_free_coherent(&pdev->dev, size, dump_vaddr,
  61. dump_addr);
  62. continue;
  63. }
  64. dump_data->addr = dump_addr;
  65. dump_data->len = size;
  66. scnprintf(dump_data->name, sizeof(dump_data->name),
  67. "KCPUSS%X", id);
  68. dump_entry.id = id;
  69. dump_entry.addr = virt_to_phys(dump_data);
  70. ret = msm_dump_data_register(MSM_DUMP_TABLE_APPS, &dump_entry);
  71. if (ret) {
  72. dev_err(&pdev->dev, "Data dump setup failed, id = %d\n",
  73. id);
  74. dma_free_coherent(&pdev->dev, size, dump_vaddr,
  75. dump_addr);
  76. devm_kfree(&pdev->dev, dump_data);
  77. }
  78. }
  79. return 0;
  80. }
  81. static int cpuss_dump_remove(struct platform_device *pdev)
  82. {
  83. return 0;
  84. }
  85. static const struct of_device_id cpuss_dump_match_table[] = {
  86. { .compatible = "qcom,cpuss-dump", },
  87. {}
  88. };
  89. static struct platform_driver cpuss_dump_driver = {
  90. .probe = cpuss_dump_probe,
  91. .remove = cpuss_dump_remove,
  92. .driver = {
  93. .name = "msm_cpuss_dump",
  94. .owner = THIS_MODULE,
  95. .of_match_table = cpuss_dump_match_table,
  96. },
  97. };
  98. static int __init cpuss_dump_init(void)
  99. {
  100. return platform_driver_register(&cpuss_dump_driver);
  101. }
  102. static void __exit cpuss_dump_exit(void)
  103. {
  104. platform_driver_unregister(&cpuss_dump_driver);
  105. }
  106. subsys_initcall(cpuss_dump_init);
  107. module_exit(cpuss_dump_exit)