2014-02-10 16:18:59 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014, ARM Limited and Contributors. All rights reserved.
|
|
|
|
*
|
2017-05-03 09:38:09 +01:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2014-02-10 16:18:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __IO_DRIVER_H__
|
|
|
|
#define __IO_DRIVER_H__
|
|
|
|
|
2014-04-09 13:14:54 +01:00
|
|
|
#include <io_storage.h>
|
|
|
|
#include <stdint.h>
|
2014-02-10 16:18:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Generic IO entity structure,representing an accessible IO construct on the
|
|
|
|
* device, such as a file */
|
2014-04-10 15:37:22 +01:00
|
|
|
typedef struct io_entity {
|
2014-04-23 13:47:06 +01:00
|
|
|
struct io_dev_info *dev_handle;
|
2014-02-10 16:18:59 +00:00
|
|
|
uintptr_t info;
|
2014-04-10 15:37:22 +01:00
|
|
|
} io_entity_t;
|
2014-02-10 16:18:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Device info structure, providing device-specific functions and a means of
|
|
|
|
* adding driver-specific state */
|
2014-04-10 15:37:22 +01:00
|
|
|
typedef struct io_dev_info {
|
2014-04-23 13:47:06 +01:00
|
|
|
const struct io_dev_funcs *funcs;
|
2014-02-10 16:18:59 +00:00
|
|
|
uintptr_t info;
|
2014-04-10 15:37:22 +01:00
|
|
|
} io_dev_info_t;
|
2014-02-10 16:18:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Structure used to create a connection to a type of device */
|
2014-04-10 15:37:22 +01:00
|
|
|
typedef struct io_dev_connector {
|
2014-02-10 16:18:59 +00:00
|
|
|
/* dev_open opens a connection to a particular device driver */
|
2014-04-23 13:47:06 +01:00
|
|
|
int (*dev_open)(const uintptr_t dev_spec, io_dev_info_t **dev_info);
|
2014-04-10 15:37:22 +01:00
|
|
|
} io_dev_connector_t;
|
2014-02-10 16:18:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Structure to hold device driver function pointers */
|
2014-04-10 15:37:22 +01:00
|
|
|
typedef struct io_dev_funcs {
|
|
|
|
io_type_t (*type)(void);
|
2014-04-23 13:47:06 +01:00
|
|
|
int (*open)(io_dev_info_t *dev_info, const uintptr_t spec,
|
2014-04-10 15:37:22 +01:00
|
|
|
io_entity_t *entity);
|
|
|
|
int (*seek)(io_entity_t *entity, int mode, ssize_t offset);
|
|
|
|
int (*size)(io_entity_t *entity, size_t *length);
|
2014-04-23 13:47:06 +01:00
|
|
|
int (*read)(io_entity_t *entity, uintptr_t buffer, size_t length,
|
2014-02-10 16:18:59 +00:00
|
|
|
size_t *length_read);
|
2014-04-23 13:47:06 +01:00
|
|
|
int (*write)(io_entity_t *entity, const uintptr_t buffer,
|
2014-02-10 16:18:59 +00:00
|
|
|
size_t length, size_t *length_written);
|
2014-04-10 15:37:22 +01:00
|
|
|
int (*close)(io_entity_t *entity);
|
2014-04-23 13:47:06 +01:00
|
|
|
int (*dev_init)(io_dev_info_t *dev_info, const uintptr_t init_params);
|
2014-04-10 15:37:22 +01:00
|
|
|
int (*dev_close)(io_dev_info_t *dev_info);
|
|
|
|
} io_dev_funcs_t;
|
2014-02-10 16:18:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Operations intended to be performed during platform initialisation */
|
|
|
|
|
2014-08-04 18:31:43 +01:00
|
|
|
/* Register an IO device */
|
2014-04-23 13:47:06 +01:00
|
|
|
int io_register_device(const io_dev_info_t *dev_info);
|
2014-02-10 16:18:59 +00:00
|
|
|
|
|
|
|
#endif /* __IO_DRIVER_H__ */
|