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
)
46 /* Helper function to do the ioctls needed for setup and init. */
47 static void do_ioctls(struct r300_winsys
* winsys
, int fd
)
49 drm_radeon_getparam_t gp
;
53 /* XXX is this cast safe? */
54 gp
.value
= (int*)&target
;
56 /* First, get PCI ID */
57 gp
.param
= RADEON_PARAM_DEVICE_ID
;
58 retval
= drmCommandWriteRead(fd
, DRM_RADEON_GETPARAM
, &gp
, sizeof(gp
));
60 fprintf(stderr
, "%s: Failed to get PCI ID, error number %d",
61 __FUNCTION__
, retval
);
64 winsys
->pci_id
= target
;
66 /* Then, get the number of pixel pipes */
67 gp
.param
= RADEON_PARAM_NUM_GB_PIPES
;
68 retval
= drmCommandWriteRead(fd
, DRM_RADEON_GETPARAM
, &gp
, sizeof(gp
));
70 fprintf(stderr
, "%s: Failed to get GB pipe count, error number %d",
71 __FUNCTION__
, retval
);
74 winsys
->gb_pipes
= target
;
79 radeon_create_r300_winsys(int fd
, struct radeon_winsys
* old_winsys
)
81 struct r300_winsys
* winsys
= CALLOC_STRUCT(r300_winsys
);
83 do_ioctls(winsys
, fd
);
85 struct radeon_cs_manager
* csm
= radeon_cs_manager_gem_ctor(fd
);
87 winsys
->cs
= radeon_cs_create(csm
, 1024 * 64 / 4);
89 winsys
->check_cs
= radeon_r300_check_cs
;
90 winsys
->begin_cs
= radeon_cs_begin
;
91 winsys
->write_cs_dword
= radeon_cs_write_dword
;
92 winsys
->write_cs_reloc
= radeon_r300_write_cs_reloc
;
93 winsys
->end_cs
= radeon_cs_end
;
94 winsys
->flush_cs
= radeon_r300_flush_cs
;
96 memcpy(winsys
, old_winsys
, sizeof(struct radeon_winsys
));