r300-gallium, radeon-winsys: Reorganize r300_winsys header, break ABI.
[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 r300_winsys* winsys, int size)
26 {
27 /* XXX check size here, lazy ass! */
28 /* XXX also validate buffers */
29 return TRUE;
30 }
31
32 static void radeon_r300_begin_cs(struct r300_winsys* winsys,
33 int size,
34 const char* file,
35 const char* function,
36 int line)
37 {
38 radeon_cs_begin(winsys->cs, size, file, function, line);
39 }
40
41 static void radeon_r300_write_cs_dword(struct r300_winsys* winsys,
42 uint32_t dword)
43 {
44 radeon_cs_write_dword(winsys->cs, dword);
45 }
46
47 static void radeon_r300_write_cs_reloc(struct r300_winsys* winsys,
48 struct pipe_buffer* pbuffer,
49 uint32_t rd,
50 uint32_t wd,
51 uint32_t flags)
52 {
53 radeon_cs_write_reloc(winsys->cs,
54 ((struct radeon_pipe_buffer*)pbuffer)->bo, rd, wd, flags);
55 }
56
57 static void radeon_r300_end_cs(struct r300_winsys* winsys,
58 const char* file,
59 const char* function,
60 int line)
61 {
62 radeon_cs_end(winsys->cs, file, function, line);
63 }
64
65 static void radeon_r300_flush_cs(struct r300_winsys* winsys)
66 {
67 int retval = 0;
68
69 retval = radeon_cs_emit(winsys->cs);
70 if (retval) {
71 debug_printf("radeon: Bad CS, dumping...\n");
72 radeon_cs_print(winsys->cs, stderr);
73 }
74 radeon_cs_erase(winsys->cs);
75 }
76
77 /* Helper function to do the ioctls needed for setup and init. */
78 static void do_ioctls(struct r300_winsys* winsys, int fd)
79 {
80 drm_radeon_getparam_t gp;
81 int target;
82 int retval;
83
84 gp.value = &target;
85
86 /* First, get the number of pixel pipes */
87 gp.param = RADEON_PARAM_NUM_GB_PIPES;
88 retval = drmCommandWriteRead(fd, DRM_RADEON_GETPARAM, &gp, sizeof(gp));
89 if (retval) {
90 fprintf(stderr, "%s: Failed to get GB pipe count, error number %d\n",
91 __FUNCTION__, retval);
92 exit(1);
93 }
94 winsys->gb_pipes = target;
95
96 /* Then, get PCI ID */
97 gp.param = RADEON_PARAM_DEVICE_ID;
98 retval = drmCommandWriteRead(fd, DRM_RADEON_GETPARAM, &gp, sizeof(gp));
99 if (retval) {
100 fprintf(stderr, "%s: Failed to get PCI ID, error number %d\n",
101 __FUNCTION__, retval);
102 exit(1);
103 }
104 winsys->pci_id = target;
105 }
106
107 struct r300_winsys*
108 radeon_create_r300_winsys(int fd, struct radeon_winsys* old_winsys)
109 {
110 struct r300_winsys* winsys = CALLOC_STRUCT(r300_winsys);
111 struct radeon_cs_manager* csm;
112
113 if (winsys == NULL) {
114 return NULL;
115 }
116
117 do_ioctls(winsys, fd);
118
119 csm = radeon_cs_manager_gem_ctor(fd);
120
121 winsys->cs = radeon_cs_create(csm, 1024 * 64 / 4);
122
123 winsys->check_cs = radeon_r300_check_cs;
124 winsys->begin_cs = radeon_r300_begin_cs;
125 winsys->write_cs_dword = radeon_r300_write_cs_dword;
126 winsys->write_cs_reloc = radeon_r300_write_cs_reloc;
127 winsys->end_cs = radeon_r300_end_cs;
128 winsys->flush_cs = radeon_r300_flush_cs;
129
130 memcpy(winsys, old_winsys, sizeof(struct radeon_winsys));
131
132 return winsys;
133 }