coresight:add tmc device support

Signed-off-by: liaoao <liaoao@xiaomi.com>
This commit is contained in:
liaoao
2023-09-22 16:13:47 +08:00
committed by Xiang Xiao
parent 79af05c4ae
commit df33c392ae
9 changed files with 1616 additions and 1 deletions
+5
View File
@@ -41,6 +41,11 @@ if(CONFIG_CORESIGHT)
list(APPEND SRCS coresight_stm.c) list(APPEND SRCS coresight_stm.c)
endif() endif()
if(CONFIG_CORESIGHT_TMC)
list(APPEND SRCS coresight_tmc_core.c coresight_tmc_etf.c
coresight_tmc_etr.c)
endif()
if(CONFIG_CORESIGHT_TPIU) if(CONFIG_CORESIGHT_TPIU)
list(APPEND SRCS coresight_tpiu.c) list(APPEND SRCS coresight_tpiu.c)
endif() endif()
+4
View File
@@ -51,6 +51,10 @@ config CORESIGHT_STM
bool "STM coresight device support" bool "STM coresight device support"
default n default n
config CORESIGHT_TMC
bool "TMC coresight device support"
default n
config CORESIGHT_TPIU config CORESIGHT_TPIU
bool "TPIU coresight device support" bool "TPIU coresight device support"
default n default n
+4
View File
@@ -44,6 +44,10 @@ ifeq ($(CONFIG_CORESIGHT_STM),y)
CSRCS += coresight_stm.c CSRCS += coresight_stm.c
endif endif
ifeq ($(CONFIG_CORESIGHT_TMC),y)
CSRCS += coresight_tmc_core.c coresight_tmc_etf.c coresight_tmc_etr.c
endif
ifeq ($(CONFIG_CORESIGHT_TPIU),y) ifeq ($(CONFIG_CORESIGHT_TPIU),y)
CSRCS += coresight_tpiu.c CSRCS += coresight_tpiu.c
endif endif
+204
View File
@@ -0,0 +1,204 @@
/****************************************************************************
* drivers/coresight/coresight_tmc_core.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <errno.h>
#include <debug.h>
#include <nuttx/bits.h>
#include <nuttx/kmalloc.h>
#include <nuttx/coresight/coresight_tmc.h>
#include "coresight_common.h"
#include "coresight_tmc_core.h"
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: tmc_etf_get_memwidth
****************************************************************************/
static enum tmc_mem_intf_width_e tmc_etf_get_memwidth(uint32_t devid)
{
/* Indicate the minimum alignemnt for RRR/RURP/RWP/DBA etc registers. */
switch (BMVAL(devid, 8, 10))
{
case 0x2:
return TMC_MEM_INTF_WIDTH_32BITS;
case 0x3:
return TMC_MEM_INTF_WIDTH_64BITS;
case 0x4:
return TMC_MEM_INTF_WIDTH_128BITS;
case 0x5:
return TMC_MEM_INTF_WIDTH_256BITS;
default:
return 0;
}
}
/****************************************************************************
* Name: tmc_etr_get_memwidth
****************************************************************************/
static enum tmc_mem_intf_width_e tmc_etr_get_memwidth(uint32_t devid)
{
uint32_t val = (BMVAL(devid, 14, 15) << 3) | BMVAL(devid, 8, 10);
/* Indicate the minimum alignemnt for RRR/RURP/RWP/DBA etc registers. */
switch (val)
{
case 0x5:
return TMC_MEM_INTF_WIDTH_32BITS;
case 0x6:
return TMC_MEM_INTF_WIDTH_64BITS;
case 0x7:
return TMC_MEM_INTF_WIDTH_128BITS;
case 0x8:
return TMC_MEM_INTF_WIDTH_256BITS;
default:
return 0;
}
}
/****************************************************************************
* Name: tmc_init_arch_data
****************************************************************************/
static void tmc_init_arch_data(FAR struct coresight_tmc_dev_s *tmcdev,
FAR const struct coresight_desc_s *desc)
{
uint32_t devid;
coresight_unlock(desc->addr);
devid = coresight_get32(desc->addr + CORESIGHT_DEVID);
tmcdev->config_type = BMVAL(devid, 6, 7);
if (tmcdev->config_type == TMC_CONFIG_TYPE_ETR)
{
tmcdev->size = desc->buffer_size;
tmcdev->burst_size = desc->burst_size;
tmcdev->mmwidth = tmc_etr_get_memwidth(devid);
}
else
{
tmcdev->size = coresight_get32(desc->addr + TMC_RSZ) * 4;
tmcdev->mmwidth = tmc_etf_get_memwidth(devid);
}
coresight_lock(desc->addr);
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: tmc_register
*
* Description:
* Register a TMC devices.
*
* Input Parameters:
* desc - A description of this coresight device.
*
* Returned Value:
* Pointer to a TMC device on success; NULL on failure.
*
****************************************************************************/
FAR struct coresight_tmc_dev_s *
tmc_register(FAR const struct coresight_desc_s *desc)
{
FAR struct coresight_tmc_dev_s *tmcdev;
int ret = -EINVAL;
tmcdev = kmm_zalloc(sizeof(struct coresight_tmc_dev_s));
if (tmcdev == NULL)
{
cserr("%s:malloc failed!\n", desc->name);
return NULL;
}
tmc_init_arch_data(tmcdev, desc);
switch (tmcdev->config_type)
{
case TMC_CONFIG_TYPE_ETB:
case TMC_CONFIG_TYPE_ETF:
ret = tmc_etf_register(tmcdev, desc);
break;
case TMC_CONFIG_TYPE_ETR:
ret = tmc_etr_register(tmcdev, desc);
break;
default:
cserr("config type error\n");
break;
}
if (ret < 0)
{
kmm_free(tmcdev);
return NULL;
}
nxmutex_init(&tmcdev->lock);
return tmcdev;
}
/****************************************************************************
* Name: tmc_unregister
*
* Description:
* Unregister a TMC devices.
*
* Input Parameters:
* tmcdev - Pointer to the TMC device.
*
****************************************************************************/
void tmc_unregister(FAR struct coresight_tmc_dev_s *tmcdev)
{
switch (tmcdev->config_type)
{
case TMC_CONFIG_TYPE_ETB:
case TMC_CONFIG_TYPE_ETF:
tmc_etf_unregister(tmcdev);
break;
case TMC_CONFIG_TYPE_ETR:
tmc_etr_unregister(tmcdev);
break;
default:
cserr("wrong config type\n");
break;
}
nxmutex_destroy(&tmcdev->lock);
kmm_free(tmcdev);
}
+189
View File
@@ -0,0 +1,189 @@
/****************************************************************************
* drivers/coresight/coresight_tmc_core.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __DRIVERS_CORESIGHT_CORESIGHT_TMC_CORE_H
#define __DRIVERS_CORESIGHT_CORESIGHT_TMC_CORE_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/bits.h>
#include <nuttx/coresight/coresight_tmc.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define TMC_RSZ 0x004
#define TMC_STS 0x00c
#define TMC_RRD 0x010
#define TMC_RRP 0x014
#define TMC_RWP 0x018
#define TMC_TRG 0x01c
#define TMC_CTL 0x020
#define TMC_RWD 0x024
#define TMC_MODE 0x028
#define TMC_LBUFLEVEL 0x02c
#define TMC_CBUFLEVEL 0x030
#define TMC_BUFWM 0x034
#define TMC_RRPHI 0x038
#define TMC_RWPHI 0x03c
#define TMC_AXICTL 0x110
#define TMC_DBALO 0x118
#define TMC_DBAHI 0x11c
#define TMC_FFSR 0x300
#define TMC_FFCR 0x304
#define TMC_PSCR 0x308
#define TMC_ITMISCOP0 0xee0
#define TMC_ITTRFLIN 0xee8
#define TMC_ITATBDATA0 0xeec
#define TMC_ITATBCTR2 0xef0
#define TMC_ITATBCTR1 0xef4
#define TMC_ITATBCTR0 0xef8
#define TMC_AUTHSTATUS 0xfb8
/* TMC_AUTHSTATUS - 0xfb8 */
#define TMC_AUTH_NSID_MASK GENMASK(1, 0)
#define TMC_NSID_EN 0x03
/* TMC_CTL - 0x020 */
#define TMC_CTL_CAPT_EN BIT(0)
/* TMC_STS - 0x00C */
#define TMC_STS_FULL BIT(0)
#define TMC_STS_TRIGGERED BIT(1)
#define TMC_STS_TMCREADY BIT(2)
#define TMC_STS_MEMERR BIT(5)
/* TMC_AXICTL - 0x110
*
* TMC AXICTL format for SoC-400
* Bits [0-1] : ProtCtrlBit0-1
* Bits [2-5] : CacheCtrlBits 0-3 (AXCACHE)
* Bit 6 : Reserved
* Bit 7 : ScatterGatherMode
* Bits [8-11] : WrBurstLen
* Bits [12-31] : Reserved.
* TMC AXICTL format for SoC-600, as above except:
* Bits [2-5 : AXI WCACHE
* Bits [16-19] : AXI RCACHE
* Bits [20-31] : Reserved
*/
#define TMC_AXICTL_CLEAR_MASK 0xfbf
#define TMC_AXICTL_ARCACHE_MASK (0xf << 16)
#define TMC_AXICTL_PROT_CTL_B0 BIT(0)
#define TMC_AXICTL_PROT_CTL_B1 BIT(1)
#define TMC_AXICTL_SCT_GAT_MODE BIT(7)
#define TMC_AXICTL_WR_BURST(v) (((v) & 0xf) << 8)
#define TMC_AXICTL_WR_BURST_16 0xf
/* Write-back Read and Write-allocate */
#define TMC_AXICTL_AXCACHE_OS (0xf << 2)
#define TMC_AXICTL_ARCACHE_OS (0xf << 16)
/* TMC_FFCR - 0x304 */
#define TMC_FFCR_EN_FMT BIT(0)
#define TMC_FFCR_EN_TI BIT(1)
#define TMC_FFCR_FON_FLIN BIT(4)
#define TMC_FFCR_FON_TRIG_EVT BIT(5)
#define TMC_FFCR_FON_MAN BIT(6)
#define TMC_FFCR_TRIGON_TRIGIN BIT(8)
#define TMC_FFCR_STOP_ON_FLUSH BIT(12)
#define TMC_DEVID_AXIAW_VALID BIT(16)
#define TMC_DEVID_NOSCAT BIT(24)
#define TMC_DEVID_AXIAW_SHIFT 17
#define TMC_DEVID_AXIAW_MASK 0x7f
/* TMC ETR Capability bit definitions. These need to be set by software. */
#define TMC_ETR_SG (0x1U << 0)
/* ETR has separate read/write cache encodings. */
#define TMC_ETR_AXI_ARCACHE (0x1U << 1)
/* TMC_ETR_SAVE_RESTORE - Values of RRP/RWP/STS.Full are
* retained when TMC leaves Disabled state, allowing us to continue
* the tracing from a point where we stopped. This also implies that
* the RRP/RWP/STS.Full should always be programmed to the correct
* value. Unfortunately this is not advertised by the hardware,
* so we have to rely on PID of the IP to detect the functionality.
*/
#define TMC_ETR_SAVE_RESTORE (0x1U << 2)
/* Coresight SoC-600 TMC-ETR unadvertised capabilities */
#define TMC_600_ETR_CAPS \
(TMC_ETR_SAVE_RESTORE | TMC_ETR_AXI_ARCACHE)
#define TMC_MAX_NAME_LEN 32
/****************************************************************************
* Public Types
****************************************************************************/
enum tmc_mode_e
{
TMC_MODE_CIRCULAR_BUFFER,
TMC_MODE_SOFTWARE_FIFO,
TMC_MODE_HARDWARE_FIFO,
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: tmc_etf_register
****************************************************************************/
int tmc_etf_register(FAR struct coresight_tmc_dev_s *tmcdev,
FAR const struct coresight_desc_s *desc);
/****************************************************************************
* Name: tmc_etr_register
****************************************************************************/
int tmc_etr_register(FAR struct coresight_tmc_dev_s *tmcdev,
FAR const struct coresight_desc_s *desc);
/****************************************************************************
* Name: tmc_etf_unregister
****************************************************************************/
void tmc_etf_unregister(FAR struct coresight_tmc_dev_s * tmcdev);
/****************************************************************************
* Name: tmc_etr_unregister
****************************************************************************/
void tmc_etr_unregister(FAR struct coresight_tmc_dev_s * tmcdev);
#endif //__DRIVERS_CORESIGHT_CORESIGHT_TMC_CORE_H
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+9 -1
View File
@@ -54,13 +54,16 @@ enum coresight_dev_subtype_link_e
{ {
CORESIGHT_DEV_SUBTYPE_LINK_MERG, /* Funnel */ CORESIGHT_DEV_SUBTYPE_LINK_MERG, /* Funnel */
CORESIGHT_DEV_SUBTYPE_LINK_SPLIT, /* Replocator */ CORESIGHT_DEV_SUBTYPE_LINK_SPLIT, /* Replocator */
CORESIGHT_DEV_SUBTYPE_LINK_FIFO, /* TMC ETR */ CORESIGHT_DEV_SUBTYPE_LINK_FIFO, /* TMC ETF */
}; };
enum coresight_dev_subtype_sink_e enum coresight_dev_subtype_sink_e
{ {
CORESIGHT_DEV_SUBTYPE_SINK_PORT, /* TPIU */ CORESIGHT_DEV_SUBTYPE_SINK_PORT, /* TPIU */
CORESIGHT_DEV_SUBTYPE_SINK_BUFFER, /* ETB */ CORESIGHT_DEV_SUBTYPE_SINK_BUFFER, /* ETB */
CORESIGHT_DEV_SUBTYPE_SINK_TMC_BUFFER, /* TMC ETB */
CORESIGHT_DEV_SUBTYPE_SINK_TMC_SYSMEM, /* TMC ETR */
CORESIGHT_DEV_SUBTYPE_SINK_TMC_ETF, /* TMC ETF */
}; };
/* This structure is used to unify different subtype of devices. */ /* This structure is used to unify different subtype of devices. */
@@ -137,6 +140,11 @@ struct coresight_desc_s
uintptr_t stimulus_port_addr; uintptr_t stimulus_port_addr;
/* Used in TMC-ETR device. */
uint32_t buffer_size;
uint32_t burst_size;
/* Description of outports of current device. */ /* Description of outports of current device. */
int outport_num; int outport_num;
+109
View File
@@ -0,0 +1,109 @@
/****************************************************************************
* include/nuttx/coresight/coresight_tmc.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __INCLUDE_NUTTX_CORESIGHT_CORESIGHT_TMC_H
#define __INCLUDE_NUTTX_CORESIGHT_CORESIGHT_TMC_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/mutex.h>
#include <nuttx/coresight/coresight.h>
/****************************************************************************
* Public Types
****************************************************************************/
enum tmc_config_type_e
{
TMC_CONFIG_TYPE_ETB,
TMC_CONFIG_TYPE_ETR,
TMC_CONFIG_TYPE_ETF,
};
enum tmc_mem_intf_width_e
{
TMC_MEM_INTF_WIDTH_32BITS = 1,
TMC_MEM_INTF_WIDTH_64BITS = 2,
TMC_MEM_INTF_WIDTH_128BITS = 4,
TMC_MEM_INTF_WIDTH_256BITS = 8,
};
enum tmc_etr_mode_e
{
TMC_ETR_MODE_FLAT, /* Uses contiguous flat buffer. */
TMC_ETR_MODE_ETR_SG, /* Uses in-built TMC ETR SG mechanism. */
TMC_ETR_MODE_CATU, /* Use SG mechanism in CATU. */
};
struct coresight_tmc_dev_s
{
struct coresight_dev_s csdev;
enum tmc_config_type_e config_type; /* Device type: ETB/ETR/ETF. */
enum tmc_mem_intf_width_e mmwidth; /* Width of the memory interface databus, in bytes. */
uint32_t trigger_cntr; /* Amount of words to store after a trigger. */
uint32_t size; /* RAM buffer size. */
uint32_t burst_size; /* Max burst size used in ETR devices. */
FAR uint32_t *buf; /* Pointer to the RAM buf. */
uint32_t len; /* Valid data len in RAM buffer. */
mutex_t lock; /* Mutex for driver's open/close. */
uint32_t caps; /* Capalilities current etr device has. */
enum tmc_etr_mode_e mode; /* ETR buffer mode. */
uint32_t offset; /* Data offset in ETR buffer. */
uint8_t refcnt; /* TMC coresight device's enable count */
uint8_t opencnt; /* TMC device's open count. */
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: tmc_register
*
* Description:
* Register a TMC devices.
*
* Input Parameters:
* desc - A description of this coresight device.
*
* Returned Value:
* Pointer to a TMC device on success; NULL on failure.
*
****************************************************************************/
FAR struct coresight_tmc_dev_s *
tmc_register(FAR const struct coresight_desc_s *desc);
/****************************************************************************
* Name: tmc_unregister
*
* Description:
* Unregister a TMC devices.
*
* Input Parameters:
* tmcdev - Pointer to the TMC device.
*
****************************************************************************/
void tmc_unregister(FAR struct coresight_tmc_dev_s *tmcdev);
#endif //__INCLUDE_NUTTX_CORESIGHT_CORESIGHT_TMC_H