139f40346SAlexander Shishkin /* 239f40346SAlexander Shishkin * Intel(R) Trace Hub data structures 339f40346SAlexander Shishkin * 439f40346SAlexander Shishkin * Copyright (C) 2014-2015 Intel Corporation. 539f40346SAlexander Shishkin * 639f40346SAlexander Shishkin * This program is free software; you can redistribute it and/or modify it 739f40346SAlexander Shishkin * under the terms and conditions of the GNU General Public License, 839f40346SAlexander Shishkin * version 2, as published by the Free Software Foundation. 939f40346SAlexander Shishkin * 1039f40346SAlexander Shishkin * This program is distributed in the hope it will be useful, but WITHOUT 1139f40346SAlexander Shishkin * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1239f40346SAlexander Shishkin * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 1339f40346SAlexander Shishkin * more details. 1439f40346SAlexander Shishkin */ 1539f40346SAlexander Shishkin 1639f40346SAlexander Shishkin #ifndef __INTEL_TH_H__ 1739f40346SAlexander Shishkin #define __INTEL_TH_H__ 1839f40346SAlexander Shishkin 1939f40346SAlexander Shishkin /* intel_th_device device types */ 2039f40346SAlexander Shishkin enum { 2139f40346SAlexander Shishkin /* Devices that generate trace data */ 2239f40346SAlexander Shishkin INTEL_TH_SOURCE = 0, 2339f40346SAlexander Shishkin /* Output ports (MSC, PTI) */ 2439f40346SAlexander Shishkin INTEL_TH_OUTPUT, 2539f40346SAlexander Shishkin /* Switch, the Global Trace Hub (GTH) */ 2639f40346SAlexander Shishkin INTEL_TH_SWITCH, 2739f40346SAlexander Shishkin }; 2839f40346SAlexander Shishkin 2939f40346SAlexander Shishkin /** 3039f40346SAlexander Shishkin * struct intel_th_output - descriptor INTEL_TH_OUTPUT type devices 3139f40346SAlexander Shishkin * @port: output port number, assigned by the switch 3239f40346SAlexander Shishkin * @type: GTH_{MSU,CTP,PTI} 334d02ceffSAlexander Shishkin * @scratchpad: scratchpad bits to flag when this output is enabled 3439f40346SAlexander Shishkin * @multiblock: true for multiblock output configuration 3539f40346SAlexander Shishkin * @active: true when this output is enabled 3639f40346SAlexander Shishkin * 3739f40346SAlexander Shishkin * Output port descriptor, used by switch driver to tell which output 3839f40346SAlexander Shishkin * port this output device corresponds to. Filled in at output device's 3939f40346SAlexander Shishkin * probe time by switch::assign(). Passed from output device driver to 4039f40346SAlexander Shishkin * switch related code to enable/disable its port. 4139f40346SAlexander Shishkin */ 4239f40346SAlexander Shishkin struct intel_th_output { 4339f40346SAlexander Shishkin int port; 4439f40346SAlexander Shishkin unsigned int type; 454d02ceffSAlexander Shishkin unsigned int scratchpad; 4639f40346SAlexander Shishkin bool multiblock; 4739f40346SAlexander Shishkin bool active; 4839f40346SAlexander Shishkin }; 4939f40346SAlexander Shishkin 5039f40346SAlexander Shishkin /** 5139f40346SAlexander Shishkin * struct intel_th_device - device on the intel_th bus 5239f40346SAlexander Shishkin * @dev: device 5339f40346SAlexander Shishkin * @resource: array of resources available to this device 5439f40346SAlexander Shishkin * @num_resources: number of resources in @resource array 5539f40346SAlexander Shishkin * @type: INTEL_TH_{SOURCE,OUTPUT,SWITCH} 5639f40346SAlexander Shishkin * @id: device instance or -1 57*c49a7591SAlexander Shishkin * @host_mode: Intel TH is controlled by an external debug host 5839f40346SAlexander Shishkin * @output: output descriptor for INTEL_TH_OUTPUT devices 5939f40346SAlexander Shishkin * @name: device name to match the driver 6039f40346SAlexander Shishkin */ 6139f40346SAlexander Shishkin struct intel_th_device { 6239f40346SAlexander Shishkin struct device dev; 6339f40346SAlexander Shishkin struct resource *resource; 6439f40346SAlexander Shishkin unsigned int num_resources; 6539f40346SAlexander Shishkin unsigned int type; 6639f40346SAlexander Shishkin int id; 6739f40346SAlexander Shishkin 68*c49a7591SAlexander Shishkin /* INTEL_TH_SWITCH specific */ 69*c49a7591SAlexander Shishkin bool host_mode; 70*c49a7591SAlexander Shishkin 7139f40346SAlexander Shishkin /* INTEL_TH_OUTPUT specific */ 7239f40346SAlexander Shishkin struct intel_th_output output; 7339f40346SAlexander Shishkin 7439f40346SAlexander Shishkin char name[]; 7539f40346SAlexander Shishkin }; 7639f40346SAlexander Shishkin 7739f40346SAlexander Shishkin #define to_intel_th_device(_d) \ 7839f40346SAlexander Shishkin container_of((_d), struct intel_th_device, dev) 7939f40346SAlexander Shishkin 8039f40346SAlexander Shishkin /** 8139f40346SAlexander Shishkin * intel_th_device_get_resource() - obtain @num'th resource of type @type 8239f40346SAlexander Shishkin * @thdev: the device to search the resource for 8339f40346SAlexander Shishkin * @type: resource type 8439f40346SAlexander Shishkin * @num: number of the resource 8539f40346SAlexander Shishkin */ 8639f40346SAlexander Shishkin static inline struct resource * 8739f40346SAlexander Shishkin intel_th_device_get_resource(struct intel_th_device *thdev, unsigned int type, 8839f40346SAlexander Shishkin unsigned int num) 8939f40346SAlexander Shishkin { 9039f40346SAlexander Shishkin int i; 9139f40346SAlexander Shishkin 9239f40346SAlexander Shishkin for (i = 0; i < thdev->num_resources; i++) 9339f40346SAlexander Shishkin if (resource_type(&thdev->resource[i]) == type && !num--) 9439f40346SAlexander Shishkin return &thdev->resource[i]; 9539f40346SAlexander Shishkin 9639f40346SAlexander Shishkin return NULL; 9739f40346SAlexander Shishkin } 9839f40346SAlexander Shishkin 9939f40346SAlexander Shishkin /** 10039f40346SAlexander Shishkin * intel_th_output_assigned() - if an output device is assigned to a switch port 10139f40346SAlexander Shishkin * @thdev: the output device 10239f40346SAlexander Shishkin * 10339f40346SAlexander Shishkin * Return: true if the device is INTEL_TH_OUTPUT *and* is assigned a port 10439f40346SAlexander Shishkin */ 10539f40346SAlexander Shishkin static inline bool 10639f40346SAlexander Shishkin intel_th_output_assigned(struct intel_th_device *thdev) 10739f40346SAlexander Shishkin { 10839f40346SAlexander Shishkin return thdev->type == INTEL_TH_OUTPUT && 10939f40346SAlexander Shishkin thdev->output.port >= 0; 11039f40346SAlexander Shishkin } 11139f40346SAlexander Shishkin 11239f40346SAlexander Shishkin /** 11339f40346SAlexander Shishkin * struct intel_th_driver - driver for an intel_th_device device 11439f40346SAlexander Shishkin * @driver: generic driver 11539f40346SAlexander Shishkin * @probe: probe method 11639f40346SAlexander Shishkin * @remove: remove method 11739f40346SAlexander Shishkin * @assign: match a given output type device against available outputs 11839f40346SAlexander Shishkin * @unassign: deassociate an output type device from an output port 11939f40346SAlexander Shishkin * @enable: enable tracing for a given output device 12039f40346SAlexander Shishkin * @disable: disable tracing for a given output device 121bd581f23SAlexander Shishkin * @irq: interrupt callback 122bd581f23SAlexander Shishkin * @activate: enable tracing on the output's side 123bd581f23SAlexander Shishkin * @deactivate: disable tracing on the output's side 12439f40346SAlexander Shishkin * @fops: file operations for device nodes 125b5edbf1eSAlexander Shishkin * @attr_group: attributes provided by the driver 12639f40346SAlexander Shishkin * 12739f40346SAlexander Shishkin * Callbacks @probe and @remove are required for all device types. 12839f40346SAlexander Shishkin * Switch device driver needs to fill in @assign, @enable and @disable 12939f40346SAlexander Shishkin * callbacks. 13039f40346SAlexander Shishkin */ 13139f40346SAlexander Shishkin struct intel_th_driver { 13239f40346SAlexander Shishkin struct device_driver driver; 13339f40346SAlexander Shishkin int (*probe)(struct intel_th_device *thdev); 13439f40346SAlexander Shishkin void (*remove)(struct intel_th_device *thdev); 13539f40346SAlexander Shishkin /* switch (GTH) ops */ 13639f40346SAlexander Shishkin int (*assign)(struct intel_th_device *thdev, 13739f40346SAlexander Shishkin struct intel_th_device *othdev); 13839f40346SAlexander Shishkin void (*unassign)(struct intel_th_device *thdev, 13939f40346SAlexander Shishkin struct intel_th_device *othdev); 14039f40346SAlexander Shishkin void (*enable)(struct intel_th_device *thdev, 14139f40346SAlexander Shishkin struct intel_th_output *output); 14239f40346SAlexander Shishkin void (*disable)(struct intel_th_device *thdev, 14339f40346SAlexander Shishkin struct intel_th_output *output); 14439f40346SAlexander Shishkin /* output ops */ 14539f40346SAlexander Shishkin void (*irq)(struct intel_th_device *thdev); 14639f40346SAlexander Shishkin int (*activate)(struct intel_th_device *thdev); 14739f40346SAlexander Shishkin void (*deactivate)(struct intel_th_device *thdev); 14839f40346SAlexander Shishkin /* file_operations for those who want a device node */ 14939f40346SAlexander Shishkin const struct file_operations *fops; 150b5edbf1eSAlexander Shishkin /* optional attributes */ 151b5edbf1eSAlexander Shishkin struct attribute_group *attr_group; 15239f40346SAlexander Shishkin 15339f40346SAlexander Shishkin /* source ops */ 15439f40346SAlexander Shishkin int (*set_output)(struct intel_th_device *thdev, 15539f40346SAlexander Shishkin unsigned int master); 15639f40346SAlexander Shishkin }; 15739f40346SAlexander Shishkin 15839f40346SAlexander Shishkin #define to_intel_th_driver(_d) \ 15939f40346SAlexander Shishkin container_of((_d), struct intel_th_driver, driver) 16039f40346SAlexander Shishkin 161f18a9531SAlexander Shishkin #define to_intel_th_driver_or_null(_d) \ 162f18a9531SAlexander Shishkin ((_d) ? to_intel_th_driver(_d) : NULL) 163f18a9531SAlexander Shishkin 16439f40346SAlexander Shishkin static inline struct intel_th_device * 16539f40346SAlexander Shishkin to_intel_th_hub(struct intel_th_device *thdev) 16639f40346SAlexander Shishkin { 16739f40346SAlexander Shishkin struct device *parent = thdev->dev.parent; 16839f40346SAlexander Shishkin 16939f40346SAlexander Shishkin if (!parent) 17039f40346SAlexander Shishkin return NULL; 17139f40346SAlexander Shishkin 17239f40346SAlexander Shishkin return to_intel_th_device(parent); 17339f40346SAlexander Shishkin } 17439f40346SAlexander Shishkin 17539f40346SAlexander Shishkin struct intel_th * 17639f40346SAlexander Shishkin intel_th_alloc(struct device *dev, struct resource *devres, 17739f40346SAlexander Shishkin unsigned int ndevres, int irq); 17839f40346SAlexander Shishkin void intel_th_free(struct intel_th *th); 17939f40346SAlexander Shishkin 18039f40346SAlexander Shishkin int intel_th_driver_register(struct intel_th_driver *thdrv); 18139f40346SAlexander Shishkin void intel_th_driver_unregister(struct intel_th_driver *thdrv); 18239f40346SAlexander Shishkin 18339f40346SAlexander Shishkin int intel_th_trace_enable(struct intel_th_device *thdev); 18439f40346SAlexander Shishkin int intel_th_trace_disable(struct intel_th_device *thdev); 18539f40346SAlexander Shishkin int intel_th_set_output(struct intel_th_device *thdev, 18639f40346SAlexander Shishkin unsigned int master); 18739f40346SAlexander Shishkin 18839f40346SAlexander Shishkin enum { 18939f40346SAlexander Shishkin TH_MMIO_CONFIG = 0, 19039f40346SAlexander Shishkin TH_MMIO_SW = 2, 19139f40346SAlexander Shishkin TH_MMIO_END, 19239f40346SAlexander Shishkin }; 19339f40346SAlexander Shishkin 19439f40346SAlexander Shishkin #define TH_SUBDEVICE_MAX 6 19539f40346SAlexander Shishkin #define TH_POSSIBLE_OUTPUTS 8 19639f40346SAlexander Shishkin #define TH_CONFIGURABLE_MASTERS 256 19739f40346SAlexander Shishkin #define TH_MSC_MAX 2 19839f40346SAlexander Shishkin 19939f40346SAlexander Shishkin /** 20039f40346SAlexander Shishkin * struct intel_th - Intel TH controller 20139f40346SAlexander Shishkin * @dev: driver core's device 20239f40346SAlexander Shishkin * @thdev: subdevices 20339f40346SAlexander Shishkin * @hub: "switch" subdevice (GTH) 20439f40346SAlexander Shishkin * @id: this Intel TH controller's device ID in the system 20539f40346SAlexander Shishkin * @major: device node major for output devices 20639f40346SAlexander Shishkin */ 20739f40346SAlexander Shishkin struct intel_th { 20839f40346SAlexander Shishkin struct device *dev; 20939f40346SAlexander Shishkin 21039f40346SAlexander Shishkin struct intel_th_device *thdev[TH_SUBDEVICE_MAX]; 21139f40346SAlexander Shishkin struct intel_th_device *hub; 21239f40346SAlexander Shishkin 21339f40346SAlexander Shishkin int id; 21439f40346SAlexander Shishkin int major; 215a36aa80fSAlexander Shishkin #ifdef CONFIG_MODULES 216a36aa80fSAlexander Shishkin struct work_struct request_module_work; 217a36aa80fSAlexander Shishkin #endif /* CONFIG_MODULES */ 21839f40346SAlexander Shishkin #ifdef CONFIG_INTEL_TH_DEBUG 21939f40346SAlexander Shishkin struct dentry *dbg; 22039f40346SAlexander Shishkin #endif 22139f40346SAlexander Shishkin }; 22239f40346SAlexander Shishkin 22339f40346SAlexander Shishkin /* 22439f40346SAlexander Shishkin * Register windows 22539f40346SAlexander Shishkin */ 22639f40346SAlexander Shishkin enum { 22739f40346SAlexander Shishkin /* Global Trace Hub (GTH) */ 22839f40346SAlexander Shishkin REG_GTH_OFFSET = 0x0000, 22939f40346SAlexander Shishkin REG_GTH_LENGTH = 0x2000, 23039f40346SAlexander Shishkin 23139f40346SAlexander Shishkin /* Software Trace Hub (STH) [0x4000..0x4fff] */ 23239f40346SAlexander Shishkin REG_STH_OFFSET = 0x4000, 23339f40346SAlexander Shishkin REG_STH_LENGTH = 0x2000, 23439f40346SAlexander Shishkin 23539f40346SAlexander Shishkin /* Memory Storage Unit (MSU) [0xa0000..0xa1fff] */ 23639f40346SAlexander Shishkin REG_MSU_OFFSET = 0xa0000, 23739f40346SAlexander Shishkin REG_MSU_LENGTH = 0x02000, 23839f40346SAlexander Shishkin 23939f40346SAlexander Shishkin /* Internal MSU trace buffer [0x80000..0x9ffff] */ 24039f40346SAlexander Shishkin BUF_MSU_OFFSET = 0x80000, 24139f40346SAlexander Shishkin BUF_MSU_LENGTH = 0x20000, 24239f40346SAlexander Shishkin 24339f40346SAlexander Shishkin /* PTI output == same window as GTH */ 24439f40346SAlexander Shishkin REG_PTI_OFFSET = REG_GTH_OFFSET, 24539f40346SAlexander Shishkin REG_PTI_LENGTH = REG_GTH_LENGTH, 24639f40346SAlexander Shishkin 24739f40346SAlexander Shishkin /* DCI Handler (DCIH) == some window as MSU */ 24839f40346SAlexander Shishkin REG_DCIH_OFFSET = REG_MSU_OFFSET, 24939f40346SAlexander Shishkin REG_DCIH_LENGTH = REG_MSU_LENGTH, 25039f40346SAlexander Shishkin }; 25139f40346SAlexander Shishkin 25239f40346SAlexander Shishkin /* 25339f40346SAlexander Shishkin * GTH, output ports configuration 25439f40346SAlexander Shishkin */ 25539f40346SAlexander Shishkin enum { 25639f40346SAlexander Shishkin GTH_NONE = 0, 25739f40346SAlexander Shishkin GTH_MSU, /* memory/usb */ 25839f40346SAlexander Shishkin GTH_CTP, /* Common Trace Port */ 25939f40346SAlexander Shishkin GTH_PTI = 4, /* MIPI-PTI */ 26039f40346SAlexander Shishkin }; 26139f40346SAlexander Shishkin 2624d02ceffSAlexander Shishkin /* 2634d02ceffSAlexander Shishkin * Scratchpad bits: tell firmware and external debuggers 2644d02ceffSAlexander Shishkin * what we are up to. 2654d02ceffSAlexander Shishkin */ 2664d02ceffSAlexander Shishkin enum { 2674d02ceffSAlexander Shishkin /* Memory is the primary destination */ 2684d02ceffSAlexander Shishkin SCRPD_MEM_IS_PRIM_DEST = BIT(0), 2694d02ceffSAlexander Shishkin /* XHCI DbC is the primary destination */ 2704d02ceffSAlexander Shishkin SCRPD_DBC_IS_PRIM_DEST = BIT(1), 2714d02ceffSAlexander Shishkin /* PTI is the primary destination */ 2724d02ceffSAlexander Shishkin SCRPD_PTI_IS_PRIM_DEST = BIT(2), 2734d02ceffSAlexander Shishkin /* BSSB is the primary destination */ 2744d02ceffSAlexander Shishkin SCRPD_BSSB_IS_PRIM_DEST = BIT(3), 2754d02ceffSAlexander Shishkin /* PTI is the alternate destination */ 2764d02ceffSAlexander Shishkin SCRPD_PTI_IS_ALT_DEST = BIT(4), 2774d02ceffSAlexander Shishkin /* BSSB is the alternate destination */ 2784d02ceffSAlexander Shishkin SCRPD_BSSB_IS_ALT_DEST = BIT(5), 2794d02ceffSAlexander Shishkin /* DeepSx exit occurred */ 2804d02ceffSAlexander Shishkin SCRPD_DEEPSX_EXIT = BIT(6), 2814d02ceffSAlexander Shishkin /* S4 exit occurred */ 2824d02ceffSAlexander Shishkin SCRPD_S4_EXIT = BIT(7), 2834d02ceffSAlexander Shishkin /* S5 exit occurred */ 2844d02ceffSAlexander Shishkin SCRPD_S5_EXIT = BIT(8), 2854d02ceffSAlexander Shishkin /* MSU controller 0/1 is enabled */ 2864d02ceffSAlexander Shishkin SCRPD_MSC0_IS_ENABLED = BIT(9), 2874d02ceffSAlexander Shishkin SCRPD_MSC1_IS_ENABLED = BIT(10), 2884d02ceffSAlexander Shishkin /* Sx exit occurred */ 2894d02ceffSAlexander Shishkin SCRPD_SX_EXIT = BIT(11), 2904d02ceffSAlexander Shishkin /* Trigger Unit is enabled */ 2914d02ceffSAlexander Shishkin SCRPD_TRIGGER_IS_ENABLED = BIT(12), 2924d02ceffSAlexander Shishkin SCRPD_ODLA_IS_ENABLED = BIT(13), 2934d02ceffSAlexander Shishkin SCRPD_SOCHAP_IS_ENABLED = BIT(14), 2944d02ceffSAlexander Shishkin SCRPD_STH_IS_ENABLED = BIT(15), 2954d02ceffSAlexander Shishkin SCRPD_DCIH_IS_ENABLED = BIT(16), 2964d02ceffSAlexander Shishkin SCRPD_VER_IS_ENABLED = BIT(17), 2974d02ceffSAlexander Shishkin /* External debugger is using Intel TH */ 2984d02ceffSAlexander Shishkin SCRPD_DEBUGGER_IN_USE = BIT(24), 2994d02ceffSAlexander Shishkin }; 3004d02ceffSAlexander Shishkin 30139f40346SAlexander Shishkin #endif 302