io_driver.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (c) 2014, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef IO_DRIVER_H
  7. #define IO_DRIVER_H
  8. #include <stdint.h>
  9. #include <drivers/io/io_storage.h>
  10. /* Generic IO entity structure,representing an accessible IO construct on the
  11. * device, such as a file */
  12. typedef struct io_entity {
  13. struct io_dev_info *dev_handle;
  14. uintptr_t info;
  15. } io_entity_t;
  16. /* Device info structure, providing device-specific functions and a means of
  17. * adding driver-specific state */
  18. typedef struct io_dev_info {
  19. const struct io_dev_funcs *funcs;
  20. uintptr_t info;
  21. } io_dev_info_t;
  22. /* Structure used to create a connection to a type of device */
  23. typedef struct io_dev_connector {
  24. /* dev_open opens a connection to a particular device driver */
  25. int (*dev_open)(const uintptr_t dev_spec, io_dev_info_t **dev_info);
  26. } io_dev_connector_t;
  27. /* Structure to hold device driver function pointers */
  28. typedef struct io_dev_funcs {
  29. io_type_t (*type)(void);
  30. int (*open)(io_dev_info_t *dev_info, const uintptr_t spec,
  31. io_entity_t *entity);
  32. int (*seek)(io_entity_t *entity, int mode, signed long long offset);
  33. int (*size)(io_entity_t *entity, size_t *length);
  34. int (*read)(io_entity_t *entity, uintptr_t buffer, size_t length,
  35. size_t *length_read);
  36. int (*write)(io_entity_t *entity, const uintptr_t buffer,
  37. size_t length, size_t *length_written);
  38. int (*close)(io_entity_t *entity);
  39. int (*dev_init)(io_dev_info_t *dev_info, const uintptr_t init_params);
  40. int (*dev_close)(io_dev_info_t *dev_info);
  41. } io_dev_funcs_t;
  42. /* Operations intended to be performed during platform initialisation */
  43. /* Register an IO device */
  44. int io_register_device(const io_dev_info_t *dev_info);
  45. #endif /* IO_DRIVER_H */