Skip to content

Commit 7957ec8

Browse files
Lijo Lazaralexdeucher
authored andcommitted
drm/amdgpu: Add FRU sysfs nodes only if needed
Create sysfs nodes for FRU data only if FRU data is available. Move the logic to FRU specific file. Signed-off-by: Lijo Lazar <[email protected]> Reviewed-by: Hawking Zhang <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent b029753 commit 7957ec8

File tree

3 files changed

+94
-68
lines changed

3 files changed

+94
-68
lines changed

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

Lines changed: 3 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -164,71 +164,6 @@ static DEVICE_ATTR(pcie_replay_count, 0444,
164164

165165
static void amdgpu_device_get_pcie_info(struct amdgpu_device *adev);
166166

167-
/**
168-
* DOC: product_name
169-
*
170-
* The amdgpu driver provides a sysfs API for reporting the product name
171-
* for the device
172-
* The file product_name is used for this and returns the product name
173-
* as returned from the FRU.
174-
* NOTE: This is only available for certain server cards
175-
*/
176-
177-
static ssize_t amdgpu_device_get_product_name(struct device *dev,
178-
struct device_attribute *attr, char *buf)
179-
{
180-
struct drm_device *ddev = dev_get_drvdata(dev);
181-
struct amdgpu_device *adev = drm_to_adev(ddev);
182-
183-
return sysfs_emit(buf, "%s\n", adev->product_name);
184-
}
185-
186-
static DEVICE_ATTR(product_name, 0444,
187-
amdgpu_device_get_product_name, NULL);
188-
189-
/**
190-
* DOC: product_number
191-
*
192-
* The amdgpu driver provides a sysfs API for reporting the part number
193-
* for the device
194-
* The file product_number is used for this and returns the part number
195-
* as returned from the FRU.
196-
* NOTE: This is only available for certain server cards
197-
*/
198-
199-
static ssize_t amdgpu_device_get_product_number(struct device *dev,
200-
struct device_attribute *attr, char *buf)
201-
{
202-
struct drm_device *ddev = dev_get_drvdata(dev);
203-
struct amdgpu_device *adev = drm_to_adev(ddev);
204-
205-
return sysfs_emit(buf, "%s\n", adev->product_number);
206-
}
207-
208-
static DEVICE_ATTR(product_number, 0444,
209-
amdgpu_device_get_product_number, NULL);
210-
211-
/**
212-
* DOC: serial_number
213-
*
214-
* The amdgpu driver provides a sysfs API for reporting the serial number
215-
* for the device
216-
* The file serial_number is used for this and returns the serial number
217-
* as returned from the FRU.
218-
* NOTE: This is only available for certain server cards
219-
*/
220-
221-
static ssize_t amdgpu_device_get_serial_number(struct device *dev,
222-
struct device_attribute *attr, char *buf)
223-
{
224-
struct drm_device *ddev = dev_get_drvdata(dev);
225-
struct amdgpu_device *adev = drm_to_adev(ddev);
226-
227-
return sysfs_emit(buf, "%s\n", adev->serial);
228-
}
229-
230-
static DEVICE_ATTR(serial_number, 0444,
231-
amdgpu_device_get_serial_number, NULL);
232167

233168
/**
234169
* amdgpu_device_supports_px - Is the device a dGPU with ATPX power control
@@ -3550,9 +3485,6 @@ static void amdgpu_device_check_iommu_direct_map(struct amdgpu_device *adev)
35503485
}
35513486

35523487
static const struct attribute *amdgpu_dev_attributes[] = {
3553-
&dev_attr_product_name.attr,
3554-
&dev_attr_product_number.attr,
3555-
&dev_attr_serial_number.attr,
35563488
&dev_attr_pcie_replay_count.attr,
35573489
NULL
35583490
};
@@ -3967,6 +3899,8 @@ int amdgpu_device_init(struct amdgpu_device *adev,
39673899
if (r)
39683900
dev_err(adev->dev, "Could not create amdgpu device attr\n");
39693901

3902+
amdgpu_fru_sysfs_init(adev);
3903+
39703904
if (IS_ENABLED(CONFIG_PERF_EVENTS))
39713905
r = amdgpu_pmu_init(adev);
39723906
if (r)
@@ -4086,6 +4020,7 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)
40864020
if (adev->ucode_sysfs_en)
40874021
amdgpu_ucode_sysfs_fini(adev);
40884022
sysfs_remove_files(&adev->dev->kobj, amdgpu_dev_attributes);
4023+
amdgpu_fru_sysfs_fini(adev);
40894024

40904025
/* disable ras feature must before hw fini */
40914026
amdgpu_ras_pre_fini(adev);

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

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,92 @@ int amdgpu_fru_get_product_info(struct amdgpu_device *adev)
212212
kfree(pia);
213213
return 0;
214214
}
215+
216+
/**
217+
* DOC: product_name
218+
*
219+
* The amdgpu driver provides a sysfs API for reporting the product name
220+
* for the device
221+
* The file product_name is used for this and returns the product name
222+
* as returned from the FRU.
223+
* NOTE: This is only available for certain server cards
224+
*/
225+
226+
static ssize_t amdgpu_fru_product_name_show(struct device *dev,
227+
struct device_attribute *attr,
228+
char *buf)
229+
{
230+
struct drm_device *ddev = dev_get_drvdata(dev);
231+
struct amdgpu_device *adev = drm_to_adev(ddev);
232+
233+
return sysfs_emit(buf, "%s\n", adev->product_name);
234+
}
235+
236+
static DEVICE_ATTR(product_name, 0444, amdgpu_fru_product_name_show, NULL);
237+
238+
/**
239+
* DOC: product_number
240+
*
241+
* The amdgpu driver provides a sysfs API for reporting the part number
242+
* for the device
243+
* The file product_number is used for this and returns the part number
244+
* as returned from the FRU.
245+
* NOTE: This is only available for certain server cards
246+
*/
247+
248+
static ssize_t amdgpu_fru_product_number_show(struct device *dev,
249+
struct device_attribute *attr,
250+
char *buf)
251+
{
252+
struct drm_device *ddev = dev_get_drvdata(dev);
253+
struct amdgpu_device *adev = drm_to_adev(ddev);
254+
255+
return sysfs_emit(buf, "%s\n", adev->product_number);
256+
}
257+
258+
static DEVICE_ATTR(product_number, 0444, amdgpu_fru_product_number_show, NULL);
259+
260+
/**
261+
* DOC: serial_number
262+
*
263+
* The amdgpu driver provides a sysfs API for reporting the serial number
264+
* for the device
265+
* The file serial_number is used for this and returns the serial number
266+
* as returned from the FRU.
267+
* NOTE: This is only available for certain server cards
268+
*/
269+
270+
static ssize_t amdgpu_fru_serial_number_show(struct device *dev,
271+
struct device_attribute *attr,
272+
char *buf)
273+
{
274+
struct drm_device *ddev = dev_get_drvdata(dev);
275+
struct amdgpu_device *adev = drm_to_adev(ddev);
276+
277+
return sysfs_emit(buf, "%s\n", adev->serial);
278+
}
279+
280+
static DEVICE_ATTR(serial_number, 0444, amdgpu_fru_serial_number_show, NULL);
281+
282+
static const struct attribute *amdgpu_fru_attributes[] = {
283+
&dev_attr_product_name.attr,
284+
&dev_attr_product_number.attr,
285+
&dev_attr_serial_number.attr,
286+
NULL
287+
};
288+
289+
int amdgpu_fru_sysfs_init(struct amdgpu_device *adev)
290+
{
291+
if (!is_fru_eeprom_supported(adev, NULL))
292+
return 0;
293+
294+
return sysfs_create_files(&adev->dev->kobj, amdgpu_fru_attributes);
295+
}
296+
297+
void amdgpu_fru_sysfs_fini(struct amdgpu_device *adev)
298+
{
299+
if (!is_fru_eeprom_supported(adev, NULL))
300+
return;
301+
302+
sysfs_remove_files(&adev->dev->kobj, amdgpu_fru_attributes);
303+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,7 @@
2525
#define __AMDGPU_FRU_EEPROM_H__
2626

2727
int amdgpu_fru_get_product_info(struct amdgpu_device *adev);
28+
int amdgpu_fru_sysfs_init(struct amdgpu_device *adev);
29+
void amdgpu_fru_sysfs_fini(struct amdgpu_device *adev);
2830

2931
#endif // __AMDGPU_FRU_EEPROM_H__

0 commit comments

Comments
 (0)