Skip to content

Commit 29b4c58

Browse files
Jiawei Gualexdeucher
authored andcommitted
drm/amdgpu: Add vbios info ioctl interface
Add AMDGPU_INFO_VBIOS_INFO subquery id for detailed vbios info. Provides a way for the user application to get the VBIOS information without having to parse the binary. It is useful for the user to be able to display in a simple way the VBIOS version in their system if they happen to encounter an issue. V2: Use numeric serial. Parse and expose vbios version string. V3: Remove redundant data in drm_amdgpu_info_vbios struct. V4: 64 bit alignment in drm_amdgpu_info_vbios. v5: squash together all the reverts, etc. (Alex) Signed-off-by: Jiawei Gu <[email protected]> Reviewed-by: Alex Deucher <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 915821a commit 29b4c58

File tree

5 files changed

+219
-6
lines changed

5 files changed

+219
-6
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,21 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
867867
min((size_t)size, (size_t)(bios_size - bios_offset)))
868868
? -EFAULT : 0;
869869
}
870+
case AMDGPU_INFO_VBIOS_INFO: {
871+
struct drm_amdgpu_info_vbios vbios_info = {};
872+
struct atom_context *atom_context;
873+
874+
atom_context = adev->mode_info.atom_context;
875+
memcpy(vbios_info.name, atom_context->name, sizeof(atom_context->name));
876+
memcpy(vbios_info.vbios_pn, atom_context->vbios_pn, sizeof(atom_context->vbios_pn));
877+
vbios_info.version = atom_context->version;
878+
memcpy(vbios_info.vbios_ver_str, atom_context->vbios_ver_str,
879+
sizeof(atom_context->vbios_ver_str));
880+
memcpy(vbios_info.date, atom_context->date, sizeof(atom_context->date));
881+
882+
return copy_to_user(out, &vbios_info,
883+
min((size_t)size, sizeof(vbios_info))) ? -EFAULT : 0;
884+
}
870885
default:
871886
DRM_DEBUG_KMS("Invalid request %d\n",
872887
info->vbios_info.type);

drivers/gpu/drm/amd/amdgpu/atom.c

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#define ATOM_DEBUG
3333

34+
#include "atomfirmware.h"
3435
#include "atom.h"
3536
#include "atom-names.h"
3637
#include "atom-bits.h"
@@ -1299,12 +1300,168 @@ static void atom_index_iio(struct atom_context *ctx, int base)
12991300
}
13001301
}
13011302

1303+
static void atom_get_vbios_name(struct atom_context *ctx)
1304+
{
1305+
unsigned char *p_rom;
1306+
unsigned char str_num;
1307+
unsigned short off_to_vbios_str;
1308+
unsigned char *c_ptr;
1309+
int name_size;
1310+
int i;
1311+
1312+
const char *na = "--N/A--";
1313+
char *back;
1314+
1315+
p_rom = ctx->bios;
1316+
1317+
str_num = *(p_rom + OFFSET_TO_GET_ATOMBIOS_NUMBER_OF_STRINGS);
1318+
if (str_num != 0) {
1319+
off_to_vbios_str =
1320+
*(unsigned short *)(p_rom + OFFSET_TO_GET_ATOMBIOS_STRING_START);
1321+
1322+
c_ptr = (unsigned char *)(p_rom + off_to_vbios_str);
1323+
} else {
1324+
/* do not know where to find name */
1325+
memcpy(ctx->name, na, 7);
1326+
ctx->name[7] = 0;
1327+
return;
1328+
}
1329+
1330+
/*
1331+
* skip the atombios strings, usually 4
1332+
* 1st is P/N, 2nd is ASIC, 3rd is PCI type, 4th is Memory type
1333+
*/
1334+
for (i = 0; i < str_num; i++) {
1335+
while (*c_ptr != 0)
1336+
c_ptr++;
1337+
c_ptr++;
1338+
}
1339+
1340+
/* skip the following 2 chars: 0x0D 0x0A */
1341+
c_ptr += 2;
1342+
1343+
name_size = strnlen(c_ptr, STRLEN_LONG - 1);
1344+
memcpy(ctx->name, c_ptr, name_size);
1345+
back = ctx->name + name_size;
1346+
while ((*--back) == ' ')
1347+
;
1348+
*(back + 1) = '\0';
1349+
}
1350+
1351+
static void atom_get_vbios_date(struct atom_context *ctx)
1352+
{
1353+
unsigned char *p_rom;
1354+
unsigned char *date_in_rom;
1355+
1356+
p_rom = ctx->bios;
1357+
1358+
date_in_rom = p_rom + OFFSET_TO_VBIOS_DATE;
1359+
1360+
ctx->date[0] = '2';
1361+
ctx->date[1] = '0';
1362+
ctx->date[2] = date_in_rom[6];
1363+
ctx->date[3] = date_in_rom[7];
1364+
ctx->date[4] = '/';
1365+
ctx->date[5] = date_in_rom[0];
1366+
ctx->date[6] = date_in_rom[1];
1367+
ctx->date[7] = '/';
1368+
ctx->date[8] = date_in_rom[3];
1369+
ctx->date[9] = date_in_rom[4];
1370+
ctx->date[10] = ' ';
1371+
ctx->date[11] = date_in_rom[9];
1372+
ctx->date[12] = date_in_rom[10];
1373+
ctx->date[13] = date_in_rom[11];
1374+
ctx->date[14] = date_in_rom[12];
1375+
ctx->date[15] = date_in_rom[13];
1376+
ctx->date[16] = '\0';
1377+
}
1378+
1379+
static unsigned char *atom_find_str_in_rom(struct atom_context *ctx, char *str, int start,
1380+
int end, int maxlen)
1381+
{
1382+
unsigned long str_off;
1383+
unsigned char *p_rom;
1384+
unsigned short str_len;
1385+
1386+
str_off = 0;
1387+
str_len = strnlen(str, maxlen);
1388+
p_rom = ctx->bios;
1389+
1390+
for (; start <= end; ++start) {
1391+
for (str_off = 0; str_off < str_len; ++str_off) {
1392+
if (str[str_off] != *(p_rom + start + str_off))
1393+
break;
1394+
}
1395+
1396+
if (str_off == str_len || str[str_off] == 0)
1397+
return p_rom + start;
1398+
}
1399+
return NULL;
1400+
}
1401+
1402+
static void atom_get_vbios_pn(struct atom_context *ctx)
1403+
{
1404+
unsigned char *p_rom;
1405+
unsigned short off_to_vbios_str;
1406+
unsigned char *vbios_str;
1407+
int count;
1408+
1409+
off_to_vbios_str = 0;
1410+
p_rom = ctx->bios;
1411+
1412+
if (*(p_rom + OFFSET_TO_GET_ATOMBIOS_NUMBER_OF_STRINGS) != 0) {
1413+
off_to_vbios_str =
1414+
*(unsigned short *)(p_rom + OFFSET_TO_GET_ATOMBIOS_STRING_START);
1415+
1416+
vbios_str = (unsigned char *)(p_rom + off_to_vbios_str);
1417+
} else {
1418+
vbios_str = p_rom + OFFSET_TO_VBIOS_PART_NUMBER;
1419+
}
1420+
1421+
if (*vbios_str == 0) {
1422+
vbios_str = atom_find_str_in_rom(ctx, BIOS_ATOM_PREFIX, 3, 1024, 64);
1423+
if (vbios_str == NULL)
1424+
vbios_str += sizeof(BIOS_ATOM_PREFIX) - 1;
1425+
}
1426+
if (vbios_str != NULL && *vbios_str == 0)
1427+
vbios_str++;
1428+
1429+
if (vbios_str != NULL) {
1430+
count = 0;
1431+
while ((count < BIOS_STRING_LENGTH) && vbios_str[count] >= ' ' &&
1432+
vbios_str[count] <= 'z') {
1433+
ctx->vbios_pn[count] = vbios_str[count];
1434+
count++;
1435+
}
1436+
1437+
ctx->vbios_pn[count] = 0;
1438+
}
1439+
}
1440+
1441+
static void atom_get_vbios_version(struct atom_context *ctx)
1442+
{
1443+
unsigned char *vbios_ver;
1444+
1445+
/* find anchor ATOMBIOSBK-AMD */
1446+
vbios_ver = atom_find_str_in_rom(ctx, BIOS_VERSION_PREFIX, 3, 1024, 64);
1447+
if (vbios_ver != NULL) {
1448+
/* skip ATOMBIOSBK-AMD VER */
1449+
vbios_ver += 18;
1450+
memcpy(ctx->vbios_ver_str, vbios_ver, STRLEN_NORMAL);
1451+
} else {
1452+
ctx->vbios_ver_str[0] = '\0';
1453+
}
1454+
}
1455+
13021456
struct atom_context *amdgpu_atom_parse(struct card_info *card, void *bios)
13031457
{
13041458
int base;
13051459
struct atom_context *ctx =
13061460
kzalloc(sizeof(struct atom_context), GFP_KERNEL);
13071461
char *str;
1462+
struct _ATOM_ROM_HEADER *atom_rom_header;
1463+
struct _ATOM_MASTER_DATA_TABLE *master_table;
1464+
struct _ATOM_FIRMWARE_INFO *atom_fw_info;
13081465
u16 idx;
13091466

13101467
if (!ctx)
@@ -1353,6 +1510,21 @@ struct atom_context *amdgpu_atom_parse(struct card_info *card, void *bios)
13531510
strlcpy(ctx->vbios_version, str, sizeof(ctx->vbios_version));
13541511
}
13551512

