1 /* $NetBSD: pcmciavar.h,v 1.33 2008/07/03 19:07:43 drochner Exp $ */
4 * Copyright (c) 1997 Marc Horowitz. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Marc Horowitz.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/types.h>
33 #include <sys/queue.h>
35 #include <dev/pcmcia/pcmciachip.h>
37 extern int pcmcia_verbose
;
40 * Contains information about mapped/allocated i/o spaces.
42 struct pcmcia_io_handle
{
43 bus_space_tag_t iot
; /* bus space tag (from chipset) */
44 bus_space_handle_t ioh
; /* mapped space handle */
45 bus_addr_t addr
; /* resulting address in bus space */
46 bus_size_t size
; /* size of i/o space */
47 int flags
; /* misc. information */
48 void *ihandle
; /* opaque i/o handle */
51 #define PCMCIA_IO_ALLOCATED 0x01 /* i/o space was allocated */
54 * Contains information about allocated memory space.
56 struct pcmcia_mem_handle
{
57 bus_space_tag_t memt
; /* bus space tag (from chipset) */
58 bus_space_handle_t memh
; /* mapped space handle */
59 bus_addr_t addr
; /* resulting address in bus space */
60 bus_size_t size
; /* size of mem space */
61 pcmcia_mem_handle_t mhandle
; /* opaque memory handle */
62 bus_size_t realsize
; /* how much we really allocated */
67 #define PCMCIA_CFE_MWAIT_REQUIRED 0x0001
68 #define PCMCIA_CFE_RDYBSY_ACTIVE 0x0002
69 #define PCMCIA_CFE_WP_ACTIVE 0x0004
70 #define PCMCIA_CFE_BVD_ACTIVE 0x0008
71 #define PCMCIA_CFE_IO8 0x0010
72 #define PCMCIA_CFE_IO16 0x0020
73 #define PCMCIA_CFE_IRQSHARE 0x0040
74 #define PCMCIA_CFE_IRQPULSE 0x0080
75 #define PCMCIA_CFE_IRQLEVEL 0x0100
76 #define PCMCIA_CFE_POWERDOWN 0x0200
77 #define PCMCIA_CFE_READONLY 0x0400
78 #define PCMCIA_CFE_AUDIO 0x0800
80 struct pcmcia_config_entry
{
87 * The card will only decode this mask in any case, so we can
88 * do dynamic allocation with this in mind, in case the suggestions
96 struct pcmcia_io_handle handle
;
98 } iospace
[4]; /* XXX this could be as high as 16 */
106 struct pcmcia_mem_handle handle
;
110 } memspace
[2]; /* XXX this could be as high as 8 */
112 SIMPLEQ_ENTRY(pcmcia_config_entry
) cfe_list
;
116 struct pcmcia_funce_disk
{
120 struct pcmcia_funce_lan
{
126 struct pcmcia_funce_disk pfv_disk
;
127 struct pcmcia_funce_lan pfv_lan
;
131 struct pcmcia_function
{
132 /* read off the card */
135 int last_config_index
;
138 SIMPLEQ_HEAD(, pcmcia_config_entry
) cfe_head
;
139 SIMPLEQ_ENTRY(pcmcia_function
) pf_list
;
141 struct pcmcia_softc
*sc
;
143 struct pcmcia_config_entry
*cfe
;
144 struct pcmcia_mem_handle pf_pcmh
;
145 #define pf_ccrt pf_pcmh.memt
146 #define pf_ccrh pf_pcmh.memh
147 #define pf_ccr_mhandle pf_pcmh.mhandle
148 #define pf_ccr_realsize pf_pcmh.realsize
149 bus_size_t pf_ccr_offset
;
151 bus_addr_t pf_mfc_iobase
;
152 bus_addr_t pf_mfc_iomax
;
156 union pcmcia_funce pf_funce
; /* CISTPL_FUNCE */
157 #define pf_funce_disk_interface pf_funce.pfv_disk.pfd_interface
158 #define pf_funce_lan_nid pf_funce.pfv_lan.pfl_nid
159 #define pf_funce_lan_nidlen pf_funce.pfv_lan.pfl_nidlen
163 #define PFF_ENABLED 0x0001 /* function is enabled */
164 #define PFF_DETACHED 0x0002 /* card is detached */
166 SIMPLEQ_HEAD(pcmcia_function_head
, pcmcia_function
);
171 /* XXX waste of space? */
172 char cis1_info_buf
[256];
175 * Use int32_t for manufacturer and product so that they can
176 * hold the id value found in card CIS and special value that
177 * indicates no id was found.
179 int32_t manufacturer
;
180 #define PCMCIA_VENDOR_INVALID -1
182 #define PCMCIA_PRODUCT_INVALID -1
184 #define PCMCIA_CIS_INVALID { NULL, NULL, NULL, NULL }
185 struct pcmcia_function_head pf_head
;
188 struct pcmcia_softc
{
191 /* this stuff is for the socket */
192 pcmcia_chipset_tag_t pct
;
193 pcmcia_chipset_handle_t pch
;
195 /* this stuff is for the card */
196 struct pcmcia_card card
;
198 int sc_enabled_count
; /* how many functions are
202 * These are passed down from the PCMCIA chip, and exist only
203 * so that cards with Very Special address allocation needs
204 * know what range they should be dealing with.
206 bus_addr_t iobase
; /* start i/o space allocation here */
207 bus_size_t iosize
; /* size of the i/o space range */
210 struct pcmcia_cis_quirk
{
211 int32_t manufacturer
;
213 const char *cis1_info
[4];
214 const struct pcmcia_function
*pf
;
215 const struct pcmcia_config_entry
*cfe
;
218 struct pcmcia_attach_args
{
219 int32_t manufacturer
;
221 struct pcmcia_card
*card
;
222 struct pcmcia_function
*pf
;
225 struct pcmcia_tuple
{
230 bus_space_tag_t memt
;
231 bus_space_handle_t memh
;
234 struct pcmcia_product
{
236 u_int32_t pp_product
;
237 const char *pp_cisinfo
[4];
240 typedef int (*pcmcia_product_match_fn
)(struct pcmcia_attach_args
*,
241 const struct pcmcia_product
*, int);
243 const void *pcmcia_product_lookup(struct pcmcia_attach_args
*, const void *,
244 size_t, size_t, pcmcia_product_match_fn
);
246 void pcmcia_devinfo(struct pcmcia_card
*, int, char *, size_t);
248 void pcmcia_read_cis(struct pcmcia_softc
*);
249 void pcmcia_check_cis_quirks(struct pcmcia_softc
*);
250 void pcmcia_print_cis(struct pcmcia_softc
*);
251 int pcmcia_scan_cis(device_t
,
252 int (*) (struct pcmcia_tuple
*, void *), void *);
254 #define pcmcia_cis_read_1(tuple, idx0) \
255 (bus_space_read_1((tuple)->memt, (tuple)->memh, (tuple)->mult*(idx0)))
257 #define pcmcia_tuple_read_1(tuple, idx1) \
258 (pcmcia_cis_read_1((tuple), ((tuple)->ptr+(2+(idx1)))))
260 #define pcmcia_tuple_read_2(tuple, idx2) \
261 (pcmcia_tuple_read_1((tuple), (idx2)) | \
262 (pcmcia_tuple_read_1((tuple), (idx2)+1)<<8))
264 #define pcmcia_tuple_read_3(tuple, idx3) \
265 (pcmcia_tuple_read_1((tuple), (idx3)) | \
266 (pcmcia_tuple_read_1((tuple), (idx3)+1)<<8) | \
267 (pcmcia_tuple_read_1((tuple), (idx3)+2)<<16))
269 #define pcmcia_tuple_read_4(tuple, idx4) \
270 (pcmcia_tuple_read_1((tuple), (idx4)) | \
271 (pcmcia_tuple_read_1((tuple), (idx4)+1)<<8) | \
272 (pcmcia_tuple_read_1((tuple), (idx4)+2)<<16) | \
273 (pcmcia_tuple_read_1((tuple), (idx4)+3)<<24))
275 #define pcmcia_tuple_read_n(tuple, n, idxn) \
276 (((n)==1)?pcmcia_tuple_read_1((tuple), (idxn)) : \
277 (((n)==2)?pcmcia_tuple_read_2((tuple), (idxn)) : \
278 (((n)==3)?pcmcia_tuple_read_3((tuple), (idxn)) : \
279 /* n == 4 */ pcmcia_tuple_read_4((tuple), (idxn)))))
281 #define PCMCIA_SPACE_MEMORY 1
282 #define PCMCIA_SPACE_IO 2
284 int pcmcia_ccr_read(struct pcmcia_function
*, int);
285 void pcmcia_ccr_write(struct pcmcia_function
*, int, int);
287 #define pcmcia_mfc(sc) (! SIMPLEQ_EMPTY(&(sc)->card.pf_head) && \
288 SIMPLEQ_NEXT(SIMPLEQ_FIRST(&(sc)->card.pf_head), pf_list))
290 void pcmcia_socket_enable(device_t
);
291 void pcmcia_socket_disable(device_t
);
292 void pcmcia_socket_settype(device_t
, int);
294 int pcmcia_config_alloc(struct pcmcia_function
*,
295 struct pcmcia_config_entry
*);
296 void pcmcia_config_free(struct pcmcia_function
*);
297 int pcmcia_config_map(struct pcmcia_function
*);
298 void pcmcia_config_unmap(struct pcmcia_function
*);
301 int pcmcia_function_configure(struct pcmcia_function
*,
302 int (*validator
)(struct pcmcia_config_entry
*));
303 void pcmcia_function_unconfigure(struct pcmcia_function
*);
304 void pcmcia_function_init(struct pcmcia_function
*,
305 struct pcmcia_config_entry
*);
306 int pcmcia_function_enable(struct pcmcia_function
*);
307 void pcmcia_function_disable(struct pcmcia_function
*);
309 #define pcmcia_io_alloc(pf, start, size, align, pciop) \
310 (pcmcia_chip_io_alloc((pf)->sc->pct, pf->sc->pch, (start), \
311 (size), (align), (pciop)))
313 #define pcmcia_io_free(pf, pciohp) \
314 (pcmcia_chip_io_free((pf)->sc->pct, (pf)->sc->pch, (pciohp)))
316 int pcmcia_io_map(struct pcmcia_function
*, int,
317 struct pcmcia_io_handle
*, int *);
318 void pcmcia_io_unmap(struct pcmcia_function
*, int);
320 void pcmcia_free_pf(struct pcmcia_function_head
*);
322 #define pcmcia_mem_alloc(pf, size, pcmhp) \
323 (pcmcia_chip_mem_alloc((pf)->sc->pct, (pf)->sc->pch, (size), (pcmhp)))
325 #define pcmcia_mem_free(pf, pcmhp) \
326 (pcmcia_chip_mem_free((pf)->sc->pct, (pf)->sc->pch, (pcmhp)))
328 #define pcmcia_mem_map(pf, kind, card_addr, size, pcmhp, offsetp, windowp) \
329 (pcmcia_chip_mem_map((pf)->sc->pct, (pf)->sc->pch, (kind), \
330 (card_addr), (size), (pcmhp), (offsetp), (windowp)))
332 #define pcmcia_mem_unmap(pf, window) \
333 (pcmcia_chip_mem_unmap((pf)->sc->pct, (pf)->sc->pch, (window)))
335 void *pcmcia_intr_establish(struct pcmcia_function
*, int,
336 int (*) (void *), void *);
337 void pcmcia_intr_disestablish(struct pcmcia_function
*, void *);