xref: /freebsd/sys/dev/pccard/pccardvar.h (revision b2d48be1bc7df45ddd13b143a160d0acb5a383c5)
1 /*	$NetBSD: pcmciavar.h,v 1.12 2000/02/08 12:51:31 enami Exp $	*/
2 /* $FreeBSD$ */
3 
4 /*-
5  * Copyright (c) 1997 Marc Horowitz.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
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.
20  *
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.
31  */
32 
33 /*
34  * Contains information about mapped/allocated i/o spaces.
35  */
36 struct pccard_io_handle {
37 	bus_space_tag_t iot;		/* bus space tag (from chipset) */
38 	bus_space_handle_t ioh;		/* mapped space handle */
39 	bus_addr_t      addr;		/* resulting address in bus space */
40 	bus_size_t      size;		/* size of i/o space */
41 	int             flags;		/* misc. information */
42 	int		width;
43 };
44 
45 #define	PCCARD_IO_ALLOCATED	0x01	/* i/o space was allocated */
46 
47 /*
48  * Contains information about allocated memory space.
49  */
50 struct pccard_mem_handle {
51 	bus_space_tag_t memt;		/* bus space tag (from chipset) */
52 	bus_space_handle_t memh;	/* mapped space handle */
53 	bus_addr_t      addr;		/* resulting address in bus space */
54 	bus_size_t      size;		/* size of mem space */
55 	bus_size_t      realsize;	/* how much we really allocated */
56 	bus_addr_t	cardaddr;	/* Absolute address on card */
57 	int		kind;
58 };
59 
60 /* Bits for kind */
61 #define	PCCARD_MEM_16BIT	1	/* 1 -> 16bit 0 -> 8bit */
62 #define PCCARD_MEM_ATTR		2	/* 1 -> attribute mem 0 -> common */
63 
64 #define	PCCARD_WIDTH_AUTO	0
65 #define	PCCARD_WIDTH_IO8	1
66 #define	PCCARD_WIDTH_IO16	2
67 
68 struct pccard_tuple {
69 	unsigned int	code;
70 	unsigned int	length;
71 	u_long		mult;		/* dist btn successive bytes */
72 	bus_addr_t	ptr;
73 	bus_space_tag_t	memt;
74 	bus_space_handle_t memh;
75 };
76 
77 typedef int (*pccard_scan_t)(const struct pccard_tuple *, void *);
78 
79 struct pccard_product {
80 	const char	*pp_name;
81 #define PCCARD_VENDOR_ANY (0xffffffff)
82 	uint32_t	pp_vendor;		/* 0 == end of table */
83 #define PCCARD_PRODUCT_ANY (0xffffffff)
84 	uint32_t	pp_product;
85 	const char	*pp_cis[4];
86 };
87 
88 typedef int (*pccard_product_match_fn) (device_t dev,
89     const struct pccard_product *ent, int vpfmatch);
90 
91 #include "card_if.h"
92 
93 /*
94  * make this inline so that we don't have to worry about dangling references
95  * to it in the modules or the code.
96  */
97 static inline const struct pccard_product *
98 pccard_product_lookup(device_t dev, const struct pccard_product *tab,
99     size_t ent_size, pccard_product_match_fn matchfn)
100 {
101 	return CARD_DO_PRODUCT_LOOKUP(device_get_parent(dev), dev,
102 	    tab, ent_size, matchfn);
103 }
104 
105 #define	pccard_cis_read_1(tuple, idx0)					\
106 	(bus_space_read_1((tuple)->memt, (tuple)->memh, (tuple)->mult*(idx0)))
107 
108 #define	pccard_tuple_read_1(tuple, idx1)				\
109 	(pccard_cis_read_1((tuple), ((tuple)->ptr+(2+(idx1)))))
110 
111 #define	pccard_tuple_read_2(tuple, idx2)				\
112 	(pccard_tuple_read_1((tuple), (idx2)) |				\
113 	 (pccard_tuple_read_1((tuple), (idx2)+1)<<8))
114 
115 #define	pccard_tuple_read_3(tuple, idx3)				\
116 	(pccard_tuple_read_1((tuple), (idx3)) |				\
117 	 (pccard_tuple_read_1((tuple), (idx3)+1)<<8) |			\
118 	 (pccard_tuple_read_1((tuple), (idx3)+2)<<16))
119 
120 #define	pccard_tuple_read_4(tuple, idx4)				\
121 	(pccard_tuple_read_1((tuple), (idx4)) |				\
122 	 (pccard_tuple_read_1((tuple), (idx4)+1)<<8) |			\
123 	 (pccard_tuple_read_1((tuple), (idx4)+2)<<16) |			\
124 	 (pccard_tuple_read_1((tuple), (idx4)+3)<<24))
125 
126 #define	pccard_tuple_read_n(tuple, n, idxn)				\
127 	(((n)==1)?pccard_tuple_read_1((tuple), (idxn)) :		\
128 	 (((n)==2)?pccard_tuple_read_2((tuple), (idxn)) :		\
129 	  (((n)==3)?pccard_tuple_read_3((tuple), (idxn)) :		\
130 	   /* n == 4 */ pccard_tuple_read_4((tuple), (idxn)))))
131 
132 #define	PCCARD_SPACE_MEMORY	1
133 #define	PCCARD_SPACE_IO		2
134 
135 #define	pccard_mfc(sc)							\
136 		(STAILQ_FIRST(&(sc)->card.pf_head) &&			\
137 		 STAILQ_NEXT(STAILQ_FIRST(&(sc)->card.pf_head),pf_list))
138 
139 /* Convenience functions */
140 
141 static inline int
142 pccard_cis_scan(device_t dev, pccard_scan_t fct, void *arg)
143 {
144 	return (CARD_CIS_SCAN(device_get_parent(dev), dev, fct, arg));
145 }
146 
147 static inline int
148 pccard_attr_read_1(device_t dev, uint32_t offset, uint8_t *val)
149 {
150 	return (CARD_ATTR_READ(device_get_parent(dev), dev, offset, val));
151 }
152 
153 static inline int
154 pccard_attr_write_1(device_t dev, uint32_t offset, uint8_t val)
155 {
156 	return (CARD_ATTR_WRITE(device_get_parent(dev), dev, offset, val));
157 }
158 
159 static inline int
160 pccard_ccr_read_1(device_t dev, uint32_t offset, uint8_t *val)
161 {
162 	return (CARD_CCR_READ(device_get_parent(dev), dev, offset, val));
163 }
164 
165 static inline int
166 pccard_ccr_write_1(device_t dev, uint32_t offset, uint8_t val)
167 {
168 	return (CARD_CCR_WRITE(device_get_parent(dev), dev, offset, val));
169 }
170 
171 /* Hack */
172 int pccard_select_cfe(device_t dev, int entry);
173 
174 /* ivar interface */
175 enum {
176 	PCCARD_IVAR_ETHADDR,	/* read ethernet address from CIS tupple */
177 	PCCARD_IVAR_VENDOR,
178 	PCCARD_IVAR_PRODUCT,
179 	PCCARD_IVAR_PRODEXT,
180 	PCCARD_IVAR_FUNCTION_NUMBER,
181 	PCCARD_IVAR_VENDOR_STR,	/* CIS string for "Manufacturer" */
182 	PCCARD_IVAR_PRODUCT_STR,/* CIS string for "Product" */
183 	PCCARD_IVAR_CIS3_STR,
184 	PCCARD_IVAR_CIS4_STR,
185 	PCCARD_IVAR_FUNCTION,
186 	PCCARD_IVAR_FUNCE_DISK
187 };
188 
189 #define PCCARD_ACCESSOR(A, B, T)					\
190 static inline int							\
191 pccard_get_ ## A(device_t dev, T *t)					\
192 {									\
193 	return BUS_READ_IVAR(device_get_parent(dev), dev,		\
194 	    PCCARD_IVAR_ ## B, (uintptr_t *) t);			\
195 }
196 
197 PCCARD_ACCESSOR(ether,		ETHADDR,		uint8_t)
198 PCCARD_ACCESSOR(vendor,		VENDOR,			uint32_t)
199 PCCARD_ACCESSOR(product,	PRODUCT,		uint32_t)
200 PCCARD_ACCESSOR(prodext,	PRODEXT,		uint16_t)
201 PCCARD_ACCESSOR(function_number,FUNCTION_NUMBER,	uint32_t)
202 PCCARD_ACCESSOR(function,	FUNCTION,		uint32_t)
203 PCCARD_ACCESSOR(funce_disk,	FUNCE_DISK,		uint16_t)
204 PCCARD_ACCESSOR(vendor_str,	VENDOR_STR,		const char *)
205 PCCARD_ACCESSOR(product_str,	PRODUCT_STR,		const char *)
206 PCCARD_ACCESSOR(cis3_str,	CIS3_STR,		const char *)
207 PCCARD_ACCESSOR(cis4_str,	CIS4_STR,		const char *)
208 
209 /* shared memory flags */
210 enum {
211 	PCCARD_A_MEM_COM,       /* common */
212 	PCCARD_A_MEM_ATTR,      /* attribute */
213 	PCCARD_A_MEM_8BIT,      /* 8 bit */
214 	PCCARD_A_MEM_16BIT      /* 16 bit */
215 };
216 
217 #define PCCARD_S(a, b) PCMCIA_STR_ ## a ## _ ## b
218 #define PCCARD_P(a, b) PCMCIA_PRODUCT_ ## a ## _ ## b
219 #define PCCARD_C(a, b) PCMCIA_CIS_ ## a ## _ ## b
220 #define PCMCIA_CARD_D(v, p) { PCCARD_S(v, p), PCMCIA_VENDOR_ ## v, \
221 		PCCARD_P(v, p), PCCARD_C(v, p) }
222 #define PCMCIA_CARD(v, p) { PCCARD_S(v, p), PCMCIA_VENDOR_ ## v, \
223 		PCCARD_P(v, p), PCCARD_C(v, p) }
224 
225 /*
226  * Defines to decode the get_funce_disk return value.  See the PCMCIA standard
227  * for all the details of what these bits mean.
228  */
229 #define	PFD_I_V_MASK		0x3
230 #define PFD_I_V_NONE_REQUIRED	0x0
231 #define PFD_I_V_REQ_MOD_ACC	0x1
232 #define PFD_I_V_REQ_ACC		0x2
233 #define PFD_I_V_REQ_ALWYS	0x1
234 #define PFD_I_S			0x4	/* 0 rotating, 1 silicon */
235 #define PFD_I_U			0x8	/* SN Uniq? */
236 #define	PFD_I_D			0x10	/* 0 - 1 drive, 1 - 2 drives */
237 #define PFD_P_P0		0x100
238 #define PFD_P_P1		0x200
239 #define PFD_P_P2		0x400
240 #define PFD_P_P3		0x800
241 #define PFD_P_N			0x1000	/* 3f7/377 excluded? */
242 #define PFD_P_E			0x2000	/* Index bit supported? */
243 #define	PFD_P_I			0x4000	/* twincard */
244