1 /* $Id: generic.c,v 1.18 2001/12/21 04:56:15 davem Exp $
2 * generic.c: Generic Sparc mm routines that are not dependent upon
3 * MMU type but are Sparc specific.
5 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
8 #include <linux/kernel.h>
10 #include <linux/swap.h>
11 #include <linux/pagemap.h>
13 #include <asm/pgalloc.h>
14 #include <asm/pgtable.h>
16 #include <asm/tlbflush.h>
18 static inline pte_t
mk_pte_io(unsigned long page
, pgprot_t prot
, int space
)
21 pte_val(pte
) = (((page
) | pgprot_val(prot
) | _PAGE_E
) &
22 ~(unsigned long)_PAGE_CACHE
);
23 pte_val(pte
) |= (((unsigned long)space
) << 32);
27 /* Remap IO memory, the same way as remap_pfn_range(), but use
28 * the obio memory space.
30 * They use a pgprot that sets PAGE_IO and does not check the
31 * mem_map table as this is independent of normal memory.
33 static inline void io_remap_pte_range(struct mm_struct
*mm
, pte_t
* pte
,
34 unsigned long address
,
36 unsigned long offset
, pgprot_t prot
,
41 /* clear hack bit that was used as a write_combine side-effect flag */
49 unsigned long curend
= address
+ PAGE_SIZE
;
51 entry
= mk_pte_io(offset
, prot
, space
);
52 if (!(address
& 0xffff)) {
53 if (!(address
& 0x3fffff) && !(offset
& 0x3ffffe) && end
>= address
+ 0x400000) {
54 entry
= mk_pte_io(offset
,
55 __pgprot(pgprot_val (prot
) | _PAGE_SZ4MB
),
57 curend
= address
+ 0x400000;
59 } else if (!(address
& 0x7ffff) && !(offset
& 0x7fffe) && end
>= address
+ 0x80000) {
60 entry
= mk_pte_io(offset
,
61 __pgprot(pgprot_val (prot
) | _PAGE_SZ512K
),
63 curend
= address
+ 0x80000;
65 } else if (!(offset
& 0xfffe) && end
>= address
+ 0x10000) {
66 entry
= mk_pte_io(offset
,
67 __pgprot(pgprot_val (prot
) | _PAGE_SZ64K
),
69 curend
= address
+ 0x10000;
77 BUG_ON(!pte_none(*pte
));
78 set_pte_at(mm
, address
, pte
, entry
);
81 } while (address
< curend
);
82 } while (address
< end
);
85 static inline int io_remap_pmd_range(struct mm_struct
*mm
, pmd_t
* pmd
, unsigned long address
, unsigned long size
,
86 unsigned long offset
, pgprot_t prot
, int space
)
90 address
&= ~PGDIR_MASK
;
96 pte_t
* pte
= pte_alloc_map(mm
, pmd
, address
);
99 io_remap_pte_range(mm
, pte
, address
, end
- address
, address
+ offset
, prot
, space
);
101 address
= (address
+ PMD_SIZE
) & PMD_MASK
;
103 } while (address
< end
);
107 static inline int io_remap_pud_range(struct mm_struct
*mm
, pud_t
* pud
, unsigned long address
, unsigned long size
,
108 unsigned long offset
, pgprot_t prot
, int space
)
112 address
&= ~PUD_MASK
;
113 end
= address
+ size
;
118 pmd_t
*pmd
= pmd_alloc(mm
, pud
, address
);
121 io_remap_pmd_range(mm
, pmd
, address
, end
- address
, address
+ offset
, prot
, space
);
122 address
= (address
+ PUD_SIZE
) & PUD_MASK
;
124 } while (address
< end
);
128 int io_remap_pfn_range(struct vm_area_struct
*vma
, unsigned long from
,
129 unsigned long pfn
, unsigned long size
, pgprot_t prot
)
133 unsigned long beg
= from
;
134 unsigned long end
= from
+ size
;
135 struct mm_struct
*mm
= vma
->vm_mm
;
136 int space
= GET_IOSPACE(pfn
);
137 unsigned long offset
= GET_PFN(pfn
) << PAGE_SHIFT
;
138 unsigned long phys_base
;
140 phys_base
= offset
| (((unsigned long) space
) << 32UL);
142 /* See comment in mm/memory.c remap_pfn_range */
143 vma
->vm_flags
|= VM_IO
| VM_RESERVED
| VM_PFNMAP
;
144 vma
->vm_pgoff
= phys_base
>> PAGE_SHIFT
;
146 prot
= __pgprot(pg_iobits
);
148 dir
= pgd_offset(mm
, from
);
149 flush_cache_range(vma
, beg
, end
);
152 pud_t
*pud
= pud_alloc(mm
, dir
, from
);
156 error
= io_remap_pud_range(mm
, pud
, from
, end
- from
, offset
+ from
, prot
, space
);
159 from
= (from
+ PGDIR_SIZE
) & PGDIR_MASK
;
163 flush_tlb_range(vma
, beg
, end
);
This page took 0.048659 seconds and 5 git commands to generate.