Skip to content

Commit 121d20c

Browse files
committed
cpu_regs: Make fields usable from assembler
Signed-off-by: Hector Martin <[email protected]>
1 parent 4638632 commit 121d20c

4 files changed

Lines changed: 41 additions & 39 deletions

File tree

src/cpu_regs.h

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,21 @@
3333
#define HID1_ENABLE_BR_KILL_LIMIT BIT(60)
3434

3535
#define HID1_ZCL_RF_RESTART_THRESHOLD_MASK GENMASK(23, 22)
36-
#define HID1_ZCL_RF_RESTART_THRESHOLD(x) (((unsigned long)x) << 22)
36+
#define HID1_ZCL_RF_RESTART_THRESHOLD(x) ((ULONG(x)) << 22)
3737
#define HID1_ZCL_RF_MISPREDICT_THRESHOLD_MASK GENMASK(43, 42)
38-
#define HID1_ZCL_RF_MISPREDICT_THRESHOLD(x) (((unsigned long)x) << 42)
38+
#define HID1_ZCL_RF_MISPREDICT_THRESHOLD(x) ((ULONG(x)) << 42)
3939

4040
#define SYS_IMP_APL_HID3 sys_reg(3, 0, 15, 3, 0)
4141
#define HID3_DISABLE_ARBITER_FIX_BIF_CRD BIT(44)
4242
#define HID3_DEV_PCIE_THROTTLE_LIMIT_MASK GENMASK(62, 57)
43-
#define HID3_DEV_PCIE_THROTTLE_LIMIT(x) (((unsigned long)x) << 57)
43+
#define HID3_DEV_PCIE_THROTTLE_LIMIT(x) ((ULONG(x)) << 57)
4444
#define HID3_DEV_PCIE_THROTTLE_ENABLE BIT(63)
4545

4646
#define SYS_IMP_APL_HID4 sys_reg(3, 0, 15, 4, 0)
4747
#define SYS_IMP_APL_EHID4 sys_reg(3, 0, 15, 4, 1)
4848
#define HID4_DISABLE_DC_MVA BIT(11)
4949
#define HID4_DISABLE_DC_SW_L2_OPS BIT(44)
50-
#define HID4_STNT_COUNTER_THRESHOLD(x) (((unsigned long)x) << 40)
50+
#define HID4_STNT_COUNTER_THRESHOLD(x) ((ULONG(x)) << 40)
5151
#define HID4_STNT_COUNTER_THRESHOLD_MASK (3UL << 40)
5252
#define HID4_ENABLE_LFSR_STALL_LOAD_PIPE_2_ISSUE BIT(49)
5353
#define HID4_ENABLE_LFSR_STALL_STQ_REPLAY BIT(53)
@@ -59,13 +59,13 @@
5959
#define HID5_DISABLE_FILL_2C_MERGE BIT(61)
6060

6161
#define SYS_IMP_APL_HID6 sys_reg(3, 0, 15, 6, 0)
62-
#define HID6_UP_CRD_TKN_INIT_C2(x) (((unsigned long)x) << 5)
62+
#define HID6_UP_CRD_TKN_INIT_C2(x) ((ULONG(x)) << 5)
6363
#define HID6_UP_CRD_TKN_INIT_C2_MASK (0x1FUL << 5)
6464

6565
#define SYS_IMP_APL_HID7 sys_reg(3, 0, 15, 7, 0)
6666
#define HID7_FORCE_NONSPEC_IF_SPEC_FLUSH_POINTER_INVALID_AND_MP_VALID BIT(16)
6767
#define HID7_FORCE_NONSPEC_IF_STEPPING BIT(20)
68-
#define HID7_FORCE_NONSPEC_TARGET_TIMER_SEL(x) (((unsigned long)x) << 24)
68+
#define HID7_FORCE_NONSPEC_TARGET_TIMER_SEL(x) ((ULONG(x)) << 24)
6969
#define HID7_FORCE_NONSPEC_TARGET_TIMER_SEL_MASK (3UL << 24)
7070

