Home | History | Annotate | Line # | Download | only in amdgpu
      1  1.1  riastrad /*	$NetBSD: amdgpu_discovery.c,v 1.2 2021/12/18 23:44:58 riastradh Exp $	*/
      2  1.1  riastrad 
      3  1.1  riastrad /*
      4  1.1  riastrad  * Copyright 2018 Advanced Micro Devices, Inc.
      5  1.1  riastrad  *
      6  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
      7  1.1  riastrad  * copy of this software and associated documentation files (the "Software"),
      8  1.1  riastrad  * to deal in the Software without restriction, including without limitation
      9  1.1  riastrad  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     10  1.1  riastrad  * and/or sell copies of the Software, and to permit persons to whom the
     11  1.1  riastrad  * Software is furnished to do so, subject to the following conditions:
     12  1.1  riastrad  *
     13  1.1  riastrad  * The above copyright notice and this permission notice shall be included in
     14  1.1  riastrad  * all copies or substantial portions of the Software.
     15  1.1  riastrad  *
     16  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     17  1.1  riastrad  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     18  1.1  riastrad  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     19  1.1  riastrad  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
     20  1.1  riastrad  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     21  1.1  riastrad  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     22  1.1  riastrad  * OTHER DEALINGS IN THE SOFTWARE.
     23  1.1  riastrad  *
     24  1.1  riastrad  */
     25  1.1  riastrad 
     26  1.1  riastrad #include <sys/cdefs.h>
     27  1.1  riastrad __KERNEL_RCSID(0, "$NetBSD: amdgpu_discovery.c,v 1.2 2021/12/18 23:44:58 riastradh Exp $");
     28  1.1  riastrad 
     29  1.1  riastrad #include "amdgpu.h"
     30  1.1  riastrad #include "amdgpu_discovery.h"
     31  1.1  riastrad #include "soc15_common.h"
     32  1.1  riastrad #include "soc15_hw_ip.h"
     33  1.1  riastrad #include "nbio/nbio_2_3_offset.h"
     34  1.1  riastrad #include "discovery.h"
     35  1.1  riastrad 
     36  1.1  riastrad #define mmRCC_CONFIG_MEMSIZE	0xde3
     37  1.1  riastrad #define mmMM_INDEX		0x0
     38  1.1  riastrad #define mmMM_INDEX_HI		0x6
     39  1.1  riastrad #define mmMM_DATA		0x1
     40  1.1  riastrad #define HW_ID_MAX		300
     41  1.1  riastrad 
     42  1.1  riastrad const char *hw_id_names[HW_ID_MAX] = {
     43  1.1  riastrad 	[MP1_HWID]		= "MP1",
     44  1.1  riastrad 	[MP2_HWID]		= "MP2",
     45  1.1  riastrad 	[THM_HWID]		= "THM",
     46  1.1  riastrad 	[SMUIO_HWID]		= "SMUIO",
     47  1.1  riastrad 	[FUSE_HWID]		= "FUSE",
     48  1.1  riastrad 	[CLKA_HWID]		= "CLKA",
     49  1.1  riastrad 	[PWR_HWID]		= "PWR",
     50  1.1  riastrad 	[GC_HWID]		= "GC",
     51  1.1  riastrad 	[UVD_HWID]		= "UVD",
     52  1.1  riastrad 	[AUDIO_AZ_HWID]		= "AUDIO_AZ",
     53  1.1  riastrad 	[ACP_HWID]		= "ACP",
     54  1.1  riastrad 	[DCI_HWID]		= "DCI",
     55  1.1  riastrad 	[DMU_HWID]		= "DMU",
     56  1.1  riastrad 	[DCO_HWID]		= "DCO",
     57  1.1  riastrad 	[DIO_HWID]		= "DIO",
     58  1.1  riastrad 	[XDMA_HWID]		= "XDMA",
     59  1.1  riastrad 	[DCEAZ_HWID]		= "DCEAZ",
     60  1.1  riastrad 	[DAZ_HWID]		= "DAZ",
     61  1.1  riastrad 	[SDPMUX_HWID]		= "SDPMUX",
     62  1.1  riastrad 	[NTB_HWID]		= "NTB",
     63  1.1  riastrad 	[IOHC_HWID]		= "IOHC",
     64  1.1  riastrad 	[L2IMU_HWID]		= "L2IMU",
     65  1.1  riastrad 	[VCE_HWID]		= "VCE",
     66  1.1  riastrad 	[MMHUB_HWID]		= "MMHUB",
     67  1.1  riastrad 	[ATHUB_HWID]		= "ATHUB",
     68  1.1  riastrad 	[DBGU_NBIO_HWID]	= "DBGU_NBIO",
     69  1.1  riastrad 	[DFX_HWID]		= "DFX",
     70  1.1  riastrad 	[DBGU0_HWID]		= "DBGU0",
     71  1.1  riastrad 	[DBGU1_HWID]		= "DBGU1",
     72  1.1  riastrad 	[OSSSYS_HWID]		= "OSSSYS",
     73  1.1  riastrad 	[HDP_HWID]		= "HDP",
     74  1.1  riastrad 	[SDMA0_HWID]		= "SDMA0",
     75  1.1  riastrad 	[SDMA1_HWID]		= "SDMA1",
     76  1.1  riastrad 	[ISP_HWID]		= "ISP",
     77  1.1  riastrad 	[DBGU_IO_HWID]		= "DBGU_IO",
     78  1.1  riastrad 	[DF_HWID]		= "DF",
     79  1.1  riastrad 	[CLKB_HWID]		= "CLKB",
     80  1.1  riastrad 	[FCH_HWID]		= "FCH",
     81  1.1  riastrad 	[DFX_DAP_HWID]		= "DFX_DAP",
     82  1.1  riastrad 	[L1IMU_PCIE_HWID]	= "L1IMU_PCIE",
     83  1.1  riastrad 	[L1IMU_NBIF_HWID]	= "L1IMU_NBIF",
     84  1.1  riastrad 	[L1IMU_IOAGR_HWID]	= "L1IMU_IOAGR",
     85  1.1  riastrad 	[L1IMU3_HWID]		= "L1IMU3",
     86  1.1  riastrad 	[L1IMU4_HWID]		= "L1IMU4",
     87  1.1  riastrad 	[L1IMU5_HWID]		= "L1IMU5",
     88  1.1  riastrad 	[L1IMU6_HWID]		= "L1IMU6",
     89  1.1  riastrad 	[L1IMU7_HWID]		= "L1IMU7",
     90  1.1  riastrad 	[L1IMU8_HWID]		= "L1IMU8",
     91  1.1  riastrad 	[L1IMU9_HWID]		= "L1IMU9",
     92  1.1  riastrad 	[L1IMU10_HWID]		= "L1IMU10",
     93  1.1  riastrad 	[L1IMU11_HWID]		= "L1IMU11",
     94  1.1  riastrad 	[L1IMU12_HWID]		= "L1IMU12",
     95  1.1  riastrad 	[L1IMU13_HWID]		= "L1IMU13",
     96  1.1  riastrad 	[L1IMU14_HWID]		= "L1IMU14",
     97  1.1  riastrad 	[L1IMU15_HWID]		= "L1IMU15",
     98  1.1  riastrad 	[WAFLC_HWID]		= "WAFLC",
     99  1.1  riastrad 	[FCH_USB_PD_HWID]	= "FCH_USB_PD",
    100  1.1  riastrad 	[PCIE_HWID]		= "PCIE",
    101  1.1  riastrad 	[PCS_HWID]		= "PCS",
    102  1.1  riastrad 	[DDCL_HWID]		= "DDCL",
    103  1.1  riastrad 	[SST_HWID]		= "SST",
    104  1.1  riastrad 	[IOAGR_HWID]		= "IOAGR",
    105  1.1  riastrad 	[NBIF_HWID]		= "NBIF",
    106  1.1  riastrad 	[IOAPIC_HWID]		= "IOAPIC",
    107  1.1  riastrad 	[SYSTEMHUB_HWID]	= "SYSTEMHUB",
    108  1.1  riastrad 	[NTBCCP_HWID]		= "NTBCCP",
    109  1.1  riastrad 	[UMC_HWID]		= "UMC",
    110  1.1  riastrad 	[SATA_HWID]		= "SATA",
    111  1.1  riastrad 	[USB_HWID]		= "USB",
    112  1.1  riastrad 	[CCXSEC_HWID]		= "CCXSEC",
    113  1.1  riastrad 	[XGMI_HWID]		= "XGMI",
    114  1.1  riastrad 	[XGBE_HWID]		= "XGBE",
    115  1.1  riastrad 	[MP0_HWID]		= "MP0",
    116  1.1  riastrad };
    117  1.1  riastrad 
    118  1.1  riastrad static int hw_id_map[MAX_HWIP] = {
    119  1.1  riastrad 	[GC_HWIP]	= GC_HWID,
    120  1.1  riastrad 	[HDP_HWIP]	= HDP_HWID,
    121  1.1  riastrad 	[SDMA0_HWIP]	= SDMA0_HWID,
    122  1.1  riastrad 	[SDMA1_HWIP]	= SDMA1_HWID,
    123  1.1  riastrad 	[MMHUB_HWIP]	= MMHUB_HWID,
    124  1.1  riastrad 	[ATHUB_HWIP]	= ATHUB_HWID,
    125  1.1  riastrad 	[NBIO_HWIP]	= NBIF_HWID,
    126  1.1  riastrad 	[MP0_HWIP]	= MP0_HWID,
    127  1.1  riastrad 	[MP1_HWIP]	= MP1_HWID,
    128  1.1  riastrad 	[UVD_HWIP]	= UVD_HWID,
    129  1.1  riastrad 	[VCE_HWIP]	= VCE_HWID,
    130  1.1  riastrad 	[DF_HWIP]	= DF_HWID,
    131  1.1  riastrad 	[DCE_HWIP]	= DMU_HWID,
    132  1.1  riastrad 	[OSSSYS_HWIP]	= OSSSYS_HWID,
    133  1.1  riastrad 	[SMUIO_HWIP]	= SMUIO_HWID,
    134  1.1  riastrad 	[PWR_HWIP]	= PWR_HWID,
    135  1.1  riastrad 	[NBIF_HWIP]	= NBIF_HWID,
    136  1.1  riastrad 	[THM_HWIP]	= THM_HWID,
    137  1.1  riastrad 	[CLK_HWIP]	= CLKA_HWID,
    138  1.1  riastrad };
    139  1.1  riastrad 
    140  1.1  riastrad static int amdgpu_discovery_read_binary(struct amdgpu_device *adev, uint8_t *binary)
    141  1.1  riastrad {
    142  1.1  riastrad 	uint64_t vram_size = (uint64_t)RREG32(mmRCC_CONFIG_MEMSIZE) << 20;
    143  1.1  riastrad 	uint64_t pos = vram_size - DISCOVERY_TMR_SIZE;
    144  1.1  riastrad 
    145  1.1  riastrad 	amdgpu_device_vram_access(adev, pos, (uint32_t *)binary, DISCOVERY_TMR_SIZE, false);
    146  1.1  riastrad 	return 0;
    147  1.1  riastrad }
    148  1.1  riastrad 
    149  1.1  riastrad static uint16_t amdgpu_discovery_calculate_checksum(uint8_t *data, uint32_t size)
    150  1.1  riastrad {
    151  1.1  riastrad 	uint16_t checksum = 0;
    152  1.1  riastrad 	int i;
    153  1.1  riastrad 
    154  1.1  riastrad 	for (i = 0; i < size; i++)
    155  1.1  riastrad 		checksum += data[i];
    156  1.1  riastrad 
    157  1.1  riastrad 	return checksum;
    158  1.1  riastrad }
    159  1.1  riastrad 
    160  1.1  riastrad static inline bool amdgpu_discovery_verify_checksum(uint8_t *data, uint32_t size,
    161  1.1  riastrad 						    uint16_t expected)
    162  1.1  riastrad {
    163  1.1  riastrad 	return !!(amdgpu_discovery_calculate_checksum(data, size) == expected);
    164  1.1  riastrad }
    165  1.1  riastrad 
    166  1.1  riastrad int amdgpu_discovery_init(struct amdgpu_device *adev)
    167  1.1  riastrad {
    168  1.1  riastrad 	struct table_info *info;
    169  1.1  riastrad 	struct binary_header *bhdr;
    170  1.1  riastrad 	struct ip_discovery_header *ihdr;
    171  1.1  riastrad 	struct gpu_info_header *ghdr;
    172  1.1  riastrad 	uint16_t offset;
    173  1.1  riastrad 	uint16_t size;
    174  1.1  riastrad 	uint16_t checksum;
    175  1.1  riastrad 	int r;
    176  1.1  riastrad 
    177  1.1  riastrad 	adev->discovery = kzalloc(DISCOVERY_TMR_SIZE, GFP_KERNEL);
    178  1.1  riastrad 	if (!adev->discovery)
    179  1.1  riastrad 		return -ENOMEM;
    180  1.1  riastrad 
    181  1.1  riastrad 	r = amdgpu_discovery_read_binary(adev, adev->discovery);
    182  1.1  riastrad 	if (r) {
    183  1.1  riastrad 		DRM_ERROR("failed to read ip discovery binary\n");
    184  1.1  riastrad 		goto out;
    185  1.1  riastrad 	}
    186  1.1  riastrad 
    187  1.1  riastrad 	bhdr = (struct binary_header *)adev->discovery;
    188  1.1  riastrad 
    189  1.1  riastrad 	if (le32_to_cpu(bhdr->binary_signature) != BINARY_SIGNATURE) {
    190  1.1  riastrad 		DRM_ERROR("invalid ip discovery binary signature\n");
    191  1.1  riastrad 		r = -EINVAL;
    192  1.1  riastrad 		goto out;
    193  1.1  riastrad 	}
    194  1.1  riastrad 
    195  1.1  riastrad 	offset = offsetof(struct binary_header, binary_checksum) +
    196  1.1  riastrad 		sizeof(bhdr->binary_checksum);
    197  1.1  riastrad 	size = bhdr->binary_size - offset;
    198  1.1  riastrad 	checksum = bhdr->binary_checksum;
    199  1.1  riastrad 
    200  1.1  riastrad 	if (!amdgpu_discovery_verify_checksum(adev->discovery + offset,
    201  1.1  riastrad 					      size, checksum)) {
    202  1.1  riastrad 		DRM_ERROR("invalid ip discovery binary checksum\n");
    203  1.1  riastrad 		r = -EINVAL;
    204  1.1  riastrad 		goto out;
    205  1.1  riastrad 	}
    206  1.1  riastrad 
    207  1.1  riastrad 	info = &bhdr->table_list[IP_DISCOVERY];
    208  1.1  riastrad 	offset = le16_to_cpu(info->offset);
    209  1.1  riastrad 	checksum = le16_to_cpu(info->checksum);
    210  1.1  riastrad 	ihdr = (struct ip_discovery_header *)(adev->discovery + offset);
    211  1.1  riastrad 
    212  1.1  riastrad 	if (le32_to_cpu(ihdr->signature) != DISCOVERY_TABLE_SIGNATURE) {
    213  1.1  riastrad 		DRM_ERROR("invalid ip discovery data table signature\n");
    214  1.1  riastrad 		r = -EINVAL;
    215  1.1  riastrad 		goto out;
    216  1.1  riastrad 	}
    217  1.1  riastrad 
    218  1.1  riastrad 	if (!amdgpu_discovery_verify_checksum(adev->discovery + offset,
    219  1.1  riastrad 					      ihdr->size, checksum)) {
    220  1.1  riastrad 		DRM_ERROR("invalid ip discovery data table checksum\n");
    221  1.1  riastrad 		r = -EINVAL;
    222  1.1  riastrad 		goto out;
    223  1.1  riastrad 	}
    224  1.1  riastrad 
    225  1.1  riastrad 	info = &bhdr->table_list[GC];
    226  1.1  riastrad 	offset = le16_to_cpu(info->offset);
    227  1.1  riastrad 	checksum = le16_to_cpu(info->checksum);
    228  1.1  riastrad 	ghdr = (struct gpu_info_header *)(adev->discovery + offset);
    229  1.1  riastrad 
    230  1.1  riastrad 	if (!amdgpu_discovery_verify_checksum(adev->discovery + offset,
    231  1.1  riastrad 				              ghdr->size, checksum)) {
    232  1.1  riastrad 		DRM_ERROR("invalid gc data table checksum\n");
    233  1.1  riastrad 		r = -EINVAL;
    234  1.1  riastrad 		goto out;
    235  1.1  riastrad 	}
    236  1.1  riastrad 
    237  1.1  riastrad 	return 0;
    238  1.1  riastrad 
    239  1.1  riastrad out:
    240  1.1  riastrad 	kfree(adev->discovery);
    241  1.1  riastrad 	adev->discovery = NULL;
    242  1.1  riastrad 
    243  1.1  riastrad 	return r;
    244  1.1  riastrad }
    245  1.1  riastrad 
    246  1.1  riastrad void amdgpu_discovery_fini(struct amdgpu_device *adev)
    247  1.1  riastrad {
    248  1.1  riastrad 	kfree(adev->discovery);
    249  1.1  riastrad 	adev->discovery = NULL;
    250  1.1  riastrad }
    251  1.1  riastrad 
    252  1.1  riastrad int amdgpu_discovery_reg_base_init(struct amdgpu_device *adev)
    253  1.1  riastrad {
    254  1.1  riastrad 	struct binary_header *bhdr;
    255  1.1  riastrad 	struct ip_discovery_header *ihdr;
    256  1.1  riastrad 	struct die_header *dhdr;
    257  1.1  riastrad 	struct ip *ip;
    258  1.1  riastrad 	uint16_t die_offset;
    259  1.1  riastrad 	uint16_t ip_offset;
    260  1.1  riastrad 	uint16_t num_dies;
    261  1.1  riastrad 	uint16_t num_ips;
    262  1.1  riastrad 	uint8_t num_base_address;
    263  1.1  riastrad 	int hw_ip;
    264  1.1  riastrad 	int i, j, k;
    265  1.1  riastrad 
    266  1.1  riastrad 	if (!adev->discovery) {
    267  1.1  riastrad 		DRM_ERROR("ip discovery uninitialized\n");
    268  1.1  riastrad 		return -EINVAL;
    269  1.1  riastrad 	}
    270  1.1  riastrad 
    271  1.1  riastrad 	bhdr = (struct binary_header *)adev->discovery;
    272  1.1  riastrad 	ihdr = (struct ip_discovery_header *)(adev->discovery +
    273  1.1  riastrad 			le16_to_cpu(bhdr->table_list[IP_DISCOVERY].offset));
    274  1.1  riastrad 	num_dies = le16_to_cpu(ihdr->num_dies);
    275  1.1  riastrad 
    276  1.1  riastrad 	DRM_DEBUG("number of dies: %d\n", num_dies);
    277  1.1  riastrad 
    278  1.1  riastrad 	for (i = 0; i < num_dies; i++) {
    279  1.1  riastrad 		die_offset = le16_to_cpu(ihdr->die_info[i].die_offset);
    280  1.1  riastrad 		dhdr = (struct die_header *)(adev->discovery + die_offset);
    281  1.1  riastrad 		num_ips = le16_to_cpu(dhdr->num_ips);
    282  1.1  riastrad 		ip_offset = die_offset + sizeof(*dhdr);
    283  1.1  riastrad 
    284  1.1  riastrad 		if (le16_to_cpu(dhdr->die_id) != i) {
    285  1.1  riastrad 			DRM_ERROR("invalid die id %d, expected %d\n",
    286  1.1  riastrad 					le16_to_cpu(dhdr->die_id), i);
    287  1.1  riastrad 			return -EINVAL;
    288  1.1  riastrad 		}
    289  1.1  riastrad 
    290  1.1  riastrad 		DRM_DEBUG("number of hardware IPs on die%d: %d\n",
    291  1.1  riastrad 				le16_to_cpu(dhdr->die_id), num_ips);
    292  1.1  riastrad 
    293  1.1  riastrad 		for (j = 0; j < num_ips; j++) {
    294  1.1  riastrad 			ip = (struct ip *)(adev->discovery + ip_offset);
    295  1.1  riastrad 			num_base_address = ip->num_base_address;
    296  1.1  riastrad 
    297  1.1  riastrad 			DRM_DEBUG("%s(%d) #%d v%d.%d.%d:\n",
    298  1.1  riastrad 				  hw_id_names[le16_to_cpu(ip->hw_id)],
    299  1.1  riastrad 				  le16_to_cpu(ip->hw_id),
    300  1.1  riastrad 				  ip->number_instance,
    301  1.1  riastrad 				  ip->major, ip->minor,
    302  1.1  riastrad 				  ip->revision);
    303  1.1  riastrad 
    304  1.1  riastrad 			for (k = 0; k < num_base_address; k++) {
    305  1.1  riastrad 				/*
    306  1.1  riastrad 				 * convert the endianness of base addresses in place,
    307  1.1  riastrad 				 * so that we don't need to convert them when accessing adev->reg_offset.
    308  1.1  riastrad 				 */
    309  1.1  riastrad 				ip->base_address[k] = le32_to_cpu(ip->base_address[k]);
    310  1.1  riastrad 				DRM_DEBUG("\t0x%08x\n", ip->base_address[k]);
    311  1.1  riastrad 			}
    312  1.1  riastrad 
    313  1.1  riastrad 			for (hw_ip = 0; hw_ip < MAX_HWIP; hw_ip++) {
    314  1.1  riastrad 				if (hw_id_map[hw_ip] == le16_to_cpu(ip->hw_id)) {
    315  1.1  riastrad 					DRM_INFO("set register base offset for %s\n",
    316  1.1  riastrad 							hw_id_names[le16_to_cpu(ip->hw_id)]);
    317  1.1  riastrad 					adev->reg_offset[hw_ip][ip->number_instance] =
    318  1.1  riastrad 						ip->base_address;
    319  1.1  riastrad 				}
    320  1.1  riastrad 
    321  1.1  riastrad 			}
    322  1.1  riastrad 
    323  1.1  riastrad 			ip_offset += sizeof(*ip) + 4 * (ip->num_base_address - 1);
    324  1.1  riastrad 		}
    325  1.1  riastrad 	}
    326  1.1  riastrad 
    327  1.1  riastrad 	return 0;
    328  1.1  riastrad }
    329  1.1  riastrad 
    330  1.1  riastrad int amdgpu_discovery_get_ip_version(struct amdgpu_device *adev, int hw_id,
    331  1.1  riastrad 				    int *major, int *minor, int *revision)
    332  1.1  riastrad {
    333  1.1  riastrad 	struct binary_header *bhdr;
    334  1.1  riastrad 	struct ip_discovery_header *ihdr;
    335  1.1  riastrad 	struct die_header *dhdr;
    336  1.1  riastrad 	struct ip *ip;
    337  1.1  riastrad 	uint16_t die_offset;
    338  1.1  riastrad 	uint16_t ip_offset;
    339  1.1  riastrad 	uint16_t num_dies;
    340  1.1  riastrad 	uint16_t num_ips;
    341  1.1  riastrad 	int i, j;
    342  1.1  riastrad 
    343  1.1  riastrad 	if (!adev->discovery) {
    344  1.1  riastrad 		DRM_ERROR("ip discovery uninitialized\n");
    345  1.1  riastrad 		return -EINVAL;
    346  1.1  riastrad 	}
    347  1.1  riastrad 
    348  1.1  riastrad 	bhdr = (struct binary_header *)adev->discovery;
    349  1.1  riastrad 	ihdr = (struct ip_discovery_header *)(adev->discovery +
    350  1.1  riastrad 			le16_to_cpu(bhdr->table_list[IP_DISCOVERY].offset));
    351  1.1  riastrad 	num_dies = le16_to_cpu(ihdr->num_dies);
    352  1.1  riastrad 
    353  1.1  riastrad 	for (i = 0; i < num_dies; i++) {
    354  1.1  riastrad 		die_offset = le16_to_cpu(ihdr->die_info[i].die_offset);
    355  1.1  riastrad 		dhdr = (struct die_header *)(adev->discovery + die_offset);
    356  1.1  riastrad 		num_ips = le16_to_cpu(dhdr->num_ips);
    357  1.1  riastrad 		ip_offset = die_offset + sizeof(*dhdr);
    358  1.1  riastrad 
    359  1.1  riastrad 		for (j = 0; j < num_ips; j++) {
    360  1.1  riastrad 			ip = (struct ip *)(adev->discovery + ip_offset);
    361  1.1  riastrad 
    362  1.1  riastrad 			if (le16_to_cpu(ip->hw_id) == hw_id) {
    363  1.1  riastrad 				if (major)
    364  1.1  riastrad 					*major = ip->major;
    365  1.1  riastrad 				if (minor)
    366  1.1  riastrad 					*minor = ip->minor;
    367  1.1  riastrad 				if (revision)
    368  1.1  riastrad 					*revision = ip->revision;
    369  1.1  riastrad 				return 0;
    370  1.1  riastrad 			}
    371  1.1  riastrad 			ip_offset += sizeof(*ip) + 4 * (ip->num_base_address - 1);
    372  1.1  riastrad 		}
    373  1.1  riastrad 	}
    374  1.1  riastrad 
    375  1.1  riastrad 	return -EINVAL;
    376  1.1  riastrad }
    377  1.1  riastrad 
    378  1.1  riastrad int amdgpu_discovery_get_gfx_info(struct amdgpu_device *adev)
    379  1.1  riastrad {
    380  1.1  riastrad 	struct binary_header *bhdr;
    381  1.1  riastrad 	struct gc_info_v1_0 *gc_info;
    382  1.1  riastrad 
    383  1.1  riastrad 	if (!adev->discovery) {
    384  1.1  riastrad 		DRM_ERROR("ip discovery uninitialized\n");
    385  1.1  riastrad 		return -EINVAL;
    386  1.1  riastrad 	}
    387  1.1  riastrad 
    388  1.1  riastrad 	bhdr = (struct binary_header *)adev->discovery;
    389  1.1  riastrad 	gc_info = (struct gc_info_v1_0 *)(adev->discovery +
    390  1.1  riastrad 			le16_to_cpu(bhdr->table_list[GC].offset));
    391  1.1  riastrad 
    392  1.1  riastrad 	adev->gfx.config.max_shader_engines = le32_to_cpu(gc_info->gc_num_se);
    393  1.1  riastrad 	adev->gfx.config.max_cu_per_sh = 2 * (le32_to_cpu(gc_info->gc_num_wgp0_per_sa) +
    394  1.1  riastrad 					      le32_to_cpu(gc_info->gc_num_wgp1_per_sa));
    395  1.1  riastrad 	adev->gfx.config.max_sh_per_se = le32_to_cpu(gc_info->gc_num_sa_per_se);
    396  1.1  riastrad 	adev->gfx.config.max_backends_per_se = le32_to_cpu(gc_info->gc_num_rb_per_se);
    397  1.1  riastrad 	adev->gfx.config.max_texture_channel_caches = le32_to_cpu(gc_info->gc_num_gl2c);
    398  1.1  riastrad 	adev->gfx.config.max_gprs = le32_to_cpu(gc_info->gc_num_gprs);
    399  1.1  riastrad 	adev->gfx.config.max_gs_threads = le32_to_cpu(gc_info->gc_num_max_gs_thds);
    400  1.1  riastrad 	adev->gfx.config.gs_vgt_table_depth = le32_to_cpu(gc_info->gc_gs_table_depth);
    401  1.1  riastrad 	adev->gfx.config.gs_prim_buffer_depth = le32_to_cpu(gc_info->gc_gsprim_buff_depth);
    402  1.1  riastrad 	adev->gfx.config.double_offchip_lds_buf = le32_to_cpu(gc_info->gc_double_offchip_lds_buffer);
    403  1.1  riastrad 	adev->gfx.cu_info.wave_front_size = le32_to_cpu(gc_info->gc_wave_size);
    404  1.1  riastrad 	adev->gfx.cu_info.max_waves_per_simd = le32_to_cpu(gc_info->gc_max_waves_per_simd);
    405  1.1  riastrad 	adev->gfx.cu_info.max_scratch_slots_per_cu = le32_to_cpu(gc_info->gc_max_scratch_slots_per_cu);
    406  1.1  riastrad 	adev->gfx.cu_info.lds_size = le32_to_cpu(gc_info->gc_lds_size);
    407  1.1  riastrad 	adev->gfx.config.num_sc_per_sh = le32_to_cpu(gc_info->gc_num_sc_per_se) /
    408  1.1  riastrad 					 le32_to_cpu(gc_info->gc_num_sa_per_se);
    409  1.1  riastrad 	adev->gfx.config.num_packer_per_sc = le32_to_cpu(gc_info->gc_num_packer_per_sc);
    410  1.1  riastrad 
    411  1.1  riastrad 	return 0;
    412  1.1  riastrad }
    413