aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChunyan Zhang <zhang.chunyan@linaro.org>2016-07-15 15:54:51 +0800
committerChunyan Zhang <zhang.chunyan@linaro.org>2016-07-15 15:54:51 +0800
commit4b26b529017da424efc1d62eade1230583dd1808 (patch)
tree27a65a621d47444a08d5dbea05b769a7aafea81e
parent67032699247b3fca6e868e44dfcac715125a06fe (diff)
downloadsample-app-4b26b529017da424efc1d62eade1230583dd1808.tar.gz
stm_user_api: changed to support Juno-r0
The channels 0~15 on Juno-r0 seem not permitted to be writen, this patch also change the start channel of mmap from 0 to 32768. The STM channel management policy will allocate the channels automatically from all unused channels. So if we want to mmap from a non-zero channel, we have to config the channel range manually, like below: / # mkdir /config/stp-policy/20100000.stm.abc / # mkdir /config/stp-policy/20100000.stm.abc/test / # echo 32768 65535 > config/stp-policy/20100000.stm.abc/test/channels Here '32768' is just the channel number from which we want to mmap STM stimulus space; 'test' is the policy name which we will use to mmap channel area. Signed-off-by: Chunyan Zhang <zhang.chunyan@linaro.org>
-rw-r--r--mmap-wrapper/example.c8
-rw-r--r--mmap-wrapper/stm_user_api.c24
-rw-r--r--mmap-wrapper/stm_user_api.h13
3 files changed, 33 insertions, 12 deletions
diff --git a/mmap-wrapper/example.c b/mmap-wrapper/example.c
index c44ede0..8e85d8e 100644
--- a/mmap-wrapper/example.c
+++ b/mmap-wrapper/example.c
@@ -15,7 +15,7 @@ extern struct stm_dev g_stm_dev;
void main()
{
int i;
- unsigned int chan_start = 0;
+ unsigned int chan_start = 32768;
unsigned width = PAGE_SIZE / BYTES_PER_CHANNEL;
unsigned int flags = STM_FLAG_TIMESTAMPED;
unsigned int dsize;
@@ -29,11 +29,15 @@ void main()
/*
* You can use any channel between [g_stm_dev.policy->channel ...
- * (g_stm_dev.policy->channel + g_stm_dev.policy->width)]
+ * (g_stm_dev.policy->channel + g_stm_dev.policy->width)]
+ * and width must <= (PAGE_SIZE / BYTES_PER_CHANNEL)
+ * http://lxr.free-electrons.com/source/drivers/hwtracing/stm/core.c?v=4.6#L542
*/
real_wrbytes = stm_trace_data(&g_stm_dev, chan_start, flags, wrbytes, trace_data);
if (real_wrbytes != wrbytes)
printf("write %d bytes and left % bytes data\n", real_wrbytes, wrbytes - real_wrbytes);
+
+ printf("Success to write %d bytes\n", real_wrbytes);
release_stm_resource(&g_stm_dev);
}
diff --git a/mmap-wrapper/stm_user_api.c b/mmap-wrapper/stm_user_api.c
index 878f3a0..296d5eb 100644
--- a/mmap-wrapper/stm_user_api.c
+++ b/mmap-wrapper/stm_user_api.c
@@ -10,11 +10,21 @@
#include <unistd.h>
#include "stm_user_api.h"
-static void enable_sink(const char *dev_name)
+void release_stm_resource(struct stm_dev *dev);
+
+static void enable_sink(const char *dev_name, unsigned int enable)
{
char buf[256] = {0};
- sprintf(buf, "echo 1 > /sys/bus/coresight/devices/%s/enable_sink",
- dev_name);
+ sprintf(buf, "echo %u > /sys/bus/coresight/devices/%s/enable_sink",
+ enable, dev_name);
+ system(buf);
+}
+
+static void enable_source(const char *dev_name, unsigned int enable)
+{
+ char buf[256] = {0};
+ sprintf(buf, "echo %u > /sys/bus/coresight/devices/%s/enable_source",
+ enable, dev_name);
system(buf);
}
@@ -57,7 +67,7 @@ int request_stm_resource(struct stm_dev *dev, unsigned int chan,
char *map;
struct stp_policy_id *policy;
unsigned int length = STM_MAP_SIZE;
- unsigned long offset = STM_MAP_OFFSET;
+ unsigned long offset = 0;
if ((fd = open(STM_DEVICE_NAME, O_RDWR | O_SYNC)) == -1) {
printf("Failed to open %s %s\n", STM_DEVICE_NAME,
@@ -70,7 +80,8 @@ int request_stm_resource(struct stm_dev *dev, unsigned int chan,
* Before allocating a policy for STM, the sink connected with STM must
* be enabled.
*/
- enable_sink(TMC_SYS_NAME);
+ enable_sink(ETF_SYS_NAME, 1);
+ enable_sink(ETR_SYS_NAME, 1);
/* set a master/channel policy for this STM device, this
* is because that kernel have to know how many channels
@@ -129,6 +140,8 @@ void release_stm_resource(struct stm_dev *dev)
close(dev->fd);
dev->fd = 0;
}
+
+ enable_source(STM_SYS_NAME, 0);
}
static char *stm_channel_addr(struct stm_dev *dev, unsigned int chan,
@@ -190,6 +203,7 @@ static unsigned int stm_write(char *addr, void *data, unsigned int size)
size = wrbytes;
memcpy(addr, (char *)data, size);
+ printf("memcpy %u bytes data to the address %p\n", size ,addr);
return size;
}
diff --git a/mmap-wrapper/stm_user_api.h b/mmap-wrapper/stm_user_api.h
index 47973b4..d13428d 100644
--- a/mmap-wrapper/stm_user_api.h
+++ b/mmap-wrapper/stm_user_api.h
@@ -2,12 +2,15 @@
#define __STM_USER_API_H
#define BYTES_PER_CHANNEL 256
-#define PAGE_SIZE sysconf(_SC_PAGE_SIZE)
-#define STM_MAP_OFFSET 0x0
+#define PAGE_SIZE sysconf(_SC_PAGE_SIZE) //4096
+#define MAP_MASK (PAGE_SIZE - 1)
#define STM_MAP_SIZE PAGE_SIZE
-#define STM_DEVICE_NAME "/dev/10006000.stm"
-#define TMC_SYS_NAME "10003000.etf"
-#define STM_SYS_NAME "10006000.stm"
+
+#define STM_DEVICE_NAME "/dev/20100000.stm"
+#define ETF_SYS_NAME "20010000.etf"
+#define ETR_SYS_NAME "20070000.etr"
+#define STM_SYS_NAME "20100000.stm"
+
#define STP_POLICY_NAME "test"
#define TEST_DATA_SIZE 4
#define POLICY_NAME_LEN 8