7171
#define SYS_IMP_APL_HID9 sys_reg(3, 0, 15, 9, 0)
@@ -78,7 +78,7 @@
7878
#define SYS_IMP_APL_EHID9 sys_reg(3, 0, 15, 9, 1)
7979
#define EHID9_DEV_2_THROTTLE_ENABLE BIT(5)
8080
#define EHID9_DEV_2_THROTTLE_LIMIT_MASK GENMASK(11, 6)
81-
#define EHID9_DEV_2_THROTTLE_LIMIT(x) (((unsigned long)x) << 6)
81+
#define EHID9_DEV_2_THROTTLE_LIMIT(x) ((ULONG(x)) << 6)
8282

8383
#define SYS_IMP_APL_HID10 sys_reg(3, 0, 15, 10, 0)
8484
#define SYS_IMP_APL_EHID10 sys_reg(3, 0, 15, 10, 1)
@@ -90,27 +90,27 @@
9090
#define HID11_DISABLE_LD_NT_WIDGET BIT(59)
9191

9292
#define SYS_IMP_APL_HID13 sys_reg(3, 0, 15, 14, 0)
93-
#define HID13_POST_OFF_CYCLES(x) (((unsigned long)x))
93+
#define HID13_POST_OFF_CYCLES(x) ((ULONG(x)))
9494
#define HID13_POST_OFF_CYCLES_MASK GENMASK(6, 0)
95-
#define HID13_POST_ON_CYCLES(x) (((unsigned long)x) << 7)
95+
#define HID13_POST_ON_CYCLES(x) ((ULONG(x)) << 7)
9696
#define HID13_POST_ON_CYCLES_MASK GENMASK(13, 7)
97-
#define HID13_PRE_CYCLES(x) (((unsigned long)x) << 14)
97+
#define HID13_PRE_CYCLES(x) ((ULONG(x)) << 14)
9898
#define HID13_PRE_CYCLES_MASK GENMASK(17, 14)
99-
#define HID13_GROUP0_FF1_DELAY(x) (((unsigned long)x) << 26)
99+
#define HID13_GROUP0_FF1_DELAY(x) ((ULONG(x)) << 26)
100100
#define HID13_GROUP0_FF1_DELAY_MASK GENMASK(29, 26)
101-
#define HID13_GROUP0_FF2_DELAY(x) (((unsigned long)x) << 30)
101+
#define HID13_GROUP0_FF2_DELAY(x) ((ULONG(x)) << 30)
102102
#define HID13_GROUP0_FF2_DELAY_MASK GENMASK(33, 30)
103-
#define HID13_GROUP0_FF3_DELAY(x) (((unsigned long)x) << 34)
103+
#define HID13_GROUP0_FF3_DELAY(x) ((ULONG(x)) << 34)
104104
#define HID13_GROUP0_FF3_DELAY_MASK GENMASK(37, 34)
105-
#define HID13_GROUP0_FF4_DELAY(x) (((unsigned long)x) << 38)
105+
#define HID13_GROUP0_FF4_DELAY(x) ((ULONG(x)) << 38)
106106
#define HID13_GROUP0_FF4_DELAY_MASK GENMASK(41, 38)
107-
#define HID13_GROUP0_FF5_DELAY(x) (((unsigned long)x) << 42)
107+
#define HID13_GROUP0_FF5_DELAY(x) ((ULONG(x)) << 42)
108108
#define HID13_GROUP0_FF5_DELAY_MASK GENMASK(45, 42)
109-
#define HID13_GROUP0_FF6_DELAY(x) (((unsigned long)x) << 46)
109+
#define HID13_GROUP0_FF6_DELAY(x) ((ULONG(x)) << 46)
110110
#define HID13_GROUP0_FF6_DELAY_MASK GENMASK(49, 46)
111-
#define HID13_GROUP0_FF7_DELAY(x) (((unsigned long)x) << 50)
111+
#define HID13_GROUP0_FF7_DELAY(x) ((ULONG(x)) << 50)
112112
#define HID13_GROUP0_FF7_DELAY_MASK GENMASK(53, 50)
113-
#define HID13_RESET_CYCLES(x) (((unsigned long)x) << 60)
113+
#define HID13_RESET_CYCLES(x) ((ULONG(x)) << 60)
114114
#define HID13_RESET_CYCLES_MASK (0xFUL << 60)
115115

