ram_internal.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2010 Marco Stornelli <marco.stornelli@gmail.com>
  4. * Copyright (C) 2011 Kees Cook <keescook@chromium.org>
  5. * Copyright (C) 2011 Google, Inc.
  6. */
  7. #include <linux/pstore_ram.h>
  8. /*
  9. * Choose whether access to the RAM zone requires locking or not. If a zone
  10. * can be written to from different CPUs like with ftrace for example, then
  11. * PRZ_FLAG_NO_LOCK is used. For all other cases, locking is required.
  12. */
  13. #define PRZ_FLAG_NO_LOCK BIT(0)
  14. /*
  15. * If a PRZ should only have a single-boot lifetime, this marks it as
  16. * getting wiped after its contents get copied out after boot.
  17. */
  18. #define PRZ_FLAG_ZAP_OLD BIT(1)
  19. /**
  20. * struct persistent_ram_zone - Details of a persistent RAM zone (PRZ)
  21. * used as a pstore backend
  22. *
  23. * @paddr: physical address of the mapped RAM area
  24. * @size: size of mapping
  25. * @label: unique name of this PRZ
  26. * @type: frontend type for this PRZ
  27. * @flags: holds PRZ_FLAGS_* bits
  28. *
  29. * @buffer_lock:
  30. * locks access to @buffer "size" bytes and "start" offset
  31. * @buffer:
  32. * pointer to actual RAM area managed by this PRZ
  33. * @buffer_size:
  34. * bytes in @buffer->data (not including any trailing ECC bytes)
  35. *
  36. * @par_buffer:
  37. * pointer into @buffer->data containing ECC bytes for @buffer->data
  38. * @par_header:
  39. * pointer into @buffer->data containing ECC bytes for @buffer header
  40. * (i.e. all fields up to @data)
  41. * @rs_decoder:
  42. * RSLIB instance for doing ECC calculations
  43. * @corrected_bytes:
  44. * ECC corrected bytes accounting since boot
  45. * @bad_blocks:
  46. * ECC uncorrectable bytes accounting since boot
  47. * @ecc_info:
  48. * ECC configuration details
  49. *
  50. * @old_log:
  51. * saved copy of @buffer->data prior to most recent wipe
  52. * @old_log_size:
  53. * bytes contained in @old_log
  54. *
  55. */
  56. struct persistent_ram_zone {
  57. phys_addr_t paddr;
  58. size_t size;
  59. void *vaddr;
  60. char *label;
  61. enum pstore_type_id type;
  62. u32 flags;
  63. raw_spinlock_t buffer_lock;
  64. struct persistent_ram_buffer *buffer;
  65. size_t buffer_size;
  66. char *par_buffer;
  67. char *par_header;
  68. struct rs_control *rs_decoder;
  69. int corrected_bytes;
  70. int bad_blocks;
  71. struct persistent_ram_ecc_info ecc_info;
  72. char *old_log;
  73. size_t old_log_size;
  74. };
  75. struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size,
  76. u32 sig, struct persistent_ram_ecc_info *ecc_info,
  77. unsigned int memtype, u32 flags, char *label);
  78. void persistent_ram_free(struct persistent_ram_zone **_prz);
  79. void persistent_ram_zap(struct persistent_ram_zone *prz);
  80. int persistent_ram_write(struct persistent_ram_zone *prz, const void *s,
  81. unsigned int count);
  82. int persistent_ram_write_user(struct persistent_ram_zone *prz,
  83. const void __user *s, unsigned int count);
  84. void persistent_ram_save_old(struct persistent_ram_zone *prz);
  85. size_t persistent_ram_old_size(struct persistent_ram_zone *prz);
  86. void *persistent_ram_old(struct persistent_ram_zone *prz);
  87. void persistent_ram_free_old(struct persistent_ram_zone *prz);
  88. ssize_t persistent_ram_ecc_string(struct persistent_ram_zone *prz,
  89. char *str, size_t len);