-- Copyright (c) 2026 Huawei Technologies Co., Ltd.
-- openUBMC is licensed under Mulan PSL v2.
-- You can use this software according to the terms and conditions of the Mulan PSL v2.
-- You may obtain a copy of Mulan PSL v2 at:
--          http://license.coscl.org.cn/MulanPSL2
-- THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
-- EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
-- MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
-- See the Mulan PSL v2 for more details.

local common = {}

local s_match = string.match

common.block_io_method = { 'Read', 'Write', 'WriteRead', 'ComboWriteRead', 'BatchWrite' }

function common.get_access_property(object_name)
    return s_match(object_name, '^%w+_(.*)')
end

function common.get_access_property_with_position(object_name)
    return s_match(object_name, '^%w+_(.*)_.*$')
end

function common.remove_position(object_name)
    return s_match(object_name, '(.*)_.*$')
end

function common.get_class_type(object_name)
    return s_match(object_name, '(.-)_')
end

common.csr_syntax_tag = { REF_TAG = '#/' }

-- 判断是否引用关系
function common.is_ref(value)
    return type(value) == 'string' and string.sub(value, 1, 2) == common.csr_syntax_tag.REF_TAG
end

-- CSR关键字
common.csr_key = {
    PARENT = '@Parent',
}

-- 判断是否层级关系
function common.is_parent(name, value)
    return name == common.csr_key.PARENT and type(value) == 'string'
end

common.support_access = { ['Smc'] = true, ['Pca9555'] = true }

common.mux_class = { ['I2cMux'] = true, ['JtagMux'] = true }

return common