summaryrefslogtreecommitdiffstats
path: root/src/include/usr/devicefw/userif.H
blob: e30595e40d56b977994be953e4673960998ca62c (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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/include/usr/devicefw/userif.H $                           */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2011,2015                        */
/* [+] Google Inc.                                                        */
/* [+] 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                                                     */
/** @file userif.H
 *  @brief Provides the user application interfaces for performing device
 *         access.
 *
 *  @note These interfaces should not be used directly by device drivers.
 *        Use driverif.H instead.
 */

#ifndef __DEVICEFW_USERIF
#define __DEVICEFW_USERIF

#ifndef PARSER
#include <stdint.h>
#include <errl/errlentry.H>
#include <vpd/vpd_if.H>
#include <targeting/common/targetservice.H>
#endif // not PARSER

namespace DeviceFW
{
    /** @enum AccessType
     *  @brief Access types for accessing a hardware device.
     */
    enum AccessType
    {
        SCOM = 0,
        PNOR,
        MAILBOX,
        PRESENT,
        FSI,
        SPD,
        MVPD,
        CVPD,
        SCAN,
        EEPROM,
        GPIO,
        LPC,
        IPMIBT,    // As opposed to other phy's
        PVPD,
        TPM,
        SIO,
        AHB_SIO,

        LAST_ACCESS_TYPE,
    };

#ifndef PARSER
    /** Construct the device addressing parameters for SCOM device ops.
     *  @param[in] i_address - Scom address to operate on.
     */
    #define DEVICE_SCOM_ADDRESS(i_address) \
        DeviceFW::SCOM, static_cast<uint64_t>((i_address))

    /** Construct the device addressing parameters for the PRESENT device ops.
     */
    #define DEVICE_PRESENT_ADDRESS() \
        DeviceFW::PRESENT

    /**
     * Construct a PNOR DD address
     *    address = 0000_0000_0000_000c_aaaa_aaaa_aaaa_aaaa
     *      c=chip, a=address
     * @param[in] i_chip  Chip Select
     * @param[in] i_addr  Offset (from zero) into selected flash chip
     * @return  64-bit address to pass into PNOR device commands
     */
     #define DEVICE_PNOR_ADDRESS( i_chip, i_addr )  \
        DeviceFW::PNOR, ((static_cast<uint64_t>(i_chip)<<32)|static_cast<uint64_t>(i_addr))

    /** Construct the device addressing parameters for FSI device ops.
     *  @param[in] i_address - FSI address to operate on.
     */
    #define DEVICE_FSI_ADDRESS(i_address) \
        DeviceFW::FSI, static_cast<uint64_t>((i_address))

    /**
     * Construct the device addressing parameters for the SPD device ops.
     * @param[in] i_keyword - The keyword enumeration value to be accessed
     *      by the device driver.
     */
    #define DEVICE_SPD_ADDRESS( i_keyword )\
        DEVICE_SPD_FORCE_ADDRESS( i_keyword, VPD::AUTOSELECT )

    /**
     * Construct the device addressing parameters for the SPD device ops.
     * @param[in] i_keyword - The keyword enumeration value to be accessed
     *      by the device driver.
     * @param[in] i_location - The location to be used for
     *      accessing the keyword (PNOR/SEEPROM).
     */
    #define DEVICE_SPD_FORCE_ADDRESS( i_keyword, i_location )\
        DeviceFW::SPD, static_cast<uint64_t>(( i_keyword )),\
                       static_cast<uint64_t>(( i_location))

    /**
     * Construct the device addressing parameters for the MAILBOX device.
     * @param[out] o_status - Set with all available status bits
     *                        from MBOX::MboxReadStatus
     */
    #define DEVICE_MBOX_ADDRESS(o_status) \
        DeviceFW::MAILBOX, static_cast<uint64_t*>((o_status))

    /**
     * Construct the device addressing parameters for the MVPD device ops.
     * @param[in] i_record - The enumeration of the MVPD record to access.
     * @param[in] i_keyword - The enumeration of the MVPD keyword, located
     *      within the i_record Record to access.
     */
    #define DEVICE_MVPD_ADDRESS( i_record, i_keyword )\
        DEVICE_MVPD_FORCE_ADDRESS( i_record, i_keyword, VPD::AUTOSELECT )

    /**
     * Construct the device addressing parameters for the MVPD device ops.
     * @param[in] i_record - The enumeration of the MVPD record to access.
     * @param[in] i_keyword - The enumeration of the MVPD keyword, located
     *      within the i_record Record to access.
     * @param[in] i_location - The location of the data (PNOR/SEEPROM)
            see vpd_if.H
     */
    #define DEVICE_MVPD_FORCE_ADDRESS( i_record, i_keyword, i_location )\
        DeviceFW::MVPD, static_cast<uint64_t>(( i_record )),\
            static_cast<uint64_t>(( i_keyword )),\
            static_cast<uint64_t>(( i_location ))

    /**
     * Construct the device addressing parameters for the CVPD device ops.
     * @param[in] i_record - The enumeration of the CVPD record to access.
     * @param[in] i_keyword - The enumeration of the CVPD keyword, located
     *      within the i_record Record to access.
     */
    #define DEVICE_CVPD_ADDRESS( i_record, i_keyword )\
        DEVICE_CVPD_FORCE_ADDRESS( i_record, i_keyword, VPD::AUTOSELECT )

    /**
     * Construct the device addressing parameters for the CVPD device ops.
     * @param[in] i_record - The enumeration of the CVPD record to access.
     * @param[in] i_keyword - The enumeration of the CVPD keyword, located
     *      within the i_record Record to access.
     * @param[in] i_location - The location of the data (PNOR/SEEPROM)
            see vpd_if.H
     */
    #define DEVICE_CVPD_FORCE_ADDRESS( i_record, i_keyword, i_location )\
        DeviceFW::CVPD, static_cast<uint64_t>(( i_record )),\
            static_cast<uint64_t>(( i_keyword )),\
            static_cast<uint64_t>(( i_location ))

    /**
     * Construct the device addressing parameters for the PVPD device ops.
     * @param[in] i_record - The enumeration of the PVPD record to access.
     * @param[in] i_keyword - The enumeration of the PVPD keyword, located
     *      within the i_record Record to access.
     */
    #define DEVICE_PVPD_ADDRESS( i_record, i_keyword )\
        DEVICE_PVPD_FORCE_ADDRESS( i_record, i_keyword, VPD::AUTOSELECT )

    /**
     * Construct the device addressing parameters for the PVPD device ops.
     * @param[in] i_record - The enumeration of the PVPD record to access.
     * @param[in] i_keyword - The enumeration of the PVPD keyword, located
     *      within the i_record Record to access.
     * @param[in] i_location - The location of the data (PNOR/SEEPROM)
            see vpd_if.H
     */
    #define DEVICE_PVPD_FORCE_ADDRESS( i_record, i_keyword, i_location )\
        DeviceFW::PVPD, static_cast<uint64_t>(( i_record )),\
            static_cast<uint64_t>(( i_keyword )),\
            static_cast<uint64_t>(( i_location ))

    /**
     * Construct the device addressing parameters for the SCAN device ops.
     * @param[in] i_ring - The ring address to scan
     * @param[in] i_ringlen - The length of the ring to scan in bits
     *                 NOTE: This value is the scanring length must
     *                       match the scandef file value.
     * @param[in] i_flag - Specific requests on the scan such as
     *             check the header, or set pulse option.
     *     Flag options are located in: src/include/usr/scan/scanif.H
     */
    #define DEVICE_SCAN_ADDRESS( i_ring, i_ringlen, i_flag )\
        DeviceFW::SCAN, static_cast<uint64_t>(( i_ring )),\
            static_cast<uint64_t>(( i_ringlen )),\
            static_cast<uint64_t>(( i_flag ))

    /**
     * Construct the device addressing parameters for the LPC device ops.
     * @param[in] i_trans_type - LPC transaction type.
     * @param[in] i_address - LPC address to operate on.
     *     Flag options are located in: src/include/usr/lpc/lpcif.H
     */
    #define DEVICE_LPC_ADDRESS( i_trans_type, i_address )\
        DeviceFW::LPC, static_cast<uint64_t>(( i_trans_type )),\
            static_cast<uint64_t>(( i_address ))

    /**
     * Construct the device addressing parameters for the SIO device ops.
     * @param[i] i_device - SIO device to operate on
     * @param[i] i_address - SIO address to operate on
     */
    #define DEVICE_SIO_ADDRESS(i_device, i_address)\
        DeviceFW::SIO, static_cast<uint64_t>((i_device)),\
            static_cast<uint64_t>((i_address))

    /**
     * Construct the device addressing parameters for the AHB_SIO device ops.
     * @param[i] i_address - AHB_SIO address to operate on
     */
    #define DEVICE_AHB_SIO_ADDRESS(i_address)\
        DeviceFW::AHB_SIO, static_cast<uint64_t>((i_address))

    /**
     * Construct the device addressing parameters for the EEPROM device ops.
     * @param[in] i_eeprom_enum - The chip number of the EEPROM to access. See
     *                            eeprom_chip_types_t in eepromif.H
     * @param[in] i_offset - The internal offset of the EEPROM slave device.
     */
    #define DEVICE_EEPROM_ADDRESS( i_eeprom_enum, i_offset )\
        DeviceFW::EEPROM, static_cast<uint64_t>(( i_eeprom_enum )),\
            static_cast<uint64_t>(( i_offset ))

    /**
     * Construct the device addressing parameters for the TPM device ops.
     * @param[in] i_tpm_enum The chip number of the TPM to access. See
     *                            tpm_chip_types_t in tpmddif.H
     * @param[in] i_tpm_operation The TPM operation to perform. See
     *                            tpm_op_types_t in tpmddif.H
     * @param[in] i_command_len Command length to write during transmit
     *                            operations
     */
    #define DEVICE_TPM_ADDRESS( i_tpm_enum, i_tpm_op, i_command_len )\
        DeviceFW::TPM, static_cast<uint64_t>(( i_tpm_enum )),\
            static_cast<uint64_t>(( i_tpm_op )),\
            static_cast<uint64_t>(( i_command_len ))

    /**
     * Construct the device addressing parameters for the GPIO port extender ops
     * @param[in] i_gpio_num - The port extender device type.
     * @param[in] i_gpio_pin = The GPIO port address
     */
    #define DEVICE_GPIO_ADDRESS( i_device_type , i_gpio_portAddr) \
        DeviceFW::GPIO, static_cast<uint64_t>(( i_device_type )),\
            static_cast<uint64_t>(( i_gpio_portAddr ))

    /**
     *  @brief Perform a hardware read operation.
     *
     *  @param[in]     i_target     Device target to operate on.
     *  @param[out]    o_buffer     Buffer to put result data into.
     *  @param[in,out] io_buflen    Length of the buffer on input, length of
     *                              data on output (in bytes).
     *  @param[in]     i_accessType Operation to perform on target.
     *  @param[in]     ...          Operation specific addressing parameters.
     *
     *  @return NULL - No error.
     *  @return Non-NULL - An error handle when error has occurred, typically
     *                     passed directly from device driver but potentially
     *                     created by the device framework as in the case of
     *                     not finding an installed driver for the desired
     *                     operation.
     *
     *  It is expected that the callers will use operation specific macros to
     *  assist in the AccessType parameter and variable arguments.
     *
     *  <PRE>
     *  Example usage:
     *      errl = deviceRead(chip, buf, bufsize, DEVICE_SCOM_ADDRESS(0x42));
     *  </PRE>
     *
     */
    errlHndl_t deviceRead(TARGETING::Target* i_target,
                          void* o_buffer, size_t& io_buflen,
                          AccessType i_accessType, ...);

    /**
     *  @brief Perform a hardware write operation.
     *
     *  @param[in]     i_target     Device target to operate on.
     *  @param[in]     i_buffer     Buffer to get write data from.
     *  @param[in,out] io_buflen    Length of the buffer on input, length of
     *                              data on output (in bytes).
     *  @param[in]     i_accessType Operation to perform on target.
     *  @param[in]     ...          Operation specific addressing parameters.
     *
     *  @return NULL - No error.
     *  @return Non-NULL - An error handle when error has occurred, typically
     *                     passed directly from device driver but potentially
     *                     created by the device framework as in the case of
     *                     not finding an installed driver for the desired
     *                     operation.
     *
     *  It is expected that the callers will use operation specific macros to
     *  assist in the AccessType parameter and variable arguments.
     *
     *  <PRE>
     *  Example usage:
     *      errl = deviceWrite(chip, buf, bufsize, DEVICE_SCOM_ADDRESS(0x42));
     *  </PRE>
     *
     */
    errlHndl_t deviceWrite(TARGETING::Target* i_target,
                           void* i_buffer, size_t& io_buflen,
                           AccessType i_accessType, ...);
#endif // not PARSER

};


#endif
OpenPOWER on IntegriCloud