radeon-r300: Fix a bit of breakage.
[mesa.git] / src / gallium / winsys / drm / radeon / core / radeon_r300.c
1 /*
2 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
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 AUTHOR(S) AND/OR THEIR 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 #include "radeon_r300.h"
24
25 static boolean radeon_r300_check_cs(struct radeon_cs* cs, int size)
26 {
27 /* XXX check size here, lazy ass! */
28 return TRUE;
29 }
30
31 static void radeon_r300_write_cs_reloc(struct radeon_cs* cs,
32 struct pipe_buffer* pbuffer,
33 uint32_t rd,
34 uint32_t wd,
35 uint32_t flags)
36 {
37 radeon_cs_write_reloc(cs, ((struct radeon_pipe_buffer*)pbuffer)->bo, rd, wd, flags);
38 }
39
40 static void radeon_r300_flush_cs(struct radeon_cs* cs)
41 {
42 int retval = 0;
43
44 retval = radeon_cs_emit(cs);
45 if (retval) {
46 debug_printf("radeon: Bad CS, dumping...\n");
47 radeon_cs_print(cs, stderr);
48 }
49 radeon_cs_erase(cs);
50 }
51
52 /* Helper function to do the ioctls needed for setup and init. */
53 static void do_ioctls(struct r300_winsys* winsys, int fd)
54 {
55 drm_radeon_getparam_t gp;
56 int target;
57 int retval;
58
59 /* XXX is this cast safe? */
60 gp.value = (int*)&target;
61
62 /* First, get the number of pixel pipes */
63 gp.param = RADEON_PARAM_NUM_GB_PIPES;
64 retval = drmCommandWriteRead(fd, DRM_RADEON_GETPARAM, &gp, sizeof(gp));
65 if (retval) {
66 fprintf(stderr, "%s: Failed to get GB pipe count, error number %d\n",
67 __FUNCTION__, retval);
68 exit(1);
69 }
70 winsys->gb_pipes = target;
71
72 /* Then, get PCI ID */
73 gp.param = RADEON_PARAM_DEVICE_ID;
74 retval = drmCommandWriteRead(fd, DRM_RADEON_GETPARAM, &gp, sizeof(gp));
75 if (retval) {
76 fprintf(stderr, "%s: Failed to get PCI ID, error number %d\n",
77 __FUNCTION__, retval);
78 exit(1);
79 }
80 winsys->pci_id = target;
81 }
82
83 struct r300_winsys*
84 radeon_create_r300_winsys(int fd, struct radeon_winsys* old_winsys)
85 {
86 struct r300_winsys* winsys = CALLOC_STRUCT(r300_winsys);
87 struct radeon_cs_manager* csm;
88
89 if (winsys == NULL) {
90 return NULL;
91 }
92
93 do_ioctls(winsys, fd);
94
95 csm = radeon_cs_manager_gem_ctor(fd);
96
97 winsys->cs = radeon_cs_create(csm, 1024 * 64 / 4);
98
99 winsys->check_cs = radeon_r300_check_cs;
100 winsys->begin_cs = radeon_cs_begin;
101 winsys->write_cs_dword = radeon_cs_write_dword;
102 winsys->write_cs_reloc = radeon_r300_write_cs_reloc;
103 winsys->end_cs = radeon_cs_end;
104 winsys->flush_cs = radeon_r300_flush_cs;
105
106 memcpy(winsys, old_winsys, sizeof(struct radeon_winsys));
107
108 return winsys;
109 }