1513+
atom_rom_header = (struct _ATOM_ROM_HEADER *)CSTR(base);
1514+
if (atom_rom_header->usMasterDataTableOffset != 0) {
1515+
master_table = (struct _ATOM_MASTER_DATA_TABLE *)
1516+
CSTR(atom_rom_header->usMasterDataTableOffset);
1517+
if (master_table->ListOfDataTables.FirmwareInfo != 0) {
1518+
atom_fw_info = (struct _ATOM_FIRMWARE_INFO *)
1519+
CSTR(master_table->ListOfDataTables.FirmwareInfo);
1520+
ctx->version = atom_fw_info->ulFirmwareRevision;
1521+
}
1522+
}
1523+
1524+
atom_get_vbios_name(ctx);
1525+
atom_get_vbios_pn(ctx);
1526+
atom_get_vbios_date(ctx);
1527+
atom_get_vbios_version(ctx);
13561528

13571529
return ctx;
13581530
}

drivers/gpu/drm/amd/amdgpu/atom.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ struct drm_device;
112112
#define ATOM_IO_SYSIO 2
113113
#define ATOM_IO_IIO 0x80
114114

115+
#define STRLEN_NORMAL 32
116+
#define STRLEN_LONG 64
117+
#define STRLEN_VERYLONG 254
118+
115119
struct card_info {
116120
struct drm_device *dev;
117121
void (* reg_write)(struct card_info *, uint32_t, uint32_t); /* filled by driver */
@@ -140,6 +144,12 @@ struct atom_context {
140144
uint32_t *scratch;
141145
int scratch_size_bytes;
142146
char vbios_version[20];
147+
148+
uint8_t name[STRLEN_LONG];
149+
uint8_t vbios_pn[STRLEN_LONG];
150+
uint32_t version;
151+
uint8_t vbios_ver_str[STRLEN_NORMAL];
152+
uint8_t date[STRLEN_NORMAL];
143153
};
144154

145155
extern int amdgpu_atom_debug;

drivers/gpu/drm/amd/include/atomfirmware.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ enum atom_dp_vs_preemph_def{
197197
DP_VS_LEVEL0_PREEMPH_LEVEL3 = 0x18,
198198
};
199199

200+
#define BIOS_ATOM_PREFIX "ATOMBIOS"
201+
#define BIOS_VERSION_PREFIX "ATOMBIOSBK-AMD"
202+
#define BIOS_STRING_LENGTH 43
200203

201204
/*
202205
enum atom_string_def{
@@ -209,12 +212,14 @@ atom_bios_string = "ATOM"
209212
#pragma pack(1) /* BIOS data must use byte aligment*/
210213

211214
enum atombios_image_offset{
212-
OFFSET_TO_ATOM_ROM_HEADER_POINTER =0x00000048,
213-
OFFSET_TO_ATOM_ROM_IMAGE_SIZE =0x00000002,
214-
OFFSET_TO_ATOMBIOS_ASIC_BUS_MEM_TYPE =0x94,
215-
MAXSIZE_OF_ATOMBIOS_ASIC_BUS_MEM_TYPE =20, /*including the terminator 0x0!*/
216-
OFFSET_TO_GET_ATOMBIOS_NUMBER_OF_STRINGS =0x2f,
217-
OFFSET_TO_GET_ATOMBIOS_STRING_START =0x6e,
215+
OFFSET_TO_ATOM_ROM_HEADER_POINTER = 0x00000048,
216+
OFFSET_TO_ATOM_ROM_IMAGE_SIZE = 0x00000002,
217+
OFFSET_TO_ATOMBIOS_ASIC_BUS_MEM_TYPE = 0x94,
218+
MAXSIZE_OF_ATOMBIOS_ASIC_BUS_MEM_TYPE = 20, /*including the terminator 0x0!*/
219+
OFFSET_TO_GET_ATOMBIOS_NUMBER_OF_STRINGS = 0x2f,
220+
OFFSET_TO_GET_ATOMBIOS_STRING_START = 0x6e,
221+
OFFSET_TO_VBIOS_PART_NUMBER = 0x80,
222+
OFFSET_TO_VBIOS_DATE = 0x50,
218223
};
219224

220225
/****************************************************************************

include/uapi/drm/amdgpu_drm.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,8 @@ struct drm_amdgpu_cs_chunk_data {
757757
#define AMDGPU_INFO_VBIOS_SIZE 0x1
758758
/* Subquery id: Query vbios image */
759759
#define AMDGPU_INFO_VBIOS_IMAGE 0x2
760+
/* Subquery id: Query vbios info */
761+
#define AMDGPU_INFO_VBIOS_INFO 0x3
760762
/* Query UVD handles */
761763
#define AMDGPU_INFO_NUM_HANDLES 0x1C
762764
/* Query sensor related information */
@@ -950,6 +952,15 @@ struct drm_amdgpu_info_firmware {
950952
__u32 feature;
951953
};
952954

955+
struct drm_amdgpu_info_vbios {
956+
__u8 name[64];
957+
__u8 vbios_pn[64];
958+
__u32 version;
959+
__u32 pad;
960+
__u8 vbios_ver_str[32];
961+
__u8 date[32];
962+
};
963+
953964
#define AMDGPU_VRAM_TYPE_UNKNOWN 0
954965
#define AMDGPU_VRAM_TYPE_GDDR1 1
955966
#define AMDGPU_VRAM_TYPE_DDR2 2

0 commit comments

Comments
 (0)