-
Notifications
You must be signed in to change notification settings - Fork 2
/
restool.h
450 lines (368 loc) · 11.5 KB
/
restool.h
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
/* Copyright 2014-2016 Freescale Semiconductor Inc.
* Copyright 2017-2022 NXP
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the above-listed copyright holders nor the
* names of any contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
*
* ALTERNATIVELY, this software may be distributed under the terms of the
* GNU General Public License ("GPL") as published by the Free Software
* Foundation, either version 2 of that License or (at your option) any
* later version.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _RESTOOL_H_
#define _RESTOOL_H_
#include <stdint.h>
#include <stdbool.h>
#include <unistd.h>
#include <limits.h>
#include "mc_v10/fsl_mc_cmd.h"
#include "mc_v10/fsl_dprc.h"
#include "mc_v10/fsl_dpmng.h"
#include "fsl_mc_sys.h"
#include "fsl_mc_ioctl.h"
#define MC_FW_VERSION_9 9
#define MC_FW_VERSION_10 10
/**
* MC object type string max length (without including the null terminator)
*/
#define OBJ_TYPE_MAX_LENGTH 16
/**
* MC resource type string max length (without including the null terminator)
*/
#define RES_TYPE_MAX_LENGTH 15
/**
* Max length of a device file
*/
#define DEV_FILE_SIZE 16
/**
* Max accepted size for a user specified device file
*/
#define USR_DEV_FILE_SIZE 7
/**
* Maximum number of command line options
*/
#define MAX_NUM_CMD_LINE_OPTIONS (sizeof(uint32_t) * 8)
/**
* Maximum level of nesting of DPRCs
*/
#define MAX_DPRC_NESTING 16
/**
* Maximum length of object label (without including the null terminator)
*/
#define MC_OBJ_LABEL_MAX_LENGTH 15
/**
* MC endpoint object type max length (without including the null terminator)
*/
#define EP_OBJ_TYPE_MAX_LEN 15
/**
* MC command high priority flag, original definition is too long
* to be an appropriate pass-in parameter for each flib API
*/
#define PRI MC_CMD_FLAG_PRI
/**
* MC command command completion flag, original definition is too long
* to be an appropriate pass-in parameter for each flib API
*/
#define INTR MC_CMD_FLAG_INTR_DIS
/**
* MC command high priority and command completion flag,
* original definition is too long
* to be an appropriate pass-in parameter for each flib API
*/
#define PRINTR (MC_CMD_FLAG_PRI | INTR MC_CMD_FLAG_INTR_DIS)
/*
* TODO: Obtain the following constants from the fsl-mc bus driver via an ioctl
*/
#define MC_PORTALS_BASE_PADDR 0x00080C000000ULL
#define MC_PORTAL_STRIDE 0x10000
#define MC_PORTAL_SIZE 64
#define MAX_MC_PORTALS 512
#define MC_PORTAL_OFFSET_TO_PORTAL_ID(_portal_offset) \
((_portal_offset) / MC_PORTAL_STRIDE)
struct restool;
typedef int restool_cmd_func_t(void);
struct object_command {
/**
* object-specific command found in the command line
*/
const char *cmd_name;
/**
* Pointer to array of getopt_long options
*/
const struct option *options;
/**
* Pointer to command function
*/
restool_cmd_func_t *cmd_func;
};
/**
* structure to hold mapping from version to object commands
*/
struct obj_command_versions {
/**
* version # of object-type flibs
*/
uint16_t version;
/**
* pointer to the correct array of commands for version #
*/
struct object_command *obj_commands;
};
/**
* Object command parser structure
*/
struct object_cmd_parser {
/**
* object-type found in the command line
*/
const char *obj_type;
/**
* Pointer to array of command/version mappings for the object type
*/
const struct obj_command_versions *obj_commands_versions;
};
/**
* look up table entry for each object version numbers
*/
struct lut_entry {
/**
* Name of object type trying to look up
*/
const char *object;
/**
* array of the different MC Versions this object is found in
*/
struct version_table *versions_table;
};
/**
* holds the MC version as well as the corresponding object version
*/
struct version_table {
/**
* MC Versions this object is found in
*/
uint32_t mc_major_version;
/**
* corresponding object version to MC Version
*/
uint16_t object_version;
};
/**
* Global state of the restool tool
*/
struct restool {
/**
* Bit mask of command-line options not consumed yet
*/
uint32_t global_option_mask;
/**
* Array of option arguments for global options found in the command line,
* that have arguments. One entry per option.
*/
const char *global_option_args[MAX_NUM_CMD_LINE_OPTIONS];
/**
* Pointer to the command being processed
*/
struct object_command *obj_cmd;
/**
* object name found in the command line
*/
const char *obj_name;
/**
* Bit mask of command-line options not consumed yet
*/
uint32_t cmd_option_mask;
/**
* Array of option arguments for options found in the command line,
* that have arguments. One entry per option.
*/
char *cmd_option_args[MAX_NUM_CMD_LINE_OPTIONS];
/**
* MC I/O portal
*/
struct fsl_mc_io mc_io;
/**
* MC firmware version
*/
struct mc_version mc_fw_version;
/**
* Id for the root DPRC in the system
*/
uint32_t root_dprc_id;
/**
* Handle for the root DPRC in the system
*/
uint16_t root_dprc_handle;
/**
* global flag to enable debug printing
*/
bool debug;
/**
* global flag to enable script printing
* it only print out created object name
* instead of the whole sentence
*/
bool script;
/**
* global flag to issue a rescan of the
* entire fsl-mc bus after the MC command
* is run
*/
bool rescan;
/**
* device file used by restool
*/
char device_file[DEV_FILE_SIZE];
/**
* string to hold user specivied device file
*/
char specified_dev_file[USR_DEV_FILE_SIZE];
};
/**
* Command-line option indices for global restool options
*/
enum global_options {
GLOBAL_OPT_HELP = 0,
GLOBAL_OPT_VERSION,
GLOBAL_OPT_MC_VERSION,
GLOBAL_OPT_DEBUG,
GLOBAL_OPT_SCRIPT,
GLOBAL_OPT_ROOT,
GLOBAL_OPT_RESCAN,
};
/* object option map entry */
#define OPTION_MAP_ENTRY(_option) {#_option, _option}
struct option_entry {
const char *str;
uint64_t value;
};
/**
* define generic flib operations
*/
typedef int flib_obj_open_t(struct fsl_mc_io *mc_io,
uint32_t cmd_flags,
int obj_id,
uint16_t *token);
typedef int flib_obj_close_t(struct fsl_mc_io *mc_io,
uint32_t cmd_flags,
uint16_t token);
typedef int flib_obj_get_irq_mask_t(struct fsl_mc_io *mc_io,
uint32_t cmd_flags,
uint16_t token,
uint8_t irq_index,
uint32_t *mask);
typedef int flib_obj_get_irq_status_t(struct fsl_mc_io *mc_io,
uint32_t cmd_flags,
uint16_t token,
uint8_t irq_index,
uint32_t *status);
struct flib_ops {
flib_obj_open_t *obj_open;
flib_obj_close_t *obj_close;
flib_obj_get_irq_mask_t *obj_get_irq_mask;
flib_obj_get_irq_status_t *obj_get_irq_status;
};
extern const struct flib_ops dpaiop_ops;
extern const struct flib_ops dpbp_ops;
extern const struct flib_ops dpci_ops;
extern const struct flib_ops dpcon_ops;
extern const struct flib_ops dpdcei_ops;
extern const struct flib_ops dpdmai_ops;
extern const struct flib_ops dpdmux_ops;
extern const struct flib_ops dpio_ops;
extern const struct flib_ops dpmac_ops;
extern const struct flib_ops dpmcp_ops;
extern const struct flib_ops dpni_ops;
extern const struct flib_ops dprc_ops;
extern const struct flib_ops dprtc_ops;
extern const struct flib_ops dpseci_ops;
extern const struct flib_ops dpsw_ops;
/* functions used for parsing user command line argumments */
int parse_object_name(const char *obj_name,
char *expected_obj_type,
uint32_t *obj_id);
int parse_generic_create_options(char *options_str,
uint64_t *options,
struct option_entry options_map[],
unsigned int num_options);
int get_option_value(int option, long *value,
const char *error_msg,
long min, long max);
/* functions used for printing the result of restool commands */
const char *mc_status_to_string(enum mc_cmd_status status);
enum mc_cmd_status flib_error_to_mc_status(int error);
void print_unexpected_options_error(uint32_t option_mask,
const struct option *options,
unsigned int num_options);
void print_obj_label(struct dprc_obj_desc *target_obj_desc);
int print_obj_verbose(struct dprc_obj_desc *target_obj_desc,
const struct flib_ops *ops);
void print_new_obj(char *type, int id, const char *parent);
/* functions used to handle generic object handling */
int open_dprc(uint32_t dprc_id, uint16_t *dprc_handle);
int find_target_obj_desc(uint32_t dprc_id, uint16_t dprc_handle,
int nesting_level,
uint32_t target_id, char *target_type,
struct dprc_obj_desc *target_obj_desc,
uint32_t *target_parent_dprc_id, bool *found);
bool find_obj(char *obj_type, uint32_t obj_id);
int check_resource_type(char *res_type);
bool in_use(const char *obj, const char *situation);
int get_parent_dprc_id(uint32_t obj_id, char *obj_type,
uint32_t *parent_dprc_id);
extern struct restool restool;
/* command maps for all MC objects */
extern struct object_command dpaiop_commands_v9[];
extern struct object_command dpaiop_commands_v10[];
extern struct object_command dpbp_commands_v9[];
extern struct object_command dpbp_commands_v10[];
extern struct object_command dpci_commands_v9[];
extern struct object_command dpci_commands_v10[];
extern struct object_command dpcon_commands_v9[];
extern struct object_command dpcon_commands_v10[];
extern struct object_command dpdcei_commands_v9[];
extern struct object_command dpdcei_commands_v10[];
extern struct object_command dpdmai_commands_v9[];
extern struct object_command dpdmai_commands_v10[];
extern struct object_command dpdmux_commands_v9[];
extern struct object_command dpdmux_commands_v10[];
extern struct object_command dpio_commands_v9[];
extern struct object_command dpio_commands_v10[];
extern struct object_command dpmac_commands_v9[];
extern struct object_command dpmac_commands_v10[];
extern struct object_command dpmcp_commands_v9[];
extern struct object_command dpmcp_commands_v10[];
extern struct object_command dprc_commands[];
extern struct object_command dprtc_commands_v9[];
extern struct object_command dprtc_commands_v10[];
extern struct object_command dpseci_commands_v9[];
extern struct object_command dpseci_commands_v10[];
extern struct object_command dpni_commands[];
extern struct object_command dpni_commands_v9[];
extern struct object_command dpni_commands_v10[];
extern struct object_command dpsw_commands[];
extern struct object_command dpsw_commands_v9[];
extern struct object_command dpsw_commands_v10[];
extern struct object_command dpdbg_commands[];
#endif /* _RESTOOL_H_ */