summaryrefslogtreecommitdiffstats
path: root/src/usr/secureboot/base/purge.C
blob: 4c5793c39dcac291fa69bf9b12422a2522fbef99 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/secureboot/base/purge.C $                             */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2013,2014              */
/*                                                                        */
/* 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 <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     Attempted 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());
                // Probably a code bug
                l_errl->addProcedureCallout( HWAS::EPUB_PRC_HB_CODE,
                                             HWAS::SRCI_PRIORITY_HIGH );
                // But there might be something wrong with the chip
                //  or the SBE image
                l_errl->addHwCallout(
                          TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
                          HWAS::SRCI_PRIORITY_LOW,
                          HWAS::NO_DECONFIG,
                          HWAS::GARD_NULL );
                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 of Reg 0x1001080E
                 * @devdesc     Purge operation never completed.
                 */
                l_errl =
                    new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                            MOD_SECURE_BLINDPURGE,
                                            RC_PURGEOP_FAIL_COMPLETE,
                                            data);
                // Most likely a hardware issue of some sort
                l_errl->addHwCallout(
                          TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
                          HWAS::SRCI_PRIORITY_HIGH,
                          HWAS::NO_DECONFIG,
                          HWAS::GARD_NULL );
                // Could also be a code bug
                l_errl->addProcedureCallout( HWAS::EPUB_PRC_HB_CODE,
                                             HWAS::SRCI_PRIORITY_MED );
                break;
            }

        } while(0);

        return l_errl;
    }

}
OpenPOWER on IntegriCloud