radeon_legacy_memory.c revision b7e1c893
1
2#ifdef HAVE_CONFIG_H
3#include "config.h"
4#endif
5
6/* Driver data structures */
7#include "radeon.h"
8
9/* Allocates memory, either by resizing the allocation pointed to by mem_struct,
10 * or by freeing mem_struct (if non-NULL) and allocating a new space.  The size
11 * is measured in bytes, and the offset from the beginning of card space is
12 * returned.
13 */
14uint32_t
15radeon_legacy_allocate_memory(ScrnInfoPtr pScrn,
16		       void **mem_struct,
17		       int size,
18		       int align)
19{
20    ScreenPtr pScreen = screenInfo.screens[pScrn->scrnIndex];
21    RADEONInfoPtr info = RADEONPTR(pScrn);
22    uint32_t offset = 0;
23
24#ifdef USE_EXA
25    if (info->useEXA) {
26	ExaOffscreenArea *area = *mem_struct;
27
28	if (area != NULL) {
29	    if (area->size >= size)
30		return area->offset;
31
32	    exaOffscreenFree(pScreen, area);
33	}
34
35	area = exaOffscreenAlloc(pScreen, size, align, TRUE,
36				 NULL, NULL);
37
38	*mem_struct = area;
39	if (area == NULL)
40	    return 0;
41	offset = area->offset;
42    }
43#endif /* USE_EXA */
44#ifdef USE_XAA
45    if (!info->useEXA) {
46	FBLinearPtr linear = *mem_struct;
47	int cpp = info->CurrentLayout.bitsPerPixel / 8;
48
49	/* XAA allocates in units of pixels at the screen bpp, so adjust size
50	 * appropriately.
51	 */
52	size = (size + cpp - 1) / cpp;
53	align = (align + cpp - 1) / cpp;
54
55	if (linear) {
56	    if(linear->size >= size)
57		return linear->offset * cpp;
58
59	    if(xf86ResizeOffscreenLinear(linear, size))
60		return linear->offset * cpp;
61
62	    xf86FreeOffscreenLinear(linear);
63	}
64
65	linear = xf86AllocateOffscreenLinear(pScreen, size, align,
66					     NULL, NULL, NULL);
67	*mem_struct = linear;
68
69	if (!linear) {
70	    int max_size;
71
72	    xf86QueryLargestOffscreenLinear(pScreen, &max_size, align,
73					    PRIORITY_EXTREME);
74
75	    if (max_size < size)
76		return 0;
77
78	    xf86PurgeUnlockedOffscreenAreas(pScreen);
79	    linear = xf86AllocateOffscreenLinear(pScreen, size, align,
80						 NULL, NULL, NULL);
81	    *mem_struct = linear;
82	    if (!linear)
83		return 0;
84	}
85	offset = linear->offset * cpp;
86    }
87#endif /* USE_XAA */
88
89    return offset;
90}
91
92void
93radeon_legacy_free_memory(ScrnInfoPtr pScrn,
94		   void *mem_struct)
95{
96    RADEONInfoPtr info = RADEONPTR(pScrn);
97#ifdef USE_EXA
98    ScreenPtr pScreen = screenInfo.screens[pScrn->scrnIndex];
99
100    if (info->useEXA) {
101	ExaOffscreenArea *area = mem_struct;
102
103	if (area != NULL)
104	    exaOffscreenFree(pScreen, area);
105	area = NULL;
106    }
107#endif /* USE_EXA */
108#ifdef USE_XAA
109    if (!info->useEXA) {
110	FBLinearPtr linear = mem_struct;
111
112	if (linear != NULL)
113	    xf86FreeOffscreenLinear(linear);
114	linear = NULL;
115    }
116#endif /* USE_XAA */
117}
118