2 * baget.c: Baget low level stuff
4 * Copyright (C) 1998 Gleb Raiko & Vladimir Roganov
9 #include <linux/kernel.h>
11 #include <asm/system.h>
12 #include <asm/bootinfo.h>
13 #include <asm/mipsregs.h>
14 #include <asm/pgtable.h>
16 #include <asm/baget/baget.h>
19 * Following code is based on routines from 'mm/vmalloc.c'
20 * Additional parameters ioaddr is needed to iterate across real I/O address.
22 static inline int alloc_area_pte(pte_t * pte, unsigned long address,
23 unsigned long size, unsigned long ioaddr)
31 while (address < end) {
34 printk("kseg2_alloc_io: page already exists\n");
36 * For MIPS looks pretty to have transparent mapping
37 * for KSEG2 areas -- user can't access one, and no
38 * problems with virtual <--> physical translation.
40 page = ioaddr & PAGE_MASK;
42 set_pte(pte, __pte(page | pgprot_val(PAGE_USERIO) |
43 _PAGE_GLOBAL | __READABLE | __WRITEABLE));
51 static inline int alloc_area_pmd(pmd_t * pmd, unsigned long address,
52 unsigned long size, unsigned long ioaddr)
56 address &= ~PGDIR_MASK;
60 while (address < end) {
61 pte_t * pte = pte_alloc_kernel(pmd, address);
64 if (alloc_area_pte(pte, address, end - address, ioaddr))
66 address = (address + PMD_SIZE) & PMD_MASK;
73 int kseg2_alloc_io (unsigned long address, unsigned long size)
76 unsigned long end = address + size;
78 dir = pgd_offset_k(address);
80 while (address < end) {
84 pmd = pmd_alloc_kernel(dir, address);
87 if (alloc_area_pmd(pmd, address, end - address, address))
89 if (pgd_val(olddir) != pgd_val(*dir))
90 set_pgdir(address, *dir);
91 address = (address + PGDIR_SIZE) & PGDIR_MASK;