Deleted Added
full compact
pmap.c (265996) pmap.c (265998)
1/*-
2 * Copyright (C) 2007-2009 Semihalf, Rafal Jaworowski <raj@semihalf.com>
3 * Copyright (C) 2006 Semihalf, Marian Balakowicz <m8@semihalf.com>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 35 unchanged lines hidden (view full) ---

44 * 0xc100_0000 - 0xc100_3fff : reserved for page zero/copy
45 * 0xc100_4000 - 0xc200_3fff : reserved for ptbl bufs
46 * 0xc200_4000 - 0xc200_8fff : guard page + kstack0
47 * 0xc200_9000 - 0xfeef_ffff : actual free KVA space
48 * 0xfef0_0000 - 0xffff_ffff : I/O devices region
49 */
50
51#include <sys/cdefs.h>
1/*-
2 * Copyright (C) 2007-2009 Semihalf, Rafal Jaworowski <raj@semihalf.com>
3 * Copyright (C) 2006 Semihalf, Marian Balakowicz <m8@semihalf.com>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 35 unchanged lines hidden (view full) ---

44 * 0xc100_0000 - 0xc100_3fff : reserved for page zero/copy
45 * 0xc100_4000 - 0xc200_3fff : reserved for ptbl bufs
46 * 0xc200_4000 - 0xc200_8fff : guard page + kstack0
47 * 0xc200_9000 - 0xfeef_ffff : actual free KVA space
48 * 0xfef0_0000 - 0xffff_ffff : I/O devices region
49 */
50
51#include <sys/cdefs.h>
52__FBSDID("$FreeBSD: stable/10/sys/powerpc/booke/pmap.c 265996 2014-05-14 00:51:26Z ian $");
52__FBSDID("$FreeBSD: stable/10/sys/powerpc/booke/pmap.c 265998 2014-05-14 01:16:05Z ian $");
53
54#include <sys/param.h>
55#include <sys/malloc.h>
56#include <sys/ktr.h>
57#include <sys/proc.h>
58#include <sys/user.h>
59#include <sys/queue.h>
60#include <sys/systm.h>

--- 123 unchanged lines hidden (view full) ---

184
185#define TLB1_ENTRIES 16
186
187/* In-ram copy of the TLB1 */
188static tlb_entry_t tlb1[TLB1_ENTRIES];
189
190/* Next free entry in the TLB1 */
191static unsigned int tlb1_idx;
53
54#include <sys/param.h>
55#include <sys/malloc.h>
56#include <sys/ktr.h>
57#include <sys/proc.h>
58#include <sys/user.h>
59#include <sys/queue.h>
60#include <sys/systm.h>

--- 123 unchanged lines hidden (view full) ---

184
185#define TLB1_ENTRIES 16
186
187/* In-ram copy of the TLB1 */
188static tlb_entry_t tlb1[TLB1_ENTRIES];
189
190/* Next free entry in the TLB1 */
191static unsigned int tlb1_idx;
192static vm_offset_t tlb1_map_base = VM_MAX_KERNEL_ADDRESS;
192
193static tlbtid_t tid_alloc(struct pmap *);
194
195static void tlb_print_entry(int, uint32_t, uint32_t, uint32_t, uint32_t);
196
197static int tlb1_set_entry(vm_offset_t, vm_offset_t, vm_size_t, uint32_t);
198static void tlb1_write_entry(unsigned int);
199static int tlb1_iomapped(int, vm_paddr_t, vm_size_t, vm_offset_t *);

--- 2476 unchanged lines hidden (view full) ---

2676 (pa + size) <= (tlb1[i].phys + tlb1[i].size))
2677 return (void *)(tlb1[i].virt +
2678 (pa - tlb1[i].phys));
2679 }
2680 }
2681
2682 size = roundup(size, PAGE_SIZE);
2683
193
194static tlbtid_t tid_alloc(struct pmap *);
195
196static void tlb_print_entry(int, uint32_t, uint32_t, uint32_t, uint32_t);
197
198static int tlb1_set_entry(vm_offset_t, vm_offset_t, vm_size_t, uint32_t);
199static void tlb1_write_entry(unsigned int);
200static int tlb1_iomapped(int, vm_paddr_t, vm_size_t, vm_offset_t *);

--- 2476 unchanged lines hidden (view full) ---

2677 (pa + size) <= (tlb1[i].phys + tlb1[i].size))
2678 return (void *)(tlb1[i].virt +
2679 (pa - tlb1[i].phys));
2680 }
2681 }
2682
2683 size = roundup(size, PAGE_SIZE);
2684
2685 /*
2686 * We leave a hole for device direct mapping between the maximum user
2687 * address (0x8000000) and the minimum KVA address (0xc0000000). If
2688 * devices are in there, just map them 1:1. If not, map them to the
2689 * device mapping area about VM_MAX_KERNEL_ADDRESS. These mapped
2690 * addresses should be pulled from an allocator, but since we do not
2691 * ever free TLB1 entries, it is safe just to increment a counter.
2692 * Note that there isn't a lot of address space here (128 MB) and it
2693 * is not at all difficult to imagine running out, since that is a 4:1
2694 * compression from the 0xc0000000 - 0xf0000000 address space that gets
2695 * mapped there.
2696 */
2684 if (pa >= (VM_MAXUSER_ADDRESS + PAGE_SIZE) &&
2685 (pa + size - 1) < VM_MIN_KERNEL_ADDRESS)
2686 va = pa;
2687 else
2697 if (pa >= (VM_MAXUSER_ADDRESS + PAGE_SIZE) &&
2698 (pa + size - 1) < VM_MIN_KERNEL_ADDRESS)
2699 va = pa;
2700 else
2688 va = kva_alloc(size);
2701 va = atomic_fetchadd_int(&tlb1_map_base, size);
2689 res = (void *)va;
2690
2691 do {
2692 sz = 1 << (ilog2(size) & ~1);
2693 if (bootverbose)
2694 printf("Wiring VA=%x to PA=%x (size=%x), "
2695 "using TLB1[%d]\n", va, pa, sz, tlb1_idx);
2696 tlb1_set_entry(va, pa, sz, tlb_calc_wimg(pa, ma));

--- 383 unchanged lines hidden (view full) ---

3080 pgsz = pgs[idx];
3081 debugf("%u: %x -> %x, size=%x\n", idx, pa, va, pgsz);
3082 tlb1_set_entry(va, pa, pgsz, _TLB_ENTRY_MEM);
3083 pa += pgsz;
3084 va += pgsz;
3085 }
3086
3087 mapped = (va - base);
2702 res = (void *)va;
2703
2704 do {
2705 sz = 1 << (ilog2(size) & ~1);
2706 if (bootverbose)
2707 printf("Wiring VA=%x to PA=%x (size=%x), "
2708 "using TLB1[%d]\n", va, pa, sz, tlb1_idx);
2709 tlb1_set_entry(va, pa, sz, tlb_calc_wimg(pa, ma));

--- 383 unchanged lines hidden (view full) ---

3093 pgsz = pgs[idx];
3094 debugf("%u: %x -> %x, size=%x\n", idx, pa, va, pgsz);
3095 tlb1_set_entry(va, pa, pgsz, _TLB_ENTRY_MEM);
3096 pa += pgsz;
3097 va += pgsz;
3098 }
3099
3100 mapped = (va - base);
3088 debugf("mapped size 0x%08x (wasted space 0x%08x)\n",
3101 printf("mapped size 0x%08x (wasted space 0x%08x)\n",
3089 mapped, mapped - size);
3090 return (mapped);
3091}
3092
3093/*
3094 * TLB1 initialization routine, to be called after the very first
3095 * assembler level setup done in locore.S.
3096 */

--- 46 unchanged lines hidden (view full) ---

3143
3144 /* Setup TLB miss defaults */
3145 set_mas4_defaults();
3146}
3147
3148vm_offset_t
3149pmap_early_io_map(vm_paddr_t pa, vm_size_t size)
3150{
3102 mapped, mapped - size);
3103 return (mapped);
3104}
3105
3106/*
3107 * TLB1 initialization routine, to be called after the very first
3108 * assembler level setup done in locore.S.
3109 */

--- 46 unchanged lines hidden (view full) ---

3156
3157 /* Setup TLB miss defaults */
3158 set_mas4_defaults();
3159}
3160
3161vm_offset_t
3162pmap_early_io_map(vm_paddr_t pa, vm_size_t size)
3163{
3151 static vm_offset_t early_io_map_base = VM_MAX_KERNEL_ADDRESS;
3152 vm_paddr_t pa_base;
3153 vm_offset_t va, sz;
3154 int i;
3155
3156 KASSERT(!pmap_bootstrapped, ("Do not use after PMAP is up!"));
3157
3158 for (i = 0; i < tlb1_idx; i++) {
3159 if (!(tlb1[i].mas1 & MAS1_VALID))
3160 continue;
3161 if (pa >= tlb1[i].phys && (pa + size) <=
3162 (tlb1[i].phys + tlb1[i].size))
3163 return (tlb1[i].virt + (pa - tlb1[i].phys));
3164 }
3165
3166 pa_base = trunc_page(pa);
3167 size = roundup(size + (pa - pa_base), PAGE_SIZE);
3164 vm_paddr_t pa_base;
3165 vm_offset_t va, sz;
3166 int i;
3167
3168 KASSERT(!pmap_bootstrapped, ("Do not use after PMAP is up!"));
3169
3170 for (i = 0; i < tlb1_idx; i++) {
3171 if (!(tlb1[i].mas1 & MAS1_VALID))
3172 continue;
3173 if (pa >= tlb1[i].phys && (pa + size) <=
3174 (tlb1[i].phys + tlb1[i].size))
3175 return (tlb1[i].virt + (pa - tlb1[i].phys));
3176 }
3177
3178 pa_base = trunc_page(pa);
3179 size = roundup(size + (pa - pa_base), PAGE_SIZE);
3168 va = early_io_map_base + (pa - pa_base);
3180 va = tlb1_map_base + (pa - pa_base);
3169
3170 do {
3171 sz = 1 << (ilog2(size) & ~1);
3181
3182 do {
3183 sz = 1 << (ilog2(size) & ~1);
3172 tlb1_set_entry(early_io_map_base, pa_base, sz, _TLB_ENTRY_IO);
3184 tlb1_set_entry(tlb1_map_base, pa_base, sz, _TLB_ENTRY_IO);
3173 size -= sz;
3174 pa_base += sz;
3185 size -= sz;
3186 pa_base += sz;
3175 early_io_map_base += sz;
3187 tlb1_map_base += sz;
3176 } while (size > 0);
3177
3178#ifdef SMP
3179 bp_ntlb1s = tlb1_idx;
3180#endif
3181
3182 return (va);
3183}

--- 105 unchanged lines hidden ---
3188 } while (size > 0);
3189
3190#ifdef SMP
3191 bp_ntlb1s = tlb1_idx;
3192#endif
3193
3194 return (va);
3195}

--- 105 unchanged lines hidden ---