summaryrefslogtreecommitdiffstats
path: root/src/usr/pnor/pnordd.C
blob: ddc760ba3e56ec20001cb7b7c78af173f7ce1b21 (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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
/**
 *  @file pnordd.C
 *
 *  @brief Implementation of the PNOR Device Driver
 */

/*****************************************************************************/
// I n c l u d e s
/*****************************************************************************/
#include <sys/mmio.h>
#include <sys/task.h>
#include <sys/sync.h>
#include <string.h>
#include <devicefw/driverif.H>
#include <trace/interface.H>
#include <errl/errlentry.H>
#include <targeting/targetservice.H>
#include <errl/errlmanager.H>
#include "pnordd.H"
#include <pnor/pnorif.H>
#include <pnor/pnor_reasoncodes.H>

#define FAKE_PNOR_START 5*1024*1024
#define FAKE_PNOR_END 8*1024*1024
#define FAKE_PNOR_SIZE 3*1024*1024

extern trace_desc_t* g_trac_pnor;

namespace PNOR
{



/**
 * @brief Performs an PNOR Read Operation
 * This function performs a PNOR Read operation. It follows a pre-defined
 * prototype functions in order to be registered with the device-driver
 * framework.
 *
 * @param[in]   i_opType        Operation type, see DeviceFW::OperationType
 *                              in driverif.H
 * @param[in]   i_target        PNOR target
 * @param[in/out] io_buffer     Read: Pointer to output data storage
 *                              Write: Pointer to input data storage
 * @param[in/out] io_buflen     Input: size of io_buffer (in bytes)
 *                              Output:
 *                                  Read: Size of output data
 *                                  Write: Size of data written
 * @param[in]   i_accessType    DeviceFW::AccessType enum (usrif.H)
 * @param[in]   i_args          This is an argument list for DD framework.
 *                              In this function, there's only one argument,
 *                              containing the PNOR address and chip select
 * @return  errlHndl_t
 */
errlHndl_t ddRead(DeviceFW::OperationType i_opType,
                  TARGETING::Target* i_target,
                  void* io_buffer,
                  size_t& io_buflen,
                  int64_t i_accessType,
                  va_list i_args)
{
    errlHndl_t l_err = NULL;
    uint64_t l_addr = va_arg(i_args,uint64_t);

    do{
        l_err = Singleton<PnorDD>::instance().read(io_buffer,
                                                   io_buflen,
                                                   l_addr);
        if(l_err)
        {
            break;
        }
 
    }while(0);

    return l_err;
}

/**
 * @brief Performs an PNOR Write Operation
 * This function performs a PNOR Write operation. It follows a pre-defined
 * prototype functions in order to be registered with the device-driver
 * framework.
 *
 * @param[in]   i_opType        Operation type, see DeviceFW::OperationType
 *                              in driverif.H
 * @param[in]   i_target        PNOR target
 * @param[in/out] io_buffer     Read: Pointer to output data storage
 *                              Write: Pointer to input data storage
 * @param[in/out] io_buflen     Input: size of io_buffer (in bytes)
 *                              Output:
 *                                  Read: Size of output data
 *                                  Write: Size of data written
 * @param[in]   i_accessType    DeviceFW::AccessType enum (usrif.H)
 * @param[in]   i_args          This is an argument list for DD framework.
 *                              In this function, there's only one argument,
 *                              containing the PNOR address and chip select
 * @return  errlHndl_t
 */
errlHndl_t ddWrite(DeviceFW::OperationType i_opType,
                  TARGETING::Target* i_target,
                  void* io_buffer,
                  size_t& io_buflen,
                  int64_t i_accessType,
                  va_list i_args)
{
    errlHndl_t l_err = NULL;
    uint64_t l_addr = va_arg(i_args,uint64_t);

    do{
        l_err = Singleton<PnorDD>::instance().write(io_buffer,
                                                    io_buflen,
                                                    l_addr);
        if(l_err)
        {
            break;
        }
 
    }while(0);

    return l_err;
}

// Register PNORDD access functions to DD framework
DEVICE_REGISTER_ROUTE(DeviceFW::READ,
                      DeviceFW::PNOR,
                      TARGETING::TYPE_PROC,
                      ddRead);

DEVICE_REGISTER_ROUTE(DeviceFW::WRITE,
                      DeviceFW::PNOR,
                      TARGETING::TYPE_PROC,
                      ddWrite);


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
errlHndl_t setLSCAccessMode(lscMode i_mode)
{
    errlHndl_t l_err = NULL;

    do{
        l_err = Singleton<PnorDD>::instance().setAccessMode(i_mode);
        if(l_err)
        {
            break;
        }
 
    }while(0);

    return l_err;
}


/**
 * @brief Read PNOR
 */
errlHndl_t PnorDD::read(void* o_buffer,
                        size_t& io_buflen,
                        uint64_t i_address)
{
    //TRACDCOMP(g_trac_pnor, "PnorDD::read(i_address=0x%llx)> ", i_address);
    errlHndl_t l_err = NULL;

    do{
        //mask off chip select for now, will probably break up fake PNOR into
        //multiple fake chips eventually
       uint64_t l_address = i_address & 0x00000000FFFFFFFF;

        l_err = verifyAddressRange(l_address, io_buflen);
        if(l_err)
        {
            io_buflen = 0;
            break;
        }

        //create a pointer to the offset start.
        char * srcPtr = (char *)(FAKE_PNOR_START+l_address);

        //@TODO: likely need a mutex around HW access

        //copy data from memory into the buffer.
        memcpy(o_buffer, srcPtr, io_buflen);


    }while(0);

    return l_err;
}

/**
 * @brief Write PNOR
 */
errlHndl_t PnorDD::write(void* i_buffer,
                         size_t& io_buflen,
                         uint64_t i_address)
{
    //TRACDCOMP(g_trac_pnor, "PnorDD::write(i_address=0x%llx)> ", i_address);
    errlHndl_t l_err = NULL;

    do{
        //mask off chip select for now, will probably break up fake PNOR into
        //multiple fake chips eventually
       uint64_t l_address = i_address & 0x00000000FFFFFFFF;


        l_err = verifyAddressRange(l_address, io_buflen);
        if(l_err)
        {
            io_buflen = 0;
            break;
        }

        //create a pointer to the offset start.
        char * destPtr = (char *)(FAKE_PNOR_START+l_address);

        //@TODO: likely need a mutex around HW access

        //copy data from memory into the buffer.
        memcpy(destPtr, i_buffer, io_buflen);


    }while(0);

    return l_err;
}

/**
 * @brief Set PNOR to desired mode
 */
errlHndl_t PnorDD::setAccessMode(lscMode i_mode)
{
    errlHndl_t l_err = NULL;
    TRACFCOMP(g_trac_pnor, "PnorDD::setAccessMode(0x%llx)> ", i_mode);

    do{
        //@TODO: real impelementation needed

        //Once we have a 'real' implementation, it will likely drive the need for mutexes
        //throughout the PnorDD interfaces, to avoid issues with weak consistency or a
        //read/write occuring while we're updating the mode, but
        //skipping that until it's actually needed.

        //Eventually need to actually change HW state here.
        //For now, just record the new mode.
        iv_lscMode = i_mode;


    }while(0);

    return l_err;
}


/********************
 Private/Protected Methods
 ********************/


/**
 * @brief  Constructor
 */
PnorDD::PnorDD()
: iv_lscMode(MMRD)
{
    TRACFCOMP(g_trac_pnor, "PnorDD::PnorDD()> ");

}

/**
 * @brief  Destructor
 */
PnorDD::~PnorDD()
{

    //Nothing to do for now
}

errlHndl_t PnorDD::verifyAddressRange(uint64_t i_address,
                                      size_t& i_length)
{
    errlHndl_t l_err = NULL;

    do{

        if((i_address+i_length) > FAKE_PNOR_SIZE)
        {
            TRACFCOMP( g_trac_pnor, "PnorDD::verifyAddressRange> Invalid Address Requested : i_address=%d", i_address );
            /*@
             * @errortype
             * @moduleid     PNOR::MOD_PNORDD_VERIFYADDRESSRANGE
             * @reasoncode   PNOR::RC_INVALID_SECTION
             * @userdata1    Requested Address
             * @userdata2    Requested Length
             * @devdesc      PnorDD::verifyAddressRange> Invalid Address requested
             */
            l_err = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                            PNOR::MOD_PNORDD_VERIFYADDRESSRANGE,
                                            PNOR::RC_INVALID_ADDRESS,
                                            TO_UINT64(i_address),
                                            TO_UINT64(i_length));
            break;
        }



    }while(0);

    return l_err;
}



}; //end PNOR namespace
OpenPOWER on IntegriCloud