io_mtd.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) 2019-2021, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef IO_MTD_H
  7. #define IO_MTD_H
  8. #include <stdint.h>
  9. #include <stdio.h>
  10. #include <drivers/io/io_storage.h>
  11. /* MTD devices ops */
  12. typedef struct io_mtd_ops {
  13. /*
  14. * Initialize MTD framework and retrieve device information.
  15. *
  16. * @size: [out] MTD device size in bytes.
  17. * @erase_size: [out] MTD erase size in bytes.
  18. * Return 0 on success, a negative error code otherwise.
  19. */
  20. int (*init)(unsigned long long *size, unsigned int *erase_size);
  21. /*
  22. * Execute a read memory operation.
  23. *
  24. * @offset: Offset in bytes to start read operation.
  25. * @buffer: [out] Buffer to store read data.
  26. * @length: Required length to be read in bytes.
  27. * @out_length: [out] Length read in bytes.
  28. * Return 0 on success, a negative error code otherwise.
  29. */
  30. int (*read)(unsigned int offset, uintptr_t buffer, size_t length,
  31. size_t *out_length);
  32. /*
  33. * Execute a write memory operation.
  34. *
  35. * @offset: Offset in bytes to start write operation.
  36. * @buffer: Buffer to be written in device.
  37. * @length: Required length to be written in bytes.
  38. * Return 0 on success, a negative error code otherwise.
  39. */
  40. int (*write)(unsigned int offset, uintptr_t buffer, size_t length);
  41. /*
  42. * Look for an offset to be added to the given offset.
  43. *
  44. * @base: Base address of the area.
  45. * @offset: Offset in bytes to start read operation.
  46. * @extra_offset: [out] Offset to be added to the previous offset.
  47. * Return 0 on success, a negative error code otherwise.
  48. */
  49. int (*seek)(uintptr_t base, unsigned int offset, size_t *extra_offset);
  50. } io_mtd_ops_t;
  51. typedef struct io_mtd_dev_spec {
  52. unsigned long long device_size;
  53. unsigned int erase_size;
  54. size_t offset;
  55. io_mtd_ops_t ops;
  56. } io_mtd_dev_spec_t;
  57. struct io_dev_connector;
  58. int register_io_dev_mtd(const struct io_dev_connector **dev_con);
  59. #endif /* IO_MTD_H */