last_radio_log.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* arch/arm/mach-msm/last_radio_log.c
  2. *
  3. * Extract the log from a modem crash though SMEM
  4. *
  5. * Copyright (C) 2007 Google, Inc.
  6. *
  7. * This software is licensed under the terms of the GNU General Public
  8. * License version 2, as published by the Free Software Foundation, and
  9. * may be copied, distributed, and modified under those terms.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/module.h>
  19. #include <linux/fs.h>
  20. #include <linux/proc_fs.h>
  21. #include <linux/uaccess.h>
  22. #include "smd_private.h"
  23. static void *radio_log_base;
  24. static size_t radio_log_size;
  25. extern void *smem_item(unsigned id, unsigned *size);
  26. static ssize_t last_radio_log_read(struct file *file, char __user *buf,
  27. size_t len, loff_t *offset)
  28. {
  29. loff_t pos = *offset;
  30. ssize_t count;
  31. if (pos >= radio_log_size)
  32. return 0;
  33. count = min(len, (size_t)(radio_log_size - pos));
  34. if (copy_to_user(buf, radio_log_base + pos, count)) {
  35. pr_err("%s: copy to user failed\n", __func__);
  36. return -EFAULT;
  37. }
  38. *offset += count;
  39. return count;
  40. }
  41. static struct file_operations last_radio_log_fops = {
  42. .read = last_radio_log_read,
  43. .llseek = default_llseek,
  44. };
  45. void msm_init_last_radio_log(struct module *owner)
  46. {
  47. struct proc_dir_entry *entry;
  48. if (last_radio_log_fops.owner) {
  49. pr_err("%s: already claimed\n", __func__);
  50. return;
  51. }
  52. radio_log_base = smem_item(SMEM_CLKREGIM_BSP, &radio_log_size);
  53. if (!radio_log_base) {
  54. pr_err("%s: could not retrieve SMEM_CLKREGIM_BSP\n", __func__);
  55. return;
  56. }
  57. entry = create_proc_entry("last_radio_log", S_IFREG | S_IRUGO, NULL);
  58. if (!entry) {
  59. pr_err("%s: could not create proc entry for radio log\n",
  60. __func__);
  61. return;
  62. }
  63. pr_err("%s: last radio log is %d bytes long\n", __func__,
  64. radio_log_size);
  65. last_radio_log_fops.owner = owner;
  66. entry->proc_fops = &last_radio_log_fops;
  67. entry->size = radio_log_size;
  68. }
  69. EXPORT_SYMBOL(msm_init_last_radio_log);