From cd04a5f1aadc8e2ec4e787f5ba4cc8c38a579314 Mon Sep 17 00:00:00 2001 From: Marcin Bukat Date: Tue, 18 Nov 2014 23:27:26 +0100 Subject: hwstub/qeditor: add support for atomic read/writes The current code assumed that READ/WRITE would produce atomic read/writes for 8/16/32-bit words, which in turned put assumption on the memcpy function. Since some memcpy implementation do not always guarantee such strong assumption, introduce two new operation READ/WRITE_ATOMIC which provide the necessary tools to do correct read and write to register in a single memory access. Change-Id: I37451bd5057bb0dcaf5a800d8aef8791c792a090 --- utils/hwstub/tools/hwstub_shell.cpp | 12 ++++++------ utils/hwstub/tools/init.lua | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'utils/hwstub/tools') diff --git a/utils/hwstub/tools/hwstub_shell.cpp b/utils/hwstub/tools/hwstub_shell.cpp index b2838ebed0..30d1ac3b3f 100644 --- a/utils/hwstub/tools/hwstub_shell.cpp +++ b/utils/hwstub/tools/hwstub_shell.cpp @@ -144,7 +144,7 @@ typedef void (*hw_writen_fn_t)(lua_State *state, soc_addr_t addr, soc_word_t val soc_word_t hw_read8(lua_State *state, soc_addr_t addr) { uint8_t u; - if(hwstub_rw_mem(g_hwdev, 1, addr, &u, sizeof(u)) != sizeof(u)) + if(hwstub_rw_mem_atomic(g_hwdev, 1, addr, &u, sizeof(u)) != sizeof(u)) luaL_error(state, "fail to read8 @ %p", addr); return u; } @@ -152,7 +152,7 @@ soc_word_t hw_read8(lua_State *state, soc_addr_t addr) soc_word_t hw_read16(lua_State *state, soc_addr_t addr) { uint16_t u; - if(hwstub_rw_mem(g_hwdev, 1, addr, &u, sizeof(u)) != sizeof(u)) + if(hwstub_rw_mem_atomic(g_hwdev, 1, addr, &u, sizeof(u)) != sizeof(u)) luaL_error(state, "fail to read16 @ %p", addr); return u; } @@ -160,7 +160,7 @@ soc_word_t hw_read16(lua_State *state, soc_addr_t addr) soc_word_t hw_read32(lua_State *state, soc_addr_t addr) { uint32_t u; - if(hwstub_rw_mem(g_hwdev, 1, addr, &u, sizeof(u)) != sizeof(u)) + if(hwstub_rw_mem_atomic(g_hwdev, 1, addr, &u, sizeof(u)) != sizeof(u)) luaL_error(state, "fail to read32 @ %p", addr); return u; } @@ -168,21 +168,21 @@ soc_word_t hw_read32(lua_State *state, soc_addr_t addr) void hw_write8(lua_State *state, soc_addr_t addr, soc_word_t val) { uint8_t u = val; - if(hwstub_rw_mem(g_hwdev, 0, addr, &u, sizeof(u)) != sizeof(u)) + if(hwstub_rw_mem_atomic(g_hwdev, 0, addr, &u, sizeof(u)) != sizeof(u)) luaL_error(state, "fail to write8 @ %p", addr); } void hw_write16(lua_State *state, soc_addr_t addr, soc_word_t val) { uint16_t u = val; - if(hwstub_rw_mem(g_hwdev, 0, addr, &u, sizeof(u)) != sizeof(u)) + if(hwstub_rw_mem_atomic(g_hwdev, 0, addr, &u, sizeof(u)) != sizeof(u)) luaL_error(state, "fail to write16 @ %p", addr); } void hw_write32(lua_State *state, soc_addr_t addr, soc_word_t val) { uint32_t u = val; - if(hwstub_rw_mem(g_hwdev, 0, addr, &u, sizeof(u)) != sizeof(u)) + if(hwstub_rw_mem_atomic(g_hwdev, 0, addr, &u, sizeof(u)) != sizeof(u)) luaL_error(state, "fail to write32 @ %p", addr); } diff --git a/utils/hwstub/tools/init.lua b/utils/hwstub/tools/init.lua index 1fe0e0d734..aaca8b6c82 100644 --- a/utils/hwstub/tools/init.lua +++ b/utils/hwstub/tools/init.lua @@ -38,8 +38,8 @@ do h = HELP:create_topic("DEV"); h:add("This variable redirects to hwstub.dev and provides direct access to the device."); h:add("It contains some information about the device and the following methods."); - h:add("* read8/16/32(a) reads a 8/16/32-bit integer at address a"); - h:add("* write8/16/32(a, v) writes the 8/16/32-bit integer v at address a"); + h:add("* read8/16/32(a) reads a 8/16/32-bit integer at address a atomically"); + h:add("* write8/16/32(a, v) writes the 8/16/32-bit integer v at address a atomically"); h:add("* print_log() prints the device log"); h = HELP:create_topic("HW"); -- cgit v1.2.3