smem.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * The shared memory system is an allocate-only heap structure that
  4. * consists of one of more memory areas that can be accessed by the processors
  5. * in the SoC.
  6. *
  7. * Allocation can be done globally for all processors or to an individual processor.
  8. * This is controlled by the @host parameter.
  9. *
  10. * Allocation and management of heap can be implemented in various ways,
  11. * The @item parameter should be used as an index/hash to the memory region.
  12. *
  13. * Copyright (c) 2018 Ramon Fried <ramon.fried@gmail.com>
  14. */
  15. #ifndef _smemh_
  16. #define _smemh_
  17. /* struct smem_ops: Operations for the SMEM uclass */
  18. struct smem_ops {
  19. /**
  20. * alloc() - allocate space for a smem item
  21. *
  22. * @host: remote processor id, or -1 for all processors.
  23. * @item: smem item handle
  24. * @size: number of bytes to be allocated
  25. * @return 0 if OK, -ve on error
  26. */
  27. int (*alloc)(unsigned int host,
  28. unsigned int item, size_t size);
  29. /**
  30. * get() - Resolve ptr of size of a smem item
  31. *
  32. * @host: the remote processor, of -1 for all processors.
  33. * @item: smem item handle
  34. * @size: pointer to be filled out with the size of the item
  35. * @return pointer on success, NULL on error
  36. */
  37. void *(*get)(unsigned int host,
  38. unsigned int item, size_t *size);
  39. /**
  40. * get_free_space() - Get free space in smem in bytes
  41. *
  42. * @host: the remote processor identifying a partition, or -1
  43. * for all processors.
  44. * @return free space, -ve on error
  45. */
  46. int (*get_free_space)(unsigned int host);
  47. };
  48. #define smem_get_ops(dev) ((struct smem_ops *)(dev)->driver->ops)
  49. /**
  50. * smem_alloc() - allocate space for a smem item
  51. * @host: remote processor id, or -1
  52. * @item: smem item handle
  53. * @size: number of bytes to be allocated
  54. * @return 0 if OK, -ve on error
  55. *
  56. * Allocate space for a given smem item of size @size, given that the item is
  57. * not yet allocated.
  58. */
  59. int smem_alloc(struct udevice *dev, unsigned int host, unsigned int item, size_t size);
  60. /**
  61. * smem_get() - resolve ptr of size of a smem item
  62. * @host: the remote processor, or -1 for all processors.
  63. * @item: smem item handle
  64. * @size: pointer to be filled out with size of the item
  65. * @return pointer on success, NULL on error
  66. *
  67. * Looks up smem item and returns pointer to it. Size of smem
  68. * item is returned in @size.
  69. */
  70. void *smem_get(struct udevice *dev, unsigned int host, unsigned int item, size_t *size);
  71. /**
  72. * smem_get_free_space() - retrieve amount of free space in a partition
  73. * @host: the remote processor identifying a partition, or -1
  74. * for all processors.
  75. * @return size in bytes, -ve on error
  76. *
  77. * To be used by smem clients as a quick way to determine if any new
  78. * allocations has been made.
  79. */
  80. int smem_get_free_space(struct udevice *dev, unsigned int host);
  81. #endif /* _smem_h_ */