Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2019 Advanced Micro Devices, Inc.
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial portions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0017  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020  * OTHER DEALINGS IN THE SOFTWARE.
0021  *
0022  * Authors: AMD
0023  *
0024  */
0025 
0026 #ifndef _DMUB_REG_H_
0027 #define _DMUB_REG_H_
0028 
0029 #include "../inc/dmub_cmd.h"
0030 
0031 struct dmub_srv;
0032 
0033 /* Register offset and field lookup. */
0034 
0035 #define BASE(seg) BASE_INNER(seg)
0036 
0037 #define REG_OFFSET(reg_name) (BASE(mm##reg_name##_BASE_IDX) + mm##reg_name)
0038 
0039 #define FD_SHIFT(reg_name, field) reg_name##__##field##__SHIFT
0040 
0041 #define FD_MASK(reg_name, field) reg_name##__##field##_MASK
0042 
0043 #define REG(reg) (REGS)->offset.reg
0044 
0045 #define FD(reg_field) (REGS)->shift.reg_field, (REGS)->mask.reg_field
0046 
0047 #define FN(reg_name, field) FD(reg_name##__##field)
0048 
0049 /* Register reads and writes. */
0050 
0051 #define REG_READ(reg) ((CTX)->funcs.reg_read((CTX)->user_ctx, REG(reg)))
0052 
0053 #define REG_WRITE(reg, val) \
0054     ((CTX)->funcs.reg_write((CTX)->user_ctx, REG(reg), (val)))
0055 
0056 /* Register field setting. */
0057 
0058 #define REG_SET_N(reg_name, n, initial_val, ...) \
0059     dmub_reg_set(CTX, REG(reg_name), initial_val, n, __VA_ARGS__)
0060 
0061 #define REG_SET(reg_name, initial_val, field, val) \
0062         REG_SET_N(reg_name, 1, initial_val, \
0063                 FN(reg_name, field), val)
0064 
0065 #define REG_SET_2(reg, init_value, f1, v1, f2, v2) \
0066         REG_SET_N(reg, 2, init_value, \
0067                 FN(reg, f1), v1, \
0068                 FN(reg, f2), v2)
0069 
0070 #define REG_SET_3(reg, init_value, f1, v1, f2, v2, f3, v3) \
0071         REG_SET_N(reg, 3, init_value, \
0072                 FN(reg, f1), v1, \
0073                 FN(reg, f2), v2, \
0074                 FN(reg, f3), v3)
0075 
0076 #define REG_SET_4(reg, init_value, f1, v1, f2, v2, f3, v3, f4, v4) \
0077         REG_SET_N(reg, 4, init_value, \
0078                 FN(reg, f1), v1, \
0079                 FN(reg, f2), v2, \
0080                 FN(reg, f3), v3, \
0081                 FN(reg, f4), v4)
0082 
0083 /* Register field updating. */
0084 
0085 #define REG_UPDATE_N(reg_name, n, ...)\
0086         dmub_reg_update(CTX, REG(reg_name), n, __VA_ARGS__)
0087 
0088 #define REG_UPDATE(reg_name, field, val)    \
0089         REG_UPDATE_N(reg_name, 1, \
0090                 FN(reg_name, field), val)
0091 
0092 #define REG_UPDATE_2(reg, f1, v1, f2, v2)   \
0093         REG_UPDATE_N(reg, 2,\
0094                 FN(reg, f1), v1,\
0095                 FN(reg, f2), v2)
0096 
0097 #define REG_UPDATE_3(reg, f1, v1, f2, v2, f3, v3) \
0098         REG_UPDATE_N(reg, 3, \
0099                 FN(reg, f1), v1, \
0100                 FN(reg, f2), v2, \
0101                 FN(reg, f3), v3)
0102 
0103 #define REG_UPDATE_4(reg, f1, v1, f2, v2, f3, v3, f4, v4) \
0104         REG_UPDATE_N(reg, 4, \
0105                 FN(reg, f1), v1, \
0106                 FN(reg, f2), v2, \
0107                 FN(reg, f3), v3, \
0108                 FN(reg, f4), v4)
0109 
0110 /* Register field getting. */
0111 
0112 #define REG_GET(reg_name, field, val) \
0113     dmub_reg_get(CTX, REG(reg_name), FN(reg_name, field), val)
0114 
0115 void dmub_reg_set(struct dmub_srv *srv, uint32_t addr, uint32_t reg_val, int n,
0116           uint8_t shift1, uint32_t mask1, uint32_t field_value1, ...);
0117 
0118 void dmub_reg_update(struct dmub_srv *srv, uint32_t addr, int n, uint8_t shift1,
0119              uint32_t mask1, uint32_t field_value1, ...);
0120 
0121 void dmub_reg_get(struct dmub_srv *srv, uint32_t addr, uint8_t shift,
0122           uint32_t mask, uint32_t *field_value);
0123 
0124 #endif /* _DMUB_REG_H_ */