Skip to content

Commit d6fa802

Browse files
Lijo Lazaralexdeucher
authored andcommitted
drm/amdgpu: Add vbios build number interface
Fetch VBIOS build number from atom rom image. Add a sysfs interface to read the build number. Signed-off-by: Lijo Lazar <lijo.lazar@amd.com> Acked-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent c5f4fb4 commit d6fa802

3 files changed

Lines changed: 54 additions & 3 deletions

File tree

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

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,16 +1816,43 @@ static ssize_t amdgpu_atombios_get_vbios_version(struct device *dev,
18161816
return sysfs_emit(buf, "%s\n", ctx->vbios_pn);
18171817
}
18181818

1819+
static ssize_t amdgpu_atombios_get_vbios_build(struct device *dev,
1820+
struct device_attribute *attr,
1821+
char *buf)
1822+
{
1823+
struct drm_device *ddev = dev_get_drvdata(dev);
1824+
struct amdgpu_device *adev = drm_to_adev(ddev);
1825+
struct atom_context *ctx = adev->mode_info.atom_context;
1826+
1827+
return sysfs_emit(buf, "%s\n", ctx->build_num);
1828+
}
1829+
18191830
static DEVICE_ATTR(vbios_version, 0444, amdgpu_atombios_get_vbios_version,
18201831
NULL);
1832+
static DEVICE_ATTR(vbios_build, 0444, amdgpu_atombios_get_vbios_build, NULL);
18211833

18221834
static struct attribute *amdgpu_vbios_version_attrs[] = {
1823-
&dev_attr_vbios_version.attr,
1824-
NULL
1835+
&dev_attr_vbios_version.attr, &dev_attr_vbios_build.attr, NULL
18251836
};
18261837

1838+
static umode_t amdgpu_vbios_version_attrs_is_visible(struct kobject *kobj,
1839+
struct attribute *attr,
1840+
int index)
1841+
{
1842+
struct device *dev = kobj_to_dev(kobj);
1843+
struct drm_device *ddev = dev_get_drvdata(dev);
1844+
struct amdgpu_device *adev = drm_to_adev(ddev);
1845+
struct atom_context *ctx = adev->mode_info.atom_context;
1846+
1847+
if (attr == &dev_attr_vbios_build.attr && !strlen(ctx->build_num))
1848+
return 0;
1849+
1850+
return attr->mode;
1851+
}
1852+
18271853
const struct attribute_group amdgpu_vbios_version_attr_group = {
1828-
.attrs = amdgpu_vbios_version_attrs
1854+
.attrs = amdgpu_vbios_version_attrs,
1855+
.is_visible = amdgpu_vbios_version_attrs_is_visible,
18291856
};
18301857

18311858
int amdgpu_atombios_sysfs_init(struct amdgpu_device *adev)

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,6 +1494,27 @@ static void atom_get_vbios_version(struct atom_context *ctx)
14941494
}
14951495
}
14961496

1497+
static void atom_get_vbios_build(struct atom_context *ctx)
1498+
{
1499+
unsigned char *atom_rom_hdr;
1500+
unsigned char *str;
1501+
uint16_t base;
1502+
1503+
base = CU16(ATOM_ROM_TABLE_PTR);
1504+
atom_rom_hdr = CSTR(base);
1505+
1506+
str = CSTR(CU16(base + ATOM_ROM_CFG_PTR));
1507+
/* Skip config string */
1508+
while (str < atom_rom_hdr && *str++)
1509+
;
1510+
/* Skip change list string */
1511+
while (str < atom_rom_hdr && *str++)
1512+
;
1513+
1514+
if ((str + STRLEN_NORMAL) < atom_rom_hdr)
1515+
strscpy(ctx->build_num, str, STRLEN_NORMAL);
1516+
}
1517+
14971518
struct atom_context *amdgpu_atom_parse(struct card_info *card, void *bios)
14981519
{
14991520
int base;
@@ -1554,6 +1575,7 @@ struct atom_context *amdgpu_atom_parse(struct card_info *card, void *bios)
15541575
atom_get_vbios_pn(ctx);
15551576
atom_get_vbios_date(ctx);
15561577
atom_get_vbios_version(ctx);
1578+
atom_get_vbios_build(ctx);
15571579

15581580
return ctx;
15591581
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct drm_device;
3737
#define ATOM_ROM_MAGIC "ATOM"
3838
#define ATOM_ROM_MAGIC_PTR 4
3939

40+
#define ATOM_ROM_CFG_PTR 0xC
4041
#define ATOM_ROM_MSG_PTR 0x10
4142
#define ATOM_ROM_CMD_PTR 0x1E
4243
#define ATOM_ROM_DATA_PTR 0x20
@@ -151,6 +152,7 @@ struct atom_context {
151152
uint32_t version;
152153
uint8_t vbios_ver_str[STRLEN_NORMAL];
153154
uint8_t date[STRLEN_NORMAL];
155+
uint8_t build_num[STRLEN_NORMAL];
154156
};
155157

156158
extern int amdgpu_atom_debug;

0 commit comments

Comments
 (0)