2 * Initial implementation:
3 * Copyright (c) 2001 Robert Drehmel
6 * As long as the above copyright statement and this notice remain
7 * unchanged, you can do what ever you want with this file.
10 * Copyright (c) 2008 Marius Strobl <marius@FreeBSD.org>
11 * All rights reserved.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
39 * FreeBSD/sparc64 kernel loader - machine dependent part
41 * - implements copyin and readin functions that map kernel
42 * pages on demand. The machine independent code does not
43 * know the size of the kernel early enough to pre-enter
44 * TTEs and install just one 4MB mapping seemed to limiting
49 #include <sys/param.h>
51 #include <sys/linker.h>
52 #include <sys/queue.h>
53 #include <sys/types.h>
54 #ifdef LOADER_ZFS_SUPPORT
59 #include <machine/asi.h>
60 #include <machine/cmt.h>
61 #include <machine/cpufunc.h>
62 #include <machine/elf.h>
63 #include <machine/fireplane.h>
64 #include <machine/jbus.h>
65 #include <machine/lsu.h>
66 #include <machine/metadata.h>
67 #include <machine/tte.h>
68 #include <machine/tlb.h>
69 #include <machine/upa.h>
70 #include <machine/ver.h>
71 #include <machine/vmparam.h>
73 #include "bootstrap.h"
77 extern char bootprog_name[], bootprog_rev[], bootprog_date[], bootprog_maker[];
82 LOADSZ = 0x1000000 /* for kernel and modules */
85 /* At least Sun Fire V1280 require page sized allocations to be claimed. */
86 CTASSERT(HEAPSZ % PAGE_SIZE == 0);
88 static struct mmu_ops {
89 void (*tlb_init)(void);
90 int (*mmu_mapin)(vm_offset_t va, vm_size_t len);
93 typedef void kernel_entry_t(vm_offset_t mdp, u_long o1, u_long o2, u_long o3,
96 static inline u_long dtlb_get_data_sun4u(u_int, u_int);
97 static int dtlb_enter_sun4u(u_int, u_long data, vm_offset_t);
98 static vm_offset_t dtlb_va_to_pa_sun4u(vm_offset_t);
99 static inline u_long itlb_get_data_sun4u(u_int, u_int);
100 static int itlb_enter_sun4u(u_int, u_long data, vm_offset_t);
101 static vm_offset_t itlb_va_to_pa_sun4u(vm_offset_t);
102 static void itlb_relocate_locked0_sun4u(void);
103 extern vm_offset_t md_load(char *, vm_offset_t *);
104 static int sparc64_autoload(void);
105 static ssize_t sparc64_readin(const int, vm_offset_t, const size_t);
106 static ssize_t sparc64_copyin(const void *, vm_offset_t, size_t);
107 static void sparc64_maphint(vm_offset_t, size_t);
108 static vm_offset_t claim_virt(vm_offset_t, size_t, int);
109 static vm_offset_t alloc_phys(size_t, int);
110 static int map_phys(int, size_t, vm_offset_t, vm_offset_t);
111 static void release_phys(vm_offset_t, u_int);
112 static int __elfN(exec)(struct preloaded_file *);
113 static int mmu_mapin_sun4u(vm_offset_t, vm_size_t);
114 static int mmu_mapin_sun4v(vm_offset_t, vm_size_t);
115 static vm_offset_t init_heap(void);
116 static phandle_t find_bsp_sun4u(phandle_t, uint32_t);
117 const char *cpu_cpuid_prop_sun4u(void);
118 uint32_t cpu_get_mid_sun4u(void);
119 static void tlb_init_sun4u(void);
120 static void tlb_init_sun4v(void);
123 typedef u_int64_t tte_t;
125 static void pmap_print_tlb_sun4u(void);
126 static void pmap_print_tte_sun4u(tte_t, tte_t);
129 static struct mmu_ops mmu_ops_sun4u = { tlb_init_sun4u, mmu_mapin_sun4u };
130 static struct mmu_ops mmu_ops_sun4v = { tlb_init_sun4v, mmu_mapin_sun4v };
133 struct tlb_entry *dtlb_store;
134 struct tlb_entry *itlb_store;
138 static u_int dtlb_slot_max;
139 static u_int itlb_slot_max;
140 static u_int tlb_locked;
143 static struct tlb_entry *tlb_store;
144 static int is_sun4v = 0;
146 * no direct TLB access on sun4v
147 * we somewhat arbitrarily declare enough
148 * slots to cover a 4GB AS with 4MB pages
150 #define SUN4V_TLB_SLOT_MAX (1 << 10)
152 static vm_offset_t curkva = 0;
153 static vm_offset_t heapva;
155 static phandle_t root;
157 #ifdef LOADER_ZFS_SUPPORT
158 static int zfs_dev_init(void);
163 * Machine dependent structures that the machine independent
166 struct devsw *devsw[] = {
167 #ifdef LOADER_DISK_SUPPORT
170 #ifdef LOADER_NET_SUPPORT
173 #ifdef LOADER_ZFS_SUPPORT
178 struct arch_switch archsw;
180 static struct file_format sparc64_elf = {
184 struct file_format *file_formats[] = {
189 struct fs_ops *file_system[] = {
190 #ifdef LOADER_UFS_SUPPORT
193 #ifdef LOADER_CD9660_SUPPORT
196 #ifdef LOADER_ZFS_SUPPORT
199 #ifdef LOADER_ZIP_SUPPORT
202 #ifdef LOADER_GZIP_SUPPORT
205 #ifdef LOADER_BZIP2_SUPPORT
208 #ifdef LOADER_NFS_SUPPORT
211 #ifdef LOADER_TFTP_SUPPORT
216 struct netif_driver *netif_drivers[] = {
217 #ifdef LOADER_NET_SUPPORT
223 extern struct console ofwconsole;
224 struct console *consoles[] = {
231 watch_phys_set_mask(vm_offset_t pa, u_long mask)
235 stxa(AA_DMMU_PWPR, ASI_DMMU, pa & (((2UL << 38) - 1) << 3));
236 lsucr = ldxa(0, ASI_LSU_CTL_REG);
237 lsucr = ((lsucr | LSU_PW) & ~LSU_PM_MASK) |
238 (mask << LSU_PM_SHIFT);
239 stxa(0, ASI_LSU_CTL_REG, lsucr);
244 watch_phys_set(vm_offset_t pa, int sz)
248 off = (u_long)pa & 7;
249 /* Test for misaligned watch points. */
252 return (watch_phys_set_mask(pa, ((1 << sz) - 1) << off));
257 watch_virt_set_mask(vm_offset_t va, u_long mask)
261 stxa(AA_DMMU_VWPR, ASI_DMMU, va & (((2UL << 41) - 1) << 3));
262 lsucr = ldxa(0, ASI_LSU_CTL_REG);
263 lsucr = ((lsucr | LSU_VW) & ~LSU_VM_MASK) |
264 (mask << LSU_VM_SHIFT);
265 stxa(0, ASI_LSU_CTL_REG, lsucr);
270 watch_virt_set(vm_offset_t va, int sz)
274 off = (u_long)va & 7;
275 /* Test for misaligned watch points. */
278 return (watch_virt_set_mask(va, ((1 << sz) - 1) << off));
286 sparc64_autoload(void)
293 sparc64_readin(const int fd, vm_offset_t va, const size_t len)
296 mmu_ops->mmu_mapin(va, len);
297 return (read(fd, (void *)va, len));
301 sparc64_copyin(const void *src, vm_offset_t dest, size_t len)
304 mmu_ops->mmu_mapin(dest, len);
305 memcpy((void *)dest, src, len);
310 sparc64_maphint(vm_offset_t va, size_t len)
315 int i, free_excess = 0;
320 if (tlb_store[va >> 22].te_pa != -1)
323 /* round up to nearest 4MB page */
324 size = (len + PAGE_MASK_4M) & ~PAGE_MASK_4M;
326 pa = alloc_phys(PAGE_SIZE_256M, PAGE_SIZE_256M);
332 pa = alloc_phys(size, PAGE_SIZE_256M);
334 pa = alloc_phys(size, PAGE_SIZE_4M);
336 panic("%s: out of memory", __func__);
338 for (i = 0; i < size; i += PAGE_SIZE_4M) {
339 mva = claim_virt(va + i, PAGE_SIZE_4M, 0);
341 panic("%s: can't claim virtual page "
342 "(wanted %#lx, got %#lx)",
345 tlb_store[mva >> 22].te_pa = pa + i;
346 if (map_phys(-1, PAGE_SIZE_4M, mva, pa + i) != 0)
347 printf("%s: can't map physical page\n", __func__);
350 release_phys(pa, PAGE_SIZE_256M);
357 claim_virt(vm_offset_t virt, size_t size, int align)
361 if (OF_call_method("claim", mmu, 3, 1, virt, size, align, &mva) == -1)
362 return ((vm_offset_t)-1);
367 alloc_phys(size_t size, int align)
369 cell_t phys_hi, phys_low;
371 if (OF_call_method("claim", memory, 2, 2, size, align, &phys_low,
373 return ((vm_offset_t)-1);
374 return ((vm_offset_t)phys_hi << 32 | phys_low);
378 map_phys(int mode, size_t size, vm_offset_t virt, vm_offset_t phys)
381 return (OF_call_method("map", mmu, 5, 0, (uint32_t)phys,
382 (uint32_t)(phys >> 32), virt, size, mode));
386 release_phys(vm_offset_t phys, u_int size)
389 (void)OF_call_method("release", memory, 3, 0, (uint32_t)phys,
390 (uint32_t)(phys >> 32), size);
394 __elfN(exec)(struct preloaded_file *fp)
396 struct file_metadata *fmp;
402 if ((fmp = file_findmetadata(fp, MODINFOMD_ELFHDR)) == 0)
404 e = (Elf_Ehdr *)&fmp->md_data;
406 if ((error = md_load(fp->f_args, &mdp)) != 0)
409 printf("jumping to kernel entry at %#lx.\n", e->e_entry);
411 pmap_print_tlb_sun4u();
418 OF_release((void *)heapva, HEAPSZ);
420 ((kernel_entry_t *)entry)(mdp, 0, 0, 0, openfirmware);
422 panic("%s: exec returned", __func__);
426 dtlb_get_data_sun4u(u_int tlb, u_int slot)
430 slot = TLB_DAR_SLOT(tlb, slot);
432 * We read ASI_DTLB_DATA_ACCESS_REG twice back-to-back in order to
433 * work around errata of USIII and beyond.
435 pstate = rdpr(pstate);
436 wrpr(pstate, pstate & ~PSTATE_IE, 0);
437 (void)ldxa(slot, ASI_DTLB_DATA_ACCESS_REG);
438 data = ldxa(slot, ASI_DTLB_DATA_ACCESS_REG);
439 wrpr(pstate, pstate, 0);
444 itlb_get_data_sun4u(u_int tlb, u_int slot)
448 slot = TLB_DAR_SLOT(tlb, slot);
450 * We read ASI_DTLB_DATA_ACCESS_REG twice back-to-back in order to
451 * work around errata of USIII and beyond.
453 pstate = rdpr(pstate);
454 wrpr(pstate, pstate & ~PSTATE_IE, 0);
455 (void)ldxa(slot, ASI_ITLB_DATA_ACCESS_REG);
456 data = ldxa(slot, ASI_ITLB_DATA_ACCESS_REG);
457 wrpr(pstate, pstate, 0);
462 dtlb_va_to_pa_sun4u(vm_offset_t va)
467 pstate = rdpr(pstate);
468 wrpr(pstate, pstate & ~PSTATE_IE, 0);
469 for (i = 0; i < dtlb_slot_max; i++) {
470 reg = ldxa(TLB_DAR_SLOT(tlb_locked, i),
471 ASI_DTLB_TAG_READ_REG);
472 if (TLB_TAR_VA(reg) != va)
474 reg = dtlb_get_data_sun4u(tlb_locked, i);
475 wrpr(pstate, pstate, 0);
477 if (cpu_impl == CPU_IMPL_SPARC64V ||
478 cpu_impl >= CPU_IMPL_ULTRASPARCIII)
479 return (reg & TD_PA_CH_MASK);
480 return (reg & TD_PA_SF_MASK);
482 wrpr(pstate, pstate, 0);
487 itlb_va_to_pa_sun4u(vm_offset_t va)
492 pstate = rdpr(pstate);
493 wrpr(pstate, pstate & ~PSTATE_IE, 0);
494 for (i = 0; i < itlb_slot_max; i++) {
495 reg = ldxa(TLB_DAR_SLOT(tlb_locked, i),
496 ASI_ITLB_TAG_READ_REG);
497 if (TLB_TAR_VA(reg) != va)
499 reg = itlb_get_data_sun4u(tlb_locked, i);
500 wrpr(pstate, pstate, 0);
502 if (cpu_impl == CPU_IMPL_SPARC64V ||
503 cpu_impl >= CPU_IMPL_ULTRASPARCIII)
504 return (reg & TD_PA_CH_MASK);
505 return (reg & TD_PA_SF_MASK);
507 wrpr(pstate, pstate, 0);
512 dtlb_enter_sun4u(u_int index, u_long data, vm_offset_t virt)
515 return (OF_call_method("SUNW,dtlb-load", mmu, 3, 0, index, data,
520 itlb_enter_sun4u(u_int index, u_long data, vm_offset_t virt)
523 if (cpu_impl == CPU_IMPL_ULTRASPARCIIIp && index == 0 &&
525 panic("%s: won't enter locked TLB entry at index 0 on USIII+",
527 return (OF_call_method("SUNW,itlb-load", mmu, 3, 0, index, data,
532 itlb_relocate_locked0_sun4u(void)
534 u_long data, pstate, tag;
537 if (cpu_impl != CPU_IMPL_ULTRASPARCIIIp)
540 pstate = rdpr(pstate);
541 wrpr(pstate, pstate & ~PSTATE_IE, 0);
543 data = itlb_get_data_sun4u(tlb_locked, 0);
544 if ((data & (TD_V | TD_L)) != (TD_V | TD_L)) {
545 wrpr(pstate, pstate, 0);
549 /* Flush the mapping of slot 0. */
550 tag = ldxa(TLB_DAR_SLOT(tlb_locked, 0), ASI_ITLB_TAG_READ_REG);
551 stxa(TLB_DEMAP_VA(TLB_TAR_VA(tag)) | TLB_DEMAP_PRIMARY |
552 TLB_DEMAP_PAGE, ASI_IMMU_DEMAP, 0);
553 flush(0); /* The USIII-family ignores the address. */
556 * Search a replacement slot != 0 and enter the data and tag
557 * that formerly were in slot 0.
559 for (i = 1; i < itlb_slot_max; i++) {
560 if ((itlb_get_data_sun4u(tlb_locked, i) & TD_V) != 0)
563 stxa(AA_IMMU_TAR, ASI_IMMU, tag);
564 stxa(TLB_DAR_SLOT(tlb_locked, i), ASI_ITLB_DATA_ACCESS_REG,
566 flush(0); /* The USIII-family ignores the address. */
569 wrpr(pstate, pstate, 0);
570 if (i == itlb_slot_max)
571 panic("%s: could not find a replacement slot", __func__);
575 mmu_mapin_sun4u(vm_offset_t va, vm_size_t len)
581 if (va + len > curkva)
584 pa = (vm_offset_t)-1;
585 len += va & PAGE_MASK_4M;
588 if (dtlb_va_to_pa_sun4u(va) == (vm_offset_t)-1 ||
589 itlb_va_to_pa_sun4u(va) == (vm_offset_t)-1) {
590 /* Allocate a physical page, claim the virtual area. */
591 if (pa == (vm_offset_t)-1) {
592 pa = alloc_phys(PAGE_SIZE_4M, PAGE_SIZE_4M);
593 if (pa == (vm_offset_t)-1)
594 panic("%s: out of memory", __func__);
595 mva = claim_virt(va, PAGE_SIZE_4M, 0);
597 panic("%s: can't claim virtual page "
598 "(wanted %#lx, got %#lx)",
601 * The mappings may have changed, be paranoid.
606 * Actually, we can only allocate two pages less at
607 * most (depending on the kernel TSB size).
609 if (dtlb_slot >= dtlb_slot_max)
610 panic("%s: out of dtlb_slots", __func__);
611 if (itlb_slot >= itlb_slot_max)
612 panic("%s: out of itlb_slots", __func__);
613 data = TD_V | TD_4M | TD_PA(pa) | TD_L | TD_CP |
615 dtlb_store[dtlb_slot].te_pa = pa;
616 dtlb_store[dtlb_slot].te_va = va;
617 index = dtlb_slot_max - dtlb_slot - 1;
618 if (dtlb_enter_sun4u(index, data, va) < 0)
619 panic("%s: can't enter dTLB slot %d data "
620 "%#lx va %#lx", __func__, index, data,
623 itlb_store[itlb_slot].te_pa = pa;
624 itlb_store[itlb_slot].te_va = va;
625 index = itlb_slot_max - itlb_slot - 1;
626 if (itlb_enter_sun4u(index, data, va) < 0)
627 panic("%s: can't enter iTLB slot %d data "
628 "%#lx va %#lxd", __func__, index, data,
631 pa = (vm_offset_t)-1;
633 len -= len > PAGE_SIZE_4M ? PAGE_SIZE_4M : len;
636 if (pa != (vm_offset_t)-1)
637 release_phys(pa, PAGE_SIZE_4M);
642 mmu_mapin_sun4v(vm_offset_t va, vm_size_t len)
646 if (va + len > curkva)
649 pa = (vm_offset_t)-1;
650 len += va & PAGE_MASK_4M;
653 if ((va >> 22) > SUN4V_TLB_SLOT_MAX)
654 panic("%s: trying to map more than 4GB", __func__);
655 if (tlb_store[va >> 22].te_pa == -1) {
656 /* Allocate a physical page, claim the virtual area */
657 if (pa == (vm_offset_t)-1) {
658 pa = alloc_phys(PAGE_SIZE_4M, PAGE_SIZE_4M);
659 if (pa == (vm_offset_t)-1)
660 panic("%s: out of memory", __func__);
661 mva = claim_virt(va, PAGE_SIZE_4M, 0);
663 panic("%s: can't claim virtual page "
664 "(wanted %#lx, got %#lx)",
668 tlb_store[va >> 22].te_pa = pa;
669 if (map_phys(-1, PAGE_SIZE_4M, va, pa) == -1)
670 printf("%s: can't map physical page\n",
672 pa = (vm_offset_t)-1;
674 len -= len > PAGE_SIZE_4M ? PAGE_SIZE_4M : len;
677 if (pa != (vm_offset_t)-1)
678 release_phys(pa, PAGE_SIZE_4M);
686 /* There is no need for continuous physical heap memory. */
687 heapva = (vm_offset_t)OF_claim((void *)HEAPVA, HEAPSZ, 32);
692 find_bsp_sun4u(phandle_t node, uint32_t bspid)
694 char type[sizeof("cpu")];
698 for (; node > 0; node = OF_peer(node)) {
699 child = OF_child(node);
701 child = find_bsp_sun4u(child, bspid);
705 if (OF_getprop(node, "device_type", type,
708 if (strcmp(type, "cpu") != 0)
710 if (OF_getprop(node, cpu_cpuid_prop_sun4u(), &cpuid,
721 cpu_cpuid_prop_sun4u(void)
725 case CPU_IMPL_SPARC64:
726 case CPU_IMPL_SPARC64V:
727 case CPU_IMPL_ULTRASPARCI:
728 case CPU_IMPL_ULTRASPARCII:
729 case CPU_IMPL_ULTRASPARCIIi:
730 case CPU_IMPL_ULTRASPARCIIe:
731 return ("upa-portid");
732 case CPU_IMPL_ULTRASPARCIII:
733 case CPU_IMPL_ULTRASPARCIIIp:
734 case CPU_IMPL_ULTRASPARCIIIi:
735 case CPU_IMPL_ULTRASPARCIIIip:
737 case CPU_IMPL_ULTRASPARCIV:
738 case CPU_IMPL_ULTRASPARCIVp:
746 cpu_get_mid_sun4u(void)
750 case CPU_IMPL_SPARC64:
751 case CPU_IMPL_SPARC64V:
752 case CPU_IMPL_ULTRASPARCI:
753 case CPU_IMPL_ULTRASPARCII:
754 case CPU_IMPL_ULTRASPARCIIi:
755 case CPU_IMPL_ULTRASPARCIIe:
756 return (UPA_CR_GET_MID(ldxa(0, ASI_UPA_CONFIG_REG)));
757 case CPU_IMPL_ULTRASPARCIII:
758 case CPU_IMPL_ULTRASPARCIIIp:
759 return (FIREPLANE_CR_GET_AID(ldxa(AA_FIREPLANE_CONFIG,
760 ASI_FIREPLANE_CONFIG_REG)));
761 case CPU_IMPL_ULTRASPARCIIIi:
762 case CPU_IMPL_ULTRASPARCIIIip:
763 return (JBUS_CR_GET_JID(ldxa(0, ASI_JBUS_CONFIG_REG)));
764 case CPU_IMPL_ULTRASPARCIV:
765 case CPU_IMPL_ULTRASPARCIVp:
766 return (INTR_ID_GET_ID(ldxa(AA_INTR_ID, ASI_INTR_ID)));
777 cpu_impl = VER_IMPL(rdpr(ver));
779 case CPU_IMPL_SPARC64:
780 case CPU_IMPL_ULTRASPARCI:
781 case CPU_IMPL_ULTRASPARCII:
782 case CPU_IMPL_ULTRASPARCIIi:
783 case CPU_IMPL_ULTRASPARCIIe:
784 tlb_locked = TLB_DAR_T32;
786 case CPU_IMPL_ULTRASPARCIII:
787 case CPU_IMPL_ULTRASPARCIIIp:
788 case CPU_IMPL_ULTRASPARCIIIi:
789 case CPU_IMPL_ULTRASPARCIIIip:
790 case CPU_IMPL_ULTRASPARCIV:
791 case CPU_IMPL_ULTRASPARCIVp:
792 tlb_locked = TLB_DAR_T16;
794 case CPU_IMPL_SPARC64V:
795 tlb_locked = TLB_DAR_FTLB;
798 bsp = find_bsp_sun4u(OF_child(root), cpu_get_mid_sun4u());
800 panic("%s: no node for bootcpu?!?!", __func__);
802 if (OF_getprop(bsp, "#dtlb-entries", &dtlb_slot_max,
803 sizeof(dtlb_slot_max)) == -1 ||
804 OF_getprop(bsp, "#itlb-entries", &itlb_slot_max,
805 sizeof(itlb_slot_max)) == -1)
806 panic("%s: can't get TLB slot max.", __func__);
808 if (cpu_impl == CPU_IMPL_ULTRASPARCIIIp) {
810 printf("pre fixup:\n");
811 pmap_print_tlb_sun4u();
815 * Relocate the locked entry in it16 slot 0 (if existent)
816 * as part of working around Cheetah+ erratum 34.
818 itlb_relocate_locked0_sun4u();
821 printf("post fixup:\n");
822 pmap_print_tlb_sun4u();
826 dtlb_store = malloc(dtlb_slot_max * sizeof(*dtlb_store));
827 itlb_store = malloc(itlb_slot_max * sizeof(*itlb_store));
828 if (dtlb_store == NULL || itlb_store == NULL)
829 panic("%s: can't allocate TLB store", __func__);
836 tlb_store = malloc(SUN4V_TLB_SLOT_MAX * sizeof(*tlb_store));
837 memset(tlb_store, 0xFF, SUN4V_TLB_SLOT_MAX * sizeof(*tlb_store));
840 #ifdef LOADER_ZFS_SUPPORT
855 /* Get the GUID of the ZFS pool on the boot device. */
856 fd = open(getenv("currdev"), O_RDONLY);
858 if (vdev_probe(vdev_read, (void *)(uintptr_t) fd, &spa) == 0)
859 guid = spa->spa_guid;
863 /* Clean up the environment to let ZFS work. */
864 while ((vdev = STAILQ_FIRST(&zfs_vdevs)) != NULL) {
865 STAILQ_REMOVE_HEAD(&zfs_vdevs, v_alllink);
868 while ((spa = STAILQ_FIRST(&zfs_pools)) != NULL) {
869 STAILQ_REMOVE_HEAD(&zfs_pools, spa_link);
873 for (unit = 0; unit < MAXBDDEV; unit++) {
874 /* Find freebsd-zfs slices in the VTOC. */
875 sprintf(devname, "disk%d:", unit);
876 fd = open(devname, O_RDONLY);
879 lseek(fd, 0, SEEK_SET);
880 if (read(fd, &vtoc, sizeof(vtoc)) != sizeof(vtoc)) {
886 for (part = 0; part < 8; part++) {
887 if (part == 2 || vtoc.part[part].tag !=
888 VTOC_TAG_FREEBSD_ZFS)
890 sprintf(devname, "disk%d:%c", unit, part + 'a');
891 fd = open(devname, O_RDONLY);
895 if (vdev_probe(vdev_read, (void*)(uintptr_t) fd, 0))
901 unit = zfs_guid_to_unit(guid);
903 /* Update the environment for ZFS. */
904 sprintf(devname, "zfs%d", unit);
905 env_setenv("currdev", EV_VOLATILE, devname,
906 ofw_setcurrdev, env_nounset);
907 env_setenv("loaddev", EV_VOLATILE, devname,
908 env_noset, env_nounset);
914 #endif /* LOADER_ZFS_SUPPORT */
917 main(int (*openfirm)(void *))
924 * Tell the Open Firmware functions where they find the OFW gate.
928 archsw.arch_getdev = ofw_getdev;
929 archsw.arch_copyin = sparc64_copyin;
930 archsw.arch_copyout = ofw_copyout;
931 archsw.arch_readin = sparc64_readin;
932 archsw.arch_autoload = sparc64_autoload;
933 archsw.arch_maphint = sparc64_maphint;
935 if (init_heap() == (vm_offset_t)-1)
937 setheap((void *)heapva, (void *)(heapva + HEAPSZ));
940 * Probe for a console.
944 if ((root = OF_peer(0)) == -1)
945 panic("%s: can't get root phandle", __func__);
946 OF_getprop(root, "compatible", compatible, sizeof(compatible));
947 if (!strcmp(compatible, "sun4v")) {
948 printf("\nBooting with sun4v support.\n");
949 mmu_ops = &mmu_ops_sun4v;
952 printf("\nBooting with sun4u support.\n");
953 mmu_ops = &mmu_ops_sun4u;
959 * Set up the current device.
961 OF_getprop(chosen, "bootpath", bootpath, sizeof(bootpath));
964 * Sun compatible bootable CD-ROMs have a disk label placed
965 * before the cd9660 data, with the actual filesystem being
966 * in the first partition, while the other partitions contain
967 * pseudo disk labels with embedded boot blocks for different
968 * architectures, which may be followed by UFS filesystems.
969 * The firmware will set the boot path to the partition it
970 * boots from ('f' in the sun4u case), but we want the kernel
971 * to be loaded from the cd9660 fs ('a'), so the boot path
972 * needs to be altered.
974 if (bootpath[strlen(bootpath) - 2] == ':' &&
975 bootpath[strlen(bootpath) - 1] == 'f' &&
976 strstr(bootpath, "cdrom")) {
977 bootpath[strlen(bootpath) - 1] = 'a';
978 printf("Boot path set to %s\n", bootpath);
981 env_setenv("currdev", EV_VOLATILE, bootpath,
982 ofw_setcurrdev, env_nounset);
983 env_setenv("loaddev", EV_VOLATILE, bootpath,
984 env_noset, env_nounset);
987 * Initialize devices.
989 for (dp = devsw; *dp != 0; dp++)
990 if ((*dp)->dv_init != 0)
994 printf("%s, Revision %s\n", bootprog_name, bootprog_rev);
995 printf("(%s, %s)\n", bootprog_maker, bootprog_date);
996 printf("bootpath=\"%s\"\n", bootpath);
998 /* Give control to the machine independent loader code. */
1003 COMMAND_SET(heap, "heap", "show heap usage", command_heap);
1006 command_heap(int argc, char *argv[])
1010 printf("heap base at %p, top at %p, upper limit at %p\n", heapva,
1011 sbrk(0), heapva + HEAPSZ);
1015 COMMAND_SET(reboot, "reboot", "reboot the system", command_reboot);
1018 command_reboot(int argc, char *argv[])
1022 for (i = 0; devsw[i] != NULL; ++i)
1023 if (devsw[i]->dv_cleanup != NULL)
1024 (devsw[i]->dv_cleanup)();
1026 printf("Rebooting...\n");
1030 /* provide this for panic, as it's not in the startup code */
1039 static const char *const page_sizes[] = {
1040 " 8k", " 64k", "512k", " 4m"
1044 pmap_print_tte_sun4u(tte_t tag, tte_t tte)
1048 page_sizes[(tte >> TD_SIZE_SHIFT) & TD_SIZE_MASK],
1049 tag & TD_G ? "G" : " ");
1050 printf(tte & TD_W ? "W " : " ");
1051 printf(tte & TD_P ? "\e[33mP\e[0m " : " ");
1052 printf(tte & TD_E ? "E " : " ");
1053 printf(tte & TD_CV ? "CV " : " ");
1054 printf(tte & TD_CP ? "CP " : " ");
1055 printf(tte & TD_L ? "\e[32mL\e[0m " : " ");
1056 printf(tte & TD_IE ? "IE " : " ");
1057 printf(tte & TD_NFO ? "NFO " : " ");
1058 printf("pa=0x%lx va=0x%lx ctx=%ld\n",
1059 TD_PA(tte), TLB_TAR_VA(tag), TLB_TAR_CTX(tag));
1063 pmap_print_tlb_sun4u(void)
1069 pstate = rdpr(pstate);
1070 for (i = 0; i < itlb_slot_max; i++) {
1071 wrpr(pstate, pstate & ~PSTATE_IE, 0);
1072 tte = itlb_get_data_sun4u(tlb_locked, i);
1073 wrpr(pstate, pstate, 0);
1076 tag = ldxa(TLB_DAR_SLOT(tlb_locked, i),
1077 ASI_ITLB_TAG_READ_REG);
1078 printf("iTLB-%2u: ", i);
1079 pmap_print_tte_sun4u(tag, tte);
1081 for (i = 0; i < dtlb_slot_max; i++) {
1082 wrpr(pstate, pstate & ~PSTATE_IE, 0);
1083 tte = dtlb_get_data_sun4u(tlb_locked, i);
1084 wrpr(pstate, pstate, 0);
1087 tag = ldxa(TLB_DAR_SLOT(tlb_locked, i),
1088 ASI_DTLB_TAG_READ_REG);
1089 printf("dTLB-%2u: ", i);
1090 pmap_print_tte_sun4u(tag, tte);