diff options
author | Andrey Grodzovsky <andrey.grodzovsky@amd.com> | 2019-03-05 10:39:08 -0500 |
---|---|---|
committer | Alex Deucher <alexander.deucher@amd.com> | 2019-03-19 16:36:48 -0400 |
commit | b1fa8c89556e8d704e9a2e014151c47c64f02e06 (patch) | |
tree | 9b3d8a5aa7696eba5c88adf6cade39b506a36163 /drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | |
parent | b5dcec9c90fdb3287cd465ee8d3fb00d33e1133d (diff) |
drm/amdgpu: Add sysfs entries for xgmi hive v2.
For each device a file xgmi_device_id is created.
On the first device a subdirectory named xgmi_hive_info is created,
It contains a file named hive_id and symlinks named node 1-4 linking
to each device in the hive.
v2: Return error codes instead of '-1' and few misspellings.
Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c')
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 145 |
1 files changed, 142 insertions, 3 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c index 407dd16cc35c..fcc4b05c745c 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | |||
@@ -34,12 +34,132 @@ static DEFINE_MUTEX(xgmi_mutex); | |||
34 | static struct amdgpu_hive_info xgmi_hives[AMDGPU_MAX_XGMI_HIVE]; | 34 | static struct amdgpu_hive_info xgmi_hives[AMDGPU_MAX_XGMI_HIVE]; |
35 | static unsigned hive_count = 0; | 35 | static unsigned hive_count = 0; |
36 | 36 | ||
37 | |||
38 | void *amdgpu_xgmi_hive_try_lock(struct amdgpu_hive_info *hive) | 37 | void *amdgpu_xgmi_hive_try_lock(struct amdgpu_hive_info *hive) |
39 | { | 38 | { |
40 | return &hive->device_list; | 39 | return &hive->device_list; |
41 | } | 40 | } |
42 | 41 | ||
42 | static ssize_t amdgpu_xgmi_show_hive_id(struct device *dev, | ||
43 | struct device_attribute *attr, char *buf) | ||
44 | { | ||
45 | struct amdgpu_hive_info *hive = | ||
46 | container_of(attr, struct amdgpu_hive_info, dev_attr); | ||
47 | |||
48 | return snprintf(buf, PAGE_SIZE, "%llu\n", hive->hive_id); | ||
49 | } | ||
50 | |||
51 | static int amdgpu_xgmi_sysfs_create(struct amdgpu_device *adev, | ||
52 | struct amdgpu_hive_info *hive) | ||
53 | { | ||
54 | int ret = 0; | ||
55 | |||
56 | if (WARN_ON(hive->kobj)) | ||
57 | return -EINVAL; | ||
58 | |||
59 | hive->kobj = kobject_create_and_add("xgmi_hive_info", &adev->dev->kobj); | ||
60 | if (!hive->kobj) { | ||
61 | dev_err(adev->dev, "XGMI: Failed to allocate sysfs entry!\n"); | ||
62 | return -EINVAL; | ||
63 | } | ||
64 | |||
65 | hive->dev_attr = (struct device_attribute) { | ||
66 | .attr = { | ||
67 | .name = "xgmi_hive_id", | ||
68 | .mode = S_IRUGO, | ||
69 | |||
70 | }, | ||
71 | .show = amdgpu_xgmi_show_hive_id, | ||
72 | }; | ||
73 | |||
74 | ret = sysfs_create_file(hive->kobj, &hive->dev_attr.attr); | ||
75 | if (ret) { | ||
76 | dev_err(adev->dev, "XGMI: Failed to create device file xgmi_hive_id\n"); | ||
77 | kobject_del(hive->kobj); | ||
78 | kobject_put(hive->kobj); | ||
79 | hive->kobj = NULL; | ||
80 | } | ||
81 | |||
82 | return ret; | ||
83 | } | ||
84 | |||
85 | static void amdgpu_xgmi_sysfs_destroy(struct amdgpu_device *adev, | ||
86 | struct amdgpu_hive_info *hive) | ||
87 | { | ||
88 | sysfs_remove_file(hive->kobj, &hive->dev_attr.attr); | ||
89 | kobject_del(hive->kobj); | ||
90 | kobject_put(hive->kobj); | ||
91 | hive->kobj = NULL; | ||
92 | } | ||
93 | |||
94 | static ssize_t amdgpu_xgmi_show_device_id(struct device *dev, | ||
95 | struct device_attribute *attr, | ||
96 | char *buf) | ||
97 | { | ||
98 | struct drm_device *ddev = dev_get_drvdata(dev); | ||
99 | struct amdgpu_device *adev = ddev->dev_private; | ||
100 | |||
101 | return snprintf(buf, PAGE_SIZE, "%llu\n", adev->gmc.xgmi.node_id); | ||
102 | |||
103 | } | ||
104 | |||
105 | |||
106 | static DEVICE_ATTR(xgmi_device_id, S_IRUGO, amdgpu_xgmi_show_device_id, NULL); | ||
107 | |||
108 | |||
109 | static int amdgpu_xgmi_sysfs_add_dev_info(struct amdgpu_device *adev, | ||
110 | struct amdgpu_hive_info *hive) | ||
111 | { | ||
112 | int ret = 0; | ||
113 | char node[10] = { 0 }; | ||
114 | |||
115 | /* Create xgmi device id file */ | ||
116 | ret = device_create_file(adev->dev, &dev_attr_xgmi_device_id); | ||
117 | if (ret) { | ||
118 | dev_err(adev->dev, "XGMI: Failed to create device file xgmi_device_id\n"); | ||
119 | return ret; | ||
120 | } | ||
121 | |||
122 | /* Create sysfs link to hive info folder on the first device */ | ||
123 | if (adev != hive->adev) { | ||
124 | ret = sysfs_create_link(&adev->dev->kobj, hive->kobj, | ||
125 | "xgmi_hive_info"); | ||
126 | if (ret) { | ||
127 | dev_err(adev->dev, "XGMI: Failed to create link to hive info"); | ||
128 | goto remove_file; | ||
129 | } | ||
130 | } | ||
131 | |||
132 | sprintf(node, "node%d", hive->number_devices); | ||
133 | /* Create sysfs link form the hive folder to yourself */ | ||
134 | ret = sysfs_create_link(hive->kobj, &adev->dev->kobj, node); | ||
135 | if (ret) { | ||
136 | dev_err(adev->dev, "XGMI: Failed to create link from hive info"); | ||
137 | goto remove_link; | ||
138 | } | ||
139 | |||
140 | goto success; | ||
141 | |||
142 | |||
143 | remove_link: | ||
144 | sysfs_remove_link(&adev->dev->kobj, adev->ddev->unique); | ||
145 | |||
146 | remove_file: | ||
147 | device_remove_file(adev->dev, &dev_attr_xgmi_device_id); | ||
148 | |||
149 | success: | ||
150 | return ret; | ||
151 | } | ||
152 | |||
153 | static void amdgpu_xgmi_sysfs_rem_dev_info(struct amdgpu_device *adev, | ||
154 | struct amdgpu_hive_info *hive) | ||
155 | { | ||
156 | device_remove_file(adev->dev, &dev_attr_xgmi_device_id); | ||
157 | sysfs_remove_link(&adev->dev->kobj, adev->ddev->unique); | ||
158 | sysfs_remove_link(hive->kobj, adev->ddev->unique); | ||
159 | } | ||
160 | |||
161 | |||
162 | |||
43 | struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev, int lock) | 163 | struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev, int lock) |
44 | { | 164 | { |
45 | int i; | 165 | int i; |
@@ -66,10 +186,18 @@ struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev, int lo | |||
66 | 186 | ||
67 | /* initialize new hive if not exist */ | 187 | /* initialize new hive if not exist */ |
68 | tmp = &xgmi_hives[hive_count++]; | 188 | tmp = &xgmi_hives[hive_count++]; |
189 | |||
190 | if (amdgpu_xgmi_sysfs_create(adev, tmp)) { | ||
191 | mutex_unlock(&xgmi_mutex); | ||
192 | return NULL; | ||
193 | } | ||
194 | |||
195 | tmp->adev = adev; | ||
69 | tmp->hive_id = adev->gmc.xgmi.hive_id; | 196 | tmp->hive_id = adev->gmc.xgmi.hive_id; |
70 | INIT_LIST_HEAD(&tmp->device_list); | 197 | INIT_LIST_HEAD(&tmp->device_list); |
71 | mutex_init(&tmp->hive_lock); | 198 | mutex_init(&tmp->hive_lock); |
72 | mutex_init(&tmp->reset_lock); | 199 | mutex_init(&tmp->reset_lock); |
200 | |||
73 | if (lock) | 201 | if (lock) |
74 | mutex_lock(&tmp->hive_lock); | 202 | mutex_lock(&tmp->hive_lock); |
75 | 203 | ||
@@ -156,8 +284,17 @@ int amdgpu_xgmi_add_device(struct amdgpu_device *adev) | |||
156 | break; | 284 | break; |
157 | } | 285 | } |
158 | 286 | ||
159 | dev_info(adev->dev, "XGMI: Add node %d, hive 0x%llx.\n", | 287 | if (!ret) |
160 | adev->gmc.xgmi.physical_node_id, adev->gmc.xgmi.hive_id); | 288 | ret = amdgpu_xgmi_sysfs_add_dev_info(adev, hive); |
289 | |||
290 | if (!ret) | ||
291 | dev_info(adev->dev, "XGMI: Add node %d, hive 0x%llx.\n", | ||
292 | adev->gmc.xgmi.physical_node_id, adev->gmc.xgmi.hive_id); | ||
293 | else | ||
294 | dev_err(adev->dev, "XGMI: Failed to add node %d, hive 0x%llx ret: %d\n", | ||
295 | adev->gmc.xgmi.physical_node_id, adev->gmc.xgmi.hive_id, | ||
296 | ret); | ||
297 | |||
161 | 298 | ||
162 | mutex_unlock(&hive->hive_lock); | 299 | mutex_unlock(&hive->hive_lock); |
163 | exit: | 300 | exit: |
@@ -176,9 +313,11 @@ void amdgpu_xgmi_remove_device(struct amdgpu_device *adev) | |||
176 | return; | 313 | return; |
177 | 314 | ||
178 | if (!(hive->number_devices--)) { | 315 | if (!(hive->number_devices--)) { |
316 | amdgpu_xgmi_sysfs_destroy(adev, hive); | ||
179 | mutex_destroy(&hive->hive_lock); | 317 | mutex_destroy(&hive->hive_lock); |
180 | mutex_destroy(&hive->reset_lock); | 318 | mutex_destroy(&hive->reset_lock); |
181 | } else { | 319 | } else { |
320 | amdgpu_xgmi_sysfs_rem_dev_info(adev, hive); | ||
182 | mutex_unlock(&hive->hive_lock); | 321 | mutex_unlock(&hive->hive_lock); |
183 | } | 322 | } |
184 | } | 323 | } |