summaryrefslogtreecommitdiffstats
path: root/src/usr/runtime/hdatservice.H
blob: 78bd55fffc2a3695cbddcd947402b7d89c63d99d (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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/runtime/hdatservice.H $                               */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2011,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                                                     */
#ifndef __RUNTIME_HDATSERVICE_H
#define __RUNTIME_HDATSERVICE_H

#include <sys/sync.h>
#include <util/locked/list.H>
#include <list>
#include <errl/errlentry.H>
#include <attributestructs.H>
#include <sys/task.h>
#include <vector>

namespace RUNTIME
{
    /** @file hdatservice.H
     *  @brief Provides the definition of the HDAT Service class
     */

    /**
     * Class to service HDAT data
     *   there will be a single instance within hostboot
     */
    class hdatService
    {
        struct hdatMemRegion_t
        {
            uint64_t    phys_addr;
            void *      virt_addr;
            size_t      size;

            /**
             * Default Contructor
             */
            hdatMemRegion_t() :
              phys_addr(0), virt_addr(NULL), size(0) {}
        };

        typedef std::vector<hdatMemRegion_t>::iterator    memRegionItr;

      public:

        /**
         * @brief  Add the host data mainstore location to VMM
         *
         * @description  If running with the standard PHYP payload this function
         *    will map all supported HDAT sections into the VMM to allow access
         *    from user space.  When running in standalone (no payload) mode,
         *    some reserved memory will be mapped in for testcases.  If AVPs are
         *    enabled, no memory will be mapped and the PAYLOAD_KIND attribute
         *    will be set appropriately.
         *
         * @return errlHndl_t  NULL on success
         */
        errlHndl_t loadHostData( void );

        /**
         * @brief  Get a pointer to the beginning of a particular section of
         *         the host data memory.
         *
         * @description  The returned pointer will not include any hdat header
         *     information.
         *
         * @param[in] i_section  Chunk of data to find
         * @param[in] i_instance  Instance of section when there are multiple
         *                        entries
         * @param[out] o_dataAddr  Virtual memory address of data
         * @param[out] o_dataSize  Size of data in bytes, 0 on error,
         *                         DATA_SIZE_UNKNOWN if unknown
         *
         * @return errlHndl_t  NULL on success
         */
        errlHndl_t getHostDataSection( SectionId i_section,
                                       uint64_t i_instance,
                                       uint64_t& o_dataAddr,
                                       size_t& o_dataSize );

        /**
         * @brief  Update the actual count of section.  Only supported for
         *         memory dump results table
         *
         * @param[in] i_section  Chunk of data to find
         * @param[in] i_count   Actual count
         *
         * @return errlHndl_t  NULL on success
         */
        errlHndl_t updateHostDataSectionActual( SectionId i_section,
                                                uint16_t i_count );

        /**
         * @brief  Retrieve and log FFDC data relevant to a given section of
         *         host data memory
         *
         * @param[in] i_section  Relevant section
         * @param[inout] io_errlog  Log to append FFDC to
         *
         * @return errlHndl_t  NULL on success
         */
        void addFFDC( SectionId i_section,
                      errlHndl_t& io_errlog );

      protected:
        /**
         * @brief Constructor
         */
        hdatService();


        /**
         * @brief Destructor
         */
        ~hdatService();

        /**
         * @brief Map a region of memory
         *
         * Utility to map a region of memory so it can be accessed.
         * Map information is stored as a class variable
         *
         * @param[in] i_addr  Physical address to map
         * @param[in] i_bytes Number of bytes to map
         * @param[out] o_vaddr Virtual address mapped to
         *
         * @return errlHndl_t  NULL on success
         */
        errlHndl_t mapRegion( uint64_t i_addr, size_t i_bytes,
                              uint64_t &o_vaddr);

        /**
         * @brief Retrieve (and map if necessary) a SPIRA data area
         *
         *  PHYP SPIRA is within the base mapping, Sapphire is not
         *
         * @param[in] i_tuple Valid tuple pointer to area to be mapped
         * @param[out] o_vaddr Virtual address to access data area
         *
         * @return errlHndl_t  NULL on success
         */
        errlHndl_t getSpiraTupleVA(hdat5Tuple_t* i_tuple,
                                     uint64_t & o_vaddr);

          /**
           * @brief Verify that a block of memory falls inside a safe range
           * @param i_addr  Address to check
           * @param i_size  Number of bytes to check
           * @return Error if address seems wrong
           */
          errlHndl_t verify_hdat_address( void* i_addr,
                                          size_t i_size );

        /**
         * @brief Verify the header portion of an HDAT section
         * @param i_header  Actual header data
         * @param i_exp  Expected header data
         * @return Error on mismatch
         */
        errlHndl_t check_header( hdatHDIF_t* i_header,
                                 const hdatHeaderExp_t& i_exp );

          /**
           * @brief Verify basic characteristics of a HDAT Tuple structure
           * @param i_section  Section name being verified
           * @param i_tuple  Tuple to check
           * @return Error if Tuple is unallocated
           */
          errlHndl_t check_tuple( const RUNTIME::SectionId i_section,
                                  hdat5Tuple_t* i_tuple );


        /**
         * @brief Retrieve hardcoded section addresses for standalone mode
         *
         * This is here to allow us to manually generate attribute data for
         *  the HostServices code without requiring a full FipS/PHYP boot.
         *
         * @param[in] i_section  Chunk of data to find
         * @param[in] i_instance  Instance of section when there are multiple
         *                        entries
         * @param[out] o_dataAddr  Virtual memory address of data
         * @param[out] o_dataSize  Size of data in bytes, 0 on error,
         *                         DATA_SIZE_UNKNOWN if unknown
         *
         * @return errlHndl_t  NULL on success
         */
        errlHndl_t get_standalone_section( RUNTIME::SectionId i_section,
                                           uint64_t i_instance,
                                           uint64_t& o_dataAddr,
                                           size_t& o_dataSize );

        /**
         * @brief Locates the proper SPIRA structure and sets instance vars
         *
         * Walks the NACA and interrogates structures to determine which
         * kind of SPIRA is available (if any).
         *
         * @return errlHndl_t  NULL on success
         */
        errlHndl_t findSpira( void );

      private:

        /********************************************
         * VARIABLES
         ********************************************/

        /**
         * Vector of virtual address mapped in
         */
        std::vector<hdatMemRegion_t>    iv_mem_regions;

        /**
         * Legacy SPIRA
         */
        hdatSpira_t* iv_spiraL;

        /**
         * SPIRA-H
         */
        hdatSpira_t* iv_spiraH;

        /**
         * SPIRA-S
         */
        hdatSpira_t* iv_spiraS;

        /**
         * Save the actual count value for sections
         * -Used to keep track of things across HDAT writes
         *  from FSP
         */
        uint16_t iv_actuals[RUNTIME::LAST_SECTION+1];

        /**
         * Dummy value for unassigned actual
         */
        enum {
            ACTUAL_NOT_SET = 0xFFFF
        };

      public:
        /**
         * @brief  Store the actual count of a section.  
         *
         * @param[in] i_section  Chunk of data to update
         * @param[in] i_count   Actual count for MDRT entries
         *
         */
        void saveActualCount( RUNTIME::SectionId i_id,
                              uint16_t i_count )
        {
            iv_actuals[i_id] = i_count;
        }

        /**
         * @brief  Write the stored actual count to SPIRA
         *
         * @param[in] i_section  Chunk of data to update
         *
         * @return errlHndl_t  NULL on success
         */
        errlHndl_t writeActualCount( RUNTIME::SectionId i_id )
        {
            errlHndl_t l_err = NULL;
            if(iv_actuals[i_id] != ACTUAL_NOT_SET)
            {
                l_err = updateHostDataSectionActual( i_id, iv_actuals[i_id] );
            }
            return l_err;
        }
    };

};
#endif
OpenPOWER on IntegriCloud