James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 7 | #ifndef IO_DRIVER_H |
| 8 | #define IO_DRIVER_H |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 9 | |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 10 | #include <io_storage.h> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 11 | #include <stdint.h> |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 12 | |
| 13 | |
| 14 | /* Generic IO entity structure,representing an accessible IO construct on the |
| 15 | * device, such as a file */ |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 16 | typedef struct io_entity { |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 17 | struct io_dev_info *dev_handle; |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 18 | uintptr_t info; |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 19 | } io_entity_t; |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 20 | |
| 21 | |
| 22 | /* Device info structure, providing device-specific functions and a means of |
| 23 | * adding driver-specific state */ |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 24 | typedef struct io_dev_info { |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 25 | const struct io_dev_funcs *funcs; |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 26 | uintptr_t info; |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 27 | } io_dev_info_t; |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 28 | |
| 29 | |
| 30 | /* Structure used to create a connection to a type of device */ |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 31 | typedef struct io_dev_connector { |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 32 | /* dev_open opens a connection to a particular device driver */ |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 33 | int (*dev_open)(const uintptr_t dev_spec, io_dev_info_t **dev_info); |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 34 | } io_dev_connector_t; |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 35 | |
| 36 | |
| 37 | /* Structure to hold device driver function pointers */ |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 38 | typedef struct io_dev_funcs { |
| 39 | io_type_t (*type)(void); |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 40 | int (*open)(io_dev_info_t *dev_info, const uintptr_t spec, |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 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); |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 44 | int (*read)(io_entity_t *entity, uintptr_t buffer, size_t length, |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 45 | size_t *length_read); |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 46 | int (*write)(io_entity_t *entity, const uintptr_t buffer, |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 47 | size_t length, size_t *length_written); |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 48 | int (*close)(io_entity_t *entity); |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 49 | int (*dev_init)(io_dev_info_t *dev_info, const uintptr_t init_params); |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 50 | int (*dev_close)(io_dev_info_t *dev_info); |
| 51 | } io_dev_funcs_t; |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 52 | |
| 53 | |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 54 | /* Operations intended to be performed during platform initialisation */ |
| 55 | |
Dan Handley | 3aa9216 | 2014-08-04 18:31:43 +0100 | [diff] [blame] | 56 | /* Register an IO device */ |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 57 | int io_register_device(const io_dev_info_t *dev_info); |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 58 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 59 | #endif /* IO_DRIVER_H */ |