pstore.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * Persistent Storage - pstore.h
  3. *
  4. * Copyright (C) 2010 Intel Corporation <tony.luck@intel.com>
  5. *
  6. * This code is the generic layer to export data records from platform
  7. * level persistent storage via a file system.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #ifndef _LINUX_PSTORE_H
  23. #define _LINUX_PSTORE_H
  24. #include <linux/compiler.h>
  25. #include <linux/errno.h>
  26. #include <linux/kmsg_dump.h>
  27. #include <linux/mutex.h>
  28. #include <linux/spinlock.h>
  29. #include <linux/time.h>
  30. #include <linux/types.h>
  31. /* types */
  32. enum pstore_type_id {
  33. PSTORE_TYPE_DMESG = 0,
  34. PSTORE_TYPE_MCE = 1,
  35. PSTORE_TYPE_CONSOLE = 2,
  36. PSTORE_TYPE_FTRACE = 3,
  37. /* PPC64 partition types */
  38. PSTORE_TYPE_PPC_RTAS = 4,
  39. PSTORE_TYPE_PPC_OF = 5,
  40. PSTORE_TYPE_PPC_COMMON = 6,
  41. PSTORE_TYPE_PMSG = 7,
  42. PSTORE_TYPE_PPC_OPAL = 8,
  43. PSTORE_TYPE_UNKNOWN = 255
  44. };
  45. struct module;
  46. struct pstore_info {
  47. struct module *owner;
  48. char *name;
  49. spinlock_t buf_lock; /* serialize access to 'buf' */
  50. char *buf;
  51. size_t bufsize;
  52. struct mutex read_mutex; /* serialize open/read/close */
  53. int flags;
  54. int (*open)(struct pstore_info *psi);
  55. int (*close)(struct pstore_info *psi);
  56. ssize_t (*read)(u64 *id, enum pstore_type_id *type,
  57. int *count, struct timespec *time, char **buf,
  58. bool *compressed, ssize_t *ecc_notice_size,
  59. struct pstore_info *psi);
  60. int (*write)(enum pstore_type_id type,
  61. enum kmsg_dump_reason reason, u64 *id,
  62. unsigned int part, int count, bool compressed,
  63. size_t size, struct pstore_info *psi);
  64. int (*write_buf)(enum pstore_type_id type,
  65. enum kmsg_dump_reason reason, u64 *id,
  66. unsigned int part, const char *buf, bool compressed,
  67. size_t size, struct pstore_info *psi);
  68. int (*write_buf_user)(enum pstore_type_id type,
  69. enum kmsg_dump_reason reason, u64 *id,
  70. unsigned int part, const char __user *buf,
  71. bool compressed, size_t size, struct pstore_info *psi);
  72. int (*erase)(enum pstore_type_id type, u64 id,
  73. int count, struct timespec time,
  74. struct pstore_info *psi);
  75. void *data;
  76. };
  77. #define PSTORE_FLAGS_DMESG (1 << 0)
  78. #define PSTORE_FLAGS_FRAGILE PSTORE_FLAGS_DMESG
  79. #define PSTORE_FLAGS_CONSOLE (1 << 1)
  80. #define PSTORE_FLAGS_FTRACE (1 << 2)
  81. #define PSTORE_FLAGS_PMSG (1 << 3)
  82. extern int pstore_register(struct pstore_info *);
  83. extern void pstore_unregister(struct pstore_info *);
  84. extern bool pstore_cannot_block_path(enum kmsg_dump_reason reason);
  85. struct pstore_ftrace_record {
  86. unsigned long ip;
  87. unsigned long parent_ip;
  88. u64 ts;
  89. };
  90. /*
  91. * ftrace related stuff: Both backends and frontends need these so expose
  92. * them here.
  93. */
  94. #if NR_CPUS <= 2 && defined(CONFIG_ARM_THUMB)
  95. #define PSTORE_CPU_IN_IP 0x1
  96. #elif NR_CPUS <= 4 && defined(CONFIG_ARM)
  97. #define PSTORE_CPU_IN_IP 0x3
  98. #endif
  99. #define TS_CPU_SHIFT 8
  100. #define TS_CPU_MASK (BIT(TS_CPU_SHIFT) - 1)
  101. /*
  102. * If CPU number can be stored in IP, store it there, otherwise store it in
  103. * the time stamp. This means more timestamp resolution is available when
  104. * the CPU can be stored in the IP.
  105. */
  106. #ifdef PSTORE_CPU_IN_IP
  107. static inline void
  108. pstore_ftrace_encode_cpu(struct pstore_ftrace_record *rec, unsigned int cpu)
  109. {
  110. rec->ip |= cpu;
  111. }
  112. static inline unsigned int
  113. pstore_ftrace_decode_cpu(struct pstore_ftrace_record *rec)
  114. {
  115. return rec->ip & PSTORE_CPU_IN_IP;
  116. }
  117. static inline u64
  118. pstore_ftrace_read_timestamp(struct pstore_ftrace_record *rec)
  119. {
  120. return rec->ts;
  121. }
  122. static inline void
  123. pstore_ftrace_write_timestamp(struct pstore_ftrace_record *rec, u64 val)
  124. {
  125. rec->ts = val;
  126. }
  127. #else
  128. static inline void
  129. pstore_ftrace_encode_cpu(struct pstore_ftrace_record *rec, unsigned int cpu)
  130. {
  131. rec->ts &= ~(TS_CPU_MASK);
  132. rec->ts |= cpu;
  133. }
  134. static inline unsigned int
  135. pstore_ftrace_decode_cpu(struct pstore_ftrace_record *rec)
  136. {
  137. return rec->ts & TS_CPU_MASK;
  138. }
  139. static inline u64
  140. pstore_ftrace_read_timestamp(struct pstore_ftrace_record *rec)
  141. {
  142. return rec->ts >> TS_CPU_SHIFT;
  143. }
  144. static inline void
  145. pstore_ftrace_write_timestamp(struct pstore_ftrace_record *rec, u64 val)
  146. {
  147. rec->ts = (rec->ts & TS_CPU_MASK) | (val << TS_CPU_SHIFT);
  148. }
  149. #endif
  150. #endif /*_LINUX_PSTORE_H*/