uh_debug_log.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include <linux/module.h>
  2. #include <linux/kernel.h>
  3. #include <linux/init.h>
  4. #include <linux/proc_fs.h>
  5. #include <linux/highmem.h>
  6. #include <linux/uh.h>
  7. ssize_t uh_log_read(struct file *filep, char __user *buf, size_t size, loff_t *offset)
  8. {
  9. static size_t log_buf_size;
  10. unsigned long *log_addr = 0;
  11. if (!strcmp(filep->f_path.dentry->d_iname, "uh_log"))
  12. log_addr = (unsigned long *)phys_to_virt(UH_LOG_START);
  13. else
  14. return -EINVAL;
  15. /* To print s2 table status */
  16. uh_call(UH_APP_INIT, 13, 0, 0, 0, 0);
  17. if (!*offset) {
  18. log_buf_size = 0;
  19. while (log_buf_size < UH_LOG_SIZE && ((char *)log_addr)[log_buf_size] != 0)
  20. log_buf_size++;
  21. }
  22. if (*offset >= log_buf_size)
  23. return 0;
  24. if (*offset + size > log_buf_size)
  25. size = log_buf_size - *offset;
  26. if (copy_to_user(buf, (const char *)log_addr + (*offset), size))
  27. return -EFAULT;
  28. *offset += size;
  29. return size;
  30. }
  31. static const struct proc_ops uh_proc_ops = {
  32. .proc_read = uh_log_read,
  33. };
  34. static int __init uh_log_init(void)
  35. {
  36. struct proc_dir_entry *entry;
  37. entry = proc_create("uh_log", 0644, NULL, &uh_proc_ops);
  38. if (!entry) {
  39. pr_err("uh_log: Error creating proc entry\n");
  40. return -ENOMEM;
  41. }
  42. pr_info("uh_log : create /proc/uh_log\n");
  43. return 0;
  44. }
  45. static void __exit uh_log_exit(void)
  46. {
  47. remove_proc_entry("uh_log", NULL);
  48. }
  49. module_init(uh_log_init);
  50. module_exit(uh_log_exit);