Jiafei Pan | 46367ad | 2018-03-02 07:23:30 +0000 | [diff] [blame] | 1 | /* |
Justin Chadwell | 7d0e3ba | 2019-09-17 15:21:50 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved. |
Jiafei Pan | 46367ad | 2018-03-02 07:23:30 +0000 | [diff] [blame] | 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 | |
Justin Chadwell | 7d0e3ba | 2019-09-17 15:21:50 +0100 | [diff] [blame] | 16 | static void enable_devices_ns_access(struct csu_ns_dev *_ns_dev, uint32_t num) |
Jiafei Pan | 46367ad | 2018-03-02 07:23:30 +0000 | [diff] [blame] | 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++) { |
Justin Chadwell | 7d0e3ba | 2019-09-17 15:21:50 +0100 | [diff] [blame] | 24 | reg = base + _ns_dev[i].ind / 2; |
Jiafei Pan | 46367ad | 2018-03-02 07:23:30 +0000 | [diff] [blame] | 25 | val = be32toh(mmio_read_32((uintptr_t)reg)); |
Justin Chadwell | 7d0e3ba | 2019-09-17 15:21:50 +0100 | [diff] [blame] | 26 | if (_ns_dev[i].ind % 2 == 0) { |
Jiafei Pan | 46367ad | 2018-03-02 07:23:30 +0000 | [diff] [blame] | 27 | val &= 0x0000ffff; |
Justin Chadwell | 7d0e3ba | 2019-09-17 15:21:50 +0100 | [diff] [blame] | 28 | val |= _ns_dev[i].val << 16; |
Jiafei Pan | 46367ad | 2018-03-02 07:23:30 +0000 | [diff] [blame] | 29 | } else { |
| 30 | val &= 0xffff0000; |
Justin Chadwell | 7d0e3ba | 2019-09-17 15:21:50 +0100 | [diff] [blame] | 31 | val |= _ns_dev[i].val; |
Jiafei Pan | 46367ad | 2018-03-02 07:23:30 +0000 | [diff] [blame] | 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 | } |