Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / sys / bus / pccard / pccardvar.h
1 /*      $NetBSD: pcmciavar.h,v 1.9 1998/12/29 09:00:28 marc Exp $       */
2 /* $FreeBSD: src/sys/dev/pccard/pccardvar.h,v 1.6.2.3 2002/09/01 05:45:51 imp Exp $ */
3 /* $DragonFly: src/sys/bus/pccard/pccardvar.h,v 1.2 2003/06/17 04:28:29 dillon Exp $ */
4
5 /*
6  * Copyright (c) 1997 Marc Horowitz.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *      This product includes software developed by Marc Horowitz.
19  * 4. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <sys/types.h>
35 #include <sys/queue.h>
36
37 #include <machine/bus.h>
38
39 extern int      pccard_verbose;
40
41 /*
42  * Contains information about mapped/allocated i/o spaces.
43  */
44 struct pccard_io_handle {
45         bus_space_tag_t iot;            /* bus space tag (from chipset) */
46         bus_space_handle_t ioh;         /* mapped space handle */
47         bus_addr_t      addr;           /* resulting address in bus space */
48         bus_size_t      size;           /* size of i/o space */
49         int             flags;          /* misc. information */
50         int             width;
51 };
52
53 #define PCCARD_IO_ALLOCATED     0x01    /* i/o space was allocated */
54
55 /*
56  * Contains information about allocated memory space.
57  */
58 struct pccard_mem_handle {
59         bus_space_tag_t memt;           /* bus space tag (from chipset) */
60         bus_space_handle_t memh;        /* mapped space handle */
61         bus_addr_t      addr;           /* resulting address in bus space */
62         bus_size_t      size;           /* size of mem space */
63         bus_size_t      realsize;       /* how much we really allocated */
64         long            offset;
65         int             kind;
66 };
67
68 /* pccard itself */
69
70 #define PCCARD_CFE_MWAIT_REQUIRED       0x0001
71 #define PCCARD_CFE_RDYBSY_ACTIVE        0x0002
72 #define PCCARD_CFE_WP_ACTIVE            0x0004
73 #define PCCARD_CFE_BVD_ACTIVE           0x0008
74 #define PCCARD_CFE_IO8                  0x0010
75 #define PCCARD_CFE_IO16                 0x0020
76 #define PCCARD_CFE_IRQSHARE             0x0040
77 #define PCCARD_CFE_IRQPULSE             0x0080
78 #define PCCARD_CFE_IRQLEVEL             0x0100
79 #define PCCARD_CFE_POWERDOWN            0x0200
80 #define PCCARD_CFE_READONLY             0x0400
81 #define PCCARD_CFE_AUDIO                0x0800
82
83 struct pccard_config_entry {
84         int             number;
85         u_int32_t       flags;
86         int             iftype;
87         int             num_iospace;
88
89         /*
90          * The card will only decode this mask in any case, so we can
91          * do dynamic allocation with this in mind, in case the suggestions
92          * below are no good.
93          */
94         u_long          iomask;
95         struct {
96                 u_long  length;
97                 u_long  start;
98         } iospace[4];           /* XXX this could be as high as 16 */
99         u_int16_t       irqmask;
100         int             num_memspace;
101         struct {
102                 u_long  length;
103                 u_long  cardaddr;
104                 u_long  hostaddr;
105         } memspace[2];          /* XXX this could be as high as 8 */
106         int             maxtwins;
107         STAILQ_ENTRY(pccard_config_entry) cfe_list;
108 };
109
110 struct pccard_function {
111         /* read off the card */
112         int             number;
113         int             function;
114         int             last_config_index;
115         u_long          ccr_base;
116         u_long          ccr_mask;
117         struct resource *ccr_res;
118         int             ccr_rid;
119         STAILQ_HEAD(, pccard_config_entry) cfe_head;
120         STAILQ_ENTRY(pccard_function) pf_list;
121         /* run-time state */
122         struct pccard_softc *sc;
123         struct pccard_config_entry *cfe;
124         struct pccard_mem_handle pf_pcmh;
125 #define pf_ccrt         pf_pcmh.memt
126 #define pf_ccrh         pf_pcmh.memh
127 #define pf_ccr_realsize pf_pcmh.realsize
128         bus_addr_t      pf_ccr_offset;
129         int             pf_ccr_window;
130         long            pf_mfc_iobase;
131         long            pf_mfc_iomax;
132         int             (*ih_fct)(void *);
133         void            *ih_arg;
134         int             ih_ipl;
135         int             pf_flags;
136 };
137
138 /* pf_flags */
139 #define PFF_ENABLED     0x0001          /* function is enabled */
140
141 struct pccard_card {
142         int             cis1_major;
143         int             cis1_minor;
144         /* XXX waste of space? */
145         char            cis1_info_buf[256];
146         char            *cis1_info[4];
147         /*
148          * Use int32_t for manufacturer and product so that they can
149          * hold the id value found in card CIS and special value that
150          * indicates no id was found.
151          */
152         int32_t         manufacturer;
153 #define PCCARD_VENDOR_INVALID   -1
154         int32_t         product;
155 #define PCCARD_PRODUCT_INVALID          -1
156         u_int16_t       error;
157 #define PCCARD_CIS_INVALID              { NULL, NULL, NULL, NULL }
158         STAILQ_HEAD(, pccard_function) pf_head;
159 };
160
161 #define PCCARD_MEM_ATTR         1
162 #define PCCARD_MEM_COMMON       2
163
164 #define PCCARD_WIDTH_AUTO       0
165 #define PCCARD_WIDTH_IO8        1
166 #define PCCARD_WIDTH_IO16       2
167
168 /* More later? */
169 struct pccard_ivar {
170         struct resource_list resources;
171         int     slotnum;
172 };
173
174 struct pccard_softc {
175         device_t                dev;
176         /* this stuff is for the socket */
177
178         /* this stuff is for the card */
179         struct pccard_card card;
180         void            *ih;
181         int             sc_enabled_count;       /* num functions enabled */
182
183 };
184
185 void
186 pccardbus_if_setup(struct pccard_softc*);
187
188 struct pccard_cis_quirk {
189         int32_t manufacturer;
190         int32_t product;
191         char *cis1_info[4];
192         struct pccard_function *pf;
193         struct pccard_config_entry *cfe;
194 };
195
196 struct pccard_tuple {
197         unsigned int    code;
198         unsigned int    length;
199         u_long          mult;
200         bus_addr_t      ptr;
201         bus_space_tag_t memt;
202         bus_space_handle_t memh;
203 };
204
205 void    pccard_read_cis(struct pccard_softc *);
206 void    pccard_check_cis_quirks(device_t);
207 void    pccard_print_cis(device_t);
208 int     pccard_scan_cis(device_t, 
209                 int (*) (struct pccard_tuple *, void *), void *);
210
211 #define pccard_cis_read_1(tuple, idx0)                                  \
212         (bus_space_read_1((tuple)->memt, (tuple)->memh, (tuple)->mult*(idx0)))
213
214 #define pccard_tuple_read_1(tuple, idx1)                                \
215         (pccard_cis_read_1((tuple), ((tuple)->ptr+(2+(idx1)))))
216
217 #define pccard_tuple_read_2(tuple, idx2)                                \
218         (pccard_tuple_read_1((tuple), (idx2)) |                         \
219          (pccard_tuple_read_1((tuple), (idx2)+1)<<8))
220
221 #define pccard_tuple_read_3(tuple, idx3)                                \
222         (pccard_tuple_read_1((tuple), (idx3)) |                         \
223          (pccard_tuple_read_1((tuple), (idx3)+1)<<8) |                  \
224          (pccard_tuple_read_1((tuple), (idx3)+2)<<16))
225
226 #define pccard_tuple_read_4(tuple, idx4)                                \
227         (pccard_tuple_read_1((tuple), (idx4)) |                         \
228          (pccard_tuple_read_1((tuple), (idx4)+1)<<8) |                  \
229          (pccard_tuple_read_1((tuple), (idx4)+2)<<16) |                 \
230          (pccard_tuple_read_1((tuple), (idx4)+3)<<24))
231
232 #define pccard_tuple_read_n(tuple, n, idxn)                             \
233         (((n)==1)?pccard_tuple_read_1((tuple), (idxn)) :                \
234          (((n)==2)?pccard_tuple_read_2((tuple), (idxn)) :               \
235           (((n)==3)?pccard_tuple_read_3((tuple), (idxn)) :              \
236            /* n == 4 */ pccard_tuple_read_4((tuple), (idxn)))))
237
238 #define PCCARD_SPACE_MEMORY     1
239 #define PCCARD_SPACE_IO         2
240
241 int     pccard_ccr_read(struct pccard_function *, int);
242 void    pccard_ccr_write(struct pccard_function *, int, int);
243
244 #define pccard_mfc(sc)  (STAILQ_FIRST(&(sc)->card.pf_head) &&           \
245                  STAILQ_NEXT(STAILQ_FIRST(&(sc)->card.pf_head),pf_list))
246
247 void    pccard_function_init(struct pccard_function *,
248             struct pccard_config_entry *);
249 int     pccard_function_enable(struct pccard_function *);
250 void    pccard_function_disable(struct pccard_function *);
251
252 #define pccard_io_alloc(pf, start, size, align, pciop)                  \
253         (pccard_chip_io_alloc((pf)->sc->pct, pf->sc->pch, (start),      \
254          (size), (align), (pciop)))
255
256 #define pccard_io_free(pf, pciohp)                                      \
257         (pccard_chip_io_free((pf)->sc->pct, (pf)->sc->pch, (pciohp)))
258
259 int     pccard_io_map(struct pccard_function *, int, bus_addr_t,
260             bus_size_t, struct pccard_io_handle *, int *);
261 void    pccard_io_unmap(struct pccard_function *, int);
262
263 #define pccard_mem_alloc(pf, size, pcmhp)                               \
264         (pccard_chip_mem_alloc((pf)->sc->pct, (pf)->sc->pch, (size), (pcmhp)))
265
266 #define pccard_mem_free(pf, pcmhp)                                      \
267         (pccard_chip_mem_free((pf)->sc->pct, (pf)->sc->pch, (pcmhp)))
268
269 #define pccard_mem_map(pf, kind, card_addr, size, pcmhp, offsetp, windowp) \
270         (pccard_chip_mem_map((pf)->sc->pct, (pf)->sc->pch, (kind),      \
271          (card_addr), (size), (pcmhp), (offsetp), (windowp)))
272
273 #define pccard_mem_unmap(pf, window)                                    \
274         (pccard_chip_mem_unmap((pf)->sc->pct, (pf)->sc->pch, (window)))
275
276 /* ivar interface */
277 enum {
278         PCCARD_IVAR_ETHADDR,    /* read ethernet address from CIS tupple */
279         PCCARD_IVAR_VENDOR,
280         PCCARD_IVAR_PRODUCT,
281         PCCARD_IVAR_PRODEXT,
282         PCCARD_IVAR_FUNCTION_NUMBER,
283         PCCARD_IVAR_VENDOR_STR, /* CIS string for "Manufacturer" */
284         PCCARD_IVAR_PRODUCT_STR,/* CIS strnig for "Product" */
285         PCCARD_IVAR_CIS3_STR,
286         PCCARD_IVAR_CIS4_STR,
287         PCCARD_IVAR_FUNCTION
288 };
289
290 /* read ethernet address from CIS tupple */
291 __inline static int
292 pccard_get_ether(device_t dev, u_char *enaddr)
293 {
294         return BUS_READ_IVAR(device_get_parent(dev), dev, 
295             PCCARD_IVAR_ETHADDR, (uintptr_t *)enaddr);
296 }
297
298 /* shared memory flags */
299 enum {
300         PCCARD_A_MEM_ATTR=1,    /* attribute */
301         PCCARD_A_MEM_COM,       /* common */
302         PCCARD_A_MEM_8BIT,      /* 8 bit */
303         PCCARD_A_MEM_16BIT      /* 16 bit */
304 };