io_storage.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (c) 2014-2020, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef IO_STORAGE_H
  7. #define IO_STORAGE_H
  8. #include <errno.h>
  9. #include <stdint.h>
  10. #include <stdio.h> /* For ssize_t */
  11. #include <tools_share/uuid.h>
  12. /* Device type which can be used to enable policy decisions about which device
  13. * to access */
  14. typedef enum {
  15. IO_TYPE_INVALID,
  16. IO_TYPE_SEMIHOSTING,
  17. IO_TYPE_MEMMAP,
  18. IO_TYPE_DUMMY,
  19. IO_TYPE_FIRMWARE_IMAGE_PACKAGE,
  20. IO_TYPE_BLOCK,
  21. IO_TYPE_MTD,
  22. IO_TYPE_MMC,
  23. IO_TYPE_STM32IMAGE,
  24. IO_TYPE_ENCRYPTED,
  25. IO_TYPE_MAX
  26. } io_type_t;
  27. /* Modes used when seeking data on a supported device */
  28. typedef enum {
  29. IO_SEEK_INVALID,
  30. IO_SEEK_SET,
  31. IO_SEEK_END,
  32. IO_SEEK_CUR,
  33. IO_SEEK_MAX
  34. } io_seek_mode_t;
  35. /* Connector type, providing a means of identifying a device to open */
  36. struct io_dev_connector;
  37. /* File specification - used to refer to data on a device supporting file-like
  38. * entities */
  39. typedef struct io_file_spec {
  40. const char *path;
  41. unsigned int mode;
  42. } io_file_spec_t;
  43. /* UUID specification - used to refer to data accessed using UUIDs (i.e. FIP
  44. * images) */
  45. typedef struct io_uuid_spec {
  46. uuid_t uuid;
  47. } io_uuid_spec_t;
  48. /* Block specification - used to refer to data on a device supporting
  49. * block-like entities */
  50. typedef struct io_block_spec {
  51. size_t offset;
  52. size_t length;
  53. } io_block_spec_t;
  54. /* Access modes used when accessing data on a device */
  55. #define IO_MODE_INVALID (0)
  56. #define IO_MODE_RO (1 << 0)
  57. #define IO_MODE_RW (1 << 1)
  58. /* Open a connection to a device */
  59. int io_dev_open(const struct io_dev_connector *dev_con,
  60. const uintptr_t dev_spec,
  61. uintptr_t *handle);
  62. /* Initialise a device explicitly - to permit lazy initialisation or
  63. * re-initialisation */
  64. int io_dev_init(uintptr_t dev_handle, const uintptr_t init_params);
  65. /* Close a connection to a device */
  66. int io_dev_close(uintptr_t dev_handle);
  67. /* Synchronous operations */
  68. int io_open(uintptr_t dev_handle, const uintptr_t spec, uintptr_t *handle);
  69. int io_seek(uintptr_t handle, io_seek_mode_t mode, signed long long offset);
  70. int io_size(uintptr_t handle, size_t *length);
  71. int io_read(uintptr_t handle, uintptr_t buffer, size_t length,
  72. size_t *length_read);
  73. int io_write(uintptr_t handle, const uintptr_t buffer, size_t length,
  74. size_t *length_written);
  75. int io_close(uintptr_t handle);
  76. #endif /* IO_STORAGE_H */