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 radeon_cs
* cs
, int size
)
27 /* XXX check size here, lazy ass! */
31 static void radeon_r300_write_cs_reloc(struct radeon_cs
* cs
,
32 struct pipe_buffer
* pbuffer
,
37 radeon_cs_write_reloc(cs
, ((struct radeon_pipe_buffer
*)pbuffer
)->bo
, rd
, wd
, flags
);
40 static void radeon_r300_flush_cs(struct radeon_cs
* cs
)
44 retval
= radeon_cs_emit(cs
);
46 debug_printf("radeon: Bad CS, dumping...\n");
47 radeon_cs_print(cs
, stderr
);
52 /* Helper function to do the ioctls needed for setup and init. */
53 static void do_ioctls(struct r300_winsys
* winsys
, int fd
)
55 drm_radeon_getparam_t gp
;
59 /* XXX is this cast safe? */
60 gp
.value
= (int*)&target
;
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
));
66 fprintf(stderr
, "%s: Failed to get GB pipe count, error number %d\n",
67 __FUNCTION__
, retval
);
70 winsys
->gb_pipes
= target
;
72 /* Then, get PCI ID */
73 gp
.param
= RADEON_PARAM_DEVICE_ID
;
74 retval
= drmCommandWriteRead(fd
, DRM_RADEON_GETPARAM
, &gp
, sizeof(gp
));
76 fprintf(stderr
, "%s: Failed to get PCI ID, error number %d\n",
77 __FUNCTION__
, retval
);
80 winsys
->pci_id
= target
;
84 radeon_create_r300_winsys(int fd
, struct radeon_winsys
* old_winsys
)
86 struct r300_winsys
* winsys
= CALLOC_STRUCT(r300_winsys
);
87 struct radeon_cs_manager
* csm
;
93 do_ioctls(winsys
, fd
);
95 csm
= radeon_cs_manager_gem_ctor(fd
);
97 winsys
->cs
= radeon_cs_create(csm
, 1024 * 64 / 4);
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
;
106 memcpy(winsys
, old_winsys
, sizeof(struct radeon_winsys
));