summaryrefslogtreecommitdiffstats
path: root/src/usr/expaccess/test/exptest_utils.C
blob: 01096716fe3a3c03fcc23bc3e57e17116c5dba04 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/expaccess/test/exptest_utils.C $                      */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2019                             */
/* [+] 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 <fapi2.H>
#include <cxxtest/TestSuite.H>
#include "exptest_utils.H"

namespace exptest
{
    errlHndl_t loadModule(const char * i_modName)
    {
        errlHndl_t err = NULL;

    // VFS functions only compilable in non-runtime environment
    #ifndef __HOSTBOOT_RUNTIME
        if(!VFS::module_is_loaded(i_modName))
        {
            err = VFS::module_load(i_modName);
            if(err)
            {
                TS_FAIL("loadModule() - %s load failed", i_modName );
            }
            else
            {
                FAPI_INF("loadModule: %s loaded", i_modName);
            }
        }
    #endif
        return err;
    }

    TARGETING::HB_MUTEX_SERIALIZE_TEST_LOCK_ATTR getTestMutex(void)
    {
        TARGETING::HB_MUTEX_SERIALIZE_TEST_LOCK_ATTR pMutex = nullptr;

        // Get a reference to the target service
        TARGETING::TargetService& l_targetService = TARGETING::targetService();

        // Get the system target containing the test mutex
        TARGETING::Target* l_pTarget = NULL;
        (void) l_targetService.getTopLevelTarget(l_pTarget);
        if (l_pTarget == nullptr)
        {
            TS_INFO("getTestMutex: Top level target handle is NULL");
        }
        else
        {
            // use the chip-specific mutex attribute
            pMutex = l_pTarget->getHbMutexAttr
                               <TARGETING::ATTR_HB_MUTEX_SERIALIZE_TEST_LOCK>();
        }
        return pMutex;
    }

    void enableInbandScomsOcmb(const TARGETING::TargetHandle_t i_ocmbTarget)
    {
        mutex_t* l_mutex = nullptr;

        assert((i_ocmbTarget != nullptr),
                "enableInbandScomsOcmb: target is NULL!");

        // Verify that the target is of type OCMB_CHIP
        TARGETING::ATTR_TYPE_type l_targetType =
                    i_ocmbTarget->getAttr<TARGETING::ATTR_TYPE>();
        assert((l_targetType == TARGETING::TYPE_OCMB_CHIP),
                "enableInbandScomsOcmb: target is not an OCMB chip!");

        TS_INFO("enableInbandScomsOcmb: switching to use MMIO on OCMB 0x%08x",
                   TARGETING::get_huid(i_ocmbTarget));

        //don't mess with attributes without the mutex (just to be safe)
        l_mutex = i_ocmbTarget->getHbMutexAttr<TARGETING::ATTR_IBSCOM_MUTEX>();
        mutex_lock(l_mutex);

        TARGETING::ScomSwitches l_switches =
            i_ocmbTarget->getAttr<TARGETING::ATTR_SCOM_SWITCHES>();
        l_switches.useInbandScom = 1;
        l_switches.useI2cScom = 0;

        // Modify attribute
        i_ocmbTarget->setAttr<TARGETING::ATTR_SCOM_SWITCHES>(l_switches);
        mutex_unlock(l_mutex);
    };

    void disableInbandScomsOcmb(const TARGETING::TargetHandle_t i_ocmbTarget)
    {
        mutex_t* l_mutex = nullptr;

        assert((i_ocmbTarget != nullptr),
                "disableInbandScomsOcmb: target is NULL!");

        // Verify that the target is of type OCMB_CHIP
        TARGETING::ATTR_TYPE_type l_targetType =
                    i_ocmbTarget->getAttr<TARGETING::ATTR_TYPE>();
        assert((l_targetType == TARGETING::TYPE_OCMB_CHIP),
                "disableInbandScomsOcmb: target is not an OCMB chip!");

        TS_INFO("disableInbandScomsOcmb: switching to use i2c on OCMB 0x%08x",
                   TARGETING::get_huid(i_ocmbTarget));

        //don't mess with attributes without the mutex (just to be safe)
        l_mutex = i_ocmbTarget->getHbMutexAttr<TARGETING::ATTR_IBSCOM_MUTEX>();
        mutex_lock(l_mutex);

        TARGETING::ScomSwitches l_switches =
            i_ocmbTarget->getAttr<TARGETING::ATTR_SCOM_SWITCHES>();
        l_switches.useInbandScom = 0;
        l_switches.useI2cScom = 1;

        // Modify attribute
        i_ocmbTarget->setAttr<TARGETING::ATTR_SCOM_SWITCHES>(l_switches);
        mutex_unlock(l_mutex);
    };

}
OpenPOWER on IntegriCloud