generic_32.c 2.6 KB

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