Commit 6e99fe1a authored by Manish Pandey's avatar Manish Pandey Committed by TrustedFirmware Code Review
Browse files

Merge "IO Driver Misra Cleanup" into integration

parents 21e04cf2 d471bd9c
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
typedef struct { typedef struct {
unsigned int file_pos; unsigned int file_pos;
fip_toc_entry_t entry; fip_toc_entry_t entry;
} file_state_t; } fip_file_state_t;
/* /*
* Maintain dev_spec per FIP Device * Maintain dev_spec per FIP Device
...@@ -49,7 +49,6 @@ typedef struct { ...@@ -49,7 +49,6 @@ typedef struct {
uint16_t plat_toc_flag; uint16_t plat_toc_flag;
} fip_dev_state_t; } fip_dev_state_t;
static const uuid_t uuid_null;
/* /*
* Only one file can be open across all FIP device * Only one file can be open across all FIP device
* as backends like io_memmap don't support * as backends like io_memmap don't support
...@@ -57,7 +56,7 @@ static const uuid_t uuid_null; ...@@ -57,7 +56,7 @@ static const uuid_t uuid_null;
* backend handle should be maintained per FIP device * backend handle should be maintained per FIP device
* if the same support is available in the backend * if the same support is available in the backend
*/ */
static file_state_t current_file = {0}; static fip_file_state_t current_fip_file = {0};
static uintptr_t backend_dev_handle; static uintptr_t backend_dev_handle;
static uintptr_t backend_image_spec; static uintptr_t backend_image_spec;
...@@ -288,6 +287,7 @@ static int fip_file_open(io_dev_info_t *dev_info, const uintptr_t spec, ...@@ -288,6 +287,7 @@ static int fip_file_open(io_dev_info_t *dev_info, const uintptr_t spec,
int result; int result;
uintptr_t backend_handle; uintptr_t backend_handle;
const io_uuid_spec_t *uuid_spec = (io_uuid_spec_t *)spec; const io_uuid_spec_t *uuid_spec = (io_uuid_spec_t *)spec;
static const uuid_t uuid_null = { {0} }; /* Double braces for clang */
size_t bytes_read; size_t bytes_read;
int found_file = 0; int found_file = 0;
...@@ -300,7 +300,7 @@ static int fip_file_open(io_dev_info_t *dev_info, const uintptr_t spec, ...@@ -300,7 +300,7 @@ static int fip_file_open(io_dev_info_t *dev_info, const uintptr_t spec,
* When the system supports dynamic memory allocation we can allow more * When the system supports dynamic memory allocation we can allow more
* than one open file at a time if needed. * than one open file at a time if needed.
*/ */
if (current_file.entry.offset_address != 0) { if (current_fip_file.entry.offset_address != 0U) {
WARN("fip_file_open : Only one open file at a time.\n"); WARN("fip_file_open : Only one open file at a time.\n");
return -ENOMEM; return -ENOMEM;
} }
...@@ -326,31 +326,32 @@ static int fip_file_open(io_dev_info_t *dev_info, const uintptr_t spec, ...@@ -326,31 +326,32 @@ static int fip_file_open(io_dev_info_t *dev_info, const uintptr_t spec,
found_file = 0; found_file = 0;
do { do {
result = io_read(backend_handle, result = io_read(backend_handle,
(uintptr_t)&current_file.entry, (uintptr_t)&current_fip_file.entry,
sizeof(current_file.entry), sizeof(current_fip_file.entry),
&bytes_read); &bytes_read);
if (result == 0) { if (result == 0) {
if (compare_uuids(&current_file.entry.uuid, if (compare_uuids(&current_fip_file.entry.uuid,
&uuid_spec->uuid) == 0) { &uuid_spec->uuid) == 0) {
found_file = 1; found_file = 1;
break;
} }
} else { } else {
WARN("Failed to read FIP (%i)\n", result); WARN("Failed to read FIP (%i)\n", result);
goto fip_file_open_close; goto fip_file_open_close;
} }
} while (compare_uuids(&current_file.entry.uuid, &uuid_null) != 0); } while ((found_file == 0) &&
(compare_uuids(&current_fip_file.entry.uuid,
&uuid_null) != 0));
if (found_file == 1) { if (found_file == 1) {
/* All fine. Update entity info with file state and return. Set /* All fine. Update entity info with file state and return. Set
* the file position to 0. The 'current_file.entry' holds the * the file position to 0. The 'current_fip_file.entry' holds
* base and size of the file. * the base and size of the file.
*/ */
current_file.file_pos = 0; current_fip_file.file_pos = 0;
entity->info = (uintptr_t)&current_file; entity->info = (uintptr_t)&current_fip_file;
} else { } else {
/* Did not find the file in the FIP. */ /* Did not find the file in the FIP. */
current_file.entry.offset_address = 0; current_fip_file.entry.offset_address = 0;
result = -ENOENT; result = -ENOENT;
} }
...@@ -368,7 +369,7 @@ static int fip_file_len(io_entity_t *entity, size_t *length) ...@@ -368,7 +369,7 @@ static int fip_file_len(io_entity_t *entity, size_t *length)
assert(entity != NULL); assert(entity != NULL);
assert(length != NULL); assert(length != NULL);
*length = ((file_state_t *)entity->info)->entry.size; *length = ((fip_file_state_t *)entity->info)->entry.size;
return 0; return 0;
} }
...@@ -379,7 +380,7 @@ static int fip_file_read(io_entity_t *entity, uintptr_t buffer, size_t length, ...@@ -379,7 +380,7 @@ static int fip_file_read(io_entity_t *entity, uintptr_t buffer, size_t length,
size_t *length_read) size_t *length_read)
{ {
int result; int result;
file_state_t *fp; fip_file_state_t *fp;
size_t file_offset; size_t file_offset;
size_t bytes_read; size_t bytes_read;
uintptr_t backend_handle; uintptr_t backend_handle;
...@@ -397,7 +398,7 @@ static int fip_file_read(io_entity_t *entity, uintptr_t buffer, size_t length, ...@@ -397,7 +398,7 @@ static int fip_file_read(io_entity_t *entity, uintptr_t buffer, size_t length,
goto fip_file_read_exit; goto fip_file_read_exit;
} }
fp = (file_state_t *)entity->info; fp = (fip_file_state_t *)entity->info;
/* Seek to the position in the FIP where the payload lives */ /* Seek to the position in the FIP where the payload lives */
file_offset = fp->entry.offset_address + fp->file_pos; file_offset = fp->entry.offset_address + fp->file_pos;
...@@ -436,8 +437,8 @@ static int fip_file_close(io_entity_t *entity) ...@@ -436,8 +437,8 @@ static int fip_file_close(io_entity_t *entity)
/* Clear our current file pointer. /* Clear our current file pointer.
* If we had malloc() we would free() here. * If we had malloc() we would free() here.
*/ */
if (current_file.entry.offset_address != 0) { if (current_fip_file.entry.offset_address != 0U) {
zeromem(&current_file, sizeof(current_file)); zeromem(&current_fip_file, sizeof(current_fip_file));
} }
/* Clear the Entity info. */ /* Clear the Entity info. */
......
/* /*
* Copyright (c) 2014-2018, ARM Limited and Contributors. All rights reserved. * Copyright (c) 2014-2020, ARM Limited and Contributors. All rights reserved.
* *
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
...@@ -27,9 +27,9 @@ typedef struct { ...@@ -27,9 +27,9 @@ typedef struct {
uintptr_t base; uintptr_t base;
unsigned long long file_pos; unsigned long long file_pos;
unsigned long long size; unsigned long long size;
} file_state_t; } memmap_file_state_t;
static file_state_t current_file = {0}; static memmap_file_state_t current_memmap_file = {0};
/* Identify the device type as memmap */ /* Identify the device type as memmap */
static io_type_t device_type_memmap(void) static io_type_t device_type_memmap(void)
...@@ -71,7 +71,7 @@ static const io_dev_funcs_t memmap_dev_funcs = { ...@@ -71,7 +71,7 @@ static const io_dev_funcs_t memmap_dev_funcs = {
/* No state associated with this device so structure can be const */ /* No state associated with this device so structure can be const */
static const io_dev_info_t memmap_dev_info = { static io_dev_info_t memmap_dev_info = {
.funcs = &memmap_dev_funcs, .funcs = &memmap_dev_funcs,
.info = (uintptr_t)NULL .info = (uintptr_t)NULL
}; };
...@@ -82,8 +82,7 @@ static int memmap_dev_open(const uintptr_t dev_spec __unused, ...@@ -82,8 +82,7 @@ static int memmap_dev_open(const uintptr_t dev_spec __unused,
io_dev_info_t **dev_info) io_dev_info_t **dev_info)
{ {
assert(dev_info != NULL); assert(dev_info != NULL);
*dev_info = (io_dev_info_t *)&memmap_dev_info; /* cast away const */ *dev_info = &memmap_dev_info;
return 0; return 0;
} }
...@@ -109,16 +108,16 @@ static int memmap_block_open(io_dev_info_t *dev_info, const uintptr_t spec, ...@@ -109,16 +108,16 @@ static int memmap_block_open(io_dev_info_t *dev_info, const uintptr_t spec,
* spec at a time. When we have dynamic memory we can malloc and set * spec at a time. When we have dynamic memory we can malloc and set
* entity->info. * entity->info.
*/ */
if (current_file.in_use == 0) { if (current_memmap_file.in_use == 0) {
assert(block_spec != NULL); assert(block_spec != NULL);
assert(entity != NULL); assert(entity != NULL);
current_file.in_use = 1; current_memmap_file.in_use = 1;
current_file.base = block_spec->offset; current_memmap_file.base = block_spec->offset;
/* File cursor offset for seek and incremental reads etc. */ /* File cursor offset for seek and incremental reads etc. */
current_file.file_pos = 0; current_memmap_file.file_pos = 0;
current_file.size = block_spec->length; current_memmap_file.size = block_spec->length;
entity->info = (uintptr_t)&current_file; entity->info = (uintptr_t)&current_memmap_file;
result = 0; result = 0;
} else { } else {
WARN("A Memmap device is already active. Close first.\n"); WARN("A Memmap device is already active. Close first.\n");
...@@ -133,13 +132,13 @@ static int memmap_block_seek(io_entity_t *entity, int mode, ...@@ -133,13 +132,13 @@ static int memmap_block_seek(io_entity_t *entity, int mode,
signed long long offset) signed long long offset)
{ {
int result = -ENOENT; int result = -ENOENT;
file_state_t *fp; memmap_file_state_t *fp;
/* We only support IO_SEEK_SET for the moment. */ /* We only support IO_SEEK_SET for the moment. */
if (mode == IO_SEEK_SET) { if (mode == IO_SEEK_SET) {
assert(entity != NULL); assert(entity != NULL);
fp = (file_state_t *) entity->info; fp = (memmap_file_state_t *) entity->info;
/* Assert that new file position is valid */ /* Assert that new file position is valid */
assert((offset >= 0) && assert((offset >= 0) &&
...@@ -160,7 +159,7 @@ static int memmap_block_len(io_entity_t *entity, size_t *length) ...@@ -160,7 +159,7 @@ static int memmap_block_len(io_entity_t *entity, size_t *length)
assert(entity != NULL); assert(entity != NULL);
assert(length != NULL); assert(length != NULL);
*length = (size_t)((file_state_t *)entity->info)->size; *length = (size_t)((memmap_file_state_t *)entity->info)->size;
return 0; return 0;
} }
...@@ -170,13 +169,13 @@ static int memmap_block_len(io_entity_t *entity, size_t *length) ...@@ -170,13 +169,13 @@ static int memmap_block_len(io_entity_t *entity, size_t *length)
static int memmap_block_read(io_entity_t *entity, uintptr_t buffer, static int memmap_block_read(io_entity_t *entity, uintptr_t buffer,
size_t length, size_t *length_read) size_t length, size_t *length_read)
{ {
file_state_t *fp; memmap_file_state_t *fp;
unsigned long long pos_after; unsigned long long pos_after;
assert(entity != NULL); assert(entity != NULL);
assert(length_read != NULL); assert(length_read != NULL);
fp = (file_state_t *) entity->info; fp = (memmap_file_state_t *) entity->info;
/* Assert that file position is valid for this read operation */ /* Assert that file position is valid for this read operation */
pos_after = fp->file_pos + length; pos_after = fp->file_pos + length;
...@@ -198,13 +197,13 @@ static int memmap_block_read(io_entity_t *entity, uintptr_t buffer, ...@@ -198,13 +197,13 @@ static int memmap_block_read(io_entity_t *entity, uintptr_t buffer,
static int memmap_block_write(io_entity_t *entity, const uintptr_t buffer, static int memmap_block_write(io_entity_t *entity, const uintptr_t buffer,
size_t length, size_t *length_written) size_t length, size_t *length_written)
{ {
file_state_t *fp; memmap_file_state_t *fp;
unsigned long long pos_after; unsigned long long pos_after;
assert(entity != NULL); assert(entity != NULL);
assert(length_written != NULL); assert(length_written != NULL);
fp = (file_state_t *) entity->info; fp = (memmap_file_state_t *) entity->info;
/* Assert that file position is valid for this write operation */ /* Assert that file position is valid for this write operation */
pos_after = fp->file_pos + length; pos_after = fp->file_pos + length;
...@@ -230,7 +229,7 @@ static int memmap_block_close(io_entity_t *entity) ...@@ -230,7 +229,7 @@ static int memmap_block_close(io_entity_t *entity)
entity->info = 0; entity->info = 0;
/* This would be a mem free() if we had malloc.*/ /* This would be a mem free() if we had malloc.*/
zeromem((void *)&current_file, sizeof(current_file)); zeromem((void *)&current_memmap_file, sizeof(current_memmap_file));
return 0; return 0;
} }
......
/* /*
* Copyright (c) 2014-2018, ARM Limited and Contributors. All rights reserved. * Copyright (c) 2014-2020, ARM Limited and Contributors. All rights reserved.
* *
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
...@@ -51,8 +51,7 @@ static const io_dev_funcs_t sh_dev_funcs = { ...@@ -51,8 +51,7 @@ static const io_dev_funcs_t sh_dev_funcs = {
}; };
/* No state associated with this device so structure can be const */ static io_dev_info_t sh_dev_info = {
static const io_dev_info_t sh_dev_info = {
.funcs = &sh_dev_funcs, .funcs = &sh_dev_funcs,
.info = (uintptr_t)NULL .info = (uintptr_t)NULL
}; };
...@@ -63,7 +62,7 @@ static int sh_dev_open(const uintptr_t dev_spec __unused, ...@@ -63,7 +62,7 @@ static int sh_dev_open(const uintptr_t dev_spec __unused,
io_dev_info_t **dev_info) io_dev_info_t **dev_info)
{ {
assert(dev_info != NULL); assert(dev_info != NULL);
*dev_info = (io_dev_info_t *)&sh_dev_info; /* cast away const */ *dev_info = &sh_dev_info;
return 0; return 0;
} }
......
/* /*
* Copyright (c) 2014-2017, ARM Limited and Contributors. All rights reserved. * Copyright (c) 2014-2020, ARM Limited and Contributors. All rights reserved.
* *
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
...@@ -32,14 +32,13 @@ static unsigned int dev_count; ...@@ -32,14 +32,13 @@ static unsigned int dev_count;
#if ENABLE_ASSERTIONS #if ENABLE_ASSERTIONS
/* Return a boolean value indicating whether a device connector is valid */ /* Return a boolean value indicating whether a device connector is valid */
static int is_valid_dev_connector(const io_dev_connector_t *dev_con) static bool is_valid_dev_connector(const io_dev_connector_t *dev_con)
{ {
return (dev_con != NULL) && (dev_con->dev_open != NULL); return (dev_con != NULL) && (dev_con->dev_open != NULL);
} }
/* Return a boolean value indicating whether a device handle is valid */ /* Return a boolean value indicating whether a device handle is valid */
static int is_valid_dev(const uintptr_t dev_handle) static bool is_valid_dev(const uintptr_t dev_handle)
{ {
const io_dev_info_t *dev = (io_dev_info_t *)dev_handle; const io_dev_info_t *dev = (io_dev_info_t *)dev_handle;
...@@ -50,7 +49,7 @@ static int is_valid_dev(const uintptr_t dev_handle) ...@@ -50,7 +49,7 @@ static int is_valid_dev(const uintptr_t dev_handle)
/* Return a boolean value indicating whether an IO entity is valid */ /* Return a boolean value indicating whether an IO entity is valid */
static int is_valid_entity(const uintptr_t handle) static bool is_valid_entity(const uintptr_t handle)
{ {
const io_entity_t *entity = (io_entity_t *)handle; const io_entity_t *entity = (io_entity_t *)handle;
...@@ -60,7 +59,7 @@ static int is_valid_entity(const uintptr_t handle) ...@@ -60,7 +59,7 @@ static int is_valid_entity(const uintptr_t handle)
/* Return a boolean value indicating whether a seek mode is valid */ /* Return a boolean value indicating whether a seek mode is valid */
static int is_valid_seek_mode(io_seek_mode_t mode) static bool is_valid_seek_mode(io_seek_mode_t mode)
{ {
return ((mode != IO_SEEK_INVALID) && (mode < IO_SEEK_MAX)); return ((mode != IO_SEEK_INVALID) && (mode < IO_SEEK_MAX));
} }
...@@ -70,7 +69,8 @@ static int is_valid_seek_mode(io_seek_mode_t mode) ...@@ -70,7 +69,8 @@ static int is_valid_seek_mode(io_seek_mode_t mode)
/* Open a connection to a specific device */ /* Open a connection to a specific device */
static int dev_open(const io_dev_connector_t *dev_con, const uintptr_t dev_spec, static int io_storage_dev_open(const io_dev_connector_t *dev_con,
const uintptr_t dev_spec,
io_dev_info_t **dev_info) io_dev_info_t **dev_info)
{ {
assert(dev_info != NULL); assert(dev_info != NULL);
...@@ -113,7 +113,8 @@ static int allocate_entity(io_entity_t **entity) ...@@ -113,7 +113,8 @@ static int allocate_entity(io_entity_t **entity)
unsigned int index = 0; unsigned int index = 0;
result = find_first_entity(NULL, &index); result = find_first_entity(NULL, &index);
assert(result == 0); assert(result == 0);
*entity = entity_map[index] = &entity_pool[index]; *entity = &entity_pool[index];
entity_map[index] = &entity_pool[index];
++entity_count; ++entity_count;
} }
...@@ -161,8 +162,7 @@ int io_dev_open(const io_dev_connector_t *dev_con, const uintptr_t dev_spec, ...@@ -161,8 +162,7 @@ int io_dev_open(const io_dev_connector_t *dev_con, const uintptr_t dev_spec,
uintptr_t *handle) uintptr_t *handle)
{ {
assert(handle != NULL); assert(handle != NULL);
return io_storage_dev_open(dev_con, dev_spec, (io_dev_info_t **)handle);
return dev_open(dev_con, dev_spec, (io_dev_info_t **)handle);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment