1/*
2 * Copyright 2018 Advanced Micro Devices, Inc.
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 shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 */
23
24#ifndef _DISCOVERY_H_
25#define _DISCOVERY_H_
26
27#define PSP_HEADER_SIZE                 256
28#define BINARY_SIGNATURE                0x28211407
29#define DISCOVERY_TABLE_SIGNATURE       0x53445049
30
31typedef enum
32{
33	IP_DISCOVERY = 0,
34	GC,
35	HARVEST_INFO,
36	TABLE_4,
37	RESERVED_1,
38	RESERVED_2,
39	TOTAL_TABLES = 6
40} table;
41
42#pragma pack(1)
43
44typedef struct table_info
45{
46	uint16_t offset;   /* Byte offset */
47	uint16_t checksum; /* Byte sum of the table */
48	uint16_t size;     /* Table size */
49	uint16_t padding;
50} table_info;
51
52typedef struct binary_header
53{
54	/* psp structure should go at the top of this structure */
55	uint32_t binary_signature; /* 0x7, 0x14, 0x21, 0x28 */
56	uint16_t version_major;
57	uint16_t version_minor;
58	uint16_t binary_checksum;  /* Byte sum of the binary after this field */
59	uint16_t binary_size;      /* Binary Size*/
60	table_info table_list[TOTAL_TABLES];
61} binary_header;
62
63typedef struct die_info
64{
65	uint16_t die_id;
66	uint16_t die_offset; /* Points to the corresponding die_header structure */
67} die_info;
68
69
70typedef struct ip_discovery_header
71{
72	uint32_t signature;    /* Table Signature */
73	uint16_t version;      /* Table Version */
74	uint16_t size;         /* Table Size */
75	uint32_t id;           /* Table ID */
76	uint16_t num_dies;     /* Number of Dies */
77	die_info die_info[16]; /* list die information for up to 16 dies */
78	uint16_t padding[1];   /* padding */
79} ip_discovery_header;
80
81typedef struct ip
82{
83	uint16_t hw_id;           /* Hardware ID */
84	uint8_t number_instance;  /* instance of the IP */
85	uint8_t num_base_address; /* Number of Base Addresses */
86	uint8_t major;            /* HCID Major */
87	uint8_t minor;            /* HCID Minor */
88	uint8_t revision;         /* HCID Revision */
89#if defined(__BIG_ENDIAN)
90	uint8_t reserved : 4;     /* Placeholder field */
91	uint8_t harvest : 4;      /* Harvest */
92#else
93	uint8_t harvest : 4;      /* Harvest */
94	uint8_t reserved : 4;     /* Placeholder field */
95#endif
96	uint32_t base_address[1]; /* variable number of Addresses */
97} ip;
98
99typedef struct die_header
100{
101	uint16_t die_id;
102	uint16_t num_ips;
103} die_header;
104
105typedef struct ip_structure
106{
107	ip_discovery_header* header;
108	struct die
109	{
110		die_header *die_header;
111		ip *ip_list;
112	} die;
113} ip_structure;
114
115struct gpu_info_header {
116	uint32_t table_id;      /* table ID */
117	uint16_t version_major; /* table version */
118	uint16_t version_minor; /* table version */
119	uint32_t size;          /* size of the entire header+data in bytes */
120};
121
122struct gc_info_v1_0 {
123	struct gpu_info_header header;
124
125	uint32_t gc_num_se;
126	uint32_t gc_num_wgp0_per_sa;
127	uint32_t gc_num_wgp1_per_sa;
128	uint32_t gc_num_rb_per_se;
129	uint32_t gc_num_gl2c;
130	uint32_t gc_num_gprs;
131	uint32_t gc_num_max_gs_thds;
132	uint32_t gc_gs_table_depth;
133	uint32_t gc_gsprim_buff_depth;
134	uint32_t gc_parameter_cache_depth;
135	uint32_t gc_double_offchip_lds_buffer;
136	uint32_t gc_wave_size;
137	uint32_t gc_max_waves_per_simd;
138	uint32_t gc_max_scratch_slots_per_cu;
139	uint32_t gc_lds_size;
140	uint32_t gc_num_sc_per_se;
141	uint32_t gc_num_sa_per_se;
142	uint32_t gc_num_packer_per_sc;
143	uint32_t gc_num_gl2a;
144};
145
146struct gc_info_v1_1 {
147	struct gpu_info_header header;
148
149	uint32_t gc_num_se;
150	uint32_t gc_num_wgp0_per_sa;
151	uint32_t gc_num_wgp1_per_sa;
152	uint32_t gc_num_rb_per_se;
153	uint32_t gc_num_gl2c;
154	uint32_t gc_num_gprs;
155	uint32_t gc_num_max_gs_thds;
156	uint32_t gc_gs_table_depth;
157	uint32_t gc_gsprim_buff_depth;
158	uint32_t gc_parameter_cache_depth;
159	uint32_t gc_double_offchip_lds_buffer;
160	uint32_t gc_wave_size;
161	uint32_t gc_max_waves_per_simd;
162	uint32_t gc_max_scratch_slots_per_cu;
163	uint32_t gc_lds_size;
164	uint32_t gc_num_sc_per_se;
165	uint32_t gc_num_sa_per_se;
166	uint32_t gc_num_packer_per_sc;
167	uint32_t gc_num_gl2a;
168	uint32_t gc_num_tcp_per_sa;
169	uint32_t gc_num_sdp_interface;
170	uint32_t gc_num_tcps;
171};
172
173struct gc_info_v2_0 {
174	struct gpu_info_header header;
175
176	uint32_t gc_num_se;
177	uint32_t gc_num_cu_per_sh;
178	uint32_t gc_num_sh_per_se;
179	uint32_t gc_num_rb_per_se;
180	uint32_t gc_num_tccs;
181	uint32_t gc_num_gprs;
182	uint32_t gc_num_max_gs_thds;
183	uint32_t gc_gs_table_depth;
184	uint32_t gc_gsprim_buff_depth;
185	uint32_t gc_parameter_cache_depth;
186	uint32_t gc_double_offchip_lds_buffer;
187	uint32_t gc_wave_size;
188	uint32_t gc_max_waves_per_simd;
189	uint32_t gc_max_scratch_slots_per_cu;
190	uint32_t gc_lds_size;
191	uint32_t gc_num_sc_per_se;
192	uint32_t gc_num_packer_per_sc;
193};
194
195typedef struct harvest_info_header {
196	uint32_t signature; /* Table Signature */
197	uint32_t version;   /* Table Version */
198} harvest_info_header;
199
200typedef struct harvest_info {
201	uint16_t hw_id;          /* Hardware ID */
202	uint8_t number_instance; /* Instance of the IP */
203	uint8_t reserved;        /* Reserved for alignment */
204} harvest_info;
205
206typedef struct harvest_table {
207	harvest_info_header header;
208	harvest_info list[32];
209} harvest_table;
210
211#pragma pack()
212
213#endif
214