@@ -71,6 +71,15 @@ vram_d3cold_threshold_store(struct device *dev, struct device_attribute *attr,
7171
7272static DEVICE_ATTR_RW (vram_d3cold_threshold );
7373
74+ static struct attribute * vram_attrs [] = {
75+ & dev_attr_vram_d3cold_threshold .attr ,
76+ NULL
77+ };
78+
79+ static const struct attribute_group vram_attr_group = {
80+ .attrs = vram_attrs ,
81+ };
82+
7483static ssize_t
7584lb_fan_control_version_show (struct device * dev , struct device_attribute * attr , char * buf )
7685{
@@ -149,41 +158,16 @@ lb_voltage_regulator_version_show(struct device *dev, struct device_attribute *a
149158}
150159static DEVICE_ATTR_ADMIN_RO (lb_voltage_regulator_version );
151160
152- static int late_bind_create_files (struct device * dev )
153- {
154- struct xe_device * xe = pdev_to_xe_device (to_pci_dev (dev ));
155- struct xe_tile * root = xe_device_get_root_tile (xe );
156- u32 cap = 0 ;
157- int ret ;
158-
159- xe_pm_runtime_get (xe );
160-
161- ret = xe_pcode_read (root , PCODE_MBOX (PCODE_LATE_BINDING , GET_CAPABILITY_STATUS , 0 ),
162- & cap , NULL );
163- if (ret ) {
164- if (ret == - ENXIO ) {
165- drm_dbg (& xe -> drm , "Late binding not supported by firmware\n" );
166- ret = 0 ;
167- }
168- goto out ;
169- }
170-
171- if (REG_FIELD_GET (V1_FAN_SUPPORTED , cap )) {
172- ret = sysfs_create_file (& dev -> kobj , & dev_attr_lb_fan_control_version .attr );
173- if (ret )
174- goto out ;
175- }
176-
177- if (REG_FIELD_GET (VR_PARAMS_SUPPORTED , cap ))
178- ret = sysfs_create_file (& dev -> kobj , & dev_attr_lb_voltage_regulator_version .attr );
179- out :
180- xe_pm_runtime_put (xe );
181-
182- return ret ;
183- }
161+ static struct attribute * late_bind_attrs [] = {
162+ & dev_attr_lb_fan_control_version .attr ,
163+ & dev_attr_lb_voltage_regulator_version .attr ,
164+ NULL
165+ };
184166
185- static void late_bind_remove_files (struct device * dev )
167+ static umode_t late_bind_attr_is_visible (struct kobject * kobj ,
168+ struct attribute * attr , int n )
186169{
170+ struct device * dev = kobj_to_dev (kobj );
187171 struct xe_device * xe = pdev_to_xe_device (to_pci_dev (dev ));
188172 struct xe_tile * root = xe_device_get_root_tile (xe );
189173 u32 cap = 0 ;
@@ -193,18 +177,25 @@ static void late_bind_remove_files(struct device *dev)
193177
194178 ret = xe_pcode_read (root , PCODE_MBOX (PCODE_LATE_BINDING , GET_CAPABILITY_STATUS , 0 ),
195179 & cap , NULL );
180+ xe_pm_runtime_put (xe );
196181 if (ret )
197- goto out ;
182+ return 0 ;
198183
199- if (REG_FIELD_GET (V1_FAN_SUPPORTED , cap ))
200- sysfs_remove_file (& dev -> kobj , & dev_attr_lb_fan_control_version .attr );
184+ if (attr == & dev_attr_lb_fan_control_version .attr &&
185+ REG_FIELD_GET (V1_FAN_SUPPORTED , cap ))
186+ return attr -> mode ;
187+ if (attr == & dev_attr_lb_voltage_regulator_version .attr &&
188+ REG_FIELD_GET (VR_PARAMS_SUPPORTED , cap ))
189+ return attr -> mode ;
201190
202- if (REG_FIELD_GET (VR_PARAMS_SUPPORTED , cap ))
203- sysfs_remove_file (& dev -> kobj , & dev_attr_lb_voltage_regulator_version .attr );
204- out :
205- xe_pm_runtime_put (xe );
191+ return 0 ;
206192}
207193
194+ static const struct attribute_group late_bind_attr_group = {
195+ .attrs = late_bind_attrs ,
196+ .is_visible = late_bind_attr_is_visible ,
197+ };
198+
208199/**
209200 * DOC: PCIe Gen5 Limitations
210201 *
@@ -278,49 +269,36 @@ auto_link_downgrade_status_show(struct device *dev, struct device_attribute *att
278269}
279270static DEVICE_ATTR_ADMIN_RO (auto_link_downgrade_status );
280271
281- static const struct attribute * auto_link_downgrade_attrs [] = {
272+ static struct attribute * auto_link_downgrade_attrs [] = {
282273 & dev_attr_auto_link_downgrade_capable .attr ,
283274 & dev_attr_auto_link_downgrade_status .attr ,
284275 NULL
285276};
286277
287- static void xe_device_sysfs_fini (void * arg )
288- {
289- struct xe_device * xe = arg ;
290-
291- if (xe -> d3cold .capable )
292- sysfs_remove_file (& xe -> drm .dev -> kobj , & dev_attr_vram_d3cold_threshold .attr );
293-
294- if (xe -> info .platform == XE_BATTLEMAGE ) {
295- sysfs_remove_files (& xe -> drm .dev -> kobj , auto_link_downgrade_attrs );
296- late_bind_remove_files (xe -> drm .dev );
297- }
298- }
278+ static const struct attribute_group auto_link_downgrade_attr_group = {
279+ .attrs = auto_link_downgrade_attrs ,
280+ };
299281
300282int xe_device_sysfs_init (struct xe_device * xe )
301283{
302284 struct device * dev = xe -> drm .dev ;
303285 int ret ;
304286
305287 if (xe -> d3cold .capable ) {
306- ret = sysfs_create_file ( & dev -> kobj , & dev_attr_vram_d3cold_threshold . attr );
288+ ret = devm_device_add_group ( dev , & vram_attr_group );
307289 if (ret )
308290 return ret ;
309291 }
310292
311293 if (xe -> info .platform == XE_BATTLEMAGE && !IS_SRIOV_VF (xe )) {
312- ret = sysfs_create_files ( & dev -> kobj , auto_link_downgrade_attrs );
294+ ret = devm_device_add_group ( dev , & auto_link_downgrade_attr_group );
313295 if (ret )
314- goto cleanup ;
296+ return ret ;
315297
316- ret = late_bind_create_files (dev );
298+ ret = devm_device_add_group (dev , & late_bind_attr_group );
317299 if (ret )
318- goto cleanup ;
300+ return ret ;
319301 }
320302
321- return devm_add_action_or_reset (dev , xe_device_sysfs_fini , xe );
322-
323- cleanup :
324- xe_device_sysfs_fini (xe );
325- return ret ;
303+ return 0 ;
326304}
0 commit comments