shm_initialize.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /****************************************************************************
  2. * mm/shm/shm_initialize.c
  3. *
  4. * Copyright (C) 2014 Gregory Nutt. All rights reserved.
  5. * Author: Gregory Nutt <gnutt@nuttx.org>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ****************************************************************************/
  35. /****************************************************************************
  36. * Included Files
  37. ****************************************************************************/
  38. #include <nuttx/config.h>
  39. #include <assert.h>
  40. #include <errno.h>
  41. #include <nuttx/addrenv.h>
  42. #include <nuttx/sched.h>
  43. #include <nuttx/mm/gran.h>
  44. #include <nuttx/pgalloc.h>
  45. #include <nuttx/mm/shm.h>
  46. #include "shm/shm.h"
  47. #ifdef CONFIG_MM_SHM
  48. /****************************************************************************
  49. * Public Data
  50. ****************************************************************************/
  51. /* State of the all shared memory */
  52. struct shm_info_s g_shminfo;
  53. /****************************************************************************
  54. * Public Functions
  55. ****************************************************************************/
  56. /****************************************************************************
  57. * Name: shm_initialize
  58. *
  59. * Description:
  60. * Perform one time, start-up initialization of the shared memor logic.
  61. *
  62. * Input Parameters:
  63. * None
  64. *
  65. * Returned Value:
  66. * None
  67. *
  68. ****************************************************************************/
  69. void shm_initialize(void)
  70. {
  71. #if 0
  72. FAR struct shm_region_s *region;
  73. int i;
  74. #endif
  75. /* Initialize the shared memory region list */
  76. nxsem_init(&g_shminfo.si_sem, 0, 1);
  77. #if 0
  78. /* Initialize each shared memory region */
  79. for (i = 0; i < CONFIG_ARCH_SHM_NPAGES; i++)
  80. {
  81. region = &g_shminfo.si_region[i];
  82. /* Nothing to be done */
  83. }
  84. #endif
  85. }
  86. /****************************************************************************
  87. * Name: shm_group_initialize
  88. *
  89. * Description:
  90. * Initialize the group shared memory data structures when a new task
  91. * group is initialized.
  92. *
  93. * Input Parameters:
  94. * group - A reference to the new group structure to be initialized.
  95. *
  96. * Returned Value:
  97. * Zero (OK) on success; a negated errno value on failure.
  98. *
  99. ****************************************************************************/
  100. int shm_group_initialize(FAR struct task_group_s *group)
  101. {
  102. DEBUGASSERT(group && !group->tg_shm.gs_handle);
  103. group->tg_shm.gs_handle =
  104. gran_initialize((FAR void *)CONFIG_ARCH_SHM_VBASE,
  105. ARCH_SHM_MAXPAGES << MM_PGSHIFT,
  106. MM_PGSHIFT, MM_PGSHIFT);
  107. if (!group->tg_shm.gs_handle)
  108. {
  109. shmerr("ERROR: gran_initialize() failed\n");
  110. return -ENOMEM;
  111. }
  112. return OK;
  113. }
  114. /****************************************************************************
  115. * Name: shm_group_release
  116. *
  117. * Description:
  118. * Release resources used by the group shared memory logic. This function
  119. * is called at the time at the group is destroyed.
  120. *
  121. * Input Parameters:
  122. * group - A reference to the group structure to be un-initialized.
  123. *
  124. * Returned Value:
  125. * None
  126. *
  127. ****************************************************************************/
  128. void shm_group_release(FAR struct task_group_s *group)
  129. {
  130. GRAN_HANDLE handle;
  131. DEBUGASSERT(group);
  132. handle = group->tg_shm.gs_handle;
  133. if (handle)
  134. {
  135. gran_release(handle);
  136. }
  137. }
  138. #endif /* CONFIG_MM_SHM */