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_check_cs(struct r300_winsys
* winsys
, int size
)
27 /* XXX check size here, lazy ass! */
28 /* XXX also validate buffers */
32 static void radeon_r300_begin_cs(struct r300_winsys
* winsys
,
38 radeon_cs_begin(winsys
->cs
, size
, file
, function
, line
);
41 static void radeon_r300_write_cs_dword(struct r300_winsys
* winsys
,
44 radeon_cs_write_dword(winsys
->cs
, dword
);
47 static void radeon_r300_write_cs_reloc(struct r300_winsys
* winsys
,
48 struct pipe_buffer
* pbuffer
,
53 radeon_cs_write_reloc(winsys
->cs
,
54 ((struct radeon_pipe_buffer
*)pbuffer
)->bo
, rd
, wd
, flags
);
57 static void radeon_r300_end_cs(struct r300_winsys
* winsys
,
62 radeon_cs_end(winsys
->cs
, file
, function
, line
);
65 static void radeon_r300_flush_cs(struct r300_winsys
* winsys
)
69 retval
= radeon_cs_emit(winsys
->cs
);
71 debug_printf("radeon: Bad CS, dumping...\n");
72 radeon_cs_print(winsys
->cs
, stderr
);
74 radeon_cs_erase(winsys
->cs
);
77 /* Helper function to do the ioctls needed for setup and init. */
78 static void do_ioctls(struct r300_winsys
* winsys
, int fd
)
80 drm_radeon_getparam_t gp
;
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
));
90 fprintf(stderr
, "%s: Failed to get GB pipe count, error number %d\n",
91 __FUNCTION__
, retval
);
94 winsys
->gb_pipes
= target
;
96 /* Then, get PCI ID */
97 gp
.param
= RADEON_PARAM_DEVICE_ID
;
98 retval
= drmCommandWriteRead(fd
, DRM_RADEON_GETPARAM
, &gp
, sizeof(gp
));
100 fprintf(stderr
, "%s: Failed to get PCI ID, error number %d\n",
101 __FUNCTION__
, retval
);
104 winsys
->pci_id
= target
;
108 radeon_create_r300_winsys(int fd
, struct radeon_winsys
* old_winsys
)
110 struct r300_winsys
* winsys
= CALLOC_STRUCT(r300_winsys
);
111 struct radeon_cs_manager
* csm
;
113 if (winsys
== NULL
) {
117 do_ioctls(winsys
, fd
);
119 csm
= radeon_cs_manager_gem_ctor(fd
);
121 winsys
->cs
= radeon_cs_create(csm
, 1024 * 64 / 4);
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
;
130 memcpy(winsys
, old_winsys
, sizeof(struct radeon_winsys
));