116116
#define SYS_IMP_APL_HID14 sys_reg(3, 0, 15, 15, 0)
@@ -137,7 +137,7 @@
137137
#define EHID20_TRAP_SMC BIT(8)
138138
#define EHID20_FORCE_NONSPEC_IF_OLDEST_REDIR_VALID_AND_OLDER BIT(15)
139139
#define EHID20_FORCE_NONSPEC_IF_SPEC_FLUSH_POINTER_NE_BLK_RTR_POINTER BIT(16)
140-
#define EHID20_FORCE_NONSPEC_TARGETED_TIMER_SEL(x) (((unsigned long)x) << 21)
140+
#define EHID20_FORCE_NONSPEC_TARGETED_TIMER_SEL(x) ((ULONG(x)) << 21)
141141
#define EHID20_FORCE_NONSPEC_TARGETED_TIMER_SEL_MASK (3UL << 21)
142142

143143
#define SYS_IMP_APL_HID21 sys_reg(3, 0, 15, 1, 3)
@@ -147,13 +147,13 @@
147147
#define HID21_AVL_UNK52 BIT(52)
148148

149149
#define SYS_IMP_APL_HID26 sys_reg(3, 0, 15, 0, 3)
150-
#define HID26_GROUP1_OFFSET(x) (((unsigned long)x) << 0)
150+
#define HID26_GROUP1_OFFSET(x) ((ULONG(x)) << 0)
151151
#define HID26_GROUP1_OFFSET_MASK (0xffUL << 0)
152-
#define HID26_GROUP2_OFFSET(x) (((unsigned long)x) << 36)
152+
#define HID26_GROUP2_OFFSET(x) ((ULONG(x)) << 36)
153153
#define HID26_GROUP2_OFFSET_MASK (0xffUL << 36)
154154

155155
#define SYS_IMP_APL_HID27 sys_reg(3, 0, 15, 0, 4)
156-
#define HID27_GROUP3_OFFSET(x) (((unsigned long)x) << 8)
156+
#define HID27_GROUP3_OFFSET(x) ((ULONG(x)) << 8)
157157
#define HID27_GROUP3_OFFSET_MASK (0xffUL << 8)
158158

159159
#define SYS_IMP_APL_PMCR0 sys_reg(3, 1, 15, 0, 0)
@@ -209,29 +209,29 @@
209209

210210
/* ACC/CYC Registers */
211211
#define SYS_IMP_APL_ACC_CFG sys_reg(3, 5, 15, 4, 0)
212-
#define ACC_CFG_BP_SLEEP(x) (((unsigned long)x) << 2)
212+
#define ACC_CFG_BP_SLEEP(x) ((ULONG(x)) << 2)
213213
#define ACC_CFG_BP_SLEEP_MASK (3UL << 2)
214214

215215
#define SYS_IMP_APL_CYC_OVRD sys_reg(3, 5, 15, 5, 0)
216-
#define CYC_OVRD_FIQ_MODE(x) (((unsigned long)x) << 20)
216+
#define CYC_OVRD_FIQ_MODE(x) ((ULONG(x)) << 20)
217217
#define CYC_OVRD_FIQ_MODE_MASK (3UL << 20)
218-
#define CYC_OVRD_IRQ_MODE(x) (((unsigned long)x) << 22)
218+
#define CYC_OVRD_IRQ_MODE(x) ((ULONG(x)) << 22)
219219
#define CYC_OVRD_IRQ_MODE_MASK (3UL << 22)
220-
#define CYC_OVRD_WFI_MODE(x) (((unsigned long)x) << 24)
220+
#define CYC_OVRD_WFI_MODE(x) ((ULONG(x)) << 24)
221221
#define CYC_OVRD_WFI_MODE_MASK (3UL << 24)
222222
#define CYC_OVRD_DISABLE_WFI_RET BIT(0)
223223

224224
#define SYS_IMP_APL_ACC_OVRD sys_reg(3, 5, 15, 6, 0)
225225

