readcis.h revision 185033
1/*
2 * Copyright (c) 1995 Andrew McRae.  All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 * 3. The name of the author may not be used to endorse or promote products
13 *    derived from this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 * $FreeBSD: head/usr.sbin/dumpcis/readcis.h 185033 2008-11-17 22:46:29Z imp $
27 */
28
29struct tuple {
30	struct tuple *next;
31	unsigned char code;
32	int     length;
33	unsigned char *data;
34};
35
36struct tuple_list {
37	struct tuple_list *next;
38	struct tuple *tuples;
39	off_t   offs;
40	int     flags;
41};
42
43struct tuple_info {
44	const char   *name;
45	unsigned char code;
46	unsigned char length;		/* 255 means variable length */
47};
48
49/*
50 *	Memory device descriptor.
51 */
52struct dev_mem {
53	unsigned char valid;
54	unsigned char type;
55	unsigned char speed;
56	unsigned char wps;
57	unsigned char addr;
58	unsigned char units;
59};
60
61/*
62 *	One I/O structure describing a possible I/O map
63 *	of the card.
64 */
65struct cis_ioblk {
66	struct cis_ioblk *next;
67	unsigned int addr;
68	unsigned int size;
69};
70
71/*
72 *	A structure storing a memory map for the card.
73 */
74struct cis_memblk {
75	struct cis_memblk *next;
76	unsigned int address;
77	unsigned int length;
78	unsigned int host_address;
79};
80
81/*
82 *	One configuration entry for the card.
83 */
84struct cis_config {
85	struct cis_config *next;
86	unsigned int pwr:1;		/* Which values are defined. */
87	unsigned int timing:1;
88	unsigned int iospace:1;
89	unsigned int irq:1;
90	unsigned int memspace:1;
91	unsigned int misc_valid:1;
92	unsigned char id;
93	unsigned char io_blks;
94	unsigned char io_addr;
95	unsigned char io_bus;
96	struct cis_ioblk *io;
97	unsigned char irqlevel;
98	unsigned char irq_flags;
99	unsigned irq_mask;
100	unsigned char memwins;
101	struct cis_memblk *mem;
102	unsigned char misc;
103};
104
105/*
106 *	Structure holding all data retrieved from the
107 *	CIS block on the card.
108 *	The default configuration contains interface defaults
109 *	not listed in each separate configuration.
110 */
111struct cis {
112	struct tuple_list *tlist;
113	char    *manuf;
114	char    *vers;
115	char    *add_info1;
116	char    *add_info2;
117	unsigned char maj_v, min_v;
118	unsigned char last_config;
119	unsigned char ccrs;
120	unsigned long reg_addr;
121	u_int manufacturer;
122	u_int product;
123	u_int prodext;
124	unsigned char func_id1, func_id2;
125	struct dev_mem attr_mem;
126	struct dev_mem common_mem;
127	struct cis_config *def_config;
128	struct cis_config *conf;
129	unsigned char *lan_nid;
130};
131
132#define	tpl32(tp)	((*((tp) + 3) << 24) | \
133			 (*((tp) + 2) << 16) | \
134			 (*((tp) + 1) << 8)  | *(tp))
135#define	tpl24(tp)	((*((tp) + 2) << 16) | \
136			 (*((tp) + 1) << 8)  | *(tp))
137#define	tpl16(tp)	((*((tp) + 1) << 8)  | *(tp))
138
139int	dumpcisfile_main(int, char **);
140void    dump(unsigned char *, int);
141void    dumpcis(struct cis *);
142void    freecis(struct cis *);
143struct cis *readcis(int);
144
145const char *tuple_name(unsigned char);
146u_int   parse_num(int, u_char *, u_char **, int);
147
148int isdumpcisfile;
149