ns_access.c 840 Bytes
Newer Older
1
/*
Justin Chadwell's avatar
Justin Chadwell committed
2
 * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
3
4
5
6
7
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <endian.h>
8
9
10
11
12
13

#include <platform_def.h>

#include <common/debug.h>
#include <lib/mmio.h>

14
15
#include "ns_access.h"

Justin Chadwell's avatar
Justin Chadwell committed
16
static void enable_devices_ns_access(struct csu_ns_dev *_ns_dev, uint32_t num)
17
18
19
20
21
22
23
{
	uint32_t *base = (uint32_t *)CONFIG_SYS_FSL_CSU_ADDR;
	uint32_t *reg;
	uint32_t val;
	int i;

	for (i = 0; i < num; i++) {
Justin Chadwell's avatar
Justin Chadwell committed
24
		reg = base + _ns_dev[i].ind / 2;
25
		val = be32toh(mmio_read_32((uintptr_t)reg));
Justin Chadwell's avatar
Justin Chadwell committed
26
		if (_ns_dev[i].ind % 2 == 0) {
27
			val &= 0x0000ffff;
Justin Chadwell's avatar
Justin Chadwell committed
28
			val |= _ns_dev[i].val << 16;
29
30
		} else {
			val &= 0xffff0000;
Justin Chadwell's avatar
Justin Chadwell committed
31
			val |= _ns_dev[i].val;
32
33
34
35
36
37
38
39
40
		}
		mmio_write_32((uintptr_t)reg, htobe32(val));
	}
}

void enable_layerscape_ns_access(void)
{
	enable_devices_ns_access(ns_dev, ARRAY_SIZE(ns_dev));
}