benchmark: change ts buffer allocation flow

1. Change timestamp buffer allocation/mapping flow
2. Add misc cosmetic fixes

In case if timestamp buffer is allocated in userspace and new register
user memory API is used for its registering in OP-TEE (introduced in
optee_client commit 27888d73d156 ("tee_client_api: register user memory")),
there is no possibility to keep this mapping permanent among different
TEEC_InvokeCommand invocations. All all SHM are automatically unmapped from
OP-TEE VA space after TEEC_InvokeCommand is handled by OP-TEE.

Fixes: https://github.com/OP-TEE/optee_os/issues/1979
Acked-by: Joakim Bech <joakim.bech@linaro.org>
Signed-off-by: Igor Opaniuk <igor.opaniuk@linaro.org>
diff --git a/benchmark_aux.c b/benchmark_aux.c
index 7995c18..222b179 100644
--- a/benchmark_aux.c
+++ b/benchmark_aux.c
@@ -24,12 +24,15 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  */
+#include <fcntl.h>
 #include <libgen.h>
 #include <linux/limits.h>
 #include <math.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
 #include <unistd.h>
 
 #include "benchmark_aux.h"
@@ -121,3 +124,28 @@
 {
 	return sysconf(_SC_NPROCESSORS_ONLN);
 }
+
+void *mmap_paddr(intptr_t paddr, uint64_t size)
+{
+	int devmem;
+	off_t offset = 0;
+	off_t page_addr;
+	intptr_t *hw_addr = (intptr_t *)paddr;
+
+	devmem = open("/dev/mem", O_RDWR);
+	if (!devmem)
+		return NULL;
+
+	offset = (off_t)hw_addr % getpagesize();
+	page_addr = (off_t)(hw_addr - offset);
+
+	hw_addr = (intptr_t *)mmap(0, size, PROT_READ|PROT_WRITE,
+					MAP_SHARED, devmem, page_addr);
+	if (hw_addr == MAP_FAILED) {
+		close(devmem);
+		return NULL;
+	}
+
+	close(devmem);
+	return (hw_addr + offset);
+}