/* A bitmap, two bits for every 256MB of physical memory. These two * bits determine what page size we use for kernel linear * translations. They form an index into kern_linear_pte_xor[]. The * value in the indexed slot is XOR'd with the TLB miss virtual * address to form the resulting TTE. The mapping is: * * 0 ==> 4MB * 1 ==> 256MB * 2 ==> 2GB * 3 ==> 16GB * * All sun4v chips support 256MB pages. Only SPARC-T4 and later * support 2GB pages, and hopefully future cpus will support the 16GB * pages as well. For slots 2 and 3, we encode a 256MB TTE xor there * if these larger page sizes are not supported by the cpu. * * It would be nice to determine this from the machine description * 'cpu' properties, but we need to have this table setup before the * MDESC is initialized.
*/
#ifndef CONFIG_DEBUG_PAGEALLOC /* A special kernel TSB for 4MB, 256MB, 2GB and 16GB linear mappings. * Space is allocated for this right after the trap table in * arch/sparc64/kernel/head.S
*/ externstruct tsb swapper_4m_tsb[KERNEL_TSB4M_NENTRIES]; #endif externstruct tsb swapper_tsb[KERNEL_TSB_NENTRIES];
if (x->phys_addr > y->phys_addr) return 1; if (x->phys_addr < y->phys_addr) return -1; return 0;
}
staticvoid __init read_obp_memory(constchar *property, struct linux_prom64_registers *regs, int *num_ents)
{
phandle node = prom_finddevice("/memory"); int prop_size = prom_getproplen(node, property); int ents, ret, i;
ents = prop_size / sizeof(struct linux_prom64_registers); if (ents > MAX_BANKS) {
prom_printf("The machine has more %s property entries than " "this kernel can support (%d).\n",
property, MAX_BANKS);
prom_halt();
}
ret = prom_getproperty(node, property, (char *) regs, prop_size); if (ret == -1) {
prom_printf("Couldn't get %s property from /memory.\n",
property);
prom_halt();
}
/* Sanitize what we got from the firmware, by page aligning * everything.
*/ for (i = 0; i < ents; i++) { unsignedlong base, size;
base = regs[i].phys_addr;
size = regs[i].reg_size;
size -= new_base - base; if ((long) size < 0L)
size = 0UL;
base = new_base;
} if (size == 0UL) { /* If it is empty, simply get rid of it. * This simplifies the logic of the other * functions that process these arrays.
*/
memmove(®s[i], ®s[i + 1],
(ents - i - 1) * sizeof(regs[0]));
i--;
ents--; continue;
}
regs[i].phys_addr = base;
regs[i].reg_size = size;
}
pg_flags = folio->flags; if (pg_flags & (1UL << PG_dcache_dirty)) { int cpu = ((pg_flags >> PG_dcache_cpu_shift) &
PG_dcache_cpu_mask); int this_cpu = get_cpu();
/* This is just to optimize away some function calls * in the SMP case.
*/ if (cpu == this_cpu)
flush_dcache_folio_impl(folio); else
smp_flush_dcache_folio_impl(folio, cpu);
clear_dcache_dirty_cpu(folio, cpu);
put_cpu();
}
}
}
/* mm->context.lock must be held */ staticvoid __update_mmu_tsb_insert(struct mm_struct *mm, unsignedlong tsb_index, unsignedlong tsb_hash_shift, unsignedlong address, unsignedlong tte)
{ struct tsb *tsb = mm->context.tsb_block[tsb_index].tsb; unsignedlong tag;
/* Do not bother with the expensive D-cache flush if it * is merely the zero page. The 'bigcore' testcase in GDB * causes this case to run millions of times.
*/ if (is_zero_pfn(pfn)) return;
this_cpu = get_cpu();
mapping = folio_flush_mapping(folio); if (mapping && !mapping_mapped(mapping)) { bool dirty = test_bit(PG_dcache_dirty, &folio->flags); if (dirty) { int dirty_cpu = dcache_dirty_cpu(folio);
if (dirty_cpu == this_cpu) goto out;
smp_flush_dcache_folio_impl(folio, dirty_cpu);
}
set_dcache_dirty(folio, this_cpu);
} else { /* We could delay the flush for the !folio_mapping * case too. But that case is for exec env/arg * pages and those are %99 certainly going to get * faulted into the tlb (and thus flushed) anyways.
*/
flush_dcache_folio_impl(folio);
}
void __kprobes flush_icache_range(unsignedlong start, unsignedlong end)
{ /* Cheetah and Hypervisor platform cpus have coherent I-cache. */ if (tlb_type == spitfire) { unsignedlong kaddr;
/* This code only runs on Spitfire cpus so this is * why we can assume _PAGE_PADDR_4U.
*/ for (kaddr = start; kaddr < end; kaddr += PAGE_SIZE) { unsignedlong paddr, mask = _PAGE_PADDR_4U;
/* The obp translations are saved based on 8k pagesize, since obp can * use a mixture of pagesizes. Misses to the LOW_OBP_ADDRESS -> * HI_OBP_ADDRESS range are handled in ktlb.S.
*/ staticinlineint in_obp_range(unsignedlong vaddr)
{ return (vaddr >= LOW_OBP_ADDRESS &&
vaddr < HI_OBP_ADDRESS);
}
/* Now kick out all the non-OBP entries. */ for (i = 0; i < ents; i++) { if (in_obp_range(prom_trans[i].virt)) break;
}
first = i; for (; i < ents; i++) { if (!in_obp_range(prom_trans[i].virt)) break;
}
last = i;
for (i = 0; i < (last - first); i++) { struct linux_prom_translation *src = &prom_trans[i + first]; struct linux_prom_translation *dest = &prom_trans[i];
/* Now lock us into the TLBs via Hypervisor or OBP. */ if (tlb_type == hypervisor) { for (i = 0; i < num_kernel_image_mappings; i++) {
hypervisor_tlb_lock(tte_vaddr, tte_data, HV_MMU_DMMU);
hypervisor_tlb_lock(tte_vaddr, tte_data, HV_MMU_IMMU);
tte_vaddr += 0x400000;
tte_data += 0x400000;
}
} else { for (i = 0; i < num_kernel_image_mappings; i++) {
prom_dtlb_load(tlb_ent - i, tte_data, tte_vaddr);
prom_itlb_load(tlb_ent - i, tte_data, tte_vaddr);
tte_vaddr += 0x400000;
tte_data += 0x400000;
}
sparc64_highest_unlocked_tlb_ent = tlb_ent - i;
} if (tlb_type == cheetah_plus) {
sparc64_kern_pri_context = (CTX_CHEETAH_PLUS_CTX0 |
CTX_CHEETAH_PLUS_NUC);
sparc64_kern_pri_nuc_bits = CTX_CHEETAH_PLUS_NUC;
sparc64_kern_sec_context = CTX_CHEETAH_PLUS_CTX0;
}
}
staticvoid __init inherit_prom_mappings(void)
{ /* Now fixup OBP's idea about where we really are mapped. */
printk("Remapping the kernel... ");
remap_kernel();
printk("done.\n");
}
void prom_world(int enter)
{ /* * No need to change the address space any more, just flush * the register windows
*/
__asm__ __volatile__("flushw");
}
/* * Make sure that any new mm that are added into per_cpu_secondary_mm, * are going to go through get_new_mmu_context() path.
*/
mb();
/* * Updated versions to current on those CPUs that had valid secondary * contexts
*/
for_each_online_cpu(cpu) { /* * If a new mm is stored after we took this mm from the array, * it will go into get_new_mmu_context() path, because we * already bumped the version in tlb_context_cache.
*/
mm = per_cpu(per_cpu_secondary_mm, cpu);
/* Caller does TLB context flushing on local CPU if necessary. * The caller also ensures that CTX_VALID(mm->context) is false. * * We must be careful about boundary cases so that we never * let the user have CTX 0 (nucleus) or we ever use a CTX * version of zero (and thus NO_CONTEXT would not be caught * by version mis-match tests in mmu_context.h). * * Always invoked with interrupts disabled.
*/ void get_new_mmu_context(struct mm_struct *mm)
{ unsignedlong ctx, new_ctx; unsignedlong orig_pgsz_bits;
spin_lock(&ctx_alloc_lock);
retry: /* wrap might have happened, test again if our context became valid */ if (unlikely(CTX_VALID(mm->context))) goto out;
orig_pgsz_bits = (mm->context.sparc64_ctx_val & CTX_PGSZ_MASK);
ctx = (tlb_context_cache + 1) & CTX_NR_MASK;
new_ctx = find_next_zero_bit(mmu_context_bmap, 1 << CTX_NR_BITS, ctx); if (new_ctx >= (1 << CTX_NR_BITS)) {
new_ctx = find_next_zero_bit(mmu_context_bmap, ctx, 1); if (new_ctx >= ctx) {
mmu_context_wrap(); goto retry;
}
} if (mm->context.sparc64_ctx_val)
cpumask_clear(mm_cpumask(mm));
mmu_context_bmap[new_ctx>>6] |= (1UL << (new_ctx & 63));
new_ctx |= (tlb_context_cache & CTX_VERSION_MASK);
tlb_context_cache = new_ctx;
mm->context.sparc64_ctx_val = new_ctx | orig_pgsz_bits;
out:
spin_unlock(&ctx_alloc_lock);
}
staticint numa_enabled = 1; staticint numa_debug;
staticint __init early_numa(char *p)
{ if (!p) return 0;
if (strstr(p, "off"))
numa_enabled = 0;
if (strstr(p, "debug"))
numa_debug = 1;
return 0;
}
early_param("numa", early_numa);
#define numadbg(f, a...) \ do { if (numa_debug) \
printk(KERN_INFO f, ## a); \
} while (0)
/* Older versions of the bootloader only supported a * 32-bit physical address for the ramdisk image * location, stored at sparc_ramdisk_image. Newer * SILO versions set sparc_ramdisk_image to zero and * provide a full 64-bit physical address at * sparc_ramdisk_image64.
*/
ramdisk_image = sparc_ramdisk_image; if (!ramdisk_image)
ramdisk_image = sparc_ramdisk_image64;
/* Another bootloader quirk. The bootloader normalizes * the physical address to KERNBASE, so we have to * factor that back out and add in the lowest valid * physical page address to get the true physical address.
*/
ramdisk_image -= KERNBASE;
ramdisk_image += phys_base;
numadbg("Found ramdisk at physical address 0x%lx, size %u\n",
ramdisk_image, sparc_ramdisk_size);
if ((start & p->mask) == p->match) { if (prev_nid == NUMA_NO_NODE)
prev_nid = new_nid; break;
}
}
if (new_nid == num_node_masks) {
prev_nid = 0;
WARN_ONCE(1, "addr[%Lx] doesn't match a NUMA node rule. Some memory will be owned by node 0.",
start); break;
}
if (prev_nid != new_nid) break;
}
*nid = prev_nid;
if (num_node_masks == _nid) { /* We could not find NUMA group, so default to 0, but lets * search for latency group, so we could calculate the correct * end address that we return
*/
_nid = 0;
for (i = 0; i < num_mlgroups; i++) { struct mdesc_mlgroup *const m = &mlgroups[i];
if (i == num_mlgroups) {
WARN_ONCE(1, "memblock_nid_range: Can't find latency group addr[%Lx]",
start);
ret_end = end; goto done;
}
}
/* * Each latency group has match and mask, and each memory block has an * offset. An address belongs to a latency group if its address matches * the following formula: ((addr + offset) & mask) == match * It is, however, slow to check every single page if it matches a * particular latency group. As optimization we calculate end value by * using bit arithmetics.
*/
m_end = m_match + (1ul << __ffs(m_mask)) - mblock->offset;
m_end += pa_start & ~((1ul << fls64(m_mask)) - 1);
ret_end = m_end > end ? end : m_end;
done:
*nid = _nid; return ret_end;
} #endif
/* This must be invoked after performing all of the necessary * memblock_set_node() calls for 'nid'. We need to be able to get * correct data from get_pfn_range_for_nid().
*/ staticvoid __init allocate_node_data(int nid)
{ struct pglist_data *p; unsignedlong start_pfn, end_pfn;
int of_node_to_nid(struct device_node *dp)
{ conststruct linux_prom64_registers *regs; struct mdesc_handle *md;
u32 cfg_handle; int count, nid;
u64 grp;
/* This is the right thing to do on currently supported * SUN4U NUMA platforms as well, as the PCI controller does * not sit behind any particular memory controller.
*/ if (!mlgroups) return -1;
regs = of_get_property(dp, "reg", NULL); if (!regs) return -1;
/* NUMA node id is encoded in bits 36 and higher, and there is * a 1-to-1 mapping from CPU ID to NUMA node ID.
*/
index = 0;
for_each_present_cpu(cpu) {
numa_cpu_lookup_table[cpu] = index;
cpumask_copy(&numa_cpumask_lookup_table[index], cpumask_of(cpu));
node_masks[index].mask = ~((1UL << 36UL) - 1UL);
node_masks[index].match = cpu << 36UL;
index++;
}
num_node_masks = index;
add_node_ranges();
for (index = 0; index < num_node_masks; index++) {
allocate_node_data(index);
node_set_online(index);
}
staticint __init bootmem_init_numa(void)
{ int i, j; int err = -1;
numadbg("bootmem_init_numa()\n");
/* Some sane defaults for numa latency values */ for (i = 0; i < MAX_NUMNODES; i++) { for (j = 0; j < MAX_NUMNODES; j++)
numa_latency[i][j] = (i == j) ?
LOCAL_DISTANCE : REMOTE_DISTANCE;
}
if (numa_enabled) { if (tlb_type == hypervisor)
err = numa_parse_mdesc(); else
err = numa_parse_sun4u();
} return err;
}
/* we should perform an IPI and flush all tlbs, * but that can deadlock->flush only current cpu.
*/
__flush_tlb_kernel_range(PAGE_OFFSET + phys_start,
PAGE_OFFSET + phys_end);
} #endif
unsignedlong __init find_ecache_flush_span(unsignedlong size)
{ int i;
for (i = 0; i < pavail_ents; i++) { if (pavail[i].reg_size >= size) return pavail[i].phys_addr;
}
staticvoid __init setup_page_offset(void)
{ if (tlb_type == cheetah || tlb_type == cheetah_plus) { /* Cheetah/Panther support a full 64-bit virtual * address, so we can use all that our page tables * support.
*/
sparc64_va_hole_top = 0xfff0000000000000UL;
sparc64_va_hole_bottom = 0x0010000000000000UL;
max_phys_bits = 42;
} elseif (tlb_type == hypervisor) { switch (sun4v_chip_type) { case SUN4V_CHIP_NIAGARA1: case SUN4V_CHIP_NIAGARA2: /* T1 and T2 support 48-bit virtual addresses. */
sparc64_va_hole_top = 0xffff800000000000UL;
sparc64_va_hole_bottom = 0x0000800000000000UL;
max_phys_bits = 39; break; case SUN4V_CHIP_NIAGARA3: /* T3 supports 48-bit virtual addresses. */
sparc64_va_hole_top = 0xffff800000000000UL;
sparc64_va_hole_bottom = 0x0000800000000000UL;
max_phys_bits = 43; break; case SUN4V_CHIP_NIAGARA4: case SUN4V_CHIP_NIAGARA5: case SUN4V_CHIP_SPARC64X: case SUN4V_CHIP_SPARC_M6: /* T4 and later support 52-bit virtual addresses. */
sparc64_va_hole_top = 0xfff8000000000000UL;
sparc64_va_hole_bottom = 0x0008000000000000UL;
max_phys_bits = 47; break; case SUN4V_CHIP_SPARC_M7: case SUN4V_CHIP_SPARC_SN: /* M7 and later support 52-bit virtual addresses. */
sparc64_va_hole_top = 0xfff8000000000000UL;
sparc64_va_hole_bottom = 0x0008000000000000UL;
max_phys_bits = 49; break; case SUN4V_CHIP_SPARC_M8: default: /* M8 and later support 54-bit virtual addresses. * However, restricting M8 and above VA bits to 53 * as 4-level page table cannot support more than * 53 VA bits.
*/
sparc64_va_hole_top = 0xfff0000000000000UL;
sparc64_va_hole_bottom = 0x0010000000000000UL;
max_phys_bits = 51; break;
}
}
if (max_phys_bits > MAX_PHYS_ADDRESS_BITS) {
prom_printf("MAX_PHYS_ADDRESS_BITS is too small, need %lu\n",
max_phys_bits);
prom_halt();
}
/* Don't mark as init, we give this to the Hypervisor. */ #ifndef CONFIG_DEBUG_PAGEALLOC #define NUM_KTSB_DESCR 2 #else #define NUM_KTSB_DESCR 1 #endif staticstruct hv_tsb_descr ktsb_descr[NUM_KTSB_DESCR];
/* The swapper TSBs are loaded with a base sequence of: * * sethi %uhi(SYMBOL), REG1 * sethi %hi(SYMBOL), REG2 * or REG1, %ulo(SYMBOL), REG1 * or REG2, %lo(SYMBOL), REG2 * sllx REG1, 32, REG1 * or REG1, REG2, REG1 * * When we use physical addressing for the TSB accesses, we patch the * first four instructions in the above sequence.
*/
pa = kern_base + ((unsignedlong)&ktsb_descr[0] - KERNBASE);
ret = sun4v_mmu_tsb_ctx0(NUM_KTSB_DESCR, pa); if (ret != 0) {
prom_printf("hypervisor_mmu_tsb_ctx0[%lx]: " "errors with %lx\n", pa, ret);
prom_halt();
}
}
staticvoid __init sun4u_linear_pte_xor_finalize(void)
{ #ifndef CONFIG_DEBUG_PAGEALLOC /* This is where we would add Panther support for * 32MB and 256MB pages.
*/ #endif
}
/* Bit 9 of TTE is no longer CV bit on M7 processor and it instead * enables MCD error. Do not set bit 9 on M7 processor.
*/ switch (sun4v_chip_type) { case SUN4V_CHIP_SPARC_M7: case SUN4V_CHIP_SPARC_M8: case SUN4V_CHIP_SPARC_SN:
pagecv_flag = 0x00; break; default:
pagecv_flag = _PAGE_CV_4V; break;
} #ifndef CONFIG_DEBUG_PAGEALLOC if (cpu_pgsz_mask & HV_PGSZ_MASK_256MB) {
kern_linear_pte_xor[1] = (_PAGE_VALID | _PAGE_SZ256MB_4V) ^
PAGE_OFFSET;
kern_linear_pte_xor[1] |= (_PAGE_CP_4V | pagecv_flag |
_PAGE_P_4V | _PAGE_W_4V);
} else {
kern_linear_pte_xor[1] = kern_linear_pte_xor[0];
}
/* We need to exclude reserved regions. This exclusion will include * vmlinux and initrd. To be more precise the initrd size could be used to * compute a new lower limit because it is freed later during initialization.
*/ staticvoid __init reduce_memory(phys_addr_t limit_ram)
{
limit_ram += memblock_reserved_size();
memblock_enforce_memory_limit(limit_ram);
}
/* These build time checkes make sure that the dcache_dirty_cpu() * folio->flags usage will work. * * When a page gets marked as dcache-dirty, we store the * cpu number starting at bit 32 in the folio->flags. Also, * functions like clear_dcache_dirty_cpu use the cpu mask * in 13-bit signed-immediate instruction fields.
*/
/* * Page flags must not reach into upper 32 bits that are used * for the cpu number
*/
BUILD_BUG_ON(NR_PAGEFLAGS > 32);
/* * The bit fields placed in the high range must not reach below * the 32 bit boundary. Otherwise we cannot place the cpu field * at the 32 bit boundary.
*/
BUILD_BUG_ON(SECTIONS_WIDTH + NODES_WIDTH + ZONES_WIDTH +
ilog2(roundup_pow_of_two(NR_CPUS)) > 32);
/* TTE.cv bit on sparc v9 occupies the same position as TTE.mcde * bit on M7 processor. This is a conflicting usage of the same * bit. Enabling TTE.cv on M7 would turn on Memory Corruption * Detection error on all pages and this will lead to problems * later. Kernel does not run with MCD enabled and hence rest * of the required steps to fully configure memory corruption * detection are not taken. We need to ensure TTE.mcde is not * set on M7 processor. Compute the value of cacheability * flag for use later taking this into consideration.
*/ switch (sun4v_chip_type) { case SUN4V_CHIP_SPARC_M7: case SUN4V_CHIP_SPARC_M8: case SUN4V_CHIP_SPARC_SN:
page_cache4v_flag = _PAGE_CP_4V; break; default:
page_cache4v_flag = _PAGE_CACHE_4V; break;
}
if (tlb_type == hypervisor)
sun4v_pgprot_init(); else
sun4u_pgprot_init();
if (tlb_type == hypervisor)
sun4v_patch_tlb_handlers();
/* Find available physical memory... * * Read it twice in order to work around a bug in openfirmware. * The call to grab this table itself can cause openfirmware to * allocate memory, which in turn can take away some space from * the list of available memory. Reading it twice makes sure * we really do get the final value.
*/
read_obp_translations();
read_obp_memory("reg", &pall[0], &pall_ents);
read_obp_memory("available", &pavail[0], &pavail_ents);
read_obp_memory("available", &pavail[0], &pavail_ents);
phys_base = 0xffffffffffffffffUL; for (i = 0; i < pavail_ents; i++) {
phys_base = min(phys_base, pavail[i].phys_addr);
memblock_add(pavail[i].phys_addr, pavail[i].reg_size);
}
memblock_reserve(kern_base, kern_size);
find_ramdisk(phys_base);
if (cmdline_memory_size)
reduce_memory(cmdline_memory_size);
/* Flush the TLBs and the 4M TSB so that the updated linear * pte XOR settings are realized for all mappings.
*/
__flush_tlb_all(); #ifndef CONFIG_DEBUG_PAGEALLOC
memset(swapper_4m_tsb, 0x40, sizeof(swapper_4m_tsb)); #endif
__flush_tlb_all();
staticvoid __init register_page_bootmem_info(void)
{ #ifdef CONFIG_NUMA int i;
for_each_online_node(i) if (NODE_DATA(i)->node_spanned_pages)
register_page_bootmem_info_node(NODE_DATA(i)); #endif
} void __init mem_init(void)
{ /* * Must be done after boot memory is put on freelist, because here we * might set fields in deferred struct pages that have not yet been * initialized, and memblock_free_all() initializes all the reserved * deferred pages for us.
*/
register_page_bootmem_info();
/* * Set up the zero page, mark it reserved, so that page count * is not manipulated when freeing the page from user ptes.
*/
mem_map_zero = alloc_pages(GFP_KERNEL|__GFP_ZERO, 0); if (mem_map_zero == NULL) {
prom_printf("paging_init: Cannot alloc zero page.\n");
prom_halt();
}
mark_page_reserved(mem_map_zero);
if (tlb_type == cheetah || tlb_type == cheetah_plus)
cheetah_ecache_flush_init();
}
void free_initmem(void)
{ unsignedlong addr, initend; int do_free = 1;
/* If the physical memory maps were trimmed by kernel command * line options, don't even try freeing this initmem stuff up. * The kernel image could have been in the trimmed out region * and if so the freeing below will free invalid page structs.
*/ if (cmdline_memory_size)
do_free = 0;
/* * The init section is aligned to 8k in vmlinux.lds. Page align for >8k pagesizes.
*/
addr = PAGE_ALIGN((unsignedlong)(__init_begin));
initend = (unsignedlong)(__init_end) & PAGE_MASK; for (; addr < initend; addr += PAGE_SIZE) { unsignedlong page;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.