Jiafei Pan | 46367ad | 2018-03-02 07:23:30 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Jiafei Pan | 46367ad | 2018-03-02 07:23:30 +0000 | [diff] [blame] | 7 | #include <endian.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | |
| 9 | #include <platform_def.h> |
| 10 | |
| 11 | #include <common/debug.h> |
| 12 | #include <lib/mmio.h> |
| 13 | |
Jiafei Pan | 46367ad | 2018-03-02 07:23:30 +0000 | [diff] [blame] | 14 | #include "ns_access.h" |
Jiafei Pan | 46367ad | 2018-03-02 07:23:30 +0000 | [diff] [blame] | 15 | |
| 16 | static void enable_devices_ns_access(struct csu_ns_dev *ns_dev, uint32_t num) |
| 17 | { |
| 18 | uint32_t *base = (uint32_t *)CONFIG_SYS_FSL_CSU_ADDR; |
| 19 | uint32_t *reg; |
| 20 | uint32_t val; |
| 21 | int i; |
| 22 | |
| 23 | for (i = 0; i < num; i++) { |
| 24 | reg = base + ns_dev[i].ind / 2; |
| 25 | val = be32toh(mmio_read_32((uintptr_t)reg)); |
| 26 | if (ns_dev[i].ind % 2 == 0) { |
| 27 | val &= 0x0000ffff; |
| 28 | val |= ns_dev[i].val << 16; |
| 29 | } else { |
| 30 | val &= 0xffff0000; |
| 31 | val |= ns_dev[i].val; |
| 32 | } |
| 33 | mmio_write_32((uintptr_t)reg, htobe32(val)); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | void enable_layerscape_ns_access(void) |
| 38 | { |
| 39 | enable_devices_ns_access(ns_dev, ARRAY_SIZE(ns_dev)); |
| 40 | } |