blob: 9717c7281a955daf3eba4797f08a9c8f6bd9841c [file] [log] [blame]
Jiafei Pan46367ad2018-03-02 07:23:30 +00001/*
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +01002 * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
Jiafei Pan46367ad2018-03-02 07:23:30 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Jiafei Pan46367ad2018-03-02 07:23:30 +00007#include <endian.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008
9#include <platform_def.h>
10
11#include <common/debug.h>
12#include <lib/mmio.h>
13
Jiafei Pan46367ad2018-03-02 07:23:30 +000014#include "ns_access.h"
Jiafei Pan46367ad2018-03-02 07:23:30 +000015
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +010016static void enable_devices_ns_access(struct csu_ns_dev *_ns_dev, uint32_t num)
Jiafei Pan46367ad2018-03-02 07:23:30 +000017{
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 Chadwell7d0e3ba2019-09-17 15:21:50 +010024 reg = base + _ns_dev[i].ind / 2;
Jiafei Pan46367ad2018-03-02 07:23:30 +000025 val = be32toh(mmio_read_32((uintptr_t)reg));
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +010026 if (_ns_dev[i].ind % 2 == 0) {
Jiafei Pan46367ad2018-03-02 07:23:30 +000027 val &= 0x0000ffff;
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +010028 val |= _ns_dev[i].val << 16;
Jiafei Pan46367ad2018-03-02 07:23:30 +000029 } else {
30 val &= 0xffff0000;
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +010031 val |= _ns_dev[i].val;
Jiafei Pan46367ad2018-03-02 07:23:30 +000032 }
33 mmio_write_32((uintptr_t)reg, htobe32(val));
34 }
35}
36
37void enable_layerscape_ns_access(void)
38{
39 enable_devices_ns_access(ns_dev, ARRAY_SIZE(ns_dev));
40}