@@ -1725,50 +1725,50 @@ static struct amdgpu_device_attr amdgpu_device_attrs[] = {
1725
1725
};
1726
1726
1727
1727
static int default_attr_update (struct amdgpu_device * adev , struct amdgpu_device_attr * attr ,
1728
- uint32_t mask )
1728
+ uint32_t mask , enum amdgpu_device_attr_states * states )
1729
1729
{
1730
1730
struct device_attribute * dev_attr = & attr -> dev_attr ;
1731
1731
const char * attr_name = dev_attr -> attr .name ;
1732
1732
struct pp_hwmgr * hwmgr = adev -> powerplay .pp_handle ;
1733
1733
enum amd_asic_type asic_type = adev -> asic_type ;
1734
1734
1735
1735
if (!(attr -> flags & mask )) {
1736
- attr -> states = ATTR_STATE_UNSUPPORTED ;
1736
+ * states = ATTR_STATE_UNSUPPORTED ;
1737
1737
return 0 ;
1738
1738
}
1739
1739
1740
1740
#define DEVICE_ATTR_IS (_name ) (!strcmp(attr_name, #_name))
1741
1741
1742
1742
if (DEVICE_ATTR_IS (pp_dpm_socclk )) {
1743
1743
if (asic_type < CHIP_VEGA10 )
1744
- attr -> states = ATTR_STATE_UNSUPPORTED ;
1744
+ * states = ATTR_STATE_UNSUPPORTED ;
1745
1745
} else if (DEVICE_ATTR_IS (pp_dpm_dcefclk )) {
1746
1746
if (asic_type < CHIP_VEGA10 || asic_type == CHIP_ARCTURUS )
1747
- attr -> states = ATTR_STATE_UNSUPPORTED ;
1747
+ * states = ATTR_STATE_UNSUPPORTED ;
1748
1748
} else if (DEVICE_ATTR_IS (pp_dpm_fclk )) {
1749
1749
if (asic_type < CHIP_VEGA20 )
1750
- attr -> states = ATTR_STATE_UNSUPPORTED ;
1750
+ * states = ATTR_STATE_UNSUPPORTED ;
1751
1751
} else if (DEVICE_ATTR_IS (pp_dpm_pcie )) {
1752
1752
if (asic_type == CHIP_ARCTURUS )
1753
- attr -> states = ATTR_STATE_UNSUPPORTED ;
1753
+ * states = ATTR_STATE_UNSUPPORTED ;
1754
1754
} else if (DEVICE_ATTR_IS (pp_od_clk_voltage )) {
1755
- attr -> states = ATTR_STATE_UNSUPPORTED ;
1755
+ * states = ATTR_STATE_UNSUPPORTED ;
1756
1756
if ((is_support_sw_smu (adev ) && adev -> smu .od_enabled ) ||
1757
1757
(!is_support_sw_smu (adev ) && hwmgr -> od_enabled ))
1758
- attr -> states = ATTR_STATE_SUPPORTED ;
1758
+ * states = ATTR_STATE_SUPPORTED ;
1759
1759
} else if (DEVICE_ATTR_IS (mem_busy_percent )) {
1760
1760
if (adev -> flags & AMD_IS_APU || asic_type == CHIP_VEGA10 )
1761
- attr -> states = ATTR_STATE_UNSUPPORTED ;
1761
+ * states = ATTR_STATE_UNSUPPORTED ;
1762
1762
} else if (DEVICE_ATTR_IS (pcie_bw )) {
1763
1763
/* PCIe Perf counters won't work on APU nodes */
1764
1764
if (adev -> flags & AMD_IS_APU )
1765
- attr -> states = ATTR_STATE_UNSUPPORTED ;
1765
+ * states = ATTR_STATE_UNSUPPORTED ;
1766
1766
} else if (DEVICE_ATTR_IS (unique_id )) {
1767
1767
if (!adev -> unique_id )
1768
- attr -> states = ATTR_STATE_UNSUPPORTED ;
1768
+ * states = ATTR_STATE_UNSUPPORTED ;
1769
1769
} else if (DEVICE_ATTR_IS (pp_features )) {
1770
1770
if (adev -> flags & AMD_IS_APU || asic_type < CHIP_VEGA10 )
1771
- attr -> states = ATTR_STATE_UNSUPPORTED ;
1771
+ * states = ATTR_STATE_UNSUPPORTED ;
1772
1772
}
1773
1773
1774
1774
if (asic_type == CHIP_ARCTURUS ) {
@@ -1789,27 +1789,29 @@ static int default_attr_update(struct amdgpu_device *adev, struct amdgpu_device_
1789
1789
1790
1790
static int amdgpu_device_attr_create (struct amdgpu_device * adev ,
1791
1791
struct amdgpu_device_attr * attr ,
1792
- uint32_t mask )
1792
+ uint32_t mask , struct list_head * attr_list )
1793
1793
{
1794
1794
int ret = 0 ;
1795
1795
struct device_attribute * dev_attr = & attr -> dev_attr ;
1796
1796
const char * name = dev_attr -> attr .name ;
1797
+ enum amdgpu_device_attr_states attr_states = ATTR_STATE_SUPPORTED ;
1798
+ struct amdgpu_device_attr_entry * attr_entry ;
1799
+
1797
1800
int (* attr_update )(struct amdgpu_device * adev , struct amdgpu_device_attr * attr ,
1798
- uint32_t mask ) = default_attr_update ;
1801
+ uint32_t mask , enum amdgpu_device_attr_states * states ) = default_attr_update ;
1799
1802
1800
1803
BUG_ON (!attr );
1801
1804
1802
1805
attr_update = attr -> attr_update ? attr_update : default_attr_update ;
1803
1806
1804
- ret = attr_update (adev , attr , mask );
1807
+ ret = attr_update (adev , attr , mask , & attr_states );
1805
1808
if (ret ) {
1806
1809
dev_err (adev -> dev , "failed to update device file %s, ret = %d\n" ,
1807
1810
name , ret );
1808
1811
return ret ;
1809
1812
}
1810
1813
1811
- /* the attr->states maybe changed after call attr->attr_update function */
1812
- if (attr -> states == ATTR_STATE_UNSUPPORTED )
1814
+ if (attr_states == ATTR_STATE_UNSUPPORTED )
1813
1815
return 0 ;
1814
1816
1815
1817
ret = device_create_file (adev -> dev , dev_attr );
@@ -1818,7 +1820,14 @@ static int amdgpu_device_attr_create(struct amdgpu_device *adev,
1818
1820
name , ret );
1819
1821
}
1820
1822
1821
- attr -> states = ATTR_STATE_SUPPORTED ;
1823
+ attr_entry = kmalloc (sizeof (* attr_entry ), GFP_KERNEL );
1824
+ if (!attr_entry )
1825
+ return - ENOMEM ;
1826
+
1827
+ attr_entry -> attr = attr ;
1828
+ INIT_LIST_HEAD (& attr_entry -> entry );
1829
+
1830
+ list_add_tail (& attr_entry -> entry , attr_list );
1822
1831
1823
1832
return ret ;
1824
1833
}
@@ -1827,45 +1836,48 @@ static void amdgpu_device_attr_remove(struct amdgpu_device *adev, struct amdgpu_
1827
1836
{
1828
1837
struct device_attribute * dev_attr = & attr -> dev_attr ;
1829
1838
1830
- if (attr -> states == ATTR_STATE_UNSUPPORTED )
1831
- return ;
1832
-
1833
1839
device_remove_file (adev -> dev , dev_attr );
1834
-
1835
- attr -> states = ATTR_STATE_UNSUPPORTED ;
1836
1840
}
1837
1841
1842
+ static void amdgpu_device_attr_remove_groups (struct amdgpu_device * adev ,
1843
+ struct list_head * attr_list );
1844
+
1838
1845
static int amdgpu_device_attr_create_groups (struct amdgpu_device * adev ,
1839
1846
struct amdgpu_device_attr * attrs ,
1840
1847
uint32_t counts ,
1841
- uint32_t mask )
1848
+ uint32_t mask ,
1849
+ struct list_head * attr_list )
1842
1850
{
1843
1851
int ret = 0 ;
1844
1852
uint32_t i = 0 ;
1845
1853
1846
1854
for (i = 0 ; i < counts ; i ++ ) {
1847
- ret = amdgpu_device_attr_create (adev , & attrs [i ], mask );
1855
+ ret = amdgpu_device_attr_create (adev , & attrs [i ], mask , attr_list );
1848
1856
if (ret )
1849
1857
goto failed ;
1850
1858
}
1851
1859
1852
1860
return 0 ;
1853
1861
1854
1862
failed :
1855
- while (i -- )
1856
- amdgpu_device_attr_remove (adev , & attrs [i ]);
1863
+ amdgpu_device_attr_remove_groups (adev , attr_list );
1857
1864
1858
1865
return ret ;
1859
1866
}
1860
1867
1861
1868
static void amdgpu_device_attr_remove_groups (struct amdgpu_device * adev ,
1862
- struct amdgpu_device_attr * attrs ,
1863
- uint32_t counts )
1869
+ struct list_head * attr_list )
1864
1870
{
1865
- uint32_t i = 0 ;
1871
+ struct amdgpu_device_attr_entry * entry , * entry_tmp ;
1866
1872
1867
- for (i = 0 ; i < counts ; i ++ )
1868
- amdgpu_device_attr_remove (adev , & attrs [i ]);
1873
+ if (list_empty (attr_list ))
1874
+ return ;
1875
+
1876
+ list_for_each_entry_safe (entry , entry_tmp , attr_list , entry ) {
1877
+ amdgpu_device_attr_remove (adev , entry -> attr );
1878
+ list_del (& entry -> entry );
1879
+ kfree (entry );
1880
+ }
1869
1881
}
1870
1882
1871
1883
static ssize_t amdgpu_hwmon_show_temp (struct device * dev ,
@@ -3276,6 +3288,8 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
3276
3288
if (adev -> pm .dpm_enabled == 0 )
3277
3289
return 0 ;
3278
3290
3291
+ INIT_LIST_HEAD (& adev -> pm .pm_attr_list );
3292
+
3279
3293
adev -> pm .int_hwmon_dev = hwmon_device_register_with_groups (adev -> dev ,
3280
3294
DRIVER_NAME , adev ,
3281
3295
hwmon_groups );
@@ -3302,7 +3316,8 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
3302
3316
ret = amdgpu_device_attr_create_groups (adev ,
3303
3317
amdgpu_device_attrs ,
3304
3318
ARRAY_SIZE (amdgpu_device_attrs ),
3305
- mask );
3319
+ mask ,
3320
+ & adev -> pm .pm_attr_list );
3306
3321
if (ret )
3307
3322
return ret ;
3308
3323
@@ -3319,9 +3334,7 @@ void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)
3319
3334
if (adev -> pm .int_hwmon_dev )
3320
3335
hwmon_device_unregister (adev -> pm .int_hwmon_dev );
3321
3336
3322
- amdgpu_device_attr_remove_groups (adev ,
3323
- amdgpu_device_attrs ,
3324
- ARRAY_SIZE (amdgpu_device_attrs ));
3337
+ amdgpu_device_attr_remove_groups (adev , & adev -> pm .pm_attr_list );
3325
3338
}
3326
3339
3327
3340
void amdgpu_pm_compute_clocks (struct amdgpu_device * adev )
0 commit comments