summaryrefslogtreecommitdiffstats
path: root/src/usr/trace/compdesc.C
blob: 35f4de0c581ad40c183217b1529ab43e6ec27941 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/trace/compdesc.C $                                    */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2012,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 "compdesc.H"
#include "service.H"
#include <assert.h>
#include <string.h>
#include <string_ext.h>

#include <targeting/common/commontargeting.H>

namespace TRACE
{
    ComponentDesc::ComponentDesc(const char* i_comp, uint32_t i_size,
                                 uint8_t i_bufferType) :
        iv_bufferType(i_bufferType), iv_debugEnabled(false),
        iv_maxSize(i_size), iv_curSize(0),
        iv_first(NULL), iv_last(NULL)
    {
        assert(iv_bufferType < BUFFER_COUNT);

        memset(iv_compName, '\0', sizeof(iv_compName));
        strcpy(iv_compName, i_comp); // No buffer overrun because of assert
                                     // in ComponentList::getDescriptor.
        strupr(iv_compName);

        iv_compNameLen = strlen(iv_compName) + 1;
    }

    ComponentList::ComponentList() :
        iv_components()
    {
        mutex_init(&iv_mutex);
    };

    ComponentList::~ComponentList()
    {
        mutex_destroy(&iv_mutex);
    };

    ComponentDesc* ComponentList::getDescriptor(const char* i_comp,
                                                uint32_t i_size,
                                                uint8_t i_bufferType)
    {
        ComponentDesc* l_rc = NULL;

        assert(strlen(i_comp) < ComponentDesc::COMP_SIZE);

        // Fix up the component name to be upper case.
        char l_compName[ComponentDesc::COMP_SIZE];
        memset(l_compName, '\0', sizeof(l_compName));
        strcpy(l_compName, i_comp);
        strupr(l_compName);

        mutex_lock(&iv_mutex);

        // Look for existing descriptor.
        for(List::iterator i = iv_components.begin();
            i != iv_components.end();
            ++i)
        {
            if (0 == memcmp(&i->iv_compName, l_compName, sizeof(l_compName)))
            {
                l_rc = &(*i);
                break;
            }
        }

        // Insert new descriptor if none found.
        if ((NULL == l_rc) && (i_size > 0))
        {
            iv_components.push_back(ComponentDesc(l_compName, i_size,
                                                  i_bufferType));
            l_rc = &iv_components.back();
        }

#ifndef __HOSTBOOT_RUNTIME  // TODO: RTC 79408
        // Check for special SCAN component to force enable debug trace on.
        if (0 == memcmp(l_compName, "SCAN", 5))
        {
            TARGETING::Target* sys = NULL;
            TARGETING::targetService().getTopLevelTarget(sys);

            TARGETING::HbSettings hbSettings =
                sys->getAttr<TARGETING::ATTR_HB_SETTINGS>();

            if (hbSettings.traceScanDebug)
            {
                l_rc->iv_debugEnabled = true;
            }
        }
#endif

        mutex_unlock(&iv_mutex);
        return l_rc;
    }

};
OpenPOWER on IntegriCloud