summaryrefslogtreecommitdiffstats
path: root/src/occ_405/pgpe/pgpe_interface.c
blob: e664e9d534758ebc61dadb0cee036233d65b0438 (plain)
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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/occ_405/pgpe/pgpe_interface.c $                           */
/*                                                                        */
/* OpenPOWER OnChipController Project                                     */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2011,2017                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

#include "occ_common.h"
#include "occhw_async.h"
#include "pgpe_interface.h"
#include "pstate_pgpe_occ_api.h"
#include "occ_service_codes.h"
#include "pgpe_service_codes.h"
#include "trac.h"
#include "state.h"
#include "proc_pstate.h"
#include "proc_data_control.h"
#include "occ_sys_config.h"
#include "ssx.h"
#include "wof.h"
#include "amec_sys.h"

// Maximum waiting time (usec) for clip update IPC task
#define CLIP_UPDATE_TIMEOUT 100  // maximum waiting time (usec) for clip update IPC task

extern pstateStatus G_proc_pstate_status;
extern PMCR_OWNER G_proc_pmcr_owner;

extern uint16_t G_proc_fmax_mhz;

extern bool G_simics_environment;

// IPC GPE Requests
GpeRequest G_clip_update_req;
GpeRequest G_pmcr_set_req;
GpeRequest G_start_suspend_req;
GpeRequest G_wof_control_req;
GpeRequest G_wof_vfrt_req;

// GPE parameter fields for PGPE IPC calls
GPE_BUFFER(ipcmsg_clip_update_t   G_clip_update_parms);
GPE_BUFFER(ipcmsg_set_pmcr_t      G_pmcr_set_parms);
GPE_BUFFER(ipcmsg_start_stop_t    G_start_suspend_parms);
GPE_BUFFER(ipcmsg_wof_control_t   G_wof_control_parms);
GPE_BUFFER(ipcmsg_wof_vfrt_t      G_wof_vfrt_parms);


// Function Specification
//
// Name: init_pgpe_ipcs
//
// Description: Create all PGPE IPC messages.
//
// End Function Specification
void init_pgpe_ipcs(void)
{
    errlHndl_t  err = NULL;    // Error handler

    do
    {
        err = pgpe_init_clips();
        if(err)
        {
            break;
        }
        err = pgpe_init_pmcr();
        if(err)
        {
            break;
        }
        err = pgpe_init_start_suspend();
        if(err)
        {
            break;
        }
        err = pgpe_init_wof_control();
        if(err)
        {
            break;
        }
        err = pgpe_init_wof_vfrt();
    }while(0);

    if(err)
    {
        REQUEST_RESET(err);
    }

    return;
}


// Function Specification
//
// Name: pgpe_init_clips
//
// Description: Create PGPE clip update IPC messages (non-blocking).
//
// End Function Specification
errlHndl_t pgpe_init_clips(void)
{
    int rc;                    // return code
    errlHndl_t  err = NULL;    // Error handler

    do
    {
        G_clip_update_parms.msg_cb.rc = PGPE_RC_SUCCESS;

        //Initializes the GpeRequest object for pgpe clips setting IPC
        rc = gpe_request_create(&G_clip_update_req,         // GpeRequest for the task
                                &G_async_gpe_queue2,        // Queue
                                IPC_MSGID_405_CLIPS,        // Function ID
                                &G_clip_update_parms,       // Task parameters
                                SSX_WAIT_FOREVER,           // Timeout (none)
                                NULL,                       // Callback
                                NULL,                       // Callback arguments
                                ASYNC_CALLBACK_IMMEDIATE ); // Options

        if( rc )
        {
            // If we failed to create the GpeRequest then there is a serious problem.
            MAIN_TRAC_ERR("pgpe_init_clips: Failure creating the "
                          "IPC_MSGID_405_CLIPS GpeRequest. [RC=0x%08x]", rc );

            /*
             * @errortype
             * @moduleid    PGPE_INIT_CLIPS_MOD
             * @reasoncode  GPE_REQUEST_CREATE_FAILURE
             * @userdata1   gpe_request_create return code
             * @userdata4   OCC_NO_EXTENDED_RC
             * @devdesc     Failure to create clips GpeRequest object
             */
            err = createErrl(
                PGPE_INIT_CLIPS_MOD,             //ModId
                GPE_REQUEST_CREATE_FAILURE,      //Reasoncode
                OCC_NO_EXTENDED_RC,              //Extended reason code
                ERRL_SEV_PREDICTIVE,             //Severity
                NULL,                            //Trace Buf
                DEFAULT_TRACE_SIZE,              //Trace Size
                rc,                              //Userdata1
                0                                //Userdata2
                );
        }

    } while (0);

    return(err);
}

