uintptr_t image_handle;
uintptr_t image_spec;
size_t image_size = 0;
- int io_result = IO_FAIL;
+ int io_result;
/* Obtain a reference to the image by querying the platform layer */
io_result = plat_get_image_source(image_id, &dev_handle, &image_spec);
- if (io_result != IO_SUCCESS) {
+ if (io_result != 0) {
WARN("Failed to obtain reference to image id=%u (%i)\n",
image_id, io_result);
return 0;
/* Attempt to access the image */
io_result = io_open(dev_handle, image_spec, &image_handle);
- if (io_result != IO_SUCCESS) {
+ if (io_result != 0) {
WARN("Failed to access image id=%u (%i)\n",
image_id, io_result);
return 0;
/* Find the size of the image */
io_result = io_size(image_handle, &image_size);
- if ((io_result != IO_SUCCESS) || (image_size == 0)) {
+ if ((io_result != 0) || (image_size == 0)) {
WARN("Failed to determine the size of the image id=%u (%i)\n",
image_id, io_result);
}
assert(dev_info != NULL);
*dev_info = (io_dev_info_t *)&fip_dev_info; /* cast away const */
- return IO_SUCCESS;
+ return 0;
}
/* Do some basic package checks. */
static int fip_dev_init(io_dev_info_t *dev_info, const uintptr_t init_params)
{
- int result = IO_FAIL;
+ int result;
unsigned int image_id = (unsigned int)init_params;
uintptr_t backend_handle;
fip_toc_header_t header;
/* Obtain a reference to the image by querying the platform layer */
result = plat_get_image_source(image_id, &backend_dev_handle,
&backend_image_spec);
- if (result != IO_SUCCESS) {
+ if (result != 0) {
WARN("Failed to obtain reference to image id=%u (%i)\n",
image_id, result);
- result = IO_FAIL;
+ result = -ENOENT;
goto fip_dev_init_exit;
}
/* Attempt to access the FIP image */
result = io_open(backend_dev_handle, backend_image_spec,
&backend_handle);
- if (result != IO_SUCCESS) {
+ if (result != 0) {
WARN("Failed to access image id=%u (%i)\n", image_id, result);
- result = IO_FAIL;
+ result = -ENOENT;
goto fip_dev_init_exit;
}
result = io_read(backend_handle, (uintptr_t)&header, sizeof(header),
&bytes_read);
- if (result == IO_SUCCESS) {
+ if (result == 0) {
if (!is_valid_header(&header)) {
WARN("Firmware Image Package header check failed.\n");
- result = IO_FAIL;
+ result = -ENOENT;
} else {
VERBOSE("FIP header looks OK.\n");
}
backend_dev_handle = (uintptr_t)NULL;
backend_image_spec = (uintptr_t)NULL;
- return IO_SUCCESS;
+ return 0;
}
static int fip_file_open(io_dev_info_t *dev_info, const uintptr_t spec,
io_entity_t *entity)
{
- int result = IO_FAIL;
+ int result;
uintptr_t backend_handle;
const io_uuid_spec_t *uuid_spec = (io_uuid_spec_t *)spec;
size_t bytes_read;
*/
if (current_file.entry.offset_address != 0) {
WARN("fip_file_open : Only one open file at a time.\n");
- return IO_RESOURCES_EXHAUSTED;
+ return -ENOMEM;
}
/* Attempt to access the FIP image */
result = io_open(backend_dev_handle, backend_image_spec,
&backend_handle);
- if (result != IO_SUCCESS) {
+ if (result != 0) {
WARN("Failed to open Firmware Image Package (%i)\n", result);
- result = IO_FAIL;
+ result = -ENOENT;
goto fip_file_open_exit;
}
/* Seek past the FIP header into the Table of Contents */
result = io_seek(backend_handle, IO_SEEK_SET, sizeof(fip_toc_header_t));
- if (result != IO_SUCCESS) {
+ if (result != 0) {
WARN("fip_file_open: failed to seek\n");
- result = IO_FAIL;
+ result = -ENOENT;
goto fip_file_open_close;
}
(uintptr_t)¤t_file.entry,
sizeof(current_file.entry),
&bytes_read);
- if (result == IO_SUCCESS) {
+ if (result == 0) {
if (compare_uuids(¤t_file.entry.uuid,
&uuid_spec->uuid) == 0) {
found_file = 1;
} else {
/* Did not find the file in the FIP. */
current_file.entry.offset_address = 0;
- result = IO_FAIL;
+ result = -ENOENT;
}
fip_file_open_close:
*length = ((file_state_t *)entity->info)->entry.size;
- return IO_SUCCESS;
+ return 0;
}
static int fip_file_read(io_entity_t *entity, uintptr_t buffer, size_t length,
size_t *length_read)
{
- int result = IO_FAIL;
+ int result;
file_state_t *fp;
size_t file_offset;
size_t bytes_read;
/* Open the backend, attempt to access the blob image */
result = io_open(backend_dev_handle, backend_image_spec,
&backend_handle);
- if (result != IO_SUCCESS) {
+ if (result != 0) {
WARN("Failed to open FIP (%i)\n", result);
- result = IO_FAIL;
+ result = -ENOENT;
goto fip_file_read_exit;
}
/* Seek to the position in the FIP where the payload lives */
file_offset = fp->entry.offset_address + fp->file_pos;
result = io_seek(backend_handle, IO_SEEK_SET, file_offset);
- if (result != IO_SUCCESS) {
+ if (result != 0) {
WARN("fip_file_read: failed to seek\n");
- result = IO_FAIL;
+ result = -ENOENT;
goto fip_file_read_close;
}
result = io_read(backend_handle, buffer, length, &bytes_read);
- if (result != IO_SUCCESS) {
+ if (result != 0) {
/* We cannot read our data. Fail. */
WARN("Failed to read payload (%i)\n", result);
- result = IO_FAIL;
+ result = -ENOENT;
goto fip_file_read_close;
} else {
/* Set caller length and new file position. */
/* Clear the Entity info. */
entity->info = 0;
- return IO_SUCCESS;
+ return 0;
}
/* Exported functions */
/* Register the Firmware Image Package driver with the IO abstraction */
int register_io_dev_fip(const io_dev_connector_t **dev_con)
{
- int result = IO_FAIL;
+ int result;
assert(dev_con != NULL);
result = io_register_device(&fip_dev_info);
- if (result == IO_SUCCESS)
+ if (result == 0)
*dev_con = &fip_dev_connector;
return result;
assert(dev_info != NULL);
*dev_info = (io_dev_info_t *)&memmap_dev_info; /* cast away const */
- return IO_SUCCESS;
+ return 0;
}
{
/* NOP */
/* TODO: Consider tracking open files and cleaning them up here */
- return IO_SUCCESS;
+ return 0;
}
static int memmap_block_open(io_dev_info_t *dev_info, const uintptr_t spec,
io_entity_t *entity)
{
- int result = IO_FAIL;
+ int result = -ENOMEM;
const io_block_spec_t *block_spec = (io_block_spec_t *)spec;
/* Since we need to track open state for seek() we only allow one open
/* File cursor offset for seek and incremental reads etc. */
current_file.file_pos = 0;
entity->info = (uintptr_t)¤t_file;
- result = IO_SUCCESS;
+ result = 0;
} else {
WARN("A Memmap device is already active. Close first.\n");
- result = IO_RESOURCES_EXHAUSTED;
}
return result;
/* Seek to a particular file offset on the memmap device */
static int memmap_block_seek(io_entity_t *entity, int mode, ssize_t offset)
{
- int result = IO_FAIL;
+ int result = -ENOENT;
/* We only support IO_SEEK_SET for the moment. */
if (mode == IO_SEEK_SET) {
/* TODO: can we do some basic limit checks on seek? */
((file_state_t *)entity->info)->file_pos = offset;
- result = IO_SUCCESS;
- } else {
- result = IO_FAIL;
+ result = 0;
}
return result;
/* advance the file 'cursor' for incremental reads */
fp->file_pos += length;
- return IO_SUCCESS;
+ return 0;
}
/* advance the file 'cursor' for incremental writes */
fp->file_pos += length;
- return IO_SUCCESS;
+ return 0;
}
/* This would be a mem free() if we had malloc.*/
memset((void *)¤t_file, 0, sizeof(current_file));
- return IO_SUCCESS;
+ return 0;
}
/* Register the memmap driver with the IO abstraction */
int register_io_dev_memmap(const io_dev_connector_t **dev_con)
{
- int result = IO_FAIL;
+ int result;
assert(dev_con != NULL);
result = io_register_device(&memmap_dev_info);
- if (result == IO_SUCCESS)
+ if (result == 0)
*dev_con = &memmap_dev_connector;
return result;
static int sh_dev_open(const uintptr_t dev_spec __unused,
io_dev_info_t **dev_info)
{
- int result = IO_SUCCESS;
assert(dev_info != NULL);
*dev_info = (io_dev_info_t *)&sh_dev_info; /* cast away const */
- return result;
+ return 0;
}
static int sh_file_open(io_dev_info_t *dev_info __attribute__((unused)),
const uintptr_t spec, io_entity_t *entity)
{
- int result = IO_FAIL;
+ int result = -ENOENT;
long sh_result = -1;
const io_file_spec_t *file_spec = (const io_file_spec_t *)spec;
if (sh_result > 0) {
entity->info = (uintptr_t)sh_result;
- result = IO_SUCCESS;
- } else {
- result = IO_FAIL;
+ result = 0;
}
return result;
}
/* Seek to a particular file offset on the semi-hosting device */
static int sh_file_seek(io_entity_t *entity, int mode, ssize_t offset)
{
- int result = IO_FAIL;
long file_handle, sh_result;
assert(entity != NULL);
sh_result = semihosting_file_seek(file_handle, offset);
- result = (sh_result == 0) ? IO_SUCCESS : IO_FAIL;
-
- return result;
+ return (sh_result == 0) ? 0 : -ENOENT;
}
/* Return the size of a file on the semi-hosting device */
static int sh_file_len(io_entity_t *entity, size_t *length)
{
- int result = IO_FAIL;
+ int result = -ENOENT;
assert(entity != NULL);
assert(length != NULL);
long sh_result = semihosting_file_length(sh_handle);
if (sh_result >= 0) {
- result = IO_SUCCESS;
+ result = 0;
*length = (size_t)sh_result;
}
static int sh_file_read(io_entity_t *entity, uintptr_t buffer, size_t length,
size_t *length_read)
{
- int result = IO_FAIL;
+ int result = -ENOENT;
long sh_result = -1;
size_t bytes = length;
long file_handle;
if (sh_result >= 0) {
*length_read = (bytes != length) ? bytes : length;
- result = IO_SUCCESS;
- } else
- result = IO_FAIL;
+ result = 0;
+ }
return result;
}
*length_written = length - bytes;
- return (sh_result == 0) ? IO_SUCCESS : IO_FAIL;
+ return (sh_result == 0) ? 0 : -ENOENT;
}
/* Close a file on the semi-hosting device */
static int sh_file_close(io_entity_t *entity)
{
- int result = IO_FAIL;
long sh_result = -1;
long file_handle;
sh_result = semihosting_file_close(file_handle);
- result = (sh_result >= 0) ? IO_SUCCESS : IO_FAIL;
-
- return result;
+ return (sh_result >= 0) ? 0 : -ENOENT;
}
/* Register the semi-hosting driver with the IO abstraction */
int register_io_dev_sh(const io_dev_connector_t **dev_con)
{
- int result = IO_FAIL;
+ int result;
assert(dev_con != NULL);
result = io_register_device(&sh_dev_info);
- if (result == IO_SUCCESS)
+ if (result == 0)
*dev_con = &sh_dev_connector;
return result;
static int dev_open(const io_dev_connector_t *dev_con, const uintptr_t dev_spec,
io_dev_info_t **dev_info)
{
- int result = IO_FAIL;
+ int result;
assert(dev_info != NULL);
assert(is_valid_dev_connector(dev_con));
/* Locate an entity in the pool, specified by address */
static int find_first_entity(const io_entity_t *entity, unsigned int *index_out)
{
- int result = IO_FAIL;
+ int result = -ENOENT;
for (int index = 0; index < MAX_IO_HANDLES; ++index) {
if (entity_map[index] == entity) {
- result = IO_SUCCESS;
+ result = 0;
*index_out = index;
break;
}
/* Allocate an entity from the pool and return a pointer to it */
static int allocate_entity(io_entity_t **entity)
{
- int result = IO_FAIL;
+ int result = -ENOMEM;
assert(entity != NULL);
if (entity_count < MAX_IO_HANDLES) {
unsigned int index = 0;
result = find_first_entity(NULL, &index);
- assert(result == IO_SUCCESS);
+ assert(result == 0);
*entity = entity_map[index] = &entity_pool[index];
++entity_count;
- } else
- result = IO_RESOURCES_EXHAUSTED;
+ }
return result;
}
/* Release an entity back to the pool */
static int free_entity(const io_entity_t *entity)
{
- int result = IO_FAIL;
+ int result;
unsigned int index = 0;
assert(entity != NULL);
result = find_first_entity(entity, &index);
- if (result == IO_SUCCESS) {
+ if (result == 0) {
entity_map[index] = NULL;
--entity_count;
}
/* Register a device driver */
int io_register_device(const io_dev_info_t *dev_info)
{
- int result = IO_FAIL;
+ int result = -ENOMEM;
assert(dev_info != NULL);
if (dev_count < MAX_IO_DEVICES) {
devices[dev_count] = dev_info;
dev_count++;
- result = IO_SUCCESS;
- } else {
- result = IO_RESOURCES_EXHAUSTED;
+ result = 0;
}
return result;
int io_dev_open(const io_dev_connector_t *dev_con, const uintptr_t dev_spec,
uintptr_t *handle)
{
- int result = IO_FAIL;
+ int result;
assert(handle != NULL);
result = dev_open(dev_con, dev_spec, (io_dev_info_t **)handle);
* re-initialisation */
int io_dev_init(uintptr_t dev_handle, const uintptr_t init_params)
{
- int result = IO_FAIL;
+ int result = 0;
assert(dev_handle != (uintptr_t)NULL);
assert(is_valid_dev(dev_handle));
io_dev_info_t *dev = (io_dev_info_t *)dev_handle;
+ /* Absence of registered function implies NOP here */
if (dev->funcs->dev_init != NULL) {
result = dev->funcs->dev_init(dev, init_params);
- } else {
- /* Absence of registered function implies NOP here */
- result = IO_SUCCESS;
}
+
return result;
}
/* Close a connection to a device */
int io_dev_close(uintptr_t dev_handle)
{
- int result = IO_FAIL;
+ int result = 0;
assert(dev_handle != (uintptr_t)NULL);
assert(is_valid_dev(dev_handle));
io_dev_info_t *dev = (io_dev_info_t *)dev_handle;
+ /* Absence of registered function implies NOP here */
if (dev->funcs->dev_close != NULL) {
result = dev->funcs->dev_close(dev);
- } else {
- /* Absence of registered function implies NOP here */
- result = IO_SUCCESS;
}
return result;
/* Open an IO entity */
int io_open(uintptr_t dev_handle, const uintptr_t spec, uintptr_t *handle)
{
- int result = IO_FAIL;
+ int result;
assert((spec != (uintptr_t)NULL) && (handle != NULL));
assert(is_valid_dev(dev_handle));
result = allocate_entity(&entity);
- if (result == IO_SUCCESS) {
+ if (result == 0) {
assert(dev->funcs->open != NULL);
result = dev->funcs->open(dev, spec, entity);
- if (result == IO_SUCCESS) {
+ if (result == 0) {
entity->dev_handle = dev;
set_handle(handle, entity);
} else
/* Seek to a specific position in an IO entity */
int io_seek(uintptr_t handle, io_seek_mode_t mode, ssize_t offset)
{
- int result = IO_FAIL;
+ int result = -ENODEV;
assert(is_valid_entity(handle) && is_valid_seek_mode(mode));
io_entity_t *entity = (io_entity_t *)handle;
if (dev->funcs->seek != NULL)
result = dev->funcs->seek(entity, mode, offset);
- else
- result = IO_NOT_SUPPORTED;
return result;
}
/* Determine the length of an IO entity */
int io_size(uintptr_t handle, size_t *length)
{
- int result = IO_FAIL;
+ int result = -ENODEV;
assert(is_valid_entity(handle) && (length != NULL));
io_entity_t *entity = (io_entity_t *)handle;
if (dev->funcs->size != NULL)
result = dev->funcs->size(entity, length);
- else
- result = IO_NOT_SUPPORTED;
return result;
}
size_t length,
size_t *length_read)
{
- int result = IO_FAIL;
+ int result = -ENODEV;
assert(is_valid_entity(handle) && (buffer != (uintptr_t)NULL));
io_entity_t *entity = (io_entity_t *)handle;
if (dev->funcs->read != NULL)
result = dev->funcs->read(entity, buffer, length, length_read);
- else
- result = IO_NOT_SUPPORTED;
return result;
}
size_t length,
size_t *length_written)
{
- int result = IO_FAIL;
+ int result = -ENODEV;
assert(is_valid_entity(handle) && (buffer != (uintptr_t)NULL));
io_entity_t *entity = (io_entity_t *)handle;
if (dev->funcs->write != NULL) {
result = dev->funcs->write(entity, buffer, length,
length_written);
- } else
- result = IO_NOT_SUPPORTED;
+ }
return result;
}
/* Close an IO entity */
int io_close(uintptr_t handle)
{
- int result = IO_FAIL;
+ int result = 0;
assert(is_valid_entity(handle));
io_entity_t *entity = (io_entity_t *)handle;
io_dev_info_t *dev = entity->dev_handle;
+ /* Absence of registered function implies NOP here */
if (dev->funcs->close != NULL)
result = dev->funcs->close(entity);
- else {
- /* Absence of registered function implies NOP here */
- result = IO_SUCCESS;
- }
+
/* Ignore improbable free_entity failure */
(void)free_entity(entity);
#define IO_MODE_RW (1 << 1)
-/* Return codes reported by 'io_*' APIs.
- * IMPORTANT: these definitions are deprecated. Callers should use standard
- * errno definitions when checking the return value of io_* APIs. */
-#define IO_SUCCESS (0)
-#define IO_FAIL (-ENOENT)
-#define IO_NOT_SUPPORTED (-ENODEV)
-#define IO_RESOURCES_EXHAUSTED (-ENOMEM)
-
-
/* Open a connection to a device */
int io_dev_open(const struct io_dev_connector *dev_con,
const uintptr_t dev_spec,
static int open_semihosting(const uintptr_t spec)
{
- int result = IO_FAIL;
+ int result;
uintptr_t local_image_handle;
/* See if the file exists on semi-hosting.*/
result = io_dev_init(sh_dev_handle, (uintptr_t)NULL);
- if (result == IO_SUCCESS) {
+ if (result == 0) {
result = io_open(sh_dev_handle, spec, &local_image_handle);
- if (result == IO_SUCCESS) {
+ if (result == 0) {
VERBOSE("Using Semi-hosting IO\n");
io_close(local_image_handle);
}
/* Register the additional IO devices on this platform */
io_result = register_io_dev_sh(&sh_dev_con);
- assert(io_result == IO_SUCCESS);
+ assert(io_result == 0);
/* Open connections to devices and cache the handles */
io_result = io_dev_open(sh_dev_con, (uintptr_t)NULL, &sh_dev_handle);
- assert(io_result == IO_SUCCESS);
+ assert(io_result == 0);
/* Ignore improbable errors in release builds */
(void)io_result;
uintptr_t *image_spec)
{
int result = open_semihosting((const uintptr_t)&sh_file_spec[image_id]);
- if (result == IO_SUCCESS) {
+ if (result == 0) {
*dev_handle = sh_dev_handle;
*image_spec = (uintptr_t)&sh_file_spec[image_id];
}
/* See if a Firmware Image Package is available */
result = io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID);
- if (result == IO_SUCCESS) {
+ if (result == 0) {
result = io_open(fip_dev_handle, spec, &local_image_handle);
- if (result == IO_SUCCESS) {
+ if (result == 0) {
VERBOSE("Using FIP\n");
io_close(local_image_handle);
}
uintptr_t local_image_handle;
result = io_dev_init(memmap_dev_handle, (uintptr_t)NULL);
- if (result == IO_SUCCESS) {
+ if (result == 0) {
result = io_open(memmap_dev_handle, spec, &local_image_handle);
- if (result == IO_SUCCESS) {
+ if (result == 0) {
VERBOSE("Using Memmap\n");
io_close(local_image_handle);
}
int io_result;
io_result = register_io_dev_fip(&fip_dev_con);
- assert(io_result == IO_SUCCESS);
+ assert(io_result == 0);
io_result = register_io_dev_memmap(&memmap_dev_con);
- assert(io_result == IO_SUCCESS);
+ assert(io_result == 0);
/* Open connections to devices and cache the handles */
io_result = io_dev_open(fip_dev_con, (uintptr_t)NULL,
&fip_dev_handle);
- assert(io_result == IO_SUCCESS);
+ assert(io_result == 0);
io_result = io_dev_open(memmap_dev_con, (uintptr_t)NULL,
&memmap_dev_handle);
- assert(io_result == IO_SUCCESS);
+ assert(io_result == 0);
/* Ignore improbable errors in release builds */
(void)io_result;
uintptr_t *image_spec __attribute__((unused)))
{
/* By default do not try an alternative */
- return IO_FAIL;
+ return -ENOENT;
}
/* Return an IO device handle and specification which can be used to access
int plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle,
uintptr_t *image_spec)
{
- int result = IO_FAIL;
+ int result;
const struct plat_io_policy *policy;
assert(image_id < ARRAY_SIZE(policies));
policy = &policies[image_id];
result = policy->check(policy->image_spec);
- if (result == IO_SUCCESS) {
+ if (result == 0) {
*image_spec = policy->image_spec;
*dev_handle = *(policy->dev_handle);
} else {