226-
#define ACC_OVRD_PWR_DN_SRM(x) (((unsigned long)x) << 13)
226+
#define ACC_OVRD_PWR_DN_SRM(x) ((ULONG(x)) << 13)
227227
#define ACC_OVRD_PWR_DN_SRM_MASK GENMASK(14, 13)
228-
#define ACC_OVRD_DIS_L2_FLUSH_ACC_SLEEP(x) (((unsigned long)x) << 15)
228+
#define ACC_OVRD_DIS_L2_FLUSH_ACC_SLEEP(x) ((ULONG(x)) << 15)
229229
#define ACC_OVRD_DIS_L2_FLUSH_ACC_SLEEP_MASK GENMASK(16, 15)
230-
#define ACC_OVRD_TRAIN_DOWN_LINK(x) (((unsigned long)x) << 17)
230+
#define ACC_OVRD_TRAIN_DOWN_LINK(x) ((ULONG(x)) << 17)
231231
#define ACC_OVRD_TRAIN_DOWN_LINK_MASK GENMASK(18, 17)
232-
#define ACC_OVRD_POWER_DOWN_CPM(x) (((unsigned long)x) << 25)
232+
#define ACC_OVRD_POWER_DOWN_CPM(x) ((ULONG(x)) << 25)
233233
#define ACC_OVRD_POWER_DOWN_CPM_MASK GENMASK(26, 25)
234-
#define ACC_OVRD_CPM_WAKE_UP(x) (((unsigned long)x) << 27)
234+
#define ACC_OVRD_CPM_WAKE_UP(x) ((ULONG(x)) << 27)
235235
#define ACC_OVRD_CPM_WAKE_UP_MASK GENMASK(28, 27)
236236
#define ACC_OVRD_DISABLE_CLK_DTR BIT(29)
237237
#define ACC_OVRD_DISABLE_PIO_ON_WFI_CPU BIT(32)

src/types.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,21 @@ typedef s64 ssize_t;
4949
#define SZ_1M (1 << 20)
5050
#define SZ_32M (1 << 25)
5151

52+
#define BIT(x) (1UL << (x))
53+
#define MASK(x) (BIT(x) - 1)
54+
#define GENMASK(msb, lsb) ((BIT((msb + 1) - (lsb)) - 1) << (lsb))
55+
#define _FIELD_LSB(field) ((field) & ~(field - 1))
56+
#define FIELD_PREP(field, val) ((val) * (_FIELD_LSB(field)))
57+
#define FIELD_GET(field, val) (((val) & (field)) / _FIELD_LSB(field))
58+
5259
#ifdef __ASSEMBLER__
5360

61+
#define ULONG(x) (x)
5462
#define sys_reg(op0, op1, CRn, CRm, op2) s##op0##_##op1##_c##CRn##_c##CRm##_##op2
5563

5664
#else
5765

66+
#define ULONG(x) ((unsigned long)(x))
5867
#define sys_reg(op0, op1, CRn, CRm, op2) , _S, op0, op1, CRn, CRm, op2
5968

6069
#endif

src/utils.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@
1717

1818
#define ARRAY_SIZE(s) (sizeof(s) / sizeof((s)[0]))
1919

20-
#define BIT(x) (1UL << (x))
21-
#define MASK(x) (BIT(x) - 1)
22-
#define GENMASK(msb, lsb) ((BIT((msb + 1) - (lsb)) - 1) << (lsb))
23-
#define _FIELD_LSB(field) ((field) & ~(field - 1))
24-
#define FIELD_PREP(field, val) ((val) * (_FIELD_LSB(field)))
25-
#define FIELD_GET(field, val) (((val) & (field)) / _FIELD_LSB(field))
26-
2720
#define ALIGN_UP(x, a) (((x) + ((a)-1)) & ~((a)-1))
2821
#define ALIGN_DOWN(x, a) ((x) & ~((a)-1))
2922

src/utils_asm.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ put_simd_state:
154154
.type deep_wfi, @function
155155
deep_wfi:
156156
mrs x0, SYS_IMP_APL_CYC_OVRD
157-
orr x1, x0, #(3L << 24)
157+
orr x1, x0, #CYC_OVRD_WFI_MODE(3)
158158
msr SYS_IMP_APL_CYC_OVRD, x1
159159

160160
stp x30, x0, [sp, #-16]!

0 commit comments

Comments
 (0)