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