42 u32 aux_sc_cntl = 0x00000000;
226 DRM_DEBUG(
"dirty=0x%08x\n", dirty);
229 r128_emit_core(dev_priv);
230 sarea_priv->
dirty &= ~R128_UPLOAD_CORE;
234 r128_emit_context(dev_priv);
235 sarea_priv->
dirty &= ~R128_UPLOAD_CONTEXT;
239 r128_emit_setup(dev_priv);
240 sarea_priv->
dirty &= ~R128_UPLOAD_SETUP;
244 r128_emit_masks(dev_priv);
245 sarea_priv->
dirty &= ~R128_UPLOAD_MASKS;
249 r128_emit_window(dev_priv);
250 sarea_priv->
dirty &= ~R128_UPLOAD_WINDOW;
254 r128_emit_tex0(dev_priv);
255 sarea_priv->
dirty &= ~R128_UPLOAD_TEX0;
259 r128_emit_tex1(dev_priv);
260 sarea_priv->
dirty &= ~R128_UPLOAD_TEX1;
269 #if R128_PERFORMANCE_BOXES
275 int x,
int y,
int w,
int h,
int r,
int g,
int b)
281 switch (dev_priv->fb_bpp) {
284 color = (((r & 0xf8) << 8) |
285 ((g & 0xfc) << 3) | ((b & 0xf8) >> 3));
289 color = ((r << 16) | (g << 8) |
b);
293 color = (((0xff) << 24) | (r << 16) | (g << 8) |
b);
312 OUT_RING((pitch << 21) | (offset >> 5));
324 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
335 static void r128_print_dirty(
const char *
msg,
unsigned int flags)
337 DRM_INFO(
"%s: (0x%x) %s%s%s%s%s%s%s%s%s\n",
340 (flags & R128_UPLOAD_CORE) ?
"core, " :
"",
341 (flags & R128_UPLOAD_CONTEXT) ?
"context, " :
"",
342 (flags & R128_UPLOAD_SETUP) ?
"setup, " :
"",
343 (flags & R128_UPLOAD_TEX0) ?
"tex0, " :
"",
345 (flags & R128_UPLOAD_MASKS) ?
"masks, " :
"",
346 (flags & R128_UPLOAD_WINDOW) ?
"window, " :
"",
356 int nbox = sarea_priv->
nbox;
358 unsigned int flags = clear->
flags;
373 for (i = 0; i < nbox; i++) {
376 int w = pbox[
i].
x2 -
x;
377 int h = pbox[
i].
y2 -
y;
379 DRM_DEBUG(
"dispatch clear %d,%d-%d,%d flags 0x%x\n",
380 pbox[i].
x1, pbox[i].
y1, pbox[i].
x2,
392 if (flags & R128_FRONT) {
457 static void r128_cce_dispatch_swap(
struct drm_device *dev)
461 int nbox = sarea_priv->
nbox;
467 #if R128_PERFORMANCE_BOXES
470 r128_cce_performance_boxes(dev_priv);
473 for (i = 0; i < nbox; i++) {
476 int w = pbox[
i].
x2 -
x;
477 int h = pbox[
i].
y2 -
y;
523 static void r128_cce_dispatch_flip(
struct drm_device *dev)
527 DRM_DEBUG(
"page=%d pfCurrentPage=%d\n",
530 #if R128_PERFORMANCE_BOXES
533 r128_cce_performance_boxes(dev_priv);
564 static void r128_cce_dispatch_vertex(
struct drm_device *dev,
struct drm_buf *
buf)
570 int offset = buf->bus_address;
571 int size = buf->used;
575 DRM_DEBUG(
"buf=%d nbox=%d\n", buf->idx, sarea_priv->
nbox);
578 r128_print_dirty(
"dispatch_vertex", sarea_priv->
dirty);
584 r128_emit_state(dev_priv);
588 if (i < sarea_priv->nbox) {
589 r128_emit_clip_rects(dev_priv,
590 &sarea_priv->
boxes[i],
591 sarea_priv->
nbox - i);
607 }
while (i < sarea_priv->nbox);
630 sarea_priv->
nbox = 0;
633 static void r128_cce_dispatch_indirect(
struct drm_device *dev,
634 struct drm_buf *buf,
int start,
int end)
639 DRM_DEBUG(
"indirect: buf=%d s=0x%x e=0x%x\n", buf->idx, start, end);
642 int offset = buf->bus_address +
start;
643 int dwords = (end - start + 3) /
sizeof(
u32);
651 ((
char *)dev->agp_buffer_map->handle
652 + buf->offset +
start);
688 static void r128_cce_dispatch_indices(
struct drm_device *dev,
690 int start,
int end,
int count)
697 int prim = buf_priv->
prim;
702 DRM_DEBUG(
"indices: s=%d e=%d c=%d\n", start, end, count);
705 r128_print_dirty(
"dispatch_indices", sarea_priv->
dirty);
711 r128_emit_state(dev_priv);
713 dwords = (end - start + 3) /
sizeof(
u32);
715 data = (
u32 *) ((
char *)dev->agp_buffer_map->handle
716 + buf->offset +
start);
728 #ifdef __LITTLE_ENDIAN
729 data[dwords - 1] &= 0x0000ffff;
731 data[dwords - 1] &= 0xffff0000;
737 if (i < sarea_priv->nbox) {
738 r128_emit_clip_rects(dev_priv,
739 &sarea_priv->
boxes[i],
740 sarea_priv->
nbox - i);
743 r128_cce_dispatch_indirect(dev, buf, start, end);
746 }
while (i < sarea_priv->nbox);
768 sarea_priv->
nbox = 0;
771 static int r128_cce_dispatch_blit(
struct drm_device *dev,
772 struct drm_file *file_priv,
776 struct drm_device_dma *
dma = dev->dma;
780 int dword_shift, dwords;
804 DRM_ERROR(
"invalid blit format %d\n", blit->
format);
822 buf = dma->buflist[blit->
idx];
823 buf_priv = buf->dev_private;
825 if (buf->file_priv != file_priv) {
826 DRM_ERROR(
"process %d using buffer owned by %p\n",
831 DRM_ERROR(
"sending pending buffer %d\n", blit->
idx);
837 dwords = (blit->
width * blit->
height) >> dword_shift;
839 data = (
u32 *) ((
char *)dev->agp_buffer_map->handle + buf->offset);
858 buf->used = (dwords + 8) *
sizeof(
u32);
860 r128_cce_dispatch_indirect(dev, buf, 0, buf->used);
883 static int r128_cce_dispatch_write_span(
struct drm_device *dev,
895 if (count > 4096 || count <= 0)
903 buffer_size = depth->
n *
sizeof(
u32);
912 mask_size = depth->
n *
sizeof(
u8);
925 for (i = 0; i <
count; i++, x++) {
950 for (i = 0; i <
count; i++, x++) {
977 static int r128_cce_dispatch_write_pixels(
struct drm_device *dev,
984 int i, xbuf_size, ybuf_size, buffer_size, mask_size;
989 if (count > 4096 || count <= 0)
992 xbuf_size = count *
sizeof(*x);
993 ybuf_size = count *
sizeof(*y);
1013 buffer_size = depth->
n *
sizeof(
u32);
1015 if (buffer ==
NULL) {
1028 mask_size = depth->
n *
sizeof(
u8);
1044 for (i = 0; i <
count; i++) {
1069 for (i = 0; i <
count; i++) {
1098 static int r128_cce_dispatch_read_span(
struct drm_device *dev,
1107 if (count > 4096 || count <= 0)
1139 static int r128_cce_dispatch_read_pixels(
struct drm_device *dev,
1144 int i, xbuf_size, ybuf_size;
1149 if (count > 4096 || count <= 0)
1155 xbuf_size = count *
sizeof(*x);
1156 ybuf_size = count *
sizeof(*y);
1176 for (i = 0; i <
count; i++) {
1209 static void r128_cce_dispatch_stipple(
struct drm_device *dev,
u32 *stipple)
1219 for (i = 0; i < 32; i++)
1229 static int r128_cce_clear(
struct drm_device *dev,
void *data,
struct drm_file *file_priv)
1236 LOCK_TEST_WITH_RETURN(dev, file_priv);
1247 r128_cce_dispatch_clear(dev, clear);
1257 static int r128_do_init_pageflip(
struct drm_device *dev)
1276 static int r128_do_cleanup_pageflip(
struct drm_device *dev)
1285 r128_cce_dispatch_flip(dev);
1297 static int r128_cce_flip(
struct drm_device *dev,
void *data,
struct drm_file *file_priv)
1302 LOCK_TEST_WITH_RETURN(dev, file_priv);
1309 r128_do_init_pageflip(dev);
1311 r128_cce_dispatch_flip(dev);
1317 static int r128_cce_swap(
struct drm_device *dev,
void *data,
struct drm_file *file_priv)
1323 LOCK_TEST_WITH_RETURN(dev, file_priv);
1332 r128_cce_dispatch_swap(dev);
1340 static int r128_cce_vertex(
struct drm_device *dev,
void *data,
struct drm_file *file_priv)
1343 struct drm_device_dma *dma = dev->dma;
1344 struct drm_buf *
buf;
1348 LOCK_TEST_WITH_RETURN(dev, file_priv);
1352 DRM_DEBUG(
"pid=%d index=%d count=%d discard=%d\n",
1355 if (vertex->
idx < 0 || vertex->
idx >= dma->buf_count) {
1356 DRM_ERROR(
"buffer index %d (of %d max)\n",
1357 vertex->
idx, dma->buf_count - 1);
1360 if (vertex->
prim < 0 ||
1362 DRM_ERROR(
"buffer prim %d\n", vertex->
prim);
1369 buf = dma->buflist[vertex->
idx];
1370 buf_priv = buf->dev_private;
1372 if (buf->file_priv != file_priv) {
1373 DRM_ERROR(
"process %d using buffer owned by %p\n",
1378 DRM_ERROR(
"sending pending buffer %d\n", vertex->
idx);
1382 buf->used = vertex->
count;
1386 r128_cce_dispatch_vertex(dev, buf);
1392 static int r128_cce_indices(
struct drm_device *dev,
void *data,
struct drm_file *file_priv)
1395 struct drm_device_dma *dma = dev->dma;
1396 struct drm_buf *
buf;
1401 LOCK_TEST_WITH_RETURN(dev, file_priv);
1408 if (elts->
idx < 0 || elts->
idx >= dma->buf_count) {
1409 DRM_ERROR(
"buffer index %d (of %d max)\n",
1410 elts->
idx, dma->buf_count - 1);
1413 if (elts->
prim < 0 ||
1415 DRM_ERROR(
"buffer prim %d\n", elts->
prim);
1422 buf = dma->buflist[elts->
idx];
1423 buf_priv = buf->dev_private;
1425 if (buf->file_priv != file_priv) {
1426 DRM_ERROR(
"process %d using buffer owned by %p\n",
1431 DRM_ERROR(
"sending pending buffer %d\n", elts->
idx);
1438 if (elts->
start & 0x7) {
1439 DRM_ERROR(
"misaligned buffer 0x%x\n", elts->
start);
1442 if (elts->
start < buf->used) {
1443 DRM_ERROR(
"no header 0x%x - 0x%x\n", elts->
start, buf->used);
1447 buf->used = elts->
end;
1451 r128_cce_dispatch_indices(dev, buf, elts->
start, elts->
end, count);
1457 static int r128_cce_blit(
struct drm_device *dev,
void *data,
struct drm_file *file_priv)
1459 struct drm_device_dma *dma = dev->dma;
1464 LOCK_TEST_WITH_RETURN(dev, file_priv);
1470 if (blit->
idx < 0 || blit->
idx >= dma->buf_count) {
1471 DRM_ERROR(
"buffer index %d (of %d max)\n",
1472 blit->
idx, dma->buf_count - 1);
1479 ret = r128_cce_dispatch_blit(dev, file_priv, blit);
1485 static int r128_cce_depth(
struct drm_device *dev,
void *data,
struct drm_file *file_priv)
1491 LOCK_TEST_WITH_RETURN(dev, file_priv);
1498 switch (depth->
func) {
1499 case R128_WRITE_SPAN:
1500 ret = r128_cce_dispatch_write_span(dev, depth);
1502 case R128_WRITE_PIXELS:
1503 ret = r128_cce_dispatch_write_pixels(dev, depth);
1505 case R128_READ_SPAN:
1506 ret = r128_cce_dispatch_read_span(dev, depth);
1508 case R128_READ_PIXELS:
1509 ret = r128_cce_dispatch_read_pixels(dev, depth);
1517 static int r128_cce_stipple(
struct drm_device *dev,
void *data,
struct drm_file *file_priv)
1523 LOCK_TEST_WITH_RETURN(dev, file_priv);
1532 r128_cce_dispatch_stipple(dev, mask);
1538 static int r128_cce_indirect(
struct drm_device *dev,
void *data,
struct drm_file *file_priv)
1541 struct drm_device_dma *dma = dev->dma;
1542 struct drm_buf *
buf;
1549 LOCK_TEST_WITH_RETURN(dev, file_priv);
1553 DRM_DEBUG(
"idx=%d s=%d e=%d d=%d\n",
1557 if (indirect->
idx < 0 || indirect->
idx >= dma->buf_count) {
1558 DRM_ERROR(
"buffer index %d (of %d max)\n",
1559 indirect->
idx, dma->buf_count - 1);
1563 buf = dma->buflist[indirect->
idx];
1564 buf_priv = buf->dev_private;
1566 if (buf->file_priv != file_priv) {
1567 DRM_ERROR(
"process %d using buffer owned by %p\n",
1572 DRM_ERROR(
"sending pending buffer %d\n", indirect->
idx);
1576 if (indirect->
start < buf->used) {
1577 DRM_ERROR(
"reusing indirect: start=0x%x actual=0x%x\n",
1578 indirect->
start, buf->used);
1585 buf->used = indirect->
end;
1601 r128_cce_dispatch_indirect(dev, buf, indirect->
start, indirect->
end);
1607 static int r128_getparam(
struct drm_device *dev,
void *data,
struct drm_file *file_priv)
1617 switch (param->
param) {
1619 value = drm_dev_to_irq(dev);
1626 DRM_ERROR(
"copy_to_user\n");
1635 if (dev->dev_private) {
1638 r128_do_cleanup_pageflip(dev);
1647 DRM_IOCTL_DEF_DRV(R128_INIT,
r128_cce_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1648 DRM_IOCTL_DEF_DRV(R128_CCE_START,
r128_cce_start, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1649 DRM_IOCTL_DEF_DRV(R128_CCE_STOP,
r128_cce_stop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1650 DRM_IOCTL_DEF_DRV(R128_CCE_RESET,
r128_cce_reset, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1654 DRM_IOCTL_DEF_DRV(R128_SWAP, r128_cce_swap, DRM_AUTH),
1655 DRM_IOCTL_DEF_DRV(R128_FLIP, r128_cce_flip, DRM_AUTH),
1656 DRM_IOCTL_DEF_DRV(R128_CLEAR, r128_cce_clear, DRM_AUTH),
1657 DRM_IOCTL_DEF_DRV(R128_VERTEX, r128_cce_vertex, DRM_AUTH),
1658 DRM_IOCTL_DEF_DRV(R128_INDICES, r128_cce_indices, DRM_AUTH),
1659 DRM_IOCTL_DEF_DRV(R128_BLIT, r128_cce_blit, DRM_AUTH),
1660 DRM_IOCTL_DEF_DRV(R128_DEPTH, r128_cce_depth, DRM_AUTH),
1661 DRM_IOCTL_DEF_DRV(R128_STIPPLE, r128_cce_stipple, DRM_AUTH),
1662 DRM_IOCTL_DEF_DRV(R128_INDIRECT, r128_cce_indirect, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1663 DRM_IOCTL_DEF_DRV(R128_GETPARAM, r128_getparam, DRM_AUTH),