Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008 Freescale Semiconductor, Inc. |
| 3 | * |
| 4 | * (C) Copyright 2000 |
| 5 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 6 | * |
| 7 | * See file CREDITS for list of people who contributed to this |
| 8 | * project. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of |
| 13 | * the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 23 | * MA 02111-1307 USA |
| 24 | */ |
| 25 | |
| 26 | #include <common.h> |
| 27 | #include <asm/fsl_law.h> |
| 28 | #include <asm/io.h> |
| 29 | |
Kumar Gala | 75639e0 | 2008-06-11 00:44:10 -0500 | [diff] [blame] | 30 | DECLARE_GLOBAL_DATA_PTR; |
| 31 | |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 32 | #define LAWAR_EN 0x80000000 |
Kumar Gala | 75639e0 | 2008-06-11 00:44:10 -0500 | [diff] [blame] | 33 | /* number of LAWs in the hw implementation */ |
| 34 | #if defined(CONFIG_MPC8540) || defined(CONFIG_MPC8541) || \ |
| 35 | defined(CONFIG_MPC8560) || defined(CONFIG_MPC8555) |
| 36 | #define FSL_HW_NUM_LAWS 8 |
| 37 | #elif defined(CONFIG_MPC8548) || defined(CONFIG_MPC8544) || \ |
| 38 | defined(CONFIG_MPC8568) || \ |
| 39 | defined(CONFIG_MPC8641) || defined(CONFIG_MPC8610) |
| 40 | #define FSL_HW_NUM_LAWS 10 |
Kumar Gala | cd77728 | 2008-08-12 11:14:19 -0500 | [diff] [blame] | 41 | #elif defined(CONFIG_MPC8536) || defined(CONFIG_MPC8572) |
Kumar Gala | 75639e0 | 2008-06-11 00:44:10 -0500 | [diff] [blame] | 42 | #define FSL_HW_NUM_LAWS 12 |
| 43 | #else |
| 44 | #error FSL_HW_NUM_LAWS not defined for this platform |
| 45 | #endif |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 46 | |
| 47 | void set_law(u8 idx, phys_addr_t addr, enum law_size sz, enum law_trgt_if id) |
| 48 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 49 | volatile u32 *base = (volatile u32 *)(CONFIG_SYS_IMMR + 0xc08); |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 50 | volatile u32 *lawbar = base + 8 * idx; |
| 51 | volatile u32 *lawar = base + 8 * idx + 2; |
| 52 | |
Kumar Gala | 75639e0 | 2008-06-11 00:44:10 -0500 | [diff] [blame] | 53 | gd->used_laws |= (1 << idx); |
| 54 | |
Ed Swarthout | cf92b98 | 2008-10-09 01:25:55 -0500 | [diff] [blame] | 55 | out_be32(lawar, 0); |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 56 | out_be32(lawbar, addr >> 12); |
| 57 | out_be32(lawar, LAWAR_EN | ((u32)id << 20) | (u32)sz); |
| 58 | |
| 59 | return ; |
| 60 | } |
| 61 | |
Kumar Gala | 75639e0 | 2008-06-11 00:44:10 -0500 | [diff] [blame] | 62 | int set_next_law(phys_addr_t addr, enum law_size sz, enum law_trgt_if id) |
| 63 | { |
| 64 | u32 idx = ffz(gd->used_laws); |
| 65 | |
| 66 | if (idx >= FSL_HW_NUM_LAWS) |
| 67 | return -1; |
| 68 | |
| 69 | set_law(idx, addr, sz, id); |
| 70 | |
| 71 | return idx; |
| 72 | } |
| 73 | |
Kumar Gala | a9abb00 | 2008-06-10 16:16:02 -0500 | [diff] [blame] | 74 | int set_last_law(phys_addr_t addr, enum law_size sz, enum law_trgt_if id) |
| 75 | { |
| 76 | u32 idx; |
| 77 | |
| 78 | /* we have no LAWs free */ |
| 79 | if (gd->used_laws == -1) |
| 80 | return -1; |
| 81 | |
| 82 | /* grab the last free law */ |
| 83 | idx = __ilog2(~(gd->used_laws)); |
| 84 | |
| 85 | if (idx >= FSL_HW_NUM_LAWS) |
| 86 | return -1; |
| 87 | |
| 88 | set_law(idx, addr, sz, id); |
| 89 | |
| 90 | return idx; |
| 91 | } |
| 92 | |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 93 | void disable_law(u8 idx) |
| 94 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 95 | volatile u32 *base = (volatile u32 *)(CONFIG_SYS_IMMR + 0xc08); |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 96 | volatile u32 *lawbar = base + 8 * idx; |
| 97 | volatile u32 *lawar = base + 8 * idx + 2; |
| 98 | |
Kumar Gala | 75639e0 | 2008-06-11 00:44:10 -0500 | [diff] [blame] | 99 | gd->used_laws &= ~(1 << idx); |
| 100 | |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 101 | out_be32(lawar, 0); |
| 102 | out_be32(lawbar, 0); |
| 103 | |
| 104 | return; |
| 105 | } |
| 106 | |
Becky Bruce | 2a15f75 | 2008-01-23 16:31:05 -0600 | [diff] [blame] | 107 | void print_laws(void) |
| 108 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 109 | volatile u32 *base = (volatile u32 *)(CONFIG_SYS_IMMR + 0xc08); |
Becky Bruce | 2a15f75 | 2008-01-23 16:31:05 -0600 | [diff] [blame] | 110 | volatile u32 *lawbar = base; |
| 111 | volatile u32 *lawar = base + 2; |
| 112 | int i; |
| 113 | |
| 114 | printf("\nLocal Access Window Configuration\n"); |
| 115 | for(i = 0; i < FSL_HW_NUM_LAWS; i++) { |
| 116 | printf("\tLAWBAR%d : 0x%08x, LAWAR%d : 0x%08x\n", |
| 117 | i, in_be32(lawbar), i, in_be32(lawar)); |
| 118 | lawbar += 8; |
| 119 | lawar += 8; |
| 120 | } |
| 121 | |
| 122 | return; |
| 123 | } |
| 124 | |
Kumar Gala | 61ed053 | 2008-08-26 15:01:28 -0500 | [diff] [blame] | 125 | /* use up to 2 LAWs for DDR, used the last available LAWs */ |
| 126 | int set_ddr_laws(u64 start, u64 sz, enum law_trgt_if id) |
| 127 | { |
| 128 | u64 start_align, law_sz; |
| 129 | int law_sz_enc; |
| 130 | |
| 131 | if (start == 0) |
| 132 | start_align = 1ull << (LAW_SIZE_32G + 1); |
| 133 | else |
| 134 | start_align = 1ull << (ffs64(start) - 1); |
| 135 | law_sz = min(start_align, sz); |
| 136 | law_sz_enc = __ilog2_u64(law_sz) - 1; |
| 137 | |
| 138 | if (set_last_law(start, law_sz_enc, id) < 0) |
| 139 | return -1; |
| 140 | |
| 141 | /* do we still have anything to map */ |
| 142 | sz = sz - law_sz; |
| 143 | if (sz) { |
| 144 | start += law_sz; |
| 145 | |
| 146 | start_align = 1ull << (ffs64(start) - 1); |
| 147 | law_sz = min(start_align, sz); |
| 148 | law_sz_enc = __ilog2_u64(law_sz) - 1; |
| 149 | |
| 150 | if (set_last_law(start, law_sz_enc, id) < 0) |
| 151 | return -1; |
| 152 | } else { |
| 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | /* do we still have anything to map */ |
| 157 | sz = sz - law_sz; |
| 158 | if (sz) |
| 159 | return 1; |
| 160 | |
| 161 | return 0; |
| 162 | } |
| 163 | |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 164 | void init_laws(void) |
| 165 | { |
| 166 | int i; |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 167 | |
Kumar Gala | 75639e0 | 2008-06-11 00:44:10 -0500 | [diff] [blame] | 168 | gd->used_laws = ~((1 << FSL_HW_NUM_LAWS) - 1); |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 169 | |
Kumar Gala | 75639e0 | 2008-06-11 00:44:10 -0500 | [diff] [blame] | 170 | for (i = 0; i < num_law_entries; i++) { |
| 171 | if (law_table[i].index == -1) |
| 172 | set_next_law(law_table[i].addr, law_table[i].size, |
| 173 | law_table[i].trgt_id); |
| 174 | else |
| 175 | set_law(law_table[i].index, law_table[i].addr, |
| 176 | law_table[i].size, law_table[i].trgt_id); |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | return ; |
| 180 | } |