summaryrefslogtreecommitdiff
path: root/radeon_atom.c
blob: e27116f7fd4b4006b1bd62d52deffa03ffe07b58 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
 * Copyright © 2010 Jerome Glisse <glisse@freedesktop.org>
 *
 * This file is free software; you can redistribute it and/or modify
 * it under the terms of version 2 of the GNU General Public License
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 */
#include "radeon_device.h"

int radeon_atom_init(struct radeon_atom *atom, radeon_atom_emit_t emit)
{
	int r;

	INIT_LIST_HEAD(&atom->list);
	kref_init(&atom->kref);
	atom->emit = emit;
	atom->nflushes = 0;
	return 0;
}

void radeon_atom_flush_cleanup(struct list_head *flushes)
{
	struct radeon_atom_flush *i, *n;

	list_for_each_entry_safe(i, n, flushes, list) {
		list_del(&i->list);
		kfree(i);
	}
}

int radeon_atom_flush_add(struct list_head *flushes, struct radeon_bo *bo, u32 flags)
{
	struct radeon_atom_flush *i;

	list_for_each_entry(i, flushes, list) {
		if (i->bo->handle == bo->handle) {
			i->flags |= flags;
			return 0;
		}
	}
	i = kmalloc(sizeof(*i), GFP_KERNEL);
	if (i == NULL)
		return -ENOMEM;
	i->bo = bo;
	i->flags = flags;
	list_add_tail(&i->list, flushes);
	return 1;
}

int radeon_atom_emit_default(struct radeon_device *rdev, struct radeon_atom *atom,
				void *data, struct radeon_ib *ib)
{
	return radeon_ib_copy(ib, atom->pkts, atom->npkts);
}

int radeon_atom_create(struct radeon_device *rdev,
			struct drm_radeon_atom *patom,
			struct radeon_atom **atom)
{
	return r600_atom_create(rdev, patom, atom);
}

int radeon_batches_queue(struct radeon_device *rdev, void *batch)
{
	return r600_batches_queue(rdev, batch);
}

int radeon_batches_flush(struct radeon_device *rdev)
{
	return r600_batches_flush(rdev);
}

struct radeon_bo *radeon_bo_lookup(struct radeon_device *rdev, u32 handle)
{
	int i;

	for (i = 0; i < rdev->nbo; i++) {
		if (rdev->bo[i] && rdev->bo[i]->handle == handle) {
			radeon_bo_ref(rdev->bo[i]);
			return rdev->bo[i];
		}
	}
	return NULL;
}

void radeon_device_set_bo_list(struct radeon_device *rdev, u32 nbo, struct radeon_bo **bo)
{
	memcpy(rdev->bo, bo, sizeof(void*) * nbo);
	rdev->nbo = nbo;
}

void radeon_atom_release(struct kref *kref)
{
	struct radeon_atom *atom = container_of(kref, struct radeon_atom, kref);
	int i;

	for (i = 0; i < atom->nbo; i++) {
		radeon_bo_unref(atom->bo[i]);
	}
	free(atom->state);
	free(atom);
}