2 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
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:
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
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. */
23 #include "radeon_r300.h"
25 static boolean
radeon_r300_add_buffer(struct r300_winsys
* winsys
,
26 struct pipe_buffer
* pbuffer
,
30 struct radeon_winsys_priv
* priv
=
31 (struct radeon_winsys_priv
*)winsys
->radeon_winsys
;
32 struct radeon_bo
* bo
= ((struct radeon_pipe_buffer
*)pbuffer
)->bo
;
34 radeon_cs_space_add_persistent_bo(priv
->cs
, bo
, rd
, wd
);
38 static boolean
radeon_r300_validate(struct r300_winsys
* winsys
)
40 struct radeon_winsys_priv
* priv
=
41 (struct radeon_winsys_priv
*)winsys
->radeon_winsys
;
43 if (radeon_cs_space_check(priv
->cs
) < 0) {
47 /* Things are fine, we can proceed as normal. */
51 static boolean
radeon_r300_check_cs(struct r300_winsys
* winsys
, int size
)
53 /* XXX check size here, lazy ass! */
54 /* XXX also validate buffers */
58 static void radeon_r300_begin_cs(struct r300_winsys
* winsys
,
64 struct radeon_winsys_priv
* priv
=
65 (struct radeon_winsys_priv
*)winsys
->radeon_winsys
;
67 radeon_cs_begin(priv
->cs
, size
, file
, function
, line
);
70 static void radeon_r300_write_cs_dword(struct r300_winsys
* winsys
,
73 struct radeon_winsys_priv
* priv
=
74 (struct radeon_winsys_priv
*)winsys
->radeon_winsys
;
76 radeon_cs_write_dword(priv
->cs
, dword
);
79 static void radeon_r300_write_cs_reloc(struct r300_winsys
* winsys
,
80 struct pipe_buffer
* pbuffer
,
85 struct radeon_winsys_priv
* priv
=
86 (struct radeon_winsys_priv
*)winsys
->radeon_winsys
;
89 retval
= radeon_cs_write_reloc(priv
->cs
,
90 ((struct radeon_pipe_buffer
*)pbuffer
)->bo
, rd
, wd
, flags
);
93 debug_printf("radeon: Relocation of %p (%d, %d, %d) failed!\n",
94 pbuffer
, rd
, wd
, flags
);
98 static void radeon_r300_end_cs(struct r300_winsys
* winsys
,
100 const char* function
,
103 struct radeon_winsys_priv
* priv
=
104 (struct radeon_winsys_priv
*)winsys
->radeon_winsys
;
106 radeon_cs_end(priv
->cs
, file
, function
, line
);
109 static void radeon_r300_flush_cs(struct r300_winsys
* winsys
)
111 struct radeon_winsys_priv
* priv
=
112 (struct radeon_winsys_priv
*)winsys
->radeon_winsys
;
116 retval
= radeon_cs_emit(priv
->cs
);
118 debug_printf("radeon: Bad CS, dumping...\n");
119 radeon_cs_print(priv
->cs
, stderr
);
123 radeon_cs_space_reset_bos(priv
->cs
);
126 * Someday, when we care about performance, we should really find a way
127 * to rotate between two or three CS objects so that the GPU can be
128 * spinning through one CS while another one is being filled. */
129 radeon_cs_erase(priv
->cs
);
132 /* Helper function to do the ioctls needed for setup and init. */
133 static void do_ioctls(struct r300_winsys
* winsys
, int fd
)
135 struct drm_radeon_gem_info gem_info
= {0};
136 struct drm_radeon_info info
= {0};
140 info
.value
= &target
;
142 /* First, get the number of pixel pipes */
143 info
.request
= RADEON_INFO_NUM_GB_PIPES
;
144 retval
= drmCommandWriteRead(fd
, DRM_RADEON_INFO
, &info
, sizeof(info
));
146 fprintf(stderr
, "%s: Failed to get GB pipe count, "
147 "error number %d\n", __FUNCTION__
, retval
);
150 winsys
->gb_pipes
= target
;
152 /* Then, get PCI ID */
153 info
.request
= RADEON_INFO_DEVICE_ID
;
154 retval
= drmCommandWriteRead(fd
, DRM_RADEON_INFO
, &info
, sizeof(info
));
156 fprintf(stderr
, "%s: Failed to get PCI ID, "
157 "error number %d\n", __FUNCTION__
, retval
);
160 winsys
->pci_id
= target
;
162 /* Finally, retrieve MM info */
163 retval
= drmCommandWriteRead(fd
, DRM_RADEON_GEM_INFO
,
164 &gem_info
, sizeof(gem_info
));
166 fprintf(stderr
, "%s: Failed to get MM info, error number %d\n",
167 __FUNCTION__
, retval
);
170 winsys
->gart_size
= gem_info
.gart_size
;
172 winsys
->vram_size
= gem_info
.vram_visible
;
176 radeon_create_r300_winsys(int fd
, struct radeon_winsys
* old_winsys
)
178 struct r300_winsys
* winsys
= CALLOC_STRUCT(r300_winsys
);
179 struct radeon_winsys_priv
* priv
;
181 if (winsys
== NULL
) {
185 priv
= old_winsys
->priv
;
187 do_ioctls(winsys
, fd
);
189 priv
->csm
= radeon_cs_manager_gem_ctor(fd
);
191 priv
->cs
= radeon_cs_create(priv
->csm
, 1024 * 64 / 4);
192 radeon_cs_set_limit(priv
->cs
,
193 RADEON_GEM_DOMAIN_GTT
, winsys
->gart_size
);
194 radeon_cs_set_limit(priv
->cs
,
195 RADEON_GEM_DOMAIN_VRAM
, winsys
->vram_size
);
197 winsys
->add_buffer
= radeon_r300_add_buffer
;
198 winsys
->validate
= radeon_r300_validate
;
200 winsys
->check_cs
= radeon_r300_check_cs
;
201 winsys
->begin_cs
= radeon_r300_begin_cs
;
202 winsys
->write_cs_dword
= radeon_r300_write_cs_dword
;
203 winsys
->write_cs_reloc
= radeon_r300_write_cs_reloc
;
204 winsys
->end_cs
= radeon_r300_end_cs
;
205 winsys
->flush_cs
= radeon_r300_flush_cs
;
207 memcpy(winsys
, old_winsys
, sizeof(struct radeon_winsys
));