| .. | .. |
|---|
| 34 | 34 | * the same DMA mappings? |
|---|
| 35 | 35 | */ |
|---|
| 36 | 36 | |
|---|
| 37 | | -#include <drm/drmP.h> |
|---|
| 38 | | -#include <drm/via_drm.h> |
|---|
| 39 | | -#include "via_drv.h" |
|---|
| 40 | | -#include "via_dmablit.h" |
|---|
| 41 | | - |
|---|
| 42 | 37 | #include <linux/pagemap.h> |
|---|
| 38 | +#include <linux/pci.h> |
|---|
| 43 | 39 | #include <linux/slab.h> |
|---|
| 40 | +#include <linux/vmalloc.h> |
|---|
| 41 | + |
|---|
| 42 | +#include <drm/drm_device.h> |
|---|
| 43 | +#include <drm/via_drm.h> |
|---|
| 44 | + |
|---|
| 45 | +#include "via_dmablit.h" |
|---|
| 46 | +#include "via_drv.h" |
|---|
| 44 | 47 | |
|---|
| 45 | 48 | #define VIA_PGDN(x) (((unsigned long)(x)) & PAGE_MASK) |
|---|
| 46 | 49 | #define VIA_PGOFF(x) (((unsigned long)(x)) & ~PAGE_MASK) |
|---|
| .. | .. |
|---|
| 171 | 174 | static void |
|---|
| 172 | 175 | via_free_sg_info(struct pci_dev *pdev, drm_via_sg_info_t *vsg) |
|---|
| 173 | 176 | { |
|---|
| 174 | | - struct page *page; |
|---|
| 175 | 177 | int i; |
|---|
| 176 | 178 | |
|---|
| 177 | 179 | switch (vsg->state) { |
|---|
| 178 | 180 | case dr_via_device_mapped: |
|---|
| 179 | 181 | via_unmap_blit_from_device(pdev, vsg); |
|---|
| 182 | + fallthrough; |
|---|
| 180 | 183 | case dr_via_desc_pages_alloc: |
|---|
| 181 | 184 | for (i = 0; i < vsg->num_desc_pages; ++i) { |
|---|
| 182 | 185 | if (vsg->desc_pages[i] != NULL) |
|---|
| 183 | 186 | free_page((unsigned long)vsg->desc_pages[i]); |
|---|
| 184 | 187 | } |
|---|
| 185 | 188 | kfree(vsg->desc_pages); |
|---|
| 189 | + fallthrough; |
|---|
| 186 | 190 | case dr_via_pages_locked: |
|---|
| 187 | | - for (i = 0; i < vsg->num_pages; ++i) { |
|---|
| 188 | | - if (NULL != (page = vsg->pages[i])) { |
|---|
| 189 | | - if (!PageReserved(page) && (DMA_FROM_DEVICE == vsg->direction)) |
|---|
| 190 | | - SetPageDirty(page); |
|---|
| 191 | | - put_page(page); |
|---|
| 192 | | - } |
|---|
| 193 | | - } |
|---|
| 191 | + unpin_user_pages_dirty_lock(vsg->pages, vsg->num_pages, |
|---|
| 192 | + (vsg->direction == DMA_FROM_DEVICE)); |
|---|
| 193 | + fallthrough; |
|---|
| 194 | 194 | case dr_via_pages_alloc: |
|---|
| 195 | 195 | vfree(vsg->pages); |
|---|
| 196 | + fallthrough; |
|---|
| 196 | 197 | default: |
|---|
| 197 | 198 | vsg->state = dr_via_sg_init; |
|---|
| 198 | 199 | } |
|---|
| .. | .. |
|---|
| 210 | 211 | { |
|---|
| 211 | 212 | drm_via_private_t *dev_priv = (drm_via_private_t *)dev->dev_private; |
|---|
| 212 | 213 | |
|---|
| 213 | | - VIA_WRITE(VIA_PCI_DMA_MAR0 + engine*0x10, 0); |
|---|
| 214 | | - VIA_WRITE(VIA_PCI_DMA_DAR0 + engine*0x10, 0); |
|---|
| 215 | | - VIA_WRITE(VIA_PCI_DMA_CSR0 + engine*0x04, VIA_DMA_CSR_DD | VIA_DMA_CSR_TD | |
|---|
| 214 | + via_write(dev_priv, VIA_PCI_DMA_MAR0 + engine*0x10, 0); |
|---|
| 215 | + via_write(dev_priv, VIA_PCI_DMA_DAR0 + engine*0x10, 0); |
|---|
| 216 | + via_write(dev_priv, VIA_PCI_DMA_CSR0 + engine*0x04, VIA_DMA_CSR_DD | VIA_DMA_CSR_TD | |
|---|
| 216 | 217 | VIA_DMA_CSR_DE); |
|---|
| 217 | | - VIA_WRITE(VIA_PCI_DMA_MR0 + engine*0x04, VIA_DMA_MR_CM | VIA_DMA_MR_TDIE); |
|---|
| 218 | | - VIA_WRITE(VIA_PCI_DMA_BCR0 + engine*0x10, 0); |
|---|
| 219 | | - VIA_WRITE(VIA_PCI_DMA_DPR0 + engine*0x10, vsg->chain_start); |
|---|
| 218 | + via_write(dev_priv, VIA_PCI_DMA_MR0 + engine*0x04, VIA_DMA_MR_CM | VIA_DMA_MR_TDIE); |
|---|
| 219 | + via_write(dev_priv, VIA_PCI_DMA_BCR0 + engine*0x10, 0); |
|---|
| 220 | + via_write(dev_priv, VIA_PCI_DMA_DPR0 + engine*0x10, vsg->chain_start); |
|---|
| 220 | 221 | wmb(); |
|---|
| 221 | | - VIA_WRITE(VIA_PCI_DMA_CSR0 + engine*0x04, VIA_DMA_CSR_DE | VIA_DMA_CSR_TS); |
|---|
| 222 | | - VIA_READ(VIA_PCI_DMA_CSR0 + engine*0x04); |
|---|
| 222 | + via_write(dev_priv, VIA_PCI_DMA_CSR0 + engine*0x04, VIA_DMA_CSR_DE | VIA_DMA_CSR_TS); |
|---|
| 223 | + via_read(dev_priv, VIA_PCI_DMA_CSR0 + engine*0x04); |
|---|
| 223 | 224 | } |
|---|
| 224 | 225 | |
|---|
| 225 | 226 | /* |
|---|
| .. | .. |
|---|
| 238 | 239 | vsg->pages = vzalloc(array_size(sizeof(struct page *), vsg->num_pages)); |
|---|
| 239 | 240 | if (NULL == vsg->pages) |
|---|
| 240 | 241 | return -ENOMEM; |
|---|
| 241 | | - ret = get_user_pages_fast((unsigned long)xfer->mem_addr, |
|---|
| 242 | | - vsg->num_pages, vsg->direction == DMA_FROM_DEVICE, |
|---|
| 242 | + ret = pin_user_pages_fast((unsigned long)xfer->mem_addr, |
|---|
| 243 | + vsg->num_pages, |
|---|
| 244 | + vsg->direction == DMA_FROM_DEVICE ? FOLL_WRITE : 0, |
|---|
| 243 | 245 | vsg->pages); |
|---|
| 244 | 246 | if (ret != vsg->num_pages) { |
|---|
| 245 | 247 | if (ret < 0) |
|---|
| .. | .. |
|---|
| 286 | 288 | { |
|---|
| 287 | 289 | drm_via_private_t *dev_priv = (drm_via_private_t *)dev->dev_private; |
|---|
| 288 | 290 | |
|---|
| 289 | | - VIA_WRITE(VIA_PCI_DMA_CSR0 + engine*0x04, VIA_DMA_CSR_TA); |
|---|
| 291 | + via_write(dev_priv, VIA_PCI_DMA_CSR0 + engine*0x04, VIA_DMA_CSR_TA); |
|---|
| 290 | 292 | } |
|---|
| 291 | 293 | |
|---|
| 292 | 294 | static void |
|---|
| .. | .. |
|---|
| 294 | 296 | { |
|---|
| 295 | 297 | drm_via_private_t *dev_priv = (drm_via_private_t *)dev->dev_private; |
|---|
| 296 | 298 | |
|---|
| 297 | | - VIA_WRITE(VIA_PCI_DMA_CSR0 + engine*0x04, VIA_DMA_CSR_TD | VIA_DMA_CSR_DD); |
|---|
| 299 | + via_write(dev_priv, VIA_PCI_DMA_CSR0 + engine*0x04, VIA_DMA_CSR_TD | VIA_DMA_CSR_DD); |
|---|
| 298 | 300 | } |
|---|
| 299 | 301 | |
|---|
| 300 | 302 | |
|---|
| .. | .. |
|---|
| 325 | 327 | spin_lock_irqsave(&blitq->blit_lock, irqsave); |
|---|
| 326 | 328 | |
|---|
| 327 | 329 | done_transfer = blitq->is_active && |
|---|
| 328 | | - ((status = VIA_READ(VIA_PCI_DMA_CSR0 + engine*0x04)) & VIA_DMA_CSR_TD); |
|---|
| 330 | + ((status = via_read(dev_priv, VIA_PCI_DMA_CSR0 + engine*0x04)) & VIA_DMA_CSR_TD); |
|---|
| 329 | 331 | done_transfer = done_transfer || (blitq->aborting && !(status & VIA_DMA_CSR_DE)); |
|---|
| 330 | 332 | |
|---|
| 331 | 333 | cur = blitq->cur; |
|---|
| .. | .. |
|---|
| 344 | 346 | * Clear transfer done flag. |
|---|
| 345 | 347 | */ |
|---|
| 346 | 348 | |
|---|
| 347 | | - VIA_WRITE(VIA_PCI_DMA_CSR0 + engine*0x04, VIA_DMA_CSR_TD); |
|---|
| 349 | + via_write(dev_priv, VIA_PCI_DMA_CSR0 + engine*0x04, VIA_DMA_CSR_TD); |
|---|
| 348 | 350 | |
|---|
| 349 | 351 | blitq->is_active = 0; |
|---|
| 350 | 352 | blitq->aborting = 0; |
|---|
| .. | .. |
|---|
| 431 | 433 | int ret = 0; |
|---|
| 432 | 434 | |
|---|
| 433 | 435 | if (via_dmablit_active(blitq, engine, handle, &queue)) { |
|---|
| 434 | | - DRM_WAIT_ON(ret, *queue, 3 * HZ, |
|---|
| 436 | + VIA_WAIT_ON(ret, *queue, 3 * HZ, |
|---|
| 435 | 437 | !via_dmablit_active(blitq, engine, handle, NULL)); |
|---|
| 436 | 438 | } |
|---|
| 437 | 439 | DRM_DEBUG("DMA blit sync handle 0x%x engine %d returned %d\n", |
|---|
| .. | .. |
|---|
| 682 | 684 | while (blitq->num_free == 0) { |
|---|
| 683 | 685 | spin_unlock_irqrestore(&blitq->blit_lock, irqsave); |
|---|
| 684 | 686 | |
|---|
| 685 | | - DRM_WAIT_ON(ret, blitq->busy_queue, HZ, blitq->num_free > 0); |
|---|
| 687 | + VIA_WAIT_ON(ret, blitq->busy_queue, HZ, blitq->num_free > 0); |
|---|
| 686 | 688 | if (ret) |
|---|
| 687 | 689 | return (-EINTR == ret) ? -EAGAIN : ret; |
|---|
| 688 | 690 | |
|---|