Commit 5cc34831 authored by danh-arm's avatar danh-arm
Browse files

Merge pull request #547 from ljerry/tf_issue_371

Add "size" function to IO memmap device driver
parents 195d29f3 6d70bfa1
...@@ -45,6 +45,7 @@ typedef struct { ...@@ -45,6 +45,7 @@ typedef struct {
int in_use; int in_use;
uintptr_t base; uintptr_t base;
size_t file_pos; size_t file_pos;
size_t size;
} file_state_t; } file_state_t;
static file_state_t current_file = {0}; static file_state_t current_file = {0};
...@@ -61,6 +62,7 @@ static int memmap_block_open(io_dev_info_t *dev_info, const uintptr_t spec, ...@@ -61,6 +62,7 @@ static int memmap_block_open(io_dev_info_t *dev_info, const uintptr_t spec,
io_entity_t *entity); io_entity_t *entity);
static int memmap_block_seek(io_entity_t *entity, int mode, static int memmap_block_seek(io_entity_t *entity, int mode,
ssize_t offset); ssize_t offset);
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);
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,
...@@ -78,7 +80,7 @@ static const io_dev_funcs_t memmap_dev_funcs = { ...@@ -78,7 +80,7 @@ static const io_dev_funcs_t memmap_dev_funcs = {
.type = device_type_memmap, .type = device_type_memmap,
.open = memmap_block_open, .open = memmap_block_open,
.seek = memmap_block_seek, .seek = memmap_block_seek,
.size = NULL, .size = memmap_block_len,
.read = memmap_block_read, .read = memmap_block_read,
.write = memmap_block_write, .write = memmap_block_write,
.close = memmap_block_close, .close = memmap_block_close,
...@@ -135,6 +137,7 @@ static int memmap_block_open(io_dev_info_t *dev_info, const uintptr_t spec, ...@@ -135,6 +137,7 @@ static int memmap_block_open(io_dev_info_t *dev_info, const uintptr_t spec,
current_file.base = block_spec->offset; current_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_file.file_pos = 0;
current_file.size = block_spec->length;
entity->info = (uintptr_t)&current_file; entity->info = (uintptr_t)&current_file;
result = 0; result = 0;
} else { } else {
...@@ -163,6 +166,18 @@ static int memmap_block_seek(io_entity_t *entity, int mode, ssize_t offset) ...@@ -163,6 +166,18 @@ static int memmap_block_seek(io_entity_t *entity, int mode, ssize_t offset)
} }
/* Return the size of a file on the memmap device */
static int memmap_block_len(io_entity_t *entity, size_t *length)
{
assert(entity != NULL);
assert(length != NULL);
*length = ((file_state_t *)entity->info)->size;
return 0;
}
/* Read data from a file on the memmap device */ /* Read data from a file on the memmap device */
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)
......
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