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 5739f40346SAlexander Shishkin * @output: output descriptor for INTEL_TH_OUTPUT devices 5839f40346SAlexander Shishkin * @name: device name to match the driver 5939f40346SAlexander Shishkin */ 6039f40346SAlexander Shishkin struct intel_th_device { 6139f40346SAlexander Shishkin struct device dev; 6239f40346SAlexander Shishkin struct resource *resource; 6339f40346SAlexander Shishkin unsigned int num_resources; 6439f40346SAlexander Shishkin unsigned int type; 6539f40346SAlexander Shishkin int id; 6639f40346SAlexander Shishkin 6739f40346SAlexander Shishkin /* INTEL_TH_OUTPUT specific */ 6839f40346SAlexander Shishkin struct intel_th_output output; 6939f40346SAlexander Shishkin 7039f40346SAlexander Shishkin char name[]; 7139f40346SAlexander Shishkin }; 7239f40346SAlexander Shishkin 7339f40346SAlexander Shishkin #define to_intel_th_device(_d) \ 7439f40346SAlexander Shishkin container_of((_d), struct intel_th_device, dev) 7539f40346SAlexander Shishkin 7639f40346SAlexander Shishkin /** 7739f40346SAlexander Shishkin * intel_th_device_get_resource() - obtain @num'th resource of type @type 7839f40346SAlexander Shishkin * @thdev: the device to search the resource for 7939f40346SAlexander Shishkin * @type: resource type 8039f40346SAlexander Shishkin * @num: number of the resource 8139f40346SAlexander Shishkin */ 8239f40346SAlexander Shishkin static inline struct resource * 8339f40346SAlexander Shishkin intel_th_device_get_resource(struct intel_th_device *thdev, unsigned int type, 8439f40346SAlexander Shishkin unsigned int num) 8539f40346SAlexander Shishkin { 8639f40346SAlexander Shishkin int i; 8739f40346SAlexander Shishkin 8839f40346SAlexander Shishkin for (i = 0; i < thdev->num_resources; i++) 8939f40346SAlexander Shishkin if (resource_type(&thdev->resource[i]) == type && !num--) 9039f40346SAlexander Shishkin return &thdev->resource[i]; 9139f40346SAlexander Shishkin 9239f40346SAlexander Shishkin return NULL; 9339f40346SAlexander Shishkin } 9439f40346SAlexander Shishkin 9539f40346SAlexander Shishkin /** 9639f40346SAlexander Shishkin * intel_th_output_assigned() - if an output device is assigned to a switch port 9739f40346SAlexander Shishkin * @thdev: the output device 9839f40346SAlexander Shishkin * 9939f40346SAlexander Shishkin * Return: true if the device is INTEL_TH_OUTPUT *and* is assigned a port 10039f40346SAlexander Shishkin */ 10139f40346SAlexander Shishkin static inline bool 10239f40346SAlexander Shishkin intel_th_output_assigned(struct intel_th_device *thdev) 10339f40346SAlexander Shishkin { 10439f40346SAlexander Shishkin return thdev->type == INTEL_TH_OUTPUT && 10539f40346SAlexander Shishkin thdev->output.port >= 0; 10639f40346SAlexander Shishkin } 10739f40346SAlexander Shishkin 10839f40346SAlexander Shishkin /** 10939f40346SAlexander Shishkin * struct intel_th_driver - driver for an intel_th_device device 11039f40346SAlexander Shishkin * @driver: generic driver 11139f40346SAlexander Shishkin * @probe: probe method 11239f40346SAlexander Shishkin * @remove: remove method 11339f40346SAlexander Shishkin * @assign: match a given output type device against available outputs 11439f40346SAlexander Shishkin * @unassign: deassociate an output type device from an output port 11539f40346SAlexander Shishkin * @enable: enable tracing for a given output device 11639f40346SAlexander Shishkin * @disable: disable tracing for a given output device 11739f40346SAlexander Shishkin * @fops: file operations for device nodes 118*b5edbf1eSAlexander Shishkin * @attr_group: attributes provided by the driver 11939f40346SAlexander Shishkin * 12039f40346SAlexander Shishkin * Callbacks @probe and @remove are required for all device types. 12139f40346SAlexander Shishkin * Switch device driver needs to fill in @assign, @enable and @disable 12239f40346SAlexander Shishkin * callbacks. 12339f40346SAlexander Shishkin */ 12439f40346SAlexander Shishkin struct intel_th_driver { 12539f40346SAlexander Shishkin struct device_driver driver; 12639f40346SAlexander Shishkin int (*probe)(struct intel_th_device *thdev); 12739f40346SAlexander Shishkin void (*remove)(struct intel_th_device *thdev); 12839f40346SAlexander Shishkin /* switch (GTH) ops */ 12939f40346SAlexander Shishkin int (*assign)(struct intel_th_device *thdev, 13039f40346SAlexander Shishkin struct intel_th_device *othdev); 13139f40346SAlexander Shishkin void (*unassign)(struct intel_th_device *thdev, 13239f40346SAlexander Shishkin struct intel_th_device *othdev); 13339f40346SAlexander Shishkin void (*enable)(struct intel_th_device *thdev, 13439f40346SAlexander Shishkin struct intel_th_output *output); 13539f40346SAlexander Shishkin void (*disable)(struct intel_th_device *thdev, 13639f40346SAlexander Shishkin struct intel_th_output *output); 13739f40346SAlexander Shishkin /* output ops */ 13839f40346SAlexander Shishkin void (*irq)(struct intel_th_device *thdev); 13939f40346SAlexander Shishkin int (*activate)(struct intel_th_device *thdev); 14039f40346SAlexander Shishkin void (*deactivate)(struct intel_th_device *thdev); 14139f40346SAlexander Shishkin /* file_operations for those who want a device node */ 14239f40346SAlexander Shishkin const struct file_operations *fops; 143*b5edbf1eSAlexander Shishkin /* optional attributes */ 144*b5edbf1eSAlexander Shishkin struct attribute_group *attr_group; 14539f40346SAlexander Shishkin 14639f40346SAlexander Shishkin /* source ops */ 14739f40346SAlexander Shishkin int (*set_output)(struct intel_th_device *thdev, 14839f40346SAlexander Shishkin unsigned int master); 14939f40346SAlexander Shishkin }; 15039f40346SAlexander Shishkin 15139f40346SAlexander Shishkin #define to_intel_th_driver(_d) \ 15239f40346SAlexander Shishkin container_of((_d), struct intel_th_driver, driver) 15339f40346SAlexander Shishkin 15439f40346SAlexander Shishkin static inline struct intel_th_device * 15539f40346SAlexander Shishkin to_intel_th_hub(struct intel_th_device *thdev) 15639f40346SAlexander Shishkin { 15739f40346SAlexander Shishkin struct device *parent = thdev->dev.parent; 15839f40346SAlexander Shishkin 15939f40346SAlexander Shishkin if (!parent) 16039f40346SAlexander Shishkin return NULL; 16139f40346SAlexander Shishkin 16239f40346SAlexander Shishkin return to_intel_th_device(parent); 16339f40346SAlexander Shishkin } 16439f40346SAlexander Shishkin 16539f40346SAlexander Shishkin struct intel_th * 16639f40346SAlexander Shishkin intel_th_alloc(struct device *dev, struct resource *devres, 16739f40346SAlexander Shishkin unsigned int ndevres, int irq); 16839f40346SAlexander Shishkin void intel_th_free(struct intel_th *th); 16939f40346SAlexander Shishkin 17039f40346SAlexander Shishkin int intel_th_driver_register(struct intel_th_driver *thdrv); 17139f40346SAlexander Shishkin void intel_th_driver_unregister(struct intel_th_driver *thdrv); 17239f40346SAlexander Shishkin 17339f40346SAlexander Shishkin int intel_th_trace_enable(struct intel_th_device *thdev); 17439f40346SAlexander Shishkin int intel_th_trace_disable(struct intel_th_device *thdev); 17539f40346SAlexander Shishkin int intel_th_set_output(struct intel_th_device *thdev, 17639f40346SAlexander Shishkin unsigned int master); 17739f40346SAlexander Shishkin 17839f40346SAlexander Shishkin enum { 17939f40346SAlexander Shishkin TH_MMIO_CONFIG = 0, 18039f40346SAlexander Shishkin TH_MMIO_SW = 2, 18139f40346SAlexander Shishkin TH_MMIO_END, 18239f40346SAlexander Shishkin }; 18339f40346SAlexander Shishkin 18439f40346SAlexander Shishkin #define TH_SUBDEVICE_MAX 6 18539f40346SAlexander Shishkin #define TH_POSSIBLE_OUTPUTS 8 18639f40346SAlexander Shishkin #define TH_CONFIGURABLE_MASTERS 256 18739f40346SAlexander Shishkin #define TH_MSC_MAX 2 18839f40346SAlexander Shishkin 18939f40346SAlexander Shishkin /** 19039f40346SAlexander Shishkin * struct intel_th - Intel TH controller 19139f40346SAlexander Shishkin * @dev: driver core's device 19239f40346SAlexander Shishkin * @thdev: subdevices 19339f40346SAlexander Shishkin * @hub: "switch" subdevice (GTH) 19439f40346SAlexander Shishkin * @id: this Intel TH controller's device ID in the system 19539f40346SAlexander Shishkin * @major: device node major for output devices 19639f40346SAlexander Shishkin */ 19739f40346SAlexander Shishkin struct intel_th { 19839f40346SAlexander Shishkin struct device *dev; 19939f40346SAlexander Shishkin 20039f40346SAlexander Shishkin struct intel_th_device *thdev[TH_SUBDEVICE_MAX]; 20139f40346SAlexander Shishkin struct intel_th_device *hub; 20239f40346SAlexander Shishkin 20339f40346SAlexander Shishkin int id; 20439f40346SAlexander Shishkin int major; 20539f40346SAlexander Shishkin #ifdef CONFIG_INTEL_TH_DEBUG 20639f40346SAlexander Shishkin struct dentry *dbg; 20739f40346SAlexander Shishkin #endif 20839f40346SAlexander Shishkin }; 20939f40346SAlexander Shishkin 21039f40346SAlexander Shishkin /* 21139f40346SAlexander Shishkin * Register windows 21239f40346SAlexander Shishkin */ 21339f40346SAlexander Shishkin enum { 21439f40346SAlexander Shishkin /* Global Trace Hub (GTH) */ 21539f40346SAlexander Shishkin REG_GTH_OFFSET = 0x0000, 21639f40346SAlexander Shishkin REG_GTH_LENGTH = 0x2000, 21739f40346SAlexander Shishkin 21839f40346SAlexander Shishkin /* Software Trace Hub (STH) [0x4000..0x4fff] */ 21939f40346SAlexander Shishkin REG_STH_OFFSET = 0x4000, 22039f40346SAlexander Shishkin REG_STH_LENGTH = 0x2000, 22139f40346SAlexander Shishkin 22239f40346SAlexander Shishkin /* Memory Storage Unit (MSU) [0xa0000..0xa1fff] */ 22339f40346SAlexander Shishkin REG_MSU_OFFSET = 0xa0000, 22439f40346SAlexander Shishkin REG_MSU_LENGTH = 0x02000, 22539f40346SAlexander Shishkin 22639f40346SAlexander Shishkin /* Internal MSU trace buffer [0x80000..0x9ffff] */ 22739f40346SAlexander Shishkin BUF_MSU_OFFSET = 0x80000, 22839f40346SAlexander Shishkin BUF_MSU_LENGTH = 0x20000, 22939f40346SAlexander Shishkin 23039f40346SAlexander Shishkin /* PTI output == same window as GTH */ 23139f40346SAlexander Shishkin REG_PTI_OFFSET = REG_GTH_OFFSET, 23239f40346SAlexander Shishkin REG_PTI_LENGTH = REG_GTH_LENGTH, 23339f40346SAlexander Shishkin 23439f40346SAlexander Shishkin /* DCI Handler (DCIH) == some window as MSU */ 23539f40346SAlexander Shishkin REG_DCIH_OFFSET = REG_MSU_OFFSET, 23639f40346SAlexander Shishkin REG_DCIH_LENGTH = REG_MSU_LENGTH, 23739f40346SAlexander Shishkin }; 23839f40346SAlexander Shishkin 23939f40346SAlexander Shishkin /* 24039f40346SAlexander Shishkin * GTH, output ports configuration 24139f40346SAlexander Shishkin */ 24239f40346SAlexander Shishkin enum { 24339f40346SAlexander Shishkin GTH_NONE = 0, 24439f40346SAlexander Shishkin GTH_MSU, /* memory/usb */ 24539f40346SAlexander Shishkin GTH_CTP, /* Common Trace Port */ 24639f40346SAlexander Shishkin GTH_PTI = 4, /* MIPI-PTI */ 24739f40346SAlexander Shishkin }; 24839f40346SAlexander Shishkin 2494d02ceffSAlexander Shishkin /* 2504d02ceffSAlexander Shishkin * Scratchpad bits: tell firmware and external debuggers 2514d02ceffSAlexander Shishkin * what we are up to. 2524d02ceffSAlexander Shishkin */ 2534d02ceffSAlexander Shishkin enum { 2544d02ceffSAlexander Shishkin /* Memory is the primary destination */ 2554d02ceffSAlexander Shishkin SCRPD_MEM_IS_PRIM_DEST = BIT(0), 2564d02ceffSAlexander Shishkin /* XHCI DbC is the primary destination */ 2574d02ceffSAlexander Shishkin SCRPD_DBC_IS_PRIM_DEST = BIT(1), 2584d02ceffSAlexander Shishkin /* PTI is the primary destination */ 2594d02ceffSAlexander Shishkin SCRPD_PTI_IS_PRIM_DEST = BIT(2), 2604d02ceffSAlexander Shishkin /* BSSB is the primary destination */ 2614d02ceffSAlexander Shishkin SCRPD_BSSB_IS_PRIM_DEST = BIT(3), 2624d02ceffSAlexander Shishkin /* PTI is the alternate destination */ 2634d02ceffSAlexander Shishkin SCRPD_PTI_IS_ALT_DEST = BIT(4), 2644d02ceffSAlexander Shishkin /* BSSB is the alternate destination */ 2654d02ceffSAlexander Shishkin SCRPD_BSSB_IS_ALT_DEST = BIT(5), 2664d02ceffSAlexander Shishkin /* DeepSx exit occurred */ 2674d02ceffSAlexander Shishkin SCRPD_DEEPSX_EXIT = BIT(6), 2684d02ceffSAlexander Shishkin /* S4 exit occurred */ 2694d02ceffSAlexander Shishkin SCRPD_S4_EXIT = BIT(7), 2704d02ceffSAlexander Shishkin /* S5 exit occurred */ 2714d02ceffSAlexander Shishkin SCRPD_S5_EXIT = BIT(8), 2724d02ceffSAlexander Shishkin /* MSU controller 0/1 is enabled */ 2734d02ceffSAlexander Shishkin SCRPD_MSC0_IS_ENABLED = BIT(9), 2744d02ceffSAlexander Shishkin SCRPD_MSC1_IS_ENABLED = BIT(10), 2754d02ceffSAlexander Shishkin /* Sx exit occurred */ 2764d02ceffSAlexander Shishkin SCRPD_SX_EXIT = BIT(11), 2774d02ceffSAlexander Shishkin /* Trigger Unit is enabled */ 2784d02ceffSAlexander Shishkin SCRPD_TRIGGER_IS_ENABLED = BIT(12), 2794d02ceffSAlexander Shishkin SCRPD_ODLA_IS_ENABLED = BIT(13), 2804d02ceffSAlexander Shishkin SCRPD_SOCHAP_IS_ENABLED = BIT(14), 2814d02ceffSAlexander Shishkin SCRPD_STH_IS_ENABLED = BIT(15), 2824d02ceffSAlexander Shishkin SCRPD_DCIH_IS_ENABLED = BIT(16), 2834d02ceffSAlexander Shishkin SCRPD_VER_IS_ENABLED = BIT(17), 2844d02ceffSAlexander Shishkin /* External debugger is using Intel TH */ 2854d02ceffSAlexander Shishkin SCRPD_DEBUGGER_IN_USE = BIT(24), 2864d02ceffSAlexander Shishkin }; 2874d02ceffSAlexander Shishkin 28839f40346SAlexander Shishkin #endif 289