aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/radeon/radeon.h
diff options
context:
space:
mode:
authorMichel Dänzer <michel.daenzer@amd.com>2011-11-10 12:57:26 -0500
committerDave Airlie <airlied@redhat.com>2011-11-11 06:02:10 -0500
commit7a1619b97e978bb9c05fa4bbe64171068bd5bf85 (patch)
treec70a08db8ab123d51a622c062958786901473bdf /drivers/gpu/drm/radeon/radeon.h
parent471dd2ef3761de01348b19e83128a778df1d45b2 (diff)
drm/radeon: Make sure CS mutex is held across GPU reset.
This was only the case if the GPU reset was triggered from the CS ioctl, otherwise other processes could happily enter the CS ioctl and wreak havoc during the GPU reset. This is a little complicated because the GPU reset can be triggered from the CS ioctl, in which case we're already holding the mutex, or from other call paths, in which case we need to lock the mutex. AFAICT the mutex API doesn't allow recursive locking or finding out the mutex owner, so we need to handle this with helper functions which allow recursive locking from the same process. Signed-off-by: Michel Dänzer <michel.daenzer@amd.com> Reviewed-by: Jerome Glisse <jglisse@redhat.com> Signed-off-by: Dave Airlie <airlied@redhat.com>
Diffstat (limited to 'drivers/gpu/drm/radeon/radeon.h')
-rw-r--r--drivers/gpu/drm/radeon/radeon.h44
1 files changed, 43 insertions, 1 deletions
diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
index b316b301152f..85ef693850e7 100644
--- a/drivers/gpu/drm/radeon/radeon.h
+++ b/drivers/gpu/drm/radeon/radeon.h
@@ -1142,6 +1142,48 @@ struct r600_vram_scratch {
1142 u64 gpu_addr; 1142 u64 gpu_addr;
1143}; 1143};
1144 1144
1145
1146/*
1147 * Mutex which allows recursive locking from the same process.
1148 */
1149struct radeon_mutex {
1150 struct mutex mutex;
1151 struct task_struct *owner;
1152 int level;
1153};
1154
1155static inline void radeon_mutex_init(struct radeon_mutex *mutex)
1156{
1157 mutex_init(&mutex->mutex);
1158 mutex->owner = NULL;
1159 mutex->level = 0;
1160}
1161
1162static inline void radeon_mutex_lock(struct radeon_mutex *mutex)
1163{
1164 if (mutex_trylock(&mutex->mutex)) {
1165 /* The mutex was unlocked before, so it's ours now */
1166 mutex->owner = current;
1167 } else if (mutex->owner != current) {
1168 /* Another process locked the mutex, take it */
1169 mutex_lock(&mutex->mutex);
1170 mutex->owner = current;
1171 }
1172 /* Otherwise the mutex was already locked by this process */
1173
1174 mutex->level++;
1175}
1176
1177static inline void radeon_mutex_unlock(struct radeon_mutex *mutex)
1178{
1179 if (--mutex->level > 0)
1180 return;
1181
1182 mutex->owner = NULL;
1183 mutex_unlock(&mutex->mutex);
1184}
1185
1186
1145/* 1187/*
1146 * Core structure, functions and helpers. 1188 * Core structure, functions and helpers.
1147 */ 1189 */
@@ -1197,7 +1239,7 @@ struct radeon_device {
1197 struct radeon_gem gem; 1239 struct radeon_gem gem;
1198 struct radeon_pm pm; 1240 struct radeon_pm pm;
1199 uint32_t bios_scratch[RADEON_BIOS_NUM_SCRATCH]; 1241 uint32_t bios_scratch[RADEON_BIOS_NUM_SCRATCH];
1200 struct mutex cs_mutex; 1242 struct radeon_mutex cs_mutex;
1201 struct radeon_wb wb; 1243 struct radeon_wb wb;
1202 struct radeon_dummy_page dummy_page; 1244 struct radeon_dummy_page dummy_page;
1203 bool gpu_lockup; 1245 bool gpu_lockup;