2 * Copyright (C) 2010 Nathan Whitehorn
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #include <sys/cdefs.h>
27 __FBSDID("$FreeBSD$");
33 #include <machine/cpufunc.h>
34 #include <machine/psl.h>
35 #include <machine/pte.h>
36 #include <machine/slb.h>
37 #include <machine/param.h>
39 #include "bootstrap.h"
43 register_t pteg_count, pteg_mask;
45 uint64_t virtual_avail;
48 ps3mmu_map(uint64_t va, uint64_t pa)
52 uint64_t vsid, ptegidx;
54 if (pa < 0x8000000) { /* Phys mem? */
61 pt.pte_lo = LPTE_I | LPTE_G | LPTE_M | LPTE_NOEXEC;
62 shift = ADDR_PIDX_SHFT;
66 pt.pte_hi |= (vsid << LPTE_VSID_SHIFT) |
67 (((uint64_t)(va & ADDR_PIDX) >> ADDR_API_SHFT64) & LPTE_API);
69 ptegidx = vsid ^ (((uint64_t)va & ADDR_PIDX) >> shift);
71 pt.pte_hi |= LPTE_LOCKED | LPTE_VALID;
74 return (lv1_insert_pte(ptegidx, &pt, LPTE_LOCKED));
78 ps3mmu_mapdev(uint64_t pa, size_t length)
84 mapstart = (void *)(uintptr_t)virtual_avail;
86 for (spa = pa; spa < pa + length; spa += PAGE_SIZE) {
87 err = ps3mmu_map(virtual_avail, spa);
88 virtual_avail += PAGE_SIZE;
97 ps3mmu_init(int maxmem)
102 i = lv1_setup_address_space(&as_id, &ptsize);
103 pteg_count = ptsize / sizeof(struct lpteg);
104 pteg_mask = pteg_count - 1;
106 for (i = 0; i < maxmem; i += 16*1024*1024)
109 virtual_avail = 0x10000000;
111 __asm __volatile ("slbia; slbmte %0, %1; slbmte %2,%3" ::
112 "r"((0 << SLBV_VSID_SHIFT) | SLBV_L), "r"(0 | SLBE_VALID),
113 "r"(1 << SLBV_VSID_SHIFT),
114 "r"((1 << SLBE_ESID_SHIFT) | SLBE_VALID | 1));
116 mtmsr(PSL_IR | PSL_DR | PSL_RI | PSL_ME);