summaryrefslogtreecommitdiffstats
path: root/src/usr/util/utilmbox_scratch.C
blob: ff0b44589e313d7b8b01361fee2c56806256f299 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/util/utilmbox_scratch.C $                             */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,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                                                     */
/**
 * @file utilmem.C
 *
 * @brief   Stream manipulation
 *
 * Used for creating and manipulating streams
 */

/*****************************************************************************/
// I n c l u d e s
/*****************************************************************************/
#include <limits.h>
#include <util/util_reasoncodes.H>
#include <errl/errlentry.H>
#include <errl/errlmanager.H>
#include <devicefw/userif.H>
#include <sys/task.h>
#include <sys/misc.h>
#include <util/utilmbox_scratch.H>
#include <p9_frequency_buckets.H>

#include "utilbase.H"

using namespace ERRORLOG;

namespace Util
{

    // ----------------------------------------------
    // Globals
    // ----------------------------------------------
    mutex_t g_mutex = MUTEX_INITIALIZER;


    uint32_t readScratchReg(uint64_t i_addr)
    {
        size_t l_size = sizeof(uint64_t);
        uint64_t l_value = 0;

        errlHndl_t l_errl =
          deviceRead(TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
                     &l_value, l_size,
                     DEVICE_SCOM_ADDRESS(i_addr));

        if (l_errl)
        {
            errlCommit(l_errl, UTIL_COMP_ID);
        }

        return static_cast<uint32_t>(l_value >> 32);
    }

    void writeScratchReg(uint64_t i_addr, uint32_t i_data)
    {
        size_t l_size = sizeof(uint64_t);
        uint64_t l_value = static_cast<uint64_t>(i_data);
        l_value <<= 32; //data is in top half of scom reg

        errlHndl_t l_errl =
          deviceWrite(TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
                     &i_data, l_size,
                     DEVICE_SCOM_ADDRESS(i_addr));

        if (l_errl)
        {
            errlCommit(l_errl, UTIL_COMP_ID);
        }
    }

    void writeDebugCommRegs(uint8_t i_usage, uint32_t i_addr, uint32_t i_size)
    {
        //convert input into uint64_t for scom write
        uint64_t l_hrmorVal  =   cpu_spr_value(CPU_SPR_HRMOR);
        uint64_t l_bufAddr = i_addr | l_hrmorVal; //OR in HRMOR for RA
        uint64_t l_bufSize = (i_size & MSG_DATA_SIZE_MASK) |
                             (i_usage << MSG_USAGE_SHIFT);

        //Lock to prevent concurrent access
        mutex_lock(&g_mutex);


        //Write out the data to be xferred to debug tool
        writeScratchReg(INITSERVICE::SPLESS::MBOX_SCRATCH_REG1, l_bufAddr);
        writeScratchReg(INITSERVICE::SPLESS::MBOX_SCRATCH_REG2, l_bufSize);

        //wait paitently until tool has gotten the data
        //tool will zero addr when ready to continue
        while(0 != readScratchReg(INITSERVICE::SPLESS::MBOX_SCRATCH_REG1))
        {
            task_yield();
        }

        //Release lock
        mutex_unlock(&g_mutex);
    }

    uint32_t getBootNestFreq()
    {
        uint32_t l_bootNestFreq;
        INITSERVICE::SPLESS::MboxScratch4_t l_scratch4;

        TARGETING::Target * l_sys = nullptr;
        (void) TARGETING::targetService().getTopLevelTarget( l_sys );
        assert( l_sys, "getBootNestFreq() system target is NULL");

        TARGETING::ATTR_MASTER_MBOX_SCRATCH_type l_scratchRegs;
        assert(l_sys->tryGetAttr
               <TARGETING::ATTR_MASTER_MBOX_SCRATCH>(l_scratchRegs),
               "getBootNestFreq() failed to get MASTER_MBOX_SCRATCH");
        l_scratch4.data32 = l_scratchRegs[INITSERVICE::SPLESS::SCRATCH_4];

        size_t sizeOfPll = sizeof(NEST_PLL_FREQ_LIST)/
          sizeof(NEST_PLL_FREQ_LIST[0]);

        assert((uint8_t)(l_scratch4.nestPllBucket-1) < (uint8_t) sizeOfPll );

        // The nest PLL bucket IDs are numbered 1 - 5. Subtract 1 to
        // take zero-based indexing into account.
        l_bootNestFreq = NEST_PLL_FREQ_LIST[l_scratch4.nestPllBucket-1];

        UTIL_FT("getBootNestFreq::The boot frequency was %d: Bucket Id = %d",
                l_bootNestFreq,
                l_scratch4.nestPllBucket );

        return l_bootNestFreq;
    }


};
OpenPOWER on IntegriCloud