Deleted Added
full compact
main.c (220290) main.c (221869)
1/*-
2 * Initial implementation:
3 * Copyright (c) 2001 Robert Drehmel
4 * All rights reserved.
5 *
6 * As long as the above copyright statement and this notice remain
7 * unchanged, you can do what ever you want with this file.
8 */

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

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
32 * SUCH DAMAGE.
33 */
34
35#include <sys/cdefs.h>
1/*-
2 * Initial implementation:
3 * Copyright (c) 2001 Robert Drehmel
4 * All rights reserved.
5 *
6 * As long as the above copyright statement and this notice remain
7 * unchanged, you can do what ever you want with this file.
8 */

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

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
32 * SUCH DAMAGE.
33 */
34
35#include <sys/cdefs.h>
36__FBSDID("$FreeBSD: head/sys/boot/sparc64/loader/main.c 220290 2011-04-03 05:09:25Z marcel $");
36__FBSDID("$FreeBSD: head/sys/boot/sparc64/loader/main.c 221869 2011-05-14 01:53:38Z attilio $");
37
38/*
39 * FreeBSD/sparc64 kernel loader - machine dependent part
40 *
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

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

108static ssize_t sparc64_readin(const int, vm_offset_t, const size_t);
109static ssize_t sparc64_copyin(const void *, vm_offset_t, size_t);
110static vm_offset_t claim_virt(vm_offset_t, size_t, int);
111static vm_offset_t alloc_phys(size_t, int);
112static int map_phys(int, size_t, vm_offset_t, vm_offset_t);
113static void release_phys(vm_offset_t, u_int);
114static int __elfN(exec)(struct preloaded_file *);
115static int mmu_mapin_sun4u(vm_offset_t, vm_size_t);
37
38/*
39 * FreeBSD/sparc64 kernel loader - machine dependent part
40 *
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

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

108static ssize_t sparc64_readin(const int, vm_offset_t, const size_t);
109static ssize_t sparc64_copyin(const void *, vm_offset_t, size_t);
110static vm_offset_t claim_virt(vm_offset_t, size_t, int);
111static vm_offset_t alloc_phys(size_t, int);
112static int map_phys(int, size_t, vm_offset_t, vm_offset_t);
113static void release_phys(vm_offset_t, u_int);
114static int __elfN(exec)(struct preloaded_file *);
115static int mmu_mapin_sun4u(vm_offset_t, vm_size_t);
116static int mmu_mapin_sun4v(vm_offset_t, vm_size_t);
117static vm_offset_t init_heap(void);
118static phandle_t find_bsp_sun4u(phandle_t, uint32_t);
119const char *cpu_cpuid_prop_sun4u(void);
120uint32_t cpu_get_mid_sun4u(void);
121static void tlb_init_sun4u(void);
116static vm_offset_t init_heap(void);
117static phandle_t find_bsp_sun4u(phandle_t, uint32_t);
118const char *cpu_cpuid_prop_sun4u(void);
119uint32_t cpu_get_mid_sun4u(void);
120static void tlb_init_sun4u(void);
122static void tlb_init_sun4v(void);
123
124#ifdef LOADER_DEBUG
125typedef u_int64_t tte_t;
126
127static void pmap_print_tlb_sun4u(void);
128static void pmap_print_tte_sun4u(tte_t, tte_t);
129#endif
130
131static struct mmu_ops mmu_ops_sun4u = { tlb_init_sun4u, mmu_mapin_sun4u };
121
122#ifdef LOADER_DEBUG
123typedef u_int64_t tte_t;
124
125static void pmap_print_tlb_sun4u(void);
126static void pmap_print_tte_sun4u(tte_t, tte_t);
127#endif
128
129static struct mmu_ops mmu_ops_sun4u = { tlb_init_sun4u, mmu_mapin_sun4u };
132static struct mmu_ops mmu_ops_sun4v = { tlb_init_sun4v, mmu_mapin_sun4v };
133
134/* sun4u */
135struct tlb_entry *dtlb_store;
136struct tlb_entry *itlb_store;
137u_int dtlb_slot;
138u_int itlb_slot;
139static int cpu_impl;
140static u_int dtlb_slot_max;
141static u_int itlb_slot_max;
142
130
131/* sun4u */
132struct tlb_entry *dtlb_store;
133struct tlb_entry *itlb_store;
134u_int dtlb_slot;
135u_int itlb_slot;
136static int cpu_impl;
137static u_int dtlb_slot_max;
138static u_int itlb_slot_max;
139
143/* sun4v */
144static struct tlb_entry *tlb_store;
145static int is_sun4v = 0;
146/*
147 * no direct TLB access on sun4v
148 * we somewhat arbitrarily declare enough
149 * slots to cover a 4GB AS with 4MB pages
150 */
151#define SUN4V_TLB_SLOT_MAX (1 << 10)
152
153static vm_offset_t curkva = 0;
154static vm_offset_t heapva;
155
156static phandle_t root;
157
158/*
159 * Machine dependent structures that the machine independent
160 * loader part uses.

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

563 len -= len > PAGE_SIZE_4M ? PAGE_SIZE_4M : len;
564 va += PAGE_SIZE_4M;
565 }
566 if (pa != (vm_offset_t)-1)
567 release_phys(pa, PAGE_SIZE_4M);
568 return (0);
569}
570
140static vm_offset_t curkva = 0;
141static vm_offset_t heapva;
142
143static phandle_t root;
144
145/*
146 * Machine dependent structures that the machine independent
147 * loader part uses.

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

550 len -= len > PAGE_SIZE_4M ? PAGE_SIZE_4M : len;
551 va += PAGE_SIZE_4M;
552 }
553 if (pa != (vm_offset_t)-1)
554 release_phys(pa, PAGE_SIZE_4M);
555 return (0);
556}
557
571static int
572mmu_mapin_sun4v(vm_offset_t va, vm_size_t len)
573{
574 vm_offset_t pa, mva;
575
576 if (va + len > curkva)
577 curkva = va + len;
578
579 pa = (vm_offset_t)-1;
580 len += va & PAGE_MASK_4M;
581 va &= ~PAGE_MASK_4M;
582 while (len) {
583 if ((va >> 22) > SUN4V_TLB_SLOT_MAX)
584 panic("%s: trying to map more than 4GB", __func__);
585 if (tlb_store[va >> 22].te_pa == -1) {
586 /* Allocate a physical page, claim the virtual area */
587 if (pa == (vm_offset_t)-1) {
588 pa = alloc_phys(PAGE_SIZE_4M, PAGE_SIZE_4M);
589 if (pa == (vm_offset_t)-1)
590 panic("%s: out of memory", __func__);
591 mva = claim_virt(va, PAGE_SIZE_4M, 0);
592 if (mva != va)
593 panic("%s: can't claim virtual page "
594 "(wanted %#lx, got %#lx)",
595 __func__, va, mva);
596 }
597
598 tlb_store[va >> 22].te_pa = pa;
599 if (map_phys(-1, PAGE_SIZE_4M, va, pa) == -1)
600 printf("%s: can't map physical page\n",
601 __func__);
602 pa = (vm_offset_t)-1;
603 }
604 len -= len > PAGE_SIZE_4M ? PAGE_SIZE_4M : len;
605 va += PAGE_SIZE_4M;
606 }
607 if (pa != (vm_offset_t)-1)
608 release_phys(pa, PAGE_SIZE_4M);
609 return (0);
610}
611
612static vm_offset_t
613init_heap(void)
614{
615
616 /* There is no need for continuous physical heap memory. */
617 heapva = (vm_offset_t)OF_claim((void *)HEAPVA, HEAPSZ, 32);
618 return (heapva);
619}

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

