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 $ */
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.
33 #include <sys/types.h>
34 #include <sys/queue.h>
36 #include <machine/bus.h>
38 extern int pccard_verbose;
41 * Contains information about mapped/allocated i/o spaces.
43 struct pccard_io_handle {
44 bus_space_tag_t iot; /* bus space tag (from chipset) */
45 bus_space_handle_t ioh; /* mapped space handle */
46 bus_addr_t addr; /* resulting address in bus space */
47 bus_size_t size; /* size of i/o space */
48 int flags; /* misc. information */
52 #define PCCARD_IO_ALLOCATED 0x01 /* i/o space was allocated */
55 * Contains information about allocated memory space.
57 struct pccard_mem_handle {
58 bus_space_tag_t memt; /* bus space tag (from chipset) */
59 bus_space_handle_t memh; /* mapped space handle */
60 bus_addr_t addr; /* resulting address in bus space */
61 bus_size_t size; /* size of mem space */
62 bus_size_t realsize; /* how much we really allocated */
69 #define PCCARD_CFE_MWAIT_REQUIRED 0x0001
70 #define PCCARD_CFE_RDYBSY_ACTIVE 0x0002
71 #define PCCARD_CFE_WP_ACTIVE 0x0004
72 #define PCCARD_CFE_BVD_ACTIVE 0x0008
73 #define PCCARD_CFE_IO8 0x0010
74 #define PCCARD_CFE_IO16 0x0020
75 #define PCCARD_CFE_IRQSHARE 0x0040
76 #define PCCARD_CFE_IRQPULSE 0x0080
77 #define PCCARD_CFE_IRQLEVEL 0x0100
78 #define PCCARD_CFE_POWERDOWN 0x0200
79 #define PCCARD_CFE_READONLY 0x0400
80 #define PCCARD_CFE_AUDIO 0x0800
82 struct pccard_config_entry {
89 * The card will only decode this mask in any case, so we can
90 * do dynamic allocation with this in mind, in case the suggestions
97 } iospace[4]; /* XXX this could be as high as 16 */
104 } memspace[2]; /* XXX this could be as high as 8 */
106 STAILQ_ENTRY(pccard_config_entry) cfe_list;
109 struct pccard_function {
110 /* read off the card */
113 int last_config_index;
116 struct resource *ccr_res;
118 STAILQ_HEAD(, pccard_config_entry) cfe_head;
119 STAILQ_ENTRY(pccard_function) pf_list;
121 struct pccard_softc *sc;
122 struct pccard_config_entry *cfe;
123 struct pccard_mem_handle pf_pcmh;
124 #define pf_ccrt pf_pcmh.memt
125 #define pf_ccrh pf_pcmh.memh
126 #define pf_ccr_realsize pf_pcmh.realsize
127 bus_addr_t pf_ccr_offset;
131 int (*ih_fct)(void *);
138 #define PFF_ENABLED 0x0001 /* function is enabled */
143 /* XXX waste of space? */
144 char cis1_info_buf[256];
147 * Use int32_t for manufacturer and product so that they can
148 * hold the id value found in card CIS and special value that
149 * indicates no id was found.
151 int32_t manufacturer;
152 #define PCCARD_VENDOR_INVALID -1
154 #define PCCARD_PRODUCT_INVALID -1
156 #define PCCARD_CIS_INVALID { NULL, NULL, NULL, NULL }
157 STAILQ_HEAD(, pccard_function) pf_head;
160 #define PCCARD_MEM_ATTR 1
161 #define PCCARD_MEM_COMMON 2
163 #define PCCARD_WIDTH_AUTO 0
164 #define PCCARD_WIDTH_IO8 1
165 #define PCCARD_WIDTH_IO16 2
169 struct resource_list resources;
173 struct pccard_softc {
175 /* this stuff is for the socket */
177 /* this stuff is for the card */
178 struct pccard_card card;
180 int sc_enabled_count; /* num functions enabled */
185 pccardbus_if_setup(struct pccard_softc*);
187 struct pccard_cis_quirk {
188 int32_t manufacturer;
191 struct pccard_function *pf;
192 struct pccard_config_entry *cfe;
195 struct pccard_tuple {
200 bus_space_tag_t memt;
201 bus_space_handle_t memh;
204 void pccard_read_cis(struct pccard_softc *);
205 void pccard_check_cis_quirks(device_t);
206 void pccard_print_cis(device_t);
207 int pccard_scan_cis(device_t,
208 int (*) (struct pccard_tuple *, void *), void *);
210 #define pccard_cis_read_1(tuple, idx0) \
211 (bus_space_read_1((tuple)->memt, (tuple)->memh, (tuple)->mult*(idx0)))
213 #define pccard_tuple_read_1(tuple, idx1) \
214 (pccard_cis_read_1((tuple), ((tuple)->ptr+(2+(idx1)))))
216 #define pccard_tuple_read_2(tuple, idx2) \
217 (pccard_tuple_read_1((tuple), (idx2)) | \
218 (pccard_tuple_read_1((tuple), (idx2)+1)<<8))
220 #define pccard_tuple_read_3(tuple, idx3) \
221 (pccard_tuple_read_1((tuple), (idx3)) | \
222 (pccard_tuple_read_1((tuple), (idx3)+1)<<8) | \
223 (pccard_tuple_read_1((tuple), (idx3)+2)<<16))
225 #define pccard_tuple_read_4(tuple, idx4) \
226 (pccard_tuple_read_1((tuple), (idx4)) | \
227 (pccard_tuple_read_1((tuple), (idx4)+1)<<8) | \
228 (pccard_tuple_read_1((tuple), (idx4)+2)<<16) | \
229 (pccard_tuple_read_1((tuple), (idx4)+3)<<24))
231 #define pccard_tuple_read_n(tuple, n, idxn) \
232 (((n)==1)?pccard_tuple_read_1((tuple), (idxn)) : \
233 (((n)==2)?pccard_tuple_read_2((tuple), (idxn)) : \
234 (((n)==3)?pccard_tuple_read_3((tuple), (idxn)) : \
235 /* n == 4 */ pccard_tuple_read_4((tuple), (idxn)))))
237 #define PCCARD_SPACE_MEMORY 1
238 #define PCCARD_SPACE_IO 2
240 int pccard_ccr_read(struct pccard_function *, int);
241 void pccard_ccr_write(struct pccard_function *, int, int);
243 #define pccard_mfc(sc) (STAILQ_FIRST(&(sc)->card.pf_head) && \
244 STAILQ_NEXT(STAILQ_FIRST(&(sc)->card.pf_head),pf_list))
246 void pccard_function_init(struct pccard_function *,
247 struct pccard_config_entry *);
248 int pccard_function_enable(struct pccard_function *);
249 void pccard_function_disable(struct pccard_function *);
251 #define pccard_io_alloc(pf, start, size, align, pciop) \
252 (pccard_chip_io_alloc((pf)->sc->pct, pf->sc->pch, (start), \
253 (size), (align), (pciop)))
255 #define pccard_io_free(pf, pciohp) \
256 (pccard_chip_io_free((pf)->sc->pct, (pf)->sc->pch, (pciohp)))
258 int pccard_io_map(struct pccard_function *, int, bus_addr_t,
259 bus_size_t, struct pccard_io_handle *, int *);
260 void pccard_io_unmap(struct pccard_function *, int);
262 #define pccard_mem_alloc(pf, size, pcmhp) \
263 (pccard_chip_mem_alloc((pf)->sc->pct, (pf)->sc->pch, (size), (pcmhp)))
265 #define pccard_mem_free(pf, pcmhp) \
266 (pccard_chip_mem_free((pf)->sc->pct, (pf)->sc->pch, (pcmhp)))
268 #define pccard_mem_map(pf, kind, card_addr, size, pcmhp, offsetp, windowp) \
269 (pccard_chip_mem_map((pf)->sc->pct, (pf)->sc->pch, (kind), \
270 (card_addr), (size), (pcmhp), (offsetp), (windowp)))
272 #define pccard_mem_unmap(pf, window) \
273 (pccard_chip_mem_unmap((pf)->sc->pct, (pf)->sc->pch, (window)))
277 PCCARD_IVAR_ETHADDR, /* read ethernet address from CIS tupple */
281 PCCARD_IVAR_FUNCTION_NUMBER,
282 PCCARD_IVAR_VENDOR_STR, /* CIS string for "Manufacturer" */
283 PCCARD_IVAR_PRODUCT_STR,/* CIS strnig for "Product" */
284 PCCARD_IVAR_CIS3_STR,
285 PCCARD_IVAR_CIS4_STR,
289 /* read ethernet address from CIS tupple */
291 pccard_get_ether(device_t dev, u_char *enaddr)
293 return BUS_READ_IVAR(device_get_parent(dev), dev,
294 PCCARD_IVAR_ETHADDR, (uintptr_t *)enaddr);
297 /* shared memory flags */
299 PCCARD_A_MEM_ATTR=1, /* attribute */
300 PCCARD_A_MEM_COM, /* common */
301 PCCARD_A_MEM_8BIT, /* 8 bit */
302 PCCARD_A_MEM_16BIT /* 16 bit */