17ec681f3Smrg/*
27ec681f3Smrg * Copyright © 2018 Intel Corporation
37ec681f3Smrg *
47ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a
57ec681f3Smrg * copy of this software and associated documentation files (the "Software"),
67ec681f3Smrg * to deal in the Software without restriction, including without limitation
77ec681f3Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
87ec681f3Smrg * and/or sell copies of the Software, and to permit persons to whom the
97ec681f3Smrg * Software is furnished to do so, subject to the following conditions:
107ec681f3Smrg *
117ec681f3Smrg * The above copyright notice and this permission notice (including the next
127ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the
137ec681f3Smrg * Software.
147ec681f3Smrg *
157ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
167ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
177ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
187ec681f3Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
197ec681f3Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
207ec681f3Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
217ec681f3Smrg * IN THE SOFTWARE.
227ec681f3Smrg */
237ec681f3Smrg
247ec681f3Smrg#ifndef INTEL_PERF_MDAPI_H
257ec681f3Smrg#define INTEL_PERF_MDAPI_H
267ec681f3Smrg
277ec681f3Smrg#include <stdint.h>
287ec681f3Smrg
297ec681f3Smrg#include "dev/intel_device_info.h"
307ec681f3Smrg
317ec681f3Smrgstruct intel_perf_query_result;
327ec681f3Smrg
337ec681f3Smrg/* Guid has to matches with MDAPI's. */
347ec681f3Smrg#define INTEL_PERF_QUERY_GUID_MDAPI "2f01b241-7014-42a7-9eb6-a925cad3daba"
357ec681f3Smrg
367ec681f3Smrg/*
377ec681f3Smrg * Data format expected by MDAPI.
387ec681f3Smrg */
397ec681f3Smrg
407ec681f3Smrgstruct gfx7_mdapi_metrics {
417ec681f3Smrg   uint64_t TotalTime;
427ec681f3Smrg
437ec681f3Smrg   uint64_t ACounters[45];
447ec681f3Smrg   uint64_t NOACounters[16];
457ec681f3Smrg
467ec681f3Smrg   uint64_t PerfCounter1;
477ec681f3Smrg   uint64_t PerfCounter2;
487ec681f3Smrg   uint32_t SplitOccured;
497ec681f3Smrg   uint32_t CoreFrequencyChanged;
507ec681f3Smrg   uint64_t CoreFrequency;
517ec681f3Smrg   uint32_t ReportId;
527ec681f3Smrg   uint32_t ReportsCount;
537ec681f3Smrg};
547ec681f3Smrg
557ec681f3Smrg#define GTDI_QUERY_BDW_METRICS_OA_COUNT         36
567ec681f3Smrg#define GTDI_QUERY_BDW_METRICS_OA_40b_COUNT     32
577ec681f3Smrg#define GTDI_QUERY_BDW_METRICS_NOA_COUNT        16
587ec681f3Smrgstruct gfx8_mdapi_metrics {
597ec681f3Smrg   uint64_t TotalTime;
607ec681f3Smrg   uint64_t GPUTicks;
617ec681f3Smrg   uint64_t OaCntr[GTDI_QUERY_BDW_METRICS_OA_COUNT];
627ec681f3Smrg   uint64_t NoaCntr[GTDI_QUERY_BDW_METRICS_NOA_COUNT];
637ec681f3Smrg   uint64_t BeginTimestamp;
647ec681f3Smrg   uint64_t Reserved1;
657ec681f3Smrg   uint64_t Reserved2;
667ec681f3Smrg   uint32_t Reserved3;
677ec681f3Smrg   uint32_t OverrunOccured;
687ec681f3Smrg   uint64_t MarkerUser;
697ec681f3Smrg   uint64_t MarkerDriver;
707ec681f3Smrg
717ec681f3Smrg   uint64_t SliceFrequency;
727ec681f3Smrg   uint64_t UnsliceFrequency;
737ec681f3Smrg   uint64_t PerfCounter1;
747ec681f3Smrg   uint64_t PerfCounter2;
757ec681f3Smrg   uint32_t SplitOccured;
767ec681f3Smrg   uint32_t CoreFrequencyChanged;
777ec681f3Smrg   uint64_t CoreFrequency;
787ec681f3Smrg   uint32_t ReportId;
797ec681f3Smrg   uint32_t ReportsCount;
807ec681f3Smrg};
817ec681f3Smrg
827ec681f3Smrg#define GTDI_MAX_READ_REGS 16
837ec681f3Smrg
847ec681f3Smrgstruct gfx9_mdapi_metrics {
857ec681f3Smrg   uint64_t TotalTime;
867ec681f3Smrg   uint64_t GPUTicks;
877ec681f3Smrg   uint64_t OaCntr[GTDI_QUERY_BDW_METRICS_OA_COUNT];
887ec681f3Smrg   uint64_t NoaCntr[GTDI_QUERY_BDW_METRICS_NOA_COUNT];
897ec681f3Smrg   uint64_t BeginTimestamp;
907ec681f3Smrg   uint64_t Reserved1;
917ec681f3Smrg   uint64_t Reserved2;
927ec681f3Smrg   uint32_t Reserved3;
937ec681f3Smrg   uint32_t OverrunOccured;
947ec681f3Smrg   uint64_t MarkerUser;
957ec681f3Smrg   uint64_t MarkerDriver;
967ec681f3Smrg
977ec681f3Smrg   uint64_t SliceFrequency;
987ec681f3Smrg   uint64_t UnsliceFrequency;
997ec681f3Smrg   uint64_t PerfCounter1;
1007ec681f3Smrg   uint64_t PerfCounter2;
1017ec681f3Smrg   uint32_t SplitOccured;
1027ec681f3Smrg   uint32_t CoreFrequencyChanged;
1037ec681f3Smrg   uint64_t CoreFrequency;
1047ec681f3Smrg   uint32_t ReportId;
1057ec681f3Smrg   uint32_t ReportsCount;
1067ec681f3Smrg
1077ec681f3Smrg   uint64_t UserCntr[GTDI_MAX_READ_REGS];
1087ec681f3Smrg   uint32_t UserCntrCfgId;
1097ec681f3Smrg   uint32_t Reserved4;
1107ec681f3Smrg};
1117ec681f3Smrg
1127ec681f3Smrg/* Add new definition */
1137ec681f3Smrg#define gfx11_mdapi_metrics gfx9_mdapi_metrics
1147ec681f3Smrg
1157ec681f3Smrgstruct mdapi_pipeline_metrics {
1167ec681f3Smrg   uint64_t IAVertices;
1177ec681f3Smrg   uint64_t IAPrimitives;
1187ec681f3Smrg   uint64_t VSInvocations;
1197ec681f3Smrg   uint64_t GSInvocations;
1207ec681f3Smrg   uint64_t GSPrimitives;
1217ec681f3Smrg   uint64_t CInvocations;
1227ec681f3Smrg   uint64_t CPrimitives;
1237ec681f3Smrg   uint64_t PSInvocations;
1247ec681f3Smrg   uint64_t HSInvocations;
1257ec681f3Smrg   uint64_t DSInvocations;
1267ec681f3Smrg   uint64_t CSInvocations;
1277ec681f3Smrg   uint64_t Reserved1; /* Gfx10+ */
1287ec681f3Smrg};
1297ec681f3Smrg
1307ec681f3Smrgint intel_perf_query_result_write_mdapi(void *data, uint32_t data_size,
1317ec681f3Smrg                                        const struct intel_device_info *devinfo,
1327ec681f3Smrg                                        const struct intel_perf_query_info *query,
1337ec681f3Smrg                                        const struct intel_perf_query_result *result);
1347ec681f3Smrg
1357ec681f3Smrgstatic inline void intel_perf_query_mdapi_write_marker(void *data, uint32_t data_size,
1367ec681f3Smrg                                                       const struct intel_device_info *devinfo,
1377ec681f3Smrg                                                       uint64_t value)
1387ec681f3Smrg{
1397ec681f3Smrg   switch (devinfo->ver) {
1407ec681f3Smrg   case 8: {
1417ec681f3Smrg      if (data_size < sizeof(struct gfx8_mdapi_metrics))
1427ec681f3Smrg         return;
1437ec681f3Smrg      struct gfx8_mdapi_metrics *mdapi_data = data;
1447ec681f3Smrg      mdapi_data->MarkerUser = value;
1457ec681f3Smrg      break;
1467ec681f3Smrg   }
1477ec681f3Smrg   case 9:
1487ec681f3Smrg   case 11: {
1497ec681f3Smrg      if (data_size < sizeof(struct gfx9_mdapi_metrics))
1507ec681f3Smrg         return;
1517ec681f3Smrg      struct gfx9_mdapi_metrics *mdapi_data = data;
1527ec681f3Smrg      mdapi_data->MarkerUser = value;
1537ec681f3Smrg      break;
1547ec681f3Smrg   }
1557ec681f3Smrg   default:
1567ec681f3Smrg      break;
1577ec681f3Smrg   }
1587ec681f3Smrg}
1597ec681f3Smrg
1607ec681f3Smrg#endif /* INTEL_PERF_MDAPI_H */
161