summaryrefslogtreecommitdiffstats
path: root/src/usr/pore/fapiporeve/fapiPoreVeArg.C
blob: 9efe547dc353410db1c3607dd85f326b034ea28f (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/pore/fapiporeve/fapiPoreVeArg.C $                     */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2012,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                                                     */
// -*- mode: C++; c-file-style: "linux";  -*-
// $Id: fapiPoreVeArg.C,v 1.19 2012/04/26 21:30:40 jeshua Exp $
// $Source: /afs/awd/projects/eclipz/KnowledgeBase/.cvsroot/eclipz/poreve/working/fapiporeve/fapiPoreVeArg.C,v $
//------------------------------------------------------------------------------
// *! (C) Copyright International Business Machines Corp. 2011
// *! All Rights Reserved -- Property of IBM
// *! *** IBM Confidential ***
//------------------------------------------------------------------------------
// *! TITLE : fapiPoreVeArg.C
// *! DESCRIPTION : Defines the arg struct to pass to fapiPoreVe
// *! OWNER NAME  : Jeshua Smith    Email: jeshua@us.ibm.com
// *! BACKUP NAME : John Bordovsky  Email: johnb@us.ibm.com
// #! ADDITIONAL COMMENTS :
//
//		  

#include "fapiPoreVeArg.H"
#include <fapi.H>

#ifndef __HOSTBOOT_MODULE
//For file mapping
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>

//For hooks
#include <dlfcn.h>
#endif

using namespace vsbe;

FapiPoreVeArg::FapiPoreVeArg( const FapiPoreVeArg_t i_type ) :
    iv_type(i_type)
{
}

FapiPoreVeArg::~FapiPoreVeArg( )
{
}

#ifndef __HOSTBOOT_MODULE
FapiPoreVeMemArg::FapiPoreVeMemArg( const FapiPoreVeArg_t   i_type,
                                    const char* const       i_filename,
                                    const uint32_t          i_base ) :
    FapiPoreVeArg(i_type),
    iv_base(i_base),
    iv_filename(i_filename),
    iv_fd(open(i_filename, O_RDONLY)),
    iv_crcEnable(true)
{
    uint32_t rc = 0;

    if( iv_fd < 0 ) {
        FAPI_ERR( "Failed to open %s file\n", iv_filename );
        rc = BAD_ERROR_CODE;
    } else {
        iv_size = lseek( iv_fd, 0, SEEK_END );
        if( iv_size == (size_t)((off_t)-1) ) {
            FAPI_ERR( "Failed to determine the size of %s file\n", iv_filename );
        } else {
            if( (iv_type == ARG_SRAM) || (iv_type == ARG_MAINMEM) ||
                (iv_type == ARG_PNOR) || (iv_type == ARG_SEEPROM) ||
                (iv_type == ARG_PIBMEM) ) {
                iv_data = mmap( 0, iv_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, iv_fd, 0 );
            } else {
                iv_data = mmap( 0, iv_size, PROT_READ, MAP_PRIVATE, iv_fd, 0 );
            }
            if( iv_data == MAP_FAILED ) {
                FAPI_ERR( "Failed to map %s file\n", iv_filename );
                rc = BAD_ERROR_CODE;
            }
        }
    }
    //JDS TODO - how do I make the constructor fail if mapping failed?
}
#endif

FapiPoreVeMemArg::FapiPoreVeMemArg( const FapiPoreVeArg_t   i_type,
                                    const uint32_t          i_base,
                                    const size_t            i_size,
                                    void *                  i_data) :
    FapiPoreVeArg(i_type),
    iv_base(i_base),
#ifndef __HOSTBOOT_MODULE
    iv_filename(NULL),
    iv_fd(0),
#endif
    iv_size(i_size),
    iv_crcEnable(true),
    iv_data(i_data)
{
}

FapiPoreVeMemArg::~FapiPoreVeMemArg( )
{
#ifndef __HOSTBOOT_MODULE
    uint32_t rc = 0;
    if( iv_data != NULL && iv_data != MAP_FAILED && iv_filename != NULL ) {
        int unmap_rc = munmap( iv_data, iv_size );
        if( unmap_rc != 0 ) {
            FAPI_ERR( "Failed to unmap %s file\n", iv_filename );
            rc = BAD_ERROR_CODE;
        }
    }
    if( iv_filename != NULL ) {
        int close_rc = close( iv_fd );
        if( close_rc != 0 ) {
            FAPI_ERR( "Failed to close %s, iv_fd=%i\n", iv_filename, iv_fd );
            rc = BAD_ERROR_CODE;
        }
    }
#endif
    //JDS TODO - how do I make the destructor fail if unmapping failed?
}

#ifndef __HOSTBOOT_MODULE
FapiPoreVeStateArg::FapiPoreVeStateArg( const char* const i_filename ) :
    FapiPoreVeArg( ARG_STATE ),
    iv_filename(i_filename),
    iv_extractState(true),
    iv_installState(true),
    iv_data(NULL)
{
}
#endif

FapiPoreVeStateArg::FapiPoreVeStateArg( void * i_data ) :
    FapiPoreVeArg( ARG_STATE ),
#ifndef __HOSTBOOT_MODULE
    iv_filename(NULL),
#endif
    iv_extractState(true),
    iv_installState(true),
    iv_data(i_data)
{
}

FapiPoreVeStateArg::~FapiPoreVeStateArg( )
{
}

FapiPoreVeHooksArg::FapiPoreVeHooksArg( const char* const i_filename ) :
    FapiPoreVeArg( ARG_HOOKS ),
    iv_filename(i_filename),
    iv_handle(NULL)
{
}

FapiPoreVeHooksArg::~FapiPoreVeHooksArg( )
{
#ifndef __HOSTBOOT_MODULE
    if( iv_handle != NULL )
    {
        dlclose(iv_handle);
    }
#endif
}

FapiPoreVeOtherArg::FapiPoreVeOtherArg( const uint64_t   i_instructionCount,
                                        const PoreIbufId i_poreType ) :
    FapiPoreVeArg( ARG_OTHER ),
    iv_instructionCount(i_instructionCount),
    iv_poreType(i_poreType),
    iv_pdbgArgs(NULL),
    iv_entryPoint(NULL),
    iv_breakpoint(NULL),
    iv_mrr(0)
{
}

FapiPoreVeOtherArg::~FapiPoreVeOtherArg( )
{
}


/*
*************** Do not edit this area ***************
This section is automatically updated by CVS when you check in this file.
Be sure to create CVS comments when you commit so that they are included here.

$Log: fapiPoreVeArg.C,v $
Revision 1.19  2012/04/26 21:30:40  jeshua
file renamed from ../../../fapiporeve/working/fapiPoreVeArg.C to fapiPoreVeArg.C

Revision 1.18  2012/04/26 20:53:57  jeshua
file renamed from ../../chips/p8/working/procedures/fapiPoreVeArg.C to fapiPoreVeArg.C

Revision 1.17  2012/03/01 20:11:31  jeshua
Updated for PIBMEM support

Revision 1.16  2012/01/09 20:55:57  jeshua
Don't include file-related code for hostboot

Revision 1.15  2011/12/07 22:30:59  jeshua
Initial MRR support

Revision 1.14  2011/12/02 16:12:11  jeshua
Make seeprom writable (for control bits)

Revision 1.13  2011/11/17 18:20:05  jeshua
Skip file handling for hostboot

Revision 1.12  2011/09/20 15:38:42  jeshua
Allow creating memory args from memory pointers instead of just files

Revision 1.11  2011/09/02 20:54:29  jeshua
No longer do file open and close

Revision 1.10  2011/09/02 20:01:04  jeshua
Fixes for state arg support

Revision 1.9  2011/07/13 19:13:43  jeshua
Enabled writing of the PNOR at John B's request

Revision 1.8  2011/07/12 16:39:38  jeshua
Breakpoint support

Revision 1.7  2011/07/08 23:53:16  jeshua
Updated for FAPI changes

Revision 1.6  2011/07/07 20:34:43  jeshua
Moved entry point from hooks to other arg

Revision 1.5  2011/06/03 15:38:50  jeshua
Added pdbgArg to OtherArg type

Revision 1.4  2011/05/20 14:05:10  jeshua
Don't close hooks file if it wasn't opened

Revision 1.3  2011/05/20 13:57:48  jeshua
Added const
Use initializers
Unload hooks on destruction

Revision 1.2  2011/05/13 21:19:42  jeshua
Updated comments
Renamed InstructionCountArg to OtherArg, and added PORE type into it
Added iv_extractState
Added Hooks class

Revision 1.1  2011/05/11 19:57:29  jeshua
Initial version




*/
/* Local Variables: */
/* c-basic-offset: 4 */
/* End: */
OpenPOWER on IntegriCloud