1/*-
2 * Copyright (C) 2009-2012 Semihalf
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD$
27 */
28
29#ifndef _NANDSIM_CONFPARSER_H_
30#define _NANDSIM_CONFPARSER_H_
31
32#define VALUE_UINT	0x08
33#define VALUE_INT	0x10
34#define VALUE_UINTARRAY	0x18
35#define VALUE_INTARRAY	0x20
36#define VALUE_STRING	0x28
37#define VALUE_CHAR	0x40
38#define VALUE_BOOL	0x48
39
40#define SIZE_8	0x01
41#define SIZE_16	0x02
42#define SIZE_32	0x04
43
44#include "nandsim_rcfile.h"
45
46/*
47 * keyname	= name of a key,
48 * mandatory	= is key mandatory in section belonging to, 0=false 1=true
49 * valuetype	= what kind of value is assigned to that key, e.g.
50 *		  VALUE_UINT | SIZE_8 -- unsigned uint size 8 bits;
51 *		  VALUE_UINTARRAY | SIZE_8 -- array of uints 8-bit long;
52 *		  VALUE_BOOL -- 'on', 'off','true','false','yes' or 'no'
53 *		  literals;
54 *		  VALUE_STRING -- strings
55 * field	= ptr to the field that should hold value for parsed value
56 * maxlength	= contains maximum length of an array (used only with either
57 *		  VALUE_STRING or VALUE_(U)INTARRAY value types.
58 */
59struct nandsim_key {
60	const char	*keyname;
61	uint8_t		mandatory;
62	uint8_t		valuetype;
63	void		*field;
64	uint32_t	maxlength;
65};
66struct nandsim_section {
67	const char		*name;
68	struct nandsim_key	*keys;
69};
70
71struct nandsim_config {
72	struct sim_param	**simparams;
73	struct sim_chip		**simchips;
74	struct sim_ctrl		**simctrls;
75	int			chipcnt;
76	int			ctrlcnt;
77};
78
79int parse_intarray(char *, int **);
80int parse_config(char *, const char *);
81int parse_section(struct rcfile *, const char *, int);
82int compare_configs(struct nandsim_config *, struct nandsim_config *);
83int convert_argint(char *, int *);
84int convert_arguint(char *, unsigned int *);
85
86#endif /* _NANDSIM_CONFPARSER_H_ */
87