arch:hostfs: add cache coherence config for semihosting option

N/A

Signed-off-by: zhuyanlin <zhuyanlin1@xiaomi.com>
This commit is contained in:
zhuyanlin 2021-11-22 19:26:08 +08:00 committed by Xiang Xiao
parent ad7e36d83f
commit 4db5016d83
4 changed files with 73 additions and 9 deletions

View File

@ -975,6 +975,16 @@ config ARM_SEMIHOSTING_HOSTFS
This doesn't support some directory operations like readdir because
of the limitations of semihosting mechanism.
if ARM_SEMIHOSTING_HOSTFS
config ARM_SEMIHOSTING_HOSTFS_CACHE_COHERENCE
bool "Cache coherence in semihosting hostfs"
depends on ARCH_DCACHE
---help---
Flush & Invalidte cache before & after bkpt instruction.
endif
if ARCH_ARMV6M
source "arch/arm/src/armv6-m/Kconfig"
endif

View File

@ -23,6 +23,7 @@
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/cache.h>
#include <nuttx/fs/hostfs.h>
#include <errno.h>
@ -49,8 +50,12 @@
* Private Functions
****************************************************************************/
static long host_call(unsigned int nbr, void *parm)
static long host_call(unsigned int nbr, void *parm, size_t size)
{
#ifdef CONFIG_ARM_SEMIHOSTING_HOSTFS_CACHE_COHERENCE
up_clean_dcache(parm, parm + size);
#endif
long ret = smh_call(nbr, parm);
if (ret < 0)
{
@ -66,7 +71,7 @@ static long host_call(unsigned int nbr, void *parm)
static ssize_t host_flen(long fd)
{
return host_call(HOST_FLEN, &fd);
return host_call(HOST_FLEN, &fd, sizeof(long));
}
static int host_flags_to_mode(int flags)
@ -118,13 +123,17 @@ int host_open(const char *pathname, int flags, int mode)
.len = strlen(pathname),
};
return host_call(HOST_OPEN, &open);
#ifdef CONFIG_ARM_SEMIHOSTING_HOSTFS_CACHE_COHERENCE
up_clean_dcache(pathname, pathname + open.len + 1);
#endif
return host_call(HOST_OPEN, &open, sizeof(open));
}
int host_close(int fd_)
{
long fd = fd_;
return host_call(HOST_CLOSE, &fd);
return host_call(HOST_CLOSE, &fd, sizeof(long));
}
ssize_t host_read(int fd, void *buf, size_t count)
@ -141,7 +150,14 @@ ssize_t host_read(int fd, void *buf, size_t count)
.count = count,
};
ssize_t ret = host_call(HOST_READ, &read);
ssize_t ret;
#ifdef CONFIG_ARM_SEMIHOSTING_HOSTFS_CACHE_COHERENCE
up_invalidate_dcache(buf, buf + count);
#endif
ret = host_call(HOST_READ, &read, sizeof(read));
return ret < 0 ? ret : count - ret;
}
@ -159,7 +175,13 @@ ssize_t host_write(int fd, const void *buf, size_t count)
.count = count,
};
ssize_t ret = host_call(HOST_WRITE, &write);
ssize_t ret;
#ifdef CONFIG_ARM_SEMIHOSTING_HOSTFS_CACHE_COHERENCE
up_clean_dcache(buf, buf + count);
#endif
ret = host_call(HOST_WRITE, &write, sizeof(write));
return ret < 0 ? ret : count - ret;
}
@ -189,7 +211,7 @@ off_t host_lseek(int fd, off_t offset, int whence)
.pos = offset,
};
ret = host_call(HOST_SEEK, &seek);
ret = host_call(HOST_SEEK, &seek, sizeof(seek));
if (ret >= 0)
{
ret = offset;
@ -267,7 +289,12 @@ int host_unlink(const char *pathname)
.pathname_len = strlen(pathname),
};
return host_call(HOST_REMOVE, &remove);
#ifdef CONFIG_ARM_SEMIHOSTING_HOSTFS_CACHE_COHERENCE
up_clean_dcache(pathname, pathname +
remove.pathname_len + 1);
#endif
return host_call(HOST_REMOVE, &remove, sizeof(remove));
}
int host_mkdir(const char *pathname, mode_t mode)
@ -296,7 +323,12 @@ int host_rename(const char *oldpath, const char *newpath)
.newpath_len = strlen(newpath),
};
return host_call(HOST_RENAME, &rename);
#ifdef CONFIG_ARM_SEMIHOSTING_HOSTFS_CACHE_COHERENCE
up_clean_dcache(oldpath, oldpath + rename.oldpath_len + 1);
up_clean_dcache(newpath, newpath + rename.newpath_len + 1);
#endif
return host_call(HOST_RENAME, &rename, sizeof(rename));
}
int host_stat(const char *path, struct stat *buf)

View File

@ -220,6 +220,16 @@ config XTENSA_EXTMEM_BSS
Adds a section and an attribute that allows to force variables into
the external memory.
if CONFIG_FS_HOSTFS
config XTENSA_HOSTFS_CACHE_COHERENCE
bool "Cache coherence in semihosting hostfs"
depends on ARCH_DCACHE
---help---
Flush & Invalidte cache before & after sim call.
endif
choice
prompt "Toolchain Selection"
default XTENSA_TOOLCHAIN_ESP

View File

@ -23,6 +23,7 @@
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/cache.h>
#include <nuttx/fs/hostfs.h>
#include <arch/simcall.h>
@ -96,6 +97,9 @@ int host_open(const char *pathname, int flags, int mode)
simcall_flags |= SIMCALL_O_EXCL;
}
#ifdef CONFIG_XTENSA_HOSTFS_CACHE_COHERENCE
up_clean_dcache(pathname, pathname + strlen(pathname) + 1);
#endif
return host_call(SIMCALL_SYS_OPEN, (int)pathname, simcall_flags, mode);
}
@ -106,11 +110,19 @@ int host_close(int fd)
ssize_t host_read(int fd, void *buf, size_t count)
{
#ifdef CONFIG_XTENSA_HOSTFS_CACHE_COHERENCE
up_invalidate_dcache(buf, buf + count);
#endif
return host_call(SIMCALL_SYS_READ, fd, (int)buf, count);
}
ssize_t host_write(int fd, const void *buf, size_t count)
{
#ifdef CONFIG_XTENSA_HOSTFS_CACHE_COHERENCE
up_clean_dcache(buf, buf + count);
#endif
return host_call(SIMCALL_SYS_WRITE, fd, (int)buf, count);
}