Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 Mar 2010 18:35:55 +0000 (UTC)
From:      Nathan Whitehorn <nwhitehorn@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r205849 - projects/ppc64/sys/boot/powerpc/ps3
Message-ID:  <201003291835.o2TIZtG6037618@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: nwhitehorn
Date: Mon Mar 29 18:35:55 2010
New Revision: 205849
URL: http://svn.freebsd.org/changeset/base/205849

Log:
  Turn on the MMU, which is required to use the frame buffer or to do much
  of anything. The relevant hypervisor calls are faked, for now, with
  replacements that set up a regular real page table, but Mambo will soon
  be a thing of the past.

Added:
  projects/ppc64/sys/boot/powerpc/ps3/lv1call.h
  projects/ppc64/sys/boot/powerpc/ps3/lv1call_fake.c
  projects/ppc64/sys/boot/powerpc/ps3/ps3mmu.c
Modified:
  projects/ppc64/sys/boot/powerpc/ps3/Makefile
  projects/ppc64/sys/boot/powerpc/ps3/main.c

Modified: projects/ppc64/sys/boot/powerpc/ps3/Makefile
==============================================================================
--- projects/ppc64/sys/boot/powerpc/ps3/Makefile	Mon Mar 29 18:24:08 2010	(r205848)
+++ projects/ppc64/sys/boot/powerpc/ps3/Makefile	Mon Mar 29 18:35:55 2010	(r205849)
@@ -9,7 +9,7 @@ BINDIR?=	/boot
 INSTALLFLAGS=	-b
 
 # Architecture-specific loader code
-SRCS=		start.S conf.c metadata.c vers.c main.c
+SRCS=		start.S conf.c metadata.c vers.c main.c lv1call_fake.c ps3mmu.c
 SRCS+=		ucmpdi2.c
 
 LOADER_DISK_SUPPORT?=	no
@@ -70,7 +70,7 @@ CFLAGS+=	-I.
 
 CLEANFILES+=	vers.c loader.help
 
-CFLAGS+=	-ffreestanding -msoft-float
+CFLAGS+=	-ffreestanding -msoft-float -DAIM
 # load address. set in linker script
 RELOC?=		0x0
 CFLAGS+=	-DRELOC=${RELOC}

Added: projects/ppc64/sys/boot/powerpc/ps3/lv1call.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ projects/ppc64/sys/boot/powerpc/ps3/lv1call.h	Mon Mar 29 18:35:55 2010	(r205849)
@@ -0,0 +1,38 @@
+/*-
+ * Copyright (C) 2010 Nathan Whitehorn
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _PS3_LV1CALL_H
+#define _PS3_LV1CALL_H
+
+int lv1_insert_htab_entry(register_t htab_id, register_t ptegidx, 
+	uint64_t pte_hi, uint64_t pte_lo, register_t lockflags,
+	register_t flags, uint64_t *evict_index, uint64_t *ev_pte_hi,
+	uint64_t *ev_pte_lo);
+int lv1_construct_virtual_address_space(int htab_size, int npgsizes,
+	uint64_t page_sizes, uint64_t *as_id, uint64_t *ptsize);
+int lv1_select_virtual_address_space(uint64_t as);
+
+#endif
+

Added: projects/ppc64/sys/boot/powerpc/ps3/lv1call_fake.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ projects/ppc64/sys/boot/powerpc/ps3/lv1call_fake.c	Mon Mar 29 18:35:55 2010	(r205849)
@@ -0,0 +1,97 @@
+/*-
+ * Copyright (C) 2010 Nathan Whitehorn
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/sys/boot/powerpc/ofw/start.c 174722 2007-12-17 22:18:07Z marcel $");
+
+
+#include <stand.h>
+#include <machine/pte.h>
+
+#include "bootstrap.h"
+#include "lv1call.h"
+
+#define PTEG_COUNT	2048
+#define PTEG_MASK	((uint64_t)PTEG_COUNT - 1)
+
+static struct lpteg *pagetable = (struct lpteg *)0x80000;
+
+	int mambocall(int, ...);
+	#define mambo_print(a) mambocall(0,a,strlen(a));
+
+int
+lv1_insert_htab_entry(register_t htab_id, register_t ptegidx, 
+    uint64_t pte_hi, uint64_t pte_lo, register_t lockflags,
+    register_t flags, uint64_t *evict_index, uint64_t *ev_pte_hi,
+    uint64_t *ev_pte_lo)
+{
+	struct  lpte *pt;
+	int     i;
+
+	/*
+	 * First try primary hash.
+	 */
+	for (pt = pagetable[ptegidx].pt, i = 0; i < 8; i++, pt++) {
+		if (!(pt->pte_hi & LPTE_VALID)) {
+			pte_hi &= ~LPTE_HID;
+			pt->pte_lo = pte_lo;
+			pt->pte_hi = pte_hi;
+			return (0);
+		}
+	}
+
+	/*
+	 * Now try secondary hash.
+	 */
+        ptegidx ^= PTEG_MASK;
+
+	for (pt = pagetable[ptegidx].pt, i = 0; i < 8; i++, pt++) {
+		if (!(pt->pte_hi & LPTE_VALID)) {
+			pte_hi |= LPTE_HID;
+			pt->pte_lo = pte_lo;
+			pt->pte_hi = pte_hi;
+			return (0);
+		}
+        }
+
+	return (-1);
+}
+
+int
+lv1_construct_virtual_address_space(int htab_size, int npgsizes,
+    uint64_t page_sizes, uint64_t *as_id, uint64_t *ptsize)
+{
+	*ptsize = PTEG_COUNT * sizeof(struct lpteg);
+	*as_id = 0;
+	return (0);
+}
+
+int
+lv1_select_virtual_address_space(uint64_t as)
+{
+	__asm __volatile("ptesync; mtsdr1 %0; isync" :: "r"((u_int)pagetable | ffs(PTEG_MASK >> 7)));
+	return (0);
+}
+

