blob: 9cae1224313fee5d84ef03e008ee9a8376015d90 [file] [log] [blame]
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -08001/*
2 **************************************************************************
Guojun Jinf7f90f82018-08-16 18:09:23 -07003 * Copyright (c) 2014, 2018 The Linux Foundation. All rights reserved.
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -08004 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all copies.
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
13 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 **************************************************************************
15 */
16
17/*
Guojun Jinf7f90f82018-08-16 18:09:23 -070018 * nss profile node.h
19 * device node for the profiler, for communicating between FW and GUI via host
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -080020 */
21
22#include "profilesample.h"
23
Guojun Jinf7f90f82018-08-16 18:09:23 -070024#define NSS_PROFILE_HD_MAGIC 0x4F525000 /* 0 + "PRO" */
25#define NSS_PROFILE_HD_MAGIC_REV 0x0050524F /* different endian */
26#define NSS_PROFILE_HD_MMASK 0xFFFFFF00 /* 1st byte is Rx/Tx cmd */
27#define NSS_PROFILE_HD_MMASK_REV 0x00FFFFFF
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -080028
Guojun Jinf7f90f82018-08-16 18:09:23 -070029struct nss_profile_sample_ctrl {
30 uint32_t psc_magic; /* MAGIC + cmd for packet and endianess check */
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -080031
32 /*
Guojun Jinf7f90f82018-08-16 18:09:23 -070033 * controlling data need to be sent to and used by upper layer (HLOS).
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -080034 */
Guojun Jinf7f90f82018-08-16 18:09:23 -070035 uint16_t ps_count; /* number of valid samples */
36 uint16_t ps_max_samples; /* how many samples can be in the samples array */
37 uint32_t ps_dropped; /* how many samples did the profiler drop due to buffer overruns */
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -080038
39 /*
40 * info data -- sent to remote profiler tool (need swap)
41 */
Guojun Jinf7f90f82018-08-16 18:09:23 -070042 struct profile_ext_header ex_hd;
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -080043
44};
45
46/*
47 * # of sample buffers in pbuf payload
48 */
49#ifndef PBUF_PAYLOAD_SIZE
Guojun Jinf7f90f82018-08-16 18:09:23 -070050#define PBUF_PAYLOAD_SIZE 1792 /* for HLOS driver: must sync with pbuf_public */
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -080051typedef enum meta_types {
52 PINGPONG_EMPTY,
53 PINGPONG_FULL,
54 PINGPONG_INUSE,
55} flowctrl_t;
56#else
Guojun Jinf7f90f82018-08-16 18:09:23 -070057typedef enum pnode_c2h_metadata_types flowctrl_t; /* for NSS driver */
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -080058#endif
59
Guojun Jinf7f90f82018-08-16 18:09:23 -070060#define MAX_SAMPLES_PER_PBUF ((PBUF_PAYLOAD_SIZE - sizeof(struct nss_profile_sample_ctrl)) / sizeof(struct nss_profile_sample))
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -080061
62struct n2h_meta_header {
Guojun Jinf7f90f82018-08-16 18:09:23 -070063 flowctrl_t md_type; /* N2H (NSS) and receiver (HLOS) flow control (meta type) */
64 uint32_t d_len; /* total data length start from psc_header */
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -080065};
66
Guojun Jinf7f90f82018-08-16 18:09:23 -070067struct nss_profile_session { /* use for per session start */
68 uint32_t hd_magic; /* common ovarlay in all headers */
Guojun Jin3deae8c2016-08-23 15:51:21 -070069 uint8_t num_counters; /* # performance (app) counters registered (changeable) */
70 uint8_t unused1B;
71 uint8_t nc_sts_sel_thrA;
72 uint8_t nc_sts_sel_thrB;
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -080073 uint32_t ocm_size;
74 uint32_t sram_start;
75
Guojun Jinf7f90f82018-08-16 18:09:23 -070076 uint32_t rate; /* sampling rate */
77 uint32_t cpu_id; /* chip_id register */
78 uint32_t cpu_freq; /* chip clock */
79 uint32_t ddr_freq; /* DDR MEM speed */
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -080080 struct profile_counter counters[PROFILE_MAX_APP_COUNTERS];
81};
82
Guojun Jinf7f90f82018-08-16 18:09:23 -070083struct nss_profile_n2h_sample_buf {
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -080084 struct n2h_meta_header mh;
85
Guojun Jinf7f90f82018-08-16 18:09:23 -070086 struct nss_profile_sample_ctrl psc_header; /* per sample period */
87 struct nss_profile_sample samples[MAX_SAMPLES_PER_PBUF]; /* per thread samples - for NSS send */
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -080088};
89
Guojun Jinf7f90f82018-08-16 18:09:23 -070090struct nss_profile_common {
91 struct nss_profile_session un;
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -080092 /*
93 * changable data sent everything pbuf
94 */
Guojun Jinf7f90f82018-08-16 18:09:23 -070095 struct nss_profile_n2h_sample_buf *pn2h; /* sampling ctrl for this sample period */
96 struct nss_profile_sample *samples; /* samples array was allocated by the linux driver */
97 /* now NSS points it to pbuf + pn2h header */
98 uint16_t cur; /* pos where driver take (read) samples */
99 int16_t enabled; /* Is the profiler enabled to take samples? */
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -0800100};
101
102/*
Guojun Jinf7f90f82018-08-16 18:09:23 -0700103 * Each buffer holds 4-7 sets (sample intrs) of samples, by average 5 sets per buffer
104 * at 10ms sample clock; 1s sleep in profilerd requires kernel to have 1000 / 10 / 5 = 20
105 * buffers to store one 1s samples. For higher sampling rate, either kernel needs more
106 * buffers or profilerd needs less sleep time, but both needs to make match.
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -0800107 */
108#define CCL_SIZE 32
109
110struct profile_io {
Guojun Jinf7f90f82018-08-16 18:09:23 -0700111 struct nss_profile_common pnc;
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -0800112
113 /*
114 * control fields - HLOS
115 */
116 void *ctx; // nss_ctx for Linux driver
117 int profile_first_packet;
118 int profile_sequence_num;
119
120 /*
121 * circular buffers for psc_header/samples
122 */
Guojun Jinf7f90f82018-08-16 18:09:23 -0700123 struct nss_profile_n2h_sample_buf *ccl;
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -0800124 int ccl_read;
125 int ccl_write;
126
127 /*
128 * data from HLOS -- used to generate sample->pid in ULTRA -- no longer needed in NSS
Guojun Jinf7f90f82018-08-16 18:09:23 -0700129 * uint32_t task_offset; offset in bytes in thread_info to task_struct pointer
130 * uint32_t pid_offset; offset in bytes in task_struct to the PID
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -0800131 */
132 uint32_t *sw_ksp_ptr; // pointer to array (per hardware thread) of pointers to struct thread_info
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -0800133};
134
135/*
Guojun Jinf7f90f82018-08-16 18:09:23 -0700136 * Krait <--> NSS debug mechanism. It lays over on nss_profile_n2h_sample_buf.samples (ccl->samples)
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -0800137 */
138#define MAX_DB_WR 28 // profile_session has 31 4B words data (32W total with hd_magic) and
139#define MAX_DB_RD 30 // common has two more ptrs
140struct debug_box { // this overlays with profile_common (RD) or profile_session (WR)
141 uint32_t hd_magic; // cmd + MAGIC for packet and endianess check
142
143 uint32_t opts;
Guojun Jina09b8b02018-01-25 16:34:43 -0800144 int32_t base_addr; /* Ubi32 is 32-bit */
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -0800145 int32_t dlen; // in 4B words
146 uint32_t data[MAX_DB_RD];
147};
148
149#define DEBUG_OPT_BCTRL 1 // basic CTRL
150#define DEBUG_OPT_MOVEIO (1<<1) // force to use moveio in case new OCP range is added