Home | History | Annotate | Download | only in io
      1 /*
      2  * Copyright (c) 2014, 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 
     14 /* Generic IO entity structure,representing an accessible IO construct on the
     15  * device, such as a file */
     16 typedef struct io_entity {
     17 	struct io_dev_info *dev_handle;
     18 	uintptr_t info;
     19 } io_entity_t;
     20 
     21 
     22 /* Device info structure, providing device-specific functions and a means of
     23  * adding driver-specific state */
     24 typedef struct io_dev_info {
     25 	const struct io_dev_funcs *funcs;
     26 	uintptr_t info;
     27 } io_dev_info_t;
     28 
     29 
     30 /* Structure used to create a connection to a type of device */
     31 typedef struct io_dev_connector {
     32 	/* dev_open opens a connection to a particular device driver */
     33 	int (*dev_open)(const uintptr_t dev_spec, io_dev_info_t **dev_info);
     34 } io_dev_connector_t;
     35 
     36 
     37 /* Structure to hold device driver function pointers */
     38 typedef struct io_dev_funcs {
     39 	io_type_t (*type)(void);
     40 	int (*open)(io_dev_info_t *dev_info, const uintptr_t spec,
     41 			io_entity_t *entity);
     42 	int (*seek)(io_entity_t *entity, int mode, ssize_t offset);
     43 	int (*size)(io_entity_t *entity, size_t *length);
     44 	int (*read)(io_entity_t *entity, uintptr_t buffer, size_t length,
     45 			size_t *length_read);
     46 	int (*write)(io_entity_t *entity, const uintptr_t buffer,
     47 			size_t length, size_t *length_written);
     48 	int (*close)(io_entity_t *entity);
     49 	int (*dev_init)(io_dev_info_t *dev_info, const uintptr_t init_params);
     50 	int (*dev_close)(io_dev_info_t *dev_info);
     51 } io_dev_funcs_t;
     52 
     53 
     54 /* Operations intended to be performed during platform initialisation */
     55 
     56 /* Register an IO device */
     57 int io_register_device(const io_dev_info_t *dev_info);
     58 
     59 #endif  /* __IO_DRIVER_H__ */
     60