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_H__
8 #define __IO_H__
9 
10 #include <errno.h>
11 #include <stdint.h>
12 #include <stdio.h> /* For ssize_t */
13 #include <uuid.h>
14 
15 
16 /* Device type which can be used to enable policy decisions about which device
17  * to access */
18 typedef enum {
19 	IO_TYPE_INVALID,
20 	IO_TYPE_SEMIHOSTING,
21 	IO_TYPE_MEMMAP,
22 	IO_TYPE_DUMMY,
23 	IO_TYPE_FIRMWARE_IMAGE_PACKAGE,
24 	IO_TYPE_BLOCK,
25 	IO_TYPE_MAX
26 } io_type_t;
27 
28 
29 /* Modes used when seeking data on a supported device */
30 typedef enum {
31 	IO_SEEK_INVALID,
32 	IO_SEEK_SET,
33 	IO_SEEK_END,
34 	IO_SEEK_CUR,
35 	IO_SEEK_MAX
36 } io_seek_mode_t;
37 
38 
39 /* Connector type, providing a means of identifying a device to open */
40 struct io_dev_connector;
41 
42 
43 /* File specification - used to refer to data on a device supporting file-like
44  * entities */
45 typedef struct io_file_spec {
46 	const char *path;
47 	unsigned int mode;
48 } io_file_spec_t;
49 
50 /* UUID specification - used to refer to data accessed using UUIDs (i.e. FIP
51  * images) */
52 typedef struct io_uuid_spec {
53 	const uuid_t uuid;
54 } io_uuid_spec_t;
55 
56 /* Block specification - used to refer to data on a device supporting
57  * block-like entities */
58 typedef struct io_block_spec {
59 	size_t offset;
60 	size_t length;
61 } io_block_spec_t;
62 
63 
64 /* Access modes used when accessing data on a device */
65 #define IO_MODE_INVALID (0)
66 #define IO_MODE_RO	(1 << 0)
67 #define IO_MODE_RW	(1 << 1)
68 
69 
70 /* Open a connection to a device */
71 int io_dev_open(const struct io_dev_connector *dev_con,
72 		const uintptr_t dev_spec,
73 		uintptr_t *dev_handle);
74 
75 
76 /* Initialise a device explicitly - to permit lazy initialisation or
77  * re-initialisation */
78 int io_dev_init(uintptr_t dev_handle, const uintptr_t init_params);
79 
80 /* TODO: Consider whether an explicit "shutdown" API should be included */
81 
82 /* Close a connection to a device */
83 int io_dev_close(uintptr_t dev_handle);
84 
85 
86 /* Synchronous operations */
87 int io_open(uintptr_t dev_handle, const uintptr_t spec, uintptr_t *handle);
88 
89 int io_seek(uintptr_t handle, io_seek_mode_t mode, ssize_t offset);
90 
91 int io_size(uintptr_t handle, size_t *length);
92 
93 int io_read(uintptr_t handle, uintptr_t buffer, size_t length,
94 		size_t *length_read);
95 
96 int io_write(uintptr_t handle, const uintptr_t buffer, size_t length,
97 		size_t *length_written);
98 
99 int io_close(uintptr_t handle);
100 
101 
102 #endif /* __IO_H__ */
103