summaryrefslogtreecommitdiffstats
path: root/src/usr/i2c/eepromCache.H
blob: 253367b0754f2e4302d4c30d51e2ed6ceb394e89 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/i2c/eepromCache.H $                                   */
/*                                                                        */
/* 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                                                     */
#ifndef __EEPROM_CACHE_H
#define __EEPROM_CACHE_H

#include <i2c/eeprom_const.H>
#include <errl/errlentry.H>

namespace EEPROM
{

/**
*
* @brief Perform a read or write operation on an eeprom record inside EEACHE
*
*
* @param[in] i_opType - Operation Type - See DeviceFW::OperationType in
*       driververif.H
*
* @param[in] i_target - Target device associated w/ the EEPROM.
*
* @param[in/out] io_buffer
*       INPUT: Pointer to the data that will be  written to the target
*           device.
*       OUTPUT: Pointer to the data that was read from the target device.
*
* @param[in] io_buflen
*       INPUT: Length of the buffer to be written to target device or
*       length of buffer to be read from target device.
*       Output: If io_buffer is passed in as nullptr size will be set in
*               io_buflen as an out param
*
* @param [in] i_eepromInfo struct containing information needed to perform
*        operation on the given i2c eeprom. NOTE It is expected that
*        eepromRole and offset have been filled out in this struct
*        prior to passing it into this function
*
* @return errlHndl_t - nullptr if successful, otherwise a pointer to the
*       error log.
*
*/
errlHndl_t eepromPerformOpCache(DeviceFW::OperationType i_opType,
                                TARGETING::Target * i_target,
                                void * io_buffer,
                                size_t & io_buflen,
                                eeprom_addr_t &i_eepromInfo);

/**
*
* @brief Build up a struct that is used to compare cached eeprom entries
*        in the EECACHE section. Each eeprom will get an entry in the
*        eepromRecordHeader order in the EECACHE section header
*
* @param[in] i_target - Target device associated w/ the EEPROM.
*
* @param [in/out] io_eepromInfo struct containing information needed to perform
*        operation on the given i2c eeprom. NOTE It is expected that
*        eepromRole has been filled out in this struct prior to passing
*        it into this function
* @param [out] o_eepromRecordHeader struct that will be populated with infromation
*        that can be used to determine if the eeprom has been cached yet or not,
*        or for looking up an eeprom we want to write to/ read from.
*
* @pre  It is expected that io_i2cInfo.eepromRole will have a valid role set
*
* @post After function o_eepromRecordHeader will be filled in with information
*       found while looking up the eeprom info from the target's attributes.
*       o_eepromRecordHeader can be used to see if a cached copy exists
*
* @return errlHndl_t - nullptr if successful, otherwise a pointer to the
*       error log.
*
*/
errlHndl_t buildEepromRecordHeader(TARGETING::Target * i_target,
                                    eeprom_addr_t & io_eepromInfo,
                                    eepromRecordHeader & o_eepromRecordHeader);


#ifndef __HOSTBOOT_RUNTIME

/**
*
* @brief Check if entry already exists in g_cachedEeproms, if a match is
*        found then return true. If there is no match, add it to the list
*        and return false;
*
* @param[in] i_eepromRecordHeader Header for record we want to add to map
*
* @param[in] i_recordHeaderVaddr Virtual address to PNOR copy of header information
*
* @return TRUE if entry is already in map FALSE if this is a new entry
*
*/
bool addEepromToCachedList(const eepromRecordHeader & i_eepromRecordHeader,
                           const uint64_t i_recordHeaderVaddr);

/**
*
* @brief Perform a lookup on the global map g_cachedEeproms to get a
*        virtual address for a given EEPROM entry in the EECACHE table of contents
*
* @param[in] i_eepromRecordHeader
*
* @pre  It is expected that i_eepromRecordHeader has valid information for
*       the uniqueID (i2cm_huid, port, engine, devAddr, mux_select)
*
* @return uint64_t virtual address pointing to the cached eeprom data in pnor
*
*/
uint64_t lookupEepromHeaderAddr(const eepromRecordHeader& i_eepromRecordHeader);

/**
*
* @brief Perform a lookup on the global map g_cachedEeproms to get a
*        virtual address for a given EEPROM cache entry
*
* @param[in] i_eepromRecordHeader
*
* @pre  It is expected that i_eepromRecordHeader has valid information for
*       the uniqueID (i2cm_huid, port, engine, devAddr, mux_select)
*
* @return uint64_t virtual address pointing to the cached eeprom data in pnor
*
*/
uint64_t lookupEepromCacheAddr(const eepromRecordHeader& i_eepromRecordHeader);


/**
*
* @brief Print the info found in the Table of Contents of the EECACHE
*        section of pnor to trace buffer
*
* @return void
*
*/
void printTableOfContents(void);


/**
*
* @brief Update the record entry in the Table of Contents of the EECACHE
*        section of pnor to either mark the contents of the cache to be
*        valid or invalid
*
* @param[in] i_target     Target associated with EEPROM
*
* @param[in] i_eepromRole Role of EEPROM associated with target (VPD_PRIMARY etc)
*
* @param[in] i_isValid    Mark eeprom cache valid or invalid ? 
*
* @return errlHndl_t - nullptr if successful, otherwise a pointer to the
*       error log.
*
*/
errlHndl_t setIsValidCacheEntry(const TARGETING::Target * i_target,
                                const EEPROM_ROLE &i_eepromRole,
                                bool i_isValid);

/**
*
* @brief Update the record entry in the Table of Contents of the EECACHE
*        section of pnor to either mark the contents of the cache to be
*        valid or invalid
*
* @param[in] i_eepromRecordHeader eepromRecord oject already filled in (including eepromRole)
*
* @param[in] i_isValid    Mark eeprom cache valid or invalid ? 
*
* @return errlHndl_t - nullptr if successful, otherwise a pointer to the
*       error log.
*
*/
errlHndl_t setIsValidCacheEntry(const eepromRecordHeader& i_eepromRecordHeader, bool i_isValid);

/**
*
* @brief Lookup a given i_eepromRecordHeader in the global map of eeprom
*        caches and check if the eeprom has changed this IPL or not
*
* @param[in] i_eepromRecordHeader we want to look up
*
* @return bool Return TRUE if eeprom is found in map AND mark_target_changed
               was set to true for the eeprom entry. Return FALSE otherwise.
*
*/
bool hasEeepromChanged(const eepromRecordHeader & i_eepromRecordHeader);

/**
*
* @brief Lookup a given i_eepromRecordHeader in the global map of eeprom
*        caches and mark that it has changed this IPL
*
* @param[in] i_eepromRecordHeader we want to mark as changed
*
* @return void
*/
void setEeepromChanged(const eepromRecordHeader & i_eepromRecordHeader);
#else
/**
*
* @brief Check if entry already exists in g_cachedEeproms, if a match is
*        found then return true. If there is no match, add it to the list
*        and return false;
*
* @param[in] i_eepromRecordHeader Header for record we want to add to map
*
* @param[in] i_recordHeaderVaddr Virtual address to PNOR copy of header information
*
* @param[in] i_instance          Node ID that this eeprom is on
*
* @return TRUE if entry is already in map FALSE if this is a new entry
*
*/
bool addEepromToCachedList(const eepromRecordHeader & i_eepromRecordHeader,
                           const uint64_t i_recordHeaderVaddr,
                           const uint8_t i_instance);

/**
*
* @brief Perform a lookup on the global map g_cachedEeproms to get a
*        virtual address for a given EEPROM cache entry
*
* @param[in] i_eepromRecordHeader Header for record we want to add to lookup address for
*
* @param[in] i_isntance  Node ID that this eeprom is on
*
* @pre  It is expected that i_eepromRecordHeader has valid information for
*       the uniqueID (i2cm_huid, port, engine, devAddr, mux_select)
*
* @return uint64_t virtual address pointing to the cached eeprom data in pnor
*
*/
uint64_t lookupEepromCacheAddr(const eepromRecordHeader& i_eepromRecordHeader,
                               const uint8_t i_instance);

/**
*
* @brief Walk through g_cachedEeproms map and print information about
*        the cached eeproms found
*
* @return void
*
*/
void printCurrentCachedEepromMap(void);
#endif  // __HOSTBOOT_RUNTIME
}

#endif
OpenPOWER on IntegriCloud