summaryrefslogtreecommitdiff
path: root/radeon.c
diff options
context:
space:
mode:
Diffstat (limited to 'radeon.c')
-rw-r--r--radeon.c144
1 files changed, 144 insertions, 0 deletions
diff --git a/radeon.c b/radeon.c
new file mode 100644
index 0000000..5d6c90e
--- /dev/null
+++ b/radeon.c
@@ -0,0 +1,144 @@
+/*
+ * Copyright © 2009 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 "config.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include "xf86drm.h"
+#include "radeon_bo_gem.h"
+#include "radeon_cs_gem.h"
+#include "radeon.h"
+
+int radeon_init(struct radeon *radeon)
+{
+ int r;
+
+ memset(radeon, 0, sizeof(*radeon));
+ radeon->fd = drmOpen("radeon", NULL);
+ if (radeon->fd < 0) {
+ fprintf(stderr, "Failed to open the card fd (%d)\n", radeon->fd);
+ return radeon->fd;
+ }
+ radeon->csm = radeon_cs_manager_gem_ctor(radeon->fd);
+ if (radeon->csm == NULL) {
+ fprintf(stderr, "Failed to create CS manager\n");
+ return -1;
+ }
+ radeon->bom = radeon_bo_manager_gem_ctor(radeon->fd);
+ if (radeon->bom == NULL) {
+ fprintf(stderr, "Failed to create BO manager\n");
+ return -1;
+ }
+ r = radeon_mode_configure(radeon);
+ if (r) {
+ return r;
+ }
+ return 0;
+}
+
+void radeon_fini(struct radeon *radeon)
+{
+ radeon_mode_cleanup(radeon);
+ radeon_bo_manager_gem_dtor(radeon->bom);
+ radeon_cs_manager_gem_dtor(radeon->csm);
+ drmClose(radeon->fd);
+}
+
+void memset_bo(struct radeon_bo *bo, u32 value)
+{
+ u32 *ptr;
+ int r;
+
+ r = radeon_bo_map(bo, 1);
+ if (r) {
+ fprintf(stderr, "Failed to map buffer\n");
+ perror(NULL);
+ return;
+ }
+ ptr = (u32*)bo->ptr;
+ for (r = 0; r < (bo->size / 4); r++)
+ ptr[r] = value;
+ radeon_bo_unmap(bo);
+}
+
+void memcpy_bo(struct radeon_bo *bo, u32 *src, u32 size)
+{
+ u32 *ptr;
+ int r;
+
+ r = radeon_bo_map(bo, 1);
+ if (r) {
+ fprintf(stderr, "Failed to map buffer\n");
+ perror(NULL);
+ return;
+ }
+ ptr = (u32*)bo->ptr;
+ for (r = 0; r < size; r++)
+ ptr[r] = src[r];
+ radeon_bo_unmap(bo);
+}
+
+int memcmp_bo(struct radeon_bo *s1, struct radeon_bo *s2, u32 size)
+{
+ u32 *s1ptr;
+ u32 *s2ptr;
+ int r;
+
+ r = radeon_bo_map(s1, 1);
+ if (r) {
+ fprintf(stderr, "Failed to map buffer\n");
+ perror(NULL);
+ return -1;
+ }
+ r = radeon_bo_map(s2, 1);
+ if (r) {
+ fprintf(stderr, "Failed to map buffer\n");
+ perror(NULL);
+ return -1;
+ }
+ s1ptr = (u32*)s1->ptr;
+ s2ptr = (u32*)s2->ptr;
+ for (r = 0; r < (size / 4); r++)
+ if (s1ptr[r] != s2ptr[r])
+ return -1;
+ radeon_bo_unmap(s2);
+ radeon_bo_unmap(s1);
+ return 0;
+}
+
+void memsetrandom_bo(struct radeon_bo *bo)
+{
+ u32 *ptr;
+ int r;
+ double tmp;
+
+ r = radeon_bo_map(bo, 1);
+ if (r) {
+ fprintf(stderr, "Failed to map buffer\n");
+ perror(NULL);
+ return;
+ }
+ ptr = (u32*)bo->ptr;
+ for (r = 0; r < (bo->size / 4); r++) {
+ tmp = ((double)rand()) / ((double)RAND_MAX);
+ ptr[r] = (u32)(tmp * 0xFFFFFF);
+ }
+ radeon_bo_unmap(bo);
+}