1 /* $Id: generic.c,v 1.6 1998/10/27 23:28:00 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/pgtable.h>
16 /* Allocate a block of RAM which is aligned to its size.
17 * This procedure can be used until the call to mem_init().
19 void *sparc_init_alloc(unsigned long *kbrk
, unsigned long size
)
21 unsigned long mask
= size
- 1;
27 prom_printf("panic: sparc_init_alloc botch\n");
30 ret
= (*kbrk
+ mask
) & ~mask
;
32 memset((void*) ret
, 0, size
);
36 static inline void forget_pte(pte_t page
)
40 if (pte_present(page
)) {
41 unsigned long addr
= pte_page(page
);
42 if (MAP_NR(addr
) >= max_mapnr
|| PageReserved(mem_map
+MAP_NR(addr
)))
45 * free_page() used to be able to clear swap cache
46 * entries. We may now have to do it manually.
48 free_page_and_swap_cache(addr
);
51 swap_free(pte_val(page
));
54 /* Remap IO memory, the same way as remap_page_range(), but use
55 * the obio memory space.
57 * They use a pgprot that sets PAGE_IO and does not check the
58 * mem_map table as this is independent of normal memory.
60 static inline void io_remap_pte_range(pte_t
* pte
, unsigned long address
, unsigned long size
,
61 unsigned long offset
, pgprot_t prot
, int space
)
72 set_pte(pte
, mk_pte_io(offset
, prot
, space
));
77 } while (address
< end
);
80 static inline int io_remap_pmd_range(pmd_t
* pmd
, unsigned long address
, unsigned long size
,
81 unsigned long offset
, pgprot_t prot
, int space
)
85 address
&= ~PGDIR_MASK
;
91 pte_t
* pte
= pte_alloc(pmd
, address
);
94 io_remap_pte_range(pte
, address
, end
- address
, address
+ offset
, prot
, space
);
95 address
= (address
+ PMD_SIZE
) & PMD_MASK
;
97 } while (address
< end
);
101 int io_remap_page_range(unsigned long from
, unsigned long offset
, unsigned long size
, pgprot_t prot
, int space
)
105 unsigned long beg
= from
;
106 unsigned long end
= from
+ size
;
108 prot
= __pgprot(pg_iobits
);
110 dir
= pgd_offset(current
->mm
, from
);
111 flush_cache_range(current
->mm
, beg
, end
);
113 pmd_t
*pmd
= pmd_alloc(dir
, from
);
117 error
= io_remap_pmd_range(pmd
, from
, end
- from
, offset
+ from
, prot
, space
);
120 from
= (from
+ PGDIR_SIZE
) & PGDIR_MASK
;
123 flush_tlb_range(current
->mm
, beg
, end
);