Modified: projects/ppc64/sys/boot/powerpc/ps3/main.c
==============================================================================
--- projects/ppc64/sys/boot/powerpc/ps3/main.c	Mon Mar 29 18:24:08 2010	(r205848)
+++ projects/ppc64/sys/boot/powerpc/ps3/main.c	Mon Mar 29 18:35:55 2010	(r205849)
@@ -35,9 +35,12 @@ __FBSDID("$FreeBSD: head/sys/boot/powerp
 
 struct arch_switch	archsw;
 
+int ps3mmu_init(int maxmem);
+
 int
 main(void)
 {
+	ps3mmu_init(128*1024*1024);
 	mambo_print("Hello world\n");
 
 	return (0);

Added: projects/ppc64/sys/boot/powerpc/ps3/ps3mmu.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ projects/ppc64/sys/boot/powerpc/ps3/ps3mmu.c	Mon Mar 29 18:35:55 2010	(r205849)
@@ -0,0 +1,94 @@
+/*-
+ * Copyright (C) 2010 Nathan Whitehorn
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/sys/boot/powerpc/ofw/start.c 174722 2007-12-17 22:18:07Z marcel $");
+
+#include <stand.h>
+#include <stdint.h>
+
+#define _KERNEL
+#include <machine/cpufunc.h>
+#include <machine/psl.h>
+#include <machine/pte.h>
+#include <machine/slb.h>
+
+#include "bootstrap.h"
+#include "lv1call.h"
+
+#define PS3_LPAR_VAS_ID_CURRENT 0
+
+register_t pteg_count, pteg_mask;
+
+void
+ps3mmu_map(uint64_t va, uint64_t pa)
+{
+	struct lpte pt, expt;
+	struct lpteg pteg;
+	uint64_t idx, vsid, ptegidx;
+	
+	if (pa < 0x8000000) { /* Phys mem? */
+		pt.pte_hi = LPTE_BIG;
+		pt.pte_lo = LPTE_M;
+		vsid = 0;
+	} else {
+		pt.pte_hi = 0;
+		pt.pte_lo = LPTE_I | LPTE_G;
+		vsid = 1;
+	}
+
+	pt.pte_hi |= (vsid << LPTE_VSID_SHIFT) |
+            (((uint64_t)(va & ADDR_PIDX) >> ADDR_API_SHFT64) & LPTE_API);
+	pt.pte_hi |= LPTE_VALID;
+
+	ptegidx = vsid ^ (((uint64_t)va & ADDR_PIDX) >> ADDR_PIDX_SHFT);
+	ptegidx &= pteg_mask;
+
+	lv1_insert_htab_entry(PS3_LPAR_VAS_ID_CURRENT, ptegidx, pt.pte_hi,
+	    pt.pte_lo, 0x10, 0, &idx, &expt.pte_hi, &expt.pte_lo);
+}
+
+int
+ps3mmu_init(int maxmem)
+{
+	uint64_t as, ptsize;
+	int i;
+
+	lv1_construct_virtual_address_space(18 /* log2 256 KB */, 1,
+	    24ULL << 56, &as, &ptsize);
+	pteg_count = ptsize / sizeof(struct lpteg);
+	pteg_mask = pteg_count - 1;
+
+	lv1_select_virtual_address_space(as);
+	for (i = 0; i < maxmem; i += 16*1024*1024)
+		ps3mmu_map(i,i);
+	__asm __volatile ("slbia; slbmte %0, %1; slbmte %2,%3" ::
+	    "r"(0 | SLBV_L), "r"(0 | SLBE_VALID),
+	    "r"(1 << SLBV_VSID_SHIFT),
+	    "r"((0xf << SLBE_ESID_SHIFT) | SLBE_VALID | 1));
+
+	mtmsr(mfmsr() | PSL_IR | PSL_DR);
+}
+



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201003291835.o2TIZtG6037618>