734 }
735
736 dtlb_store = malloc(dtlb_slot_max * sizeof(*dtlb_store));
737 itlb_store = malloc(itlb_slot_max * sizeof(*itlb_store));
738 if (dtlb_store == NULL || itlb_store == NULL)
739 panic("%s: can't allocate TLB store", __func__);
740}
741
558static vm_offset_t
559init_heap(void)
560{
561
562 /* There is no need for continuous physical heap memory. */
563 heapva = (vm_offset_t)OF_claim((void *)HEAPVA, HEAPSZ, 32);
564 return (heapva);
565}

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

680 }
681
682 dtlb_store = malloc(dtlb_slot_max * sizeof(*dtlb_store));
683 itlb_store = malloc(itlb_slot_max * sizeof(*itlb_store));
684 if (dtlb_store == NULL || itlb_store == NULL)
685 panic("%s: can't allocate TLB store", __func__);
686}
687
742static void
743tlb_init_sun4v(void)
744{
745
746 tlb_store = malloc(SUN4V_TLB_SLOT_MAX * sizeof(*tlb_store));
747 memset(tlb_store, 0xFF, SUN4V_TLB_SLOT_MAX * sizeof(*tlb_store));
748}
749
750int
751main(int (*openfirm)(void *))
752{
753 char bootpath[64];
754 char compatible[32];
755 struct devsw **dp;
756
757 /*

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

772 /*
773 * Probe for a console.
774 */
775 cons_probe();
776
777 if ((root = OF_peer(0)) == -1)
778 panic("%s: can't get root phandle", __func__);
779 OF_getprop(root, "compatible", compatible, sizeof(compatible));
688int
689main(int (*openfirm)(void *))
690{
691 char bootpath[64];
692 char compatible[32];
693 struct devsw **dp;
694
695 /*

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

710 /*
711 * Probe for a console.
712 */
713 cons_probe();
714
715 if ((root = OF_peer(0)) == -1)
716 panic("%s: can't get root phandle", __func__);
717 OF_getprop(root, "compatible", compatible, sizeof(compatible));
780 if (!strcmp(compatible, "sun4v")) {
781 printf("\nBooting with sun4v support.\n");
782 mmu_ops = &mmu_ops_sun4v;
783 is_sun4v = 1;
784 } else {
785 printf("\nBooting with sun4u support.\n");
786 mmu_ops = &mmu_ops_sun4u;
787 }
718 mmu_ops = &mmu_ops_sun4u;
788
789 mmu_ops->tlb_init();
790
791 /*
792 * Initialize devices.
793 */
794 for (dp = devsw; *dp != 0; dp++) {
795 if ((*dp)->dv_init != 0)

--- 117 unchanged lines hidden ---
719
720 mmu_ops->tlb_init();
721
722 /*
723 * Initialize devices.
724 */
725 for (dp = devsw; *dp != 0; dp++) {
726 if ((*dp)->dv_init != 0)

--- 117 unchanged lines hidden ---