blob: 50907ff70d2a9dba2d0d72b50d86ddec6ba4ce5d [file] [log] [blame]
James Morrisseyf2f9bb52014-02-10 16:18:59 +00001/*
2 * Copyright (c) 2014, ARM Limited and Contributors. All rights reserved.
3 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
James Morrisseyf2f9bb52014-02-10 16:18:59 +00005 */
6
7#ifndef __IO_H__
8#define __IO_H__
9
Juan Castilloadd146f2015-10-01 17:55:11 +010010#include <errno.h>
Dan Handleya4cb68e2014-04-23 13:47:06 +010011#include <stdint.h>
Dan Handley2bd4ef22014-04-09 13:14:54 +010012#include <stdio.h> /* For ssize_t */
Juan Castillo3a66aca2015-04-13 17:36:19 +010013#include <uuid.h>
James Morrissey9d72b4e2014-02-10 17:04:32 +000014
James Morrisseyf2f9bb52014-02-10 16:18:59 +000015
16/* Device type which can be used to enable policy decisions about which device
17 * to access */
18typedef enum {
19 IO_TYPE_INVALID,
20 IO_TYPE_SEMIHOSTING,
Harry Liebel561cd332014-02-14 14:42:48 +000021 IO_TYPE_MEMMAP,
Gerald Lejeune339f5592015-07-21 14:15:12 +020022 IO_TYPE_DUMMY,
Harry Liebel561cd332014-02-14 14:42:48 +000023 IO_TYPE_FIRMWARE_IMAGE_PACKAGE,
Haojian Zhuang12ade162016-03-18 15:14:19 +080024 IO_TYPE_BLOCK,
James Morrisseyf2f9bb52014-02-10 16:18:59 +000025 IO_TYPE_MAX
Dan Handleye2712bc2014-04-10 15:37:22 +010026} io_type_t;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000027
28
29/* Modes used when seeking data on a supported device */
30typedef enum {
31 IO_SEEK_INVALID,
32 IO_SEEK_SET,
33 IO_SEEK_END,
34 IO_SEEK_CUR,
35 IO_SEEK_MAX
Dan Handleye2712bc2014-04-10 15:37:22 +010036} io_seek_mode_t;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000037
38
39/* Connector type, providing a means of identifying a device to open */
40struct io_dev_connector;
41
James Morrisseyf2f9bb52014-02-10 16:18:59 +000042
43/* File specification - used to refer to data on a device supporting file-like
44 * entities */
Dan Handleye2712bc2014-04-10 15:37:22 +010045typedef struct io_file_spec {
James Morrisseyf2f9bb52014-02-10 16:18:59 +000046 const char *path;
47 unsigned int mode;
Dan Handleye2712bc2014-04-10 15:37:22 +010048} io_file_spec_t;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000049
Juan Castillo3a66aca2015-04-13 17:36:19 +010050/* UUID specification - used to refer to data accessed using UUIDs (i.e. FIP
51 * images) */
52typedef struct io_uuid_spec {
53 const uuid_t uuid;
54} io_uuid_spec_t;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000055
56/* Block specification - used to refer to data on a device supporting
57 * block-like entities */
Dan Handleye2712bc2014-04-10 15:37:22 +010058typedef struct io_block_spec {
Dan Handleya4cb68e2014-04-23 13:47:06 +010059 size_t offset;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000060 size_t length;
Dan Handleye2712bc2014-04-10 15:37:22 +010061} io_block_spec_t;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000062
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
James Morrisseyf2f9bb52014-02-10 16:18:59 +000070/* Open a connection to a device */
Dan Handleya4cb68e2014-04-23 13:47:06 +010071int io_dev_open(const struct io_dev_connector *dev_con,
72 const uintptr_t dev_spec,
73 uintptr_t *dev_handle);
James Morrisseyf2f9bb52014-02-10 16:18:59 +000074
75
76/* Initialise a device explicitly - to permit lazy initialisation or
77 * re-initialisation */
Dan Handleya4cb68e2014-04-23 13:47:06 +010078int io_dev_init(uintptr_t dev_handle, const uintptr_t init_params);
James Morrisseyf2f9bb52014-02-10 16:18:59 +000079
80/* TODO: Consider whether an explicit "shutdown" API should be included */
81
82/* Close a connection to a device */
Dan Handleya4cb68e2014-04-23 13:47:06 +010083int io_dev_close(uintptr_t dev_handle);
James Morrisseyf2f9bb52014-02-10 16:18:59 +000084
85
86/* Synchronous operations */
Dan Handleya4cb68e2014-04-23 13:47:06 +010087int io_open(uintptr_t dev_handle, const uintptr_t spec, uintptr_t *handle);
James Morrisseyf2f9bb52014-02-10 16:18:59 +000088
Dan Handleya4cb68e2014-04-23 13:47:06 +010089int io_seek(uintptr_t handle, io_seek_mode_t mode, ssize_t offset);
James Morrisseyf2f9bb52014-02-10 16:18:59 +000090
Dan Handleya4cb68e2014-04-23 13:47:06 +010091int io_size(uintptr_t handle, size_t *length);
James Morrisseyf2f9bb52014-02-10 16:18:59 +000092
Dan Handleya4cb68e2014-04-23 13:47:06 +010093int io_read(uintptr_t handle, uintptr_t buffer, size_t length,
94 size_t *length_read);
James Morrisseyf2f9bb52014-02-10 16:18:59 +000095
Dan Handleya4cb68e2014-04-23 13:47:06 +010096int io_write(uintptr_t handle, const uintptr_t buffer, size_t length,
James Morrisseyf2f9bb52014-02-10 16:18:59 +000097 size_t *length_written);
98
Dan Handleya4cb68e2014-04-23 13:47:06 +010099int io_close(uintptr_t handle);
James Morrisseyf2f9bb52014-02-10 16:18:59 +0000100
101
James Morrisseyf2f9bb52014-02-10 16:18:59 +0000102#endif /* __IO_H__ */