pstore_ram.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2010 Marco Stornelli <[email protected]>
  4. * Copyright (C) 2011 Kees Cook <[email protected]>
  5. * Copyright (C) 2011 Google, Inc.
  6. */
  7. #ifndef __LINUX_PSTORE_RAM_H__
  8. #define __LINUX_PSTORE_RAM_H__
  9. #include <linux/compiler.h>
  10. #include <linux/device.h>
  11. #include <linux/init.h>
  12. #include <linux/kernel.h>
  13. #include <linux/list.h>
  14. #include <linux/pstore.h>
  15. #include <linux/types.h>
  16. /*
  17. * Choose whether access to the RAM zone requires locking or not. If a zone
  18. * can be written to from different CPUs like with ftrace for example, then
  19. * PRZ_FLAG_NO_LOCK is used. For all other cases, locking is required.
  20. */
  21. #define PRZ_FLAG_NO_LOCK BIT(0)
  22. /*
  23. * If a PRZ should only have a single-boot lifetime, this marks it as
  24. * getting wiped after its contents get copied out after boot.
  25. */
  26. #define PRZ_FLAG_ZAP_OLD BIT(1)
  27. struct persistent_ram_buffer;
  28. struct rs_control;
  29. struct persistent_ram_ecc_info {
  30. int block_size;
  31. int ecc_size;
  32. int symsize;
  33. int poly;
  34. uint16_t *par;
  35. };
  36. /**
  37. * struct persistent_ram_zone - Details of a persistent RAM zone (PRZ)
  38. * used as a pstore backend
  39. *
  40. * @paddr: physical address of the mapped RAM area
  41. * @size: size of mapping
  42. * @label: unique name of this PRZ
  43. * @type: frontend type for this PRZ
  44. * @flags: holds PRZ_FLAGS_* bits
  45. *
  46. * @buffer_lock:
  47. * locks access to @buffer "size" bytes and "start" offset
  48. * @buffer:
  49. * pointer to actual RAM area managed by this PRZ
  50. * @buffer_size:
  51. * bytes in @buffer->data (not including any trailing ECC bytes)
  52. *
  53. * @par_buffer:
  54. * pointer into @buffer->data containing ECC bytes for @buffer->data
  55. * @par_header:
  56. * pointer into @buffer->data containing ECC bytes for @buffer header
  57. * (i.e. all fields up to @data)
  58. * @rs_decoder:
  59. * RSLIB instance for doing ECC calculations
  60. * @corrected_bytes:
  61. * ECC corrected bytes accounting since boot
  62. * @bad_blocks:
  63. * ECC uncorrectable bytes accounting since boot
  64. * @ecc_info:
  65. * ECC configuration details
  66. *
  67. * @old_log:
  68. * saved copy of @buffer->data prior to most recent wipe
  69. * @old_log_size:
  70. * bytes contained in @old_log
  71. *
  72. */
  73. struct persistent_ram_zone {
  74. phys_addr_t paddr;
  75. size_t size;
  76. void *vaddr;
  77. char *label;
  78. enum pstore_type_id type;
  79. u32 flags;
  80. raw_spinlock_t buffer_lock;
  81. struct persistent_ram_buffer *buffer;
  82. size_t buffer_size;
  83. char *par_buffer;
  84. char *par_header;
  85. struct rs_control *rs_decoder;
  86. int corrected_bytes;
  87. int bad_blocks;
  88. struct persistent_ram_ecc_info ecc_info;
  89. char *old_log;
  90. size_t old_log_size;
  91. };
  92. struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size,
  93. u32 sig, struct persistent_ram_ecc_info *ecc_info,
  94. unsigned int memtype, u32 flags, char *label);
  95. void persistent_ram_free(struct persistent_ram_zone *prz);
  96. void persistent_ram_zap(struct persistent_ram_zone *prz);
  97. int persistent_ram_write(struct persistent_ram_zone *prz, const void *s,
  98. unsigned int count);
  99. int persistent_ram_write_user(struct persistent_ram_zone *prz,
  100. const void __user *s, unsigned int count);
  101. void persistent_ram_save_old(struct persistent_ram_zone *prz);
  102. size_t persistent_ram_old_size(struct persistent_ram_zone *prz);
  103. void *persistent_ram_old(struct persistent_ram_zone *prz);
  104. void persistent_ram_free_old(struct persistent_ram_zone *prz);
  105. ssize_t persistent_ram_ecc_string(struct persistent_ram_zone *prz,
  106. char *str, size_t len);
  107. /*
  108. * Ramoops platform data
  109. * @mem_size memory size for ramoops
  110. * @mem_address physical memory address to contain ramoops
  111. */
  112. #define RAMOOPS_FLAG_FTRACE_PER_CPU BIT(0)
  113. struct ramoops_platform_data {
  114. unsigned long mem_size;
  115. phys_addr_t mem_address;
  116. unsigned int mem_type;
  117. unsigned long record_size;
  118. unsigned long console_size;
  119. unsigned long ftrace_size;
  120. unsigned long pmsg_size;
  121. int max_reason;
  122. u32 flags;
  123. struct persistent_ram_ecc_info ecc_info;
  124. };
  125. #endif