Merge tag 'kvmarm-fixes-5.11-2' of git://git.kernel.org/pub/scm/linux/kernel/git...
[sfrench/cifs-2.6.git] / include / linux / firmware / xlnx-zynqmp.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Xilinx Zynq MPSoC Firmware layer
4  *
5  *  Copyright (C) 2014-2019 Xilinx
6  *
7  *  Michal Simek <michal.simek@xilinx.com>
8  *  Davorin Mista <davorin.mista@aggios.com>
9  *  Jolly Shah <jollys@xilinx.com>
10  *  Rajan Vaja <rajanv@xilinx.com>
11  */
12
13 #ifndef __FIRMWARE_ZYNQMP_H__
14 #define __FIRMWARE_ZYNQMP_H__
15
16 #include <linux/err.h>
17
18 #define ZYNQMP_PM_VERSION_MAJOR 1
19 #define ZYNQMP_PM_VERSION_MINOR 0
20
21 #define ZYNQMP_PM_VERSION       ((ZYNQMP_PM_VERSION_MAJOR << 16) | \
22                                         ZYNQMP_PM_VERSION_MINOR)
23
24 #define ZYNQMP_TZ_VERSION_MAJOR 1
25 #define ZYNQMP_TZ_VERSION_MINOR 0
26
27 #define ZYNQMP_TZ_VERSION       ((ZYNQMP_TZ_VERSION_MAJOR << 16) | \
28                                         ZYNQMP_TZ_VERSION_MINOR)
29
30 /* SMC SIP service Call Function Identifier Prefix */
31 #define PM_SIP_SVC                      0xC2000000
32 #define PM_GET_TRUSTZONE_VERSION        0xa03
33 #define PM_SET_SUSPEND_MODE             0xa02
34 #define GET_CALLBACK_DATA               0xa01
35
36 /* Number of 32bits values in payload */
37 #define PAYLOAD_ARG_CNT 4U
38
39 /* Number of arguments for a callback */
40 #define CB_ARG_CNT     4
41
42 /* Payload size (consists of callback API ID + arguments) */
43 #define CB_PAYLOAD_SIZE (CB_ARG_CNT + 1)
44
45 #define ZYNQMP_PM_MAX_QOS               100U
46
47 #define GSS_NUM_REGS    (4)
48
49 /* Node capabilities */
50 #define ZYNQMP_PM_CAPABILITY_ACCESS     0x1U
51 #define ZYNQMP_PM_CAPABILITY_CONTEXT    0x2U
52 #define ZYNQMP_PM_CAPABILITY_WAKEUP     0x4U
53 #define ZYNQMP_PM_CAPABILITY_UNUSABLE   0x8U
54
55 /*
56  * Firmware FPGA Manager flags
57  * XILINX_ZYNQMP_PM_FPGA_FULL:  FPGA full reconfiguration
58  * XILINX_ZYNQMP_PM_FPGA_PARTIAL: FPGA partial reconfiguration
59  */
60 #define XILINX_ZYNQMP_PM_FPGA_FULL      0x0U
61 #define XILINX_ZYNQMP_PM_FPGA_PARTIAL   BIT(0)
62
63 enum pm_api_id {
64         PM_GET_API_VERSION = 1,
65         PM_SYSTEM_SHUTDOWN = 12,
66         PM_REQUEST_NODE = 13,
67         PM_RELEASE_NODE,
68         PM_SET_REQUIREMENT,
69         PM_RESET_ASSERT = 17,
70         PM_RESET_GET_STATUS,
71         PM_PM_INIT_FINALIZE = 21,
72         PM_FPGA_LOAD,
73         PM_FPGA_GET_STATUS,
74         PM_GET_CHIPID = 24,
75         PM_IOCTL = 34,
76         PM_QUERY_DATA,
77         PM_CLOCK_ENABLE,
78         PM_CLOCK_DISABLE,
79         PM_CLOCK_GETSTATE,
80         PM_CLOCK_SETDIVIDER,
81         PM_CLOCK_GETDIVIDER,
82         PM_CLOCK_SETRATE,
83         PM_CLOCK_GETRATE,
84         PM_CLOCK_SETPARENT,
85         PM_CLOCK_GETPARENT,
86         PM_SECURE_AES = 47,
87         PM_FEATURE_CHECK = 63,
88         PM_API_MAX,
89 };
90
91 /* PMU-FW return status codes */
92 enum pm_ret_status {
93         XST_PM_SUCCESS = 0,
94         XST_PM_NO_FEATURE = 19,
95         XST_PM_INTERNAL = 2000,
96         XST_PM_CONFLICT,
97         XST_PM_NO_ACCESS,
98         XST_PM_INVALID_NODE,
99         XST_PM_DOUBLE_REQ,
100         XST_PM_ABORT_SUSPEND,
101         XST_PM_MULT_USER = 2008,
102 };
103
104 enum pm_ioctl_id {
105         IOCTL_SD_DLL_RESET = 6,
106         IOCTL_SET_SD_TAPDELAY,
107         IOCTL_SET_PLL_FRAC_MODE,
108         IOCTL_GET_PLL_FRAC_MODE,
109         IOCTL_SET_PLL_FRAC_DATA,
110         IOCTL_GET_PLL_FRAC_DATA,
111         IOCTL_WRITE_GGS = 12,
112         IOCTL_READ_GGS = 13,
113         IOCTL_WRITE_PGGS = 14,
114         IOCTL_READ_PGGS = 15,
115         /* Set healthy bit value */
116         IOCTL_SET_BOOT_HEALTH_STATUS = 17,
117 };
118
119 enum pm_query_id {
120         PM_QID_INVALID,
121         PM_QID_CLOCK_GET_NAME,
122         PM_QID_CLOCK_GET_TOPOLOGY,
123         PM_QID_CLOCK_GET_FIXEDFACTOR_PARAMS,
124         PM_QID_CLOCK_GET_PARENTS,
125         PM_QID_CLOCK_GET_ATTRIBUTES,
126         PM_QID_CLOCK_GET_NUM_CLOCKS = 12,
127         PM_QID_CLOCK_GET_MAX_DIVISOR,
128 };
129
130 enum zynqmp_pm_reset_action {
131         PM_RESET_ACTION_RELEASE,
132         PM_RESET_ACTION_ASSERT,
133         PM_RESET_ACTION_PULSE,
134 };
135
136 enum zynqmp_pm_reset {
137         ZYNQMP_PM_RESET_START = 1000,
138         ZYNQMP_PM_RESET_PCIE_CFG = ZYNQMP_PM_RESET_START,
139         ZYNQMP_PM_RESET_PCIE_BRIDGE,
140         ZYNQMP_PM_RESET_PCIE_CTRL,
141         ZYNQMP_PM_RESET_DP,
142         ZYNQMP_PM_RESET_SWDT_CRF,
143         ZYNQMP_PM_RESET_AFI_FM5,
144         ZYNQMP_PM_RESET_AFI_FM4,
145         ZYNQMP_PM_RESET_AFI_FM3,
146         ZYNQMP_PM_RESET_AFI_FM2,
147         ZYNQMP_PM_RESET_AFI_FM1,
148         ZYNQMP_PM_RESET_AFI_FM0,
149         ZYNQMP_PM_RESET_GDMA,
150         ZYNQMP_PM_RESET_GPU_PP1,
151         ZYNQMP_PM_RESET_GPU_PP0,
152         ZYNQMP_PM_RESET_GPU,
153         ZYNQMP_PM_RESET_GT,
154         ZYNQMP_PM_RESET_SATA,
155         ZYNQMP_PM_RESET_ACPU3_PWRON,
156         ZYNQMP_PM_RESET_ACPU2_PWRON,
157         ZYNQMP_PM_RESET_ACPU1_PWRON,
158         ZYNQMP_PM_RESET_ACPU0_PWRON,
159         ZYNQMP_PM_RESET_APU_L2,
160         ZYNQMP_PM_RESET_ACPU3,
161         ZYNQMP_PM_RESET_ACPU2,
162         ZYNQMP_PM_RESET_ACPU1,
163         ZYNQMP_PM_RESET_ACPU0,
164         ZYNQMP_PM_RESET_DDR,
165         ZYNQMP_PM_RESET_APM_FPD,
166         ZYNQMP_PM_RESET_SOFT,
167         ZYNQMP_PM_RESET_GEM0,
168         ZYNQMP_PM_RESET_GEM1,
169         ZYNQMP_PM_RESET_GEM2,
170         ZYNQMP_PM_RESET_GEM3,
171         ZYNQMP_PM_RESET_QSPI,
172         ZYNQMP_PM_RESET_UART0,
173         ZYNQMP_PM_RESET_UART1,
174         ZYNQMP_PM_RESET_SPI0,
175         ZYNQMP_PM_RESET_SPI1,
176         ZYNQMP_PM_RESET_SDIO0,
177         ZYNQMP_PM_RESET_SDIO1,
178         ZYNQMP_PM_RESET_CAN0,
179         ZYNQMP_PM_RESET_CAN1,
180         ZYNQMP_PM_RESET_I2C0,
181         ZYNQMP_PM_RESET_I2C1,
182         ZYNQMP_PM_RESET_TTC0,
183         ZYNQMP_PM_RESET_TTC1,
184         ZYNQMP_PM_RESET_TTC2,
185         ZYNQMP_PM_RESET_TTC3,
186         ZYNQMP_PM_RESET_SWDT_CRL,
187         ZYNQMP_PM_RESET_NAND,
188         ZYNQMP_PM_RESET_ADMA,
189         ZYNQMP_PM_RESET_GPIO,
190         ZYNQMP_PM_RESET_IOU_CC,
191         ZYNQMP_PM_RESET_TIMESTAMP,
192         ZYNQMP_PM_RESET_RPU_R50,
193         ZYNQMP_PM_RESET_RPU_R51,
194         ZYNQMP_PM_RESET_RPU_AMBA,
195         ZYNQMP_PM_RESET_OCM,
196         ZYNQMP_PM_RESET_RPU_PGE,
197         ZYNQMP_PM_RESET_USB0_CORERESET,
198         ZYNQMP_PM_RESET_USB1_CORERESET,
199         ZYNQMP_PM_RESET_USB0_HIBERRESET,
200         ZYNQMP_PM_RESET_USB1_HIBERRESET,
201         ZYNQMP_PM_RESET_USB0_APB,
202         ZYNQMP_PM_RESET_USB1_APB,
203         ZYNQMP_PM_RESET_IPI,
204         ZYNQMP_PM_RESET_APM_LPD,
205         ZYNQMP_PM_RESET_RTC,
206         ZYNQMP_PM_RESET_SYSMON,
207         ZYNQMP_PM_RESET_AFI_FM6,
208         ZYNQMP_PM_RESET_LPD_SWDT,
209         ZYNQMP_PM_RESET_FPD,
210         ZYNQMP_PM_RESET_RPU_DBG1,
211         ZYNQMP_PM_RESET_RPU_DBG0,
212         ZYNQMP_PM_RESET_DBG_LPD,
213         ZYNQMP_PM_RESET_DBG_FPD,
214         ZYNQMP_PM_RESET_APLL,
215         ZYNQMP_PM_RESET_DPLL,
216         ZYNQMP_PM_RESET_VPLL,
217         ZYNQMP_PM_RESET_IOPLL,
218         ZYNQMP_PM_RESET_RPLL,
219         ZYNQMP_PM_RESET_GPO3_PL_0,
220         ZYNQMP_PM_RESET_GPO3_PL_1,
221         ZYNQMP_PM_RESET_GPO3_PL_2,
222         ZYNQMP_PM_RESET_GPO3_PL_3,
223         ZYNQMP_PM_RESET_GPO3_PL_4,
224         ZYNQMP_PM_RESET_GPO3_PL_5,
225         ZYNQMP_PM_RESET_GPO3_PL_6,
226         ZYNQMP_PM_RESET_GPO3_PL_7,
227         ZYNQMP_PM_RESET_GPO3_PL_8,
228         ZYNQMP_PM_RESET_GPO3_PL_9,
229         ZYNQMP_PM_RESET_GPO3_PL_10,
230         ZYNQMP_PM_RESET_GPO3_PL_11,
231         ZYNQMP_PM_RESET_GPO3_PL_12,
232         ZYNQMP_PM_RESET_GPO3_PL_13,
233         ZYNQMP_PM_RESET_GPO3_PL_14,
234         ZYNQMP_PM_RESET_GPO3_PL_15,
235         ZYNQMP_PM_RESET_GPO3_PL_16,
236         ZYNQMP_PM_RESET_GPO3_PL_17,
237         ZYNQMP_PM_RESET_GPO3_PL_18,
238         ZYNQMP_PM_RESET_GPO3_PL_19,
239         ZYNQMP_PM_RESET_GPO3_PL_20,
240         ZYNQMP_PM_RESET_GPO3_PL_21,
241         ZYNQMP_PM_RESET_GPO3_PL_22,
242         ZYNQMP_PM_RESET_GPO3_PL_23,
243         ZYNQMP_PM_RESET_GPO3_PL_24,
244         ZYNQMP_PM_RESET_GPO3_PL_25,
245         ZYNQMP_PM_RESET_GPO3_PL_26,
246         ZYNQMP_PM_RESET_GPO3_PL_27,
247         ZYNQMP_PM_RESET_GPO3_PL_28,
248         ZYNQMP_PM_RESET_GPO3_PL_29,
249         ZYNQMP_PM_RESET_GPO3_PL_30,
250         ZYNQMP_PM_RESET_GPO3_PL_31,
251         ZYNQMP_PM_RESET_RPU_LS,
252         ZYNQMP_PM_RESET_PS_ONLY,
253         ZYNQMP_PM_RESET_PL,
254         ZYNQMP_PM_RESET_PS_PL0,
255         ZYNQMP_PM_RESET_PS_PL1,
256         ZYNQMP_PM_RESET_PS_PL2,
257         ZYNQMP_PM_RESET_PS_PL3,
258         ZYNQMP_PM_RESET_END = ZYNQMP_PM_RESET_PS_PL3
259 };
260
261 enum zynqmp_pm_suspend_reason {
262         SUSPEND_POWER_REQUEST = 201,
263         SUSPEND_ALERT,
264         SUSPEND_SYSTEM_SHUTDOWN,
265 };
266
267 enum zynqmp_pm_request_ack {
268         ZYNQMP_PM_REQUEST_ACK_NO = 1,
269         ZYNQMP_PM_REQUEST_ACK_BLOCKING,
270         ZYNQMP_PM_REQUEST_ACK_NON_BLOCKING,
271 };
272
273 enum pm_node_id {
274         NODE_SD_0 = 39,
275         NODE_SD_1,
276 };
277
278 enum tap_delay_type {
279         PM_TAPDELAY_INPUT = 0,
280         PM_TAPDELAY_OUTPUT,
281 };
282
283 enum dll_reset_type {
284         PM_DLL_RESET_ASSERT,
285         PM_DLL_RESET_RELEASE,
286         PM_DLL_RESET_PULSE,
287 };
288
289 enum zynqmp_pm_shutdown_type {
290         ZYNQMP_PM_SHUTDOWN_TYPE_SHUTDOWN,
291         ZYNQMP_PM_SHUTDOWN_TYPE_RESET,
292         ZYNQMP_PM_SHUTDOWN_TYPE_SETSCOPE_ONLY,
293 };
294
295 enum zynqmp_pm_shutdown_subtype {
296         ZYNQMP_PM_SHUTDOWN_SUBTYPE_SUBSYSTEM,
297         ZYNQMP_PM_SHUTDOWN_SUBTYPE_PS_ONLY,
298         ZYNQMP_PM_SHUTDOWN_SUBTYPE_SYSTEM,
299 };
300
301 /**
302  * struct zynqmp_pm_query_data - PM query data
303  * @qid:        query ID
304  * @arg1:       Argument 1 of query data
305  * @arg2:       Argument 2 of query data
306  * @arg3:       Argument 3 of query data
307  */
308 struct zynqmp_pm_query_data {
309         u32 qid;
310         u32 arg1;
311         u32 arg2;
312         u32 arg3;
313 };
314
315 int zynqmp_pm_invoke_fn(u32 pm_api_id, u32 arg0, u32 arg1,
316                         u32 arg2, u32 arg3, u32 *ret_payload);
317
318 #if IS_REACHABLE(CONFIG_ZYNQMP_FIRMWARE)
319 int zynqmp_pm_get_api_version(u32 *version);
320 int zynqmp_pm_get_chipid(u32 *idcode, u32 *version);
321 int zynqmp_pm_query_data(struct zynqmp_pm_query_data qdata, u32 *out);
322 int zynqmp_pm_clock_enable(u32 clock_id);
323 int zynqmp_pm_clock_disable(u32 clock_id);
324 int zynqmp_pm_clock_getstate(u32 clock_id, u32 *state);
325 int zynqmp_pm_clock_setdivider(u32 clock_id, u32 divider);
326 int zynqmp_pm_clock_getdivider(u32 clock_id, u32 *divider);
327 int zynqmp_pm_clock_setrate(u32 clock_id, u64 rate);
328 int zynqmp_pm_clock_getrate(u32 clock_id, u64 *rate);
329 int zynqmp_pm_clock_setparent(u32 clock_id, u32 parent_id);
330 int zynqmp_pm_clock_getparent(u32 clock_id, u32 *parent_id);
331 int zynqmp_pm_set_pll_frac_mode(u32 clk_id, u32 mode);
332 int zynqmp_pm_get_pll_frac_mode(u32 clk_id, u32 *mode);
333 int zynqmp_pm_set_pll_frac_data(u32 clk_id, u32 data);
334 int zynqmp_pm_get_pll_frac_data(u32 clk_id, u32 *data);
335 int zynqmp_pm_set_sd_tapdelay(u32 node_id, u32 type, u32 value);
336 int zynqmp_pm_sd_dll_reset(u32 node_id, u32 type);
337 int zynqmp_pm_reset_assert(const enum zynqmp_pm_reset reset,
338                            const enum zynqmp_pm_reset_action assert_flag);
339 int zynqmp_pm_reset_get_status(const enum zynqmp_pm_reset reset, u32 *status);
340 int zynqmp_pm_init_finalize(void);
341 int zynqmp_pm_set_suspend_mode(u32 mode);
342 int zynqmp_pm_request_node(const u32 node, const u32 capabilities,
343                            const u32 qos, const enum zynqmp_pm_request_ack ack);
344 int zynqmp_pm_release_node(const u32 node);
345 int zynqmp_pm_set_requirement(const u32 node, const u32 capabilities,
346                               const u32 qos,
347                               const enum zynqmp_pm_request_ack ack);
348 int zynqmp_pm_aes_engine(const u64 address, u32 *out);
349 int zynqmp_pm_fpga_load(const u64 address, const u32 size, const u32 flags);
350 int zynqmp_pm_fpga_get_status(u32 *value);
351 int zynqmp_pm_write_ggs(u32 index, u32 value);
352 int zynqmp_pm_read_ggs(u32 index, u32 *value);
353 int zynqmp_pm_write_pggs(u32 index, u32 value);
354 int zynqmp_pm_read_pggs(u32 index, u32 *value);
355 int zynqmp_pm_system_shutdown(const u32 type, const u32 subtype);
356 int zynqmp_pm_set_boot_health_status(u32 value);
357 #else
358 static inline struct zynqmp_eemi_ops *zynqmp_pm_get_eemi_ops(void)
359 {
360         return ERR_PTR(-ENODEV);
361 }
362
363 static inline int zynqmp_pm_get_api_version(u32 *version)
364 {
365         return -ENODEV;
366 }
367
368 static inline int zynqmp_pm_get_chipid(u32 *idcode, u32 *version)
369 {
370         return -ENODEV;
371 }
372
373 static inline int zynqmp_pm_query_data(struct zynqmp_pm_query_data qdata,
374                                        u32 *out)
375 {
376         return -ENODEV;
377 }
378
379 static inline int zynqmp_pm_clock_enable(u32 clock_id)
380 {
381         return -ENODEV;
382 }
383
384 static inline int zynqmp_pm_clock_disable(u32 clock_id)
385 {
386         return -ENODEV;
387 }
388
389 static inline int zynqmp_pm_clock_getstate(u32 clock_id, u32 *state)
390 {
391         return -ENODEV;
392 }
393
394 static inline int zynqmp_pm_clock_setdivider(u32 clock_id, u32 divider)
395 {
396         return -ENODEV;
397 }
398
399 static inline int zynqmp_pm_clock_getdivider(u32 clock_id, u32 *divider)
400 {
401         return -ENODEV;
402 }
403
404 static inline int zynqmp_pm_clock_setrate(u32 clock_id, u64 rate)
405 {
406         return -ENODEV;
407 }
408
409 static inline int zynqmp_pm_clock_getrate(u32 clock_id, u64 *rate)
410 {
411         return -ENODEV;
412 }
413
414 static inline int zynqmp_pm_clock_setparent(u32 clock_id, u32 parent_id)
415 {
416         return -ENODEV;
417 }
418
419 static inline int zynqmp_pm_clock_getparent(u32 clock_id, u32 *parent_id)
420 {
421         return -ENODEV;
422 }
423
424 static inline int zynqmp_pm_set_pll_frac_mode(u32 clk_id, u32 mode)
425 {
426         return -ENODEV;
427 }
428
429 static inline int zynqmp_pm_get_pll_frac_mode(u32 clk_id, u32 *mode)
430 {
431         return -ENODEV;
432 }
433
434 static inline int zynqmp_pm_set_pll_frac_data(u32 clk_id, u32 data)
435 {
436         return -ENODEV;
437 }
438
439 static inline int zynqmp_pm_get_pll_frac_data(u32 clk_id, u32 *data)
440 {
441         return -ENODEV;
442 }
443
444 static inline int zynqmp_pm_set_sd_tapdelay(u32 node_id, u32 type, u32 value)
445 {
446         return -ENODEV;
447 }
448
449 static inline int zynqmp_pm_sd_dll_reset(u32 node_id, u32 type)
450 {
451         return -ENODEV;
452 }
453
454 static inline int zynqmp_pm_reset_assert(const enum zynqmp_pm_reset reset,
455                                          const enum zynqmp_pm_reset_action assert_flag)
456 {
457         return -ENODEV;
458 }
459
460 static inline int zynqmp_pm_reset_get_status(const enum zynqmp_pm_reset reset,
461                                              u32 *status)
462 {
463         return -ENODEV;
464 }
465
466 static inline int zynqmp_pm_init_finalize(void)
467 {
468         return -ENODEV;
469 }
470
471 static inline int zynqmp_pm_set_suspend_mode(u32 mode)
472 {
473         return -ENODEV;
474 }
475
476 static inline int zynqmp_pm_request_node(const u32 node, const u32 capabilities,
477                                          const u32 qos,
478                                          const enum zynqmp_pm_request_ack ack)
479 {
480         return -ENODEV;
481 }
482
483 static inline int zynqmp_pm_release_node(const u32 node)
484 {
485         return -ENODEV;
486 }
487
488 static inline int zynqmp_pm_set_requirement(const u32 node,
489                                             const u32 capabilities,
490                                             const u32 qos,
491                                             const enum zynqmp_pm_request_ack ack)
492 {
493         return -ENODEV;
494 }
495
496 static inline int zynqmp_pm_aes_engine(const u64 address, u32 *out)
497 {
498         return -ENODEV;
499 }
500
501 static inline int zynqmp_pm_fpga_load(const u64 address, const u32 size,
502                                       const u32 flags)
503 {
504         return -ENODEV;
505 }
506
507 static inline int zynqmp_pm_fpga_get_status(u32 *value)
508 {
509         return -ENODEV;
510 }
511
512 static inline int zynqmp_pm_write_ggs(u32 index, u32 value)
513 {
514         return -ENODEV;
515 }
516
517 static inline int zynqmp_pm_read_ggs(u32 index, u32 *value)
518 {
519         return -ENODEV;
520 }
521
522 static inline int zynqmp_pm_write_pggs(u32 index, u32 value)
523 {
524         return -ENODEV;
525 }
526
527 static inline int zynqmp_pm_read_pggs(u32 index, u32 *value)
528 {
529         return -ENODEV;
530 }
531
532 static inline int zynqmp_pm_system_shutdown(const u32 type, const u32 subtype)
533 {
534         return -ENODEV;
535 }
536
537 static inline int zynqmp_pm_set_boot_health_status(u32 value)
538 {
539         return -ENODEV;
540 }
541 #endif
542
543 #endif /* __FIRMWARE_ZYNQMP_H__ */