summaryrefslogtreecommitdiffstats
path: root/src/usr/secureboot/base/purge.C
blob: af21a7b02f81129e707096a3be10627cc4311fd3 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/secureboot/base/purge.C $                             */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2013                   */
/*                                                                        */
/* p1                                                                     */
/*                                                                        */
/* Object Code Only (OCO) source materials                                */
/* Licensed Internal Code Source Materials                                */
/* IBM HostBoot Licensed Internal Code                                    */
/*                                                                        */
/* The source code for this program is not published or otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* Origin: 30                                                             */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
#include <stdint.h>
#include <sys/task.h>
#include <sys/time.h>
#include <devicefw/userif.H>
#include <secureboot/secure_reasoncodes.H>

#include "purge.H"

namespace SECUREBOOT
{
    errlHndl_t issueBlindPurge()
    {
        static const uint64_t PURGE_REG = 0x1001080e;

            // Bits : Value
            // 0    : 0b1 = Initiate Purge
            // 1:4  : 0b0100 = Full Blind Purge
            // 13:28 : 0x1000 = CGC is (512k / 128 byte line size)
            //          CGC means "Congruence Class", ie. cache row.
        static const uint64_t PURGE_VALUE = 0xa000800000000000;

            // Bit 0 - Purge Pending.
        static const uint64_t PURGE_PENDING = 0x8000000000000000;

        static const size_t RETRY_COUNT = 100;
        static const size_t RETRY_WAIT_NS = ONE_CTX_SWITCH_NS;

        errlHndl_t l_errl = NULL;
        do
        {
            size_t coreId = (task_getcpuid() / 8) & 0xF;
            uint64_t regAddr = PURGE_REG + 0x01000000 * coreId;

            uint64_t data = 0;
            size_t size = sizeof(data);

            // Read purge register to ensure no operation is pending.
            l_errl =
                deviceRead(TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
                           &data, size,
                           DEVICE_SCOM_ADDRESS(regAddr));
            if (l_errl)
            {
                break;
            }

            if (data & PURGE_PENDING)
            {
                /*@
                 * @errortype
                 * @moduleid    SECUREBOOT::MOD_SECURE_BLINDPURGE
                 * @reasoncode  SECUREBOOT::RC_PURGEOP_PENDING
                 * @userdata1   SCOM value.
                 * @userdata2   CPU ID (PIR) encountering failure.
                 * @devdesc     Attemped to purge cache while purge operation
                 *              was pending.
                 */
                l_errl =
                    new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                            MOD_SECURE_BLINDPURGE,
                                            RC_PURGEOP_PENDING,
                                            data, task_getcpuid());
                break;
            }

            // Initiate purge operation
            data = PURGE_VALUE;
            l_errl =
                deviceWrite(TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
                            &data, size,
                            DEVICE_SCOM_ADDRESS(regAddr));
            if (l_errl)
            {
                break;
            }

            // Wait for purge to complete.
            for(size_t i = 0; i < RETRY_COUNT; i++)
            {
                l_errl =
                    deviceRead(TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
                               &data, size,
                               DEVICE_SCOM_ADDRESS(regAddr));

                if ((l_errl) || !(data & PURGE_PENDING))
                {
                    break;
                }

                nanosleep(0, RETRY_WAIT_NS);
            }
            if (l_errl)
            {
                break;
            }
            if (data & PURGE_PENDING) // Ensure op did complete.
            {
                /*@
                 * @errortype
                 * @moduleid    SECUREBOOT::MOD_SECURE_BLINDPURGE
                 * @reasoncode  SECUREBOOT::RC_PURGEOP_FAIL_COMPLETE
                 * @userdata1   SCOM value.
                 * @devdesc     Purge operation never completed.
                 */
                l_errl =
                    new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                            MOD_SECURE_BLINDPURGE,
                                            RC_PURGEOP_FAIL_COMPLETE,
                                            data);
                break;
            }

        } while(0);

        return l_errl;
    }

}
OpenPOWER on IntegriCloud