ump-import.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. *
  3. * (C) COPYRIGHT ARM Limited. All rights reserved.
  4. *
  5. * This program is free software and is provided to you under the terms of the
  6. * GNU General Public License version 2 as published by the Free Software
  7. * Foundation, and any use by you of this program is subject to the terms
  8. * of such GNU licence.
  9. *
  10. * A copy of the licence is included with the program, and can also be obtained
  11. * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  12. * Boston, MA 02110-1301, USA.
  13. *
  14. */
  15. #ifndef _UMP_IMPORT_H_
  16. #define _UMP_IMPORT_H_
  17. #include <linux/ump.h>
  18. #include <linux/module.h>
  19. /**
  20. * UMP import module info.
  21. * Contains information about the Linux module providing the import module,
  22. * used to block unloading of the Linux module while imported memory exists.
  23. * Lists the functions implementing the UMP import functions.
  24. */
  25. struct ump_import_handler
  26. {
  27. /**
  28. * Linux module of the import handler
  29. */
  30. struct module * linux_module;
  31. /**
  32. * UMP session usage begin.
  33. *
  34. * Called when a UMP session first is bound to the handler.
  35. * Typically used to set up any import module specific per-session data.
  36. * The function returns a pointer to this data in the output pointer custom_session_data
  37. * which will be passed to \a session_end and \a import.
  38. *
  39. * Note: custom_session_data must be set to non-NULL if successful.
  40. * If no pointer is needed set it a magic value to validate instead.
  41. *
  42. * @param[out] custom_session_data Pointer to a generic pointer where any data can be stored
  43. * @return 0 on success, error code if the session could not be initiated.
  44. */
  45. int (*session_begin)(void ** custom_session_data);
  46. /**
  47. * UMP session usage end.
  48. *
  49. * Called when a UMP session is no longer using the handler.
  50. * Only called if @a session_begin returned OK.
  51. *
  52. * @param[in] custom_session_data The value set by the session_begin handler
  53. */
  54. void (*session_end)(void * custom_session_data);
  55. /**
  56. * Import request.
  57. *
  58. * Called when a client has asked to import a resource of the type the import module was installed for.
  59. * Only called if @a session_begin returned OK.
  60. *
  61. * The requested flags must be verified to be valid to apply to the imported memory.
  62. * If not valid return UMP_DD_INVALID_MEMORY_HANDLE.
  63. * If the flags are found to be valid call \a ump_dd_create_from_phys_blocks_64 to create a handle.
  64. *
  65. * @param[in] custom_session_data The value set by the session_begin handler
  66. * @param[in] phandle Pointer to the handle to import
  67. * @param flags The requested UMPv2 flags to assign to the imported handle
  68. * @return UMP_DD_INVALID_MEMORY_HANDLE if the import failed, a valid ump handle on success
  69. */
  70. ump_dd_handle (*import)(void * custom_session_data, void * phandle, ump_alloc_flags flags);
  71. };
  72. /**
  73. * Import module registration.
  74. * Registers a ump_import_handler structure for a memory type.
  75. * @param type Type of the memory to register a handler for
  76. * @param[in] handler Handler strcture to install
  77. * @return 0 on success, a Linux error code on failure
  78. */
  79. int ump_import_module_register(enum ump_external_memory_type type, struct ump_import_handler * handler);
  80. /**
  81. * Import module deregistration.
  82. * Uninstalls the handler for the given memory type.
  83. * @param type Type of the memory to unregister the handler for
  84. */
  85. void ump_import_module_unregister(enum ump_external_memory_type type);
  86. #endif /* _UMP_IMPORT_H_ */