// Function Specification
//
// Name: pgpe_init_pmcr
//
// Description: Create PGPE PMCR set IPC messages (non-blocking).
//
// End Function Specification
errlHndl_t pgpe_init_pmcr(void)
{
    int rc;                    // return code
    errlHndl_t  err = NULL;    // Error handler

    do
    {
        G_pmcr_set_parms.msg_cb.rc = PGPE_RC_SUCCESS;

        //Initializes the GpeRequest object for pgpe PMCR setting IPC
        rc = gpe_request_create(&G_pmcr_set_req,            // GpeRequest for the task
                                &G_async_gpe_queue2,        // Queue
                                IPC_MSGID_405_SET_PMCR,     // Function ID
                                &G_pmcr_set_parms,          // Task parameters
                                SSX_WAIT_FOREVER,           // Timeout (none)
                                NULL,                       // Callback
                                NULL,                       // Callback arguments
                                ASYNC_CALLBACK_IMMEDIATE);  // Options

        if( rc )
        {
            // If we failed to create the GpeRequest then there is a serious problem.
            MAIN_TRAC_ERR("pgpe_init_pmcr: Failure creating the "
                          "IPC_MSGID_405_SET_PMCR GpeRequest. [RC=0x%08x]",
                          rc );

            /*
             * @errortype
             * @moduleid    PGPE_INIT_PMCR_MOD
             * @reasoncode  GPE_REQUEST_CREATE_FAILURE
             * @userdata1   gpe_request_create return code
             * @userdata4   OCC_NO_EXTENDED_RC
             * @devdesc     Failure to create pmcr GpeRequest object
             */
            err = createErrl(
                PGPE_INIT_PMCR_MOD,              //ModId
                GPE_REQUEST_CREATE_FAILURE,      //Reasoncode
                OCC_NO_EXTENDED_RC,              //Extended reason code
                ERRL_SEV_PREDICTIVE,             //Severity
                NULL,                            //Trace Buf
                DEFAULT_TRACE_SIZE,              //Trace Size
                rc,                              //Userdata1
                0                                //Userdata2
                );
        }

    } while (0);

    return(err);
}

// Function Specification
//
// Name: pgpe_init_start_suspend
//
// Description: Create PGPE start/suspend IPC messages (blocking).
//
// End Function Specification
errlHndl_t pgpe_init_start_suspend(void)
{
    int rc;                    // return code
    errlHndl_t  err = NULL;    // Error handler

    do
    {
        //Initializes the GpeRequest object for pgpe start/suspend IPC
        rc = gpe_request_create(&G_start_suspend_req,                              // GpeRequest for the task
                                &G_async_gpe_queue2,                               // Queue
                                IPC_MSGID_405_START_SUSPEND,                       // Function ID
                                &G_start_suspend_parms,                            // Task parameters
                                SSX_WAIT_FOREVER,                                  // Timeout (none)
                                (AsyncRequestCallback)pgpe_start_suspend_callback, // Callback
                                NULL,                                              // Callback arguments
                                ASYNC_CALLBACK_IMMEDIATE );                        // Options

        if( rc )
        {
            // If we failed to create the GpeRequest then there is a serious problem.
            MAIN_TRAC_ERR("pgpe_init_start_suspend: Failure creating the "
                          "IPC_MSGID_405_START_SUSPEND GpeRequest. [RC=0x%08x]",
                          rc );

            /*
             * @errortype
             * @moduleid    PGPE_INIT_START_SUSPEND_MOD
             * @reasoncode  GPE_REQUEST_CREATE_FAILURE
             * @userdata1   gpe_request_create return code
             * @userdata4   OCC_NO_EXTENDED_RC
             * @devdesc     Failure to create start_suspend GpeRequest object
             */
            err = createErrl(
                PGPE_INIT_START_SUSPEND_MOD,     //ModId
                GPE_REQUEST_CREATE_FAILURE,      //Reasoncode
                OCC_NO_EXTENDED_RC,              //Extended reason code
                ERRL_SEV_PREDICTIVE,             //Severity
                NULL,                            //Trace Buf
                DEFAULT_TRACE_SIZE,              //Trace Size
                rc,                              //Userdata1
                0                                //Userdata2
                );
        }

    } while (0);

    return(err);
}


