blob: 61d82d9e51addf2bf9ee84337509ac3b6743f2c7 [file] [log] [blame]
Ben Widawsky62873792011-06-24 11:42:03 -07001/*
2 * Copyright © 2011 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Ben Widawsky <ben@bwidawsk.net>
25 *
26 */
27
28#include <stdint.h>
29#include <stdio.h>
30#include <stdlib.h>
Daniel Vetterc03c6ce2014-03-22 21:34:29 +010031#include "intel_io.h"
Daniel Vetter6cfcd712014-03-22 20:07:35 +010032#include "intel_chipset.h"
Ben Widawsky62873792011-06-24 11:42:03 -070033
34struct eu_rdata {
35 union {
36 struct {
37 uint8_t sendc_dep : 1;
38 uint8_t swh_dep : 1;
39 uint8_t pwc_dep : 1;
40 uint8_t n2_dep : 1;
41 uint8_t n1_dep : 1;
42 uint8_t n0_dep : 1;
43 uint8_t flag1_dep : 1;
44 uint8_t flag0_dep : 1;
45 uint8_t indx_dep : 1;
46 uint8_t mrf_dep : 1;
47 uint8_t dst_dep : 1;
48 uint8_t src2_dep : 1;
49 uint8_t src1_dep : 1;
50 uint8_t src0_dep : 1;
51 uint8_t mp_dep_pin : 1;
52 uint8_t sp_dep_pin : 1;
53 uint8_t fftid : 8;
54 uint8_t ffid : 4;
55 uint8_t instruction_valid : 1;
56 uint8_t thread_status : 3;
57 };
58 uint32_t dword;
59 } ud0;
60
61 union {
62 struct {
63 uint8_t mrf_addr : 4;
64 uint8_t dst_addr : 7;
65 uint8_t src2_addr : 7;
66 uint8_t src1_addr : 7;
67 uint8_t src0_addr : 7;
68 };
69 uint32_t dword;
70 } ud1;
71
72 union {
73 struct {
74 uint16_t exip : 12;
75 uint8_t opcode : 7;
76 uint8_t pwc : 8;
77 uint8_t instruction_valid : 1;
78 uint8_t mbz : 4;
79 };
80 uint32_t dword;
81 } ud2;
82};
83
84const char *thread_status[] =
85 {"INVALID", "invalid/no thread", "standby (dependency)", "INVALID", "Executing",
86 "INVALID" , "INVALID" , "INVALID"};
87
88static struct eu_rdata
89collect_rdata(int eu, int tid) {
90 struct eu_rdata rdata;
91
92 intel_register_write(0x7800, eu << 16 | (3 * tid) << 8);
93 rdata.ud0.dword = intel_register_read(0x7840);
94
95 intel_register_write(0x7800, eu << 16 | (3 * tid + 1) << 8);
96 rdata.ud1.dword = intel_register_read(0x7840);
97
98 intel_register_write(0x7800, eu << 16 | (3 * tid + 2) << 8);
99 rdata.ud2.dword = intel_register_read(0x7840);
100
101 return rdata;
102}
103static void
104print_rdata(struct eu_rdata rdata) {
105 printf("\t%s\n", thread_status[rdata.ud0.thread_status]);
106 printf("\tn1_dep: %d\n", rdata.ud0.n1_dep);
107 printf("\tpwc_dep: %d\n", rdata.ud0.pwc_dep);
108 printf("\tswh_dep: %d\n", rdata.ud0.swh_dep);
109 printf("\tsource 0 %x\n", rdata.ud1.src0_addr);
110 printf("\tsource 1 %x\n", rdata.ud1.src1_addr);
111 printf("\tsource 2 %x\n", rdata.ud1.src2_addr);
112 printf("\tdest %x\n", rdata.ud1.dst_addr);
113 printf("\tmrf %x\n", rdata.ud1.mrf_addr);
114 printf("\tIP: %x\n", rdata.ud2.exip);
115 printf("\topcode: %x\n", rdata.ud2.opcode);
116}
117
118static void
119find_stuck_threads(void)
120{
121 int i, j;
122 for (i = 0; i < 15; i++)
123 for (j = 0; j < 5; j++) {
124 struct eu_rdata rdata;
125 rdata = collect_rdata(i, j);
126 if (rdata.ud0.thread_status == 2 ||
127 rdata.ud0.thread_status == 4) {
128 printf("%d %d:\n", i, j);
129 print_rdata(rdata);
130 }
131 }
132}
133
134int main(int argc, char *argv[]) {
135 struct pci_device *pci_dev;
136 pci_dev = intel_get_pci_device();
137
138 intel_register_access_init(pci_dev, 1);
139 find_stuck_threads();
140// collect_rdata(atoi(argv[1]), atoi(argv[2]));
141 return 0;
142}