2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
24 * Authors: Dave Airlie
30 #include "radeon_drm.h"
33 int radeon_gem_object_init(struct drm_gem_object
*obj
)
35 /* we do nothings here */
39 void radeon_gem_object_free(struct drm_gem_object
*gobj
)
41 struct radeon_bo
*robj
= gobj
->driver_private
;
43 gobj
->driver_private
= NULL
;
45 radeon_bo_unref(&robj
);
49 int radeon_gem_object_create(struct radeon_device
*rdev
, int size
,
50 int alignment
, int initial_domain
,
51 bool discardable
, bool kernel
,
52 struct drm_gem_object
**obj
)
54 struct drm_gem_object
*gobj
;
55 struct radeon_bo
*robj
;
59 gobj
= drm_gem_object_alloc(rdev
->ddev
, size
);
63 /* At least align on page size */
64 if (alignment
< PAGE_SIZE
) {
65 alignment
= PAGE_SIZE
;
67 r
= radeon_bo_create(rdev
, gobj
, size
, kernel
, initial_domain
, &robj
);
69 if (r
!= -ERESTARTSYS
)
70 DRM_ERROR("Failed to allocate GEM object (%d, %d, %u, %d)\n",
71 size
, initial_domain
, alignment
, r
);
72 drm_gem_object_unreference_unlocked(gobj
);
75 gobj
->driver_private
= robj
;
80 int radeon_gem_object_pin(struct drm_gem_object
*obj
, uint32_t pin_domain
,
83 struct radeon_bo
*robj
= obj
->driver_private
;
86 r
= radeon_bo_reserve(robj
, false);
89 r
= radeon_bo_pin(robj
, pin_domain
, gpu_addr
);
90 radeon_bo_unreserve(robj
);
94 void radeon_gem_object_unpin(struct drm_gem_object
*obj
)
96 struct radeon_bo
*robj
= obj
->driver_private
;
99 r
= radeon_bo_reserve(robj
, false);
100 if (likely(r
== 0)) {
101 radeon_bo_unpin(robj
);
102 radeon_bo_unreserve(robj
);
106 int radeon_gem_set_domain(struct drm_gem_object
*gobj
,
107 uint32_t rdomain
, uint32_t wdomain
)
109 struct radeon_bo
*robj
;
113 /* FIXME: reeimplement */
114 robj
= gobj
->driver_private
;
115 /* work out where to validate the buffer to */
122 printk(KERN_WARNING
"Set domain withou domain !\n");
125 if (domain
== RADEON_GEM_DOMAIN_CPU
) {
126 /* Asking for cpu access wait for object idle */
127 r
= radeon_bo_wait(robj
, NULL
, false);
129 printk(KERN_ERR
"Failed to wait for object !\n");
136 int radeon_gem_init(struct radeon_device
*rdev
)
138 INIT_LIST_HEAD(&rdev
->gem
.objects
);
142 void radeon_gem_fini(struct radeon_device
*rdev
)
144 radeon_bo_force_delete(rdev
);
151 int radeon_gem_info_ioctl(struct drm_device
*dev
, void *data
,
152 struct drm_file
*filp
)
154 struct radeon_device
*rdev
= dev
->dev_private
;
155 struct drm_radeon_gem_info
*args
= data
;
157 args
->vram_size
= rdev
->mc
.real_vram_size
;
158 args
->vram_visible
= rdev
->mc
.real_vram_size
;
159 if (rdev
->stollen_vga_memory
)
160 args
->vram_visible
-= radeon_bo_size(rdev
->stollen_vga_memory
);
162 args
->vram_visible
-= radeon_bo_size(rdev
->fbdev_rbo
);
163 args
->gart_size
= rdev
->mc
.gtt_size
- rdev
->cp
.ring_size
- 4096 -
164 RADEON_IB_POOL_SIZE
*64*1024;
168 int radeon_gem_pread_ioctl(struct drm_device
*dev
, void *data
,
169 struct drm_file
*filp
)
171 /* TODO: implement */
172 DRM_ERROR("unimplemented %s\n", __func__
);
176 int radeon_gem_pwrite_ioctl(struct drm_device
*dev
, void *data
,
177 struct drm_file
*filp
)
179 /* TODO: implement */
180 DRM_ERROR("unimplemented %s\n", __func__
);
184 int radeon_gem_create_ioctl(struct drm_device
*dev
, void *data
,
185 struct drm_file
*filp
)
187 struct radeon_device
*rdev
= dev
->dev_private
;
188 struct drm_radeon_gem_create
*args
= data
;
189 struct drm_gem_object
*gobj
;
193 /* create a gem object to contain this object in */
194 args
->size
= roundup(args
->size
, PAGE_SIZE
);
195 r
= radeon_gem_object_create(rdev
, args
->size
, args
->alignment
,
196 args
->initial_domain
, false,
201 r
= drm_gem_handle_create(filp
, gobj
, &handle
);
203 drm_gem_object_unreference_unlocked(gobj
);
206 drm_gem_object_handle_unreference_unlocked(gobj
);
207 args
->handle
= handle
;
211 int radeon_gem_set_domain_ioctl(struct drm_device
*dev
, void *data
,
212 struct drm_file
*filp
)
214 /* transition the BO to a domain -
215 * just validate the BO into a certain domain */
216 struct drm_radeon_gem_set_domain
*args
= data
;
217 struct drm_gem_object
*gobj
;
218 struct radeon_bo
*robj
;
221 /* for now if someone requests domain CPU -
222 * just make sure the buffer is finished with */
224 /* just do a BO wait for now */
225 gobj
= drm_gem_object_lookup(dev
, filp
, args
->handle
);
229 robj
= gobj
->driver_private
;
231 r
= radeon_gem_set_domain(gobj
, args
->read_domains
, args
->write_domain
);
233 drm_gem_object_unreference_unlocked(gobj
);
237 int radeon_gem_mmap_ioctl(struct drm_device
*dev
, void *data
,
238 struct drm_file
*filp
)
240 struct drm_radeon_gem_mmap
*args
= data
;
241 struct drm_gem_object
*gobj
;
242 struct radeon_bo
*robj
;
244 gobj
= drm_gem_object_lookup(dev
, filp
, args
->handle
);
248 robj
= gobj
->driver_private
;
249 args
->addr_ptr
= radeon_bo_mmap_offset(robj
);
250 drm_gem_object_unreference_unlocked(gobj
);
254 int radeon_gem_busy_ioctl(struct drm_device
*dev
, void *data
,
255 struct drm_file
*filp
)
257 struct drm_radeon_gem_busy
*args
= data
;
258 struct drm_gem_object
*gobj
;
259 struct radeon_bo
*robj
;
261 uint32_t cur_placement
= 0;
263 gobj
= drm_gem_object_lookup(dev
, filp
, args
->handle
);
267 robj
= gobj
->driver_private
;
268 r
= radeon_bo_wait(robj
, &cur_placement
, true);
269 switch (cur_placement
) {
271 args
->domain
= RADEON_GEM_DOMAIN_VRAM
;
274 args
->domain
= RADEON_GEM_DOMAIN_GTT
;
277 args
->domain
= RADEON_GEM_DOMAIN_CPU
;
281 drm_gem_object_unreference_unlocked(gobj
);
285 int radeon_gem_wait_idle_ioctl(struct drm_device
*dev
, void *data
,
286 struct drm_file
*filp
)
288 struct drm_radeon_gem_wait_idle
*args
= data
;
289 struct drm_gem_object
*gobj
;
290 struct radeon_bo
*robj
;
293 gobj
= drm_gem_object_lookup(dev
, filp
, args
->handle
);
297 robj
= gobj
->driver_private
;
298 r
= radeon_bo_wait(robj
, NULL
, false);
299 /* callback hw specific functions if any */
300 if (robj
->rdev
->asic
->ioctl_wait_idle
)
301 robj
->rdev
->asic
->ioctl_wait_idle(robj
->rdev
, robj
);
302 drm_gem_object_unreference_unlocked(gobj
);
306 int radeon_gem_set_tiling_ioctl(struct drm_device
*dev
, void *data
,
307 struct drm_file
*filp
)
309 struct drm_radeon_gem_set_tiling
*args
= data
;
310 struct drm_gem_object
*gobj
;
311 struct radeon_bo
*robj
;
314 DRM_DEBUG("%d \n", args
->handle
);
315 gobj
= drm_gem_object_lookup(dev
, filp
, args
->handle
);
318 robj
= gobj
->driver_private
;
319 r
= radeon_bo_set_tiling_flags(robj
, args
->tiling_flags
, args
->pitch
);
320 drm_gem_object_unreference_unlocked(gobj
);
324 int radeon_gem_get_tiling_ioctl(struct drm_device
*dev
, void *data
,
325 struct drm_file
*filp
)
327 struct drm_radeon_gem_get_tiling
*args
= data
;
328 struct drm_gem_object
*gobj
;
329 struct radeon_bo
*rbo
;
333 gobj
= drm_gem_object_lookup(dev
, filp
, args
->handle
);
336 rbo
= gobj
->driver_private
;
337 r
= radeon_bo_reserve(rbo
, false);
338 if (unlikely(r
!= 0))
340 radeon_bo_get_tiling_flags(rbo
, &args
->tiling_flags
, &args
->pitch
);
341 radeon_bo_unreserve(rbo
);
343 drm_gem_object_unreference_unlocked(gobj
);