// Function Specification
//
// Name: pgpe_init_wof_control
//
// Description: Create PGPE WOF control IPC messages (non-blocking).
//
// End Function Specification
errlHndl_t pgpe_init_wof_control(void)
{
    int rc;                    // return code
    errlHndl_t  err = NULL;    // Error handler

    do
    {
        //Initializes the GpeRequest object for pgpe wof control IPC
        rc = gpe_request_create(&G_wof_control_req,         // GpeRequest for the task
                                &G_async_gpe_queue2,        // Queue
                                IPC_MSGID_405_WOF_CONTROL,  // Function ID
                                &G_wof_control_parms,       // Task parameters
                                SSX_WAIT_FOREVER,           // Timeout (none)
                                (AsyncRequestCallback)wof_control_callback, // Callback
                                NULL,                       // Callback arguments
                                ASYNC_CALLBACK_IMMEDIATE); // Options

        if( rc )
        {
            // If we failed to create the GpeRequest then there is a serious problem.
            MAIN_TRAC_ERR("pgpe_init_wof_control: Failure creating the "
                          "IPC_MSGID_405_WOF_CONTROL GpeRequest. [RC=0x%08x]",
                          rc );

            /*
             * @errortype
             * @moduleid    PGPE_INIT_WOF_CONTROL_MOD
             * @reasoncode  GPE_REQUEST_CREATE_FAILURE
             * @userdata1   gpe_request_create return code
             * @userdata4   OCC_NO_EXTENDED_RC
             * @devdesc     Failure to create wof control GpeRequest object
             */
            err = createErrl(
                PGPE_INIT_WOF_CONTROL_MOD,       //ModId
                GPE_REQUEST_CREATE_FAILURE,      //Reasoncode
                OCC_NO_EXTENDED_RC,              //Extended reason code
                ERRL_SEV_PREDICTIVE,             //Severity
                NULL,                            //Trace Buf
                DEFAULT_TRACE_SIZE,              //Trace Size
                rc,                              //Userdata1
                0                                //Userdata2
                );
        }

    } while (0);

    return(err);
}

// Function Specification
//
// Name: pgpe_init_wof_vfrt
//
// Description: Create PGPE WOF vfrt IPC messages (non-blocking).
//
// End Function Specification
errlHndl_t pgpe_init_wof_vfrt(void)
{
    int rc;                    // return code
    errlHndl_t  err = NULL;    // Error handler

    do
    {
        //Initializes the GpeRequest object for pgpe wof vfrt IPC
        rc = gpe_request_create(&G_wof_vfrt_req,            // GpeRequest for the task
                                &G_async_gpe_queue2,        // Queue
                                IPC_MSGID_405_WOF_VFRT,     // Function ID
                                &G_wof_vfrt_parms,          // Task parameters
                                SSX_WAIT_FOREVER,           // Timeout (none)
                                (AsyncRequestCallback)wof_vfrt_callback, // Callback
                                NULL,                       // Callback arguments
                                ASYNC_CALLBACK_IMMEDIATE);  // Options

        if( rc )
        {
            // If we failed to create the GpeRequest then there is a serious problem.
            MAIN_TRAC_ERR("pgpe_init_wof_vfrt: Failure creating the "
                          "IPC_MSGID_405_WOF_VFRT GpeRequest. [RC=0x%08x]",
                          rc );

            /*
             * @errortype
             * @moduleid    PGPE_INIT_WOF_VFRT_MOD
             * @reasoncode  GPE_REQUEST_CREATE_FAILURE
             * @userdata1   gpe_request_create return code
             * @userdata4   OCC_NO_EXTENDED_RC
             * @devdesc     Failure to create wof control GpeRequest object
             */
            err = createErrl(
                PGPE_INIT_WOF_VFRT_MOD,          //ModId
                GPE_REQUEST_CREATE_FAILURE,      //Reasoncode
                OCC_NO_EXTENDED_RC,              //Extended reason code
                ERRL_SEV_PREDICTIVE,             //Severity
                NULL,                            //Trace Buf
                DEFAULT_TRACE_SIZE,              //Trace Size
                rc,                              //Userdata1
                0                                //Userdata2
                );
        }

    } while (0);

    return(err);
}


// Function Specification
//
// Name: pgpe_set_clip_blocking
//
// Description: a blocking version of pgpe_clip_update
//              this call waits until the clip IPC task completes,
//              and verifies a successful completion.
//
// End Function Specification
int pgpe_set_clip_blocking(Pstate i_pstate)
{
    errlHndl_t   err = NULL;
    uint8_t      wait_time = 0;
    int          rc = 0;  // Return code: 0 means success, otherwise an error.

    do
    {
        // verify that the clip update IPC task is not currently running
        while( !async_request_is_idle(&G_clip_update_req.request) )
        {
            if(wait_time > CLIP_UPDATE_TIMEOUT)
            {
                // an earlier clip update IPC call has not completed, trace and log an error
                TRAC_ERR("pgpe_set_clip_blocking: clip update IPC task is not Idle");

                /*
                 * @errortype
                 * @moduleid    PGPE_SET_CLIP_BLOCKING_MOD
                 * @reasoncode  PGPE_FAILURE
                 * @userdata4   ERC_PGPE_NOT_IDLE
                 * @devdesc     pgpe clip update not idle
                 */
                err = createErrl(
                    PGPE_SET_CLIP_BLOCKING_MOD,    //ModId
                    PGPE_FAILURE,                    //Reasoncode
                    ERC_PGPE_NOT_IDLE,               //Extended reason code
                    ERRL_SEV_PREDICTIVE,             //Severity
                    NULL,                            //Trace Buf
                    DEFAULT_TRACE_SIZE,              //Trace Size
                    0,                               //Userdata1
                    0                                //Userdata2
                );

                rc = PGPE_FAILURE;
                break;
            }

            // sleep for 1 microsecond (allows context switching)
            ssx_sleep(SSX_MICROSECONDS(1));

            wait_time++;
        }

        // Previous task is finished
        if( !err )
        {
            // set the all quads to same pstate and submit the update
            memset(G_desired_pstate, i_pstate, MAXIMUM_QUADS);
            rc = pgpe_clip_update();
            if(rc)
            {
                break;
            }
        }
        else
        {
            // Previous task has still not finished
            break;
        }

        // Reset wait counter
        wait_time = 0;

        // Wait until the clip_update IPC task completes
        while( !async_request_is_idle(&G_clip_update_req.request) )
        {
            if(wait_time > CLIP_UPDATE_TIMEOUT)
            {
                TRAC_ERR("pgpe_set_clip_blocking: clip update IPC task timeout!");

                /*
                 * @errortype
                 * @moduleid    PGPE_SET_CLIP_BLOCKING_MOD
                 * @reasoncode  GPE_REQUEST_TASK_TIMEOUT
                 * @userdata4   OCC_NO_EXTENDED_RC
                 * @devdesc     pgpe clip update timeout
                 */
                err = createErrl(
                    PGPE_SET_CLIP_BLOCKING_MOD,    //ModId
                    GPE_REQUEST_TASK_TIMEOUT,        //Reasoncode
                    OCC_NO_EXTENDED_RC,              //Extended reason code
                    ERRL_SEV_PREDICTIVE,             //Severity
                    NULL,                            //Trace Buf
                    DEFAULT_TRACE_SIZE,              //Trace Size
                    0,                               //Userdata1
                    0                                //Userdata2
                    );

                rc = GPE_REQUEST_TASK_TIMEOUT;
                break;
            }

            // sleep for 1 microsecond (allows context switching)
            ssx_sleep(SSX_MICROSECONDS(1));

            wait_time++;
        }

        // clip update timed out
        if(err)
        {
            break;
        }

        // IPC task completed. check for errors
        if ( G_clip_update_parms.msg_cb.rc != PGPE_RC_SUCCESS )
        {
            // clip update IPC call has not completed, trace and log an error
            TRAC_ERR("pgpe_set_clip_blocking: clip update IPC task "
                     "returned an error [0x%08X]",
                     G_clip_update_parms.msg_cb.rc);

            /*
             * @errortype
             * @moduleid    PGPE_SET_CLIP_BLOCKING_MOD
             * @reasoncode  GPE_REQUEST_RC_FAILURE
             * @userdata1   PGPE clip update's rc
             * @userdata4   OCC_NO_EXTENDED_RC
             * @devdesc     pgpe clip update returned a failure code
             */
            err = createErrl(
                PGPE_SET_CLIP_BLOCKING_MOD,         //ModId
                GPE_REQUEST_RC_FAILURE,               //Reasoncode
                OCC_NO_EXTENDED_RC,                   //Extended reason code
                ERRL_SEV_PREDICTIVE,                  //Severity
                NULL,                                 //Trace Buf
                DEFAULT_TRACE_SIZE,                   //Trace Size
                G_clip_update_parms.msg_cb.rc,   //Userdata1
                0                                     //Userdata2
                );

            rc = GPE_REQUEST_RC_FAILURE;
        }
    } while (0);

    if(err)
    {
        REQUEST_RESET(err);
    }

    return(rc);
}


// Function Specification
//
// Name: pgpe_clip_update
//
// Description: call PGPE IPC to update clip ranges. Since this IPC call is
//              non-blocking, the calling function needs to assure previous
//              call completion before calling this call.
//
// End Function Specification
int pgpe_clip_update(void)
{
    int rc = 0;              // return code
    errlHndl_t  err = NULL;  // Error handler
    uint32_t    l_wait_time = 0;
    do
    {
        // Caller must check the completion of previous invocation of clip updates.
        // This check is a safety feature in case caller didn't check IPC is idle.
        while(!async_request_is_idle(&G_clip_update_req.request))
        {
            if(l_wait_time > CLIP_UPDATE_TIMEOUT)
            {
                // an earlier clip update IPC call has not completed, trace and log an error
                TRAC_ERR("pgpe_clip_update: clip update IPC task is not Idle");

                /*
                 * @errortype
                 * @moduleid    PGPE_CLIP_UPDATE_MOD
                 * @reasoncode  PGPE_FAILURE
                 * @userdata1   0
                 * @userdata4   ERC_PGPE_NOT_IDLE
                 * @devdesc     pgpe clip update not idle
                 */
                err = createErrl(
                    PGPE_CLIP_UPDATE_MOD,            //ModId
                    PGPE_FAILURE,                    //Reasoncode
                    ERC_PGPE_NOT_IDLE,               //Extended reason code
                    ERRL_SEV_PREDICTIVE,             //Severity
                    NULL,                            //Trace Buf
                    DEFAULT_TRACE_SIZE,              //Trace Size
                    0,                               //Userdata1
                    0                                //Userdata2
                    );

                // Callout firmware
                addCalloutToErrl(err,
                                 ERRL_CALLOUT_TYPE_COMPONENT_ID,
                                 ERRL_COMPONENT_ID_FIRMWARE,
                                 ERRL_CALLOUT_PRIORITY_HIGH);

                commitErrl(&err);

                rc = PGPE_FAILURE;
                break;
            }

            // Sleep for 1us (allows context switching)
            ssx_sleep(SSX_MICROSECONDS(1));

            l_wait_time++;
        }

        if (!G_simics_environment)
        {
            // Set clip bounds
            memset(G_clip_update_parms.ps_val_clip_min, proc_freq2pstate(g_amec->sys.fmin), MAXIMUM_QUADS);
            memcpy(G_clip_update_parms.ps_val_clip_max, G_desired_pstate, sizeof(G_desired_pstate));

            // Schedule PGPE clip update IPC task
            rc = gpe_request_schedule(&G_clip_update_req);
        }
        else
        {
            G_start_suspend_parms.msg_cb.rc = PGPE_RC_SUCCESS;
            rc = 0;
        }
        // Confirm Successfull completion of PGPE clip update task
        if(rc != 0)
        {
            //Error in scheduling pgpe clip update task
            TRAC_ERR("pgpe_clip_update: Failed to schedule clip update pgpe task rc=%x",
                     rc);

            /* @
             * @errortype
             * @moduleid    PGPE_CLIP_UPDATE_MOD
             * @reasoncode  GPE_REQUEST_SCHEDULE_FAILURE
             * @userdata1   rc - gpe_request_schedule return code
             * @userdata2   0
             * @userdata4   OCC_NO_EXTENDED_RC
             * @devdesc     OCC Failed to schedule a GPE job for clip update
             */
            err = createErrl(
                PGPE_CLIP_UPDATE_MOD,                   // modId
                GPE_REQUEST_SCHEDULE_FAILURE,           // reasoncode
                OCC_NO_EXTENDED_RC,                     // Extended reason code
                ERRL_SEV_UNRECOVERABLE,                 // Severity
                NULL,                                   // Trace Buf
                DEFAULT_TRACE_SIZE,                     // Trace Size
                rc,                                     // userdata1
                0                                       // userdata2
                );

            rc = GPE_REQUEST_SCHEDULE_FAILURE;
            REQUEST_RESET(err);   //This will add a firmware callout for us
        }
    }while(0);

    return rc;
}


// Function Specification
//
// Name: start_suspend_callback
//
// Description: callback function for the pgpe_start_suspend IPC function
//              gets called after the PGPE IPC enables/disables pstates.
//              Upon successful completion, it sets/clears the G_proc_pstate_status
//              flag to indicate whether it is enabled/disabled/in-transition.
//
// End Function Specification
void pgpe_start_suspend_callback(void)
{
    int pgpe_rc;               // pgpe return codes
    errlHndl_t  err = NULL;    // Error handler

    pgpe_rc = G_start_suspend_parms.msg_cb.rc;

    do
    {
        // Confirm Successfull completion of PGPE start suspend task
        if(pgpe_rc != PGPE_RC_SUCCESS)
        {
            //Error in scheduling pgpe start suspend task

            /* @
             * @errortype
             * @moduleid    PGPE_START_SUSPEND_CALLBACK_MOD
             * @reasoncode  GPE_REQUEST_SCHEDULE_FAILURE
             * @userdata1   pgpe_rc - PGPE return code
             * @userdata4   OCC_NO_EXTENDED_RC
             * @devdesc     OCC Failed to schedule a GPE job for start_suspend
             */
            err = createErrl(
                PGPE_START_SUSPEND_CALLBACK_MOD,        // modId
                PGPE_FAILURE,                           // reasoncode
                ERC_PGPE_UNSUCCESSFULL,                 // Extended reason code
                ERRL_SEV_UNRECOVERABLE,                 // Severity
                NULL,                                   // Trace Buf
                DEFAULT_TRACE_SIZE,                     // Trace Size
                pgpe_rc,                                // userdata1
                0                                       // userdata2
                );

            REQUEST_RESET(err);   //This will add a firmware callout for us
            break;
        }
        // task completed successfully
        else
        {
            // this was a command to enable pstates
            if(G_start_suspend_parms.action == PGPE_ACTION_PSTATE_START)
            {
                // Pstates are now enabled (enable Active State transition).
                G_proc_pstate_status = PSTATES_ENABLED;

                // upon successful pstates START, assign G_proc_pmcr_owner (OCC/CHAR/HOST)
                G_proc_pmcr_owner = G_start_suspend_parms.pmcr_owner;

                // Clear WOF Pstate status flag
                g_amec->wof.wof_disabled &= ~WOF_RC_PSTATE_PROTOCOL_OFF;
            }
            // this was a command to disable pstates
            else if(G_start_suspend_parms.action == PGPE_ACTION_PSTATE_STOP)
            {
                // Pstates are now disabled (disable Active State transition).
                G_proc_pstate_status = PSTATES_DISABLED;
            }
        }

    } while(0);

}

// Function Specification
//
// Name: pgpe_start_suspend
//
// Description: Schedule a PGPE IPC to enable/disable pstates. This will also tell
//              PGPE how to set PMCR mode register (OCC/OPAL control pstates).
//              when this IPC is successfully scheduled, it sets the G_proc_pstate_status
//              global variable to in-transition, a call back function
//              (pgpe_start_suspend_callback) will set it to the appropriate value upon
//              successfull completion.
//
// End Function Specification
int pgpe_start_suspend(uint8_t action, PMCR_OWNER owner)
{
    int rc = 0;                // return code
    errlHndl_t  err = NULL;    // Error handler

    // set the IPC parameters
    G_start_suspend_parms.action     = action;
    G_start_suspend_parms.pmcr_owner = owner;

    if (!G_simics_environment)
    {
        // Schedule PGPE start_suspend task
        rc = gpe_request_schedule(&G_start_suspend_req);
    }

    // couldn't schedule the IPC task?
    if(rc != 0)
    {
        //Error in scheduling pgpe start suspend task
        TRAC_ERR("pgpe_start_suspend: Failed to schedule pgpe start_suspend task rc=%x",
                 rc);
        /* @
         * @errortype
         * @moduleid    PGPE_START_SUSPEND_MOD
         * @reasoncode  GPE_REQUEST_SCHEDULE_FAILURE
         * @userdata1   rc - gpe_request_schedule return code
         * @userdata4   OCC_NO_EXTENDED_RC
         * @devdesc     OCC Failed to schedule a PGPE job for start_suspend
         */
        err = createErrl(
            PGPE_START_SUSPEND_MOD,                 // modId
            GPE_REQUEST_SCHEDULE_FAILURE,           // reasoncode
            OCC_NO_EXTENDED_RC,                     // Extended reason code
            ERRL_SEV_UNRECOVERABLE,                 // Severity
            NULL,                                   // Trace Buf
            DEFAULT_TRACE_SIZE,                     // Trace Size
            rc,                                     // userdata1
            0                                       // userdata2
            );

        rc = GPE_REQUEST_SCHEDULE_FAILURE;
        REQUEST_RESET(err);   //This will add a firmware callout for us
    }
    // successfully scheduled, set the G_proc_pstate_status to indicate transition
    else
    {
        G_proc_pstate_status = PSTATES_IN_TRANSITION;
    }

    if (G_simics_environment)
    {
        pgpe_start_suspend_callback();
    }

    return rc;
}


// Function Specification
//
// Name: pgpe_pmcr_set
//
// Description: call PGPE IPC to set the PMCR with the pstate values.
//              Since this IPC call is non-blocking, the calling
//              function needs to assure previous call completion
//              before calling this call.
//
// End Function Specification
int pgpe_pmcr_set(void)
{
    int rc = 0;              // return code
    errlHndl_t  err = NULL;  // Error handler

    do
    {
        // Caller must check the completion of previous invocation of pmcr set IPC call.
        // This check is a safety feature in case caller didn't check IPC is idle.
        if(!async_request_is_idle(&G_pmcr_set_req.request))
        {
            // an earlier PMCR update IPC call has not completed, trace and log an error
            TRAC_ERR("pgpe_pmcr_set: PMCR update IPC task is not Idle");

            /*
             * @errortype
             * @moduleid    PGPE_PMCR_SET_MOD
             * @reasoncode  PGPE_FAILURE
             * @userdata1   0
             * @userdata4   ERC_PGPE_NOT_IDLE
             * @devdesc     pgpe pmcr set not idle
             */
            err = createErrl(
                PGPE_PMCR_SET_MOD,               //ModId
                PGPE_FAILURE,                    //Reasoncode
                ERC_PGPE_NOT_IDLE,               //Extended reason code
                ERRL_SEV_PREDICTIVE,             //Severity
                NULL,                            //Trace Buf
                DEFAULT_TRACE_SIZE,              //Trace Size
                0,                               //Userdata1
                0                                //Userdata2
                );

            // Callout firmware
            addCalloutToErrl(err,
                             ERRL_CALLOUT_TYPE_COMPONENT_ID,
                             ERRL_COMPONENT_ID_FIRMWARE,
                             ERRL_CALLOUT_PRIORITY_HIGH);

            commitErrl(&err);

            rc = PGPE_FAILURE;
            break;
        }

        if (!G_simics_environment)
        {
            // Schedule PGPE PMCR update IPC task
            rc = gpe_request_schedule(&G_pmcr_set_req);
        }

        // Confirm Successfull completion of PGPE PMCR update task
        if(rc != 0)
        {
            //Error in scheduling pgpe PMCR update task
            TRAC_ERR("pgpe_pmcr_set: Failed to schedule PMCR setup pgpe task rc=%x",
                     rc);

            /* @
             * @errortype
             * @moduleid    PGPE_PMCR_SET_MOD
             * @reasoncode  GPE_REQUEST_SCHEDULE_FAILURE
             * @userdata1   rc - gpe_request_schedule return code
             * @userdata2   0
             * @userdata4   OCC_NO_EXTENDED_RC
             * @devdesc     OCC Failed to schedule a PGPE job for PMCR update
             */
            err = createErrl(
                PGPE_PMCR_SET_MOD,                      // modId
                GPE_REQUEST_SCHEDULE_FAILURE,           // reasoncode
                OCC_NO_EXTENDED_RC,                     // Extended reason code
                ERRL_SEV_UNRECOVERABLE,                 // Severity
                NULL,                                   // Trace Buf
                DEFAULT_TRACE_SIZE,                     // Trace Size
                rc,                                     // userdata1
                0                                       // userdata2
                );

            rc = GPE_REQUEST_SCHEDULE_FAILURE;
            REQUEST_RESET(err);   //This will add a firmware callout for us
        }
    }
    while(0);

    return rc;
}
OpenPOWER on IntegriCloud