1#ifndef _DUMPREGS_
2#define	_DUMPREGS_
3/*-
4 * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer,
12 *    without modification.
13 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
14 *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
15 *    redistribution must be conditioned upon including a substantially
16 *    similar Disclaimer requirement for further binary redistribution.
17 *
18 * NO WARRANTY
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
22 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
24 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
27 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29 * THE POSSIBILITY OF SUCH DAMAGES.
30 */
31
32#define	__constructor	__attribute__((constructor))
33
34struct dumpreg {
35	uint32_t	addr;
36	const char	*name;
37	const char	*bits;
38	int		type;
39	u_int		srevMin, srevMax;
40	u_int		phyMin, phyMax;
41};
42#define	SREV(v,r)	(((v) << 16) | (r))
43#define	MAC_MATCH(dr, mv, mr) \
44	((dr)->srevMin <= SREV(mv,mr) && SREV(mv,mr) < (dr)->srevMax)
45
46#define	PHY_MATCH(dr, pr) \
47	((dr)->phyMin <= (pr) && (pr) < (dr)->phyMax)
48#define	PHYANY	0,0xffff
49
50enum {
51	DUMP_BASIC	= 0x0001,	/* basic/default registers */
52	DUMP_KEYCACHE	= 0x0002,	/* key cache */
53	DUMP_BASEBAND	= 0x0004,	/* baseband */
54	DUMP_INTERRUPT	= 0x0008,	/* interrupt state */
55	DUMP_XR		= 0x0010,	/* XR state */
56	DUMP_QCU	= 0x0020,	/* QCU state */
57	DUMP_DCU	= 0x0040,	/* DCU state */
58
59	DUMP_PUBLIC	= 0x0061,	/* public = BASIC+QCU+DCU */
60	DUMP_ALL	= 0xffff
61};
62
63#define	_DEFREG(_addr, _name, _type) \
64    { .addr = _addr, .name = _name, .type = _type }
65#define	_DEFREGx(_addr, _name, _type, _srevmin, _srevmax) \
66    { .addr = _addr, .name = _name, .type = _type, \
67     .srevMin = _srevmin, .srevMax = _srevmax }
68#define	_DEFREGfmt(_addr, _name, _type, _fmt) \
69    { .addr = _addr, .name = _name, .type = _type, .bits = _fmt }
70#define	DEFVOID(_addr, _name)	_DEFREG(_addr, _name, 0)
71#define	DEFVOIDx(_addr, _name, _smin, _smax) \
72	__DEFREGx(_addr, _name, _smin, _smax, 0)
73#define	DEFVOIDfmt(_addr, _name, _fmt) \
74	_DEFREGfmt(_addr, _name, 0, _fmt)
75#define	DEFBASIC(_addr, _name)	_DEFREG(_addr, _name, DUMP_BASIC)
76#define	DEFBASICfmt(_addr, _name, _fmt) \
77	_DEFREGfmt(_addr, _name, DUMP_BASIC, _fmt)
78#define	DEFBASICx(_addr, _name, _smin, _smax) \
79	_DEFREGx(_addr, _name, DUMP_BASIC, _smin, _smax)
80#define	DEFBB(_addr, _name)	_DEFREG(_addr, _name, DUMP_BASEBAND)
81#define	DEFINT(_addr, _name)	_DEFREG(_addr, _name, DUMP_INTERRUPT)
82#define	DEFINTfmt(_addr, _name, _fmt) \
83	_DEFREGfmt(_addr, _name, DUMP_INTERRUPT, _fmt)
84#define	DEFQCU(_addr, _name)	_DEFREG(_addr, _name, DUMP_QCU)
85#define	DEFDCU(_addr, _name)	_DEFREG(_addr, _name, DUMP_DCU)
86
87void	register_regs(struct dumpreg *_regs, u_int _nregs,
88	    int def_srev_min, int def_srev_max,
89	    int def_phy_min, int def_phy_max);
90void	register_keycache(u_int nslots,
91	    int def_srev_min, int def_srev_max,
92	    int def_phy_min, int def_phy_max);
93void	register_range(u_int brange, u_int erange, int what,
94	    int def_srev_min, int def_srev_max,
95	    int def_phy_min, int def_phy_max);
96#endif /* _DUMPREGS_ */
97