1 /* $NetBSD: pcmciavar.h,v 1.12 2000/02/08 12:51:31 enami Exp $ */
2 /* $FreeBSD: src/sys/dev/pccard/pccardvar.h,v 1.54 2005/07/13 15:00:59 imp Exp $ */
5 * Copyright (c) 1997 Marc Horowitz. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Marc Horowitz.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 * PCCARD_API_LEVEL. When set to 5, we provide a 5.x compatable API
35 * for driver writers that have to share their code between 5.x and 6.x.
36 * The 5.x compatibility interfaces will be unsupported in 7.0, at which
37 * point we'll only support 6 and newer, etc.
39 #ifndef PCCARD_API_LEVEL
40 #define PCCARD_API_LEVEL 5
41 #elif PCCARD_API_LEVEL < 5
42 #error "pccard API less than 5 unsupported"
46 * Contains information about mapped/allocated i/o spaces.
48 struct pccard_io_handle
{
49 bus_space_tag_t iot
; /* bus space tag (from chipset) */
50 bus_space_handle_t ioh
; /* mapped space handle */
51 bus_addr_t addr
; /* resulting address in bus space */
52 bus_size_t size
; /* size of i/o space */
53 int flags
; /* misc. information */
57 #define PCCARD_IO_ALLOCATED 0x01 /* i/o space was allocated */
60 * Contains information about allocated memory space.
62 struct pccard_mem_handle
{
63 bus_space_tag_t memt
; /* bus space tag (from chipset) */
64 bus_space_handle_t memh
; /* mapped space handle */
65 bus_addr_t addr
; /* resulting address in bus space */
66 bus_size_t size
; /* size of mem space */
67 bus_size_t realsize
; /* how much we really allocated */
68 bus_addr_t cardaddr
; /* Absolute address on card */
74 #define PCCARD_CFE_MWAIT_REQUIRED 0x0001
75 #define PCCARD_CFE_RDYBSY_ACTIVE 0x0002
76 #define PCCARD_CFE_WP_ACTIVE 0x0004
77 #define PCCARD_CFE_BVD_ACTIVE 0x0008
78 #define PCCARD_CFE_IO8 0x0010
79 #define PCCARD_CFE_IO16 0x0020
80 #define PCCARD_CFE_IRQSHARE 0x0040
81 #define PCCARD_CFE_IRQPULSE 0x0080
82 #define PCCARD_CFE_IRQLEVEL 0x0100
83 #define PCCARD_CFE_POWERDOWN 0x0200
84 #define PCCARD_CFE_READONLY 0x0400
85 #define PCCARD_CFE_AUDIO 0x0800
87 struct pccard_config_entry
{
94 * The card will only decode this mask in any case, so we can
95 * do dynamic allocation with this in mind, in case the suggestions
102 } iospace
[4]; /* XXX this could be as high as 16 */
109 } memspace
[2]; /* XXX this could be as high as 8 */
111 STAILQ_ENTRY(pccard_config_entry
) cfe_list
;
114 struct pccard_funce_disk
{
118 struct pccard_funce_lan
{
124 struct pccard_funce_disk pfv_disk
;
125 struct pccard_funce_lan pfv_lan
;
128 struct pccard_function
{
129 /* read off the card */
132 int last_config_index
;
133 uint32_t ccr_base
; /* Offset with card's memory */
135 struct resource
*ccr_res
;
137 STAILQ_HEAD(, pccard_config_entry
) cfe_head
;
138 STAILQ_ENTRY(pccard_function
) pf_list
;
140 struct pccard_softc
*sc
;
141 struct pccard_config_entry
*cfe
;
142 struct pccard_mem_handle pf_pcmh
;
144 #define pf_ccrt pf_pcmh.memt
145 #define pf_ccrh pf_pcmh.memh
146 #define pf_ccr_realsize pf_pcmh.realsize
147 uint32_t pf_ccr_offset
; /* Offset from ccr_base of CIS */
149 bus_addr_t pf_mfc_iobase
;
150 bus_addr_t pf_mfc_iomax
;
152 driver_intr_t
*intr_handler
;
153 void *intr_handler_arg
;
154 void *intr_handler_cookie
;
156 union pccard_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 */
168 /* XXX waste of space? */
169 char cis1_info_buf
[256];
172 * Use int32_t for manufacturer and product so that they can
173 * hold the id value found in card CIS and special value that
174 * indicates no id was found.
176 int32_t manufacturer
;
177 #define PCMCIA_VENDOR_INVALID -1
179 #define PCMCIA_PRODUCT_INVALID -1
182 #define PCMCIA_CIS_INVALID { NULL, NULL, NULL, NULL }
183 STAILQ_HEAD(, pccard_function
) pf_head
;
186 #define PCCARD_WIDTH_AUTO 0
187 #define PCCARD_WIDTH_IO8 1
188 #define PCCARD_WIDTH_IO16 2
192 struct resource_list resources
;
193 struct pccard_function
*pf
;
196 struct pccard_softc
{
198 /* this stuff is for the socket */
200 /* this stuff is for the card */
201 struct pccard_card card
;
202 int sc_enabled_count
; /* num functions enabled */
205 struct pccard_cis_quirk
{
206 int32_t manufacturer
;
209 struct pccard_function
*pf
;
210 struct pccard_config_entry
*cfe
;
213 struct pccard_tuple
{
218 bus_space_tag_t memt
;
219 bus_space_handle_t memh
;
222 typedef int (*pccard_scan_t
)(const struct pccard_tuple
*, void *);
224 struct pccard_product
{
225 const char *pp_name
; /* NULL if end of table */
226 #define PCCARD_VENDOR_ANY (0xffffffff)
228 #define PCCARD_PRODUCT_ANY (0xffffffff)
230 const char *pp_cis
[4];
233 typedef int (*pccard_product_match_fn
) (device_t dev
,
234 const struct pccard_product
*ent
, int vpfmatch
);
239 * make this inline so that we don't have to worry about dangling references
240 * to it in the modules or the code.
242 static __inline
const struct pccard_product
*
243 pccard_product_lookup(device_t dev
, const struct pccard_product
*tab
,
244 size_t ent_size
, pccard_product_match_fn matchfn
)
246 return CARD_DO_PRODUCT_LOOKUP(device_get_parent(dev
), dev
,
247 tab
, ent_size
, matchfn
);
250 void pccard_read_cis(struct pccard_softc
*);
251 void pccard_check_cis_quirks(device_t
);
252 void pccard_print_cis(device_t
);
253 int pccard_scan_cis(device_t
, pccard_scan_t
, void *);
255 #define pccard_cis_read_1(tuple, idx0) \
256 (bus_space_read_1((tuple)->memt, (tuple)->memh, (tuple)->mult*(idx0)))
258 #define pccard_tuple_read_1(tuple, idx1) \
259 (pccard_cis_read_1((tuple), ((tuple)->ptr+(2+(idx1)))))
261 #define pccard_tuple_read_2(tuple, idx2) \
262 (pccard_tuple_read_1((tuple), (idx2)) | \
263 (pccard_tuple_read_1((tuple), (idx2)+1)<<8))
265 #define pccard_tuple_read_3(tuple, idx3) \
266 (pccard_tuple_read_1((tuple), (idx3)) | \
267 (pccard_tuple_read_1((tuple), (idx3)+1)<<8) | \
268 (pccard_tuple_read_1((tuple), (idx3)+2)<<16))
270 #define pccard_tuple_read_4(tuple, idx4) \
271 (pccard_tuple_read_1((tuple), (idx4)) | \
272 (pccard_tuple_read_1((tuple), (idx4)+1)<<8) | \
273 (pccard_tuple_read_1((tuple), (idx4)+2)<<16) | \
274 (pccard_tuple_read_1((tuple), (idx4)+3)<<24))
276 #define pccard_tuple_read_n(tuple, n, idxn) \
277 (((n)==1)?pccard_tuple_read_1((tuple), (idxn)) : \
278 (((n)==2)?pccard_tuple_read_2((tuple), (idxn)) : \
279 (((n)==3)?pccard_tuple_read_3((tuple), (idxn)) : \
280 /* n == 4 */ pccard_tuple_read_4((tuple), (idxn)))))
282 #define PCCARD_SPACE_MEMORY 1
283 #define PCCARD_SPACE_IO 2
285 #define pccard_mfc(sc) \
286 (STAILQ_FIRST(&(sc)->card.pf_head) && \
287 STAILQ_NEXT(STAILQ_FIRST(&(sc)->card.pf_head),pf_list))
289 #define pccard_io_alloc(pf, start, size, align, pciop) \
290 (pccard_chip_io_alloc((pf)->sc->pct, pf->sc->pch, (start), \
291 (size), (align), (pciop)))
293 #define pccard_io_free(pf, pciohp) \
294 (pccard_chip_io_free((pf)->sc->pct, (pf)->sc->pch, (pciohp)))
296 int pccard_io_map(struct pccard_function
*, int, bus_addr_t
,
297 bus_size_t
, struct pccard_io_handle
*, int *);
298 void pccard_io_unmap(struct pccard_function
*, int);
300 #define pccard_mem_alloc(pf, size, pcmhp) \
301 (pccard_chip_mem_alloc((pf)->sc->pct, (pf)->sc->pch, (size), (pcmhp)))
302 #define pccard_mem_free(pf, pcmhp) \
303 (pccard_chip_mem_free((pf)->sc->pct, (pf)->sc->pch, (pcmhp)))
304 #define pccard_mem_map(pf, kind, card_addr, size, pcmhp, offsetp, windowp) \
305 (pccard_chip_mem_map((pf)->sc->pct, (pf)->sc->pch, (kind), \
306 (card_addr), (size), (pcmhp), (offsetp), (windowp)))
307 #define pccard_mem_unmap(pf, window) \
308 (pccard_chip_mem_unmap((pf)->sc->pct, (pf)->sc->pch, (window)))
312 pccard_compat_probe(device_t dev
)
314 return (CARD_COMPAT_DO_PROBE(device_get_parent(dev
), dev
));
318 pccard_compat_attach(device_t dev
)
320 return (CARD_COMPAT_DO_ATTACH(device_get_parent(dev
), dev
));
325 PCCARD_IVAR_ETHADDR
, /* read ethernet address from CIS tupple */
329 PCCARD_IVAR_FUNCTION_NUMBER
,
330 PCCARD_IVAR_VENDOR_STR
, /* CIS string for "Manufacturer" */
331 PCCARD_IVAR_PRODUCT_STR
,/* CIS strnig for "Product" */
332 PCCARD_IVAR_CIS3_STR
,
333 PCCARD_IVAR_CIS4_STR
,
337 #define PCCARD_ACCESSOR(A, B, T) \
339 pccard_get_ ## A(device_t dev) \
342 BUS_READ_IVAR(device_get_parent(dev), dev, PCCARD_IVAR_ ## B, &v); \
346 PCCARD_ACCESSOR(ether
, ETHADDR
, const uint8_t *)
347 PCCARD_ACCESSOR(vendor
, VENDOR
, uint32_t)
348 PCCARD_ACCESSOR(product
, PRODUCT
, uint32_t)
349 PCCARD_ACCESSOR(prodext
, PRODEXT
, uint16_t)
350 PCCARD_ACCESSOR(function_number
,FUNCTION_NUMBER
, uint32_t)
351 PCCARD_ACCESSOR(function
, FUNCTION
, uint32_t)
352 PCCARD_ACCESSOR(vendor_str
, VENDOR_STR
, const char *)
353 PCCARD_ACCESSOR(product_str
, PRODUCT_STR
, const char *)
354 PCCARD_ACCESSOR(cis3_str
, CIS3_STR
, const char *)
355 PCCARD_ACCESSOR(cis4_str
, CIS4_STR
, const char *)
357 /* shared memory flags */
359 PCCARD_A_MEM_COM
, /* common */
360 PCCARD_A_MEM_ATTR
, /* attribute */
361 PCCARD_A_MEM_8BIT
, /* 8 bit */
362 PCCARD_A_MEM_16BIT
/* 16 bit */
365 #define PCCARD_SOFTC(d) (struct pccard_softc *) device_get_softc(d)
366 #define PCCARD_IVAR(d) (struct pccard_ivar *) device_get_ivars(d)
368 #define PCCARD_S(a, b) PCMCIA_STR_ ## a ## _ ## b
369 #define PCCARD_P(a, b) PCMCIA_PRODUCT_ ## a ## _ ## b
370 #define PCCARD_C(a, b) PCMCIA_CIS_ ## a ## _ ## b
371 #if PCCARD_API_LEVEL >= 6
372 #define PCMCIA_CARD_D(v, p) { PCCARD_S(v, p), PCMCIA_VENDOR_ ## v, \
373 PCCARD_P(v, p), PCCARD_C(v, p) }
374 #define PCMCIA_CARD2_D(v1, p1, p2) \
375 { PCMCIA_STR_ ## p2, PCMCIA_VENDOR_ ## v1, PCCARD_P(v1, p1), \
377 #define PCMCIA_CARD(v, p) { NULL, PCMCIA_VENDOR_ ## v, \
378 PCCARD_P(v, p), PCCARD_C(v, p) }
379 #define PCMCIA_CARD2(v1, p1, p2) \
380 { NULL, PCMCIA_VENDOR_ ## v1, PCCARD_P(v1, p1), \
383 #define PCMCIA_CARD_D(v, p, f) { PCCARD_S(v, p), PCMCIA_VENDOR_ ## v, \
384 PCCARD_P(v, p), PCCARD_C(v, p) }
385 #define PCMCIA_CARD2_D(v1, p1, p2, f) \
386 { PCMCIA_STR_ ## p2, PCMCIA_VENDOR_ ## v1, PCCARD_P(v1, p1), \
388 #define PCMCIA_CARD(v, p, f) { NULL, PCMCIA_VENDOR_ ## v, \
389 PCCARD_P(v, p), PCCARD_C(v, p) }
390 #define PCMCIA_CARD2(v1, p1, p2, f) \
391 { NULL, PCMCIA_VENDOR_ ## v1, PCCARD_P(v1, p1), \