STRUCT STM_DATA(9)
π NAME π
hiii bestie, welcome to the Kernel API Manual π β this page is literally all about struct stm_data, aka the STM device description and callbacks. Yeah, both. It's giving dual-threat main character energy β¨
πΈ SYNOPSIS πΈ
okay so here's the whole struct, no cap, every single field:
struct stm_data {
const char *name;
struct stm_device *stm;
unsigned int sw_start;
unsigned int sw_end;
unsigned int sw_nchannels;
unsigned int sw_mmiosz;
unsigned int hw_override;
ssize_t (*packet)(struct stm_data *, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, const unsigned char *);
phys_addr_t (*mmio_addr)(struct stm_data *, unsigned int, unsigned int, unsigned int);
int (*link)(struct stm_data *, unsigned int, unsigned int);
void (*unlink)(struct stm_data *, unsigned int, unsigned int);
long (*set_options)(struct stm_data *, unsigned int, unsigned int, unsigned int, unsigned long);
};
π¦ Members π¦
okay so let's go field by field, i'm obsessed with how tidy this is π«Ά
nameβ the device name π·οΈstmβ the internal structure, and it's only used by stm class code β so like, don't touch it, that's not your lane πsw_startβ the first STP master available to softwaresw_endβ the last STP master available to softwaresw_nchannelsβ number of STP channels per mastersw_mmioszβ size of one channel's IO space, formmap, and it's optional πhw_overrideβ when this is set, the masters in the STP stream will not match the ones assigned by software β nope, they're up to the STM hardware π³packetβ callback that sends an STP packetmmio_addrβ themmapcallback, optionallinkβ called when a newstm_sourcegets linked to us, optionalunlinkβ likewise for unlinking, again optionalset_optionsβ set device-specific options on a channel
π Description π
so here's the vibe: you fill out this structure before calling stm_register_device to create an STM device, and stm_unregister_device to destroy it π. And lowkey it also gets passed back to the packet, mmio_addr, link, unlink and set_options callbacks. so it's like, everywhere. iconic.
Normally an STM device will have a range of masters available to software, and the rest are statically assigned to various hardware trace sources β¨. That former bit is defined by the range [sw_start..sw_end] of the device description. So like β the lowest master that can be allocated to software writers is sw_start, and data from this writer will appear in the sw_start master in the STP stream π
The packet callback should adhere to the following rules, fr fr, no vibing your way around these:
- it must return the number of bytes it consumed from the payload
- therefore, if it sent a packet that does not have payload (like
FLAG), it must return zero - if it does not support the requested packet type/flag combination, it must return
-ENOTSUPP
β οΈ bestie please internalise rule 3, -ENOTSUPP is the whole point β don't just return whatever π
The unlink callback is called when there are no more active writers, so that the master/channel can be quiesced π
β SEE ALSO β
Kernel file ./include/linux/stm.h β and while you're there, go say hi to enum stp_packet_type(9), enum stp_packet_flags(9), enum stm_source_type(9), and struct stm_source_data(9) π¦
and that's the page!! π this came out of ./include/linux, dated October 2026, from the Kernel API Manual β slay, go build something iconic, mwah πβ¨
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms