Linux Audio

Check our new training course

Yocto / OpenEmbedded training

Mar 24-27, 2025, special US time zones
Register
Loading...
v3.1
  1/**************************************************************************
  2 *
  3 * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA.
  4 * All Rights Reserved.
  5 *
  6 * Permission is hereby granted, free of charge, to any person obtaining a
  7 * copy of this software and associated documentation files (the
  8 * "Software"), to deal in the Software without restriction, including
  9 * without limitation the rights to use, copy, modify, merge, publish,
 10 * distribute, sub license, and/or sell copies of the Software, and to
 11 * permit persons to whom the Software is furnished to do so, subject to
 12 * the following conditions:
 13 *
 14 * The above copyright notice and this permission notice (including the
 15 * next paragraph) shall be included in all copies or substantial portions
 16 * of the Software.
 17 *
 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 21 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
 22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
 25 *
 26 *
 27 **************************************************************************/
 28
 29/*
 30 * Authors:
 31 *    Thomas Hellström <thomas-at-tungstengraphics-dot-com>
 32 */
 33
 34#include "drmP.h"
 35#include "sis_drm.h"
 36#include "sis_drv.h"
 37
 38#include <video/sisfb.h>
 39
 40#define VIDEO_TYPE 0
 41#define AGP_TYPE 1
 42
 43
 
 
 
 
 
 
 44#if defined(CONFIG_FB_SIS) || defined(CONFIG_FB_SIS_MODULE)
 45/* fb management via fb device */
 46
 47#define SIS_MM_ALIGN_SHIFT 0
 48#define SIS_MM_ALIGN_MASK 0
 49
 50static void *sis_sman_mm_allocate(void *private, unsigned long size,
 51				  unsigned alignment)
 52{
 53	struct sis_memreq req;
 54
 55	req.size = size;
 56	sis_malloc(&req);
 57	if (req.size == 0)
 58		return NULL;
 59	else
 60		return (void *)(unsigned long)~req.offset;
 61}
 62
 63static void sis_sman_mm_free(void *private, void *ref)
 64{
 65	sis_free(~((unsigned long)ref));
 66}
 67
 68static void sis_sman_mm_destroy(void *private)
 69{
 70	;
 71}
 72
 73static unsigned long sis_sman_mm_offset(void *private, void *ref)
 74{
 75	return ~((unsigned long)ref);
 76}
 77
 78#else /* CONFIG_FB_SIS[_MODULE] */
 79
 80#define SIS_MM_ALIGN_SHIFT 4
 81#define SIS_MM_ALIGN_MASK ((1 << SIS_MM_ALIGN_SHIFT) - 1)
 82
 83#endif /* CONFIG_FB_SIS[_MODULE] */
 84
 85static int sis_fb_init(struct drm_device *dev, void *data, struct drm_file *file_priv)
 86{
 87	drm_sis_private_t *dev_priv = dev->dev_private;
 88	drm_sis_fb_t *fb = data;
 89	int ret;
 90
 91	mutex_lock(&dev->struct_mutex);
 92#if defined(CONFIG_FB_SIS) || defined(CONFIG_FB_SIS_MODULE)
 93	{
 94		struct drm_sman_mm sman_mm;
 95		sman_mm.private = (void *)0xFFFFFFFF;
 96		sman_mm.allocate = sis_sman_mm_allocate;
 97		sman_mm.free = sis_sman_mm_free;
 98		sman_mm.destroy = sis_sman_mm_destroy;
 99		sman_mm.offset = sis_sman_mm_offset;
100		ret =
101		    drm_sman_set_manager(&dev_priv->sman, VIDEO_TYPE, &sman_mm);
102	}
103#else
104	ret = drm_sman_set_range(&dev_priv->sman, VIDEO_TYPE, 0,
105				 fb->size >> SIS_MM_ALIGN_SHIFT);
106#endif
107
108	if (ret) {
109		DRM_ERROR("VRAM memory manager initialisation error\n");
110		mutex_unlock(&dev->struct_mutex);
111		return ret;
112	}
113
114	dev_priv->vram_initialized = 1;
115	dev_priv->vram_offset = fb->offset;
116
117	mutex_unlock(&dev->struct_mutex);
118	DRM_DEBUG("offset = %u, size = %u\n", fb->offset, fb->size);
119
120	return 0;
121}
122
123static int sis_drm_alloc(struct drm_device *dev, struct drm_file *file_priv,
124			 void *data, int pool)
125{
126	drm_sis_private_t *dev_priv = dev->dev_private;
127	drm_sis_mem_t *mem = data;
128	int retval = 0;
129	struct drm_memblock_item *item;
 
 
130
131	mutex_lock(&dev->struct_mutex);
132
133	if (0 == ((pool == 0) ? dev_priv->vram_initialized :
134		      dev_priv->agp_initialized)) {
135		DRM_ERROR
136		    ("Attempt to allocate from uninitialized memory manager.\n");
137		mutex_unlock(&dev->struct_mutex);
138		return -EINVAL;
139	}
140
141	mem->size = (mem->size + SIS_MM_ALIGN_MASK) >> SIS_MM_ALIGN_SHIFT;
142	item = drm_sman_alloc(&dev_priv->sman, pool, mem->size, 0,
143			      (unsigned long)file_priv);
 
 
144
145	mutex_unlock(&dev->struct_mutex);
146	if (item) {
147		mem->offset = ((pool == 0) ?
148			      dev_priv->vram_offset : dev_priv->agp_offset) +
149		    (item->mm->
150		     offset(item->mm, item->mm_info) << SIS_MM_ALIGN_SHIFT);
151		mem->free = item->user_hash.key;
152		mem->size = mem->size << SIS_MM_ALIGN_SHIFT;
153	} else {
154		mem->offset = 0;
155		mem->size = 0;
156		mem->free = 0;
157		retval = -ENOMEM;
 
 
 
 
 
 
 
 
 
158	}
 
 
159
160	DRM_DEBUG("alloc %d, size = %d, offset = %d\n", pool, mem->size,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161		  mem->offset);
162
163	return retval;
164}
165
166static int sis_drm_free(struct drm_device *dev, void *data, struct drm_file *file_priv)
167{
168	drm_sis_private_t *dev_priv = dev->dev_private;
169	drm_sis_mem_t *mem = data;
170	int ret;
171
172	mutex_lock(&dev->struct_mutex);
173	ret = drm_sman_free_key(&dev_priv->sman, mem->free);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
174	mutex_unlock(&dev->struct_mutex);
175	DRM_DEBUG("free = 0x%lx\n", mem->free);
176
177	return ret;
178}
179
180static int sis_fb_alloc(struct drm_device *dev, void *data,
181			struct drm_file *file_priv)
182{
183	return sis_drm_alloc(dev, file_priv, data, VIDEO_TYPE);
184}
185
186static int sis_ioctl_agp_init(struct drm_device *dev, void *data,
187			      struct drm_file *file_priv)
188{
189	drm_sis_private_t *dev_priv = dev->dev_private;
190	drm_sis_agp_t *agp = data;
191	int ret;
192	dev_priv = dev->dev_private;
193
194	mutex_lock(&dev->struct_mutex);
195	ret = drm_sman_set_range(&dev_priv->sman, AGP_TYPE, 0,
196				 agp->size >> SIS_MM_ALIGN_SHIFT);
197
198	if (ret) {
199		DRM_ERROR("AGP memory manager initialisation error\n");
200		mutex_unlock(&dev->struct_mutex);
201		return ret;
202	}
203
204	dev_priv->agp_initialized = 1;
205	dev_priv->agp_offset = agp->offset;
206	mutex_unlock(&dev->struct_mutex);
207
208	DRM_DEBUG("offset = %u, size = %u\n", agp->offset, agp->size);
209	return 0;
210}
211
212static int sis_ioctl_agp_alloc(struct drm_device *dev, void *data,
213			       struct drm_file *file_priv)
214{
215
216	return sis_drm_alloc(dev, file_priv, data, AGP_TYPE);
217}
218
219static drm_local_map_t *sis_reg_init(struct drm_device *dev)
220{
221	struct drm_map_list *entry;
222	drm_local_map_t *map;
223
224	list_for_each_entry(entry, &dev->maplist, head) {
225		map = entry->map;
226		if (!map)
227			continue;
228		if (map->type == _DRM_REGISTERS)
229			return map;
230	}
231	return NULL;
232}
233
234int sis_idle(struct drm_device *dev)
235{
236	drm_sis_private_t *dev_priv = dev->dev_private;
237	uint32_t idle_reg;
238	unsigned long end;
239	int i;
240
241	if (dev_priv->idle_fault)
242		return 0;
243
244	if (dev_priv->mmio == NULL) {
245		dev_priv->mmio = sis_reg_init(dev);
246		if (dev_priv->mmio == NULL) {
247			DRM_ERROR("Could not find register map.\n");
248			return 0;
249		}
250	}
251
252	/*
253	 * Implement a device switch here if needed
254	 */
255
256	if (dev_priv->chipset != SIS_CHIP_315)
257		return 0;
258
259	/*
260	 * Timeout after 3 seconds. We cannot use DRM_WAIT_ON here
261	 * because its polling frequency is too low.
262	 */
263
264	end = jiffies + (DRM_HZ * 3);
265
266	for (i = 0; i < 4; ++i) {
267		do {
268			idle_reg = SIS_READ(0x85cc);
269		} while (!time_after_eq(jiffies, end) &&
270			  ((idle_reg & 0x80000000) != 0x80000000));
271	}
272
273	if (time_after_eq(jiffies, end)) {
274		DRM_ERROR("Graphics engine idle timeout. "
275			  "Disabling idle check\n");
276		dev_priv->idle_fault = 1;
277	}
278
279	/*
280	 * The caller never sees an error code. It gets trapped
281	 * in libdrm.
282	 */
283
284	return 0;
285}
286
287
288void sis_lastclose(struct drm_device *dev)
289{
290	drm_sis_private_t *dev_priv = dev->dev_private;
291
292	if (!dev_priv)
293		return;
294
295	mutex_lock(&dev->struct_mutex);
296	drm_sman_cleanup(&dev_priv->sman);
297	dev_priv->vram_initialized = 0;
298	dev_priv->agp_initialized = 0;
 
 
 
 
 
299	dev_priv->mmio = NULL;
300	mutex_unlock(&dev->struct_mutex);
301}
302
303void sis_reclaim_buffers_locked(struct drm_device *dev,
304				struct drm_file *file_priv)
305{
306	drm_sis_private_t *dev_priv = dev->dev_private;
 
 
 
 
 
 
307
308	mutex_lock(&dev->struct_mutex);
309	if (drm_sman_owner_clean(&dev_priv->sman, (unsigned long)file_priv)) {
310		mutex_unlock(&dev->struct_mutex);
 
 
311		return;
312	}
313
314	if (dev->driver->dma_quiescent)
315		dev->driver->dma_quiescent(dev);
316
317	drm_sman_owner_cleanup(&dev_priv->sman, (unsigned long)file_priv);
 
 
 
 
 
 
 
 
 
 
 
318	mutex_unlock(&dev->struct_mutex);
 
 
 
319	return;
320}
321
322struct drm_ioctl_desc sis_ioctls[] = {
323	DRM_IOCTL_DEF_DRV(SIS_FB_ALLOC, sis_fb_alloc, DRM_AUTH),
324	DRM_IOCTL_DEF_DRV(SIS_FB_FREE, sis_drm_free, DRM_AUTH),
325	DRM_IOCTL_DEF_DRV(SIS_AGP_INIT, sis_ioctl_agp_init, DRM_AUTH | DRM_MASTER | DRM_ROOT_ONLY),
326	DRM_IOCTL_DEF_DRV(SIS_AGP_ALLOC, sis_ioctl_agp_alloc, DRM_AUTH),
327	DRM_IOCTL_DEF_DRV(SIS_AGP_FREE, sis_drm_free, DRM_AUTH),
328	DRM_IOCTL_DEF_DRV(SIS_FB_INIT, sis_fb_init, DRM_AUTH | DRM_MASTER | DRM_ROOT_ONLY),
329};
330
331int sis_max_ioctl = DRM_ARRAY_SIZE(sis_ioctls);
v4.6
  1/**************************************************************************
  2 *
  3 * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA.
  4 * All Rights Reserved.
  5 *
  6 * Permission is hereby granted, free of charge, to any person obtaining a
  7 * copy of this software and associated documentation files (the
  8 * "Software"), to deal in the Software without restriction, including
  9 * without limitation the rights to use, copy, modify, merge, publish,
 10 * distribute, sub license, and/or sell copies of the Software, and to
 11 * permit persons to whom the Software is furnished to do so, subject to
 12 * the following conditions:
 13 *
 14 * The above copyright notice and this permission notice (including the
 15 * next paragraph) shall be included in all copies or substantial portions
 16 * of the Software.
 17 *
 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 21 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
 22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
 25 *
 26 *
 27 **************************************************************************/
 28
 29/*
 30 * Authors:
 31 *    Thomas Hellström <thomas-at-tungstengraphics-dot-com>
 32 */
 33
 34#include <drm/drmP.h>
 35#include <drm/sis_drm.h>
 36#include "sis_drv.h"
 37
 38#include <video/sisfb.h>
 39
 40#define VIDEO_TYPE 0
 41#define AGP_TYPE 1
 42
 43
 44struct sis_memblock {
 45	struct drm_mm_node mm_node;
 46	struct sis_memreq req;
 47	struct list_head owner_list;
 48};
 49
 50#if defined(CONFIG_FB_SIS) || defined(CONFIG_FB_SIS_MODULE)
 51/* fb management via fb device */
 52
 53#define SIS_MM_ALIGN_SHIFT 0
 54#define SIS_MM_ALIGN_MASK 0
 55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 56#else /* CONFIG_FB_SIS[_MODULE] */
 57
 58#define SIS_MM_ALIGN_SHIFT 4
 59#define SIS_MM_ALIGN_MASK ((1 << SIS_MM_ALIGN_SHIFT) - 1)
 60
 61#endif /* CONFIG_FB_SIS[_MODULE] */
 62
 63static int sis_fb_init(struct drm_device *dev, void *data, struct drm_file *file_priv)
 64{
 65	drm_sis_private_t *dev_priv = dev->dev_private;
 66	drm_sis_fb_t *fb = data;
 
 67
 68	mutex_lock(&dev->struct_mutex);
 69	/* Unconditionally init the drm_mm, even though we don't use it when the
 70	 * fb sis driver is available - make cleanup easier. */
 71	drm_mm_init(&dev_priv->vram_mm, 0, fb->size >> SIS_MM_ALIGN_SHIFT);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 72
 73	dev_priv->vram_initialized = 1;
 74	dev_priv->vram_offset = fb->offset;
 75
 76	mutex_unlock(&dev->struct_mutex);
 77	DRM_DEBUG("offset = %lu, size = %lu\n", fb->offset, fb->size);
 78
 79	return 0;
 80}
 81
 82static int sis_drm_alloc(struct drm_device *dev, struct drm_file *file,
 83			 void *data, int pool)
 84{
 85	drm_sis_private_t *dev_priv = dev->dev_private;
 86	drm_sis_mem_t *mem = data;
 87	int retval = 0, user_key;
 88	struct sis_memblock *item;
 89	struct sis_file_private *file_priv = file->driver_priv;
 90	unsigned long offset;
 91
 92	mutex_lock(&dev->struct_mutex);
 93
 94	if (0 == ((pool == 0) ? dev_priv->vram_initialized :
 95		      dev_priv->agp_initialized)) {
 96		DRM_ERROR
 97		    ("Attempt to allocate from uninitialized memory manager.\n");
 98		mutex_unlock(&dev->struct_mutex);
 99		return -EINVAL;
100	}
101
102	item = kzalloc(sizeof(*item), GFP_KERNEL);
103	if (!item) {
104		retval = -ENOMEM;
105		goto fail_alloc;
106	}
107
108	mem->size = (mem->size + SIS_MM_ALIGN_MASK) >> SIS_MM_ALIGN_SHIFT;
109	if (pool == AGP_TYPE) {
110		retval = drm_mm_insert_node(&dev_priv->agp_mm,
111					    &item->mm_node,
112					    mem->size, 0,
113					    DRM_MM_SEARCH_DEFAULT);
114		offset = item->mm_node.start;
 
115	} else {
116#if defined(CONFIG_FB_SIS) || defined(CONFIG_FB_SIS_MODULE)
117		item->req.size = mem->size;
118		sis_malloc(&item->req);
119		if (item->req.size == 0)
120			retval = -ENOMEM;
121		offset = item->req.offset;
122#else
123		retval = drm_mm_insert_node(&dev_priv->vram_mm,
124					    &item->mm_node,
125					    mem->size, 0,
126					    DRM_MM_SEARCH_DEFAULT);
127		offset = item->mm_node.start;
128#endif
129	}
130	if (retval)
131		goto fail_alloc;
132
133	retval = idr_alloc(&dev_priv->object_idr, item, 1, 0, GFP_KERNEL);
134	if (retval < 0)
135		goto fail_idr;
136	user_key = retval;
137
138	list_add(&item->owner_list, &file_priv->obj_list);
139	mutex_unlock(&dev->struct_mutex);
140
141	mem->offset = ((pool == 0) ?
142		      dev_priv->vram_offset : dev_priv->agp_offset) +
143	    (offset << SIS_MM_ALIGN_SHIFT);
144	mem->free = user_key;
145	mem->size = mem->size << SIS_MM_ALIGN_SHIFT;
146
147	return 0;
148
149fail_idr:
150	drm_mm_remove_node(&item->mm_node);
151fail_alloc:
152	kfree(item);
153	mutex_unlock(&dev->struct_mutex);
154
155	mem->offset = 0;
156	mem->size = 0;
157	mem->free = 0;
158
159	DRM_DEBUG("alloc %d, size = %ld, offset = %ld\n", pool, mem->size,
160		  mem->offset);
161
162	return retval;
163}
164
165static int sis_drm_free(struct drm_device *dev, void *data, struct drm_file *file_priv)
166{
167	drm_sis_private_t *dev_priv = dev->dev_private;
168	drm_sis_mem_t *mem = data;
169	struct sis_memblock *obj;
170
171	mutex_lock(&dev->struct_mutex);
172	obj = idr_find(&dev_priv->object_idr, mem->free);
173	if (obj == NULL) {
174		mutex_unlock(&dev->struct_mutex);
175		return -EINVAL;
176	}
177
178	idr_remove(&dev_priv->object_idr, mem->free);
179	list_del(&obj->owner_list);
180	if (drm_mm_node_allocated(&obj->mm_node))
181		drm_mm_remove_node(&obj->mm_node);
182#if defined(CONFIG_FB_SIS) || defined(CONFIG_FB_SIS_MODULE)
183	else
184		sis_free(obj->req.offset);
185#endif
186	kfree(obj);
187	mutex_unlock(&dev->struct_mutex);
188	DRM_DEBUG("free = 0x%lx\n", mem->free);
189
190	return 0;
191}
192
193static int sis_fb_alloc(struct drm_device *dev, void *data,
194			struct drm_file *file_priv)
195{
196	return sis_drm_alloc(dev, file_priv, data, VIDEO_TYPE);
197}
198
199static int sis_ioctl_agp_init(struct drm_device *dev, void *data,
200			      struct drm_file *file_priv)
201{
202	drm_sis_private_t *dev_priv = dev->dev_private;
203	drm_sis_agp_t *agp = data;
 
204	dev_priv = dev->dev_private;
205
206	mutex_lock(&dev->struct_mutex);
207	drm_mm_init(&dev_priv->agp_mm, 0, agp->size >> SIS_MM_ALIGN_SHIFT);
 
 
 
 
 
 
 
208
209	dev_priv->agp_initialized = 1;
210	dev_priv->agp_offset = agp->offset;
211	mutex_unlock(&dev->struct_mutex);
212
213	DRM_DEBUG("offset = %lu, size = %lu\n", agp->offset, agp->size);
214	return 0;
215}
216
217static int sis_ioctl_agp_alloc(struct drm_device *dev, void *data,
218			       struct drm_file *file_priv)
219{
220
221	return sis_drm_alloc(dev, file_priv, data, AGP_TYPE);
222}
223
224static drm_local_map_t *sis_reg_init(struct drm_device *dev)
225{
226	struct drm_map_list *entry;
227	drm_local_map_t *map;
228
229	list_for_each_entry(entry, &dev->maplist, head) {
230		map = entry->map;
231		if (!map)
232			continue;
233		if (map->type == _DRM_REGISTERS)
234			return map;
235	}
236	return NULL;
237}
238
239int sis_idle(struct drm_device *dev)
240{
241	drm_sis_private_t *dev_priv = dev->dev_private;
242	uint32_t idle_reg;
243	unsigned long end;
244	int i;
245
246	if (dev_priv->idle_fault)
247		return 0;
248
249	if (dev_priv->mmio == NULL) {
250		dev_priv->mmio = sis_reg_init(dev);
251		if (dev_priv->mmio == NULL) {
252			DRM_ERROR("Could not find register map.\n");
253			return 0;
254		}
255	}
256
257	/*
258	 * Implement a device switch here if needed
259	 */
260
261	if (dev_priv->chipset != SIS_CHIP_315)
262		return 0;
263
264	/*
265	 * Timeout after 3 seconds. We cannot use DRM_WAIT_ON here
266	 * because its polling frequency is too low.
267	 */
268
269	end = jiffies + (HZ * 3);
270
271	for (i = 0; i < 4; ++i) {
272		do {
273			idle_reg = SIS_READ(0x85cc);
274		} while (!time_after_eq(jiffies, end) &&
275			  ((idle_reg & 0x80000000) != 0x80000000));
276	}
277
278	if (time_after_eq(jiffies, end)) {
279		DRM_ERROR("Graphics engine idle timeout. "
280			  "Disabling idle check\n");
281		dev_priv->idle_fault = 1;
282	}
283
284	/*
285	 * The caller never sees an error code. It gets trapped
286	 * in libdrm.
287	 */
288
289	return 0;
290}
291
292
293void sis_lastclose(struct drm_device *dev)
294{
295	drm_sis_private_t *dev_priv = dev->dev_private;
296
297	if (!dev_priv)
298		return;
299
300	mutex_lock(&dev->struct_mutex);
301	if (dev_priv->vram_initialized) {
302		drm_mm_takedown(&dev_priv->vram_mm);
303		dev_priv->vram_initialized = 0;
304	}
305	if (dev_priv->agp_initialized) {
306		drm_mm_takedown(&dev_priv->agp_mm);
307		dev_priv->agp_initialized = 0;
308	}
309	dev_priv->mmio = NULL;
310	mutex_unlock(&dev->struct_mutex);
311}
312
313void sis_reclaim_buffers_locked(struct drm_device *dev,
314				struct drm_file *file)
315{
316	struct sis_file_private *file_priv = file->driver_priv;
317	struct sis_memblock *entry, *next;
318
319	if (!(file->minor->master && file->master->lock.hw_lock))
320		return;
321
322	drm_legacy_idlelock_take(&file->master->lock);
323
324	mutex_lock(&dev->struct_mutex);
325	if (list_empty(&file_priv->obj_list)) {
326		mutex_unlock(&dev->struct_mutex);
327		drm_legacy_idlelock_release(&file->master->lock);
328
329		return;
330	}
331
332	sis_idle(dev);
 
333
334
335	list_for_each_entry_safe(entry, next, &file_priv->obj_list,
336				 owner_list) {
337		list_del(&entry->owner_list);
338		if (drm_mm_node_allocated(&entry->mm_node))
339			drm_mm_remove_node(&entry->mm_node);
340#if defined(CONFIG_FB_SIS) || defined(CONFIG_FB_SIS_MODULE)
341		else
342			sis_free(entry->req.offset);
343#endif
344		kfree(entry);
345	}
346	mutex_unlock(&dev->struct_mutex);
347
348	drm_legacy_idlelock_release(&file->master->lock);
349
350	return;
351}
352
353const struct drm_ioctl_desc sis_ioctls[] = {
354	DRM_IOCTL_DEF_DRV(SIS_FB_ALLOC, sis_fb_alloc, DRM_AUTH),
355	DRM_IOCTL_DEF_DRV(SIS_FB_FREE, sis_drm_free, DRM_AUTH),
356	DRM_IOCTL_DEF_DRV(SIS_AGP_INIT, sis_ioctl_agp_init, DRM_AUTH | DRM_MASTER | DRM_ROOT_ONLY),
357	DRM_IOCTL_DEF_DRV(SIS_AGP_ALLOC, sis_ioctl_agp_alloc, DRM_AUTH),
358	DRM_IOCTL_DEF_DRV(SIS_AGP_FREE, sis_drm_free, DRM_AUTH),
359	DRM_IOCTL_DEF_DRV(SIS_FB_INIT, sis_fb_init, DRM_AUTH | DRM_MASTER | DRM_ROOT_ONLY),
360};
361
362int sis_max_ioctl = ARRAY_SIZE(sis_ioctls);