pcmciavar.h revision 1.13 1 1.13 haya /* $NetBSD: pcmciavar.h,v 1.13 2000/10/17 10:13:47 haya Exp $ */
2 1.2 thorpej
3 1.2 thorpej /*
4 1.2 thorpej * Copyright (c) 1997 Marc Horowitz. All rights reserved.
5 1.2 thorpej *
6 1.2 thorpej * Redistribution and use in source and binary forms, with or without
7 1.2 thorpej * modification, are permitted provided that the following conditions
8 1.2 thorpej * are met:
9 1.2 thorpej * 1. Redistributions of source code must retain the above copyright
10 1.2 thorpej * notice, this list of conditions and the following disclaimer.
11 1.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
12 1.2 thorpej * notice, this list of conditions and the following disclaimer in the
13 1.2 thorpej * documentation and/or other materials provided with the distribution.
14 1.2 thorpej * 3. All advertising materials mentioning features or use of this software
15 1.2 thorpej * must display the following acknowledgement:
16 1.2 thorpej * This product includes software developed by Marc Horowitz.
17 1.2 thorpej * 4. The name of the author may not be used to endorse or promote products
18 1.2 thorpej * derived from this software without specific prior written permission.
19 1.2 thorpej *
20 1.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.2 thorpej * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.2 thorpej * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.2 thorpej * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.2 thorpej * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.2 thorpej * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.2 thorpej * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.2 thorpej * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.2 thorpej * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.2 thorpej * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.2 thorpej */
31 1.2 thorpej
32 1.2 thorpej #include <sys/types.h>
33 1.2 thorpej #include <sys/queue.h>
34 1.2 thorpej
35 1.2 thorpej #include <machine/bus.h>
36 1.2 thorpej
37 1.2 thorpej #include <dev/pcmcia/pcmciachip.h>
38 1.2 thorpej
39 1.8 marc extern int pcmcia_verbose;
40 1.8 marc
41 1.2 thorpej /*
42 1.2 thorpej * Contains information about mapped/allocated i/o spaces.
43 1.2 thorpej */
44 1.2 thorpej struct pcmcia_io_handle {
45 1.2 thorpej bus_space_tag_t iot; /* bus space tag (from chipset) */
46 1.2 thorpej bus_space_handle_t ioh; /* mapped space handle */
47 1.2 thorpej bus_addr_t addr; /* resulting address in bus space */
48 1.2 thorpej bus_size_t size; /* size of i/o space */
49 1.2 thorpej int flags; /* misc. information */
50 1.2 thorpej };
51 1.2 thorpej
52 1.2 thorpej #define PCMCIA_IO_ALLOCATED 0x01 /* i/o space was allocated */
53 1.2 thorpej
54 1.2 thorpej /*
55 1.2 thorpej * Contains information about allocated memory space.
56 1.2 thorpej */
57 1.2 thorpej struct pcmcia_mem_handle {
58 1.2 thorpej bus_space_tag_t memt; /* bus space tag (from chipset) */
59 1.2 thorpej bus_space_handle_t memh; /* mapped space handle */
60 1.2 thorpej bus_addr_t addr; /* resulting address in bus space */
61 1.2 thorpej bus_size_t size; /* size of mem space */
62 1.2 thorpej pcmcia_mem_handle_t mhandle; /* opaque memory handle */
63 1.2 thorpej bus_size_t realsize; /* how much we really allocated */
64 1.2 thorpej };
65 1.2 thorpej
66 1.2 thorpej /* pcmcia itself */
67 1.2 thorpej
68 1.2 thorpej #define PCMCIA_CFE_MWAIT_REQUIRED 0x0001
69 1.2 thorpej #define PCMCIA_CFE_RDYBSY_ACTIVE 0x0002
70 1.2 thorpej #define PCMCIA_CFE_WP_ACTIVE 0x0004
71 1.2 thorpej #define PCMCIA_CFE_BVD_ACTIVE 0x0008
72 1.2 thorpej #define PCMCIA_CFE_IO8 0x0010
73 1.2 thorpej #define PCMCIA_CFE_IO16 0x0020
74 1.2 thorpej #define PCMCIA_CFE_IRQSHARE 0x0040
75 1.2 thorpej #define PCMCIA_CFE_IRQPULSE 0x0080
76 1.2 thorpej #define PCMCIA_CFE_IRQLEVEL 0x0100
77 1.2 thorpej #define PCMCIA_CFE_POWERDOWN 0x0200
78 1.2 thorpej #define PCMCIA_CFE_READONLY 0x0400
79 1.2 thorpej #define PCMCIA_CFE_AUDIO 0x0800
80 1.2 thorpej
81 1.2 thorpej struct pcmcia_config_entry {
82 1.2 thorpej int number;
83 1.2 thorpej u_int32_t flags;
84 1.2 thorpej int iftype;
85 1.2 thorpej int num_iospace;
86 1.2 thorpej
87 1.2 thorpej /*
88 1.2 thorpej * The card will only decode this mask in any case, so we can
89 1.2 thorpej * do dynamic allocation with this in mind, in case the suggestions
90 1.2 thorpej * below are no good.
91 1.2 thorpej */
92 1.2 thorpej u_long iomask;
93 1.2 thorpej struct {
94 1.2 thorpej u_long length;
95 1.2 thorpej u_long start;
96 1.2 thorpej } iospace[4]; /* XXX this could be as high as 16 */
97 1.2 thorpej u_int16_t irqmask;
98 1.2 thorpej int num_memspace;
99 1.2 thorpej struct {
100 1.2 thorpej u_long length;
101 1.2 thorpej u_long cardaddr;
102 1.2 thorpej u_long hostaddr;
103 1.2 thorpej } memspace[2]; /* XXX this could be as high as 8 */
104 1.2 thorpej int maxtwins;
105 1.2 thorpej SIMPLEQ_ENTRY(pcmcia_config_entry) cfe_list;
106 1.2 thorpej };
107 1.2 thorpej
108 1.13 haya
109 1.13 haya struct pcmcia_funce_disk {
110 1.13 haya int pfd_interface;
111 1.13 haya };
112 1.13 haya
113 1.13 haya struct pcmcia_funce_lan {
114 1.13 haya int pfl_nidlen;
115 1.13 haya u_int8_t pfl_nid[8];
116 1.13 haya };
117 1.13 haya
118 1.13 haya union pcmcia_funce {
119 1.13 haya struct pcmcia_funce_disk pfv_disk;
120 1.13 haya struct pcmcia_funce_lan pfv_lan;
121 1.13 haya };
122 1.13 haya
123 1.13 haya
124 1.2 thorpej struct pcmcia_function {
125 1.2 thorpej /* read off the card */
126 1.2 thorpej int number;
127 1.2 thorpej int function;
128 1.2 thorpej int last_config_index;
129 1.2 thorpej u_long ccr_base;
130 1.2 thorpej u_long ccr_mask;
131 1.2 thorpej SIMPLEQ_HEAD(, pcmcia_config_entry) cfe_head;
132 1.2 thorpej SIMPLEQ_ENTRY(pcmcia_function) pf_list;
133 1.2 thorpej /* run-time state */
134 1.2 thorpej struct pcmcia_softc *sc;
135 1.7 thorpej struct device *child;
136 1.2 thorpej struct pcmcia_config_entry *cfe;
137 1.2 thorpej struct pcmcia_mem_handle pf_pcmh;
138 1.2 thorpej #define pf_ccrt pf_pcmh.memt
139 1.2 thorpej #define pf_ccrh pf_pcmh.memh
140 1.2 thorpej #define pf_ccr_mhandle pf_pcmh.mhandle
141 1.2 thorpej #define pf_ccr_realsize pf_pcmh.realsize
142 1.2 thorpej bus_addr_t pf_ccr_offset;
143 1.2 thorpej int pf_ccr_window;
144 1.4 marc long pf_mfc_iobase;
145 1.4 marc long pf_mfc_iomax;
146 1.2 thorpej int (*ih_fct) __P((void *));
147 1.2 thorpej void *ih_arg;
148 1.2 thorpej int ih_ipl;
149 1.2 thorpej int pf_flags;
150 1.13 haya
151 1.13 haya union pcmcia_funce pf_funce; /* CISTPL_FUNCE */
152 1.13 haya #define pf_funce_disk_interface pf_funce.pfv_disk.pfd_interface
153 1.13 haya #define pf_funce_lan_nid pf_funce.pfv_lan.pfl_nid
154 1.13 haya #define pf_funce_lan_nidlen pf_funce.pfv_lan.pfl_nidlen
155 1.2 thorpej };
156 1.2 thorpej
157 1.2 thorpej /* pf_flags */
158 1.2 thorpej #define PFF_ENABLED 0x0001 /* function is enabled */
159 1.2 thorpej
160 1.2 thorpej struct pcmcia_card {
161 1.2 thorpej int cis1_major;
162 1.2 thorpej int cis1_minor;
163 1.2 thorpej /* XXX waste of space? */
164 1.2 thorpej char cis1_info_buf[256];
165 1.2 thorpej char *cis1_info[4];
166 1.3 enami /*
167 1.3 enami * Use int32_t for manufacturer and product so that they can
168 1.3 enami * hold the id value found in card CIS and special value that
169 1.3 enami * indicates no id was found.
170 1.3 enami */
171 1.3 enami int32_t manufacturer;
172 1.5 christos #define PCMCIA_VENDOR_INVALID -1
173 1.3 enami int32_t product;
174 1.3 enami #define PCMCIA_PRODUCT_INVALID -1
175 1.2 thorpej u_int16_t error;
176 1.5 christos #define PCMCIA_CIS_INVALID { NULL, NULL, NULL, NULL }
177 1.2 thorpej SIMPLEQ_HEAD(, pcmcia_function) pf_head;
178 1.2 thorpej };
179 1.2 thorpej
180 1.2 thorpej struct pcmcia_softc {
181 1.2 thorpej struct device dev;
182 1.2 thorpej
183 1.2 thorpej /* this stuff is for the socket */
184 1.2 thorpej pcmcia_chipset_tag_t pct;
185 1.2 thorpej pcmcia_chipset_handle_t pch;
186 1.2 thorpej
187 1.2 thorpej /* this stuff is for the card */
188 1.2 thorpej struct pcmcia_card card;
189 1.2 thorpej void *ih;
190 1.2 thorpej int sc_enabled_count; /* how many functions are
191 1.2 thorpej enabled */
192 1.2 thorpej
193 1.2 thorpej /*
194 1.2 thorpej * These are passed down from the PCMCIA chip, and exist only
195 1.2 thorpej * so that cards with Very Special address allocation needs
196 1.2 thorpej * know what range they should be dealing with.
197 1.2 thorpej */
198 1.2 thorpej bus_addr_t iobase; /* start i/o space allocation here */
199 1.2 thorpej bus_size_t iosize; /* size of the i/o space range */
200 1.2 thorpej };
201 1.2 thorpej
202 1.8 marc struct pcmcia_cis_quirk {
203 1.8 marc int32_t manufacturer;
204 1.8 marc int32_t product;
205 1.9 marc char *cis1_info[4];
206 1.8 marc struct pcmcia_function *pf;
207 1.8 marc struct pcmcia_config_entry *cfe;
208 1.8 marc };
209 1.8 marc
210 1.2 thorpej struct pcmcia_attach_args {
211 1.3 enami int32_t manufacturer;
212 1.3 enami int32_t product;
213 1.2 thorpej struct pcmcia_card *card;
214 1.2 thorpej struct pcmcia_function *pf;
215 1.2 thorpej };
216 1.2 thorpej
217 1.2 thorpej struct pcmcia_tuple {
218 1.2 thorpej unsigned int code;
219 1.2 thorpej unsigned int length;
220 1.2 thorpej u_long mult;
221 1.2 thorpej bus_addr_t ptr;
222 1.2 thorpej bus_space_tag_t memt;
223 1.2 thorpej bus_space_handle_t memh;
224 1.2 thorpej };
225 1.10 cgd
226 1.10 cgd struct pcmcia_product {
227 1.10 cgd const char *pp_name; /* NULL if end of table */
228 1.10 cgd u_int32_t pp_vendor;
229 1.10 cgd u_int32_t pp_product;
230 1.10 cgd int pp_expfunc;
231 1.10 cgd };
232 1.10 cgd
233 1.10 cgd typedef int (*pcmcia_product_match_fn) __P((struct pcmcia_attach_args *pa,
234 1.10 cgd const struct pcmcia_product *ent, int vpfmatch));
235 1.10 cgd
236 1.10 cgd const struct pcmcia_product
237 1.10 cgd *pcmcia_product_lookup __P((struct pcmcia_attach_args *pa,
238 1.10 cgd const struct pcmcia_product *tab, size_t ent_size,
239 1.10 cgd pcmcia_product_match_fn matchfn));
240 1.11 augustss
241 1.12 enami void pcmcia_devinfo __P((struct pcmcia_card *card, int showhex, char *cp,
242 1.12 enami int cplen));
243 1.2 thorpej
244 1.2 thorpej void pcmcia_read_cis __P((struct pcmcia_softc *));
245 1.8 marc void pcmcia_check_cis_quirks __P((struct pcmcia_softc *));
246 1.2 thorpej void pcmcia_print_cis __P((struct pcmcia_softc *));
247 1.2 thorpej int pcmcia_scan_cis __P((struct device * dev,
248 1.2 thorpej int (*) (struct pcmcia_tuple *, void *), void *));
249 1.2 thorpej
250 1.2 thorpej #define pcmcia_cis_read_1(tuple, idx0) \
251 1.2 thorpej (bus_space_read_1((tuple)->memt, (tuple)->memh, (tuple)->mult*(idx0)))
252 1.2 thorpej
253 1.2 thorpej #define pcmcia_tuple_read_1(tuple, idx1) \
254 1.2 thorpej (pcmcia_cis_read_1((tuple), ((tuple)->ptr+(2+(idx1)))))
255 1.2 thorpej
256 1.2 thorpej #define pcmcia_tuple_read_2(tuple, idx2) \
257 1.2 thorpej (pcmcia_tuple_read_1((tuple), (idx2)) | \
258 1.2 thorpej (pcmcia_tuple_read_1((tuple), (idx2)+1)<<8))
259 1.2 thorpej
260 1.2 thorpej #define pcmcia_tuple_read_3(tuple, idx3) \
261 1.2 thorpej (pcmcia_tuple_read_1((tuple), (idx3)) | \
262 1.2 thorpej (pcmcia_tuple_read_1((tuple), (idx3)+1)<<8) | \
263 1.2 thorpej (pcmcia_tuple_read_1((tuple), (idx3)+2)<<16))
264 1.2 thorpej
265 1.2 thorpej #define pcmcia_tuple_read_4(tuple, idx4) \
266 1.2 thorpej (pcmcia_tuple_read_1((tuple), (idx4)) | \
267 1.2 thorpej (pcmcia_tuple_read_1((tuple), (idx4)+1)<<8) | \
268 1.2 thorpej (pcmcia_tuple_read_1((tuple), (idx4)+2)<<16) | \
269 1.2 thorpej (pcmcia_tuple_read_1((tuple), (idx4)+3)<<24))
270 1.2 thorpej
271 1.2 thorpej #define pcmcia_tuple_read_n(tuple, n, idxn) \
272 1.2 thorpej (((n)==1)?pcmcia_tuple_read_1((tuple), (idxn)) : \
273 1.2 thorpej (((n)==2)?pcmcia_tuple_read_2((tuple), (idxn)) : \
274 1.2 thorpej (((n)==3)?pcmcia_tuple_read_3((tuple), (idxn)) : \
275 1.2 thorpej /* n == 4 */ pcmcia_tuple_read_4((tuple), (idxn)))))
276 1.2 thorpej
277 1.2 thorpej #define PCMCIA_SPACE_MEMORY 1
278 1.2 thorpej #define PCMCIA_SPACE_IO 2
279 1.2 thorpej
280 1.2 thorpej int pcmcia_ccr_read __P((struct pcmcia_function *, int));
281 1.2 thorpej void pcmcia_ccr_write __P((struct pcmcia_function *, int, int));
282 1.2 thorpej
283 1.2 thorpej #define pcmcia_mfc(sc) ((sc)->card.pf_head.sqh_first && \
284 1.2 thorpej (sc)->card.pf_head.sqh_first->pf_list.sqe_next)
285 1.2 thorpej
286 1.2 thorpej void pcmcia_function_init __P((struct pcmcia_function *,
287 1.2 thorpej struct pcmcia_config_entry *));
288 1.2 thorpej int pcmcia_function_enable __P((struct pcmcia_function *));
289 1.2 thorpej void pcmcia_function_disable __P((struct pcmcia_function *));
290 1.2 thorpej
291 1.2 thorpej #define pcmcia_io_alloc(pf, start, size, align, pciop) \
292 1.2 thorpej (pcmcia_chip_io_alloc((pf)->sc->pct, pf->sc->pch, (start), \
293 1.2 thorpej (size), (align), (pciop)))
294 1.6 thorpej
295 1.6 thorpej #define pcmcia_io_free(pf, pciohp) \
296 1.6 thorpej (pcmcia_chip_io_free((pf)->sc->pct, (pf)->sc->pch, (pciohp)))
297 1.2 thorpej
298 1.2 thorpej int pcmcia_io_map __P((struct pcmcia_function *, int, bus_addr_t,
299 1.2 thorpej bus_size_t, struct pcmcia_io_handle *, int *));
300 1.7 thorpej void pcmcia_io_unmap __P((struct pcmcia_function *, int));
301 1.2 thorpej
302 1.2 thorpej #define pcmcia_mem_alloc(pf, size, pcmhp) \
303 1.2 thorpej (pcmcia_chip_mem_alloc((pf)->sc->pct, (pf)->sc->pch, (size), (pcmhp)))
304 1.2 thorpej
305 1.2 thorpej #define pcmcia_mem_free(pf, pcmhp) \
306 1.2 thorpej (pcmcia_chip_mem_free((pf)->sc->pct, (pf)->sc->pch, (pcmhp)))
307 1.2 thorpej
308 1.2 thorpej #define pcmcia_mem_map(pf, kind, card_addr, size, pcmhp, offsetp, windowp) \
309 1.2 thorpej (pcmcia_chip_mem_map((pf)->sc->pct, (pf)->sc->pch, (kind), \
310 1.2 thorpej (card_addr), (size), (pcmhp), (offsetp), (windowp)))
311 1.2 thorpej
312 1.2 thorpej #define pcmcia_mem_unmap(pf, window) \
313 1.2 thorpej (pcmcia_chip_mem_unmap((pf)->sc->pct, (pf)->sc->pch, (window)))
314 1.2 thorpej
315 1.2 thorpej void *pcmcia_intr_establish __P((struct pcmcia_function *, int,
316 1.2 thorpej int (*) (void *), void *));
317 1.2 thorpej void pcmcia_intr_disestablish __P((struct pcmcia_function *, void *));
318