Path: blob/master/drivers/accel/habanalabs/common/security.h
26436 views
/* SPDX-License-Identifier: GPL-2.01*2* Copyright 2016-2022 HabanaLabs, Ltd.3* All Rights Reserved.4*5*/67#ifndef SECURITY_H_8#define SECURITY_H_910#include <linux/io-64-nonatomic-lo-hi.h>1112struct hl_device;1314/* special blocks */15#define HL_GLBL_ERR_ADDRESS_MASK GENMASK(11, 0)16/* GLBL_ERR_ADDR register offset from the start of the block */17#define HL_GLBL_ERR_ADDR_OFFSET 0xF4418/* GLBL_ERR_CAUSE register offset from the start of the block */19#define HL_GLBL_ERR_CAUSE_OFFSET 0xF482021/*22* struct hl_special_block_info - stores address details of a particular type of23* IP block which has a SPECIAL part.24*25* @block_type: block type as described in every ASIC's block_types enum.26* @base_addr: base address of the first block of particular type,27* e.g., address of NIC0_UMR0_0 of 'NIC_UMR' block.28* @major: number of major blocks of particular type.29* @minor: number of minor blocks of particular type.30* @sub_minor: number of sub minor blocks of particular type.31* @major_offset: address gap between 2 consecutive major blocks of particular type,32* e.g., offset between NIC0_UMR0_0 and NIC1_UMR0_0 is 0x80000.33* @minor_offset: address gap between 2 consecutive minor blocks of particular type,34* e.g., offset between NIC0_UMR0_0 and NIC0_UMR1_0 is 0x20000.35* @sub_minor_offset: address gap between 2 consecutive sub_minor blocks of particular36* type, e.g., offset between NIC0_UMR0_0 and NIC0_UMR0_1 is 0x1000.37*38* e.g., in Gaudi2, NIC_UMR blocks can be interpreted as:39* NIC<major>_UMR<minor>_<sub_minor> where major=12, minor=2, sub_minor=15.40* In other words, for each of 12 major numbers (i.e 0 to 11) there are41* 2 blocks with different minor numbers (i.e. 0 to 1). Again, for each minor42* number there are 15 blocks with different sub_minor numbers (i.e. 0 to 14).43* So different blocks are NIC0_UMR0_0, NIC0_UMR0_1, ..., NIC0_UMR1_0, ....,44* NIC11_UMR1_14.45*46* Struct's formatted data is located in the SOL-based auto-generated protbits headers.47*/48struct hl_special_block_info {49int block_type;50u32 base_addr;51u32 major;52u32 minor;53u32 sub_minor;54u32 major_offset;55u32 minor_offset;56u32 sub_minor_offset;57};5859/*60* struct hl_automated_pb_cfg - represents configurations of a particular type61* of IP block which has protection bits.62*63* @addr: address details as described in hl_automation_pb_addr struct.64* @prot_map: each bit corresponds to one among 32 protection configuration regs65* (e.g., SPECIAL_GLBL_PRIV). '1' means 0xffffffff and '0' means 0x066* to be written into the corresponding protection configuration reg.67* This bit is meaningful if same bit in data_map is 0, otherwise ignored.68* @data_map: each bit corresponds to one among 32 protection configuration regs69* (e.g., SPECIAL_GLBL_PRIV). '1' means corresponding protection70* configuration reg is to be written with a value in array pointed71* by 'data', otherwise the value is decided by 'prot_map'.72* @data: pointer to data array which stores the config value(s) to be written73* to corresponding protection configuration reg(s).74* @data_size: size of the data array.75*76* Each bit of 'data_map' and 'prot_map' fields corresponds to one among 3277* protection configuration registers e.g., SPECIAL GLBL PRIV regs (starting at78* offset 0xE80). '1' in 'data_map' means protection configuration to be done79* using configuration in data array. '0' in 'data_map" means protection80* configuration to be done as per the value of corresponding bit in 'prot_map'.81* '1' in 'prot_map' means the register to be programmed with 0xFFFFFFFF82* (all non-protected). '0' in 'prot_map' means the register to be programmed83* with 0x0 (all protected).84*85* e.g., prot_map = 0x00000001, data_map = 0xC0000000 , data = {0xff, 0x12}86* SPECIAL_GLBL_PRIV[0] = 0xFFFFFFFF87* SPECIAL_GLBL_PRIV[1..29] = 0x088* SPECIAL_GLBL_PRIV[30] = 0xFF89* SPECIAL_GLBL_PRIV[31] = 0x1290*/91struct hl_automated_pb_cfg {92struct hl_special_block_info addr;93u32 prot_map;94u32 data_map;95const u32 *data;96u8 data_size;97};9899/* struct hl_special_blocks_cfg - holds special blocks cfg data.100*101* @priv_automated_pb_cfg: points to the main privileged PB array.102* @sec_automated_pb_cfg: points to the main secured PB array.103* @skip_blocks_cfg: holds arrays of block types & block ranges to be excluded.104* @priv_cfg_size: size of the main privileged PB array.105* @sec_cfg_size: size of the main secured PB array.106* @prot_lvl_priv: indication if it's a privileged/secured PB configurations.107*/108struct hl_special_blocks_cfg {109struct hl_automated_pb_cfg *priv_automated_pb_cfg;110struct hl_automated_pb_cfg *sec_automated_pb_cfg;111struct hl_skip_blocks_cfg *skip_blocks_cfg;112u32 priv_cfg_size;113u32 sec_cfg_size;114u8 prot_lvl_priv;115};116117/* Automated security */118119/* struct hl_skip_blocks_cfg - holds arrays of block types & block ranges to be120* excluded from special blocks configurations.121*122* @block_types: an array of block types NOT to be configured.123* @block_types_len: len of an array of block types not to be configured.124* @block_ranges: an array of block ranges not to be configured.125* @block_ranges_len: len of an array of block ranges not to be configured.126* @skip_block_hook: hook that will be called before initializing special blocks.127*/128struct hl_skip_blocks_cfg {129int *block_types;130size_t block_types_len;131struct range *block_ranges;132size_t block_ranges_len;133bool (*skip_block_hook)(struct hl_device *hdev,134struct hl_special_blocks_cfg *special_blocks_cfg,135u32 blk_idx, u32 major, u32 minor, u32 sub_minor);136};137138/**139* struct iterate_special_ctx - HW module special block iterator140* @fn: function to apply to each HW module special block instance141* @data: optional internal data to the function iterator142*/143struct iterate_special_ctx {144/*145* callback for the HW module special block iterator146* @hdev: pointer to the habanalabs device structure147* @block_id: block (ASIC specific definition can be dcore/hdcore)148* @major: major block index within block_id149* @minor: minor block index within the major block150* @sub_minor: sub_minor block index within the minor block151* @data: function specific data152*/153int (*fn)(struct hl_device *hdev, u32 block_id, u32 major, u32 minor,154u32 sub_minor, void *data);155void *data;156};157158int hl_iterate_special_blocks(struct hl_device *hdev, struct iterate_special_ctx *ctx);159void hl_check_for_glbl_errors(struct hl_device *hdev);160161#endif /* SECURITY_H_ */162163164