1*c0474d58SKonstantin Porotchkin /* 2*c0474d58SKonstantin Porotchkin * Copyright (C) 2018 Marvell International Ltd. 3*c0474d58SKonstantin Porotchkin * 4*c0474d58SKonstantin Porotchkin * SPDX-License-Identifier: BSD-3-Clause 5*c0474d58SKonstantin Porotchkin * https://spdx.org/licenses 6*c0474d58SKonstantin Porotchkin */ 7*c0474d58SKonstantin Porotchkin 8*c0474d58SKonstantin Porotchkin /* CCU unit device driver for Marvell AP807, AP807 and AP810 SoCs */ 9*c0474d58SKonstantin Porotchkin 10*c0474d58SKonstantin Porotchkin #include <a8k_common.h> 11*c0474d58SKonstantin Porotchkin #include <ccu.h> 12*c0474d58SKonstantin Porotchkin #include <debug.h> 13*c0474d58SKonstantin Porotchkin #include <mmio.h> 14*c0474d58SKonstantin Porotchkin #include <mvebu.h> 15*c0474d58SKonstantin Porotchkin #include <mvebu_def.h> 16*c0474d58SKonstantin Porotchkin 17*c0474d58SKonstantin Porotchkin #if LOG_LEVEL >= LOG_LEVEL_INFO 18*c0474d58SKonstantin Porotchkin #define DEBUG_ADDR_MAP 19*c0474d58SKonstantin Porotchkin #endif 20*c0474d58SKonstantin Porotchkin 21*c0474d58SKonstantin Porotchkin /* common defines */ 22*c0474d58SKonstantin Porotchkin #define WIN_ENABLE_BIT (0x1) 23*c0474d58SKonstantin Porotchkin /* Physical address of the base of the window = {AddrLow[19:0],20’h0} */ 24*c0474d58SKonstantin Porotchkin #define ADDRESS_SHIFT (20 - 4) 25*c0474d58SKonstantin Porotchkin #define ADDRESS_MASK (0xFFFFFFF0) 26*c0474d58SKonstantin Porotchkin #define CCU_WIN_ALIGNMENT (0x100000) 27*c0474d58SKonstantin Porotchkin 28*c0474d58SKonstantin Porotchkin #define IS_DRAM_TARGET(tgt) ((((tgt) == DRAM_0_TID) || \ 29*c0474d58SKonstantin Porotchkin ((tgt) == DRAM_1_TID) || \ 30*c0474d58SKonstantin Porotchkin ((tgt) == RAR_TID)) ? 1 : 0) 31*c0474d58SKonstantin Porotchkin 32*c0474d58SKonstantin Porotchkin /* For storage of CR, SCR, ALR, AHR abd GCR */ 33*c0474d58SKonstantin Porotchkin static uint32_t ccu_regs_save[MVEBU_CCU_MAX_WINS * 4 + 1]; 34*c0474d58SKonstantin Porotchkin 35*c0474d58SKonstantin Porotchkin #ifdef DEBUG_ADDR_MAP 36*c0474d58SKonstantin Porotchkin static void dump_ccu(int ap_index) 37*c0474d58SKonstantin Porotchkin { 38*c0474d58SKonstantin Porotchkin uint32_t win_id, win_cr, alr, ahr; 39*c0474d58SKonstantin Porotchkin uint8_t target_id; 40*c0474d58SKonstantin Porotchkin uint64_t start, end; 41*c0474d58SKonstantin Porotchkin 42*c0474d58SKonstantin Porotchkin /* Dump all AP windows */ 43*c0474d58SKonstantin Porotchkin tf_printf("\tbank target start end\n"); 44*c0474d58SKonstantin Porotchkin tf_printf("\t----------------------------------------------------\n"); 45*c0474d58SKonstantin Porotchkin for (win_id = 0; win_id < MVEBU_CCU_MAX_WINS; win_id++) { 46*c0474d58SKonstantin Porotchkin win_cr = mmio_read_32(CCU_WIN_CR_OFFSET(ap_index, win_id)); 47*c0474d58SKonstantin Porotchkin if (win_cr & WIN_ENABLE_BIT) { 48*c0474d58SKonstantin Porotchkin target_id = (win_cr >> CCU_TARGET_ID_OFFSET) & 49*c0474d58SKonstantin Porotchkin CCU_TARGET_ID_MASK; 50*c0474d58SKonstantin Porotchkin alr = mmio_read_32(CCU_WIN_ALR_OFFSET(ap_index, 51*c0474d58SKonstantin Porotchkin win_id)); 52*c0474d58SKonstantin Porotchkin ahr = mmio_read_32(CCU_WIN_AHR_OFFSET(ap_index, 53*c0474d58SKonstantin Porotchkin win_id)); 54*c0474d58SKonstantin Porotchkin start = ((uint64_t)alr << ADDRESS_SHIFT); 55*c0474d58SKonstantin Porotchkin end = (((uint64_t)ahr + 0x10) << ADDRESS_SHIFT); 56*c0474d58SKonstantin Porotchkin tf_printf("\tccu %02x 0x%016llx 0x%016llx\n", 57*c0474d58SKonstantin Porotchkin target_id, start, end); 58*c0474d58SKonstantin Porotchkin } 59*c0474d58SKonstantin Porotchkin } 60*c0474d58SKonstantin Porotchkin win_cr = mmio_read_32(CCU_WIN_GCR_OFFSET(ap_index)); 61*c0474d58SKonstantin Porotchkin target_id = (win_cr >> CCU_GCR_TARGET_OFFSET) & CCU_GCR_TARGET_MASK; 62*c0474d58SKonstantin Porotchkin tf_printf("\tccu GCR %d - all other transactions\n", target_id); 63*c0474d58SKonstantin Porotchkin } 64*c0474d58SKonstantin Porotchkin #endif 65*c0474d58SKonstantin Porotchkin 66*c0474d58SKonstantin Porotchkin void ccu_win_check(struct addr_map_win *win) 67*c0474d58SKonstantin Porotchkin { 68*c0474d58SKonstantin Porotchkin /* check if address is aligned to 1M */ 69*c0474d58SKonstantin Porotchkin if (IS_NOT_ALIGN(win->base_addr, CCU_WIN_ALIGNMENT)) { 70*c0474d58SKonstantin Porotchkin win->base_addr = ALIGN_UP(win->base_addr, CCU_WIN_ALIGNMENT); 71*c0474d58SKonstantin Porotchkin NOTICE("%s: Align up the base address to 0x%llx\n", 72*c0474d58SKonstantin Porotchkin __func__, win->base_addr); 73*c0474d58SKonstantin Porotchkin } 74*c0474d58SKonstantin Porotchkin 75*c0474d58SKonstantin Porotchkin /* size parameter validity check */ 76*c0474d58SKonstantin Porotchkin if (IS_NOT_ALIGN(win->win_size, CCU_WIN_ALIGNMENT)) { 77*c0474d58SKonstantin Porotchkin win->win_size = ALIGN_UP(win->win_size, CCU_WIN_ALIGNMENT); 78*c0474d58SKonstantin Porotchkin NOTICE("%s: Aligning size to 0x%llx\n", 79*c0474d58SKonstantin Porotchkin __func__, win->win_size); 80*c0474d58SKonstantin Porotchkin } 81*c0474d58SKonstantin Porotchkin } 82*c0474d58SKonstantin Porotchkin 83*c0474d58SKonstantin Porotchkin void ccu_enable_win(int ap_index, struct addr_map_win *win, uint32_t win_id) 84*c0474d58SKonstantin Porotchkin { 85*c0474d58SKonstantin Porotchkin uint32_t ccu_win_reg; 86*c0474d58SKonstantin Porotchkin uint32_t alr, ahr; 87*c0474d58SKonstantin Porotchkin uint64_t end_addr; 88*c0474d58SKonstantin Porotchkin 89*c0474d58SKonstantin Porotchkin if ((win_id == 0) || (win_id > MVEBU_CCU_MAX_WINS)) { 90*c0474d58SKonstantin Porotchkin ERROR("Enabling wrong CCU window %d!\n", win_id); 91*c0474d58SKonstantin Porotchkin return; 92*c0474d58SKonstantin Porotchkin } 93*c0474d58SKonstantin Porotchkin 94*c0474d58SKonstantin Porotchkin end_addr = (win->base_addr + win->win_size - 1); 95*c0474d58SKonstantin Porotchkin alr = (uint32_t)((win->base_addr >> ADDRESS_SHIFT) & ADDRESS_MASK); 96*c0474d58SKonstantin Porotchkin ahr = (uint32_t)((end_addr >> ADDRESS_SHIFT) & ADDRESS_MASK); 97*c0474d58SKonstantin Porotchkin 98*c0474d58SKonstantin Porotchkin mmio_write_32(CCU_WIN_ALR_OFFSET(ap_index, win_id), alr); 99*c0474d58SKonstantin Porotchkin mmio_write_32(CCU_WIN_AHR_OFFSET(ap_index, win_id), ahr); 100*c0474d58SKonstantin Porotchkin 101*c0474d58SKonstantin Porotchkin ccu_win_reg = WIN_ENABLE_BIT; 102*c0474d58SKonstantin Porotchkin ccu_win_reg |= (win->target_id & CCU_TARGET_ID_MASK) 103*c0474d58SKonstantin Porotchkin << CCU_TARGET_ID_OFFSET; 104*c0474d58SKonstantin Porotchkin mmio_write_32(CCU_WIN_CR_OFFSET(ap_index, win_id), ccu_win_reg); 105*c0474d58SKonstantin Porotchkin } 106*c0474d58SKonstantin Porotchkin 107*c0474d58SKonstantin Porotchkin static void ccu_disable_win(int ap_index, uint32_t win_id) 108*c0474d58SKonstantin Porotchkin { 109*c0474d58SKonstantin Porotchkin uint32_t win_reg; 110*c0474d58SKonstantin Porotchkin 111*c0474d58SKonstantin Porotchkin if ((win_id == 0) || (win_id > MVEBU_CCU_MAX_WINS)) { 112*c0474d58SKonstantin Porotchkin ERROR("Disabling wrong CCU window %d!\n", win_id); 113*c0474d58SKonstantin Porotchkin return; 114*c0474d58SKonstantin Porotchkin } 115*c0474d58SKonstantin Porotchkin 116*c0474d58SKonstantin Porotchkin win_reg = mmio_read_32(CCU_WIN_CR_OFFSET(ap_index, win_id)); 117*c0474d58SKonstantin Porotchkin win_reg &= ~WIN_ENABLE_BIT; 118*c0474d58SKonstantin Porotchkin mmio_write_32(CCU_WIN_CR_OFFSET(ap_index, win_id), win_reg); 119*c0474d58SKonstantin Porotchkin } 120*c0474d58SKonstantin Porotchkin 121*c0474d58SKonstantin Porotchkin /* Insert/Remove temporary window for using the out-of reset default 122*c0474d58SKonstantin Porotchkin * CPx base address to access the CP configuration space prior to 123*c0474d58SKonstantin Porotchkin * the further base address update in accordance with address mapping 124*c0474d58SKonstantin Porotchkin * design. 125*c0474d58SKonstantin Porotchkin * 126*c0474d58SKonstantin Porotchkin * NOTE: Use the same window array for insertion and removal of 127*c0474d58SKonstantin Porotchkin * temporary windows. 128*c0474d58SKonstantin Porotchkin */ 129*c0474d58SKonstantin Porotchkin void ccu_temp_win_insert(int ap_index, struct addr_map_win *win, int size) 130*c0474d58SKonstantin Porotchkin { 131*c0474d58SKonstantin Porotchkin uint32_t win_id; 132*c0474d58SKonstantin Porotchkin 133*c0474d58SKonstantin Porotchkin for (int i = 0; i < size; i++) { 134*c0474d58SKonstantin Porotchkin win_id = MVEBU_CCU_MAX_WINS - 1 - i; 135*c0474d58SKonstantin Porotchkin ccu_win_check(win); 136*c0474d58SKonstantin Porotchkin ccu_enable_win(ap_index, win, win_id); 137*c0474d58SKonstantin Porotchkin win++; 138*c0474d58SKonstantin Porotchkin } 139*c0474d58SKonstantin Porotchkin } 140*c0474d58SKonstantin Porotchkin 141*c0474d58SKonstantin Porotchkin /* 142*c0474d58SKonstantin Porotchkin * NOTE: Use the same window array for insertion and removal of 143*c0474d58SKonstantin Porotchkin * temporary windows. 144*c0474d58SKonstantin Porotchkin */ 145*c0474d58SKonstantin Porotchkin void ccu_temp_win_remove(int ap_index, struct addr_map_win *win, int size) 146*c0474d58SKonstantin Porotchkin { 147*c0474d58SKonstantin Porotchkin uint32_t win_id; 148*c0474d58SKonstantin Porotchkin 149*c0474d58SKonstantin Porotchkin for (int i = 0; i < size; i++) { 150*c0474d58SKonstantin Porotchkin uint64_t base; 151*c0474d58SKonstantin Porotchkin uint32_t target; 152*c0474d58SKonstantin Porotchkin 153*c0474d58SKonstantin Porotchkin win_id = MVEBU_CCU_MAX_WINS - 1 - i; 154*c0474d58SKonstantin Porotchkin 155*c0474d58SKonstantin Porotchkin target = mmio_read_32(CCU_WIN_CR_OFFSET(ap_index, win_id)); 156*c0474d58SKonstantin Porotchkin target >>= CCU_TARGET_ID_OFFSET; 157*c0474d58SKonstantin Porotchkin target &= CCU_TARGET_ID_MASK; 158*c0474d58SKonstantin Porotchkin 159*c0474d58SKonstantin Porotchkin base = mmio_read_32(CCU_WIN_ALR_OFFSET(ap_index, win_id)); 160*c0474d58SKonstantin Porotchkin base <<= ADDRESS_SHIFT; 161*c0474d58SKonstantin Porotchkin 162*c0474d58SKonstantin Porotchkin if ((win->target_id != target) || (win->base_addr != base)) { 163*c0474d58SKonstantin Porotchkin ERROR("%s: Trying to remove bad window-%d!\n", 164*c0474d58SKonstantin Porotchkin __func__, win_id); 165*c0474d58SKonstantin Porotchkin continue; 166*c0474d58SKonstantin Porotchkin } 167*c0474d58SKonstantin Porotchkin ccu_disable_win(ap_index, win_id); 168*c0474d58SKonstantin Porotchkin win++; 169*c0474d58SKonstantin Porotchkin } 170*c0474d58SKonstantin Porotchkin } 171*c0474d58SKonstantin Porotchkin 172*c0474d58SKonstantin Porotchkin /* Returns current DRAM window target (DRAM_0_TID, DRAM_1_TID, RAR_TID) 173*c0474d58SKonstantin Porotchkin * NOTE: Call only once for each AP. 174*c0474d58SKonstantin Porotchkin * The AP0 DRAM window is located at index 2 only at the BL31 execution start. 175*c0474d58SKonstantin Porotchkin * Then it relocated to index 1 for matching the rest of APs DRAM settings. 176*c0474d58SKonstantin Porotchkin * Calling this function after relocation will produce wrong results on AP0 177*c0474d58SKonstantin Porotchkin */ 178*c0474d58SKonstantin Porotchkin static uint32_t ccu_dram_target_get(int ap_index) 179*c0474d58SKonstantin Porotchkin { 180*c0474d58SKonstantin Porotchkin /* On BLE stage the AP0 DRAM window is opened by the BootROM at index 2. 181*c0474d58SKonstantin Porotchkin * All the rest of detected APs will use window at index 1. 182*c0474d58SKonstantin Porotchkin * The AP0 DRAM window is moved from index 2 to 1 during 183*c0474d58SKonstantin Porotchkin * init_ccu() execution. 184*c0474d58SKonstantin Porotchkin */ 185*c0474d58SKonstantin Porotchkin const uint32_t win_id = (ap_index == 0) ? 2 : 1; 186*c0474d58SKonstantin Porotchkin uint32_t target; 187*c0474d58SKonstantin Porotchkin 188*c0474d58SKonstantin Porotchkin target = mmio_read_32(CCU_WIN_CR_OFFSET(ap_index, win_id)); 189*c0474d58SKonstantin Porotchkin target >>= CCU_TARGET_ID_OFFSET; 190*c0474d58SKonstantin Porotchkin target &= CCU_TARGET_ID_MASK; 191*c0474d58SKonstantin Porotchkin 192*c0474d58SKonstantin Porotchkin return target; 193*c0474d58SKonstantin Porotchkin } 194*c0474d58SKonstantin Porotchkin 195*c0474d58SKonstantin Porotchkin void ccu_dram_target_set(int ap_index, uint32_t target) 196*c0474d58SKonstantin Porotchkin { 197*c0474d58SKonstantin Porotchkin /* On BLE stage the AP0 DRAM window is opened by the BootROM at index 2. 198*c0474d58SKonstantin Porotchkin * All the rest of detected APs will use window at index 1. 199*c0474d58SKonstantin Porotchkin * The AP0 DRAM window is moved from index 2 to 1 200*c0474d58SKonstantin Porotchkin * during init_ccu() execution. 201*c0474d58SKonstantin Porotchkin */ 202*c0474d58SKonstantin Porotchkin const uint32_t win_id = (ap_index == 0) ? 2 : 1; 203*c0474d58SKonstantin Porotchkin uint32_t dram_cr; 204*c0474d58SKonstantin Porotchkin 205*c0474d58SKonstantin Porotchkin dram_cr = mmio_read_32(CCU_WIN_CR_OFFSET(ap_index, win_id)); 206*c0474d58SKonstantin Porotchkin dram_cr &= ~(CCU_TARGET_ID_MASK << CCU_TARGET_ID_OFFSET); 207*c0474d58SKonstantin Porotchkin dram_cr |= (target & CCU_TARGET_ID_MASK) << CCU_TARGET_ID_OFFSET; 208*c0474d58SKonstantin Porotchkin mmio_write_32(CCU_WIN_CR_OFFSET(ap_index, win_id), dram_cr); 209*c0474d58SKonstantin Porotchkin } 210*c0474d58SKonstantin Porotchkin 211*c0474d58SKonstantin Porotchkin /* Setup CCU DRAM window and enable it */ 212*c0474d58SKonstantin Porotchkin void ccu_dram_win_config(int ap_index, struct addr_map_win *win) 213*c0474d58SKonstantin Porotchkin { 214*c0474d58SKonstantin Porotchkin #if IMAGE_BLE /* BLE */ 215*c0474d58SKonstantin Porotchkin /* On BLE stage the AP0 DRAM window is opened by the BootROM at index 2. 216*c0474d58SKonstantin Porotchkin * Since the BootROM is not accessing DRAM at BLE stage, 217*c0474d58SKonstantin Porotchkin * the DRAM window can be temporarely disabled. 218*c0474d58SKonstantin Porotchkin */ 219*c0474d58SKonstantin Porotchkin const uint32_t win_id = (ap_index == 0) ? 2 : 1; 220*c0474d58SKonstantin Porotchkin #else /* end of BLE */ 221*c0474d58SKonstantin Porotchkin /* At the ccu_init() execution stage, DRAM windows of all APs 222*c0474d58SKonstantin Porotchkin * are arranged at index 1. 223*c0474d58SKonstantin Porotchkin * The AP0 still has the old window BootROM DRAM at index 2, so 224*c0474d58SKonstantin Porotchkin * the window-1 can be safely disabled without breaking the DRAM access. 225*c0474d58SKonstantin Porotchkin */ 226*c0474d58SKonstantin Porotchkin const uint32_t win_id = 1; 227*c0474d58SKonstantin Porotchkin #endif 228*c0474d58SKonstantin Porotchkin 229*c0474d58SKonstantin Porotchkin ccu_disable_win(ap_index, win_id); 230*c0474d58SKonstantin Porotchkin /* enable write secure (and clear read secure) */ 231*c0474d58SKonstantin Porotchkin mmio_write_32(CCU_WIN_SCR_OFFSET(ap_index, win_id), 232*c0474d58SKonstantin Porotchkin CCU_WIN_ENA_WRITE_SECURE); 233*c0474d58SKonstantin Porotchkin ccu_win_check(win); 234*c0474d58SKonstantin Porotchkin ccu_enable_win(ap_index, win, win_id); 235*c0474d58SKonstantin Porotchkin } 236*c0474d58SKonstantin Porotchkin 237*c0474d58SKonstantin Porotchkin /* Save content of CCU window + GCR */ 238*c0474d58SKonstantin Porotchkin static void ccu_save_win_range(int ap_id, int win_first, 239*c0474d58SKonstantin Porotchkin int win_last, uint32_t *buffer) 240*c0474d58SKonstantin Porotchkin { 241*c0474d58SKonstantin Porotchkin int win_id, idx; 242*c0474d58SKonstantin Porotchkin /* Save CCU */ 243*c0474d58SKonstantin Porotchkin for (idx = 0, win_id = win_first; win_id <= win_last; win_id++) { 244*c0474d58SKonstantin Porotchkin buffer[idx++] = mmio_read_32(CCU_WIN_CR_OFFSET(ap_id, win_id)); 245*c0474d58SKonstantin Porotchkin buffer[idx++] = mmio_read_32(CCU_WIN_SCR_OFFSET(ap_id, win_id)); 246*c0474d58SKonstantin Porotchkin buffer[idx++] = mmio_read_32(CCU_WIN_ALR_OFFSET(ap_id, win_id)); 247*c0474d58SKonstantin Porotchkin buffer[idx++] = mmio_read_32(CCU_WIN_AHR_OFFSET(ap_id, win_id)); 248*c0474d58SKonstantin Porotchkin } 249*c0474d58SKonstantin Porotchkin buffer[idx] = mmio_read_32(CCU_WIN_GCR_OFFSET(ap_id)); 250*c0474d58SKonstantin Porotchkin } 251*c0474d58SKonstantin Porotchkin 252*c0474d58SKonstantin Porotchkin /* Restore content of CCU window + GCR */ 253*c0474d58SKonstantin Porotchkin static void ccu_restore_win_range(int ap_id, int win_first, 254*c0474d58SKonstantin Porotchkin int win_last, uint32_t *buffer) 255*c0474d58SKonstantin Porotchkin { 256*c0474d58SKonstantin Porotchkin int win_id, idx; 257*c0474d58SKonstantin Porotchkin /* Restore CCU */ 258*c0474d58SKonstantin Porotchkin for (idx = 0, win_id = win_first; win_id <= win_last; win_id++) { 259*c0474d58SKonstantin Porotchkin mmio_write_32(CCU_WIN_CR_OFFSET(ap_id, win_id), buffer[idx++]); 260*c0474d58SKonstantin Porotchkin mmio_write_32(CCU_WIN_SCR_OFFSET(ap_id, win_id), buffer[idx++]); 261*c0474d58SKonstantin Porotchkin mmio_write_32(CCU_WIN_ALR_OFFSET(ap_id, win_id), buffer[idx++]); 262*c0474d58SKonstantin Porotchkin mmio_write_32(CCU_WIN_AHR_OFFSET(ap_id, win_id), buffer[idx++]); 263*c0474d58SKonstantin Porotchkin } 264*c0474d58SKonstantin Porotchkin mmio_write_32(CCU_WIN_GCR_OFFSET(ap_id), buffer[idx]); 265*c0474d58SKonstantin Porotchkin } 266*c0474d58SKonstantin Porotchkin 267*c0474d58SKonstantin Porotchkin void ccu_save_win_all(int ap_id) 268*c0474d58SKonstantin Porotchkin { 269*c0474d58SKonstantin Porotchkin ccu_save_win_range(ap_id, 0, MVEBU_CCU_MAX_WINS - 1, ccu_regs_save); 270*c0474d58SKonstantin Porotchkin } 271*c0474d58SKonstantin Porotchkin 272*c0474d58SKonstantin Porotchkin void ccu_restore_win_all(int ap_id) 273*c0474d58SKonstantin Porotchkin { 274*c0474d58SKonstantin Porotchkin ccu_restore_win_range(ap_id, 0, MVEBU_CCU_MAX_WINS - 1, ccu_regs_save); 275*c0474d58SKonstantin Porotchkin } 276*c0474d58SKonstantin Porotchkin 277*c0474d58SKonstantin Porotchkin int init_ccu(int ap_index) 278*c0474d58SKonstantin Porotchkin { 279*c0474d58SKonstantin Porotchkin struct addr_map_win *win, *dram_win; 280*c0474d58SKonstantin Porotchkin uint32_t win_id, win_reg; 281*c0474d58SKonstantin Porotchkin uint32_t win_count, array_id; 282*c0474d58SKonstantin Porotchkin uint32_t dram_target; 283*c0474d58SKonstantin Porotchkin #if IMAGE_BLE 284*c0474d58SKonstantin Porotchkin /* In BootROM context CCU Window-1 285*c0474d58SKonstantin Porotchkin * has SRAM_TID target and should not be disabled 286*c0474d58SKonstantin Porotchkin */ 287*c0474d58SKonstantin Porotchkin const uint32_t win_start = 2; 288*c0474d58SKonstantin Porotchkin #else 289*c0474d58SKonstantin Porotchkin const uint32_t win_start = 1; 290*c0474d58SKonstantin Porotchkin #endif 291*c0474d58SKonstantin Porotchkin 292*c0474d58SKonstantin Porotchkin INFO("Initializing CCU Address decoding\n"); 293*c0474d58SKonstantin Porotchkin 294*c0474d58SKonstantin Porotchkin /* Get the array of the windows and fill the map data */ 295*c0474d58SKonstantin Porotchkin marvell_get_ccu_memory_map(ap_index, &win, &win_count); 296*c0474d58SKonstantin Porotchkin if (win_count <= 0) { 297*c0474d58SKonstantin Porotchkin INFO("No windows configurations found\n"); 298*c0474d58SKonstantin Porotchkin } else if (win_count > (MVEBU_CCU_MAX_WINS - 1)) { 299*c0474d58SKonstantin Porotchkin ERROR("CCU mem map array > than max available windows (%d)\n", 300*c0474d58SKonstantin Porotchkin MVEBU_CCU_MAX_WINS); 301*c0474d58SKonstantin Porotchkin win_count = MVEBU_CCU_MAX_WINS; 302*c0474d58SKonstantin Porotchkin } 303*c0474d58SKonstantin Porotchkin 304*c0474d58SKonstantin Porotchkin /* Need to set GCR to DRAM before all CCU windows are disabled for 305*c0474d58SKonstantin Porotchkin * securing the normal access to DRAM location, which the ATF is running 306*c0474d58SKonstantin Porotchkin * from. Once all CCU windows are set, which have to include the 307*c0474d58SKonstantin Porotchkin * dedicated DRAM window as well, the GCR can be switched to the target 308*c0474d58SKonstantin Porotchkin * defined by the platform configuration. 309*c0474d58SKonstantin Porotchkin */ 310*c0474d58SKonstantin Porotchkin dram_target = ccu_dram_target_get(ap_index); 311*c0474d58SKonstantin Porotchkin win_reg = (dram_target & CCU_GCR_TARGET_MASK) << CCU_GCR_TARGET_OFFSET; 312*c0474d58SKonstantin Porotchkin mmio_write_32(CCU_WIN_GCR_OFFSET(ap_index), win_reg); 313*c0474d58SKonstantin Porotchkin 314*c0474d58SKonstantin Porotchkin /* If the DRAM window was already configured at the BLE stage, 315*c0474d58SKonstantin Porotchkin * only the window target considered valid, the address range should be 316*c0474d58SKonstantin Porotchkin * updated according to the platform configuration. 317*c0474d58SKonstantin Porotchkin */ 318*c0474d58SKonstantin Porotchkin for (dram_win = win, array_id = 0; array_id < win_count; 319*c0474d58SKonstantin Porotchkin array_id++, dram_win++) { 320*c0474d58SKonstantin Porotchkin if (IS_DRAM_TARGET(dram_win->target_id)) { 321*c0474d58SKonstantin Porotchkin dram_win->target_id = dram_target; 322*c0474d58SKonstantin Porotchkin break; 323*c0474d58SKonstantin Porotchkin } 324*c0474d58SKonstantin Porotchkin } 325*c0474d58SKonstantin Porotchkin 326*c0474d58SKonstantin Porotchkin /* Disable all AP CCU windows 327*c0474d58SKonstantin Porotchkin * Window-0 is always bypassed since it already contains 328*c0474d58SKonstantin Porotchkin * data allowing the internal configuration space access 329*c0474d58SKonstantin Porotchkin */ 330*c0474d58SKonstantin Porotchkin for (win_id = win_start; win_id < MVEBU_CCU_MAX_WINS; win_id++) { 331*c0474d58SKonstantin Porotchkin ccu_disable_win(ap_index, win_id); 332*c0474d58SKonstantin Porotchkin /* enable write secure (and clear read secure) */ 333*c0474d58SKonstantin Porotchkin mmio_write_32(CCU_WIN_SCR_OFFSET(ap_index, win_id), 334*c0474d58SKonstantin Porotchkin CCU_WIN_ENA_WRITE_SECURE); 335*c0474d58SKonstantin Porotchkin } 336*c0474d58SKonstantin Porotchkin 337*c0474d58SKonstantin Porotchkin /* win_id is the index of the current ccu window 338*c0474d58SKonstantin Porotchkin * array_id is the index of the current memory map window entry 339*c0474d58SKonstantin Porotchkin */ 340*c0474d58SKonstantin Porotchkin for (win_id = win_start, array_id = 0; 341*c0474d58SKonstantin Porotchkin ((win_id < MVEBU_CCU_MAX_WINS) && (array_id < win_count)); 342*c0474d58SKonstantin Porotchkin win_id++) { 343*c0474d58SKonstantin Porotchkin ccu_win_check(win); 344*c0474d58SKonstantin Porotchkin ccu_enable_win(ap_index, win, win_id); 345*c0474d58SKonstantin Porotchkin win++; 346*c0474d58SKonstantin Porotchkin array_id++; 347*c0474d58SKonstantin Porotchkin } 348*c0474d58SKonstantin Porotchkin 349*c0474d58SKonstantin Porotchkin /* Get & set the default target according to board topology */ 350*c0474d58SKonstantin Porotchkin win_reg = (marvell_get_ccu_gcr_target(ap_index) & CCU_GCR_TARGET_MASK) 351*c0474d58SKonstantin Porotchkin << CCU_GCR_TARGET_OFFSET; 352*c0474d58SKonstantin Porotchkin mmio_write_32(CCU_WIN_GCR_OFFSET(ap_index), win_reg); 353*c0474d58SKonstantin Porotchkin 354*c0474d58SKonstantin Porotchkin #ifdef DEBUG_ADDR_MAP 355*c0474d58SKonstantin Porotchkin dump_ccu(ap_index); 356*c0474d58SKonstantin Porotchkin #endif 357*c0474d58SKonstantin Porotchkin 358*c0474d58SKonstantin Porotchkin INFO("Done CCU Address decoding Initializing\n"); 359*c0474d58SKonstantin Porotchkin 360*c0474d58SKonstantin Porotchkin return 0; 361*c0474d58SKonstantin Porotchkin } 362