/*
 * Copyright (C) 2012-2014, 2016 ARM Limited. All rights reserved.
 * 
 * This program is free software and is provided to you under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
 * 
 * A copy of the licence is included with the program, and can also be obtained from Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#if !defined (MALI_LINUX_TRACE_H) || defined (TRACE_HEADER_MULTI_READ)
#define MALI_LINUX_TRACE_H

#include <linux/types.h>

#include <linux/stringify.h>
#include <linux/tracepoint.h>

#undef  TRACE_SYSTEM
#define TRACE_SYSTEM mali
#define TRACE_SYSTEM_STRING __stringfy(TRACE_SYSTEM)

#define TRACE_INCLUDE_PATH .
#define TRACE_INCLUDE_FILE mali_linux_trace

/**
 * Define the tracepoint used to communicate the status of a GPU. Called
 * when a GPU turns on or turns off.
 *
 * @param event_id The type of the event. This parameter is a bitfield
 *  encoding the type of the event.
 *
 * @param d0 First data parameter.
 * @param d1 Second data parameter.
 * @param d2 Third data parameter.
 * @param d3 Fourth data parameter.
 * @param d4 Fifth data parameter.
 */
TRACE_EVENT(mali_timeline_event,

	    TP_PROTO(unsigned int event_id, unsigned int d0, unsigned int d1,
		     unsigned int d2, unsigned int d3, unsigned int d4),

	    TP_ARGS(event_id, d0, d1, d2, d3, d4),

	    TP_STRUCT__entry(
		    __field(unsigned int, event_id)
		    __field(unsigned int, d0)
		    __field(unsigned int, d1)
		    __field(unsigned int, d2)
		    __field(unsigned int, d3)
		    __field(unsigned int, d4)
	    ),

	    TP_fast_assign(
		    __entry->event_id = event_id;
		    __entry->d0 = d0;
		    __entry->d1 = d1;
		    __entry->d2 = d2;
		    __entry->d3 = d3;
		    __entry->d4 = d4;
	    ),

	    TP_printk("event=%d", __entry->event_id)
	   );

/**
 * Define a tracepoint used to regsiter the value of a hardware counter.
 * Hardware counters belonging to the vertex or fragment processor are
 * reported via this tracepoint each frame, whilst L2 cache hardware
 * counters are reported continuously.
 *
 * @param counter_id The counter ID.
 * @param value The value of the counter.
 */
TRACE_EVENT(mali_hw_counter,

	    TP_PROTO(unsigned int counter_id, unsigned int value),

	    TP_ARGS(counter_id, value),

	    TP_STRUCT__entry(
		    __field(unsigned int, counter_id)
		    __field(unsigned int, value)
	    ),

	    TP_fast_assign(
		    __entry->counter_id = counter_id;
	    ),

	    TP_printk("event %d = %d", __entry->counter_id, __entry->value)
	   );

/**
 * Define a tracepoint used to send a bundle of software counters.
 *
 * @param counters The bundle of counters.
 */
TRACE_EVENT(mali_sw_counters,

	    TP_PROTO(pid_t pid, pid_t tid, void *surface_id, unsigned int *counters),

	    TP_ARGS(pid, tid, surface_id, counters),

	    TP_STRUCT__entry(
		    __field(pid_t, pid)
		    __field(pid_t, tid)
		    __field(void *, surface_id)
		    __field(unsigned int *, counters)
	    ),

	    TP_fast_assign(
		    __entry->pid = pid;
		    __entry->tid = tid;
		    __entry->surface_id = surface_id;
		    __entry->counters = counters;
	    ),

	    TP_printk("counters were %s", __entry->counters == NULL ? "NULL" : "not NULL")
	   );

/**
 * Define a tracepoint used to gather core activity for systrace
 * @param pid The process id for which the core activity originates from
 * @param active If the core is active (1) or not (0)
 * @param core_type The type of core active, either GP (1) or PP (0)
 * @param core_id The core id that is active for the core_type
 * @param frame_builder_id The frame builder id associated with this core activity
 * @param flush_id The flush id associated with this core activity
 */
TRACE_EVENT(mali_core_active,

	    TP_PROTO(pid_t pid, unsigned int active, unsigned int core_type, unsigned int core_id, unsigned int frame_builder_id, unsigned int flush_id),

	    TP_ARGS(pid, active, core_type, core_id, frame_builder_id, flush_id),

	    TP_STRUCT__entry(
		    __field(pid_t, pid)
		    __field(unsigned int, active)
		    __field(unsigned int, core_type)
		    __field(unsigned int, core_id)
		    __field(unsigned int, frame_builder_id)
		    __field(unsigned int, flush_id)
	    ),

	    TP_fast_assign(
		    __entry->pid = pid;
		    __entry->active = active;
		    __entry->core_type = core_type;
		    __entry->core_id = core_id;
		    __entry->frame_builder_id = frame_builder_id;
		    __entry->flush_id = flush_id;
	    ),

	    TP_printk("%s|%d|%s%i:%x|%d", __entry->active ? "S" : "F", __entry->pid, __entry->core_type ? "GP" : "PP", __entry->core_id, __entry->flush_id, __entry->frame_builder_id)
	   );

#endif /* MALI_LINUX_TRACE_H */

/* This part must exist outside the header guard. */
#include <trace/define_trace.h>

