43 #include <linux/slab.h>
45 #define VIA_PGDN(x) (((unsigned long)(x)) & PAGE_MASK)
46 #define VIA_PGOFF(x) (((unsigned long)(x)) & ~PAGE_MASK)
47 #define VIA_PFN(x) ((unsigned long)(x) >> PAGE_SHIFT)
74 if (descriptor_this_page-- == 0) {
75 cur_descriptor_page--;
77 desc_ptr = vsg->
desc_pages[cur_descriptor_page] +
95 via_map_blit_for_device(
struct pci_dev *pdev,
100 unsigned cur_descriptor_page = 0;
101 unsigned num_descriptors_this_page = 0;
102 unsigned char *mem_addr = xfer->
mem_addr;
103 unsigned char *cur_mem;
104 unsigned char *first_addr = (
unsigned char *)
VIA_PGDN(mem_addr);
107 unsigned long line_len;
108 unsigned remaining_len;
115 desc_ptr = vsg->
desc_pages[cur_descriptor_page];
123 while (line_len > 0) {
126 line_len -= remaining_len;
137 desc_ptr->
size = remaining_len;
143 num_descriptors_this_page = 0;
144 desc_ptr = vsg->
desc_pages[++cur_descriptor_page];
149 cur_mem += remaining_len;
150 cur_fb += remaining_len;
159 vsg->
state = dr_via_device_mapped;
177 switch (vsg->
state) {
178 case dr_via_device_mapped:
179 via_unmap_blit_from_device(pdev, vsg);
180 case dr_via_desc_pages_alloc:
186 case dr_via_pages_locked:
194 case dr_via_pages_alloc:
197 vsg->
state = dr_via_sg_init;
252 vsg->
state = dr_via_pages_locked;
255 vsg->
state = dr_via_pages_locked;
256 DRM_DEBUG(
"DMA pages locked\n");
278 vsg->
state = dr_via_desc_pages_alloc;
284 DRM_DEBUG(
"Allocated %d pages for %d descriptors.\n", vsg->
num_desc_pages,
290 via_abort_dmablit(
struct drm_device *dev,
int engine)
298 via_dmablit_engine_off(
struct drm_device *dev,
int engine)
321 unsigned long irqsave = 0;
324 DRM_DEBUG(
"DMA blit handler called. engine = %d, from_irq = %d, blitq = 0x%lx\n",
325 engine, from_irq, (
unsigned long) blitq);
328 spin_lock(&blitq->blit_lock);
332 done_transfer = blitq->is_active &&
339 blitq->blits[
cur]->aborted = blitq->aborting;
340 blitq->done_blit_handle++;
354 blitq->is_active = 0;
364 via_abort_dmablit(dev, engine);
369 if (!blitq->is_active) {
370 if (blitq->num_outstanding) {
371 via_fire_dmablit(dev, blitq->blits[
cur], engine);
372 blitq->is_active = 1;
374 blitq->num_outstanding--;
376 if (!timer_pending(&blitq->poll_timer))
379 if (timer_pending(&blitq->poll_timer))
381 via_dmablit_engine_off(dev, engine);
386 spin_unlock(&blitq->blit_lock);
388 spin_unlock_irqrestore(&blitq->blit_lock, irqsave);
400 unsigned long irqsave;
413 if (queue && active) {
420 spin_unlock_irqrestore(&blitq->
blit_lock, irqsave);
438 if (via_dmablit_active(blitq, engine, handle, &queue)) {
440 !via_dmablit_active(blitq, engine, handle,
NULL));
442 DRM_DEBUG(
"DMA blit sync handle 0x%x engine %d returned %d\n",
443 handle, engine, ret);
460 via_dmablit_timer(
unsigned long data)
467 DRM_DEBUG(
"Polling timer called for engine %d, jiffies %lu\n", engine,
468 (
unsigned long) jiffies);
500 unsigned long irqsave;
505 DRM_DEBUG(
"Workqueue task called for blit engine %ld\n", (
unsigned long)
514 DRM_DEBUG(
"Releasing blit slot %d\n", cur_released);
519 cur_sg = blitq->
blits[cur_released];
522 spin_unlock_irqrestore(&blitq->
blit_lock, irqsave);
526 via_free_sg_info(dev->pdev, cur_sg);
532 spin_unlock_irqrestore(&blitq->
blit_lock, irqsave);
568 (
unsigned long)blitq);
580 int draw = xfer->
to_fb;
586 vsg->
state = dr_via_sg_init;
589 DRM_ERROR(
"Zero size bitblt.\n");
601 DRM_ERROR(
"Too large system memory stride. Stride: %d, "
620 DRM_ERROR(
"Too large PCI DMA bitblt.\n");
631 DRM_ERROR(
"Invalid frame-buffer / memory stride.\n");
642 if ((((
unsigned long)xfer->
mem_addr & 3) != ((
unsigned long)xfer->
fb_addr & 3)) ||
644 DRM_ERROR(
"Invalid DRM bitblt alignment.\n");
648 if ((((
unsigned long)xfer->
mem_addr & 15) ||
649 ((
unsigned long)xfer->
fb_addr & 3)) ||
652 DRM_ERROR(
"Invalid DRM bitblt alignment.\n");
657 if (0 != (ret = via_lock_all_dma_pages(vsg, xfer))) {
658 DRM_ERROR(
"Could not lock DMA pages.\n");
659 via_free_sg_info(dev->pdev, vsg);
663 via_map_blit_for_device(dev->pdev, xfer, vsg, 0);
664 if (0 != (ret = via_alloc_desc_pages(vsg))) {
665 DRM_ERROR(
"Could not allocate DMA descriptor pages.\n");
666 via_free_sg_info(dev->pdev, vsg);
669 via_map_blit_for_device(dev->pdev, xfer, vsg, 1);
684 unsigned long irqsave;
686 DRM_DEBUG(
"Num free is %d\n", blitq->
num_free);
689 spin_unlock_irqrestore(&blitq->
blit_lock, irqsave);
699 spin_unlock_irqrestore(&blitq->
blit_lock, irqsave);
711 unsigned long irqsave;
715 spin_unlock_irqrestore(&blitq->
blit_lock, irqsave);
732 unsigned long irqsave;
735 DRM_ERROR(
"Called without initialization.\n");
739 engine = (xfer->
to_fb) ? 0 : 1;
741 if (0 != (ret = via_dmablit_grab_slot(blitq, engine)))
744 via_dmablit_release_slot(blitq);
747 if (0 != (ret = via_build_sg_info(dev, vsg, xfer))) {
748 via_dmablit_release_slot(blitq);
760 spin_unlock_irqrestore(&blitq->
blit_lock, irqsave);
805 err = via_dmablit(dev, xfer);