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 | * |
| 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 | |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 34 | #ifndef __ASSEMBLY__ |
| 35 | |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 36 | #include <stdint.h> |
| 37 | #include <stdio.h> /* For ssize_t */ |
| 38 | |
| 39 | |
| 40 | /* Device type which can be used to enable policy decisions about which device |
| 41 | * to access */ |
| 42 | typedef enum { |
| 43 | IO_TYPE_INVALID, |
| 44 | IO_TYPE_SEMIHOSTING, |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 45 | IO_TYPE_MEMMAP, |
| 46 | IO_TYPE_FIRMWARE_IMAGE_PACKAGE, |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 47 | IO_TYPE_MAX |
| 48 | } io_type; |
| 49 | |
| 50 | |
| 51 | /* Modes used when seeking data on a supported device */ |
| 52 | typedef enum { |
| 53 | IO_SEEK_INVALID, |
| 54 | IO_SEEK_SET, |
| 55 | IO_SEEK_END, |
| 56 | IO_SEEK_CUR, |
| 57 | IO_SEEK_MAX |
| 58 | } io_seek_mode; |
| 59 | |
| 60 | |
| 61 | /* Connector type, providing a means of identifying a device to open */ |
| 62 | struct io_dev_connector; |
| 63 | |
| 64 | /* Device handle, providing a client with access to a specific device */ |
| 65 | typedef struct io_dev_info *io_dev_handle; |
| 66 | |
| 67 | /* IO handle, providing a client with access to a specific source of data from |
| 68 | * a device */ |
| 69 | typedef struct io_entity *io_handle; |
| 70 | |
| 71 | |
| 72 | /* File specification - used to refer to data on a device supporting file-like |
| 73 | * entities */ |
| 74 | typedef struct { |
| 75 | const char *path; |
| 76 | unsigned int mode; |
| 77 | } io_file_spec; |
| 78 | |
| 79 | |
| 80 | /* Block specification - used to refer to data on a device supporting |
| 81 | * block-like entities */ |
| 82 | typedef struct { |
| 83 | unsigned long offset; |
| 84 | size_t length; |
| 85 | } io_block_spec; |
| 86 | |
| 87 | |
| 88 | /* Access modes used when accessing data on a device */ |
| 89 | #define IO_MODE_INVALID (0) |
| 90 | #define IO_MODE_RO (1 << 0) |
| 91 | #define IO_MODE_RW (1 << 1) |
| 92 | |
| 93 | |
| 94 | /* Return codes reported by 'io_*' APIs */ |
| 95 | #define IO_SUCCESS (0) |
| 96 | #define IO_FAIL (-1) |
| 97 | #define IO_NOT_SUPPORTED (-2) |
| 98 | #define IO_RESOURCES_EXHAUSTED (-3) |
| 99 | |
| 100 | |
| 101 | /* Open a connection to a device */ |
| 102 | int io_dev_open(struct io_dev_connector *dev_con, void *dev_spec, |
| 103 | io_dev_handle *dev_handle); |
| 104 | |
| 105 | |
| 106 | /* Initialise a device explicitly - to permit lazy initialisation or |
| 107 | * re-initialisation */ |
| 108 | int io_dev_init(io_dev_handle dev_handle, const void *init_params); |
| 109 | |
| 110 | /* TODO: Consider whether an explicit "shutdown" API should be included */ |
| 111 | |
| 112 | /* Close a connection to a device */ |
| 113 | int io_dev_close(io_dev_handle dev_handle); |
| 114 | |
| 115 | |
| 116 | /* Synchronous operations */ |
| 117 | int io_open(io_dev_handle dev_handle, const void *spec, io_handle *handle); |
| 118 | |
| 119 | int io_seek(io_handle handle, io_seek_mode mode, ssize_t offset); |
| 120 | |
| 121 | int io_size(io_handle handle, size_t *length); |
| 122 | |
| 123 | int io_read(io_handle handle, void *buffer, size_t length, size_t *length_read); |
| 124 | |
| 125 | int io_write(io_handle handle, const void *buffer, size_t length, |
| 126 | size_t *length_written); |
| 127 | |
| 128 | int io_close(io_handle handle); |
| 129 | |
| 130 | |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 131 | #endif /* __ASSEMBLY__ */ |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 132 | #endif /* __IO_H__ */ |