Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / gpu / drm / gma500 / mmu.c
blob505044c9a6732483411d4d03a8afe9fab7cb7db4
1 // SPDX-License-Identifier: GPL-2.0-only
2 /**************************************************************************
3 * Copyright (c) 2007, Intel Corporation.
5 **************************************************************************/
7 #include <linux/highmem.h>
9 #include "mmu.h"
10 #include "psb_drv.h"
11 #include "psb_reg.h"
14 * Code for the SGX MMU:
18 * clflush on one processor only:
19 * clflush should apparently flush the cache line on all processors in an
20 * SMP system.
24 * kmap atomic:
25 * The usage of the slots must be completely encapsulated within a spinlock, and
26 * no other functions that may be using the locks for other purposed may be
27 * called from within the locked region.
28 * Since the slots are per processor, this will guarantee that we are the only
29 * user.
33 * TODO: Inserting ptes from an interrupt handler:
34 * This may be desirable for some SGX functionality where the GPU can fault in
35 * needed pages. For that, we need to make an atomic insert_pages function, that
36 * may fail.
37 * If it fails, the caller need to insert the page using a workqueue function,
38 * but on average it should be fast.
41 static inline uint32_t psb_mmu_pt_index(uint32_t offset)
43 return (offset >> PSB_PTE_SHIFT) & 0x3FF;
46 static inline uint32_t psb_mmu_pd_index(uint32_t offset)
48 return offset >> PSB_PDE_SHIFT;
51 #if defined(CONFIG_X86)
52 static inline void psb_clflush(void *addr)
54 __asm__ __volatile__("clflush (%0)\n" : : "r"(addr) : "memory");
57 static inline void psb_mmu_clflush(struct psb_mmu_driver *driver, void *addr)
59 if (!driver->has_clflush)
60 return;
62 mb();
63 psb_clflush(addr);
64 mb();
66 #else
68 static inline void psb_mmu_clflush(struct psb_mmu_driver *driver, void *addr)
72 #endif
74 static void psb_mmu_flush_pd_locked(struct psb_mmu_driver *driver, int force)
76 struct drm_device *dev = driver->dev;
77 struct drm_psb_private *dev_priv = dev->dev_private;
79 if (atomic_read(&driver->needs_tlbflush) || force) {
80 uint32_t val = PSB_RSGX32(PSB_CR_BIF_CTRL);
81 PSB_WSGX32(val | _PSB_CB_CTRL_INVALDC, PSB_CR_BIF_CTRL);
83 /* Make sure data cache is turned off before enabling it */
84 wmb();
85 PSB_WSGX32(val & ~_PSB_CB_CTRL_INVALDC, PSB_CR_BIF_CTRL);
86 (void)PSB_RSGX32(PSB_CR_BIF_CTRL);
87 if (driver->msvdx_mmu_invaldc)
88 atomic_set(driver->msvdx_mmu_invaldc, 1);
90 atomic_set(&driver->needs_tlbflush, 0);
93 #if 0
94 static void psb_mmu_flush_pd(struct psb_mmu_driver *driver, int force)
96 down_write(&driver->sem);
97 psb_mmu_flush_pd_locked(driver, force);
98 up_write(&driver->sem);
100 #endif
102 void psb_mmu_flush(struct psb_mmu_driver *driver)
104 struct drm_device *dev = driver->dev;
105 struct drm_psb_private *dev_priv = dev->dev_private;
106 uint32_t val;
108 down_write(&driver->sem);
109 val = PSB_RSGX32(PSB_CR_BIF_CTRL);
110 if (atomic_read(&driver->needs_tlbflush))
111 PSB_WSGX32(val | _PSB_CB_CTRL_INVALDC, PSB_CR_BIF_CTRL);
112 else
113 PSB_WSGX32(val | _PSB_CB_CTRL_FLUSH, PSB_CR_BIF_CTRL);
115 /* Make sure data cache is turned off and MMU is flushed before
116 restoring bank interface control register */
117 wmb();
118 PSB_WSGX32(val & ~(_PSB_CB_CTRL_FLUSH | _PSB_CB_CTRL_INVALDC),
119 PSB_CR_BIF_CTRL);
120 (void)PSB_RSGX32(PSB_CR_BIF_CTRL);
122 atomic_set(&driver->needs_tlbflush, 0);
123 if (driver->msvdx_mmu_invaldc)
124 atomic_set(driver->msvdx_mmu_invaldc, 1);
125 up_write(&driver->sem);
128 void psb_mmu_set_pd_context(struct psb_mmu_pd *pd, int hw_context)
130 struct drm_device *dev = pd->driver->dev;
131 struct drm_psb_private *dev_priv = dev->dev_private;
132 uint32_t offset = (hw_context == 0) ? PSB_CR_BIF_DIR_LIST_BASE0 :
133 PSB_CR_BIF_DIR_LIST_BASE1 + hw_context * 4;
135 down_write(&pd->driver->sem);
136 PSB_WSGX32(page_to_pfn(pd->p) << PAGE_SHIFT, offset);
137 wmb();
138 psb_mmu_flush_pd_locked(pd->driver, 1);
139 pd->hw_context = hw_context;
140 up_write(&pd->driver->sem);
144 static inline unsigned long psb_pd_addr_end(unsigned long addr,
145 unsigned long end)
147 addr = (addr + PSB_PDE_MASK + 1) & ~PSB_PDE_MASK;
148 return (addr < end) ? addr : end;
151 static inline uint32_t psb_mmu_mask_pte(uint32_t pfn, int type)
153 uint32_t mask = PSB_PTE_VALID;
155 if (type & PSB_MMU_CACHED_MEMORY)
156 mask |= PSB_PTE_CACHED;
157 if (type & PSB_MMU_RO_MEMORY)
158 mask |= PSB_PTE_RO;
159 if (type & PSB_MMU_WO_MEMORY)
160 mask |= PSB_PTE_WO;
162 return (pfn << PAGE_SHIFT) | mask;
165 struct psb_mmu_pd *psb_mmu_alloc_pd(struct psb_mmu_driver *driver,
166 int trap_pagefaults, int invalid_type)
168 struct psb_mmu_pd *pd = kmalloc(sizeof(*pd), GFP_KERNEL);
169 uint32_t *v;
170 int i;
172 if (!pd)
173 return NULL;
175 pd->p = alloc_page(GFP_DMA32);
176 if (!pd->p)
177 goto out_err1;
178 pd->dummy_pt = alloc_page(GFP_DMA32);
179 if (!pd->dummy_pt)
180 goto out_err2;
181 pd->dummy_page = alloc_page(GFP_DMA32);
182 if (!pd->dummy_page)
183 goto out_err3;
185 if (!trap_pagefaults) {
186 pd->invalid_pde = psb_mmu_mask_pte(page_to_pfn(pd->dummy_pt),
187 invalid_type);
188 pd->invalid_pte = psb_mmu_mask_pte(page_to_pfn(pd->dummy_page),
189 invalid_type);
190 } else {
191 pd->invalid_pde = 0;
192 pd->invalid_pte = 0;
195 v = kmap(pd->dummy_pt);
196 for (i = 0; i < (PAGE_SIZE / sizeof(uint32_t)); ++i)
197 v[i] = pd->invalid_pte;
199 kunmap(pd->dummy_pt);
201 v = kmap(pd->p);
202 for (i = 0; i < (PAGE_SIZE / sizeof(uint32_t)); ++i)
203 v[i] = pd->invalid_pde;
205 kunmap(pd->p);
207 clear_page(kmap(pd->dummy_page));
208 kunmap(pd->dummy_page);
210 pd->tables = vmalloc_user(sizeof(struct psb_mmu_pt *) * 1024);
211 if (!pd->tables)
212 goto out_err4;
214 pd->hw_context = -1;
215 pd->pd_mask = PSB_PTE_VALID;
216 pd->driver = driver;
218 return pd;
220 out_err4:
221 __free_page(pd->dummy_page);
222 out_err3:
223 __free_page(pd->dummy_pt);
224 out_err2:
225 __free_page(pd->p);
226 out_err1:
227 kfree(pd);
228 return NULL;
231 static void psb_mmu_free_pt(struct psb_mmu_pt *pt)
233 __free_page(pt->p);
234 kfree(pt);
237 void psb_mmu_free_pagedir(struct psb_mmu_pd *pd)
239 struct psb_mmu_driver *driver = pd->driver;
240 struct drm_device *dev = driver->dev;
241 struct drm_psb_private *dev_priv = dev->dev_private;
242 struct psb_mmu_pt *pt;
243 int i;
245 down_write(&driver->sem);
246 if (pd->hw_context != -1) {
247 PSB_WSGX32(0, PSB_CR_BIF_DIR_LIST_BASE0 + pd->hw_context * 4);
248 psb_mmu_flush_pd_locked(driver, 1);
251 /* Should take the spinlock here, but we don't need to do that
252 since we have the semaphore in write mode. */
254 for (i = 0; i < 1024; ++i) {
255 pt = pd->tables[i];
256 if (pt)
257 psb_mmu_free_pt(pt);
260 vfree(pd->tables);
261 __free_page(pd->dummy_page);
262 __free_page(pd->dummy_pt);
263 __free_page(pd->p);
264 kfree(pd);
265 up_write(&driver->sem);
268 static struct psb_mmu_pt *psb_mmu_alloc_pt(struct psb_mmu_pd *pd)
270 struct psb_mmu_pt *pt = kmalloc(sizeof(*pt), GFP_KERNEL);
271 void *v;
272 uint32_t clflush_add = pd->driver->clflush_add >> PAGE_SHIFT;
273 uint32_t clflush_count = PAGE_SIZE / clflush_add;
274 spinlock_t *lock = &pd->driver->lock;
275 uint8_t *clf;
276 uint32_t *ptes;
277 int i;
279 if (!pt)
280 return NULL;
282 pt->p = alloc_page(GFP_DMA32);
283 if (!pt->p) {
284 kfree(pt);
285 return NULL;
288 spin_lock(lock);
290 v = kmap_atomic(pt->p);
291 clf = (uint8_t *) v;
292 ptes = (uint32_t *) v;
293 for (i = 0; i < (PAGE_SIZE / sizeof(uint32_t)); ++i)
294 *ptes++ = pd->invalid_pte;
296 #if defined(CONFIG_X86)
297 if (pd->driver->has_clflush && pd->hw_context != -1) {
298 mb();
299 for (i = 0; i < clflush_count; ++i) {
300 psb_clflush(clf);
301 clf += clflush_add;
303 mb();
305 #endif
306 kunmap_atomic(v);
307 spin_unlock(lock);
309 pt->count = 0;
310 pt->pd = pd;
311 pt->index = 0;
313 return pt;
316 struct psb_mmu_pt *psb_mmu_pt_alloc_map_lock(struct psb_mmu_pd *pd,
317 unsigned long addr)
319 uint32_t index = psb_mmu_pd_index(addr);
320 struct psb_mmu_pt *pt;
321 uint32_t *v;
322 spinlock_t *lock = &pd->driver->lock;
324 spin_lock(lock);
325 pt = pd->tables[index];
326 while (!pt) {
327 spin_unlock(lock);
328 pt = psb_mmu_alloc_pt(pd);
329 if (!pt)
330 return NULL;
331 spin_lock(lock);
333 if (pd->tables[index]) {
334 spin_unlock(lock);
335 psb_mmu_free_pt(pt);
336 spin_lock(lock);
337 pt = pd->tables[index];
338 continue;
341 v = kmap_atomic(pd->p);
342 pd->tables[index] = pt;
343 v[index] = (page_to_pfn(pt->p) << 12) | pd->pd_mask;
344 pt->index = index;
345 kunmap_atomic((void *) v);
347 if (pd->hw_context != -1) {
348 psb_mmu_clflush(pd->driver, (void *)&v[index]);
349 atomic_set(&pd->driver->needs_tlbflush, 1);
352 pt->v = kmap_atomic(pt->p);
353 return pt;
356 static struct psb_mmu_pt *psb_mmu_pt_map_lock(struct psb_mmu_pd *pd,
357 unsigned long addr)
359 uint32_t index = psb_mmu_pd_index(addr);
360 struct psb_mmu_pt *pt;
361 spinlock_t *lock = &pd->driver->lock;
363 spin_lock(lock);
364 pt = pd->tables[index];
365 if (!pt) {
366 spin_unlock(lock);
367 return NULL;
369 pt->v = kmap_atomic(pt->p);
370 return pt;
373 static void psb_mmu_pt_unmap_unlock(struct psb_mmu_pt *pt)
375 struct psb_mmu_pd *pd = pt->pd;
376 uint32_t *v;
378 kunmap_atomic(pt->v);
379 if (pt->count == 0) {
380 v = kmap_atomic(pd->p);
381 v[pt->index] = pd->invalid_pde;
382 pd->tables[pt->index] = NULL;
384 if (pd->hw_context != -1) {
385 psb_mmu_clflush(pd->driver, (void *)&v[pt->index]);
386 atomic_set(&pd->driver->needs_tlbflush, 1);
388 kunmap_atomic(v);
389 spin_unlock(&pd->driver->lock);
390 psb_mmu_free_pt(pt);
391 return;
393 spin_unlock(&pd->driver->lock);
396 static inline void psb_mmu_set_pte(struct psb_mmu_pt *pt, unsigned long addr,
397 uint32_t pte)
399 pt->v[psb_mmu_pt_index(addr)] = pte;
402 static inline void psb_mmu_invalidate_pte(struct psb_mmu_pt *pt,
403 unsigned long addr)
405 pt->v[psb_mmu_pt_index(addr)] = pt->pd->invalid_pte;
408 struct psb_mmu_pd *psb_mmu_get_default_pd(struct psb_mmu_driver *driver)
410 struct psb_mmu_pd *pd;
412 down_read(&driver->sem);
413 pd = driver->default_pd;
414 up_read(&driver->sem);
416 return pd;
419 /* Returns the physical address of the PD shared by sgx/msvdx */
420 uint32_t psb_get_default_pd_addr(struct psb_mmu_driver *driver)
422 struct psb_mmu_pd *pd;
424 pd = psb_mmu_get_default_pd(driver);
425 return page_to_pfn(pd->p) << PAGE_SHIFT;
428 void psb_mmu_driver_takedown(struct psb_mmu_driver *driver)
430 struct drm_device *dev = driver->dev;
431 struct drm_psb_private *dev_priv = dev->dev_private;
433 PSB_WSGX32(driver->bif_ctrl, PSB_CR_BIF_CTRL);
434 psb_mmu_free_pagedir(driver->default_pd);
435 kfree(driver);
438 struct psb_mmu_driver *psb_mmu_driver_init(struct drm_device *dev,
439 int trap_pagefaults,
440 int invalid_type,
441 atomic_t *msvdx_mmu_invaldc)
443 struct psb_mmu_driver *driver;
444 struct drm_psb_private *dev_priv = dev->dev_private;
446 driver = kmalloc(sizeof(*driver), GFP_KERNEL);
448 if (!driver)
449 return NULL;
451 driver->dev = dev;
452 driver->default_pd = psb_mmu_alloc_pd(driver, trap_pagefaults,
453 invalid_type);
454 if (!driver->default_pd)
455 goto out_err1;
457 spin_lock_init(&driver->lock);
458 init_rwsem(&driver->sem);
459 down_write(&driver->sem);
460 atomic_set(&driver->needs_tlbflush, 1);
461 driver->msvdx_mmu_invaldc = msvdx_mmu_invaldc;
463 driver->bif_ctrl = PSB_RSGX32(PSB_CR_BIF_CTRL);
464 PSB_WSGX32(driver->bif_ctrl | _PSB_CB_CTRL_CLEAR_FAULT,
465 PSB_CR_BIF_CTRL);
466 PSB_WSGX32(driver->bif_ctrl & ~_PSB_CB_CTRL_CLEAR_FAULT,
467 PSB_CR_BIF_CTRL);
469 driver->has_clflush = 0;
471 #if defined(CONFIG_X86)
472 if (boot_cpu_has(X86_FEATURE_CLFLUSH)) {
473 uint32_t tfms, misc, cap0, cap4, clflush_size;
476 * clflush size is determined at kernel setup for x86_64 but not
477 * for i386. We have to do it here.
480 cpuid(0x00000001, &tfms, &misc, &cap0, &cap4);
481 clflush_size = ((misc >> 8) & 0xff) * 8;
482 driver->has_clflush = 1;
483 driver->clflush_add =
484 PAGE_SIZE * clflush_size / sizeof(uint32_t);
485 driver->clflush_mask = driver->clflush_add - 1;
486 driver->clflush_mask = ~driver->clflush_mask;
488 #endif
490 up_write(&driver->sem);
491 return driver;
493 out_err1:
494 kfree(driver);
495 return NULL;
498 #if defined(CONFIG_X86)
499 static void psb_mmu_flush_ptes(struct psb_mmu_pd *pd, unsigned long address,
500 uint32_t num_pages, uint32_t desired_tile_stride,
501 uint32_t hw_tile_stride)
503 struct psb_mmu_pt *pt;
504 uint32_t rows = 1;
505 uint32_t i;
506 unsigned long addr;
507 unsigned long end;
508 unsigned long next;
509 unsigned long add;
510 unsigned long row_add;
511 unsigned long clflush_add = pd->driver->clflush_add;
512 unsigned long clflush_mask = pd->driver->clflush_mask;
514 if (!pd->driver->has_clflush)
515 return;
517 if (hw_tile_stride)
518 rows = num_pages / desired_tile_stride;
519 else
520 desired_tile_stride = num_pages;
522 add = desired_tile_stride << PAGE_SHIFT;
523 row_add = hw_tile_stride << PAGE_SHIFT;
524 mb();
525 for (i = 0; i < rows; ++i) {
527 addr = address;
528 end = addr + add;
530 do {
531 next = psb_pd_addr_end(addr, end);
532 pt = psb_mmu_pt_map_lock(pd, addr);
533 if (!pt)
534 continue;
535 do {
536 psb_clflush(&pt->v[psb_mmu_pt_index(addr)]);
537 } while (addr += clflush_add,
538 (addr & clflush_mask) < next);
540 psb_mmu_pt_unmap_unlock(pt);
541 } while (addr = next, next != end);
542 address += row_add;
544 mb();
546 #else
547 static void psb_mmu_flush_ptes(struct psb_mmu_pd *pd, unsigned long address,
548 uint32_t num_pages, uint32_t desired_tile_stride,
549 uint32_t hw_tile_stride)
551 drm_ttm_cache_flush();
553 #endif
555 void psb_mmu_remove_pfn_sequence(struct psb_mmu_pd *pd,
556 unsigned long address, uint32_t num_pages)
558 struct psb_mmu_pt *pt;
559 unsigned long addr;
560 unsigned long end;
561 unsigned long next;
562 unsigned long f_address = address;
564 down_read(&pd->driver->sem);
566 addr = address;
567 end = addr + (num_pages << PAGE_SHIFT);
569 do {
570 next = psb_pd_addr_end(addr, end);
571 pt = psb_mmu_pt_alloc_map_lock(pd, addr);
572 if (!pt)
573 goto out;
574 do {
575 psb_mmu_invalidate_pte(pt, addr);
576 --pt->count;
577 } while (addr += PAGE_SIZE, addr < next);
578 psb_mmu_pt_unmap_unlock(pt);
580 } while (addr = next, next != end);
582 out:
583 if (pd->hw_context != -1)
584 psb_mmu_flush_ptes(pd, f_address, num_pages, 1, 1);
586 up_read(&pd->driver->sem);
588 if (pd->hw_context != -1)
589 psb_mmu_flush(pd->driver);
591 return;
594 void psb_mmu_remove_pages(struct psb_mmu_pd *pd, unsigned long address,
595 uint32_t num_pages, uint32_t desired_tile_stride,
596 uint32_t hw_tile_stride)
598 struct psb_mmu_pt *pt;
599 uint32_t rows = 1;
600 uint32_t i;
601 unsigned long addr;
602 unsigned long end;
603 unsigned long next;
604 unsigned long add;
605 unsigned long row_add;
606 unsigned long f_address = address;
608 if (hw_tile_stride)
609 rows = num_pages / desired_tile_stride;
610 else
611 desired_tile_stride = num_pages;
613 add = desired_tile_stride << PAGE_SHIFT;
614 row_add = hw_tile_stride << PAGE_SHIFT;
616 down_read(&pd->driver->sem);
618 /* Make sure we only need to flush this processor's cache */
620 for (i = 0; i < rows; ++i) {
622 addr = address;
623 end = addr + add;
625 do {
626 next = psb_pd_addr_end(addr, end);
627 pt = psb_mmu_pt_map_lock(pd, addr);
628 if (!pt)
629 continue;
630 do {
631 psb_mmu_invalidate_pte(pt, addr);
632 --pt->count;
634 } while (addr += PAGE_SIZE, addr < next);
635 psb_mmu_pt_unmap_unlock(pt);
637 } while (addr = next, next != end);
638 address += row_add;
640 if (pd->hw_context != -1)
641 psb_mmu_flush_ptes(pd, f_address, num_pages,
642 desired_tile_stride, hw_tile_stride);
644 up_read(&pd->driver->sem);
646 if (pd->hw_context != -1)
647 psb_mmu_flush(pd->driver);
650 int psb_mmu_insert_pfn_sequence(struct psb_mmu_pd *pd, uint32_t start_pfn,
651 unsigned long address, uint32_t num_pages,
652 int type)
654 struct psb_mmu_pt *pt;
655 uint32_t pte;
656 unsigned long addr;
657 unsigned long end;
658 unsigned long next;
659 unsigned long f_address = address;
660 int ret = -ENOMEM;
662 down_read(&pd->driver->sem);
664 addr = address;
665 end = addr + (num_pages << PAGE_SHIFT);
667 do {
668 next = psb_pd_addr_end(addr, end);
669 pt = psb_mmu_pt_alloc_map_lock(pd, addr);
670 if (!pt) {
671 ret = -ENOMEM;
672 goto out;
674 do {
675 pte = psb_mmu_mask_pte(start_pfn++, type);
676 psb_mmu_set_pte(pt, addr, pte);
677 pt->count++;
678 } while (addr += PAGE_SIZE, addr < next);
679 psb_mmu_pt_unmap_unlock(pt);
681 } while (addr = next, next != end);
682 ret = 0;
684 out:
685 if (pd->hw_context != -1)
686 psb_mmu_flush_ptes(pd, f_address, num_pages, 1, 1);
688 up_read(&pd->driver->sem);
690 if (pd->hw_context != -1)
691 psb_mmu_flush(pd->driver);
693 return 0;
696 int psb_mmu_insert_pages(struct psb_mmu_pd *pd, struct page **pages,
697 unsigned long address, uint32_t num_pages,
698 uint32_t desired_tile_stride, uint32_t hw_tile_stride,
699 int type)
701 struct psb_mmu_pt *pt;
702 uint32_t rows = 1;
703 uint32_t i;
704 uint32_t pte;
705 unsigned long addr;
706 unsigned long end;
707 unsigned long next;
708 unsigned long add;
709 unsigned long row_add;
710 unsigned long f_address = address;
711 int ret = -ENOMEM;
713 if (hw_tile_stride) {
714 if (num_pages % desired_tile_stride != 0)
715 return -EINVAL;
716 rows = num_pages / desired_tile_stride;
717 } else {
718 desired_tile_stride = num_pages;
721 add = desired_tile_stride << PAGE_SHIFT;
722 row_add = hw_tile_stride << PAGE_SHIFT;
724 down_read(&pd->driver->sem);
726 for (i = 0; i < rows; ++i) {
728 addr = address;
729 end = addr + add;
731 do {
732 next = psb_pd_addr_end(addr, end);
733 pt = psb_mmu_pt_alloc_map_lock(pd, addr);
734 if (!pt)
735 goto out;
736 do {
737 pte = psb_mmu_mask_pte(page_to_pfn(*pages++),
738 type);
739 psb_mmu_set_pte(pt, addr, pte);
740 pt->count++;
741 } while (addr += PAGE_SIZE, addr < next);
742 psb_mmu_pt_unmap_unlock(pt);
744 } while (addr = next, next != end);
746 address += row_add;
749 ret = 0;
750 out:
751 if (pd->hw_context != -1)
752 psb_mmu_flush_ptes(pd, f_address, num_pages,
753 desired_tile_stride, hw_tile_stride);
755 up_read(&pd->driver->sem);
757 if (pd->hw_context != -1)
758 psb_mmu_flush(pd->driver);
760 return ret;
763 int psb_mmu_virtual_to_pfn(struct psb_mmu_pd *pd, uint32_t virtual,
764 unsigned long *pfn)
766 int ret;
767 struct psb_mmu_pt *pt;
768 uint32_t tmp;
769 spinlock_t *lock = &pd->driver->lock;
771 down_read(&pd->driver->sem);
772 pt = psb_mmu_pt_map_lock(pd, virtual);
773 if (!pt) {
774 uint32_t *v;
776 spin_lock(lock);
777 v = kmap_atomic(pd->p);
778 tmp = v[psb_mmu_pd_index(virtual)];
779 kunmap_atomic(v);
780 spin_unlock(lock);
782 if (tmp != pd->invalid_pde || !(tmp & PSB_PTE_VALID) ||
783 !(pd->invalid_pte & PSB_PTE_VALID)) {
784 ret = -EINVAL;
785 goto out;
787 ret = 0;
788 *pfn = pd->invalid_pte >> PAGE_SHIFT;
789 goto out;
791 tmp = pt->v[psb_mmu_pt_index(virtual)];
792 if (!(tmp & PSB_PTE_VALID)) {
793 ret = -EINVAL;
794 } else {
795 ret = 0;
796 *pfn = tmp >> PAGE_SHIFT;
798 psb_mmu_pt_unmap_unlock(pt);
799 out:
800 up_read(&pd->driver->sem);
801 return ret;