drivers/hwtracing/coresight/coresight-tmc-etr.c
Source file repositories/reference/linux-study-clean/drivers/hwtracing/coresight/coresight-tmc-etr.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwtracing/coresight/coresight-tmc-etr.c- Extension
.c- Size
- 58014 bytes
- Lines
- 2087
- Domain
- Driver Families
- Bucket
- drivers/hwtracing
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/atomic.hlinux/coresight.hlinux/dma-mapping.hlinux/iommu.hlinux/idr.hlinux/mutex.hlinux/refcount.hlinux/slab.hlinux/types.hlinux/vmalloc.hcoresight-catu.hcoresight-etm-perf.hcoresight-priv.hcoresight-tmc.h
Detected Declarations
struct etr_flat_bufstruct etr_buf_hwstruct etr_perf_bufferstruct etr_sg_tablefunction mapfunction tmc_pages_get_offsetfunction tmc_pages_allocfunction tmc_pages_allocfunction tmc_sg_get_data_page_offsetfunction tmc_free_table_pagesfunction tmc_free_data_pagesfunction tmc_free_sg_tablefunction devicefunction tmc_alloc_data_pagesfunction tmc_sg_table_sync_data_rangefunction tmc_sg_table_sync_tablefunction tmc_sg_table_get_datafunction tmc_sg_daddr_to_vaddrfunction tmc_etr_sg_table_dumpfunction tmc_etr_sg_table_dumpfunction tmc_init_etr_sg_tablefunction tmc_etr_alloc_flat_buffunction tmc_etr_free_flat_buffunction tmc_etr_sync_flat_buffunction tmc_etr_get_data_flat_buffunction tmc_etr_alloc_resrv_buffunction tmc_etr_free_resrv_buffunction tmc_etr_sync_resrv_buffunction tmc_etr_alloc_sg_buffunction tmc_etr_free_sg_buffunction tmc_etr_get_data_sg_buffunction tmc_etr_sync_sg_buffunction tmc_etr_get_catu_devicefunction tmc_etr_set_catu_opsfunction tmc_etr_remove_catu_opsfunction tmc_etr_mode_alloc_buffunction get_etr_buf_hwfunction etr_can_use_flat_modefunction tmc_free_etr_buffunction tmc_etr_buf_get_datafunction tmc_etr_buf_insert_barrier_packetfunction tmc_sync_etr_buffunction __tmc_etr_enable_hwfunction properlyfunction tmc_etr_enable_hwfunction bufferfunction tmc_etr_setup_sysfs_buffunction tmc_etr_free_sysfs_buf
Annotated Snippet
struct etr_flat_buf {
struct device *dev;
dma_addr_t daddr;
void *vaddr;
size_t size;
};
struct etr_buf_hw {
bool has_iommu;
bool has_etr_sg;
bool has_catu;
bool has_resrv;
};
/*
* etr_perf_buffer - Perf buffer used for ETR
* @drvdata - The ETR drvdaga this buffer has been allocated for.
* @etr_buf - Actual buffer used by the ETR
* @pid - The PID of the session owner that etr_perf_buffer
* belongs to.
* @snaphost - Perf session mode
* @nr_pages - Number of pages in the ring buffer.
* @pages - Array of Pages in the ring buffer.
*/
struct etr_perf_buffer {
struct tmc_drvdata *drvdata;
struct etr_buf *etr_buf;
pid_t pid;
bool snapshot;
int nr_pages;
void **pages;
};
/* Convert the perf index to an offset within the ETR buffer */
#define PERF_IDX2OFF(idx, buf) \
((idx) % ((unsigned long)(buf)->nr_pages << PAGE_SHIFT))
/* Lower limit for ETR hardware buffer */
#define TMC_ETR_PERF_MIN_BUF_SIZE SZ_1M
/*
* The TMC ETR SG has a page size of 4K. The SG table contains pointers
* to 4KB buffers. However, the OS may use a PAGE_SIZE different from
* 4K (i.e, 16KB or 64KB). This implies that a single OS page could
* contain more than one SG buffer and tables.
*
* A table entry has the following format:
*
* ---Bit31------------Bit4-------Bit1-----Bit0--
* | Address[39:12] | SBZ | Entry Type |
* ----------------------------------------------
*
* Address: Bits [39:12] of a physical page address. Bits [11:0] are
* always zero.
*
* Entry type:
* b00 - Reserved.
* b01 - Last entry in the tables, points to 4K page buffer.
* b10 - Normal entry, points to 4K page buffer.
* b11 - Link. The address points to the base of next table.
*/
typedef u32 sgte_t;
#define ETR_SG_PAGE_SHIFT 12
#define ETR_SG_PAGE_SIZE (1UL << ETR_SG_PAGE_SHIFT)
#define ETR_SG_PAGES_PER_SYSPAGE (PAGE_SIZE / ETR_SG_PAGE_SIZE)
#define ETR_SG_PTRS_PER_PAGE (ETR_SG_PAGE_SIZE / sizeof(sgte_t))
#define ETR_SG_PTRS_PER_SYSPAGE (PAGE_SIZE / sizeof(sgte_t))
#define ETR_SG_ET_MASK 0x3
#define ETR_SG_ET_LAST 0x1
#define ETR_SG_ET_NORMAL 0x2
#define ETR_SG_ET_LINK 0x3
#define ETR_SG_ADDR_SHIFT 4
#define ETR_SG_ENTRY(addr, type) \
(sgte_t)((((addr) >> ETR_SG_PAGE_SHIFT) << ETR_SG_ADDR_SHIFT) | \
(type & ETR_SG_ET_MASK))
#define ETR_SG_ADDR(entry) \
(((dma_addr_t)(entry) >> ETR_SG_ADDR_SHIFT) << ETR_SG_PAGE_SHIFT)
#define ETR_SG_ET(entry) ((entry) & ETR_SG_ET_MASK)
/*
* struct etr_sg_table : ETR SG Table
* @sg_table: Generic SG Table holding the data/table pages.
* @hwaddr: hwaddress used by the TMC, which is the base
* address of the table.
Annotation
- Immediate include surface: `linux/atomic.h`, `linux/coresight.h`, `linux/dma-mapping.h`, `linux/iommu.h`, `linux/idr.h`, `linux/mutex.h`, `linux/refcount.h`, `linux/slab.h`.
- Detected declarations: `struct etr_flat_buf`, `struct etr_buf_hw`, `struct etr_perf_buffer`, `struct etr_sg_table`, `function map`, `function tmc_pages_get_offset`, `function tmc_pages_alloc`, `function tmc_pages_alloc`, `function tmc_sg_get_data_page_offset`, `function tmc_free_table_pages`.
- Atlas domain: Driver Families / drivers/hwtracing.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.