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 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 7 | #ifndef IO_STORAGE_H |
| 8 | #define IO_STORAGE_H |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 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 */ |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 13 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 14 | #include <tools_share/uuid.h> |
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, |
Yann Gautier | f325df5 | 2018-10-15 09:36:21 +0200 | [diff] [blame] | 25 | IO_TYPE_MMC, |
| 26 | IO_TYPE_STM32IMAGE, |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 27 | IO_TYPE_MAX |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 28 | } io_type_t; |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 29 | |
| 30 | |
| 31 | /* Modes used when seeking data on a supported device */ |
| 32 | typedef enum { |
| 33 | IO_SEEK_INVALID, |
| 34 | IO_SEEK_SET, |
| 35 | IO_SEEK_END, |
| 36 | IO_SEEK_CUR, |
| 37 | IO_SEEK_MAX |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 38 | } io_seek_mode_t; |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 39 | |
| 40 | |
| 41 | /* Connector type, providing a means of identifying a device to open */ |
| 42 | struct io_dev_connector; |
| 43 | |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 44 | |
| 45 | /* File specification - used to refer to data on a device supporting file-like |
| 46 | * entities */ |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 47 | typedef struct io_file_spec { |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 48 | const char *path; |
| 49 | unsigned int mode; |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 50 | } io_file_spec_t; |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 51 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 52 | /* UUID specification - used to refer to data accessed using UUIDs (i.e. FIP |
| 53 | * images) */ |
| 54 | typedef struct io_uuid_spec { |
| 55 | const uuid_t uuid; |
| 56 | } io_uuid_spec_t; |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 57 | |
| 58 | /* Block specification - used to refer to data on a device supporting |
| 59 | * block-like entities */ |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 60 | typedef struct io_block_spec { |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 61 | size_t offset; |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 62 | size_t length; |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 63 | } io_block_spec_t; |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 64 | |
| 65 | |
| 66 | /* Access modes used when accessing data on a device */ |
| 67 | #define IO_MODE_INVALID (0) |
| 68 | #define IO_MODE_RO (1 << 0) |
| 69 | #define IO_MODE_RW (1 << 1) |
| 70 | |
| 71 | |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 72 | /* Open a connection to a device */ |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 73 | int io_dev_open(const struct io_dev_connector *dev_con, |
| 74 | const uintptr_t dev_spec, |
Roberto Vargas | 1a6eed3 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 75 | uintptr_t *handle); |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 76 | |
| 77 | |
| 78 | /* Initialise a device explicitly - to permit lazy initialisation or |
| 79 | * re-initialisation */ |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 80 | 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] | 81 | |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 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 | |
Yann Gautier | f30cddc | 2019-04-16 11:35:19 +0200 | [diff] [blame] | 89 | int io_seek(uintptr_t handle, io_seek_mode_t mode, signed long long 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 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 102 | #endif /* IO_STORAGE_H */ |