blob: 587f137c55c0e79ed3ee224133417dd6e0aa3d55 [file] [log] [blame]
James Morrisseyf2f9bb52014-02-10 16:18:59 +00001/*
2 * Copyright (c) 2014, ARM Limited and Contributors. All rights reserved.
3 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
James Morrisseyf2f9bb52014-02-10 16:18:59 +00005 */
6
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +00007#ifndef IO_DRIVER_H
8#define IO_DRIVER_H
James Morrisseyf2f9bb52014-02-10 16:18:59 +00009
Dan Handley2bd4ef22014-04-09 13:14:54 +010010#include <io_storage.h>
Dan Handley2bd4ef22014-04-09 13:14:54 +010011#include <stdint.h>
James Morrisseyf2f9bb52014-02-10 16:18:59 +000012
13
14/* Generic IO entity structure,representing an accessible IO construct on the
15 * device, such as a file */
Dan Handleye2712bc2014-04-10 15:37:22 +010016typedef struct io_entity {
Dan Handleya4cb68e2014-04-23 13:47:06 +010017 struct io_dev_info *dev_handle;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000018 uintptr_t info;
Dan Handleye2712bc2014-04-10 15:37:22 +010019} io_entity_t;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000020
21
22/* Device info structure, providing device-specific functions and a means of
23 * adding driver-specific state */
Dan Handleye2712bc2014-04-10 15:37:22 +010024typedef struct io_dev_info {
Dan Handleya4cb68e2014-04-23 13:47:06 +010025 const struct io_dev_funcs *funcs;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000026 uintptr_t info;
Dan Handleye2712bc2014-04-10 15:37:22 +010027} io_dev_info_t;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000028
29
30/* Structure used to create a connection to a type of device */
Dan Handleye2712bc2014-04-10 15:37:22 +010031typedef struct io_dev_connector {
James Morrisseyf2f9bb52014-02-10 16:18:59 +000032 /* dev_open opens a connection to a particular device driver */
Dan Handleya4cb68e2014-04-23 13:47:06 +010033 int (*dev_open)(const uintptr_t dev_spec, io_dev_info_t **dev_info);
Dan Handleye2712bc2014-04-10 15:37:22 +010034} io_dev_connector_t;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000035
36
37/* Structure to hold device driver function pointers */
Dan Handleye2712bc2014-04-10 15:37:22 +010038typedef struct io_dev_funcs {
39 io_type_t (*type)(void);
Dan Handleya4cb68e2014-04-23 13:47:06 +010040 int (*open)(io_dev_info_t *dev_info, const uintptr_t spec,
Dan Handleye2712bc2014-04-10 15:37:22 +010041 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 Handleya4cb68e2014-04-23 13:47:06 +010044 int (*read)(io_entity_t *entity, uintptr_t buffer, size_t length,
James Morrisseyf2f9bb52014-02-10 16:18:59 +000045 size_t *length_read);
Dan Handleya4cb68e2014-04-23 13:47:06 +010046 int (*write)(io_entity_t *entity, const uintptr_t buffer,
James Morrisseyf2f9bb52014-02-10 16:18:59 +000047 size_t length, size_t *length_written);
Dan Handleye2712bc2014-04-10 15:37:22 +010048 int (*close)(io_entity_t *entity);
Dan Handleya4cb68e2014-04-23 13:47:06 +010049 int (*dev_init)(io_dev_info_t *dev_info, const uintptr_t init_params);
Dan Handleye2712bc2014-04-10 15:37:22 +010050 int (*dev_close)(io_dev_info_t *dev_info);
51} io_dev_funcs_t;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000052
53
James Morrisseyf2f9bb52014-02-10 16:18:59 +000054/* Operations intended to be performed during platform initialisation */
55
Dan Handley3aa92162014-08-04 18:31:43 +010056/* Register an IO device */
Dan Handleya4cb68e2014-04-23 13:47:06 +010057int io_register_device(const io_dev_info_t *dev_info);
James Morrisseyf2f9bb52014-02-10 16:18:59 +000058
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +000059#endif /* IO_DRIVER_H */