1ad0dfdfdSMathieu Poirier /* SPDX-License-Identifier: GPL-2.0 */ 2ad0dfdfdSMathieu Poirier /* 3ad0dfdfdSMathieu Poirier * Copyright (c) 2012, The Linux Foundation. All rights reserved. 4a06ae860SPratik Patel */ 5a06ae860SPratik Patel 6a06ae860SPratik Patel #ifndef _LINUX_CORESIGHT_H 7a06ae860SPratik Patel #define _LINUX_CORESIGHT_H 8a06ae860SPratik Patel 9a06ae860SPratik Patel #include <linux/device.h> 106e736c60SSuzuki K Poulose #include <linux/io.h> 11882d5e11SMathieu Poirier #include <linux/perf_event.h> 12ff63ec13SMark Brown #include <linux/sched.h> 13a06ae860SPratik Patel 14a06ae860SPratik Patel /* Peripheral id registers (0xFD0-0xFEC) */ 15a06ae860SPratik Patel #define CORESIGHT_PERIPHIDR4 0xfd0 16a06ae860SPratik Patel #define CORESIGHT_PERIPHIDR5 0xfd4 17a06ae860SPratik Patel #define CORESIGHT_PERIPHIDR6 0xfd8 18a06ae860SPratik Patel #define CORESIGHT_PERIPHIDR7 0xfdC 19a06ae860SPratik Patel #define CORESIGHT_PERIPHIDR0 0xfe0 20a06ae860SPratik Patel #define CORESIGHT_PERIPHIDR1 0xfe4 21a06ae860SPratik Patel #define CORESIGHT_PERIPHIDR2 0xfe8 22a06ae860SPratik Patel #define CORESIGHT_PERIPHIDR3 0xfeC 23a06ae860SPratik Patel /* Component id registers (0xFF0-0xFFC) */ 24a06ae860SPratik Patel #define CORESIGHT_COMPIDR0 0xff0 25a06ae860SPratik Patel #define CORESIGHT_COMPIDR1 0xff4 26a06ae860SPratik Patel #define CORESIGHT_COMPIDR2 0xff8 27a06ae860SPratik Patel #define CORESIGHT_COMPIDR3 0xffC 28a06ae860SPratik Patel 29a06ae860SPratik Patel #define ETM_ARCH_V3_3 0x23 30a06ae860SPratik Patel #define ETM_ARCH_V3_5 0x25 31a06ae860SPratik Patel #define PFT_ARCH_V1_0 0x30 32a06ae860SPratik Patel #define PFT_ARCH_V1_1 0x31 33a06ae860SPratik Patel 34a06ae860SPratik Patel #define CORESIGHT_UNLOCK 0xc5acce55 35a06ae860SPratik Patel 36a06ae860SPratik Patel extern struct bus_type coresight_bustype; 37a06ae860SPratik Patel 38a06ae860SPratik Patel enum coresight_dev_type { 39a06ae860SPratik Patel CORESIGHT_DEV_TYPE_SINK, 40a06ae860SPratik Patel CORESIGHT_DEV_TYPE_LINK, 41a06ae860SPratik Patel CORESIGHT_DEV_TYPE_LINKSINK, 42a06ae860SPratik Patel CORESIGHT_DEV_TYPE_SOURCE, 438a091d84SSuzuki K Poulose CORESIGHT_DEV_TYPE_HELPER, 44835d722bSMike Leach CORESIGHT_DEV_TYPE_ECT, 45a06ae860SPratik Patel }; 46a06ae860SPratik Patel 47a06ae860SPratik Patel enum coresight_dev_subtype_sink { 48a06ae860SPratik Patel CORESIGHT_DEV_SUBTYPE_SINK_PORT, 49a06ae860SPratik Patel CORESIGHT_DEV_SUBTYPE_SINK_BUFFER, 500336bdfdSMike Leach CORESIGHT_DEV_SUBTYPE_SINK_SYSMEM, 512cd87a7bSAnshuman Khandual CORESIGHT_DEV_SUBTYPE_SINK_PERCPU_SYSMEM, 52a06ae860SPratik Patel }; 53a06ae860SPratik Patel 54a06ae860SPratik Patel enum coresight_dev_subtype_link { 55a06ae860SPratik Patel CORESIGHT_DEV_SUBTYPE_LINK_MERG, 56a06ae860SPratik Patel CORESIGHT_DEV_SUBTYPE_LINK_SPLIT, 57a06ae860SPratik Patel CORESIGHT_DEV_SUBTYPE_LINK_FIFO, 58a06ae860SPratik Patel }; 59a06ae860SPratik Patel 60a06ae860SPratik Patel enum coresight_dev_subtype_source { 61a06ae860SPratik Patel CORESIGHT_DEV_SUBTYPE_SOURCE_PROC, 62a06ae860SPratik Patel CORESIGHT_DEV_SUBTYPE_SOURCE_BUS, 63a06ae860SPratik Patel CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE, 64b3c71626SMao Jinlong CORESIGHT_DEV_SUBTYPE_SOURCE_OTHERS, 65a06ae860SPratik Patel }; 66a06ae860SPratik Patel 678a091d84SSuzuki K Poulose enum coresight_dev_subtype_helper { 68fcacb5c1SSuzuki K Poulose CORESIGHT_DEV_SUBTYPE_HELPER_CATU, 698a091d84SSuzuki K Poulose }; 708a091d84SSuzuki K Poulose 71835d722bSMike Leach /* Embedded Cross Trigger (ECT) sub-types */ 72835d722bSMike Leach enum coresight_dev_subtype_ect { 73835d722bSMike Leach CORESIGHT_DEV_SUBTYPE_ECT_NONE, 74835d722bSMike Leach CORESIGHT_DEV_SUBTYPE_ECT_CTI, 75835d722bSMike Leach }; 76835d722bSMike Leach 77a06ae860SPratik Patel /** 7800b78e8bSSuzuki K Poulose * union coresight_dev_subtype - further characterisation of a type 79a06ae860SPratik Patel * @sink_subtype: type of sink this component is, as defined 8000b78e8bSSuzuki K Poulose * by @coresight_dev_subtype_sink. 81a06ae860SPratik Patel * @link_subtype: type of link this component is, as defined 8200b78e8bSSuzuki K Poulose * by @coresight_dev_subtype_link. 83a06ae860SPratik Patel * @source_subtype: type of source this component is, as defined 8400b78e8bSSuzuki K Poulose * by @coresight_dev_subtype_source. 858a091d84SSuzuki K Poulose * @helper_subtype: type of helper this component is, as defined 868a091d84SSuzuki K Poulose * by @coresight_dev_subtype_helper. 87835d722bSMike Leach * @ect_subtype: type of cross trigger this component is, as 88835d722bSMike Leach * defined by @coresight_dev_subtype_ect 89a06ae860SPratik Patel */ 9000b78e8bSSuzuki K Poulose union coresight_dev_subtype { 9100b78e8bSSuzuki K Poulose /* We have some devices which acts as LINK and SINK */ 9200b78e8bSSuzuki K Poulose struct { 93a06ae860SPratik Patel enum coresight_dev_subtype_sink sink_subtype; 94a06ae860SPratik Patel enum coresight_dev_subtype_link link_subtype; 9500b78e8bSSuzuki K Poulose }; 96a06ae860SPratik Patel enum coresight_dev_subtype_source source_subtype; 978a091d84SSuzuki K Poulose enum coresight_dev_subtype_helper helper_subtype; 98835d722bSMike Leach enum coresight_dev_subtype_ect ect_subtype; 99a06ae860SPratik Patel }; 100a06ae860SPratik Patel 101a06ae860SPratik Patel /** 102d375b356SSuzuki K Poulose * struct coresight_platform_data - data harvested from the firmware 103d375b356SSuzuki K Poulose * specification. 104d375b356SSuzuki K Poulose * 10581d0ea76SJames Clark * @nr_inconns: Number of elements for the input connections. 10681d0ea76SJames Clark * @nr_outconns: Number of elements for the output connections. 1074e8fe7e5SJames Clark * @out_conns: Array of nr_outconns pointers to connections from this 1084e8fe7e5SJames Clark * component. 109e3f4e687SJames Clark * @in_conns: Sparse array of pointers to input connections. Sparse 110e3f4e687SJames Clark * because the source device owns the connection so when it's 111e3f4e687SJames Clark * unloaded the connection leaves an empty slot. 112a06ae860SPratik Patel */ 113a06ae860SPratik Patel struct coresight_platform_data { 11481d0ea76SJames Clark int nr_inconns; 11581d0ea76SJames Clark int nr_outconns; 1164e8fe7e5SJames Clark struct coresight_connection **out_conns; 117e3f4e687SJames Clark struct coresight_connection **in_conns; 118a06ae860SPratik Patel }; 119a06ae860SPratik Patel 120a06ae860SPratik Patel /** 1216e736c60SSuzuki K Poulose * struct csdev_access - Abstraction of a CoreSight device access. 1226e736c60SSuzuki K Poulose * 1236e736c60SSuzuki K Poulose * @io_mem : True if the device has memory mapped I/O 1246e736c60SSuzuki K Poulose * @base : When io_mem == true, base address of the component 1256e736c60SSuzuki K Poulose * @read : Read from the given "offset" of the given instance. 1266e736c60SSuzuki K Poulose * @write : Write "val" to the given "offset". 1276e736c60SSuzuki K Poulose */ 1286e736c60SSuzuki K Poulose struct csdev_access { 1296e736c60SSuzuki K Poulose bool io_mem; 1306e736c60SSuzuki K Poulose union { 1316e736c60SSuzuki K Poulose void __iomem *base; 1326e736c60SSuzuki K Poulose struct { 1336e736c60SSuzuki K Poulose u64 (*read)(u32 offset, bool relaxed, bool _64bit); 1346e736c60SSuzuki K Poulose void (*write)(u64 val, u32 offset, bool relaxed, 1356e736c60SSuzuki K Poulose bool _64bit); 1366e736c60SSuzuki K Poulose }; 1376e736c60SSuzuki K Poulose }; 1386e736c60SSuzuki K Poulose }; 1396e736c60SSuzuki K Poulose 1406e736c60SSuzuki K Poulose #define CSDEV_ACCESS_IOMEM(_addr) \ 1416e736c60SSuzuki K Poulose ((struct csdev_access) { \ 1426e736c60SSuzuki K Poulose .io_mem = true, \ 1436e736c60SSuzuki K Poulose .base = (_addr), \ 1446e736c60SSuzuki K Poulose }) 1456e736c60SSuzuki K Poulose 1466e736c60SSuzuki K Poulose /** 147a06ae860SPratik Patel * struct coresight_desc - description of a component required from drivers 148a06ae860SPratik Patel * @type: as defined by @coresight_dev_type. 149a06ae860SPratik Patel * @subtype: as defined by @coresight_dev_subtype. 150a06ae860SPratik Patel * @ops: generic operations for this component, as defined 1512ede79a6SSuzuki K Poulose * by @coresight_ops. 152a06ae860SPratik Patel * @pdata: platform data collected from DT. 153a06ae860SPratik Patel * @dev: The device entity associated to this component. 154a06ae860SPratik Patel * @groups: operations specific to this component. These will end up 1552ede79a6SSuzuki K Poulose * in the component's sysfs sub-directory. 1562ede79a6SSuzuki K Poulose * @name: name for the coresight device, also shown under sysfs. 1576e736c60SSuzuki K Poulose * @access: Describe access to the device 158a06ae860SPratik Patel */ 159a06ae860SPratik Patel struct coresight_desc { 160a06ae860SPratik Patel enum coresight_dev_type type; 16100b78e8bSSuzuki K Poulose union coresight_dev_subtype subtype; 162a06ae860SPratik Patel const struct coresight_ops *ops; 163a06ae860SPratik Patel struct coresight_platform_data *pdata; 164a06ae860SPratik Patel struct device *dev; 165a06ae860SPratik Patel const struct attribute_group **groups; 1662ede79a6SSuzuki K Poulose const char *name; 1676e736c60SSuzuki K Poulose struct csdev_access access; 168a06ae860SPratik Patel }; 169a06ae860SPratik Patel 170a06ae860SPratik Patel /** 171a06ae860SPratik Patel * struct coresight_connection - representation of a single connection 172d49c9cf1SJames Clark * @src_port: a connection's output port number. 173d49c9cf1SJames Clark * @dest_port: destination's input port number @src_port is connected to. 174d49c9cf1SJames Clark * @dest_fwnode: destination component's fwnode handle. 175d49c9cf1SJames Clark * @dest_dev: a @coresight_device representation of the component 176d49c9cf1SJames Clark connected to @src_port. NULL until the device is created 1778a7365c2SSuzuki K Poulose * @link: Representation of the connection as a sysfs link. 178e3f4e687SJames Clark * 179e3f4e687SJames Clark * The full connection structure looks like this, where in_conns store 180e3f4e687SJames Clark * references to same connection as the source device's out_conns. 181e3f4e687SJames Clark * 182e3f4e687SJames Clark * +-----------------------------+ +-----------------------------+ 183e3f4e687SJames Clark * |coresight_device | |coresight_connection | 184e3f4e687SJames Clark * |-----------------------------| |-----------------------------| 185e3f4e687SJames Clark * | | | | 186e3f4e687SJames Clark * | | | dest_dev*|<-- 187e3f4e687SJames Clark * |pdata->out_conns[nr_outconns]|<->|src_dev* | | 188e3f4e687SJames Clark * | | | | | 189e3f4e687SJames Clark * +-----------------------------+ +-----------------------------+ | 190e3f4e687SJames Clark * | 191e3f4e687SJames Clark * +-----------------------------+ | 192e3f4e687SJames Clark * |coresight_device | | 193e3f4e687SJames Clark * |------------------------------ | 194e3f4e687SJames Clark * | | | 195e3f4e687SJames Clark * | pdata->in_conns[nr_inconns]|<-- 196e3f4e687SJames Clark * | | 197e3f4e687SJames Clark * +-----------------------------+ 198a06ae860SPratik Patel */ 199a06ae860SPratik Patel struct coresight_connection { 200d49c9cf1SJames Clark int src_port; 201d49c9cf1SJames Clark int dest_port; 202d49c9cf1SJames Clark struct fwnode_handle *dest_fwnode; 203d49c9cf1SJames Clark struct coresight_device *dest_dev; 2048a7365c2SSuzuki K Poulose struct coresight_sysfs_link *link; 205e3f4e687SJames Clark struct coresight_device *src_dev; 206ae7f2b5aSJames Clark atomic_t src_refcnt; 207ae7f2b5aSJames Clark atomic_t dest_refcnt; 208a06ae860SPratik Patel }; 209a06ae860SPratik Patel 210a06ae860SPratik Patel /** 21180961525SMike Leach * struct coresight_sysfs_link - representation of a connection in sysfs. 21280961525SMike Leach * @orig: Originating (master) coresight device for the link. 21380961525SMike Leach * @orig_name: Name to use for the link orig->target. 21480961525SMike Leach * @target: Target (slave) coresight device for the link. 21580961525SMike Leach * @target_name: Name to use for the link target->orig. 21680961525SMike Leach */ 21780961525SMike Leach struct coresight_sysfs_link { 21880961525SMike Leach struct coresight_device *orig; 21980961525SMike Leach const char *orig_name; 22080961525SMike Leach struct coresight_device *target; 22180961525SMike Leach const char *target_name; 22280961525SMike Leach }; 22380961525SMike Leach 22480961525SMike Leach /** 225a06ae860SPratik Patel * struct coresight_device - representation of a device as used by the framework 226b77e3ed0SSuzuki K Poulose * @pdata: Platform data with device connections associated to this device. 227a06ae860SPratik Patel * @type: as defined by @coresight_dev_type. 228a06ae860SPratik Patel * @subtype: as defined by @coresight_dev_subtype. 229a06ae860SPratik Patel * @ops: generic operations for this component, as defined 2306e736c60SSuzuki K Poulose * by @coresight_ops. 2316e736c60SSuzuki K Poulose * @access: Device i/o access abstraction for this device. 232a06ae860SPratik Patel * @dev: The device entity associated to this component. 233a06ae860SPratik Patel * @refcnt: keep track of what is in use. 234a06ae860SPratik Patel * @orphan: true if the component has connections that haven't been linked. 235a06ae860SPratik Patel * @enable: 'true' if component is currently part of an active path. 236a06ae860SPratik Patel * @activated: 'true' only if a _sink_ has been activated. A sink can be 237bb8e370bSMathieu Poirier * activated but not yet enabled. Enabling for a _sink_ 238d061cd73SMike Leach * happens when a source has been selected and a path is enabled 239d061cd73SMike Leach * from source to that sink. 240bb8e370bSMathieu Poirier * @ea: Device attribute for sink representation under PMU directory. 2410336bdfdSMike Leach * @def_sink: cached reference to default sink found for this device. 242177af828SMike Leach * @ect_dev: Associated cross trigger device. Not part of the trace data 243177af828SMike Leach * path or connections. 24480961525SMike Leach * @nr_links: number of sysfs links created to other components from this 24580961525SMike Leach * device. These will appear in the "connections" group. 24680961525SMike Leach * @has_conns_grp: Have added a "connections" group for sysfs links. 24742ff700fSMike Leach * @feature_csdev_list: List of complex feature programming added to the device. 24842ff700fSMike Leach * @config_csdev_list: List of system configurations added to the device. 24942ff700fSMike Leach * @cscfg_csdev_lock: Protect the lists of configurations and features. 250f8cce2ffSMike Leach * @active_cscfg_ctxt: Context information for current active system configuration. 251a06ae860SPratik Patel */ 252a06ae860SPratik Patel struct coresight_device { 253b77e3ed0SSuzuki K Poulose struct coresight_platform_data *pdata; 254a06ae860SPratik Patel enum coresight_dev_type type; 25500b78e8bSSuzuki K Poulose union coresight_dev_subtype subtype; 256a06ae860SPratik Patel const struct coresight_ops *ops; 2576e736c60SSuzuki K Poulose struct csdev_access access; 258a06ae860SPratik Patel struct device dev; 259ae7f2b5aSJames Clark atomic_t refcnt; 260a06ae860SPratik Patel bool orphan; 261a06ae860SPratik Patel bool enable; /* true only if configured as part of a path */ 262bb8e370bSMathieu Poirier /* sink specific fields */ 263a06ae860SPratik Patel bool activated; /* true only if a sink is part of a path */ 264bb8e370bSMathieu Poirier struct dev_ext_attribute *ea; 2650336bdfdSMike Leach struct coresight_device *def_sink; 266177af828SMike Leach /* cross trigger handling */ 267177af828SMike Leach struct coresight_device *ect_dev; 26880961525SMike Leach /* sysfs links between components */ 26980961525SMike Leach int nr_links; 27080961525SMike Leach bool has_conns_grp; 271f2ccc7b7STingwei Zhang bool ect_enabled; /* true only if associated ect device is enabled */ 27242ff700fSMike Leach /* system configuration and feature lists */ 27342ff700fSMike Leach struct list_head feature_csdev_list; 27442ff700fSMike Leach struct list_head config_csdev_list; 27542ff700fSMike Leach spinlock_t cscfg_csdev_lock; 276f8cce2ffSMike Leach void *active_cscfg_ctxt; 277a06ae860SPratik Patel }; 278a06ae860SPratik Patel 2790f5f9b6bSSuzuki K Poulose /* 2800f5f9b6bSSuzuki K Poulose * coresight_dev_list - Mapping for devices to "name" index for device 2810f5f9b6bSSuzuki K Poulose * names. 2820f5f9b6bSSuzuki K Poulose * 2830f5f9b6bSSuzuki K Poulose * @nr_idx: Number of entries already allocated. 2840f5f9b6bSSuzuki K Poulose * @pfx: Prefix pattern for device name. 2850f5f9b6bSSuzuki K Poulose * @fwnode_list: Array of fwnode_handles associated with each allocated 2860f5f9b6bSSuzuki K Poulose * index, upto nr_idx entries. 2870f5f9b6bSSuzuki K Poulose */ 2880f5f9b6bSSuzuki K Poulose struct coresight_dev_list { 2890f5f9b6bSSuzuki K Poulose int nr_idx; 2900f5f9b6bSSuzuki K Poulose const char *pfx; 2910f5f9b6bSSuzuki K Poulose struct fwnode_handle **fwnode_list; 2920f5f9b6bSSuzuki K Poulose }; 2930f5f9b6bSSuzuki K Poulose 2940f5f9b6bSSuzuki K Poulose #define DEFINE_CORESIGHT_DEVLIST(var, dev_pfx) \ 2950f5f9b6bSSuzuki K Poulose static struct coresight_dev_list (var) = { \ 2960f5f9b6bSSuzuki K Poulose .pfx = dev_pfx, \ 2970f5f9b6bSSuzuki K Poulose .nr_idx = 0, \ 2980f5f9b6bSSuzuki K Poulose .fwnode_list = NULL, \ 2990f5f9b6bSSuzuki K Poulose } 3000f5f9b6bSSuzuki K Poulose 301a06ae860SPratik Patel #define to_coresight_device(d) container_of(d, struct coresight_device, dev) 302a06ae860SPratik Patel 3039fa36828SJames Clark enum cs_mode { 3049fa36828SJames Clark CS_MODE_DISABLED, 3059fa36828SJames Clark CS_MODE_SYSFS, 3069fa36828SJames Clark CS_MODE_PERF, 3079fa36828SJames Clark }; 3089fa36828SJames Clark 309a06ae860SPratik Patel #define source_ops(csdev) csdev->ops->source_ops 310a06ae860SPratik Patel #define sink_ops(csdev) csdev->ops->sink_ops 311a06ae860SPratik Patel #define link_ops(csdev) csdev->ops->link_ops 3128a091d84SSuzuki K Poulose #define helper_ops(csdev) csdev->ops->helper_ops 313835d722bSMike Leach #define ect_ops(csdev) csdev->ops->ect_ops 314a06ae860SPratik Patel 315a06ae860SPratik Patel /** 316a06ae860SPratik Patel * struct coresight_ops_sink - basic operations for a sink 317a06ae860SPratik Patel * Operations available for sinks 318a06ae860SPratik Patel * @enable: enables the sink. 319a06ae860SPratik Patel * @disable: disables the sink. 3202997aa40SMathieu Poirier * @alloc_buffer: initialises perf's ring buffer for trace collection. 3212997aa40SMathieu Poirier * @free_buffer: release memory allocated in @get_config. 3222997aa40SMathieu Poirier * @update_buffer: update buffer pointers after a trace session. 323a06ae860SPratik Patel */ 324a06ae860SPratik Patel struct coresight_ops_sink { 3259fa36828SJames Clark int (*enable)(struct coresight_device *csdev, enum cs_mode mode, 3269fa36828SJames Clark void *data); 3276c817a95SMathieu Poirier int (*disable)(struct coresight_device *csdev); 328a0f08a6aSMathieu Poirier void *(*alloc_buffer)(struct coresight_device *csdev, 329a0f08a6aSMathieu Poirier struct perf_event *event, void **pages, 330a0f08a6aSMathieu Poirier int nr_pages, bool overwrite); 3312997aa40SMathieu Poirier void (*free_buffer)(void *config); 3327ec786adSSuzuki K Poulose unsigned long (*update_buffer)(struct coresight_device *csdev, 3332997aa40SMathieu Poirier struct perf_output_handle *handle, 3342997aa40SMathieu Poirier void *sink_config); 335a06ae860SPratik Patel }; 336a06ae860SPratik Patel 337a06ae860SPratik Patel /** 338a06ae860SPratik Patel * struct coresight_ops_link - basic operations for a link 339a06ae860SPratik Patel * Operations available for links. 340a06ae860SPratik Patel * @enable: enables flow between iport and oport. 341a06ae860SPratik Patel * @disable: disables flow between iport and oport. 342a06ae860SPratik Patel */ 343a06ae860SPratik Patel struct coresight_ops_link { 344ae7f2b5aSJames Clark int (*enable)(struct coresight_device *csdev, 345ae7f2b5aSJames Clark struct coresight_connection *in, 346ae7f2b5aSJames Clark struct coresight_connection *out); 347ae7f2b5aSJames Clark void (*disable)(struct coresight_device *csdev, 348ae7f2b5aSJames Clark struct coresight_connection *in, 349ae7f2b5aSJames Clark struct coresight_connection *out); 350a06ae860SPratik Patel }; 351a06ae860SPratik Patel 352a06ae860SPratik Patel /** 353a06ae860SPratik Patel * struct coresight_ops_source - basic operations for a source 354a06ae860SPratik Patel * Operations available for sources. 35552210c87SMathieu Poirier * @cpu_id: returns the value of the CPU number this component 35652210c87SMathieu Poirier * is associated to. 3571d27ff5aSMathieu Poirier * @enable: enables tracing for a source. 358a06ae860SPratik Patel * @disable: disables tracing for a source. 359a06ae860SPratik Patel */ 360a06ae860SPratik Patel struct coresight_ops_source { 36152210c87SMathieu Poirier int (*cpu_id)(struct coresight_device *csdev); 3629fa36828SJames Clark int (*enable)(struct coresight_device *csdev, struct perf_event *event, 3639fa36828SJames Clark enum cs_mode mode); 36468905d73SMathieu Poirier void (*disable)(struct coresight_device *csdev, 36568905d73SMathieu Poirier struct perf_event *event); 366a06ae860SPratik Patel }; 367a06ae860SPratik Patel 3688a091d84SSuzuki K Poulose /** 3698a091d84SSuzuki K Poulose * struct coresight_ops_helper - Operations for a helper device. 3708a091d84SSuzuki K Poulose * 3718a091d84SSuzuki K Poulose * All operations could pass in a device specific data, which could 3728a091d84SSuzuki K Poulose * help the helper device to determine what to do. 3738a091d84SSuzuki K Poulose * 3748a091d84SSuzuki K Poulose * @enable : Enable the device 3758a091d84SSuzuki K Poulose * @disable : Disable the device 3768a091d84SSuzuki K Poulose */ 3778a091d84SSuzuki K Poulose struct coresight_ops_helper { 378*61486528SJames Clark int (*enable)(struct coresight_device *csdev, enum cs_mode mode, 379*61486528SJames Clark void *data); 3808a091d84SSuzuki K Poulose int (*disable)(struct coresight_device *csdev, void *data); 3818a091d84SSuzuki K Poulose }; 3828a091d84SSuzuki K Poulose 383835d722bSMike Leach /** 384835d722bSMike Leach * struct coresight_ops_ect - Ops for an embedded cross trigger device 385835d722bSMike Leach * 386835d722bSMike Leach * @enable : Enable the device 387835d722bSMike Leach * @disable : Disable the device 388835d722bSMike Leach */ 389835d722bSMike Leach struct coresight_ops_ect { 390835d722bSMike Leach int (*enable)(struct coresight_device *csdev); 391835d722bSMike Leach int (*disable)(struct coresight_device *csdev); 392835d722bSMike Leach }; 393835d722bSMike Leach 394a06ae860SPratik Patel struct coresight_ops { 395a06ae860SPratik Patel const struct coresight_ops_sink *sink_ops; 396a06ae860SPratik Patel const struct coresight_ops_link *link_ops; 397a06ae860SPratik Patel const struct coresight_ops_source *source_ops; 3988a091d84SSuzuki K Poulose const struct coresight_ops_helper *helper_ops; 399835d722bSMike Leach const struct coresight_ops_ect *ect_ops; 400a06ae860SPratik Patel }; 401a06ae860SPratik Patel 402b8127113SKim Phillips #if IS_ENABLED(CONFIG_CORESIGHT) 4036e736c60SSuzuki K Poulose 4046e736c60SSuzuki K Poulose static inline u32 csdev_access_relaxed_read32(struct csdev_access *csa, 4056e736c60SSuzuki K Poulose u32 offset) 4066e736c60SSuzuki K Poulose { 4076e736c60SSuzuki K Poulose if (likely(csa->io_mem)) 4086e736c60SSuzuki K Poulose return readl_relaxed(csa->base + offset); 4096e736c60SSuzuki K Poulose 4106e736c60SSuzuki K Poulose return csa->read(offset, true, false); 4116e736c60SSuzuki K Poulose } 4126e736c60SSuzuki K Poulose 413b6df1cbbSJames Clark static inline u64 csdev_access_relaxed_read_pair(struct csdev_access *csa, 4140a98181fSJames Clark u32 lo_offset, u32 hi_offset) 415b6df1cbbSJames Clark { 416b6df1cbbSJames Clark if (likely(csa->io_mem)) { 4170a98181fSJames Clark return readl_relaxed(csa->base + lo_offset) | 4180a98181fSJames Clark ((u64)readl_relaxed(csa->base + hi_offset) << 32); 419b6df1cbbSJames Clark } 420b6df1cbbSJames Clark 4210a98181fSJames Clark return csa->read(lo_offset, true, false) | (csa->read(hi_offset, true, false) << 32); 4220a98181fSJames Clark } 4230a98181fSJames Clark 4240a98181fSJames Clark static inline void csdev_access_relaxed_write_pair(struct csdev_access *csa, u64 val, 4250a98181fSJames Clark u32 lo_offset, u32 hi_offset) 4260a98181fSJames Clark { 4270a98181fSJames Clark if (likely(csa->io_mem)) { 4280a98181fSJames Clark writel_relaxed((u32)val, csa->base + lo_offset); 4290a98181fSJames Clark writel_relaxed((u32)(val >> 32), csa->base + hi_offset); 4300a98181fSJames Clark } else { 4310a98181fSJames Clark csa->write((u32)val, lo_offset, true, false); 4320a98181fSJames Clark csa->write((u32)(val >> 32), hi_offset, true, false); 4330a98181fSJames Clark } 434b6df1cbbSJames Clark } 435b6df1cbbSJames Clark 4366e736c60SSuzuki K Poulose static inline u32 csdev_access_read32(struct csdev_access *csa, u32 offset) 4376e736c60SSuzuki K Poulose { 4386e736c60SSuzuki K Poulose if (likely(csa->io_mem)) 4396e736c60SSuzuki K Poulose return readl(csa->base + offset); 4406e736c60SSuzuki K Poulose 4416e736c60SSuzuki K Poulose return csa->read(offset, false, false); 4426e736c60SSuzuki K Poulose } 4436e736c60SSuzuki K Poulose 4446e736c60SSuzuki K Poulose static inline void csdev_access_relaxed_write32(struct csdev_access *csa, 4456e736c60SSuzuki K Poulose u32 val, u32 offset) 4466e736c60SSuzuki K Poulose { 4476e736c60SSuzuki K Poulose if (likely(csa->io_mem)) 4486e736c60SSuzuki K Poulose writel_relaxed(val, csa->base + offset); 4496e736c60SSuzuki K Poulose else 4506e736c60SSuzuki K Poulose csa->write(val, offset, true, false); 4516e736c60SSuzuki K Poulose } 4526e736c60SSuzuki K Poulose 4536e736c60SSuzuki K Poulose static inline void csdev_access_write32(struct csdev_access *csa, u32 val, u32 offset) 4546e736c60SSuzuki K Poulose { 4556e736c60SSuzuki K Poulose if (likely(csa->io_mem)) 4566e736c60SSuzuki K Poulose writel(val, csa->base + offset); 4576e736c60SSuzuki K Poulose else 4586e736c60SSuzuki K Poulose csa->write(val, offset, false, false); 4596e736c60SSuzuki K Poulose } 4606e736c60SSuzuki K Poulose 4616e736c60SSuzuki K Poulose #ifdef CONFIG_64BIT 4626e736c60SSuzuki K Poulose 4636e736c60SSuzuki K Poulose static inline u64 csdev_access_relaxed_read64(struct csdev_access *csa, 4646e736c60SSuzuki K Poulose u32 offset) 4656e736c60SSuzuki K Poulose { 4666e736c60SSuzuki K Poulose if (likely(csa->io_mem)) 4676e736c60SSuzuki K Poulose return readq_relaxed(csa->base + offset); 4686e736c60SSuzuki K Poulose 4696e736c60SSuzuki K Poulose return csa->read(offset, true, true); 4706e736c60SSuzuki K Poulose } 4716e736c60SSuzuki K Poulose 4726e736c60SSuzuki K Poulose static inline u64 csdev_access_read64(struct csdev_access *csa, u32 offset) 4736e736c60SSuzuki K Poulose { 4746e736c60SSuzuki K Poulose if (likely(csa->io_mem)) 4756e736c60SSuzuki K Poulose return readq(csa->base + offset); 4766e736c60SSuzuki K Poulose 4776e736c60SSuzuki K Poulose return csa->read(offset, false, true); 4786e736c60SSuzuki K Poulose } 4796e736c60SSuzuki K Poulose 4806e736c60SSuzuki K Poulose static inline void csdev_access_relaxed_write64(struct csdev_access *csa, 4816e736c60SSuzuki K Poulose u64 val, u32 offset) 4826e736c60SSuzuki K Poulose { 4836e736c60SSuzuki K Poulose if (likely(csa->io_mem)) 4846e736c60SSuzuki K Poulose writeq_relaxed(val, csa->base + offset); 4856e736c60SSuzuki K Poulose else 4866e736c60SSuzuki K Poulose csa->write(val, offset, true, true); 4876e736c60SSuzuki K Poulose } 4886e736c60SSuzuki K Poulose 4896e736c60SSuzuki K Poulose static inline void csdev_access_write64(struct csdev_access *csa, u64 val, u32 offset) 4906e736c60SSuzuki K Poulose { 4916e736c60SSuzuki K Poulose if (likely(csa->io_mem)) 4926e736c60SSuzuki K Poulose writeq(val, csa->base + offset); 4936e736c60SSuzuki K Poulose else 4946e736c60SSuzuki K Poulose csa->write(val, offset, false, true); 4956e736c60SSuzuki K Poulose } 4966e736c60SSuzuki K Poulose 4976e736c60SSuzuki K Poulose #else /* !CONFIG_64BIT */ 4986e736c60SSuzuki K Poulose 4996e736c60SSuzuki K Poulose static inline u64 csdev_access_relaxed_read64(struct csdev_access *csa, 5006e736c60SSuzuki K Poulose u32 offset) 5016e736c60SSuzuki K Poulose { 5026e736c60SSuzuki K Poulose WARN_ON(1); 5036e736c60SSuzuki K Poulose return 0; 5046e736c60SSuzuki K Poulose } 5056e736c60SSuzuki K Poulose 5066e736c60SSuzuki K Poulose static inline u64 csdev_access_read64(struct csdev_access *csa, u32 offset) 5076e736c60SSuzuki K Poulose { 5086e736c60SSuzuki K Poulose WARN_ON(1); 5096e736c60SSuzuki K Poulose return 0; 5106e736c60SSuzuki K Poulose } 5116e736c60SSuzuki K Poulose 5126e736c60SSuzuki K Poulose static inline void csdev_access_relaxed_write64(struct csdev_access *csa, 5136e736c60SSuzuki K Poulose u64 val, u32 offset) 5146e736c60SSuzuki K Poulose { 5156e736c60SSuzuki K Poulose WARN_ON(1); 5166e736c60SSuzuki K Poulose } 5176e736c60SSuzuki K Poulose 5186e736c60SSuzuki K Poulose static inline void csdev_access_write64(struct csdev_access *csa, u64 val, u32 offset) 5196e736c60SSuzuki K Poulose { 5206e736c60SSuzuki K Poulose WARN_ON(1); 5216e736c60SSuzuki K Poulose } 5226e736c60SSuzuki K Poulose #endif /* CONFIG_64BIT */ 5236e736c60SSuzuki K Poulose 5242cd87a7bSAnshuman Khandual static inline bool coresight_is_percpu_source(struct coresight_device *csdev) 5252cd87a7bSAnshuman Khandual { 5262cd87a7bSAnshuman Khandual return csdev && (csdev->type == CORESIGHT_DEV_TYPE_SOURCE) && 5272cd87a7bSAnshuman Khandual (csdev->subtype.source_subtype == CORESIGHT_DEV_SUBTYPE_SOURCE_PROC); 5282cd87a7bSAnshuman Khandual } 5292cd87a7bSAnshuman Khandual 5302cd87a7bSAnshuman Khandual static inline bool coresight_is_percpu_sink(struct coresight_device *csdev) 5312cd87a7bSAnshuman Khandual { 5322cd87a7bSAnshuman Khandual return csdev && (csdev->type == CORESIGHT_DEV_TYPE_SINK) && 5332cd87a7bSAnshuman Khandual (csdev->subtype.sink_subtype == CORESIGHT_DEV_SUBTYPE_SINK_PERCPU_SYSMEM); 5342cd87a7bSAnshuman Khandual } 5352cd87a7bSAnshuman Khandual 536a06ae860SPratik Patel extern struct coresight_device * 537a06ae860SPratik Patel coresight_register(struct coresight_desc *desc); 538a06ae860SPratik Patel extern void coresight_unregister(struct coresight_device *csdev); 539a06ae860SPratik Patel extern int coresight_enable(struct coresight_device *csdev); 540a06ae860SPratik Patel extern void coresight_disable(struct coresight_device *csdev); 54102005282SSuzuki K Poulose extern int coresight_timeout(struct csdev_access *csa, u32 offset, 542a06ae860SPratik Patel int position, int value); 5432478a6aeSSuzuki K Poulose 5448ce00296SSuzuki K Poulose extern int coresight_claim_device(struct coresight_device *csdev); 5458ce00296SSuzuki K Poulose extern int coresight_claim_device_unlocked(struct coresight_device *csdev); 5462478a6aeSSuzuki K Poulose 5478ce00296SSuzuki K Poulose extern void coresight_disclaim_device(struct coresight_device *csdev); 5488ce00296SSuzuki K Poulose extern void coresight_disclaim_device_unlocked(struct coresight_device *csdev); 5490f5f9b6bSSuzuki K Poulose extern char *coresight_alloc_device_name(struct coresight_dev_list *devs, 5500f5f9b6bSSuzuki K Poulose struct device *dev); 551f188b5e7SAndrew Murray 552f188b5e7SAndrew Murray extern bool coresight_loses_context_with_cpu(struct device *dev); 5536e736c60SSuzuki K Poulose 5546e736c60SSuzuki K Poulose u32 coresight_relaxed_read32(struct coresight_device *csdev, u32 offset); 5556e736c60SSuzuki K Poulose u32 coresight_read32(struct coresight_device *csdev, u32 offset); 5566e736c60SSuzuki K Poulose void coresight_write32(struct coresight_device *csdev, u32 val, u32 offset); 5576e736c60SSuzuki K Poulose void coresight_relaxed_write32(struct coresight_device *csdev, 5586e736c60SSuzuki K Poulose u32 val, u32 offset); 5596e736c60SSuzuki K Poulose u64 coresight_relaxed_read64(struct coresight_device *csdev, u32 offset); 5606e736c60SSuzuki K Poulose u64 coresight_read64(struct coresight_device *csdev, u32 offset); 5616e736c60SSuzuki K Poulose void coresight_relaxed_write64(struct coresight_device *csdev, 5626e736c60SSuzuki K Poulose u64 val, u32 offset); 5636e736c60SSuzuki K Poulose void coresight_write64(struct coresight_device *csdev, u64 val, u32 offset); 5646e736c60SSuzuki K Poulose 565a06ae860SPratik Patel #else 566a06ae860SPratik Patel static inline struct coresight_device * 567a06ae860SPratik Patel coresight_register(struct coresight_desc *desc) { return NULL; } 568a06ae860SPratik Patel static inline void coresight_unregister(struct coresight_device *csdev) {} 569a06ae860SPratik Patel static inline int 570a06ae860SPratik Patel coresight_enable(struct coresight_device *csdev) { return -ENOSYS; } 571a06ae860SPratik Patel static inline void coresight_disable(struct coresight_device *csdev) {} 57202005282SSuzuki K Poulose 57302005282SSuzuki K Poulose static inline int coresight_timeout(struct csdev_access *csa, u32 offset, 57402005282SSuzuki K Poulose int position, int value) 57502005282SSuzuki K Poulose { 57602005282SSuzuki K Poulose return 1; 57702005282SSuzuki K Poulose } 57802005282SSuzuki K Poulose 5798ce00296SSuzuki K Poulose static inline int coresight_claim_device_unlocked(struct coresight_device *csdev) 5802478a6aeSSuzuki K Poulose { 5812478a6aeSSuzuki K Poulose return -EINVAL; 5822478a6aeSSuzuki K Poulose } 5832478a6aeSSuzuki K Poulose 5848ce00296SSuzuki K Poulose static inline int coresight_claim_device(struct coresight_device *csdev) 5852478a6aeSSuzuki K Poulose { 5862478a6aeSSuzuki K Poulose return -EINVAL; 5872478a6aeSSuzuki K Poulose } 5882478a6aeSSuzuki K Poulose 5898ce00296SSuzuki K Poulose static inline void coresight_disclaim_device(struct coresight_device *csdev) {} 5908ce00296SSuzuki K Poulose static inline void coresight_disclaim_device_unlocked(struct coresight_device *csdev) {} 5912478a6aeSSuzuki K Poulose 592f188b5e7SAndrew Murray static inline bool coresight_loses_context_with_cpu(struct device *dev) 593f188b5e7SAndrew Murray { 594f188b5e7SAndrew Murray return false; 595f188b5e7SAndrew Murray } 5966e736c60SSuzuki K Poulose 5976e736c60SSuzuki K Poulose static inline u32 coresight_relaxed_read32(struct coresight_device *csdev, u32 offset) 5986e736c60SSuzuki K Poulose { 5996e736c60SSuzuki K Poulose WARN_ON_ONCE(1); 6006e736c60SSuzuki K Poulose return 0; 6016e736c60SSuzuki K Poulose } 6026e736c60SSuzuki K Poulose 6036e736c60SSuzuki K Poulose static inline u32 coresight_read32(struct coresight_device *csdev, u32 offset) 6046e736c60SSuzuki K Poulose { 6056e736c60SSuzuki K Poulose WARN_ON_ONCE(1); 6066e736c60SSuzuki K Poulose return 0; 6076e736c60SSuzuki K Poulose } 6086e736c60SSuzuki K Poulose 6096e736c60SSuzuki K Poulose static inline void coresight_write32(struct coresight_device *csdev, u32 val, u32 offset) 6106e736c60SSuzuki K Poulose { 6116e736c60SSuzuki K Poulose } 6126e736c60SSuzuki K Poulose 6136e736c60SSuzuki K Poulose static inline void coresight_relaxed_write32(struct coresight_device *csdev, 6146e736c60SSuzuki K Poulose u32 val, u32 offset) 6156e736c60SSuzuki K Poulose { 6166e736c60SSuzuki K Poulose } 6176e736c60SSuzuki K Poulose 6186e736c60SSuzuki K Poulose static inline u64 coresight_relaxed_read64(struct coresight_device *csdev, 6196e736c60SSuzuki K Poulose u32 offset) 6206e736c60SSuzuki K Poulose { 6216e736c60SSuzuki K Poulose WARN_ON_ONCE(1); 6226e736c60SSuzuki K Poulose return 0; 6236e736c60SSuzuki K Poulose } 6246e736c60SSuzuki K Poulose 6256e736c60SSuzuki K Poulose static inline u64 coresight_read64(struct coresight_device *csdev, u32 offset) 6266e736c60SSuzuki K Poulose { 6276e736c60SSuzuki K Poulose WARN_ON_ONCE(1); 6286e736c60SSuzuki K Poulose return 0; 6296e736c60SSuzuki K Poulose } 6306e736c60SSuzuki K Poulose 6316e736c60SSuzuki K Poulose static inline void coresight_relaxed_write64(struct coresight_device *csdev, 6326e736c60SSuzuki K Poulose u64 val, u32 offset) 6336e736c60SSuzuki K Poulose { 6346e736c60SSuzuki K Poulose } 6356e736c60SSuzuki K Poulose 6366e736c60SSuzuki K Poulose static inline void coresight_write64(struct coresight_device *csdev, u64 val, u32 offset) 6376e736c60SSuzuki K Poulose { 6386e736c60SSuzuki K Poulose } 6396e736c60SSuzuki K Poulose 6406e736c60SSuzuki K Poulose #endif /* IS_ENABLED(CONFIG_CORESIGHT) */ 641c61c4b5dSMathieu Poirier 64291824db2SSuzuki K Poulose extern int coresight_get_cpu(struct device *dev); 643a06ae860SPratik Patel 644f03631daSSuzuki K Poulose struct coresight_platform_data *coresight_get_platform_data(struct device *dev); 6453d4ff657SJames Clark struct coresight_connection * 6463d4ff657SJames Clark coresight_add_out_conn(struct device *dev, 6473d4ff657SJames Clark struct coresight_platform_data *pdata, 6483d4ff657SJames Clark const struct coresight_connection *new_conn); 649e3f4e687SJames Clark int coresight_add_in_conn(struct coresight_connection *conn); 650*61486528SJames Clark struct coresight_device * 651*61486528SJames Clark coresight_find_input_type(struct coresight_platform_data *pdata, 652*61486528SJames Clark enum coresight_dev_type type, 653*61486528SJames Clark union coresight_dev_subtype subtype); 654*61486528SJames Clark struct coresight_device * 655*61486528SJames Clark coresight_find_output_type(struct coresight_platform_data *pdata, 656*61486528SJames Clark enum coresight_dev_type type, 657*61486528SJames Clark union coresight_dev_subtype subtype); 658f03631daSSuzuki K Poulose 6596e736c60SSuzuki K Poulose #endif /* _LINUX_COREISGHT_H */ 660