tima_debug_log.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #include <linux/module.h>
  2. #include <linux/kernel.h>
  3. #include <linux/init.h>
  4. #include <linux/types.h>
  5. #include <linux/proc_fs.h>
  6. #include <linux/seq_file.h>
  7. #include <linux/mm.h>
  8. #include <linux/highmem.h>
  9. #include <linux/io.h>
  10. #include <linux/types.h>
  11. #if defined(CONFIG_ARCH_MSM8974PRO)
  12. #define DEBUG_LOG_START (0x07100000)
  13. #elif defined(CONFIG_ARCH_MSM8974)
  14. #define DEBUG_LOG_START (0x07300000)
  15. #elif defined(CONFIG_ARCH_MSM8226_3G_WIFI)
  16. #if !defined CONFIG_TIMA_RKP
  17. #define DEBUG_LOG_START (0x0D180000)
  18. #else
  19. #define DEBUG_LOG_START (0x10400000)
  20. #endif
  21. #elif defined(CONFIG_ARCH_MSM8926_LTE)
  22. #define DEBUG_LOG_START (0x10A00000)
  23. #endif
  24. #if !defined CONFIG_TIMA_RKP
  25. #define DEBUG_LOG_SIZE (1<<19)
  26. #else
  27. #define DEBUG_LOG_SIZE (1<<20)
  28. #endif
  29. #define DEBUG_LOG_MAGIC (0xaabbccdd)
  30. #define DEBUG_LOG_ENTRY_SIZE 128
  31. typedef struct debug_log_entry_s
  32. {
  33. uint32_t timestamp; /* timestamp at which log entry was made*/
  34. uint32_t logger_id; /* id is 1 for tima, 2 for lkmauth app */
  35. #define DEBUG_LOG_MSG_SIZE (DEBUG_LOG_ENTRY_SIZE - sizeof(uint32_t) - sizeof(uint32_t))
  36. char log_msg[DEBUG_LOG_MSG_SIZE]; /* buffer for the entry */
  37. } __attribute__ ((packed)) debug_log_entry_t;
  38. typedef struct debug_log_header_s
  39. {
  40. uint32_t magic; /* magic number */
  41. uint32_t log_start_addr; /* address at which log starts */
  42. uint32_t log_write_addr; /* address at which next entry is written*/
  43. uint32_t num_log_entries; /* number of log entries */
  44. char padding[DEBUG_LOG_ENTRY_SIZE - 4 * sizeof(uint32_t)];
  45. } __attribute__ ((packed)) debug_log_header_t;
  46. #define DRIVER_DESC "A kernel module to read tima debug log"
  47. unsigned long *tima_debug_log_addr = 0;
  48. ssize_t tima_read(struct file *filep, char __user *buf, size_t size, loff_t *offset)
  49. {
  50. /* First check is to get rid of integer overflow exploits */
  51. if (size > DEBUG_LOG_SIZE || (*offset) + size > DEBUG_LOG_SIZE) {
  52. printk(KERN_ERR"Extra read\n");
  53. return -EINVAL;
  54. }
  55. if (copy_to_user(buf, (const char *)tima_debug_log_addr + (*offset), size)) {
  56. printk(KERN_ERR"Copy to user failed\n");
  57. return -1;
  58. } else {
  59. *offset += size;
  60. return size;
  61. }
  62. }
  63. static const struct file_operations tima_proc_fops = {
  64. .read = tima_read,
  65. };
  66. /**
  67. * tima_debug_log_read_init - Initialization function for TIMA
  68. *
  69. * It creates and initializes tima proc entry with initialized read handler
  70. */
  71. static int __init tima_debug_log_read_init(void)
  72. {
  73. if (proc_create("tima_debug_log", 0644,NULL, &tima_proc_fops) == NULL) {
  74. printk(KERN_ERR"tima_debug_log_read_init: Error creating proc entry\n");
  75. goto error_return;
  76. }
  77. printk(KERN_INFO"tima_debug_log_read_init: Registering /proc/tima_debug_log Interface \n");
  78. tima_debug_log_addr = (unsigned long *)ioremap(DEBUG_LOG_START, DEBUG_LOG_SIZE);
  79. if (tima_debug_log_addr == NULL) {
  80. printk(KERN_ERR"tima_debug_log_read_init: ioremap Failed\n");
  81. goto ioremap_failed;
  82. }
  83. return 0;
  84. ioremap_failed:
  85. remove_proc_entry("tima_debug_log", NULL);
  86. error_return:
  87. return -1;
  88. }
  89. /**
  90. * tima_debug_log_read_exit - Cleanup Code for TIMA
  91. *
  92. * It removes /proc/tima proc entry and does the required cleanup operations
  93. */
  94. static void __exit tima_debug_log_read_exit(void)
  95. {
  96. remove_proc_entry("tima_debug_log", NULL);
  97. printk(KERN_INFO"Deregistering /proc/tima_debug_log Interface\n");
  98. if(tima_debug_log_addr != NULL)
  99. iounmap(tima_debug_log_addr);
  100. }
  101. module_init(tima_debug_log_read_init);
  102. module_exit(tima_debug_log_read_exit);
  103. MODULE_DESCRIPTION(DRIVER_DESC);