From owner-svn-src-all@FreeBSD.ORG Wed Nov 21 08:04:22 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 80DB01FC; Wed, 21 Nov 2012 08:04:22 +0000 (UTC) (envelope-from adrian@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 6674E8FC08; Wed, 21 Nov 2012 08:04:22 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id qAL84MQY000903; Wed, 21 Nov 2012 08:04:22 GMT (envelope-from adrian@svn.freebsd.org) Received: (from adrian@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id qAL84Mx2000900; Wed, 21 Nov 2012 08:04:22 GMT (envelope-from adrian@svn.freebsd.org) Message-Id: <201211210804.qAL84Mx2000900@svn.freebsd.org> From: Adrian Chadd Date: Wed, 21 Nov 2012 08:04:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r243370 - in head/sys/powerpc: aim wii X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Nov 2012 08:04:22 -0000 Author: adrian Date: Wed Nov 21 08:04:21 2012 New Revision: 243370 URL: http://svnweb.freebsd.org/changeset/base/243370 Log: Setup BAT0 and BAT1 on the Wii. This is the missing piece for FreeBSD/Wii, but there's still a lot of work ahead. We have to reset the MMU in locore before continuing the boot process because we don't know how the boot loaders might have setup the BATs. We also disable the PCI BAT because there's no PCI bus on the Wii. Thanks to Nathan Whitehorn and Peter Grenhan for their help. Submitted by: Margarida Gouveia Added: head/sys/powerpc/wii/locore.S (contents, props changed) Modified: head/sys/powerpc/aim/locore32.S head/sys/powerpc/aim/mmu_oea.c Modified: head/sys/powerpc/aim/locore32.S ============================================================================== --- head/sys/powerpc/aim/locore32.S Wed Nov 21 07:56:38 2012 (r243369) +++ head/sys/powerpc/aim/locore32.S Wed Nov 21 08:04:21 2012 (r243370) @@ -64,6 +64,7 @@ #include #include #include +#include "opt_platform.h" #include "opt_kdtrace.h" @@ -129,7 +130,9 @@ __start: bdnz 1b sync isync - +#ifdef WII +#include +#endif /* Zero bss, in case we were started by something unhelpful */ li 0,0 lis 8,_edata@ha Modified: head/sys/powerpc/aim/mmu_oea.c ============================================================================== --- head/sys/powerpc/aim/mmu_oea.c Wed Nov 21 07:56:38 2012 (r243369) +++ head/sys/powerpc/aim/mmu_oea.c Wed Nov 21 08:04:21 2012 (r243370) @@ -620,8 +620,17 @@ moea_cpu_bootstrap(mmu_t mmup, int ap) isync(); } - __asm __volatile("mtdbatu 1,%0" :: "r"(battable[8].batu)); - __asm __volatile("mtdbatl 1,%0" :: "r"(battable[8].batl)); +#ifdef WII + /* + * Special case for the Wii: don't install the PCI BAT. + */ + if (strcmp(installed_platform(), "wii") != 0) { +#endif + __asm __volatile("mtdbatu 1,%0" :: "r"(battable[8].batu)); + __asm __volatile("mtdbatl 1,%0" :: "r"(battable[8].batl)); +#ifdef WII + } +#endif isync(); __asm __volatile("mtibatu 1,%0" :: "r"(0)); @@ -660,26 +669,26 @@ moea_bootstrap(mmu_t mmup, vm_offset_t k battable[0x0].batl = BATL(0x00000000, BAT_M, BAT_PP_RW); battable[0x0].batu = BATU(0x00000000, BAT_BL_256M, BAT_Vs); - /* - * Map PCI memory space. - */ - battable[0x8].batl = BATL(0x80000000, BAT_I|BAT_G, BAT_PP_RW); - battable[0x8].batu = BATU(0x80000000, BAT_BL_256M, BAT_Vs); + /* + * Map PCI memory space. + */ + battable[0x8].batl = BATL(0x80000000, BAT_I|BAT_G, BAT_PP_RW); + battable[0x8].batu = BATU(0x80000000, BAT_BL_256M, BAT_Vs); - battable[0x9].batl = BATL(0x90000000, BAT_I|BAT_G, BAT_PP_RW); - battable[0x9].batu = BATU(0x90000000, BAT_BL_256M, BAT_Vs); + battable[0x9].batl = BATL(0x90000000, BAT_I|BAT_G, BAT_PP_RW); + battable[0x9].batu = BATU(0x90000000, BAT_BL_256M, BAT_Vs); - battable[0xa].batl = BATL(0xa0000000, BAT_I|BAT_G, BAT_PP_RW); - battable[0xa].batu = BATU(0xa0000000, BAT_BL_256M, BAT_Vs); + battable[0xa].batl = BATL(0xa0000000, BAT_I|BAT_G, BAT_PP_RW); + battable[0xa].batu = BATU(0xa0000000, BAT_BL_256M, BAT_Vs); - battable[0xb].batl = BATL(0xb0000000, BAT_I|BAT_G, BAT_PP_RW); - battable[0xb].batu = BATU(0xb0000000, BAT_BL_256M, BAT_Vs); + battable[0xb].batl = BATL(0xb0000000, BAT_I|BAT_G, BAT_PP_RW); + battable[0xb].batu = BATU(0xb0000000, BAT_BL_256M, BAT_Vs); - /* - * Map obio devices. - */ - battable[0xf].batl = BATL(0xf0000000, BAT_I|BAT_G, BAT_PP_RW); - battable[0xf].batu = BATU(0xf0000000, BAT_BL_256M, BAT_Vs); + /* + * Map obio devices. + */ + battable[0xf].batl = BATL(0xf0000000, BAT_I|BAT_G, BAT_PP_RW); + battable[0xf].batu = BATU(0xf0000000, BAT_BL_256M, BAT_Vs); /* * Use an IBAT and a DBAT to map the bottom segment of memory @@ -694,9 +703,15 @@ moea_bootstrap(mmu_t mmup, vm_offset_t k :: "r"(battable[0].batu), "r"(battable[0].batl)); mtmsr(msr); - /* map pci space */ - __asm __volatile("mtdbatu 1,%0" :: "r"(battable[8].batu)); - __asm __volatile("mtdbatl 1,%0" :: "r"(battable[8].batl)); +#ifdef WII + if (strcmp(installed_platform(), "wii") != 0) { +#endif + /* map pci space */ + __asm __volatile("mtdbatu 1,%0" :: "r"(battable[8].batu)); + __asm __volatile("mtdbatl 1,%0" :: "r"(battable[8].batl)); +#ifdef WII + } +#endif isync(); /* set global direct map flag */ Added: head/sys/powerpc/wii/locore.S ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/powerpc/wii/locore.S Wed Nov 21 08:04:21 2012 (r243370) @@ -0,0 +1,131 @@ +/*- + * Copyright (C) 2012 Margarida Gouveia + * 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. + * + * $FreeBSD$ + */ + +#include +/* + * When we are invoked from Wii loaders, the state of the MMU and the BAT + * mappings can vary. In this file we try to reset the MMU to a state + * that lets us boot FreeBSD. + * + * N.B.: keep the BAT0 in sync with mmu_oea.c and never touch BAT1 later. + * + * This file is being included from aim/locore32.S. + */ + +#define MMU_REALMODE() \ + mfmsr %r12; \ + rlwinm %r12, %r12, 0, ~(PSL_DR|PSL_IR);\ + sync; \ + bl 1f; \ +1: \ + mflr %r11; \ + clrlwi %r11, %r11, 3; /* XXX why? */ \ + addi %r11, %r11, 2f - 1b; \ + mtsrr0 %r11; \ + mtsrr1 %r12; /* Disables the MMU */ \ + isync; \ + rfi; \ +2: + +#define MMU_VIRTUALMODE() \ + bl 3f; \ +3: \ + mflr %r11; \ + addi %r11, %r11, 4f - 3b; \ + mfmsr %r12; \ + ori %r12, %r12, PSL_DR|PSL_IR; \ + mtsrr0 %r11; \ + mtsrr1 %r12; /* Enables the MMU */ \ + isync; \ + rfi; \ +4: + + MMU_REALMODE() + + /* Reset standard BATs */ + li %r11, 0 + mtibatu 0, %r11 + mtibatl 0, %r11 + mtdbatu 0, %r11 + mtdbatl 0, %r11 + mtibatu 1, %r11 + mtibatl 1, %r11 + mtdbatu 1, %r11 + mtdbatl 1, %r11 + mtibatu 2, %r11 + mtibatl 2, %r11 + mtdbatu 2, %r11 + mtdbatl 2, %r11 + mtibatu 3, %r11 + mtibatl 3, %r11 + mtdbatu 3, %r11 + mtdbatl 3, %r11 + + /* Reset high BATs. IBAT[4-7][UL] + DBAT[4-7][UL] */ + mtspr 560, %r11 + mtspr 561, %r11 + mtspr 562, %r11 + mtspr 563, %r11 + mtspr 564, %r11 + mtspr 565, %r11 + mtspr 566, %r11 + mtspr 567, %r11 + mtspr 568, %r11 + mtspr 569, %r11 + mtspr 570, %r11 + mtspr 571, %r11 + mtspr 572, %r11 + mtspr 573, %r11 + mtspr 574, %r11 + mtspr 575, %r11 + + /* + * We need to setup BAT0 as in mmu_oea.c. + */ + li %r11, BATU(0x00000000, BAT_BL_256M, BAT_Vs) + li %r12, BATL(0x00000000, BAT_M, BAT_PP_RW) + mtdbatu 0, %r11 + mtdbatl 0, %r12 + mtibatu 0, %r11 + mtibatl 0, %r12 + isync + + /* + * We use BAT1 to be able to write I/O memory, including the + * framebuffer registers. + */ + /* BATU(0x0c000000, BAT_BL_32M, BAT_Vs) */ + lis %r11, 0x0c00 + ori %r11, %r11, BAT_BL_32M|BAT_Vs + /* BATL(0x0c000000, BAT_I|BAT_G, BAT_PP_RW) */ + lis %r12, 0x0c00 + ori %r12, %r12, BAT_I|BAT_G|BAT_PP_RW + mtdbatu 1, %r11 + mtdbatl 1, %r12 + isync + + MMU_VIRTUALMODE()