2 * Copyright 2018 Red Hat Inc.
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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
22 #include "nouveau_dmem.h"
23 #include "nouveau_drv.h"
24 #include "nouveau_chan.h"
25 #include "nouveau_dma.h"
26 #include "nouveau_mem.h"
27 #include "nouveau_bo.h"
29 #include <nvif/class.h>
30 #include <nvif/object.h>
31 #include <nvif/if500b.h>
32 #include <nvif/if900b.h>
34 #include <linux/sched/mm.h>
35 #include <linux/hmm.h>
38 * FIXME: this is ugly right now we are using TTM to allocate vram and we pin
39 * it in vram while in use. We likely want to overhaul memory management for
40 * nouveau to be more page like (not necessarily with system page size but a
41 * bigger page size) at lowest level and have some shim layer on top that would
42 * provide the same functionality as TTM.
44 #define DMEM_CHUNK_SIZE (2UL << 20)
45 #define DMEM_CHUNK_NPAGES (DMEM_CHUNK_SIZE >> PAGE_SHIFT)
47 struct nouveau_migrate;
55 typedef int (*nouveau_migrate_copy_t)(struct nouveau_drm *drm, u64 npages,
56 enum nouveau_aper, u64 dst_addr,
57 enum nouveau_aper, u64 src_addr);
59 struct nouveau_dmem_chunk {
60 struct list_head list;
61 struct nouveau_bo *bo;
62 struct nouveau_drm *drm;
63 unsigned long pfn_first;
64 unsigned long callocated;
65 unsigned long bitmap[BITS_TO_LONGS(DMEM_CHUNK_NPAGES)];
69 struct nouveau_dmem_migrate {
70 nouveau_migrate_copy_t copy_func;
71 struct nouveau_channel *chan;
75 struct hmm_devmem *devmem;
76 struct nouveau_dmem_migrate migrate;
77 struct list_head chunk_free;
78 struct list_head chunk_full;
79 struct list_head chunk_empty;
83 struct nouveau_dmem_fault {
84 struct nouveau_drm *drm;
85 struct nouveau_fence *fence;
90 struct nouveau_migrate {
91 struct vm_area_struct *vma;
92 struct nouveau_drm *drm;
93 struct nouveau_fence *fence;
100 nouveau_dmem_free(struct hmm_devmem *devmem, struct page *page)
102 struct nouveau_dmem_chunk *chunk;
105 chunk = (void *)hmm_devmem_page_get_drvdata(page);
106 idx = page_to_pfn(page) - chunk->pfn_first;
111 * This is really a bad example, we need to overhaul nouveau memory
112 * management to be more page focus and allow lighter locking scheme
113 * to be use in the process.
115 spin_lock(&chunk->lock);
116 clear_bit(idx, chunk->bitmap);
117 WARN_ON(!chunk->callocated);
120 * FIXME when chunk->callocated reach 0 we should add the chunk to
121 * a reclaim list so that it can be freed in case of memory pressure.
123 spin_unlock(&chunk->lock);
127 nouveau_dmem_fault_alloc_and_copy(struct vm_area_struct *vma,
128 const unsigned long *src_pfns,
129 unsigned long *dst_pfns,
134 struct nouveau_dmem_fault *fault = private;
135 struct nouveau_drm *drm = fault->drm;
136 struct device *dev = drm->dev->dev;
137 unsigned long addr, i, npages = 0;
138 nouveau_migrate_copy_t copy;
142 /* First allocate new memory */
143 for (addr = start, i = 0; addr < end; addr += PAGE_SIZE, i++) {
144 struct page *dpage, *spage;
147 spage = migrate_pfn_to_page(src_pfns[i]);
148 if (!spage || !(src_pfns[i] & MIGRATE_PFN_MIGRATE))
151 dpage = hmm_vma_alloc_locked_page(vma, addr);
153 dst_pfns[i] = MIGRATE_PFN_ERROR;
157 dst_pfns[i] = migrate_pfn(page_to_pfn(dpage)) |
162 /* Allocate storage for DMA addresses, so we can unmap later. */
163 fault->dma = kmalloc(sizeof(*fault->dma) * npages, GFP_KERNEL);
167 /* Copy things over */
168 copy = drm->dmem->migrate.copy_func;
169 for (addr = start, i = 0; addr < end; addr += PAGE_SIZE, i++) {
170 struct nouveau_dmem_chunk *chunk;
171 struct page *spage, *dpage;
172 u64 src_addr, dst_addr;
174 dpage = migrate_pfn_to_page(dst_pfns[i]);
175 if (!dpage || dst_pfns[i] == MIGRATE_PFN_ERROR)
178 spage = migrate_pfn_to_page(src_pfns[i]);
179 if (!spage || !(src_pfns[i] & MIGRATE_PFN_MIGRATE)) {
180 dst_pfns[i] = MIGRATE_PFN_ERROR;
185 fault->dma[fault->npages] =
186 dma_map_page_attrs(dev, dpage, 0, PAGE_SIZE,
187 PCI_DMA_BIDIRECTIONAL,
188 DMA_ATTR_SKIP_CPU_SYNC);
189 if (dma_mapping_error(dev, fault->dma[fault->npages])) {
190 dst_pfns[i] = MIGRATE_PFN_ERROR;
195 dst_addr = fault->dma[fault->npages++];
197 chunk = (void *)hmm_devmem_page_get_drvdata(spage);
198 src_addr = page_to_pfn(spage) - chunk->pfn_first;
199 src_addr = (src_addr << PAGE_SHIFT) + chunk->bo->bo.offset;
201 ret = copy(drm, 1, NOUVEAU_APER_HOST, dst_addr,
202 NOUVEAU_APER_VRAM, src_addr);
204 dst_pfns[i] = MIGRATE_PFN_ERROR;
210 nouveau_fence_new(drm->dmem->migrate.chan, false, &fault->fence);
215 for (addr = start, i = 0; addr < end; addr += PAGE_SIZE, ++i) {
218 if (!dst_pfns[i] || dst_pfns[i] == MIGRATE_PFN_ERROR)
221 page = migrate_pfn_to_page(dst_pfns[i]);
222 dst_pfns[i] = MIGRATE_PFN_ERROR;
230 void nouveau_dmem_fault_finalize_and_map(struct vm_area_struct *vma,
231 const unsigned long *src_pfns,
232 const unsigned long *dst_pfns,
237 struct nouveau_dmem_fault *fault = private;
238 struct nouveau_drm *drm = fault->drm;
241 nouveau_fence_wait(fault->fence, true, false);
242 nouveau_fence_unref(&fault->fence);
245 * FIXME wait for channel to be IDLE before calling finalizing
246 * the hmem object below (nouveau_migrate_hmem_fini()).
250 while (fault->npages--) {
251 dma_unmap_page(drm->dev->dev, fault->dma[fault->npages],
252 PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
257 static const struct migrate_vma_ops nouveau_dmem_fault_migrate_ops = {
258 .alloc_and_copy = nouveau_dmem_fault_alloc_and_copy,
259 .finalize_and_map = nouveau_dmem_fault_finalize_and_map,
263 nouveau_dmem_fault(struct hmm_devmem *devmem,
264 struct vm_area_struct *vma,
266 const struct page *page,
270 struct drm_device *drm_dev = dev_get_drvdata(devmem->device);
271 unsigned long src[1] = {0}, dst[1] = {0};
272 struct nouveau_dmem_fault fault = {0};
278 * FIXME what we really want is to find some heuristic to migrate more
279 * than just one page on CPU fault. When such fault happens it is very
280 * likely that more surrounding page will CPU fault too.
282 fault.drm = nouveau_drm(drm_dev);
283 ret = migrate_vma(&nouveau_dmem_fault_migrate_ops, vma, addr,
284 addr + PAGE_SIZE, src, dst, &fault);
286 return VM_FAULT_SIGBUS;
288 if (dst[0] == MIGRATE_PFN_ERROR)
289 return VM_FAULT_SIGBUS;
294 static const struct hmm_devmem_ops
295 nouveau_dmem_devmem_ops = {
296 .free = nouveau_dmem_free,
297 .fault = nouveau_dmem_fault,
301 nouveau_dmem_chunk_alloc(struct nouveau_drm *drm)
303 struct nouveau_dmem_chunk *chunk;
306 if (drm->dmem == NULL)
309 mutex_lock(&drm->dmem->mutex);
310 chunk = list_first_entry_or_null(&drm->dmem->chunk_empty,
311 struct nouveau_dmem_chunk,
314 mutex_unlock(&drm->dmem->mutex);
318 list_del(&chunk->list);
319 mutex_unlock(&drm->dmem->mutex);
321 ret = nouveau_bo_new(&drm->client, DMEM_CHUNK_SIZE, 0,
322 TTM_PL_FLAG_VRAM, 0, 0, NULL, NULL,
327 ret = nouveau_bo_pin(chunk->bo, TTM_PL_FLAG_VRAM, false);
329 nouveau_bo_ref(NULL, &chunk->bo);
333 bitmap_zero(chunk->bitmap, DMEM_CHUNK_NPAGES);
334 spin_lock_init(&chunk->lock);
337 mutex_lock(&drm->dmem->mutex);
339 list_add(&chunk->list, &drm->dmem->chunk_empty);
341 list_add_tail(&chunk->list, &drm->dmem->chunk_empty);
342 mutex_unlock(&drm->dmem->mutex);
347 static struct nouveau_dmem_chunk *
348 nouveau_dmem_chunk_first_free_locked(struct nouveau_drm *drm)
350 struct nouveau_dmem_chunk *chunk;
352 chunk = list_first_entry_or_null(&drm->dmem->chunk_free,
353 struct nouveau_dmem_chunk,
358 chunk = list_first_entry_or_null(&drm->dmem->chunk_empty,
359 struct nouveau_dmem_chunk,
368 nouveau_dmem_pages_alloc(struct nouveau_drm *drm,
369 unsigned long npages,
370 unsigned long *pages)
372 struct nouveau_dmem_chunk *chunk;
376 memset(pages, 0xff, npages * sizeof(*pages));
378 mutex_lock(&drm->dmem->mutex);
379 for (c = 0; c < npages;) {
382 chunk = nouveau_dmem_chunk_first_free_locked(drm);
384 mutex_unlock(&drm->dmem->mutex);
385 ret = nouveau_dmem_chunk_alloc(drm);
394 spin_lock(&chunk->lock);
395 i = find_first_zero_bit(chunk->bitmap, DMEM_CHUNK_NPAGES);
396 while (i < DMEM_CHUNK_NPAGES && c < npages) {
397 pages[c] = chunk->pfn_first + i;
398 set_bit(i, chunk->bitmap);
402 i = find_next_zero_bit(chunk->bitmap,
403 DMEM_CHUNK_NPAGES, i);
405 spin_unlock(&chunk->lock);
407 mutex_unlock(&drm->dmem->mutex);
413 nouveau_dmem_page_alloc_locked(struct nouveau_drm *drm)
415 unsigned long pfns[1];
419 /* FIXME stop all the miss-match API ... */
420 ret = nouveau_dmem_pages_alloc(drm, 1, pfns);
424 page = pfn_to_page(pfns[0]);
431 nouveau_dmem_page_free_locked(struct nouveau_drm *drm, struct page *page)
438 nouveau_dmem_resume(struct nouveau_drm *drm)
440 struct nouveau_dmem_chunk *chunk;
443 if (drm->dmem == NULL)
446 mutex_lock(&drm->dmem->mutex);
447 list_for_each_entry (chunk, &drm->dmem->chunk_free, list) {
448 ret = nouveau_bo_pin(chunk->bo, TTM_PL_FLAG_VRAM, false);
449 /* FIXME handle pin failure */
452 list_for_each_entry (chunk, &drm->dmem->chunk_full, list) {
453 ret = nouveau_bo_pin(chunk->bo, TTM_PL_FLAG_VRAM, false);
454 /* FIXME handle pin failure */
457 mutex_unlock(&drm->dmem->mutex);
461 nouveau_dmem_suspend(struct nouveau_drm *drm)
463 struct nouveau_dmem_chunk *chunk;
465 if (drm->dmem == NULL)
468 mutex_lock(&drm->dmem->mutex);
469 list_for_each_entry (chunk, &drm->dmem->chunk_free, list) {
470 nouveau_bo_unpin(chunk->bo);
472 list_for_each_entry (chunk, &drm->dmem->chunk_full, list) {
473 nouveau_bo_unpin(chunk->bo);
475 mutex_unlock(&drm->dmem->mutex);
479 nouveau_dmem_fini(struct nouveau_drm *drm)
481 struct nouveau_dmem_chunk *chunk, *tmp;
483 if (drm->dmem == NULL)
486 mutex_lock(&drm->dmem->mutex);
488 WARN_ON(!list_empty(&drm->dmem->chunk_free));
489 WARN_ON(!list_empty(&drm->dmem->chunk_full));
491 list_for_each_entry_safe (chunk, tmp, &drm->dmem->chunk_empty, list) {
493 nouveau_bo_unpin(chunk->bo);
494 nouveau_bo_ref(NULL, &chunk->bo);
496 list_del(&chunk->list);
500 mutex_unlock(&drm->dmem->mutex);
504 nvc0b5_migrate_copy(struct nouveau_drm *drm, u64 npages,
505 enum nouveau_aper dst_aper, u64 dst_addr,
506 enum nouveau_aper src_aper, u64 src_addr)
508 struct nouveau_channel *chan = drm->dmem->migrate.chan;
509 u32 launch_dma = (1 << 9) /* MULTI_LINE_ENABLE. */ |
510 (1 << 8) /* DST_MEMORY_LAYOUT_PITCH. */ |
511 (1 << 7) /* SRC_MEMORY_LAYOUT_PITCH. */ |
512 (1 << 2) /* FLUSH_ENABLE_TRUE. */ |
513 (2 << 0) /* DATA_TRANSFER_TYPE_NON_PIPELINED. */;
516 ret = RING_SPACE(chan, 13);
520 if (src_aper != NOUVEAU_APER_VIRT) {
522 case NOUVEAU_APER_VRAM:
523 BEGIN_IMC0(chan, NvSubCopy, 0x0260, 0);
525 case NOUVEAU_APER_HOST:
526 BEGIN_IMC0(chan, NvSubCopy, 0x0260, 1);
531 launch_dma |= 0x00001000; /* SRC_TYPE_PHYSICAL. */
534 if (dst_aper != NOUVEAU_APER_VIRT) {
536 case NOUVEAU_APER_VRAM:
537 BEGIN_IMC0(chan, NvSubCopy, 0x0264, 0);
539 case NOUVEAU_APER_HOST:
540 BEGIN_IMC0(chan, NvSubCopy, 0x0264, 1);
545 launch_dma |= 0x00002000; /* DST_TYPE_PHYSICAL. */
548 BEGIN_NVC0(chan, NvSubCopy, 0x0400, 8);
549 OUT_RING (chan, upper_32_bits(src_addr));
550 OUT_RING (chan, lower_32_bits(src_addr));
551 OUT_RING (chan, upper_32_bits(dst_addr));
552 OUT_RING (chan, lower_32_bits(dst_addr));
553 OUT_RING (chan, PAGE_SIZE);
554 OUT_RING (chan, PAGE_SIZE);
555 OUT_RING (chan, PAGE_SIZE);
556 OUT_RING (chan, npages);
557 BEGIN_NVC0(chan, NvSubCopy, 0x0300, 1);
558 OUT_RING (chan, launch_dma);
563 nouveau_dmem_migrate_init(struct nouveau_drm *drm)
565 switch (drm->ttm.copy.oclass) {
566 case PASCAL_DMA_COPY_A:
567 case PASCAL_DMA_COPY_B:
568 case VOLTA_DMA_COPY_A:
569 case TURING_DMA_COPY_A:
570 drm->dmem->migrate.copy_func = nvc0b5_migrate_copy;
571 drm->dmem->migrate.chan = drm->ttm.chan;
580 nouveau_dmem_init(struct nouveau_drm *drm)
582 struct device *device = drm->dev->dev;
583 unsigned long i, size;
586 /* This only make sense on PASCAL or newer */
587 if (drm->client.device.info.family < NV_DEVICE_INFO_V0_PASCAL)
590 if (!(drm->dmem = kzalloc(sizeof(*drm->dmem), GFP_KERNEL)))
593 mutex_init(&drm->dmem->mutex);
594 INIT_LIST_HEAD(&drm->dmem->chunk_free);
595 INIT_LIST_HEAD(&drm->dmem->chunk_full);
596 INIT_LIST_HEAD(&drm->dmem->chunk_empty);
598 size = ALIGN(drm->client.device.info.ram_user, DMEM_CHUNK_SIZE);
600 /* Initialize migration dma helpers before registering memory */
601 ret = nouveau_dmem_migrate_init(drm);
609 * FIXME we need some kind of policy to decide how much VRAM we
610 * want to register with HMM. For now just register everything
611 * and latter if we want to do thing like over commit then we
612 * could revisit this.
614 drm->dmem->devmem = hmm_devmem_add(&nouveau_dmem_devmem_ops,
616 if (IS_ERR(drm->dmem->devmem)) {
622 for (i = 0; i < (size / DMEM_CHUNK_SIZE); ++i) {
623 struct nouveau_dmem_chunk *chunk;
627 chunk = kzalloc(sizeof(*chunk), GFP_KERNEL);
629 nouveau_dmem_fini(drm);
634 chunk->pfn_first = drm->dmem->devmem->pfn_first;
635 chunk->pfn_first += (i * DMEM_CHUNK_NPAGES);
636 list_add_tail(&chunk->list, &drm->dmem->chunk_empty);
638 page = pfn_to_page(chunk->pfn_first);
639 for (j = 0; j < DMEM_CHUNK_NPAGES; ++j, ++page) {
640 hmm_devmem_page_set_drvdata(page, (long)chunk);
644 NV_INFO(drm, "DMEM: registered %ldMB of device memory\n", size >> 20);
648 nouveau_dmem_migrate_alloc_and_copy(struct vm_area_struct *vma,
649 const unsigned long *src_pfns,
650 unsigned long *dst_pfns,
655 struct nouveau_migrate *migrate = private;
656 struct nouveau_drm *drm = migrate->drm;
657 struct device *dev = drm->dev->dev;
658 unsigned long addr, i, npages = 0;
659 nouveau_migrate_copy_t copy;
662 /* First allocate new memory */
663 for (addr = start, i = 0; addr < end; addr += PAGE_SIZE, i++) {
664 struct page *dpage, *spage;
667 spage = migrate_pfn_to_page(src_pfns[i]);
668 if (!spage || !(src_pfns[i] & MIGRATE_PFN_MIGRATE))
671 dpage = nouveau_dmem_page_alloc_locked(drm);
675 dst_pfns[i] = migrate_pfn(page_to_pfn(dpage)) |
684 /* Allocate storage for DMA addresses, so we can unmap later. */
685 migrate->dma = kmalloc(sizeof(*migrate->dma) * npages, GFP_KERNEL);
689 /* Copy things over */
690 copy = drm->dmem->migrate.copy_func;
691 for (addr = start, i = 0; addr < end; addr += PAGE_SIZE, i++) {
692 struct nouveau_dmem_chunk *chunk;
693 struct page *spage, *dpage;
694 u64 src_addr, dst_addr;
696 dpage = migrate_pfn_to_page(dst_pfns[i]);
697 if (!dpage || dst_pfns[i] == MIGRATE_PFN_ERROR)
700 chunk = (void *)hmm_devmem_page_get_drvdata(dpage);
701 dst_addr = page_to_pfn(dpage) - chunk->pfn_first;
702 dst_addr = (dst_addr << PAGE_SHIFT) + chunk->bo->bo.offset;
704 spage = migrate_pfn_to_page(src_pfns[i]);
705 if (!spage || !(src_pfns[i] & MIGRATE_PFN_MIGRATE)) {
706 nouveau_dmem_page_free_locked(drm, dpage);
711 migrate->dma[migrate->dma_nr] =
712 dma_map_page_attrs(dev, spage, 0, PAGE_SIZE,
713 PCI_DMA_BIDIRECTIONAL,
714 DMA_ATTR_SKIP_CPU_SYNC);
715 if (dma_mapping_error(dev, migrate->dma[migrate->dma_nr])) {
716 nouveau_dmem_page_free_locked(drm, dpage);
721 src_addr = migrate->dma[migrate->dma_nr++];
723 ret = copy(drm, 1, NOUVEAU_APER_VRAM, dst_addr,
724 NOUVEAU_APER_HOST, src_addr);
726 nouveau_dmem_page_free_locked(drm, dpage);
732 nouveau_fence_new(drm->dmem->migrate.chan, false, &migrate->fence);
737 for (addr = start, i = 0; addr < end; addr += PAGE_SIZE, ++i) {
740 if (!dst_pfns[i] || dst_pfns[i] == MIGRATE_PFN_ERROR)
743 page = migrate_pfn_to_page(dst_pfns[i]);
744 dst_pfns[i] = MIGRATE_PFN_ERROR;
752 void nouveau_dmem_migrate_finalize_and_map(struct vm_area_struct *vma,
753 const unsigned long *src_pfns,
754 const unsigned long *dst_pfns,
759 struct nouveau_migrate *migrate = private;
760 struct nouveau_drm *drm = migrate->drm;
762 if (migrate->fence) {
763 nouveau_fence_wait(migrate->fence, true, false);
764 nouveau_fence_unref(&migrate->fence);
767 * FIXME wait for channel to be IDLE before finalizing
768 * the hmem object below (nouveau_migrate_hmem_fini()) ?
772 while (migrate->dma_nr--) {
773 dma_unmap_page(drm->dev->dev, migrate->dma[migrate->dma_nr],
774 PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
779 * FIXME optimization: update GPU page table to point to newly
784 static const struct migrate_vma_ops nouveau_dmem_migrate_ops = {
785 .alloc_and_copy = nouveau_dmem_migrate_alloc_and_copy,
786 .finalize_and_map = nouveau_dmem_migrate_finalize_and_map,
790 nouveau_dmem_migrate_vma(struct nouveau_drm *drm,
791 struct vm_area_struct *vma,
795 unsigned long *src_pfns, *dst_pfns, npages;
796 struct nouveau_migrate migrate = {0};
797 unsigned long i, c, max;
800 npages = (end - start) >> PAGE_SHIFT;
801 max = min(SG_MAX_SINGLE_ALLOC, npages);
802 src_pfns = kzalloc(sizeof(long) * max, GFP_KERNEL);
803 if (src_pfns == NULL)
805 dst_pfns = kzalloc(sizeof(long) * max, GFP_KERNEL);
806 if (dst_pfns == NULL) {
813 migrate.npages = npages;
814 for (i = 0; i < npages; i += c) {
817 c = min(SG_MAX_SINGLE_ALLOC, npages);
818 next = start + (c << PAGE_SHIFT);
819 ret = migrate_vma(&nouveau_dmem_migrate_ops, vma, start,
820 next, src_pfns, dst_pfns, &migrate);
833 nouveau_dmem_page(struct nouveau_drm *drm, struct page *page)
835 if (!is_device_private_page(page))
838 if (drm->dmem->devmem != page->pgmap->data)
845 nouveau_dmem_convert_pfn(struct nouveau_drm *drm,
846 struct hmm_range *range)
848 unsigned long i, npages;
850 npages = (range->end - range->start) >> PAGE_SHIFT;
851 for (i = 0; i < npages; ++i) {
852 struct nouveau_dmem_chunk *chunk;
856 page = hmm_pfn_to_page(range, range->pfns[i]);
860 if (!(range->pfns[i] & range->flags[HMM_PFN_DEVICE_PRIVATE])) {
864 if (!nouveau_dmem_page(drm, page)) {
865 WARN(1, "Some unknown device memory !\n");
870 chunk = (void *)hmm_devmem_page_get_drvdata(page);
871 addr = page_to_pfn(page) - chunk->pfn_first;
872 addr = (addr + chunk->bo->bo.mem.start) << PAGE_SHIFT;
874 range->pfns[i] &= ((1UL << range->pfn_shift) - 1);
875 range->pfns[i] |= (addr >> PAGE_SHIFT) << range->pfn_shift;