io_storage.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (c) 2014-2022, 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_ENCRYPTED,
  24. IO_TYPE_MAX
  25. } io_type_t;
  26. /* Modes used when seeking data on a supported device */
  27. typedef enum {
  28. IO_SEEK_INVALID,
  29. IO_SEEK_SET,
  30. IO_SEEK_END,
  31. IO_SEEK_CUR,
  32. IO_SEEK_MAX
  33. } io_seek_mode_t;
  34. /* Connector type, providing a means of identifying a device to open */
  35. struct io_dev_connector;
  36. /* File specification - used to refer to data on a device supporting file-like
  37. * entities */
  38. typedef struct io_file_spec {
  39. const char *path;
  40. unsigned int mode;
  41. } io_file_spec_t;
  42. /* UUID specification - used to refer to data accessed using UUIDs (i.e. FIP
  43. * images) */
  44. typedef struct io_uuid_spec {
  45. uuid_t uuid;
  46. } io_uuid_spec_t;
  47. /* Block specification - used to refer to data on a device supporting
  48. * block-like entities */
  49. typedef struct io_block_spec {
  50. size_t offset;
  51. size_t length;
  52. } io_block_spec_t;
  53. /* Access modes used when accessing data on a device */
  54. #define IO_MODE_INVALID (0)
  55. #define IO_MODE_RO (1 << 0)
  56. #define IO_MODE_RW (1 << 1)
  57. /* Open a connection to a device */
  58. int io_dev_open(const struct io_dev_connector *dev_con,
  59. const uintptr_t dev_spec,
  60. uintptr_t *handle);
  61. /* Initialise a device explicitly - to permit lazy initialisation or
  62. * re-initialisation */
  63. int io_dev_init(uintptr_t dev_handle, const uintptr_t init_params);
  64. /* Close a connection to a device */
  65. int io_dev_close(uintptr_t dev_handle);
  66. /* Synchronous operations */
  67. int io_open(uintptr_t dev_handle, const uintptr_t spec, uintptr_t *handle);
  68. int io_seek(uintptr_t handle, io_seek_mode_t mode, signed long long offset);
  69. int io_size(uintptr_t handle, size_t *length);
  70. int io_read(uintptr_t handle, uintptr_t buffer, size_t length,
  71. size_t *length_read);
  72. int io_write(uintptr_t handle, const uintptr_t buffer, size_t length,
  73. size_t *length_written);
  74. int io_close(uintptr_t handle);
  75. #endif /* IO_STORAGE_H */