generic_32.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * generic.c: Generic Sparc mm routines that are not dependent upon
  3. * MMU type but are Sparc specific.
  4. *
  5. * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
  6. */
  7. #include <linux/kernel.h>
  8. #include <linux/mm.h>
  9. #include <linux/swap.h>
  10. #include <linux/pagemap.h>
  11. #include <asm/pgalloc.h>
  12. #include <asm/pgtable.h>
  13. #include <asm/page.h>
  14. #include <asm/cacheflush.h>
  15. #include <asm/tlbflush.h>
  16. /* Remap IO memory, the same way as remap_pfn_range(), but use
  17. * the obio memory space.
  18. *
  19. * They use a pgprot that sets PAGE_IO and does not check the
  20. * mem_map table as this is independent of normal memory.
  21. */
  22. static inline void io_remap_pte_range(struct mm_struct *mm, pte_t * pte, unsigned long address, unsigned long size,
  23. unsigned long offset, pgprot_t prot, int space)
  24. {
  25. unsigned long end;
  26. address &= ~PMD_MASK;
  27. end = address + size;
  28. if (end > PMD_SIZE)
  29. end = PMD_SIZE;
  30. do {
  31. set_pte_at(mm, address, pte, mk_pte_io(offset, prot, space));
  32. address += PAGE_SIZE;
  33. offset += PAGE_SIZE;
  34. pte++;
  35. } while (address < end);
  36. }
  37. static inline int io_remap_pmd_range(struct mm_struct *mm, pmd_t * pmd, unsigned long address, unsigned long size,
  38. unsigned long offset, pgprot_t prot, int space)
  39. {
  40. unsigned long end;
  41. address &= ~PGDIR_MASK;
  42. end = address + size;
  43. if (end > PGDIR_SIZE)
  44. end = PGDIR_SIZE;
  45. offset -= address;
  46. do {
  47. pte_t * pte = pte_alloc_map(mm, pmd, address);
  48. if (!pte)
  49. return -ENOMEM;
  50. io_remap_pte_range(mm, pte, address, end - address, address + offset, prot, space);
  51. address = (address + PMD_SIZE) & PMD_MASK;
  52. pmd++;
  53. } while (address < end);
  54. return 0;
  55. }
  56. int io_remap_pfn_range(struct vm_area_struct *vma, unsigned long from,
  57. unsigned long pfn, unsigned long size, pgprot_t prot)
  58. {
  59. int error = 0;
  60. pgd_t * dir;
  61. unsigned long beg = from;
  62. unsigned long end = from + size;
  63. struct mm_struct *mm = vma->vm_mm;
  64. int space = GET_IOSPACE(pfn);
  65. unsigned long offset = GET_PFN(pfn) << PAGE_SHIFT;
  66. /* See comment in mm/memory.c remap_pfn_range */
  67. vma->vm_flags |= VM_IO | VM_RESERVED | VM_PFNMAP;
  68. vma->vm_pgoff = (offset >> PAGE_SHIFT) |
  69. ((unsigned long)space << 28UL);
  70. offset -= from;
  71. dir = pgd_offset(mm, from);
  72. flush_cache_range(vma, beg, end);
  73. while (from < end) {
  74. pmd_t *pmd = pmd_alloc(mm, dir, from);
  75. error = -ENOMEM;
  76. if (!pmd)
  77. break;
  78. error = io_remap_pmd_range(mm, pmd, from, end - from, offset + from, prot, space);
  79. if (error)
  80. break;
  81. from = (from + PGDIR_SIZE) & PGDIR_MASK;
  82. dir++;
  83. }
  84. flush_tlb_range(vma, beg, end);
  85. return error;
  86. }
  87. EXPORT_SYMBOL(io_remap_pfn_range);