blob: 4c3526ef10b2d7f4d3ece2caee75409cd3b2b532 [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
Juan Castillo7e26fe12015-10-01 17:55:11 +010034#include <errno.h>
Dan Handley625de1d2014-04-23 13:47:06 +010035#include <stdint.h>
Dan Handley97043ac2014-04-09 13:14:54 +010036#include <stdio.h> /* For ssize_t */
Juan Castillo16948ae2015-04-13 17:36:19 +010037#include <uuid.h>
James Morrisseyf2f9bb52014-02-10 16:18:59 +000038
39
40/* Device type which can be used to enable policy decisions about which device
41 * to access */
42typedef enum {
43 IO_TYPE_INVALID,
44 IO_TYPE_SEMIHOSTING,
Harry Liebel561cd332014-02-14 14:42:48 +000045 IO_TYPE_MEMMAP,
46 IO_TYPE_FIRMWARE_IMAGE_PACKAGE,
James Morrisseyf2f9bb52014-02-10 16:18:59 +000047 IO_TYPE_MAX
Dan Handleyfb037bf2014-04-10 15:37:22 +010048} io_type_t;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000049
50
51/* Modes used when seeking data on a supported device */
52typedef enum {
53 IO_SEEK_INVALID,
54 IO_SEEK_SET,
55 IO_SEEK_END,
56 IO_SEEK_CUR,
57 IO_SEEK_MAX
Dan Handleyfb037bf2014-04-10 15:37:22 +010058} io_seek_mode_t;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000059
60
61/* Connector type, providing a means of identifying a device to open */
62struct io_dev_connector;
63
James Morrisseyf2f9bb52014-02-10 16:18:59 +000064
65/* File specification - used to refer to data on a device supporting file-like
66 * entities */
Dan Handleyfb037bf2014-04-10 15:37:22 +010067typedef struct io_file_spec {
James Morrisseyf2f9bb52014-02-10 16:18:59 +000068 const char *path;
69 unsigned int mode;
Dan Handleyfb037bf2014-04-10 15:37:22 +010070} io_file_spec_t;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000071
Juan Castillo16948ae2015-04-13 17:36:19 +010072/* UUID specification - used to refer to data accessed using UUIDs (i.e. FIP
73 * images) */
74typedef struct io_uuid_spec {
75 const uuid_t uuid;
76} io_uuid_spec_t;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000077
78/* Block specification - used to refer to data on a device supporting
79 * block-like entities */
Dan Handleyfb037bf2014-04-10 15:37:22 +010080typedef struct io_block_spec {
Dan Handley625de1d2014-04-23 13:47:06 +010081 size_t offset;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000082 size_t length;
Dan Handleyfb037bf2014-04-10 15:37:22 +010083} io_block_spec_t;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000084
85
86/* Access modes used when accessing data on a device */
87#define IO_MODE_INVALID (0)
88#define IO_MODE_RO (1 << 0)
89#define IO_MODE_RW (1 << 1)
90
91
Juan Castillo7e26fe12015-10-01 17:55:11 +010092/* Return codes reported by 'io_*' APIs.
93 * IMPORTANT: these definitions are deprecated. Callers should use standard
94 * errno definitions when checking the return value of io_* APIs. */
James Morrisseyf2f9bb52014-02-10 16:18:59 +000095#define IO_SUCCESS (0)
Juan Castillo7e26fe12015-10-01 17:55:11 +010096#define IO_FAIL (-ENOENT)
97#define IO_NOT_SUPPORTED (-ENODEV)
98#define IO_RESOURCES_EXHAUSTED (-ENOMEM)
James Morrisseyf2f9bb52014-02-10 16:18:59 +000099
100
101/* Open a connection to a device */
Dan Handley625de1d2014-04-23 13:47:06 +0100102int io_dev_open(const struct io_dev_connector *dev_con,
103 const uintptr_t dev_spec,
104 uintptr_t *dev_handle);
James Morrisseyf2f9bb52014-02-10 16:18:59 +0000105
106
107/* Initialise a device explicitly - to permit lazy initialisation or
108 * re-initialisation */
Dan Handley625de1d2014-04-23 13:47:06 +0100109int io_dev_init(uintptr_t dev_handle, const uintptr_t init_params);
James Morrisseyf2f9bb52014-02-10 16:18:59 +0000110
111/* TODO: Consider whether an explicit "shutdown" API should be included */
112
113/* Close a connection to a device */
Dan Handley625de1d2014-04-23 13:47:06 +0100114int io_dev_close(uintptr_t dev_handle);
James Morrisseyf2f9bb52014-02-10 16:18:59 +0000115
116
117/* Synchronous operations */
Dan Handley625de1d2014-04-23 13:47:06 +0100118int io_open(uintptr_t dev_handle, const uintptr_t spec, uintptr_t *handle);
James Morrisseyf2f9bb52014-02-10 16:18:59 +0000119
Dan Handley625de1d2014-04-23 13:47:06 +0100120int io_seek(uintptr_t handle, io_seek_mode_t mode, ssize_t offset);
James Morrisseyf2f9bb52014-02-10 16:18:59 +0000121
Dan Handley625de1d2014-04-23 13:47:06 +0100122int io_size(uintptr_t handle, size_t *length);
James Morrisseyf2f9bb52014-02-10 16:18:59 +0000123
Dan Handley625de1d2014-04-23 13:47:06 +0100124int io_read(uintptr_t handle, uintptr_t buffer, size_t length,
125 size_t *length_read);
James Morrisseyf2f9bb52014-02-10 16:18:59 +0000126
Dan Handley625de1d2014-04-23 13:47:06 +0100127int io_write(uintptr_t handle, const uintptr_t buffer, size_t length,
James Morrisseyf2f9bb52014-02-10 16:18:59 +0000128 size_t *length_written);
129
Dan Handley625de1d2014-04-23 13:47:06 +0100130int io_close(uintptr_t handle);
James Morrisseyf2f9bb52014-02-10 16:18:59 +0000131
132
James Morrisseyf2f9bb52014-02-10 16:18:59 +0000133#endif /* __IO_H__ */