1 /* $Id: generic.c,v 1.13 1999/12/20 05:02:33 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>
12 #include <asm/pgalloc.h>
13 #include <asm/pgtable.h>
16 static inline void forget_pte(pte_t page
)
20 if (pte_present(page
)) {
21 unsigned long nr
= pte_pagenr(page
);
22 if (nr
>= max_mapnr
|| PageReserved(mem_map
+nr
))
25 * free_page() used to be able to clear swap cache
26 * entries. We may now have to do it manually.
28 free_page_and_swap_cache(mem_map
+nr
);
31 swap_free(pte_to_swp_entry(page
));
34 /* Remap IO memory, the same way as remap_page_range(), but use
35 * the obio memory space.
37 * They use a pgprot that sets PAGE_IO and does not check the
38 * mem_map table as this is independent of normal memory.
40 * As a special hack if the lowest bit of offset is set the
41 * side-effect bit will be turned off. This is used as a
42 * performance improvement on FFB/AFB. -DaveM
44 static inline void io_remap_pte_range(pte_t
* pte
, unsigned long address
, unsigned long size
,
45 unsigned long offset
, pgprot_t prot
, int space
)
56 unsigned long curend
= address
+ PAGE_SIZE
;
58 entry
= mk_pte_io((offset
& ~(0x1UL
)), prot
, space
);
59 if (!(address
& 0xffff)) {
60 if (!(address
& 0x3fffff) && !(offset
& 0x3ffffe) && end
>= address
+ 0x400000) {
61 entry
= mk_pte_io((offset
& ~(0x1UL
)),
62 __pgprot(pgprot_val (prot
) | _PAGE_SZ4MB
),
64 curend
= address
+ 0x400000;
66 } else if (!(address
& 0x7ffff) && !(offset
& 0x7fffe) && end
>= address
+ 0x80000) {
67 entry
= mk_pte_io((offset
& ~(0x1UL
)),
68 __pgprot(pgprot_val (prot
) | _PAGE_SZ512K
),
70 curend
= address
+ 0x80000;
72 } else if (!(offset
& 0xfffe) && end
>= address
+ 0x10000) {
73 entry
= mk_pte_io((offset
& ~(0x1UL
)),
74 __pgprot(pgprot_val (prot
) | _PAGE_SZ64K
),
76 curend
= address
+ 0x10000;
84 pte_val(entry
) &= ~(_PAGE_E
);
92 } while (address
< curend
);
93 } while (address
< end
);
96 static inline int io_remap_pmd_range(pmd_t
* pmd
, unsigned long address
, unsigned long size
,
97 unsigned long offset
, pgprot_t prot
, int space
)
101 address
&= ~PGDIR_MASK
;
102 end
= address
+ size
;
103 if (end
> PGDIR_SIZE
)
107 pte_t
* pte
= pte_alloc(pmd
, address
);
110 spin_lock(¤t
->mm
->page_table_lock
);
111 io_remap_pte_range(pte
, address
, end
- address
, address
+ offset
, prot
, space
);
112 spin_unlock(¤t
->mm
->page_table_lock
);
113 address
= (address
+ PMD_SIZE
) & PMD_MASK
;
115 } while (address
< end
);
119 int io_remap_page_range(unsigned long from
, unsigned long offset
, unsigned long size
, pgprot_t prot
, int space
)
123 unsigned long beg
= from
;
124 unsigned long end
= from
+ size
;
126 prot
= __pgprot(pg_iobits
);
128 dir
= pgd_offset(current
->mm
, from
);
129 flush_cache_range(current
->mm
, beg
, end
);
131 pmd_t
*pmd
= pmd_alloc(dir
, from
);
135 error
= io_remap_pmd_range(pmd
, from
, end
- from
, offset
+ from
, prot
, space
);
138 from
= (from
+ PGDIR_SIZE
) & PGDIR_MASK
;
141 flush_tlb_range(current
->mm
, beg
, end
);