io_driver.h 1.72 KB
Newer Older
James Morrissey's avatar
James Morrissey committed
1
2
3
/*
 * Copyright (c) 2014, ARM Limited and Contributors. All rights reserved.
 *
dp-arm's avatar
dp-arm committed
4
 * SPDX-License-Identifier: BSD-3-Clause
James Morrissey's avatar
James Morrissey committed
5
6
 */

7
8
#ifndef IO_DRIVER_H
#define IO_DRIVER_H
James Morrissey's avatar
James Morrissey committed
9

10
#include <stdint.h>
James Morrissey's avatar
James Morrissey committed
11

12
#include <drivers/io/io_storage.h>
James Morrissey's avatar
James Morrissey committed
13
14
15

/* Generic IO entity structure,representing an accessible IO construct on the
 * device, such as a file */
16
typedef struct io_entity {
17
	struct io_dev_info *dev_handle;
James Morrissey's avatar
James Morrissey committed
18
	uintptr_t info;
19
} io_entity_t;
James Morrissey's avatar
James Morrissey committed
20
21
22
23


/* Device info structure, providing device-specific functions and a means of
 * adding driver-specific state */
24
typedef struct io_dev_info {
25
	const struct io_dev_funcs *funcs;
James Morrissey's avatar
James Morrissey committed
26
	uintptr_t info;
27
} io_dev_info_t;
James Morrissey's avatar
James Morrissey committed
28
29
30


/* Structure used to create a connection to a type of device */
31
typedef struct io_dev_connector {
James Morrissey's avatar
James Morrissey committed
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;
James Morrissey's avatar
James Morrissey committed
35
36
37


/* Structure to hold device driver function pointers */
38
39
typedef struct io_dev_funcs {
	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, signed long long offset);
43
	int (*size)(io_entity_t *entity, size_t *length);
44
	int (*read)(io_entity_t *entity, uintptr_t buffer, size_t length,
James Morrissey's avatar
James Morrissey committed
45
			size_t *length_read);
46
	int (*write)(io_entity_t *entity, const uintptr_t buffer,
James Morrissey's avatar
James Morrissey committed
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
51
	int (*dev_close)(io_dev_info_t *dev_info);
} io_dev_funcs_t;
James Morrissey's avatar
James Morrissey committed
52
53
54
55


/* Operations intended to be performed during platform initialisation */

56
/* Register an IO device */
57
int io_register_device(const io_dev_info_t *dev_info);
James Morrissey's avatar
James Morrissey committed
58

59
#endif /* IO_DRIVER_H */