diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/io/io_fip.c | 56 | ||||
-rw-r--r-- | drivers/io/io_memmap.c | 25 | ||||
-rw-r--r-- | drivers/io/io_semihosting.c | 36 | ||||
-rw-r--r-- | drivers/io/io_storage.c | 69 |
4 files changed, 79 insertions, 107 deletions
diff --git a/drivers/io/io_fip.c b/drivers/io/io_fip.c index 5a8a294a0..d29142380 100644 --- a/drivers/io/io_fip.c +++ b/drivers/io/io_fip.c @@ -134,14 +134,14 @@ static int fip_dev_open(const uintptr_t dev_spec __attribute__((unused)), 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; @@ -150,28 +150,28 @@ static int fip_dev_init(io_dev_info_t *dev_info, const uintptr_t init_params) /* 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"); } @@ -192,7 +192,7 @@ static int fip_dev_close(io_dev_info_t *dev_info) backend_dev_handle = (uintptr_t)NULL; backend_image_spec = (uintptr_t)NULL; - return IO_SUCCESS; + return 0; } @@ -200,7 +200,7 @@ static int fip_dev_close(io_dev_info_t *dev_info) 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; @@ -217,23 +217,23 @@ static int fip_file_open(io_dev_info_t *dev_info, const uintptr_t spec, */ 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; } @@ -243,7 +243,7 @@ static int fip_file_open(io_dev_info_t *dev_info, const uintptr_t spec, (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; @@ -265,7 +265,7 @@ static int fip_file_open(io_dev_info_t *dev_info, const uintptr_t spec, } else { /* Did not find the file in the FIP. */ current_file.entry.offset_address = 0; - result = IO_FAIL; + result = -ENOENT; } fip_file_open_close: @@ -284,7 +284,7 @@ static int fip_file_len(io_entity_t *entity, size_t *length) *length = ((file_state_t *)entity->info)->entry.size; - return IO_SUCCESS; + return 0; } @@ -292,7 +292,7 @@ static int fip_file_len(io_entity_t *entity, size_t *length) 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; @@ -306,9 +306,9 @@ static int fip_file_read(io_entity_t *entity, uintptr_t buffer, size_t length, /* 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; } @@ -317,17 +317,17 @@ static int fip_file_read(io_entity_t *entity, uintptr_t buffer, size_t length, /* 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. */ @@ -357,7 +357,7 @@ static int fip_file_close(io_entity_t *entity) /* Clear the Entity info. */ entity->info = 0; - return IO_SUCCESS; + return 0; } /* Exported functions */ @@ -365,11 +365,11 @@ static int fip_file_close(io_entity_t *entity) /* 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; diff --git a/drivers/io/io_memmap.c b/drivers/io/io_memmap.c index fc06fbb90..d45107e51 100644 --- a/drivers/io/io_memmap.c +++ b/drivers/io/io_memmap.c @@ -101,7 +101,7 @@ static int memmap_dev_open(const uintptr_t dev_spec __attribute__((unused)), assert(dev_info != NULL); *dev_info = (io_dev_info_t *)&memmap_dev_info; /* cast away const */ - return IO_SUCCESS; + return 0; } @@ -111,7 +111,7 @@ static int memmap_dev_close(io_dev_info_t *dev_info) { /* NOP */ /* TODO: Consider tracking open files and cleaning them up here */ - return IO_SUCCESS; + return 0; } @@ -120,7 +120,7 @@ static int memmap_dev_close(io_dev_info_t *dev_info) 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 @@ -136,10 +136,9 @@ static int memmap_block_open(io_dev_info_t *dev_info, const uintptr_t spec, /* 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; @@ -149,7 +148,7 @@ static int memmap_block_open(io_dev_info_t *dev_info, const uintptr_t spec, /* 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) { @@ -157,9 +156,7 @@ static int memmap_block_seek(io_entity_t *entity, int mode, ssize_t offset) /* 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; @@ -184,7 +181,7 @@ static int memmap_block_read(io_entity_t *entity, uintptr_t buffer, /* advance the file 'cursor' for incremental reads */ fp->file_pos += length; - return IO_SUCCESS; + return 0; } @@ -207,7 +204,7 @@ static int memmap_block_write(io_entity_t *entity, const uintptr_t buffer, /* advance the file 'cursor' for incremental writes */ fp->file_pos += length; - return IO_SUCCESS; + return 0; } @@ -221,7 +218,7 @@ static int memmap_block_close(io_entity_t *entity) /* This would be a mem free() if we had malloc.*/ memset((void *)¤t_file, 0, sizeof(current_file)); - return IO_SUCCESS; + return 0; } @@ -230,11 +227,11 @@ static int memmap_block_close(io_entity_t *entity) /* 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; diff --git a/drivers/io/io_semihosting.c b/drivers/io/io_semihosting.c index 8e62be1d9..63d0f68ec 100644 --- a/drivers/io/io_semihosting.c +++ b/drivers/io/io_semihosting.c @@ -84,10 +84,9 @@ static const io_dev_info_t sh_dev_info = { 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; } @@ -95,7 +94,7 @@ static int sh_dev_open(const uintptr_t dev_spec __unused, 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; @@ -106,9 +105,7 @@ static int sh_file_open(io_dev_info_t *dev_info __attribute__((unused)), if (sh_result > 0) { entity->info = (uintptr_t)sh_result; - result = IO_SUCCESS; - } else { - result = IO_FAIL; + result = 0; } return result; } @@ -117,7 +114,6 @@ static int sh_file_open(io_dev_info_t *dev_info __attribute__((unused)), /* 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); @@ -126,16 +122,14 @@ static int sh_file_seek(io_entity_t *entity, int mode, ssize_t offset) 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); @@ -144,7 +138,7 @@ static int sh_file_len(io_entity_t *entity, size_t *length) long sh_result = semihosting_file_length(sh_handle); if (sh_result >= 0) { - result = IO_SUCCESS; + result = 0; *length = (size_t)sh_result; } @@ -156,7 +150,7 @@ static int sh_file_len(io_entity_t *entity, size_t *length) 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; @@ -171,9 +165,8 @@ static int sh_file_read(io_entity_t *entity, uintptr_t buffer, size_t length, if (sh_result >= 0) { *length_read = (bytes != length) ? bytes : length; - result = IO_SUCCESS; - } else - result = IO_FAIL; + result = 0; + } return result; } @@ -197,14 +190,13 @@ static int sh_file_write(io_entity_t *entity, const uintptr_t buffer, *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; @@ -214,9 +206,7 @@ static int sh_file_close(io_entity_t *entity) sh_result = semihosting_file_close(file_handle); - result = (sh_result >= 0) ? IO_SUCCESS : IO_FAIL; - - return result; + return (sh_result >= 0) ? 0 : -ENOENT; } @@ -225,11 +215,11 @@ static int sh_file_close(io_entity_t *entity) /* 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; diff --git a/drivers/io/io_storage.c b/drivers/io/io_storage.c index a3a8186d0..7cb1a6aa2 100644 --- a/drivers/io/io_storage.c +++ b/drivers/io/io_storage.c @@ -96,7 +96,7 @@ static int is_valid_seek_mode(io_seek_mode_t mode) 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)); @@ -116,10 +116,10 @@ static void set_handle(uintptr_t *handle, io_entity_t *entity) /* 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; } @@ -131,17 +131,16 @@ static int find_first_entity(const io_entity_t *entity, unsigned int *index_out) /* 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; } @@ -150,12 +149,12 @@ static int allocate_entity(io_entity_t **entity) /* 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; } @@ -169,15 +168,13 @@ static int free_entity(const io_entity_t *entity) /* 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; @@ -188,7 +185,7 @@ int io_register_device(const io_dev_info_t *dev_info) 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); @@ -200,18 +197,17 @@ int io_dev_open(const io_dev_connector_t *dev_con, const uintptr_t dev_spec, * 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; } @@ -221,17 +217,15 @@ int io_dev_init(uintptr_t dev_handle, const uintptr_t init_params) /* 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; @@ -244,7 +238,7 @@ int io_dev_close(uintptr_t dev_handle) /* 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)); @@ -253,11 +247,11 @@ int io_open(uintptr_t dev_handle, const uintptr_t spec, uintptr_t *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 @@ -270,7 +264,7 @@ int io_open(uintptr_t dev_handle, const uintptr_t spec, uintptr_t *handle) /* 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; @@ -279,8 +273,6 @@ int io_seek(uintptr_t handle, io_seek_mode_t mode, ssize_t offset) if (dev->funcs->seek != NULL) result = dev->funcs->seek(entity, mode, offset); - else - result = IO_NOT_SUPPORTED; return result; } @@ -289,7 +281,7 @@ int io_seek(uintptr_t handle, io_seek_mode_t mode, ssize_t offset) /* 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; @@ -298,8 +290,6 @@ int io_size(uintptr_t handle, size_t *length) if (dev->funcs->size != NULL) result = dev->funcs->size(entity, length); - else - result = IO_NOT_SUPPORTED; return result; } @@ -311,7 +301,7 @@ int io_read(uintptr_t handle, 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; @@ -320,8 +310,6 @@ int io_read(uintptr_t handle, if (dev->funcs->read != NULL) result = dev->funcs->read(entity, buffer, length, length_read); - else - result = IO_NOT_SUPPORTED; return result; } @@ -333,7 +321,7 @@ int io_write(uintptr_t handle, 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; @@ -343,8 +331,7 @@ int io_write(uintptr_t handle, if (dev->funcs->write != NULL) { result = dev->funcs->write(entity, buffer, length, length_written); - } else - result = IO_NOT_SUPPORTED; + } return result; } @@ -353,19 +340,17 @@ int io_write(uintptr_t handle, /* 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); |