summaryrefslogtreecommitdiff
path: root/src/gallium/winsys/r600/drm/radeon_ws_bo.c
blob: c789f8780f9652131ed4def289eb423ba2e538ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <malloc.h>
#include "radeon_priv.h"

struct radeon_ws_bo *radeon_ws_bo(struct radeon *radeon,
				  unsigned size, unsigned alignment)
{
	struct radeon_ws_bo *ws_bo = calloc(1, sizeof(struct radeon_ws_bo));

	ws_bo->bo = radeon_bo(radeon, 0, size, alignment, NULL);
	if (!ws_bo->bo) {
		free(ws_bo);
		return NULL;
	}

	pipe_reference_init(&ws_bo->reference, 1);
	return ws_bo;
}

struct radeon_ws_bo *radeon_ws_bo_handle(struct radeon *radeon,
					 unsigned handle)
{
	struct radeon_ws_bo *ws_bo = calloc(1, sizeof(struct radeon_ws_bo));

	ws_bo->bo = radeon_bo(radeon, handle, 0, 0, NULL);
	if (!ws_bo->bo) {
		free(ws_bo);
		return NULL;
	}
	pipe_reference_init(&ws_bo->reference, 1);
	return ws_bo;
}

void *radeon_ws_bo_map(struct radeon *radeon, struct radeon_ws_bo *bo)
{
	radeon_bo_map(radeon, bo->bo);
	return bo->bo->data;
}

void radeon_ws_bo_unmap(struct radeon *radeon, struct radeon_ws_bo *bo)
{
	radeon_bo_unmap(radeon, bo->bo);
}

static void radeon_ws_bo_destroy(struct radeon *radeon, struct radeon_ws_bo *bo)
{
	radeon_bo_reference(radeon, &bo->bo, NULL);
	free(bo);
}

void radeon_ws_bo_reference(struct radeon *radeon, struct radeon_ws_bo **dst,
			    struct radeon_ws_bo *src)
{
	struct radeon_ws_bo *old = *dst;
	if (pipe_reference(&(*dst)->reference, &src->reference)) {
		radeon_ws_bo_destroy(radeon, old);
	}
	*dst = src;
}

int radeon_ws_bo_wait(struct radeon *radeon, struct radeon_ws_bo *bo)
{
	return radeon_bo_wait(radeon, bo->bo);
}