199767f8919635c4928607450d9e0abb932109ceToomas Soome/*-
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Initial implementation:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 2001 Robert Drehmel
199767f8919635c4928607450d9e0abb932109ceToomas Soome * All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * As long as the above copyright statement and this notice remain
199767f8919635c4928607450d9e0abb932109ceToomas Soome * unchanged, you can do what ever you want with this file.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*-
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 2008 - 2012 Marius Strobl <marius@FreeBSD.org>
199767f8919635c4928607450d9e0abb932109ceToomas Soome * All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Redistribution and use in source and binary forms, with or without
199767f8919635c4928607450d9e0abb932109ceToomas Soome * modification, are permitted provided that the following conditions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * are met:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1. Redistributions of source code must retain the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer in the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * documentation and/or other materials provided with the distribution.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
199767f8919635c4928607450d9e0abb932109ceToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
199767f8919635c4928607450d9e0abb932109ceToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
199767f8919635c4928607450d9e0abb932109ceToomas Soome * SUCH DAMAGE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/cdefs.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome__FBSDID("$FreeBSD$");
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * FreeBSD/sparc64 kernel loader - machine dependent part
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * - implements copyin and readin functions that map kernel
199767f8919635c4928607450d9e0abb932109ceToomas Soome * pages on demand. The machine independent code does not
199767f8919635c4928607450d9e0abb932109ceToomas Soome * know the size of the kernel early enough to pre-enter
199767f8919635c4928607450d9e0abb932109ceToomas Soome * TTEs and install just one 4MB mapping seemed to limiting
199767f8919635c4928607450d9e0abb932109ceToomas Soome * to me.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <stand.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/param.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/exec.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/linker.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/queue.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/types.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef LOADER_ZFS_SUPPORT
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/vtoc.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "../zfs/libzfs.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <vm/vm.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <machine/asi.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <machine/cmt.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <machine/cpufunc.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <machine/elf.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <machine/fireplane.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <machine/jbus.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <machine/lsu.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <machine/metadata.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <machine/tte.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <machine/tlb.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <machine/upa.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <machine/ver.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <machine/vmparam.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "bootstrap.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "libofw.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "dev_net.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern char bootprog_name[], bootprog_rev[], bootprog_date[], bootprog_maker[];
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeenum {
199767f8919635c4928607450d9e0abb932109ceToomas Soome HEAPVA = 0x800000,
199767f8919635c4928607450d9e0abb932109ceToomas Soome HEAPSZ = 0x1000000,
199767f8919635c4928607450d9e0abb932109ceToomas Soome LOADSZ = 0x1000000 /* for kernel and modules */
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* At least Sun Fire V1280 require page sized allocations to be claimed. */
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCTASSERT(HEAPSZ % PAGE_SIZE == 0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic struct mmu_ops {
199767f8919635c4928607450d9e0abb932109ceToomas Soome void (*tlb_init)(void);
199767f8919635c4928607450d9e0abb932109ceToomas Soome int (*mmu_mapin)(vm_offset_t va, vm_size_t len);
199767f8919635c4928607450d9e0abb932109ceToomas Soome} *mmu_ops;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef void kernel_entry_t(vm_offset_t mdp, u_long o1, u_long o2, u_long o3,
199767f8919635c4928607450d9e0abb932109ceToomas Soome void *openfirmware);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic inline u_long dtlb_get_data_sun4u(u_int, u_int);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int dtlb_enter_sun4u(u_int, u_long data, vm_offset_t);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic vm_offset_t dtlb_va_to_pa_sun4u(vm_offset_t);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic inline u_long itlb_get_data_sun4u(u_int, u_int);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int itlb_enter_sun4u(u_int, u_long data, vm_offset_t);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic vm_offset_t itlb_va_to_pa_sun4u(vm_offset_t);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void itlb_relocate_locked0_sun4u(void);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern vm_offset_t md_load(char *, vm_offset_t *, vm_offset_t *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int sparc64_autoload(void);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic ssize_t sparc64_readin(const int, vm_offset_t, const size_t);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic ssize_t sparc64_copyin(const void *, vm_offset_t, size_t);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic vm_offset_t claim_virt(vm_offset_t, size_t, int);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic vm_offset_t alloc_phys(size_t, int);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int map_phys(int, size_t, vm_offset_t, vm_offset_t);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void release_phys(vm_offset_t, u_int);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int __elfN(exec)(struct preloaded_file *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int mmu_mapin_sun4u(vm_offset_t, vm_size_t);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic vm_offset_t init_heap(void);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic phandle_t find_bsp_sun4u(phandle_t, uint32_t);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeconst char *cpu_cpuid_prop_sun4u(void);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeuint32_t cpu_get_mid_sun4u(void);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void tlb_init_sun4u(void);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef LOADER_DEBUG
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef u_int64_t tte_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void pmap_print_tlb_sun4u(void);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void pmap_print_tte_sun4u(tte_t, tte_t);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic struct mmu_ops mmu_ops_sun4u = { tlb_init_sun4u, mmu_mapin_sun4u };
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* sun4u */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct tlb_entry *dtlb_store;
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct tlb_entry *itlb_store;
199767f8919635c4928607450d9e0abb932109ceToomas Soomeu_int dtlb_slot;
199767f8919635c4928607450d9e0abb932109ceToomas Soomeu_int itlb_slot;
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int cpu_impl;
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic u_int dtlb_slot_max;
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic u_int itlb_slot_max;
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic u_int tlb_locked;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic vm_offset_t curkva = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic vm_offset_t heapva;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic char bootpath[64];
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic phandle_t root;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef LOADER_ZFS_SUPPORT
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic struct zfs_devdesc zfs_currdev;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Machine dependent structures that the machine independent
199767f8919635c4928607450d9e0abb932109ceToomas Soome * loader part uses.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct devsw *devsw[] = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef LOADER_DISK_SUPPORT
199767f8919635c4928607450d9e0abb932109ceToomas Soome &ofwdisk,
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef LOADER_NET_SUPPORT
199767f8919635c4928607450d9e0abb932109ceToomas Soome &netdev,
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef LOADER_ZFS_SUPPORT
199767f8919635c4928607450d9e0abb932109ceToomas Soome &zfs_dev,
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome NULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct arch_switch archsw;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic struct file_format sparc64_elf = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome __elfN(loadfile),
199767f8919635c4928607450d9e0abb932109ceToomas Soome __elfN(exec)
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct file_format *file_formats[] = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome &sparc64_elf,
199767f8919635c4928607450d9e0abb932109ceToomas Soome NULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct fs_ops *file_system[] = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef LOADER_ZFS_SUPPORT
199767f8919635c4928607450d9e0abb932109ceToomas Soome &zfs_fsops,
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef LOADER_UFS_SUPPORT
199767f8919635c4928607450d9e0abb932109ceToomas Soome &ufs_fsops,
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef LOADER_CD9660_SUPPORT
199767f8919635c4928607450d9e0abb932109ceToomas Soome &cd9660_fsops,
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef LOADER_ZIP_SUPPORT
199767f8919635c4928607450d9e0abb932109ceToomas Soome &zipfs_fsops,
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef LOADER_GZIP_SUPPORT
199767f8919635c4928607450d9e0abb932109ceToomas Soome &gzipfs_fsops,
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef LOADER_BZIP2_SUPPORT
199767f8919635c4928607450d9e0abb932109ceToomas Soome &bzipfs_fsops,
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef LOADER_NFS_SUPPORT
199767f8919635c4928607450d9e0abb932109ceToomas Soome &nfs_fsops,
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef LOADER_TFTP_SUPPORT
199767f8919635c4928607450d9e0abb932109ceToomas Soome &tftp_fsops,
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome NULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct netif_driver *netif_drivers[] = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef LOADER_NET_SUPPORT
199767f8919635c4928607450d9e0abb932109ceToomas Soome &ofwnet,
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome NULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern struct console ofwconsole;
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct console *consoles[] = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome &ofwconsole,
199767f8919635c4928607450d9e0abb932109ceToomas Soome NULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef LOADER_DEBUG
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int
199767f8919635c4928607450d9e0abb932109ceToomas Soomewatch_phys_set_mask(vm_offset_t pa, u_long mask)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_long lsucr;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome stxa(AA_DMMU_PWPR, ASI_DMMU, pa & (((2UL << 38) - 1) << 3));
199767f8919635c4928607450d9e0abb932109ceToomas Soome lsucr = ldxa(0, ASI_LSU_CTL_REG);
199767f8919635c4928607450d9e0abb932109ceToomas Soome lsucr = ((lsucr | LSU_PW) & ~LSU_PM_MASK) |
199767f8919635c4928607450d9e0abb932109ceToomas Soome (mask << LSU_PM_SHIFT);
199767f8919635c4928607450d9e0abb932109ceToomas Soome stxa(0, ASI_LSU_CTL_REG, lsucr);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int
199767f8919635c4928607450d9e0abb932109ceToomas Soomewatch_phys_set(vm_offset_t pa, int sz)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_long off;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome off = (u_long)pa & 7;
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Test for misaligned watch points. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (off + sz > 8)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (watch_phys_set_mask(pa, ((1 << sz) - 1) << off));
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int
199767f8919635c4928607450d9e0abb932109ceToomas Soomewatch_virt_set_mask(vm_offset_t va, u_long mask)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_long lsucr;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome stxa(AA_DMMU_VWPR, ASI_DMMU, va & (((2UL << 41) - 1) << 3));
199767f8919635c4928607450d9e0abb932109ceToomas Soome lsucr = ldxa(0, ASI_LSU_CTL_REG);
199767f8919635c4928607450d9e0abb932109ceToomas Soome lsucr = ((lsucr | LSU_VW) & ~LSU_VM_MASK) |
199767f8919635c4928607450d9e0abb932109ceToomas Soome (mask << LSU_VM_SHIFT);
199767f8919635c4928607450d9e0abb932109ceToomas Soome stxa(0, ASI_LSU_CTL_REG, lsucr);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int
199767f8919635c4928607450d9e0abb932109ceToomas Soomewatch_virt_set(vm_offset_t va, int sz)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_long off;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome off = (u_long)va & 7;
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Test for misaligned watch points. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (off + sz > 8)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (watch_virt_set_mask(va, ((1 << sz) - 1) << off));
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * archsw functions
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int
199767f8919635c4928607450d9e0abb932109ceToomas Soomesparc64_autoload(void)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic ssize_t
199767f8919635c4928607450d9e0abb932109ceToomas Soomesparc64_readin(const int fd, vm_offset_t va, const size_t len)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome mmu_ops->mmu_mapin(va, len);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (read(fd, (void *)va, len));
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic ssize_t
199767f8919635c4928607450d9e0abb932109ceToomas Soomesparc64_copyin(const void *src, vm_offset_t dest, size_t len)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome mmu_ops->mmu_mapin(dest, len);
199767f8919635c4928607450d9e0abb932109ceToomas Soome memcpy((void *)dest, src, len);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (len);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * other MD functions
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic vm_offset_t
199767f8919635c4928607450d9e0abb932109ceToomas Soomeclaim_virt(vm_offset_t virt, size_t size, int align)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome vm_offset_t mva;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (OF_call_method("claim", mmu, 3, 1, virt, size, align, &mva) == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return ((vm_offset_t)-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (mva);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic vm_offset_t
199767f8919635c4928607450d9e0abb932109ceToomas Soomealloc_phys(size_t size, int align)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t phys_hi, phys_low;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (OF_call_method("claim", memory, 2, 2, size, align, &phys_low,
199767f8919635c4928607450d9e0abb932109ceToomas Soome &phys_hi) == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return ((vm_offset_t)-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return ((vm_offset_t)phys_hi << 32 | phys_low);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int
199767f8919635c4928607450d9e0abb932109ceToomas Soomemap_phys(int mode, size_t size, vm_offset_t virt, vm_offset_t phys)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (OF_call_method("map", mmu, 5, 0, (uint32_t)phys,
199767f8919635c4928607450d9e0abb932109ceToomas Soome (uint32_t)(phys >> 32), virt, size, mode));
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void
199767f8919635c4928607450d9e0abb932109ceToomas Soomerelease_phys(vm_offset_t phys, u_int size)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome (void)OF_call_method("release", memory, 3, 0, (uint32_t)phys,
199767f8919635c4928607450d9e0abb932109ceToomas Soome (uint32_t)(phys >> 32), size);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int
199767f8919635c4928607450d9e0abb932109ceToomas Soome__elfN(exec)(struct preloaded_file *fp)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct file_metadata *fmp;
199767f8919635c4928607450d9e0abb932109ceToomas Soome vm_offset_t mdp, dtbp;
199767f8919635c4928607450d9e0abb932109ceToomas Soome Elf_Addr entry;
199767f8919635c4928607450d9e0abb932109ceToomas Soome Elf_Ehdr *e;
199767f8919635c4928607450d9e0abb932109ceToomas Soome int error;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((fmp = file_findmetadata(fp, MODINFOMD_ELFHDR)) == 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (EFTYPE);
199767f8919635c4928607450d9e0abb932109ceToomas Soome e = (Elf_Ehdr *)&fmp->md_data;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((error = md_load(fp->f_args, &mdp, &dtbp)) != 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (error);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("jumping to kernel entry at %#lx.\n", e->e_entry);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef LOADER_DEBUG
199767f8919635c4928607450d9e0abb932109ceToomas Soome pmap_print_tlb_sun4u();
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome dev_cleanup();
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome entry = e->e_entry;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome OF_release((void *)heapva, HEAPSZ);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((kernel_entry_t *)entry)(mdp, 0, 0, 0, openfirmware);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome panic("%s: exec returned", __func__);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic inline u_long
199767f8919635c4928607450d9e0abb932109ceToomas Soomedtlb_get_data_sun4u(u_int tlb, u_int slot)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_long data, pstate;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome slot = TLB_DAR_SLOT(tlb, slot);
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * We read ASI_DTLB_DATA_ACCESS_REG twice back-to-back in order to
199767f8919635c4928607450d9e0abb932109ceToomas Soome * work around errata of USIII and beyond.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome pstate = rdpr(pstate);
199767f8919635c4928607450d9e0abb932109ceToomas Soome wrpr(pstate, pstate & ~PSTATE_IE, 0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome (void)ldxa(slot, ASI_DTLB_DATA_ACCESS_REG);
199767f8919635c4928607450d9e0abb932109ceToomas Soome data = ldxa(slot, ASI_DTLB_DATA_ACCESS_REG);
199767f8919635c4928607450d9e0abb932109ceToomas Soome wrpr(pstate, pstate, 0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (data);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic inline u_long
199767f8919635c4928607450d9e0abb932109ceToomas Soomeitlb_get_data_sun4u(u_int tlb, u_int slot)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_long data, pstate;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome slot = TLB_DAR_SLOT(tlb, slot);
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * We read ASI_DTLB_DATA_ACCESS_REG twice back-to-back in order to
199767f8919635c4928607450d9e0abb932109ceToomas Soome * work around errata of USIII and beyond.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome pstate = rdpr(pstate);
199767f8919635c4928607450d9e0abb932109ceToomas Soome wrpr(pstate, pstate & ~PSTATE_IE, 0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome (void)ldxa(slot, ASI_ITLB_DATA_ACCESS_REG);
199767f8919635c4928607450d9e0abb932109ceToomas Soome data = ldxa(slot, ASI_ITLB_DATA_ACCESS_REG);
199767f8919635c4928607450d9e0abb932109ceToomas Soome wrpr(pstate, pstate, 0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (data);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic vm_offset_t
199767f8919635c4928607450d9e0abb932109ceToomas Soomedtlb_va_to_pa_sun4u(vm_offset_t va)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_long pstate, reg;
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int i, tlb;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome pstate = rdpr(pstate);
199767f8919635c4928607450d9e0abb932109ceToomas Soome wrpr(pstate, pstate & ~PSTATE_IE, 0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < dtlb_slot_max; i++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome reg = ldxa(TLB_DAR_SLOT(tlb_locked, i),
199767f8919635c4928607450d9e0abb932109ceToomas Soome ASI_DTLB_TAG_READ_REG);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (TLB_TAR_VA(reg) != va)
199767f8919635c4928607450d9e0abb932109ceToomas Soome continue;
199767f8919635c4928607450d9e0abb932109ceToomas Soome reg = dtlb_get_data_sun4u(tlb_locked, i);
199767f8919635c4928607450d9e0abb932109ceToomas Soome wrpr(pstate, pstate, 0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome reg >>= TD_PA_SHIFT;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (cpu_impl == CPU_IMPL_SPARC64V ||
199767f8919635c4928607450d9e0abb932109ceToomas Soome cpu_impl >= CPU_IMPL_ULTRASPARCIII)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (reg & TD_PA_CH_MASK);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (reg & TD_PA_SF_MASK);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome wrpr(pstate, pstate, 0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic vm_offset_t
199767f8919635c4928607450d9e0abb932109ceToomas Soomeitlb_va_to_pa_sun4u(vm_offset_t va)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_long pstate, reg;
199767f8919635c4928607450d9e0abb932109ceToomas Soome int i;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome pstate = rdpr(pstate);
199767f8919635c4928607450d9e0abb932109ceToomas Soome wrpr(pstate, pstate & ~PSTATE_IE, 0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < itlb_slot_max; i++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome reg = ldxa(TLB_DAR_SLOT(tlb_locked, i),
199767f8919635c4928607450d9e0abb932109ceToomas Soome ASI_ITLB_TAG_READ_REG);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (TLB_TAR_VA(reg) != va)
199767f8919635c4928607450d9e0abb932109ceToomas Soome continue;
199767f8919635c4928607450d9e0abb932109ceToomas Soome reg = itlb_get_data_sun4u(tlb_locked, i);
199767f8919635c4928607450d9e0abb932109ceToomas Soome wrpr(pstate, pstate, 0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome reg >>= TD_PA_SHIFT;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (cpu_impl == CPU_IMPL_SPARC64V ||
199767f8919635c4928607450d9e0abb932109ceToomas Soome cpu_impl >= CPU_IMPL_ULTRASPARCIII)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (reg & TD_PA_CH_MASK);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (reg & TD_PA_SF_MASK);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome wrpr(pstate, pstate, 0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int
199767f8919635c4928607450d9e0abb932109ceToomas Soomedtlb_enter_sun4u(u_int index, u_long data, vm_offset_t virt)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (OF_call_method("SUNW,dtlb-load", mmu, 3, 0, index, data,
199767f8919635c4928607450d9e0abb932109ceToomas Soome virt));
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int
199767f8919635c4928607450d9e0abb932109ceToomas Soomeitlb_enter_sun4u(u_int index, u_long data, vm_offset_t virt)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (cpu_impl == CPU_IMPL_ULTRASPARCIIIp && index == 0 &&
199767f8919635c4928607450d9e0abb932109ceToomas Soome (data & TD_L) != 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome panic("%s: won't enter locked TLB entry at index 0 on USIII+",
199767f8919635c4928607450d9e0abb932109ceToomas Soome __func__);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (OF_call_method("SUNW,itlb-load", mmu, 3, 0, index, data,
199767f8919635c4928607450d9e0abb932109ceToomas Soome virt));
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void
199767f8919635c4928607450d9e0abb932109ceToomas Soomeitlb_relocate_locked0_sun4u(void)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_long data, pstate, tag;
199767f8919635c4928607450d9e0abb932109ceToomas Soome int i;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (cpu_impl != CPU_IMPL_ULTRASPARCIIIp)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome pstate = rdpr(pstate);
199767f8919635c4928607450d9e0abb932109ceToomas Soome wrpr(pstate, pstate & ~PSTATE_IE, 0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome data = itlb_get_data_sun4u(tlb_locked, 0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((data & (TD_V | TD_L)) != (TD_V | TD_L)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome wrpr(pstate, pstate, 0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Flush the mapping of slot 0. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome tag = ldxa(TLB_DAR_SLOT(tlb_locked, 0), ASI_ITLB_TAG_READ_REG);
199767f8919635c4928607450d9e0abb932109ceToomas Soome stxa(TLB_DEMAP_VA(TLB_TAR_VA(tag)) | TLB_DEMAP_PRIMARY |
199767f8919635c4928607450d9e0abb932109ceToomas Soome TLB_DEMAP_PAGE, ASI_IMMU_DEMAP, 0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome flush(0); /* The USIII-family ignores the address. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Search a replacement slot != 0 and enter the data and tag
199767f8919635c4928607450d9e0abb932109ceToomas Soome * that formerly were in slot 0.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 1; i < itlb_slot_max; i++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((itlb_get_data_sun4u(tlb_locked, i) & TD_V) != 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome continue;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome stxa(AA_IMMU_TAR, ASI_IMMU, tag);
199767f8919635c4928607450d9e0abb932109ceToomas Soome stxa(TLB_DAR_SLOT(tlb_locked, i), ASI_ITLB_DATA_ACCESS_REG,
199767f8919635c4928607450d9e0abb932109ceToomas Soome data);
199767f8919635c4928607450d9e0abb932109ceToomas Soome flush(0); /* The USIII-family ignores the address. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome wrpr(pstate, pstate, 0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (i == itlb_slot_max)
199767f8919635c4928607450d9e0abb932109ceToomas Soome panic("%s: could not find a replacement slot", __func__);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int
199767f8919635c4928607450d9e0abb932109ceToomas Soomemmu_mapin_sun4u(vm_offset_t va, vm_size_t len)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome vm_offset_t pa, mva;
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_long data;
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int index;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (va + len > curkva)
199767f8919635c4928607450d9e0abb932109ceToomas Soome curkva = va + len;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome pa = (vm_offset_t)-1;
199767f8919635c4928607450d9e0abb932109ceToomas Soome len += va & PAGE_MASK_4M;
199767f8919635c4928607450d9e0abb932109ceToomas Soome va &= ~PAGE_MASK_4M;
199767f8919635c4928607450d9e0abb932109ceToomas Soome while (len) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (dtlb_va_to_pa_sun4u(va) == (vm_offset_t)-1 ||
199767f8919635c4928607450d9e0abb932109ceToomas Soome itlb_va_to_pa_sun4u(va) == (vm_offset_t)-1) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Allocate a physical page, claim the virtual area. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (pa == (vm_offset_t)-1) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome pa = alloc_phys(PAGE_SIZE_4M, PAGE_SIZE_4M);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (pa == (vm_offset_t)-1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome panic("%s: out of memory", __func__);
199767f8919635c4928607450d9e0abb932109ceToomas Soome mva = claim_virt(va, PAGE_SIZE_4M, 0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (mva != va)
199767f8919635c4928607450d9e0abb932109ceToomas Soome panic("%s: can't claim virtual page "
199767f8919635c4928607450d9e0abb932109ceToomas Soome "(wanted %#lx, got %#lx)",
199767f8919635c4928607450d9e0abb932109ceToomas Soome __func__, va, mva);
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The mappings may have changed, be paranoid.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome continue;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Actually, we can only allocate two pages less at
199767f8919635c4928607450d9e0abb932109ceToomas Soome * most (depending on the kernel TSB size).
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (dtlb_slot >= dtlb_slot_max)
199767f8919635c4928607450d9e0abb932109ceToomas Soome panic("%s: out of dtlb_slots", __func__);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (itlb_slot >= itlb_slot_max)
199767f8919635c4928607450d9e0abb932109ceToomas Soome panic("%s: out of itlb_slots", __func__);
199767f8919635c4928607450d9e0abb932109ceToomas Soome data = TD_V | TD_4M | TD_PA(pa) | TD_L | TD_CP |
199767f8919635c4928607450d9e0abb932109ceToomas Soome TD_CV | TD_P | TD_W;
199767f8919635c4928607450d9e0abb932109ceToomas Soome dtlb_store[dtlb_slot].te_pa = pa;
199767f8919635c4928607450d9e0abb932109ceToomas Soome dtlb_store[dtlb_slot].te_va = va;
199767f8919635c4928607450d9e0abb932109ceToomas Soome index = dtlb_slot_max - dtlb_slot - 1;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (dtlb_enter_sun4u(index, data, va) < 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome panic("%s: can't enter dTLB slot %d data "
199767f8919635c4928607450d9e0abb932109ceToomas Soome "%#lx va %#lx", __func__, index, data,
199767f8919635c4928607450d9e0abb932109ceToomas Soome va);
199767f8919635c4928607450d9e0abb932109ceToomas Soome dtlb_slot++;
199767f8919635c4928607450d9e0abb932109ceToomas Soome itlb_store[itlb_slot].te_pa = pa;
199767f8919635c4928607450d9e0abb932109ceToomas Soome itlb_store[itlb_slot].te_va = va;
199767f8919635c4928607450d9e0abb932109ceToomas Soome index = itlb_slot_max - itlb_slot - 1;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (itlb_enter_sun4u(index, data, va) < 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome panic("%s: can't enter iTLB slot %d data "
199767f8919635c4928607450d9e0abb932109ceToomas Soome "%#lx va %#lxd", __func__, index, data,
199767f8919635c4928607450d9e0abb932109ceToomas Soome va);
199767f8919635c4928607450d9e0abb932109ceToomas Soome itlb_slot++;
199767f8919635c4928607450d9e0abb932109ceToomas Soome pa = (vm_offset_t)-1;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome len -= len > PAGE_SIZE_4M ? PAGE_SIZE_4M : len;
199767f8919635c4928607450d9e0abb932109ceToomas Soome va += PAGE_SIZE_4M;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (pa != (vm_offset_t)-1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome release_phys(pa, PAGE_SIZE_4M);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic vm_offset_t
199767f8919635c4928607450d9e0abb932109ceToomas Soomeinit_heap(void)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* There is no need for continuous physical heap memory. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome heapva = (vm_offset_t)OF_claim((void *)HEAPVA, HEAPSZ, 32);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (heapva);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic phandle_t
199767f8919635c4928607450d9e0abb932109ceToomas Soomefind_bsp_sun4u(phandle_t node, uint32_t bspid)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome char type[sizeof("cpu")];
199767f8919635c4928607450d9e0abb932109ceToomas Soome phandle_t child;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t cpuid;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (; node > 0; node = OF_peer(node)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome child = OF_child(node);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (child > 0) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome child = find_bsp_sun4u(child, bspid);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (child > 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (child);
199767f8919635c4928607450d9e0abb932109ceToomas Soome } else {
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (OF_getprop(node, "device_type", type,
199767f8919635c4928607450d9e0abb932109ceToomas Soome sizeof(type)) <= 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome continue;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (strcmp(type, "cpu") != 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome continue;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (OF_getprop(node, cpu_cpuid_prop_sun4u(), &cpuid,
199767f8919635c4928607450d9e0abb932109ceToomas Soome sizeof(cpuid)) <= 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome continue;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (cpuid == bspid)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (node);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeconst char *
199767f8919635c4928607450d9e0abb932109ceToomas Soomecpu_cpuid_prop_sun4u(void)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome switch (cpu_impl) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_SPARC64:
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_SPARC64V:
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_ULTRASPARCI:
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_ULTRASPARCII:
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_ULTRASPARCIIi:
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_ULTRASPARCIIe:
199767f8919635c4928607450d9e0abb932109ceToomas Soome return ("upa-portid");
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_ULTRASPARCIII:
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_ULTRASPARCIIIp:
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_ULTRASPARCIIIi:
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_ULTRASPARCIIIip:
199767f8919635c4928607450d9e0abb932109ceToomas Soome return ("portid");
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_ULTRASPARCIV:
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_ULTRASPARCIVp:
199767f8919635c4928607450d9e0abb932109ceToomas Soome return ("cpuid");
199767f8919635c4928607450d9e0abb932109ceToomas Soome default:
199767f8919635c4928607450d9e0abb932109ceToomas Soome return ("");
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeuint32_t
199767f8919635c4928607450d9e0abb932109ceToomas Soomecpu_get_mid_sun4u(void)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome switch (cpu_impl) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_SPARC64:
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_SPARC64V:
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_ULTRASPARCI:
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_ULTRASPARCII:
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_ULTRASPARCIIi:
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_ULTRASPARCIIe:
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (UPA_CR_GET_MID(ldxa(0, ASI_UPA_CONFIG_REG)));
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_ULTRASPARCIII:
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_ULTRASPARCIIIp:
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (FIREPLANE_CR_GET_AID(ldxa(AA_FIREPLANE_CONFIG,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ASI_FIREPLANE_CONFIG_REG)));
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_ULTRASPARCIIIi:
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_ULTRASPARCIIIip:
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (JBUS_CR_GET_JID(ldxa(0, ASI_JBUS_CONFIG_REG)));
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_ULTRASPARCIV:
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_ULTRASPARCIVp:
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (INTR_ID_GET_ID(ldxa(AA_INTR_ID, ASI_INTR_ID)));
199767f8919635c4928607450d9e0abb932109ceToomas Soome default:
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void
199767f8919635c4928607450d9e0abb932109ceToomas Soometlb_init_sun4u(void)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome phandle_t bsp;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome cpu_impl = VER_IMPL(rdpr(ver));
199767f8919635c4928607450d9e0abb932109ceToomas Soome switch (cpu_impl) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_SPARC64:
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_ULTRASPARCI:
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_ULTRASPARCII:
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_ULTRASPARCIIi:
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_ULTRASPARCIIe:
199767f8919635c4928607450d9e0abb932109ceToomas Soome tlb_locked = TLB_DAR_T32;
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_ULTRASPARCIII:
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_ULTRASPARCIIIp:
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_ULTRASPARCIIIi:
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_ULTRASPARCIIIip:
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_ULTRASPARCIV:
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_ULTRASPARCIVp:
199767f8919635c4928607450d9e0abb932109ceToomas Soome tlb_locked = TLB_DAR_T16;
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome case CPU_IMPL_SPARC64V:
199767f8919635c4928607450d9e0abb932109ceToomas Soome tlb_locked = TLB_DAR_FTLB;
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome bsp = find_bsp_sun4u(OF_child(root), cpu_get_mid_sun4u());
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (bsp == 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome panic("%s: no node for bootcpu?!?!", __func__);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (OF_getprop(bsp, "#dtlb-entries", &dtlb_slot_max,
199767f8919635c4928607450d9e0abb932109ceToomas Soome sizeof(dtlb_slot_max)) == -1 ||
199767f8919635c4928607450d9e0abb932109ceToomas Soome OF_getprop(bsp, "#itlb-entries", &itlb_slot_max,
199767f8919635c4928607450d9e0abb932109ceToomas Soome sizeof(itlb_slot_max)) == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome panic("%s: can't get TLB slot max.", __func__);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (cpu_impl == CPU_IMPL_ULTRASPARCIIIp) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef LOADER_DEBUG
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("pre fixup:\n");
199767f8919635c4928607450d9e0abb932109ceToomas Soome pmap_print_tlb_sun4u();
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Relocate the locked entry in it16 slot 0 (if existent)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * as part of working around Cheetah+ erratum 34.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome itlb_relocate_locked0_sun4u();
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef LOADER_DEBUG
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("post fixup:\n");
199767f8919635c4928607450d9e0abb932109ceToomas Soome pmap_print_tlb_sun4u();
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome dtlb_store = malloc(dtlb_slot_max * sizeof(*dtlb_store));
199767f8919635c4928607450d9e0abb932109ceToomas Soome itlb_store = malloc(itlb_slot_max * sizeof(*itlb_store));
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (dtlb_store == NULL || itlb_store == NULL)
199767f8919635c4928607450d9e0abb932109ceToomas Soome panic("%s: can't allocate TLB store", __func__);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef LOADER_ZFS_SUPPORT
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void
199767f8919635c4928607450d9e0abb932109ceToomas Soomesparc64_zfs_probe(void)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct vtoc8 vtoc;
199767f8919635c4928607450d9e0abb932109ceToomas Soome char alias[64], devname[sizeof(alias) + sizeof(":x") - 1];
199767f8919635c4928607450d9e0abb932109ceToomas Soome char type[sizeof("device_type")];
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *bdev, *dev, *odev;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t guid;
199767f8919635c4928607450d9e0abb932109ceToomas Soome int fd, len, part;
199767f8919635c4928607450d9e0abb932109ceToomas Soome phandle_t aliases, options;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Get the GUID of the ZFS pool on the boot device. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome guid = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome zfs_probe_dev(bootpath, &guid);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Get the GUIDs of the ZFS pools on any additional disks listed in
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the boot-device environment variable.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((aliases = OF_finddevice("/aliases")) == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome goto out;
199767f8919635c4928607450d9e0abb932109ceToomas Soome options = OF_finddevice("/options");
199767f8919635c4928607450d9e0abb932109ceToomas Soome len = OF_getproplen(options, "boot-device");
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (len <= 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome goto out;
199767f8919635c4928607450d9e0abb932109ceToomas Soome bdev = odev = malloc(len + 1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (bdev == NULL)
199767f8919635c4928607450d9e0abb932109ceToomas Soome goto out;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (OF_getprop(options, "boot-device", bdev, len) <= 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome goto out;
199767f8919635c4928607450d9e0abb932109ceToomas Soome bdev[len] = '\0';
199767f8919635c4928607450d9e0abb932109ceToomas Soome while ((dev = strsep(&bdev, " ")) != NULL) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (*dev == '\0')
199767f8919635c4928607450d9e0abb932109ceToomas Soome continue;
199767f8919635c4928607450d9e0abb932109ceToomas Soome strcpy(alias, dev);
199767f8919635c4928607450d9e0abb932109ceToomas Soome (void)OF_getprop(aliases, dev, alias, sizeof(alias));
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Don't probe the boot disk twice. Note that bootpath
199767f8919635c4928607450d9e0abb932109ceToomas Soome * includes the partition specifier.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (strncmp(alias, bootpath, strlen(alias)) == 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome continue;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (OF_getprop(OF_finddevice(alias), "device_type", type,
199767f8919635c4928607450d9e0abb932109ceToomas Soome sizeof(type)) == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome continue;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (strcmp(type, "block") != 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome continue;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Find freebsd-zfs slices in the VTOC. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome fd = open(alias, O_RDONLY);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (fd == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome continue;
199767f8919635c4928607450d9e0abb932109ceToomas Soome lseek(fd, 0, SEEK_SET);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (read(fd, &vtoc, sizeof(vtoc)) != sizeof(vtoc)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome close(fd);
199767f8919635c4928607450d9e0abb932109ceToomas Soome continue;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome close(fd);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (part = 0; part < 8; part++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (part == 2 || vtoc.part[part].tag !=
199767f8919635c4928607450d9e0abb932109ceToomas Soome VTOC_TAG_FREEBSD_ZFS)
199767f8919635c4928607450d9e0abb932109ceToomas Soome continue;
199767f8919635c4928607450d9e0abb932109ceToomas Soome (void)sprintf(devname, "%s:%c", alias, part + 'a');
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (zfs_probe_dev(devname, NULL) == ENXIO)
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome free(odev);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome out:
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (guid != 0) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome zfs_currdev.pool_guid = guid;
199767f8919635c4928607450d9e0abb932109ceToomas Soome zfs_currdev.root_guid = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome zfs_currdev.d_dev = &zfs_dev;
199767f8919635c4928607450d9e0abb932109ceToomas Soome zfs_currdev.d_type = zfs_currdev.d_dev->dv_type;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* LOADER_ZFS_SUPPORT */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint
199767f8919635c4928607450d9e0abb932109ceToomas Soomemain(int (*openfirm)(void *))
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome char compatible[32];
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct devsw **dp;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Tell the Open Firmware functions where they find the OFW gate.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome OF_init(openfirm);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome archsw.arch_getdev = ofw_getdev;
199767f8919635c4928607450d9e0abb932109ceToomas Soome archsw.arch_copyin = sparc64_copyin;
199767f8919635c4928607450d9e0abb932109ceToomas Soome archsw.arch_copyout = ofw_copyout;
199767f8919635c4928607450d9e0abb932109ceToomas Soome archsw.arch_readin = sparc64_readin;
199767f8919635c4928607450d9e0abb932109ceToomas Soome archsw.arch_autoload = sparc64_autoload;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef LOADER_ZFS_SUPPORT
199767f8919635c4928607450d9e0abb932109ceToomas Soome archsw.arch_zfs_probe = sparc64_zfs_probe;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (init_heap() == (vm_offset_t)-1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome OF_exit();
199767f8919635c4928607450d9e0abb932109ceToomas Soome setheap((void *)heapva, (void *)(heapva + HEAPSZ));
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Probe for a console.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome cons_probe();
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((root = OF_peer(0)) == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome panic("%s: can't get root phandle", __func__);
199767f8919635c4928607450d9e0abb932109ceToomas Soome OF_getprop(root, "compatible", compatible, sizeof(compatible));
199767f8919635c4928607450d9e0abb932109ceToomas Soome mmu_ops = &mmu_ops_sun4u;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome mmu_ops->tlb_init();
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Set up the current device.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome OF_getprop(chosen, "bootpath", bootpath, sizeof(bootpath));
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Initialize devices.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (dp = devsw; *dp != 0; dp++)
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((*dp)->dv_init != 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome (*dp)->dv_init();
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef LOADER_ZFS_SUPPORT
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (zfs_currdev.pool_guid != 0) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (void)strncpy(bootpath, zfs_fmtdev(&zfs_currdev),
199767f8919635c4928607450d9e0abb932109ceToomas Soome sizeof(bootpath) - 1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome bootpath[sizeof(bootpath) - 1] = '\0';
199767f8919635c4928607450d9e0abb932109ceToomas Soome } else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Sun compatible bootable CD-ROMs have a disk label placed before
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the ISO 9660 data, with the actual file system being in the first
199767f8919635c4928607450d9e0abb932109ceToomas Soome * partition, while the other partitions contain pseudo disk labels
199767f8919635c4928607450d9e0abb932109ceToomas Soome * with embedded boot blocks for different architectures, which may
199767f8919635c4928607450d9e0abb932109ceToomas Soome * be followed by UFS file systems.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The firmware will set the boot path to the partition it boots from
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ('f' in the sun4u/sun4v case), but we want the kernel to be loaded
199767f8919635c4928607450d9e0abb932109ceToomas Soome * from the ISO 9660 file system ('a'), so the boot path needs to be
199767f8919635c4928607450d9e0abb932109ceToomas Soome * altered.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (bootpath[strlen(bootpath) - 2] == ':' &&
199767f8919635c4928607450d9e0abb932109ceToomas Soome bootpath[strlen(bootpath) - 1] == 'f')
199767f8919635c4928607450d9e0abb932109ceToomas Soome bootpath[strlen(bootpath) - 1] = 'a';
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome env_setenv("currdev", EV_VOLATILE, bootpath,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ofw_setcurrdev, env_nounset);
199767f8919635c4928607450d9e0abb932109ceToomas Soome env_setenv("loaddev", EV_VOLATILE, bootpath,
199767f8919635c4928607450d9e0abb932109ceToomas Soome env_noset, env_nounset);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("\n");
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("%s, Revision %s\n", bootprog_name, bootprog_rev);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("(%s, %s)\n", bootprog_maker, bootprog_date);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("bootpath=\"%s\"\n", bootpath);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Give control to the machine independent loader code. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome interact(NULL);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCOMMAND_SET(heap, "heap", "show heap usage", command_heap);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int
199767f8919635c4928607450d9e0abb932109ceToomas Soomecommand_heap(int argc, char *argv[])
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome mallocstats();
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("heap base at %p, top at %p, upper limit at %p\n", heapva,
199767f8919635c4928607450d9e0abb932109ceToomas Soome sbrk(0), heapva + HEAPSZ);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return(CMD_OK);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCOMMAND_SET(reboot, "reboot", "reboot the system", command_reboot);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int
199767f8919635c4928607450d9e0abb932109ceToomas Soomecommand_reboot(int argc, char *argv[])
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome int i;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; devsw[i] != NULL; ++i)
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (devsw[i]->dv_cleanup != NULL)
199767f8919635c4928607450d9e0abb932109ceToomas Soome (devsw[i]->dv_cleanup)();
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("Rebooting...\n");
199767f8919635c4928607450d9e0abb932109ceToomas Soome OF_exit();
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* provide this for panic, as it's not in the startup code */
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid
199767f8919635c4928607450d9e0abb932109ceToomas Soomeexit(int code)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome OF_exit();
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef LOADER_DEBUG
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic const char *const page_sizes[] = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome " 8k", " 64k", "512k", " 4m"
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void
199767f8919635c4928607450d9e0abb932109ceToomas Soomepmap_print_tte_sun4u(tte_t tag, tte_t tte)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("%s %s ",
199767f8919635c4928607450d9e0abb932109ceToomas Soome page_sizes[(tte >> TD_SIZE_SHIFT) & TD_SIZE_MASK],
199767f8919635c4928607450d9e0abb932109ceToomas Soome tag & TD_G ? "G" : " ");
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(tte & TD_W ? "W " : " ");
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(tte & TD_P ? "\e[33mP\e[0m " : " ");
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(tte & TD_E ? "E " : " ");
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(tte & TD_CV ? "CV " : " ");
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(tte & TD_CP ? "CP " : " ");
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(tte & TD_L ? "\e[32mL\e[0m " : " ");
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(tte & TD_IE ? "IE " : " ");
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(tte & TD_NFO ? "NFO " : " ");
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("pa=0x%lx va=0x%lx ctx=%ld\n",
199767f8919635c4928607450d9e0abb932109ceToomas Soome TD_PA(tte), TLB_TAR_VA(tag), TLB_TAR_CTX(tag));
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void
199767f8919635c4928607450d9e0abb932109ceToomas Soomepmap_print_tlb_sun4u(void)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome tte_t tag, tte;
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_long pstate;
199767f8919635c4928607450d9e0abb932109ceToomas Soome int i;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome pstate = rdpr(pstate);
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < itlb_slot_max; i++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome wrpr(pstate, pstate & ~PSTATE_IE, 0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome tte = itlb_get_data_sun4u(tlb_locked, i);
199767f8919635c4928607450d9e0abb932109ceToomas Soome wrpr(pstate, pstate, 0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (!(tte & TD_V))
199767f8919635c4928607450d9e0abb932109ceToomas Soome continue;
199767f8919635c4928607450d9e0abb932109ceToomas Soome tag = ldxa(TLB_DAR_SLOT(tlb_locked, i),
199767f8919635c4928607450d9e0abb932109ceToomas Soome ASI_ITLB_TAG_READ_REG);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("iTLB-%2u: ", i);
199767f8919635c4928607450d9e0abb932109ceToomas Soome pmap_print_tte_sun4u(tag, tte);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < dtlb_slot_max; i++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome wrpr(pstate, pstate & ~PSTATE_IE, 0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome tte = dtlb_get_data_sun4u(tlb_locked, i);
199767f8919635c4928607450d9e0abb932109ceToomas Soome wrpr(pstate, pstate, 0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (!(tte & TD_V))
199767f8919635c4928607450d9e0abb932109ceToomas Soome continue;
199767f8919635c4928607450d9e0abb932109ceToomas Soome tag = ldxa(TLB_DAR_SLOT(tlb_locked, i),
199767f8919635c4928607450d9e0abb932109ceToomas Soome ASI_DTLB_TAG_READ_REG);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("dTLB-%2u: ", i);
199767f8919635c4928607450d9e0abb932109ceToomas Soome pmap_print_tte_sun4u(tag, tte);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif