/
xpm_api.c
4237 lines (3791 loc) · 115 KB
/
xpm_api.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************************
* Copyright (c) 2018 - 2020 Xilinx, Inc. All rights reserved.
* SPDX-License-Identifier: MIT
******************************************************************************/
#include "xplmi_util.h"
#include "xpm_api.h"
#include "xpm_defs.h"
#include "xpm_psm_api.h"
#include "xpm_pldomain.h"
#include "xpm_pll.h"
#include "xpm_powerdomain.h"
#include "xpm_pmcdomain.h"
#include "xpm_pslpdomain.h"
#include "xpm_psfpdomain.h"
#include "xpm_npdomain.h"
#include "xpm_cpmdomain.h"
#include "xpm_psm.h"
#include "xpm_pmc.h"
#include "xpm_periph.h"
#include "xpm_mem.h"
#include "xpm_apucore.h"
#include "xpm_rpucore.h"
#include "xpm_power.h"
#include "xpm_pin.h"
#include "xplmi.h"
#include "xplmi_modules.h"
#include "xpm_aie.h"
#include "xpm_prot.h"
#include "xpm_regs.h"
#include "xpm_ioctl.h"
#include "xpm_ipi.h"
#include "xsysmonpsv.h"
#include "xpm_notifier.h"
#include "xplmi_error_node.h"
#include "xpm_rail.h"
#include "xpm_pldevice.h"
#include "xpm_debug.h"
#include "xpm_device.h"
#define XPm_RegisterWakeUpHandler(GicId, SrcId, NodeId) \
XPlmi_GicRegisterHandler(((GicId) << (8U)) | ((SrcId) << (16U)), \
XPm_DispatchWakeHandler, (void *)(NodeId))
u32 ResetReason;
void (*PmRequestCb)(const u32 SubsystemId, const XPmApiCbId_t EventId, u32 *Payload);
static XPlmi_ModuleCmd XPlmi_PmCmds[PM_API_MAX+1];
static XPlmi_Module XPlmi_Pm =
{
XPLMI_MODULE_XILPM_ID,
XPlmi_PmCmds,
PM_API_MAX+1,
};
static int (*PmRestartCb)(u32 ImageId, u32 *FuncId);
/****************************************************************************/
/**
* @brief This function sets the rate of the clock.
*
* @param IpiMask IpiMask of subsystem
* @param ClockId Clock node ID
* @param ClkRate Clock rate
*
* @return XST_SUCCESS if successful else XST_FAILURE or an error code
* or a reason code
*
* @note None
*
****************************************************************************/
static int XPm_SetClockRate(const u32 IpiMask, const u32 ClockId, const u32 ClkRate)
{
int Status = XST_FAILURE;
XPm_ClockNode *Clk = XPmClock_GetById(ClockId);
if (NULL == Clk) {
Status = XPM_INVALID_CLKID;
goto done;
}
/* Set rate is allow only for the request come from CDO,
* So by use of IpiMask check that request come from CDO or not,
* If request comes from CDO then IpiMask will 0x00U.
*/
if (0U != IpiMask) {
Status = XPM_PM_NO_ACCESS;
goto done;
}
/* Set rate is allowed only for ref clocks */
if (!ISREFCLK(ClockId)) {
Status = XST_INVALID_PARAM;
goto done;
}
Status = XPmClock_SetRate(Clk, ClkRate);
done:
return Status;
}
/****************************************************************************/
/**
* @brief This function gets the rate of the clock.
*
* @param ClockId Clock node ID
* @param ClkRate Pointer to store clock rate.
*
* @return XST_SUCCESS if successful else XST_FAILURE or an error code
* or a reason code
*
* @note None
*
****************************************************************************/
static int XPm_GetClockRate(const u32 ClockId, u32 *ClkRate)
{
int Status = XST_SUCCESS;
XPm_ClockNode *Clk = XPmClock_GetById(ClockId);
if (NULL == Clk) {
Status = XST_INVALID_PARAM;
goto done;
}
/* Get rate is allowed only for ref clocks */
if (!ISREFCLK(ClockId)) {
Status = XST_INVALID_PARAM;
goto done;
}
Status = XPmClock_GetRate(Clk, ClkRate);
done:
return Status;
}
/****************************************************************************/
/**
* @brief This function activates subsystem by requesting all pre-alloc
* devices which are essential for susbystem to be operational.
*
* @param SubsystemId ID of subsystem which is requesting to activate other
* subsystem (NULL in case of request from XSDB master)
* @param IpiMask IPI mask of requesting master
* @param TargetSubsystemId ID of subsystem which needs activation
*
* @return XST_SUCCESS if successful else XST_FAILURE or an error code
* or a reason code
*
* @note This command is only allowed from XSDB master or from PMC subsystem
*
****************************************************************************/
static XStatus XPm_ActivateSubsystem(u32 SubsystemId, u32 IpiMask,
u32 TargetSubsystemId)
{
XStatus Status = XST_FAILURE;
/* Return error if request is not from XSDB master or PMC subsystem */
if ((XSDB_IPI_INT_MASK != IpiMask) && (PM_SUBSYS_PMC != SubsystemId)) {
Status = XPM_PM_NO_ACCESS;
goto done;
}
/* Configure target subsystem */
Status = XPmSubsystem_Configure(TargetSubsystemId);
done:
return Status;
}
static int XPm_ProcessCmd(XPlmi_Cmd * Cmd)
{
u32 ApiResponse[XPLMI_CMD_RESP_SIZE-1] = {0};
int Status = XST_FAILURE;
XPm_Subsystem *Subsystem = NULL;
u32 SubsystemId = INVALID_SUBSYSID;
u32 *Pload = Cmd->Payload;
u32 Len = Cmd->Len;
u32 SetAddress;
u64 Address;
PmDbg("Processing Cmd %x\r\n", Cmd->CmdId);
if((Cmd->CmdId & 0xFFU) != PM_SET_CURRENT_SUBSYSTEM) {
SubsystemId = XPmSubsystem_GetCurrent();
if(SubsystemId != INVALID_SUBSYSID) {
PmDbg("Using current subsystemId: 0x%x\n\r", SubsystemId);
} else if ((0U == Cmd->IpiMask) && (0U != Cmd->SubsystemId)) {
SubsystemId = Cmd->SubsystemId;
PmDbg("Using subsystemId passed by PLM: 0x%x\n\r", SubsystemId);
/* PLD node ids are used as image ids for PLD images */
if (((u32)XPM_NODECLASS_DEVICE == NODECLASS(SubsystemId)) &&
((u32)XPM_NODESUBCL_DEV_PL == NODESUBCLASS(SubsystemId))) {
SubsystemId = PM_SUBSYS_PMC;
}
/* Use PMC subsystem ID for power domain CDOs. */
if ((u32)XPM_NODECLASS_POWER == NODECLASS(SubsystemId)) {
SubsystemId = PM_SUBSYS_PMC;
}
} else if (0U != Cmd->IpiMask) {
SubsystemId = XPmSubsystem_GetSubSysIdByIpiMask(Cmd->IpiMask);
PmDbg("Using subsystemId mapped to IPI: 0x%x\n\r", SubsystemId);
} else {
/* Required due to MISRA */
PmDbg("[%d] Unknown else case\r\n", __LINE__);
}
Subsystem = XPmSubsystem_GetById(SubsystemId);
if ((NULL == Subsystem) || (Subsystem->State == (u8)OFFLINE)) {
if (XSDB_IPI_INT_MASK == Cmd->IpiMask) {
PmDbg("Command from XSDB master\r\n");
} else {
/* Subsystem must not be offline here */
PmErr("Invalid SubsystemId 0x%x\n\r",
SubsystemId);
Status = XPM_INVALID_SUBSYSID;
goto done;
}
}
}
switch (Cmd->CmdId & 0xFFU) {
case PM_GET_CHIPID:
Status = XPm_GetChipID(&ApiResponse[0], &ApiResponse[1]);
break;
case PM_GET_API_VERSION:
Status = XPm_GetApiVersion(ApiResponse);
break;
case PM_REQUEST_WAKEUP:
/* setAddress is encoded in the 1st bit of the low-word address */
SetAddress = Pload[1] & 0x1U;
/* addresses are word-aligned, ignore bit 0 */
Address = ((u64) Pload[2]) << 32ULL;
Address += Pload[1] & (~(u64)0x1U);
Status = XPm_RequestWakeUp(SubsystemId, Pload[0],
SetAddress, Address,
Pload[3]);
break;
case PM_FORCE_POWERDOWN:
Status = XPm_ForcePowerdown(SubsystemId, Pload[0], Pload[1]);
break;
case PM_SYSTEM_SHUTDOWN:
Status = XPm_SystemShutdown(SubsystemId, Pload[0], Pload[1]);
break;
case PM_SELF_SUSPEND:
Status = XPm_SelfSuspend(SubsystemId, Pload[0],
Pload[1], (u8)Pload[2],
Pload[3], Pload[4]);
break;
case PM_REQUEST_SUSPEND:
Status = XPm_RequestSuspend(SubsystemId, Pload[0], Pload[1], Pload[2], Pload[3]);
break;
case PM_ABORT_SUSPEND:
Status = XPm_AbortSuspend(SubsystemId, Pload[0], Pload[1]);
break;
case PM_SET_WAKEUP_SOURCE:
Status = XPm_SetWakeUpSource(SubsystemId, Pload[0], Pload[1], Pload[2]);
break;
case PM_CLOCK_SETRATE:
Status = XPm_SetClockRate(Cmd->IpiMask, Pload[0], Pload[1]);
break;
case PM_CLOCK_GETRATE:
Status = XPm_GetClockRate(Pload[0], ApiResponse);
break;
case PM_CLOCK_SETPARENT:
Status = XPm_SetClockParent(SubsystemId, Pload[0], Pload[1]);
break;
case PM_CLOCK_GETPARENT:
Status = XPm_GetClockParent(Pload[0], ApiResponse);
break;
case PM_CLOCK_ENABLE:
Status = XPm_SetClockState(SubsystemId, Pload[0], 1);
break;
case PM_CLOCK_DISABLE:
Status = XPm_SetClockState(SubsystemId, Pload[0], 0);
break;
case PM_CLOCK_GETSTATE:
Status = XPm_GetClockState(Pload[0], ApiResponse);
break;
case PM_CLOCK_SETDIVIDER:
Status = XPm_SetClockDivider(SubsystemId, Pload[0], Pload[1]);
break;
case PM_CLOCK_GETDIVIDER:
Status = XPm_GetClockDivider(Pload[0], ApiResponse);
break;
case PM_PLL_SET_PARAMETER:
Status = XPm_SetPllParameter(SubsystemId, Pload[0], Pload[1], Pload[2]);
break;
case PM_PLL_GET_PARAMETER:
Status = XPm_GetPllParameter(Pload[0], Pload[1], ApiResponse);
break;
case PM_PLL_SET_MODE:
Status = XPm_SetPllMode(SubsystemId, Pload[0], Pload[1]);
break;
case PM_PLL_GET_MODE:
Status = XPm_GetPllMode(Pload[0], ApiResponse);
break;
case PM_REQUEST_NODE:
Status = XPm_RequestDevice(SubsystemId, Pload[0],
Pload[1], Pload[2],
Pload[3]);
break;
case PM_RELEASE_NODE:
Status = XPm_ReleaseDevice(SubsystemId, Pload[0]);
break;
case PM_SET_REQUIREMENT:
Status = XPm_SetRequirement(SubsystemId, Pload[0], Pload[1], Pload[2], Pload[3]);
break;
case PM_SET_MAX_LATENCY:
Status = XPm_SetMaxLatency(SubsystemId, Pload[0],
Pload[1]);
break;
case PM_GET_NODE_STATUS:
Status = XPm_GetDeviceStatus(SubsystemId, Pload[0], (XPm_DeviceStatus *)ApiResponse);
break;
case PM_QUERY_DATA:
Status = XPm_Query(Pload[0], Pload[1], Pload[2],
Pload[3], ApiResponse);
break;
case PM_RESET_ASSERT:
Status = XPm_SetResetState(SubsystemId, Cmd->IpiMask,
Pload[0], Pload[1]);
break;
case PM_RESET_GET_STATUS:
Status = XPm_GetResetState(Pload[0], ApiResponse);
break;
case PM_ADD_SUBSYSTEM:
Status = XPm_AddSubsystem(Pload[0]);
break;
case PM_DESTROY_SUBSYSTEM:
Status = XPm_DestroySubsystem(Pload[0]);
break;
case PM_PINCTRL_REQUEST:
Status = XPm_PinCtrlRequest(SubsystemId, Pload[0]);
break;
case PM_PINCTRL_RELEASE:
Status = XPm_PinCtrlRelease(SubsystemId, Pload[0]);
break;
case PM_PINCTRL_GET_FUNCTION:
Status = XPm_GetPinFunction(Pload[0], ApiResponse);
break;
case PM_PINCTRL_SET_FUNCTION:
Status = XPm_SetPinFunction(SubsystemId, Pload[0], Pload[1]);
break;
case PM_PINCTRL_CONFIG_PARAM_GET:
Status = XPm_GetPinParameter(Pload[0], Pload[1], ApiResponse);
break;
case PM_PINCTRL_CONFIG_PARAM_SET:
Status = XPm_SetPinParameter(SubsystemId, Pload[0], Pload[1], Pload[2]);
break;
case PM_IOCTL:
Status = XPm_DevIoctl(SubsystemId, Pload[0], (pm_ioctl_id) Pload[1],
Pload[2], Pload[3], ApiResponse);
break;
case PM_INIT_FINALIZE:
Status = XPm_InitFinalize(SubsystemId);
break;
case PM_DESCRIBE_NODES:
Status = XPm_DescribeNodes(Len);
break;
case PM_ADD_NODE:
Status = XPm_AddNode(&Pload[0], Len);
break;
case PM_ADD_NODE_PARENT:
Status = XPm_AddNodeParent(&Pload[0], Len);
break;
case PM_ADD_NODE_NAME:
Status = XPm_AddNodeName(&Pload[0], Len);
break;
case PM_ADD_REQUIREMENT:
Status = XPm_AddRequirement(Pload[0], Pload[1], Pload[2], &Pload[3], Len-3U);
break;
case PM_SET_CURRENT_SUBSYSTEM:
Status = XPm_SetCurrentSubsystem(Pload[0]);
break;
case PM_INIT_NODE:
Status = XPm_InitNode(Pload[0], Pload[1], &Pload[2], Len-2U);
break;
case PM_FEATURE_CHECK:
Status = XPm_FeatureCheck(Pload[0], ApiResponse);
break;
case PM_ISO_CONTROL:
Status = XPm_IsoControl(Pload[0], Pload[1]);
break;
case PM_GET_OP_CHARACTERISTIC:
Status = XPm_GetOpCharacteristic(Pload[0], Pload[1],
ApiResponse);
break;
case PM_REGISTER_NOTIFIER:
Status = XPm_RegisterNotifier(SubsystemId, Pload[0],
Pload[1], Pload[2],
Pload[3], Cmd->IpiMask);
break;
case PM_ACTIVATE_SUBSYSTEM:
Status = XPm_ActivateSubsystem(SubsystemId, Cmd->IpiMask,
Pload[0]);
break;
default:
PmErr("CMD: INVALID PARAM\r\n");
Status = XST_INVALID_PARAM;
break;
}
if (XST_SUCCESS == Status) {
Cmd->ResumeHandler = NULL;
} else {
PmErr("Error 0x%x while processing command 0x%x\r\n", Status, Cmd->CmdId);
PmDbg("Command payload: 0x%x, 0x%x, 0x%x, 0x%x\r\n",
Pload[0], Pload[1], Pload[2], Pload[3]);
}
/* First word of the response is status */
Cmd->Response[0] = (u32)Status;
Status = Xil_SecureMemCpy(&Cmd->Response[1], sizeof(ApiResponse),
ApiResponse, sizeof(ApiResponse));
if (XST_SUCCESS != Status) {
PmErr("Error 0x%x while copying the Cmd 0x%x return payload\r\n", Status, Cmd->CmdId);
goto done;
}
/* Restore the CmdHandler status */
Status = (int)Cmd->Response[0];
done:
if (XST_SUCCESS != Status) {
PmErr("Err Code: 0x%x\r\n", Status);
}
return Status;
}
/*****************************************************************************/
/**
* @brief This is the handler for wake up interrupts
*
* @param DeviceIdx Index of peripheral device
*
* @return Status XST_SUCCESS if processor wake successfully
* XST_FAILURE or error code in case of failure
*
*****************************************************************************/
static int XPm_DispatchWakeHandler(void *DeviceIdx)
{
int Status;
Status = XPm_GicProxyWakeUp((u32)DeviceIdx);
return Status;
}
/****************************************************************************/
/**
* @brief Register wakeup handlers with XilPlmi
* @param none
* @return none
****************************************************************************/
static void XPm_RegisterWakeUpHandlers(void)
{
/**
* Register the events for PM
*/
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP0, (u32)XPLMI_GICP0_SRC13, XPM_NODEIDX_DEV_GPIO);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP0, (u32)XPLMI_GICP0_SRC14, XPM_NODEIDX_DEV_I2C_0);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP0, (u32)XPLMI_GICP0_SRC15, XPM_NODEIDX_DEV_I2C_1);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP0, (u32)XPLMI_GICP0_SRC16, XPM_NODEIDX_DEV_SPI_0);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP0, (u32)XPLMI_GICP0_SRC17, XPM_NODEIDX_DEV_SPI_1);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP0, (u32)XPLMI_GICP0_SRC18, XPM_NODEIDX_DEV_UART_0);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP0, (u32)XPLMI_GICP0_SRC19, XPM_NODEIDX_DEV_UART_1);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP0, (u32)XPLMI_GICP0_SRC20, XPM_NODEIDX_DEV_CAN_FD_0);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP0, (u32)XPLMI_GICP0_SRC21, XPM_NODEIDX_DEV_CAN_FD_1);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP0, (u32)XPLMI_GICP0_SRC22, XPM_NODEIDX_DEV_USB_0);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP0, (u32)XPLMI_GICP0_SRC23, XPM_NODEIDX_DEV_USB_0);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP0, (u32)XPLMI_GICP0_SRC24, XPM_NODEIDX_DEV_USB_0);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP0, (u32)XPLMI_GICP0_SRC25, XPM_NODEIDX_DEV_USB_0);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP0, (u32)XPLMI_GICP0_SRC26, XPM_NODEIDX_DEV_USB_0);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP1, (u32)XPLMI_GICP1_SRC5, XPM_NODEIDX_DEV_TTC_0);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP1, (u32)XPLMI_GICP1_SRC6, XPM_NODEIDX_DEV_TTC_0);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP1, (u32)XPLMI_GICP1_SRC7, XPM_NODEIDX_DEV_TTC_0);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP1, (u32)XPLMI_GICP1_SRC8, XPM_NODEIDX_DEV_TTC_1);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP1, (u32)XPLMI_GICP1_SRC9, XPM_NODEIDX_DEV_TTC_1);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP1, (u32)XPLMI_GICP1_SRC10, XPM_NODEIDX_DEV_TTC_1);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP1, (u32)XPLMI_GICP1_SRC11, XPM_NODEIDX_DEV_TTC_2);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP1, (u32)XPLMI_GICP1_SRC12, XPM_NODEIDX_DEV_TTC_2);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP1, (u32)XPLMI_GICP1_SRC13, XPM_NODEIDX_DEV_TTC_2);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP1, (u32)XPLMI_GICP1_SRC14, XPM_NODEIDX_DEV_TTC_3);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP1, (u32)XPLMI_GICP1_SRC15, XPM_NODEIDX_DEV_TTC_3);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP1, (u32)XPLMI_GICP1_SRC16, XPM_NODEIDX_DEV_TTC_3);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP1, (u32)XPLMI_GICP1_SRC24, XPM_NODEIDX_DEV_GEM_0);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP1, (u32)XPLMI_GICP1_SRC25, XPM_NODEIDX_DEV_GEM_0);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP1, (u32)XPLMI_GICP1_SRC26, XPM_NODEIDX_DEV_GEM_1);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP1, (u32)XPLMI_GICP1_SRC27, XPM_NODEIDX_DEV_GEM_1);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP1, (u32)XPLMI_GICP1_SRC28, XPM_NODEIDX_DEV_ADMA_0);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP1, (u32)XPLMI_GICP1_SRC29, XPM_NODEIDX_DEV_ADMA_1);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP1, (u32)XPLMI_GICP1_SRC30, XPM_NODEIDX_DEV_ADMA_2);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP1, (u32)XPLMI_GICP1_SRC31, XPM_NODEIDX_DEV_ADMA_3);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP2, (u32)XPLMI_GICP2_SRC0, XPM_NODEIDX_DEV_ADMA_4);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP2, (u32)XPLMI_GICP2_SRC1, XPM_NODEIDX_DEV_ADMA_5);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP2, (u32)XPLMI_GICP2_SRC2, XPM_NODEIDX_DEV_ADMA_6);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP2, (u32)XPLMI_GICP2_SRC3, XPM_NODEIDX_DEV_ADMA_7);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP2, (u32)XPLMI_GICP2_SRC10, XPM_NODEIDX_DEV_USB_0);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP3, (u32)XPLMI_GICP3_SRC30, XPM_NODEIDX_DEV_SDIO_0);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP3, (u32)XPLMI_GICP3_SRC31, XPM_NODEIDX_DEV_SDIO_0);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP4, (u32)XPLMI_GICP4_SRC0, XPM_NODEIDX_DEV_SDIO_1);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP4, (u32)XPLMI_GICP4_SRC1, XPM_NODEIDX_DEV_SDIO_1);
XPm_RegisterWakeUpHandler((u32)XPLMI_PMC_GIC_IRQ_GICP4, (u32)XPLMI_GICP4_SRC14, XPM_NODEIDX_DEV_RTC);
}
static void XPm_CheckLastResetReason(void)
{
u32 CurrResetReason;
u32 PreviousSysResetReason;
u32 LatestSysReset;
u32 SysRstReason;
u32 RegVal;
PmIn32(CRP_RESET_REASON, CurrResetReason);
/* Read previous system reset reason stored in PGGS2 BIT[3:0] */
PmIn32(PGGS_BASEADDR + 0x8U, RegVal);
PreviousSysResetReason = (RegVal << 7U) & CRP_RESET_REASON_SYS_RESET_MASK;
SysRstReason = CurrResetReason & CRP_RESET_REASON_SYS_RESET_MASK;
/* No need to do anything is same system reset occurs back to back */
if (CurrResetReason == PreviousSysResetReason) {
ResetReason = CurrResetReason;
return;
}
LatestSysReset = SysRstReason & ~PreviousSysResetReason;
/*
* Clear all reset reasons, except the latest sys reset reason.
* The reset reason can not be completely cleared since ROM need
* to know if last reset was due to sys reset or not.
* Clear all POR and all sys resets except the latest so
* next reset reason can be uniquely identified.
*/
PmOut32(CRP_RESET_REASON, CurrResetReason & ~LatestSysReset);
/* Store latest system reset reason in PGGS2 BIT[3:0] */
PmRmw32(PGGS_BASEADDR + 0x8U, 0xFU, (LatestSysReset >> 7U));
/* Mast out previous system reset reason. */
ResetReason = CurrResetReason & ~PreviousSysResetReason;
return;
}
/****************************************************************************/
/**
* @brief Initialize XilPM library
*
* @param IpiInst IPI instance
* @param RequestCb Pointer to the request calbback handler
*
* @return XST_SUCCESS if successful else XST_FAILURE or an error code
* or a reason code
*
* @note None
*
****************************************************************************/
XStatus XPm_Init(void (*const RequestCb)(const u32 SubsystemId, const XPmApiCbId_t EventId, u32 *Payload),
int (*const RestartCb)(u32 ImageId, u32 *FuncId))
{
XStatus Status = XST_FAILURE;
unsigned int i;
u32 Platform = 0;
u32 PlatformVersion = 0;
u32 PmcIPORMask = (CRP_RESET_REASON_ERR_POR_MASK |
CRP_RESET_REASON_SLR_POR_MASK |
CRP_RESET_REASON_SW_POR_MASK);
u32 SysResetMask = (CRP_RESET_REASON_SLR_SYS_MASK |
CRP_RESET_REASON_SW_SYS_MASK |
CRP_RESET_REASON_ERR_SYS_MASK |
CRP_RESET_REASON_DAP_SYS_MASK);
u32 IsolationIdx[] = {
(u32)XPM_NODEIDX_ISO_VCCAUX_VCCRAM,
(u32)XPM_NODEIDX_ISO_VCCRAM_SOC,
(u32)XPM_NODEIDX_ISO_VCCAUX_SOC,
(u32)XPM_NODEIDX_ISO_PL_SOC,
(u32)XPM_NODEIDX_ISO_PMC_SOC,
(u32)XPM_NODEIDX_ISO_PMC_SOC_NPI,
(u32)XPM_NODEIDX_ISO_PMC_PL,
(u32)XPM_NODEIDX_ISO_PMC_LPD,
(u32)XPM_NODEIDX_ISO_LPD_SOC,
(u32)XPM_NODEIDX_ISO_LPD_PL,
(u32)XPM_NODEIDX_ISO_LPD_CPM,
(u32)XPM_NODEIDX_ISO_FPD_SOC,
(u32)XPM_NODEIDX_ISO_FPD_PL,
};
PmInfo("Initializing LibPM\n\r");
PmRequestCb = RequestCb;
/* Register command handlers with eFSBL */
for (i = 1; i < XPlmi_Pm.CmdCnt; i++) {
XPlmi_PmCmds[i].Handler = XPm_ProcessCmd;
}
XPlmi_ModuleRegister(&XPlmi_Pm);
XPm_PsmModuleInit();
PlatformVersion = XPm_GetPlatformVersion();
Platform = XPm_GetPlatform();
/* Check last reset reason */
XPm_CheckLastResetReason();
if (0U != (ResetReason & SysResetMask)) {
/* Enable domain isolations after system reset */
for (i = 0; i < ARRAY_SIZE(IsolationIdx); i++) {
Status = XPmDomainIso_Control(IsolationIdx[i], TRUE_VALUE);
if (Status != XST_SUCCESS) {
goto done;
}
}
/* For some boards, vccaux workaround is implemented using gpio to control vccram supply.
During system reset, when gpio goes low, delay is required for system controller to process
vccram rail off, before pdi load is started */
if ((PLATFORM_VERSION_SILICON == Platform) && (PLATFORM_VERSION_SILICON_ES1 == PlatformVersion)) {
usleep(300000);
}
}
/*
* Clear DomainInitStatusReg in case of internal PMC_POR. Since PGGS0
* value is not cleared in case of internal POR.
*/
if (0U != (ResetReason & PmcIPORMask)) {
XPm_Out32(XPM_DOMAIN_INIT_STATUS_REG, 0);
}
XPm_RegisterWakeUpHandlers();
Status = XPmSubsystem_Add(PM_SUBSYS_PMC);
PmRestartCb = RestartCb;
done:
return Status;
}
static void PostTopologyHook(void)
{
/* TODO: Remove this when PL topology handling is added */
/* Set all PL clock as read only so that Linux won't disable those */
XPmClock_SetPlClockAsReadOnly();
}
XStatus XPm_HookAfterPlmCdo(void)
{
XStatus Status = XST_FAILURE;
u32 PlatformVersion;
u32 SysmonAddr;
/*
* There is a silicon problem where on 2-4% of Versal ES1 XCVC1902 devices
* you can get 12A of VCCINT_PL current before CFI housecleaning is run.
* The problem is eliminated when PL Vgg frame housecleaning is run
* so we need to do that ASAP after PLM is loaded.
* Otherwise also, PL housecleaning needs to be trigerred asap to reduce
* boot time.
*/
(void)XPmPlDomain_InitandHouseclean();
/* On Boot, Update PMC SAT0 & SAT1 sysmon trim */
SysmonAddr = XPm_GetSysmonByIndex((u32)XPM_NODEIDX_MONITOR_SYSMON_PMC_0);
if (0U == SysmonAddr) {
Status = XST_DEVICE_NOT_FOUND;
goto done;
}
(void)XPmPowerDomain_ApplyAmsTrim(SysmonAddr, PM_POWER_PMC, 0);
SysmonAddr = XPm_GetSysmonByIndex((u32)XPM_NODEIDX_MONITOR_SYSMON_PMC_1);
if (0U == SysmonAddr) {
Status = XST_DEVICE_NOT_FOUND;
goto done;
}
(void)XPmPowerDomain_ApplyAmsTrim(SysmonAddr, PM_POWER_PMC, 1);
PostTopologyHook();
/**
* VCK190/VMK180 boards have VCC_AUX workaround where MIO-37 (PMC GPIO)
* is used to enable the VCC_RAM which used to power the PL.
* As a result, if PMC GPIO is disabled, VCC_RAM goes off.
* To prevent this from happening, request PMC GPIO device on behalf PMC subsystem.
* This will take care of the use cases where PMC is up.
* GPIO will get reset only when PMC goes down.
*
* The VCC_AUX workaround will be removed from MIO-37 in future.
*/
PlatformVersion = XPm_GetPlatformVersion();
if ((PLATFORM_VERSION_SILICON == XPm_GetPlatform() &&
(((u32)PLATFORM_VERSION_SILICON_ES1 == PlatformVersion) ||
((u32)PLATFORM_VERSION_SILICON_ES2 == PlatformVersion)))) {
Status = XPmDevice_Request(PM_SUBSYS_PMC, PM_DEV_GPIO_PMC,
XPM_MAX_CAPABILITY, XPM_MAX_QOS);
if (XST_SUCCESS != Status) {
goto done;
}
}
Status = XST_SUCCESS;
done:
return Status;
}
/****************************************************************************/
/**
* @brief This function is used to request the version and ID code of a chip
*
* @param IDCode Returns the chip ID code.
* @param Version Returns the chip version.
*
* @return XST_SUCCESS
*
* @note None
*
****************************************************************************/
int XPm_GetChipID(u32* IDCode, u32 *Version)
{
/* Read the chip ID code */
PmIn32(PMC_TAP_IDCODE, *IDCode);
/* Read the chip version */
PmIn32(PMC_TAP_VERSION, *Version);
return XST_SUCCESS;
}
/****************************************************************************/
/**
* @brief This function is used to request the version number of the API
* running on the power management controller.
*
* @param Version Returns the API 32-bit version number.
* Returns 0 if no firmware present.
*
* @return XST_SUCCESS if successful else XST_FAILURE or an error code
* or a reason code
*
* @note None
*
****************************************************************************/
XStatus XPm_GetApiVersion(u32 *Version)
{
*Version = PM_VERSION;
return XST_SUCCESS;
}
/****************************************************************************/
/**
* @brief This function configures the
* platform resources for the new subsystem.
*
* @param SubSystemCdo Pointer to the subsystem CDO
* @param NotifyCb Pointer to the notify callback handler
* @param SubsystemId Address to store the new subsystem ID
*
* @return XST_SUCCESS if successful else XST_FAILURE or an error code
* or a reason code
*
* @note The provided address must be in an address space which is
* accessible by the callee. There will be no change if the subsystem CDO
* is incompatible or if the required resources are not available, so no
* clean-up will be necessary
*
****************************************************************************/
XStatus XPm_AddSubsystem(u32 SubsystemId)
{
XStatus Status = XST_FAILURE;
Status = XPmSubsystem_Add(SubsystemId);
if (Status != XST_SUCCESS) {
PmErr("Failed to configure platform resources\n\r");
}
return Status;
}
/****************************************************************************/
/**
* @brief This function allows to set current subsystem id.
*
* @param SubsystemId Address to store the new subsystem ID
*
* @return XST_SUCCESS if successful else XST_FAILURE or an error code
* or a reason code
*
* @note none
*
****************************************************************************/
XStatus XPm_SetCurrentSubsystem(u32 SubsystemId)
{
XStatus Status = XST_FAILURE;
Status = XPmSubsystem_SetCurrent(SubsystemId);
if (Status != XST_SUCCESS) {
PmErr("Unable to set current subsystem. Returned: 0x%x\n\r", Status);
}
return Status;
}
static XStatus PwrDomainInitNode(u32 NodeId, u32 Function, u32 *Args, u32 NumArgs)
{
XStatus Status = XST_FAILURE;
XPm_PowerDomain *PwrDomainNode;
PwrDomainNode = (XPm_PowerDomain *)XPmPower_GetById(NodeId);
if (NULL == PwrDomainNode) {
PmErr("Unable to find Power Domain for given Node Id\n\r");
Status = XPM_PM_INVALID_NODE;
goto done;
}
switch (NODEINDEX(NodeId)) {
case (u32)XPM_NODEIDX_POWER_PMC:
case (u32)XPM_NODEIDX_POWER_LPD:
case (u32)XPM_NODEIDX_POWER_FPD:
case (u32)XPM_NODEIDX_POWER_NOC:
case (u32)XPM_NODEIDX_POWER_PLD:
case (u32)XPM_NODEIDX_POWER_ME:
case (u32)XPM_NODEIDX_POWER_CPM:
case (u32)XPM_NODEIDX_POWER_CPM5:
Status = XPmPowerDomain_InitDomain(PwrDomainNode, Function,
Args, NumArgs);
break;
default:
Status = XPM_INVALID_PWRDOMAIN;
PmErr("Unrecognized Power Domain: 0x%x\n\r", NODEINDEX(NodeId));
break;
}
/*
* Call LPD init to initialize required components
*/
if ((NODEINDEX(NodeId) == (u32)XPM_NODEIDX_POWER_LPD) &&
(Function == (u32)FUNC_INIT_FINISH) &&
(XST_SUCCESS == Status)) {
#ifdef DEBUG_UART_PS
/**
* PLM needs to request UART if debug is enabled, else LibPM
* will turn it off when it is not used by other processor.
* During such scenario when PLM tries to print debug message,
* system may not work properly.
*/
Status = XPm_RequestDevice(PM_SUBSYS_PMC, NODE_UART,
(u32)PM_CAP_ACCESS, XPM_MAX_QOS, 0);
if (XST_SUCCESS != Status) {
goto done;
}
#endif
/**
* PLM needs to request PMC IPI, else LibPM will reset IPI
* when it is not used by other processor. Because of that PLM
* hangs when it tires to communicate through IPI.
*/
Status = XPm_RequestDevice(PM_SUBSYS_PMC, PM_DEV_IPI_PMC,
(u32)PM_CAP_ACCESS, XPM_MAX_QOS, 0);
if (XST_SUCCESS != Status) {
PmErr("Error %d in request IPI PMC\r\n", Status);
}
XPlmi_LpdInit();
}
done:
if (Status != XST_SUCCESS) {
PmErr("Unable to initialize node for NodeId: 0x%x Function: 0x%x \
Returned: 0x%x\n\r", NodeId, Function, Status);
}
return Status;
}
static XStatus PldInitNode(u32 NodeId, u32 Function, u32 *Args, u32 NumArgs)
{
XStatus Status = XST_FAILURE;
u16 DbgErr = XPM_INT_ERR_UNDEFINED;
XPm_PlDevice *PlDevice = NULL;
PlDevice = (XPm_PlDevice *)XPmDevice_GetById(NodeId);
if (NULL == PlDevice) {
DbgErr = XPM_INT_ERR_INVALID_NODE;
goto done;
}
if (NULL == PlDevice->Ops) {
DbgErr = XPM_INT_ERR_NO_FEATURE;
goto done;
}
switch (Function) {
case (u32)FUNC_INIT_START:
if (NULL == PlDevice->Ops->InitStart) {
DbgErr = XPM_INT_ERR_NO_FEATURE;
goto done;
}
Status = PlDevice->Ops->InitStart(PlDevice, Args, NumArgs);
break;
case (u32)FUNC_INIT_FINISH:
if (NULL == PlDevice->Ops->InitFinish) {
DbgErr = XPM_INT_ERR_NO_FEATURE;
goto done;
}
Status = PlDevice->Ops->InitFinish(PlDevice, Args, NumArgs);
break;
default:
DbgErr = XPM_INT_ERR_INVALID_FUNC;
break;
}
done:
XPm_PrintDbgErr(Status, DbgErr);
return Status;
}
/****************************************************************************/
/**
* @brief This function allows to initialize the node.
*
* @param NodeId Supported power domain nodes only
* @param Function Function id
* @param Args Arguments speicifc to function
* @param NumArgs Number of arguments
*
* @return XST_SUCCESS if successful else XST_FAILURE or an error code
* or a reason code
*
* @note none
*
****************************************************************************/
XStatus XPm_InitNode(u32 NodeId, u32 Function, u32 *Args, u32 NumArgs)
{
XStatus Status = XST_FAILURE;
u16 DbgErr = XPM_INT_ERR_UNDEFINED;
if (((u32)XPM_NODECLASS_POWER == NODECLASS(NodeId)) &&
((u32)XPM_NODESUBCL_POWER_DOMAIN == NODESUBCLASS(NodeId)) &&
((u32)XPM_NODEIDX_POWER_MAX > NODEINDEX(NodeId))) {
Status = PwrDomainInitNode(NodeId, Function, Args, NumArgs);
} else if (((u32)XPM_NODECLASS_DEVICE == NODECLASS(NodeId)) &&
((u32)XPM_NODESUBCL_DEV_PL == NODESUBCLASS(NodeId)) &&
((u32)XPM_NODEIDX_DEV_PLD_MAX > NODEINDEX(NodeId))) {
Status = PldInitNode(NodeId, Function, Args, NumArgs);
} else {
Status = XPM_PM_INVALID_NODE;
DbgErr = XPM_INT_ERR_PLDEVICE_INITNODE;
}
XPm_PrintDbgErr(Status, DbgErr);
return Status;
}
/****************************************************************************/
/**
* @brief This function allows to control isolation nodes.
*
* @param Isoaltion NodeId Supported isoaltion nodes only
* @param Enable/Disable
*
* @return XST_SUCCESS if successful else XST_FAILURE or an error code
* or a reason code
*
* @note none
*
****************************************************************************/
XStatus XPm_IsoControl(u32 NodeId, u32 Enable)
{
XStatus Status = XST_FAILURE;
if (((u32)XPM_NODECLASS_ISOLATION != NODECLASS(NodeId)) ||
((u32)XPM_NODEIDX_ISO_MAX <= NODEINDEX(NodeId))) {
Status = XPM_PM_INVALID_NODE;
goto done;
}
Status = XPmDomainIso_Control(NODEINDEX(NodeId), Enable);
done:
if (Status != XST_SUCCESS) {
PmErr("Unable to initialize node. Returned: 0x%x\n\r", Status);
}
return Status;
}
/****************************************************************************/
/**
* @brief This function releases all the resources of a subsystem. The
* subsystem ID will become invalid.
*
* @param SubsystemId Subsystem ID
*
* @return XST_SUCCESS if successful else XST_FAILURE or an error code
* or a reason code