io_storage.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright (c) 2014, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * Redistributions of source code must retain the above copyright notice, this
  8. * list of conditions and the following disclaimer.
  9. *
  10. * Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. *
  14. * Neither the name of ARM nor the names of its contributors may be used
  15. * to endorse or promote products derived from this software without specific
  16. * prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  22. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  23. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  24. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  25. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  26. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. * POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef __IO_H__
  31. #define __IO_H__
  32. #ifndef __ASSEMBLY__
  33. #include <stdint.h>
  34. #include <stdio.h> /* For ssize_t */
  35. /* Device type which can be used to enable policy decisions about which device
  36. * to access */
  37. typedef enum {
  38. IO_TYPE_INVALID,
  39. IO_TYPE_SEMIHOSTING,
  40. IO_TYPE_MEMMAP,
  41. IO_TYPE_FIRMWARE_IMAGE_PACKAGE,
  42. IO_TYPE_MAX
  43. } io_type;
  44. /* Modes used when seeking data on a supported device */
  45. typedef enum {
  46. IO_SEEK_INVALID,
  47. IO_SEEK_SET,
  48. IO_SEEK_END,
  49. IO_SEEK_CUR,
  50. IO_SEEK_MAX
  51. } io_seek_mode;
  52. /* Connector type, providing a means of identifying a device to open */
  53. struct io_dev_connector;
  54. /* Device handle, providing a client with access to a specific device */
  55. typedef struct io_dev_info *io_dev_handle;
  56. /* IO handle, providing a client with access to a specific source of data from
  57. * a device */
  58. typedef struct io_entity *io_handle;
  59. /* File specification - used to refer to data on a device supporting file-like
  60. * entities */
  61. typedef struct {
  62. const char *path;
  63. unsigned int mode;
  64. } io_file_spec;
  65. /* Block specification - used to refer to data on a device supporting
  66. * block-like entities */
  67. typedef struct {
  68. unsigned long offset;
  69. size_t length;
  70. } io_block_spec;
  71. /* Access modes used when accessing data on a device */
  72. #define IO_MODE_INVALID (0)
  73. #define IO_MODE_RO (1 << 0)
  74. #define IO_MODE_RW (1 << 1)
  75. /* Return codes reported by 'io_*' APIs */
  76. #define IO_SUCCESS (0)
  77. #define IO_FAIL (-1)
  78. #define IO_NOT_SUPPORTED (-2)
  79. #define IO_RESOURCES_EXHAUSTED (-3)
  80. /* Open a connection to a device */
  81. int io_dev_open(struct io_dev_connector *dev_con, void *dev_spec,
  82. io_dev_handle *dev_handle);
  83. /* Initialise a device explicitly - to permit lazy initialisation or
  84. * re-initialisation */
  85. int io_dev_init(io_dev_handle dev_handle, const void *init_params);
  86. /* TODO: Consider whether an explicit "shutdown" API should be included */
  87. /* Close a connection to a device */
  88. int io_dev_close(io_dev_handle dev_handle);
  89. /* Synchronous operations */
  90. int io_open(io_dev_handle dev_handle, const void *spec, io_handle *handle);
  91. int io_seek(io_handle handle, io_seek_mode mode, ssize_t offset);
  92. int io_size(io_handle handle, size_t *length);
  93. int io_read(io_handle handle, void *buffer, size_t length, size_t *length_read);
  94. int io_write(io_handle handle, const void *buffer, size_t length,
  95. size_t *length_written);
  96. int io_close(io_handle handle);
  97. #endif /* __ASSEMBLY__ */
  98. #endif /* __IO_H__ */