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