radeon: only do the fb read if we are mapping a VRAM object
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_bo_legacy.c
1 /*
2 * Copyright © 2008 Nicolai Haehnle
3 * Copyright © 2008 Dave Airlie
4 * Copyright © 2008 Jérôme Glisse
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * The above copyright notice and this permission notice (including the
24 * next paragraph) shall be included in all copies or substantial portions
25 * of the Software.
26 */
27 /*
28 * Authors:
29 * Aapo Tahkola <aet@rasterburn.org>
30 * Nicolai Haehnle <prefect_@gmx.net>
31 * Dave Airlie
32 * Jérôme Glisse <glisse@freedesktop.org>
33 */
34 #include <stdio.h>
35 #include <stdint.h>
36 #include <stdlib.h>
37 #include <string.h>
38 #include <errno.h>
39 #include <unistd.h>
40 #include <sys/mman.h>
41 #include <sys/ioctl.h>
42 #include "xf86drm.h"
43 #include "texmem.h"
44 #include "main/simple_list.h"
45
46 #include "drm.h"
47 #include "radeon_drm.h"
48 #include "radeon_bo.h"
49 #include "radeon_bo_legacy.h"
50 #include "common_context.h"
51
52 struct bo_legacy {
53 struct radeon_bo base;
54 driTextureObject tobj_base;
55 int map_count;
56 uint32_t pending;
57 int is_pending;
58 int validated;
59 int static_bo;
60 int got_dri_texture_obj;
61 int dirty;
62 uint32_t offset;
63 driTextureObject dri_texture_obj;
64 void *ptr;
65 struct bo_legacy *next, *prev;
66 struct bo_legacy *pnext, *pprev;
67 };
68
69 struct bo_manager_legacy {
70 struct radeon_bo_manager base;
71 unsigned nhandle;
72 unsigned nfree_handles;
73 unsigned cfree_handles;
74 uint32_t current_age;
75 struct bo_legacy bos;
76 struct bo_legacy pending_bos;
77 uint32_t fb_location;
78 uint32_t texture_offset;
79 unsigned dma_alloc_size;
80 uint32_t dma_buf_count;
81 unsigned cpendings;
82 driTextureObject texture_swapped;
83 driTexHeap *texture_heap;
84 struct radeon_screen *screen;
85 unsigned *free_handles;
86 };
87
88 static void bo_legacy_tobj_destroy(void *data, driTextureObject *t)
89 {
90 struct bo_legacy *bo_legacy;
91
92 bo_legacy = (struct bo_legacy*)((char*)t)-sizeof(struct radeon_bo);
93 bo_legacy->got_dri_texture_obj = 0;
94 bo_legacy->validated = 0;
95 }
96
97 static void inline clean_handles(struct bo_manager_legacy *bom)
98 {
99 while (bom->cfree_handles > 0 &&
100 !bom->free_handles[bom->cfree_handles - 1])
101 bom->cfree_handles--;
102
103 }
104 static int legacy_new_handle(struct bo_manager_legacy *bom, uint32_t *handle)
105 {
106 uint32_t tmp;
107
108 *handle = 0;
109 if (bom->nhandle == 0xFFFFFFFF) {
110 return -EINVAL;
111 }
112 if (bom->cfree_handles > 0) {
113 tmp = bom->free_handles[--bom->cfree_handles];
114 clean_handles(bom);
115 } else {
116 bom->cfree_handles = 0;
117 tmp = bom->nhandle++;
118 }
119 assert(tmp);
120 *handle = tmp;
121 return 0;
122 }
123
124 static int legacy_free_handle(struct bo_manager_legacy *bom, uint32_t handle)
125 {
126 uint32_t *handles;
127
128 if (!handle) {
129 return 0;
130 }
131 if (handle == (bom->nhandle - 1)) {
132 int i;
133
134 bom->nhandle--;
135 for (i = bom->cfree_handles - 1; i >= 0; i--) {
136 if (bom->free_handles[i] == (bom->nhandle - 1)) {
137 bom->nhandle--;
138 bom->free_handles[i] = 0;
139 }
140 }
141 clean_handles(bom);
142 return 0;
143 }
144 if (bom->cfree_handles < bom->nfree_handles) {
145 bom->free_handles[bom->cfree_handles++] = handle;
146 return 0;
147 }
148 bom->nfree_handles += 0x100;
149 handles = (uint32_t*)realloc(bom->free_handles, bom->nfree_handles * 4);
150 if (handles == NULL) {
151 bom->nfree_handles -= 0x100;
152 return -ENOMEM;
153 }
154 bom->free_handles = handles;
155 bom->free_handles[bom->cfree_handles++] = handle;
156 return 0;
157 }
158
159 static void legacy_get_current_age(struct bo_manager_legacy *boml)
160 {
161 drm_radeon_getparam_t gp;
162 int r;
163
164 if (IS_R300_CLASS(boml->screen)) {
165 gp.param = RADEON_PARAM_LAST_CLEAR;
166 gp.value = (int *)&boml->current_age;
167 r = drmCommandWriteRead(boml->base.fd, DRM_RADEON_GETPARAM,
168 &gp, sizeof(gp));
169 if (r) {
170 fprintf(stderr, "%s: drmRadeonGetParam: %d\n", __FUNCTION__, r);
171 exit(1);
172 }
173 } else
174 boml->current_age = boml->screen->scratch[3];
175 }
176
177 static int legacy_is_pending(struct radeon_bo *bo)
178 {
179 struct bo_manager_legacy *boml = (struct bo_manager_legacy *)bo->bom;
180 struct bo_legacy *bo_legacy = (struct bo_legacy*)bo;
181
182 if (bo_legacy->is_pending <= 0) {
183 bo_legacy->is_pending = 0;
184 return 0;
185 }
186 if (boml->current_age >= bo_legacy->pending) {
187 if (boml->pending_bos.pprev == bo_legacy) {
188 boml->pending_bos.pprev = bo_legacy->pprev;
189 }
190 bo_legacy->pprev->pnext = bo_legacy->pnext;
191 if (bo_legacy->pnext) {
192 bo_legacy->pnext->pprev = bo_legacy->pprev;
193 }
194 assert(bo_legacy->is_pending <= bo->cref);
195 while (bo_legacy->is_pending--) {
196 bo = radeon_bo_unref(bo);
197 if (!bo)
198 break;
199 }
200 if (bo)
201 bo_legacy->is_pending = 0;
202 boml->cpendings--;
203 return 0;
204 }
205 return 1;
206 }
207
208 static int legacy_wait_pending(struct radeon_bo *bo)
209 {
210 struct bo_manager_legacy *boml = (struct bo_manager_legacy *)bo->bom;
211 struct bo_legacy *bo_legacy = (struct bo_legacy*)bo;
212
213 if (!bo_legacy->is_pending) {
214 return 0;
215 }
216 /* FIXME: lockup and userspace busy looping that's all the folks */
217 legacy_get_current_age(boml);
218 while (legacy_is_pending(bo)) {
219 usleep(10);
220 legacy_get_current_age(boml);
221 }
222 return 0;
223 }
224
225 static void legacy_track_pending(struct bo_manager_legacy *boml, int debug)
226 {
227 struct bo_legacy *bo_legacy;
228 struct bo_legacy *next;
229
230 legacy_get_current_age(boml);
231 bo_legacy = boml->pending_bos.pnext;
232 while (bo_legacy) {
233 if (debug)
234 fprintf(stderr,"pending %p %d %d %d\n", bo_legacy, bo_legacy->base.size,
235 boml->current_age, bo_legacy->pending);
236 next = bo_legacy->pnext;
237 if (legacy_is_pending(&(bo_legacy->base))) {
238 }
239 bo_legacy = next;
240 }
241 }
242
243 static int legacy_wait_any_pending(struct bo_manager_legacy *boml)
244 {
245 struct bo_legacy *bo_legacy;
246 struct bo_legacy *next;
247
248 legacy_get_current_age(boml);
249 bo_legacy = boml->pending_bos.pnext;
250 if (!bo_legacy)
251 return -1;
252 legacy_wait_pending(&bo_legacy->base);
253 return 0;
254 }
255
256 static struct bo_legacy *bo_allocate(struct bo_manager_legacy *boml,
257 uint32_t size,
258 uint32_t alignment,
259 uint32_t domains,
260 uint32_t flags)
261 {
262 struct bo_legacy *bo_legacy;
263 uint32_t pgsize = getpagesize() - 1;
264
265 size = (size + pgsize) & ~pgsize;
266
267 bo_legacy = (struct bo_legacy*)calloc(1, sizeof(struct bo_legacy));
268 if (bo_legacy == NULL) {
269 return NULL;
270 }
271 bo_legacy->base.bom = (struct radeon_bo_manager*)boml;
272 bo_legacy->base.handle = 0;
273 bo_legacy->base.size = size;
274 bo_legacy->base.alignment = alignment;
275 bo_legacy->base.domains = domains;
276 bo_legacy->base.flags = flags;
277 bo_legacy->base.ptr = NULL;
278 bo_legacy->map_count = 0;
279 bo_legacy->next = NULL;
280 bo_legacy->prev = NULL;
281 bo_legacy->got_dri_texture_obj = 0;
282 bo_legacy->pnext = NULL;
283 bo_legacy->pprev = NULL;
284 bo_legacy->next = boml->bos.next;
285 bo_legacy->prev = &boml->bos;
286 boml->bos.next = bo_legacy;
287 if (bo_legacy->next) {
288 bo_legacy->next->prev = bo_legacy;
289 }
290 return bo_legacy;
291 }
292
293 static int bo_dma_alloc(struct radeon_bo *bo)
294 {
295 struct bo_manager_legacy *boml = (struct bo_manager_legacy *)bo->bom;
296 struct bo_legacy *bo_legacy = (struct bo_legacy*)bo;
297 drm_radeon_mem_alloc_t alloc;
298 unsigned size;
299 int base_offset;
300 int r;
301
302 /* align size on 4Kb */
303 size = (((4 * 1024) - 1) + bo->size) & ~((4 * 1024) - 1);
304 alloc.region = RADEON_MEM_REGION_GART;
305 alloc.alignment = bo_legacy->base.alignment;
306 alloc.size = size;
307 alloc.region_offset = &base_offset;
308 r = drmCommandWriteRead(bo->bom->fd,
309 DRM_RADEON_ALLOC,
310 &alloc,
311 sizeof(alloc));
312 if (r) {
313 /* ptr is set to NULL if dma allocation failed */
314 bo_legacy->ptr = NULL;
315 return r;
316 }
317 bo_legacy->ptr = boml->screen->gartTextures.map + base_offset;
318 bo_legacy->offset = boml->screen->gart_texture_offset + base_offset;
319 bo->size = size;
320 boml->dma_alloc_size += size;
321 boml->dma_buf_count++;
322 return 0;
323 }
324
325 static int bo_dma_free(struct radeon_bo *bo)
326 {
327 struct bo_manager_legacy *boml = (struct bo_manager_legacy *)bo->bom;
328 struct bo_legacy *bo_legacy = (struct bo_legacy*)bo;
329 drm_radeon_mem_free_t memfree;
330 int r;
331
332 if (bo_legacy->ptr == NULL) {
333 /* ptr is set to NULL if dma allocation failed */
334 return 0;
335 }
336 legacy_get_current_age(boml);
337 memfree.region = RADEON_MEM_REGION_GART;
338 memfree.region_offset = bo_legacy->offset;
339 memfree.region_offset -= boml->screen->gart_texture_offset;
340 r = drmCommandWrite(boml->base.fd,
341 DRM_RADEON_FREE,
342 &memfree,
343 sizeof(memfree));
344 if (r) {
345 fprintf(stderr, "Failed to free bo[%p] at %08x\n",
346 &bo_legacy->base, memfree.region_offset);
347 fprintf(stderr, "ret = %s\n", strerror(-r));
348 return r;
349 }
350 boml->dma_alloc_size -= bo_legacy->base.size;
351 boml->dma_buf_count--;
352 return 0;
353 }
354
355 static void bo_free(struct bo_legacy *bo_legacy)
356 {
357 struct bo_manager_legacy *boml;
358
359 if (bo_legacy == NULL) {
360 return;
361 }
362 boml = (struct bo_manager_legacy *)bo_legacy->base.bom;
363 bo_legacy->prev->next = bo_legacy->next;
364 if (bo_legacy->next) {
365 bo_legacy->next->prev = bo_legacy->prev;
366 }
367 if (!bo_legacy->static_bo) {
368 legacy_free_handle(boml, bo_legacy->base.handle);
369 if (bo_legacy->base.domains & RADEON_GEM_DOMAIN_GTT) {
370 /* dma buffers */
371 bo_dma_free(&bo_legacy->base);
372 } else {
373 /* free backing store */
374 free(bo_legacy->ptr);
375 }
376 }
377 memset(bo_legacy, 0 , sizeof(struct bo_legacy));
378 free(bo_legacy);
379 }
380
381 static struct radeon_bo *bo_open(struct radeon_bo_manager *bom,
382 uint32_t handle,
383 uint32_t size,
384 uint32_t alignment,
385 uint32_t domains,
386 uint32_t flags)
387 {
388 struct bo_manager_legacy *boml = (struct bo_manager_legacy *)bom;
389 struct bo_legacy *bo_legacy;
390 int r;
391
392 if (handle) {
393 bo_legacy = boml->bos.next;
394 while (bo_legacy) {
395 if (bo_legacy->base.handle == handle) {
396 radeon_bo_ref(&(bo_legacy->base));
397 return (struct radeon_bo*)bo_legacy;
398 }
399 bo_legacy = bo_legacy->next;
400 }
401 return NULL;
402 }
403
404 bo_legacy = bo_allocate(boml, size, alignment, domains, flags);
405 bo_legacy->static_bo = 0;
406 r = legacy_new_handle(boml, &bo_legacy->base.handle);
407 if (r) {
408 bo_free(bo_legacy);
409 return NULL;
410 }
411 if (bo_legacy->base.domains & RADEON_GEM_DOMAIN_GTT) {
412 retry:
413 legacy_track_pending(boml, 0);
414 /* dma buffers */
415
416 r = bo_dma_alloc(&(bo_legacy->base));
417 if (r) {
418 if (legacy_wait_any_pending(boml) == -1) {
419 bo_free(bo_legacy);
420 return NULL;
421 }
422 goto retry;
423 return NULL;
424 }
425 } else {
426 bo_legacy->ptr = malloc(bo_legacy->base.size);
427 if (bo_legacy->ptr == NULL) {
428 bo_free(bo_legacy);
429 return NULL;
430 }
431 }
432 radeon_bo_ref(&(bo_legacy->base));
433 return (struct radeon_bo*)bo_legacy;
434 }
435
436 static void bo_ref(struct radeon_bo *bo)
437 {
438 }
439
440 static struct radeon_bo *bo_unref(struct radeon_bo *bo)
441 {
442 struct bo_legacy *bo_legacy = (struct bo_legacy*)bo;
443
444 if (bo->cref <= 0) {
445 bo_legacy->prev->next = bo_legacy->next;
446 if (bo_legacy->next) {
447 bo_legacy->next->prev = bo_legacy->prev;
448 }
449 if (!bo_legacy->is_pending) {
450 bo_free(bo_legacy);
451 }
452 return NULL;
453 }
454 return bo;
455 }
456
457 static int bo_map(struct radeon_bo *bo, int write)
458 {
459 struct bo_manager_legacy *boml = (struct bo_manager_legacy *)bo->bom;
460 struct bo_legacy *bo_legacy = (struct bo_legacy*)bo;
461
462 legacy_wait_pending(bo);
463 bo_legacy->validated = 0;
464 bo_legacy->dirty = 1;
465 bo_legacy->map_count++;
466 bo->ptr = bo_legacy->ptr;
467 /* Read the first pixel in the frame buffer. This should
468 * be a noop, right? In fact without this conform fails as reading
469 * from the framebuffer sometimes produces old results -- the
470 * on-card read cache gets mixed up and doesn't notice that the
471 * framebuffer has been updated.
472 *
473 * Note that we should probably be reading some otherwise unused
474 * region of VRAM, otherwise we might get incorrect results when
475 * reading pixels from the top left of the screen.
476 *
477 * I found this problem on an R420 with glean's texCube test.
478 * Note that the R200 span code also *writes* the first pixel in the
479 * framebuffer, but I've found this to be unnecessary.
480 * -- Nicolai Hähnle, June 2008
481 */
482 if (!(bo->domains & RADEON_GEM_DOMAIN_GTT)) {
483 int p;
484 volatile int *buf = (int*)boml->screen->driScreen->pFB;
485 p = *buf;
486 }
487 return 0;
488 }
489
490 static int bo_unmap(struct radeon_bo *bo)
491 {
492 struct bo_legacy *bo_legacy = (struct bo_legacy*)bo;
493
494 if (--bo_legacy->map_count > 0) {
495 return 0;
496 }
497 bo->ptr = NULL;
498 return 0;
499 }
500
501 static struct radeon_bo_funcs bo_legacy_funcs = {
502 bo_open,
503 bo_ref,
504 bo_unref,
505 bo_map,
506 bo_unmap
507 };
508
509 static int bo_vram_validate(struct radeon_bo *bo,
510 uint32_t *soffset,
511 uint32_t *eoffset)
512 {
513 struct bo_manager_legacy *boml = (struct bo_manager_legacy *)bo->bom;
514 struct bo_legacy *bo_legacy = (struct bo_legacy*)bo;
515 int r;
516
517 if (!bo_legacy->got_dri_texture_obj) {
518 make_empty_list(&bo_legacy->dri_texture_obj);
519 bo_legacy->dri_texture_obj.totalSize = bo->size;
520 r = driAllocateTexture(&boml->texture_heap, 1,
521 &bo_legacy->dri_texture_obj);
522 if (r) {
523 uint8_t *segfault=NULL;
524 fprintf(stderr, "Ouch! vram_validate failed %d\n", r);
525 *segfault=1;
526 return -1;
527 }
528 bo_legacy->offset = boml->texture_offset +
529 bo_legacy->dri_texture_obj.memBlock->ofs;
530 bo_legacy->got_dri_texture_obj = 1;
531 bo_legacy->dirty = 1;
532 }
533 if (bo_legacy->dirty) {
534 /* Copy to VRAM using a blit.
535 * All memory is 4K aligned. We're using 1024 pixels wide blits.
536 */
537 drm_radeon_texture_t tex;
538 drm_radeon_tex_image_t tmp;
539 int ret;
540
541 tex.offset = bo_legacy->offset;
542 tex.image = &tmp;
543 assert(!(tex.offset & 1023));
544
545 tmp.x = 0;
546 tmp.y = 0;
547 if (bo->size < 4096) {
548 tmp.width = (bo->size + 3) / 4;
549 tmp.height = 1;
550 } else {
551 tmp.width = 1024;
552 tmp.height = (bo->size + 4095) / 4096;
553 }
554 tmp.data = bo_legacy->ptr;
555 tex.format = RADEON_TXFORMAT_ARGB8888;
556 tex.width = tmp.width;
557 tex.height = tmp.height;
558 tex.pitch = MAX2(tmp.width / 16, 1);
559 do {
560 ret = drmCommandWriteRead(bo->bom->fd,
561 DRM_RADEON_TEXTURE,
562 &tex,
563 sizeof(drm_radeon_texture_t));
564 if (ret) {
565 if (RADEON_DEBUG & DEBUG_IOCTL)
566 fprintf(stderr, "DRM_RADEON_TEXTURE: again!\n");
567 usleep(1);
568 }
569 } while (ret == -EAGAIN);
570 bo_legacy->dirty = 0;
571 }
572 return 0;
573 }
574
575 int radeon_bo_legacy_validate(struct radeon_bo *bo,
576 uint32_t *soffset,
577 uint32_t *eoffset)
578 {
579 struct bo_legacy *bo_legacy = (struct bo_legacy*)bo;
580 int r;
581
582 if (bo_legacy->map_count) {
583 fprintf(stderr, "bo(%p, %d) is mapped (%d) can't valide it.\n",
584 bo, bo->size, bo_legacy->map_count);
585 return -EINVAL;
586 }
587 if (bo_legacy->static_bo || bo_legacy->validated) {
588 *soffset = bo_legacy->offset;
589 *eoffset = bo_legacy->offset + bo->size;
590 return 0;
591 }
592 if (!(bo->domains & RADEON_GEM_DOMAIN_GTT)) {
593 r = bo_vram_validate(bo, soffset, eoffset);
594 if (r) {
595 return r;
596 }
597 }
598 *soffset = bo_legacy->offset;
599 *eoffset = bo_legacy->offset + bo->size;
600 bo_legacy->validated = 1;
601 return 0;
602 }
603
604 void radeon_bo_legacy_pending(struct radeon_bo *bo, uint32_t pending)
605 {
606 struct bo_manager_legacy *boml = (struct bo_manager_legacy *)bo->bom;
607 struct bo_legacy *bo_legacy = (struct bo_legacy*)bo;
608
609 bo_legacy->pending = pending;
610 bo_legacy->is_pending++;
611 /* add to pending list */
612 radeon_bo_ref(bo);
613 if (bo_legacy->is_pending > 1) {
614 return;
615 }
616 bo_legacy->pprev = boml->pending_bos.pprev;
617 bo_legacy->pnext = NULL;
618 bo_legacy->pprev->pnext = bo_legacy;
619 boml->pending_bos.pprev = bo_legacy;
620 boml->cpendings++;
621 }
622
623 void radeon_bo_manager_legacy_dtor(struct radeon_bo_manager *bom)
624 {
625 struct bo_manager_legacy *boml = (struct bo_manager_legacy *)bom;
626 struct bo_legacy *bo_legacy;
627
628 if (bom == NULL) {
629 return;
630 }
631 bo_legacy = boml->bos.next;
632 while (bo_legacy) {
633 struct bo_legacy *next;
634
635 next = bo_legacy->next;
636 bo_free(bo_legacy);
637 bo_legacy = next;
638 }
639 free(boml->free_handles);
640 free(boml);
641 }
642
643 static struct bo_legacy *radeon_legacy_bo_alloc_static(struct bo_manager_legacy *bom,
644 int size, uint32_t offset)
645 {
646 struct bo_legacy *bo;
647
648 bo = bo_allocate(bom, size, 0, RADEON_GEM_DOMAIN_VRAM, 0);
649 if (bo == NULL)
650 return NULL;
651 bo->static_bo = 1;
652 bo->offset = offset + bom->fb_location;
653 bo->base.handle = bo->offset;
654 bo->ptr = bom->screen->driScreen->pFB + offset;
655 if (bo->base.handle > bom->nhandle) {
656 bom->nhandle = bo->base.handle + 1;
657 }
658 radeon_bo_ref(&(bo->base));
659 return bo;
660 }
661
662 struct radeon_bo_manager *radeon_bo_manager_legacy_ctor(struct radeon_screen *scrn)
663 {
664 struct bo_manager_legacy *bom;
665 struct bo_legacy *bo;
666 unsigned size;
667
668 bom = (struct bo_manager_legacy*)
669 calloc(1, sizeof(struct bo_manager_legacy));
670 if (bom == NULL) {
671 return NULL;
672 }
673
674 bom->texture_heap = driCreateTextureHeap(0,
675 bom,
676 scrn->texSize[0],
677 12,
678 RADEON_NR_TEX_REGIONS,
679 (drmTextureRegionPtr)scrn->sarea->tex_list[0],
680 &scrn->sarea->tex_age[0],
681 &bom->texture_swapped,
682 sizeof(struct bo_legacy),
683 &bo_legacy_tobj_destroy);
684 bom->texture_offset = scrn->texOffset[0];
685
686 bom->base.funcs = &bo_legacy_funcs;
687 bom->base.fd = scrn->driScreen->fd;
688 bom->bos.next = NULL;
689 bom->bos.prev = NULL;
690 bom->pending_bos.pprev = &bom->pending_bos;
691 bom->pending_bos.pnext = NULL;
692 bom->screen = scrn;
693 bom->fb_location = scrn->fbLocation;
694 bom->nhandle = 1;
695 bom->cfree_handles = 0;
696 bom->nfree_handles = 0x400;
697 bom->free_handles = (uint32_t*)malloc(bom->nfree_handles * 4);
698 if (bom->free_handles == NULL) {
699 radeon_bo_manager_legacy_dtor((struct radeon_bo_manager*)bom);
700 return NULL;
701 }
702
703 /* biggest framebuffer size */
704 size = 4096*4096*4;
705
706 /* allocate front */
707 bo = radeon_legacy_bo_alloc_static(bom, size, bom->screen->frontOffset);
708 if (!bo) {
709 radeon_bo_manager_legacy_dtor((struct radeon_bo_manager*)bom);
710 return NULL;
711 }
712 if (scrn->sarea->tiling_enabled) {
713 bo->base.flags = RADEON_BO_FLAGS_MACRO_TILE;
714 }
715
716 /* allocate back */
717 bo = radeon_legacy_bo_alloc_static(bom, size, bom->screen->backOffset);
718 if (!bo) {
719 radeon_bo_manager_legacy_dtor((struct radeon_bo_manager*)bom);
720 return NULL;
721 }
722 if (scrn->sarea->tiling_enabled) {
723 bo->base.flags = RADEON_BO_FLAGS_MACRO_TILE;
724 }
725
726 /* allocate depth */
727 bo = radeon_legacy_bo_alloc_static(bom, size, bom->screen->depthOffset);
728 if (!bo) {
729 radeon_bo_manager_legacy_dtor((struct radeon_bo_manager*)bom);
730 return NULL;
731 }
732 bo->base.flags = 0;
733 if (scrn->sarea->tiling_enabled) {
734 bo->base.flags |= RADEON_BO_FLAGS_MACRO_TILE;
735 bo->base.flags |= RADEON_BO_FLAGS_MICRO_TILE;
736 }
737 return (struct radeon_bo_manager*)bom;
738 }
739
740 void radeon_bo_legacy_texture_age(struct radeon_bo_manager *bom)
741 {
742 struct bo_manager_legacy *boml = (struct bo_manager_legacy *)bom;
743 DRI_AGE_TEXTURES(boml->texture_heap);
744 }
745
746 unsigned radeon_bo_legacy_relocs_size(struct radeon_bo *bo)
747 {
748 struct bo_legacy *bo_legacy = (struct bo_legacy*)bo;
749
750 if (bo_legacy->static_bo || (bo->domains & RADEON_GEM_DOMAIN_GTT)) {
751 return 0;
752 }
753 return bo->size;
754 }
755
756 int radeon_legacy_bo_is_static(struct radeon_bo *bo)
757 {
758 struct bo_legacy *bo_legacy = (struct bo_legacy*)bo;
759 return bo_legacy->static_bo;
760 }
761