James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef __IO_H__ |
| 8 | #define __IO_H__ |
| 9 | |
Juan Castillo | add146f | 2015-10-01 17:55:11 +0100 | [diff] [blame] | 10 | #include <errno.h> |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 11 | #include <stdint.h> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 12 | #include <stdio.h> /* For ssize_t */ |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 13 | #include <uuid.h> |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 14 | |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 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, |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 21 | IO_TYPE_MEMMAP, |
Gerald Lejeune | 339f559 | 2015-07-21 14:15:12 +0200 | [diff] [blame] | 22 | IO_TYPE_DUMMY, |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 23 | IO_TYPE_FIRMWARE_IMAGE_PACKAGE, |
Haojian Zhuang | 12ade16 | 2016-03-18 15:14:19 +0800 | [diff] [blame] | 24 | IO_TYPE_BLOCK, |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 25 | IO_TYPE_MAX |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 26 | } io_type_t; |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 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 |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 36 | } io_seek_mode_t; |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 37 | |
| 38 | |
| 39 | /* Connector type, providing a means of identifying a device to open */ |
| 40 | struct io_dev_connector; |
| 41 | |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 42 | |
| 43 | /* File specification - used to refer to data on a device supporting file-like |
| 44 | * entities */ |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 45 | typedef struct io_file_spec { |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 46 | const char *path; |
| 47 | unsigned int mode; |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 48 | } io_file_spec_t; |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 49 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 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; |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 55 | |
| 56 | /* Block specification - used to refer to data on a device supporting |
| 57 | * block-like entities */ |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 58 | typedef struct io_block_spec { |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 59 | size_t offset; |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 60 | size_t length; |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 61 | } io_block_spec_t; |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 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 | |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 70 | /* Open a connection to a device */ |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 71 | int io_dev_open(const struct io_dev_connector *dev_con, |
| 72 | const uintptr_t dev_spec, |
Roberto Vargas | 1a6eed3 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 73 | uintptr_t *handle); |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 74 | |
| 75 | |
| 76 | /* Initialise a device explicitly - to permit lazy initialisation or |
| 77 | * re-initialisation */ |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 78 | int io_dev_init(uintptr_t dev_handle, const uintptr_t init_params); |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 79 | |
| 80 | /* TODO: Consider whether an explicit "shutdown" API should be included */ |
| 81 | |
| 82 | /* Close a connection to a device */ |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 83 | int io_dev_close(uintptr_t dev_handle); |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 84 | |
| 85 | |
| 86 | /* Synchronous operations */ |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 87 | int io_open(uintptr_t dev_handle, const uintptr_t spec, uintptr_t *handle); |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 88 | |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 89 | int io_seek(uintptr_t handle, io_seek_mode_t mode, ssize_t offset); |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 90 | |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 91 | int io_size(uintptr_t handle, size_t *length); |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 92 | |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 93 | int io_read(uintptr_t handle, uintptr_t buffer, size_t length, |
| 94 | size_t *length_read); |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 95 | |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 96 | int io_write(uintptr_t handle, const uintptr_t buffer, size_t length, |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 97 | size_t *length_written); |
| 98 | |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 99 | int io_close(uintptr_t handle); |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 100 | |
| 101 | |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 102 | #endif /* __IO_H__ */ |