Initial import from FreeBSD RELENG_4:
[dragonfly.git] / usr.sbin / pccard / pccardd / readcis.h
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: src/usr.sbin/pccard/pccardd/readcis.h,v 1.11.2.2 2000/06/05 14:59:03 iwasaki Exp $
27  */
28
29 struct tuple {
30         struct tuple *next;
31         unsigned char code;
32         int     length;
33         unsigned char *data;
34 };
35
36 struct tuple_list {
37         struct tuple_list *next;
38         struct tuple *tuples;
39         off_t   offs;
40         int     flags;
41 };
42
43 struct tuple_info {
44         char   *name;
45         unsigned char code;
46         unsigned char length;           /* 255 means variable length */
47 };
48
49 /*
50  *      Memory device descriptor.
51  */
52 struct 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  */
65 struct 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  */
74 struct 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  */
84 struct 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  */
111 struct 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         unsigned char func_id1, func_id2;
122         struct dev_mem attr_mem;
123         struct dev_mem common_mem;
124         struct cis_config *def_config;
125         struct cis_config *conf;
126         unsigned char *lan_nid;
127 };
128
129 #define tpl32(tp)       ((*((tp) + 3) << 24) | \
130                          (*((tp) + 2) << 16) | \
131                          (*((tp) + 1) << 8)  | *(tp))
132 #define tpl24(tp)       ((*((tp) + 2) << 16) | \
133                          (*((tp) + 1) << 8)  | *(tp))
134 #define tpl16(tp)       ((*((tp) + 1) << 8)  | *(tp))
135
136 void   *xmalloc(int);
137 void    dump(unsigned char *, int);
138 void    dumpcis(struct cis *);
139 void    freecis(struct cis *);
140 struct cis *readcis(int);
141
142 char   *tuple_name(unsigned char);
143 u_int   parse_num(int, u_char *, u_char **, int);