blob: b6c5f9f5894d4becfe52f142339b447b09e45cdb [file] [log] [blame]
James Morrisseyf2f9bb52014-02-10 16:18:59 +00001/*
2 * Copyright (c) 2014, ARM Limited and Contributors. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#ifndef __IO_H__
32#define __IO_H__
33
Dan Handley2bd4ef22014-04-09 13:14:54 +010034#include <stdio.h> /* For ssize_t */
James Morrissey9d72b4e2014-02-10 17:04:32 +000035
James Morrisseyf2f9bb52014-02-10 16:18:59 +000036
37/* Device type which can be used to enable policy decisions about which device
38 * to access */
39typedef enum {
40 IO_TYPE_INVALID,
41 IO_TYPE_SEMIHOSTING,
Harry Liebel561cd332014-02-14 14:42:48 +000042 IO_TYPE_MEMMAP,
43 IO_TYPE_FIRMWARE_IMAGE_PACKAGE,
James Morrisseyf2f9bb52014-02-10 16:18:59 +000044 IO_TYPE_MAX
Dan Handleye2712bc2014-04-10 15:37:22 +010045} io_type_t;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000046
47
48/* Modes used when seeking data on a supported device */
49typedef enum {
50 IO_SEEK_INVALID,
51 IO_SEEK_SET,
52 IO_SEEK_END,
53 IO_SEEK_CUR,
54 IO_SEEK_MAX
Dan Handleye2712bc2014-04-10 15:37:22 +010055} io_seek_mode_t;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000056
57
58/* Connector type, providing a means of identifying a device to open */
59struct io_dev_connector;
60
61/* Device handle, providing a client with access to a specific device */
62typedef struct io_dev_info *io_dev_handle;
63
64/* IO handle, providing a client with access to a specific source of data from
65 * a device */
66typedef struct io_entity *io_handle;
67
68
69/* File specification - used to refer to data on a device supporting file-like
70 * entities */
Dan Handleye2712bc2014-04-10 15:37:22 +010071typedef struct io_file_spec {
James Morrisseyf2f9bb52014-02-10 16:18:59 +000072 const char *path;
73 unsigned int mode;
Dan Handleye2712bc2014-04-10 15:37:22 +010074} io_file_spec_t;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000075
76
77/* Block specification - used to refer to data on a device supporting
78 * block-like entities */
Dan Handleye2712bc2014-04-10 15:37:22 +010079typedef struct io_block_spec {
James Morrisseyf2f9bb52014-02-10 16:18:59 +000080 unsigned long offset;
81 size_t length;
Dan Handleye2712bc2014-04-10 15:37:22 +010082} io_block_spec_t;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000083
84
85/* Access modes used when accessing data on a device */
86#define IO_MODE_INVALID (0)
87#define IO_MODE_RO (1 << 0)
88#define IO_MODE_RW (1 << 1)
89
90
91/* Return codes reported by 'io_*' APIs */
92#define IO_SUCCESS (0)
93#define IO_FAIL (-1)
94#define IO_NOT_SUPPORTED (-2)
95#define IO_RESOURCES_EXHAUSTED (-3)
96
97
98/* Open a connection to a device */
99int io_dev_open(struct io_dev_connector *dev_con, void *dev_spec,
100 io_dev_handle *dev_handle);
101
102
103/* Initialise a device explicitly - to permit lazy initialisation or
104 * re-initialisation */
105int io_dev_init(io_dev_handle dev_handle, const void *init_params);
106
107/* TODO: Consider whether an explicit "shutdown" API should be included */
108
109/* Close a connection to a device */
110int io_dev_close(io_dev_handle dev_handle);
111
112
113/* Synchronous operations */
114int io_open(io_dev_handle dev_handle, const void *spec, io_handle *handle);
115
Dan Handleye2712bc2014-04-10 15:37:22 +0100116int io_seek(io_handle handle, io_seek_mode_t mode, ssize_t offset);
James Morrisseyf2f9bb52014-02-10 16:18:59 +0000117
118int io_size(io_handle handle, size_t *length);
119
120int io_read(io_handle handle, void *buffer, size_t length, size_t *length_read);
121
122int io_write(io_handle handle, const void *buffer, size_t length,
123 size_t *length_written);
124
125int io_close(io_handle handle);
126
127
James Morrisseyf2f9bb52014-02-10 16:18:59 +0000128#endif /* __IO_H__ */