nxp: added csu driver

NXP Central Security Unit(CSU) for NXP SoC.
CSU is used for:
- Access permissions for peripheral that donot have their own
  access control.
- Locking of individual CSU settings until the next POR
- General purpose security related control bits

Refer NXP SoC manuals fro more details.

Signed-off-by: Pankaj Gupta <pankaj.gupta@nxp.com>
Change-Id: I07a4729c79c5e2597f8b2a782e87e09f7f30c2ca
This commit is contained in:
Pankaj Gupta 2020-12-09 14:02:39 +05:30
parent d57186ea2c
commit 34412eda32
3 changed files with 102 additions and 0 deletions

34
drivers/nxp/csu/csu.c Normal file
View File

@ -0,0 +1,34 @@
/*
* Copyright 2020 NXP
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#include <endian.h>
#include <common/debug.h>
#include <csu.h>
#include <lib/mmio.h>
void enable_layerscape_ns_access(struct csu_ns_dev_st *csu_ns_dev,
uint32_t num, uintptr_t nxp_csu_addr)
{
uint32_t *base = (uint32_t *)nxp_csu_addr;
uint32_t *reg;
uint32_t val;
int i;
for (i = 0; i < num; i++) {
reg = base + csu_ns_dev[i].ind / 2U;
val = be32toh(mmio_read_32((uintptr_t)reg));
if (csu_ns_dev[i].ind % 2U == 0U) {
val &= 0x0000ffffU;
val |= csu_ns_dev[i].val << 16U;
} else {
val &= 0xffff0000U;
val |= csu_ns_dev[i].val;
}
mmio_write_32((uintptr_t)reg, htobe32(val));
}
}

40
drivers/nxp/csu/csu.h Normal file
View File

@ -0,0 +1,40 @@
/*
* Copyright 2020 NXP
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#ifndef CSU_H
#define CSU_H
#define CSU_SEC_ACCESS_REG_OFFSET (0x0021CU)
/* Macros defining access permissions to configure
* the regions controlled by Central Security Unit.
*/
enum csu_cslx_access {
CSU_NS_SUP_R = (0x8U),
CSU_NS_SUP_W = (0x80U),
CSU_NS_SUP_RW = (0x88U),
CSU_NS_USER_R = (0x4U),
CSU_NS_USER_W = (0x40U),
CSU_NS_USER_RW = (0x44U),
CSU_S_SUP_R = (0x2U),
CSU_S_SUP_W = (0x20U),
CSU_S_SUP_RW = (0x22U),
CSU_S_USER_R = (0x1U),
CSU_S_USER_W = (0x10U),
CSU_S_USER_RW = (0x11U),
CSU_ALL_RW = (0xffU),
};
struct csu_ns_dev_st {
uintptr_t ind;
uint32_t val;
};
void enable_layerscape_ns_access(struct csu_ns_dev_st *csu_ns_dev,
uint32_t num, uintptr_t nxp_csu_addr);
#endif

28
drivers/nxp/csu/csu.mk Normal file
View File

@ -0,0 +1,28 @@
#
# Copyright 2020 NXP
#
# SPDX-License-Identifier: BSD-3-Clause
#
#-----------------------------------------------------------------------------
ifeq (${CSU_ADDED},)
CSU_ADDED := 1
CSU_DRIVERS_PATH := ${PLAT_DRIVERS_PATH}/csu
PLAT_INCLUDES += -I$(CSU_DRIVERS_PATH)
CSU_SOURCES += $(CSU_DRIVERS_PATH)/csu.c
ifeq (${BL_COMM_CSU_NEEDED},yes)
BL_COMMON_SOURCES += ${CSU_SOURCES}
else
ifeq (${BL2_CSU_NEEDED},yes)
BL2_SOURCES += ${CSU_SOURCES}
endif
ifeq (${BL31_CSU_NEEDED},yes)
BL31_SOURCES += ${CSU_SOURCES}
endif
endif
endif