Alexander Shishkin | 9ea393d | 2018-03-28 18:43:57 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Alexander Shishkin | 7bd1d40 | 2015-09-22 15:47:10 +0300 | [diff] [blame] | 2 | /* |
| 3 | * System Trace Module (STM) infrastructure apis |
| 4 | * Copyright (C) 2014 Intel Corporation. |
Alexander Shishkin | 7bd1d40 | 2015-09-22 15:47:10 +0300 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef _STM_H_ |
| 8 | #define _STM_H_ |
| 9 | |
| 10 | #include <linux/device.h> |
| 11 | |
| 12 | /** |
| 13 | * enum stp_packet_type - STP packets that an STM driver sends |
| 14 | */ |
| 15 | enum stp_packet_type { |
| 16 | STP_PACKET_DATA = 0, |
| 17 | STP_PACKET_FLAG, |
| 18 | STP_PACKET_USER, |
| 19 | STP_PACKET_MERR, |
| 20 | STP_PACKET_GERR, |
| 21 | STP_PACKET_TRIG, |
| 22 | STP_PACKET_XSYNC, |
| 23 | }; |
| 24 | |
| 25 | /** |
| 26 | * enum stp_packet_flags - STP packet modifiers |
| 27 | */ |
| 28 | enum stp_packet_flags { |
| 29 | STP_PACKET_MARKED = 0x1, |
| 30 | STP_PACKET_TIMESTAMPED = 0x2, |
| 31 | }; |
| 32 | |
| 33 | struct stp_policy; |
| 34 | |
| 35 | struct stm_device; |
| 36 | |
| 37 | /** |
| 38 | * struct stm_data - STM device description and callbacks |
| 39 | * @name: device name |
| 40 | * @stm: internal structure, only used by stm class code |
| 41 | * @sw_start: first STP master available to software |
| 42 | * @sw_end: last STP master available to software |
| 43 | * @sw_nchannels: number of STP channels per master |
| 44 | * @sw_mmiosz: size of one channel's IO space, for mmap, optional |
Alexander Shishkin | 8e996a2 | 2016-05-03 11:33:37 -0600 | [diff] [blame] | 45 | * @hw_override: masters in the STP stream will not match the ones |
| 46 | * assigned by software, but are up to the STM hardware |
Alexander Shishkin | 7bd1d40 | 2015-09-22 15:47:10 +0300 | [diff] [blame] | 47 | * @packet: callback that sends an STP packet |
| 48 | * @mmio_addr: mmap callback, optional |
| 49 | * @link: called when a new stm_source gets linked to us, optional |
| 50 | * @unlink: likewise for unlinking, again optional |
| 51 | * @set_options: set device-specific options on a channel |
| 52 | * |
| 53 | * Fill out this structure before calling stm_register_device() to create |
| 54 | * an STM device and stm_unregister_device() to destroy it. It will also be |
| 55 | * passed back to @packet(), @mmio_addr(), @link(), @unlink() and @set_options() |
| 56 | * callbacks. |
| 57 | * |
| 58 | * Normally, an STM device will have a range of masters available to software |
| 59 | * and the rest being statically assigned to various hardware trace sources. |
| 60 | * The former is defined by the the range [@sw_start..@sw_end] of the device |
| 61 | * description. That is, the lowest master that can be allocated to software |
| 62 | * writers is @sw_start and data from this writer will appear is @sw_start |
| 63 | * master in the STP stream. |
Alexander Shishkin | f8560a9 | 2016-02-15 19:12:01 +0200 | [diff] [blame] | 64 | * |
| 65 | * The @packet callback should adhere to the following rules: |
| 66 | * 1) it must return the number of bytes it consumed from the payload; |
| 67 | * 2) therefore, if it sent a packet that does not have payload (like FLAG), |
| 68 | * it must return zero; |
| 69 | * 3) if it does not support the requested packet type/flag combination, |
| 70 | * it must return -ENOTSUPP. |
Alexander Shishkin | cc84240 | 2016-02-15 19:12:09 +0200 | [diff] [blame] | 71 | * |
| 72 | * The @unlink callback is called when there are no more active writers so |
| 73 | * that the master/channel can be quiesced. |
Alexander Shishkin | 7bd1d40 | 2015-09-22 15:47:10 +0300 | [diff] [blame] | 74 | */ |
| 75 | struct stm_data { |
| 76 | const char *name; |
| 77 | struct stm_device *stm; |
| 78 | unsigned int sw_start; |
| 79 | unsigned int sw_end; |
| 80 | unsigned int sw_nchannels; |
| 81 | unsigned int sw_mmiosz; |
Alexander Shishkin | 8e996a2 | 2016-05-03 11:33:37 -0600 | [diff] [blame] | 82 | unsigned int hw_override; |
Rama Aparna Mallavarapu | 969c012 | 2017-10-12 16:05:08 -0700 | [diff] [blame] | 83 | bool (*ost_configured)(void); |
Alexander Shishkin | 7bd1d40 | 2015-09-22 15:47:10 +0300 | [diff] [blame] | 84 | ssize_t (*packet)(struct stm_data *, unsigned int, |
| 85 | unsigned int, unsigned int, |
| 86 | unsigned int, unsigned int, |
| 87 | const unsigned char *); |
Rama Aparna Mallavarapu | 969c012 | 2017-10-12 16:05:08 -0700 | [diff] [blame] | 88 | ssize_t (*ost_packet)(struct stm_data *stm_data, |
| 89 | unsigned int size, |
| 90 | const unsigned char *buf); |
Alexander Shishkin | 7bd1d40 | 2015-09-22 15:47:10 +0300 | [diff] [blame] | 91 | phys_addr_t (*mmio_addr)(struct stm_data *, unsigned int, |
| 92 | unsigned int, unsigned int); |
| 93 | int (*link)(struct stm_data *, unsigned int, |
| 94 | unsigned int); |
| 95 | void (*unlink)(struct stm_data *, unsigned int, |
| 96 | unsigned int); |
| 97 | long (*set_options)(struct stm_data *, unsigned int, |
| 98 | unsigned int, unsigned int, |
| 99 | unsigned long); |
| 100 | }; |
| 101 | |
| 102 | int stm_register_device(struct device *parent, struct stm_data *stm_data, |
| 103 | struct module *owner); |
| 104 | void stm_unregister_device(struct stm_data *stm_data); |
| 105 | |
| 106 | struct stm_source_device; |
| 107 | |
| 108 | /** |
| 109 | * struct stm_source_data - STM source device description and callbacks |
| 110 | * @name: device name, will be used for policy lookup |
| 111 | * @src: internal structure, only used by stm class code |
| 112 | * @nr_chans: number of channels to allocate |
| 113 | * @link: called when this source gets linked to an STM device |
| 114 | * @unlink: called when this source is about to get unlinked from its STM |
| 115 | * |
| 116 | * Fill in this structure before calling stm_source_register_device() to |
| 117 | * register a source device. Also pass it to unregister and write calls. |
| 118 | */ |
| 119 | struct stm_source_data { |
| 120 | const char *name; |
| 121 | struct stm_source_device *src; |
| 122 | unsigned int percpu; |
| 123 | unsigned int nr_chans; |
| 124 | int (*link)(struct stm_source_data *data); |
| 125 | void (*unlink)(struct stm_source_data *data); |
| 126 | }; |
| 127 | |
| 128 | int stm_source_register_device(struct device *parent, |
| 129 | struct stm_source_data *data); |
| 130 | void stm_source_unregister_device(struct stm_source_data *data); |
| 131 | |
Chunyan Zhang | 9dfed80 | 2016-11-21 15:57:23 +0800 | [diff] [blame] | 132 | int notrace stm_source_write(struct stm_source_data *data, unsigned int chan, |
| 133 | const char *buf, size_t count); |
Alexander Shishkin | 7bd1d40 | 2015-09-22 15:47:10 +0300 | [diff] [blame] | 134 | |
| 135 | #endif /* _STM_H_ */ |