xref: /freebsd/sys/dev/pccard/pccardvar.h (revision a90b9d0159070121c221b966469c3e36d912bf82)
1 /*	$NetBSD: pcmciavar.h,v 1.12 2000/02/08 12:51:31 enami Exp $	*/
2 
3 /*-
4  * SPDX-License-Identifier: BSD-4-Clause
5  *
6  * Copyright (c) 1997 Marc Horowitz.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *	This product includes software developed by Marc Horowitz.
19  * 4. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 /*
35  * Contains information about mapped/allocated i/o spaces.
36  */
37 struct pccard_io_handle {
38 	bus_space_tag_t iot;		/* bus space tag (from chipset) */
39 	bus_space_handle_t ioh;		/* mapped space handle */
40 	bus_addr_t      addr;		/* resulting address in bus space */
41 	bus_size_t      size;		/* size of i/o space */
42 	int             flags;		/* misc. information */
43 	int		width;
44 };
45 
46 #define	PCCARD_IO_ALLOCATED	0x01	/* i/o space was allocated */
47 
48 /*
49  * Contains information about allocated memory space.
50  */
51 struct pccard_mem_handle {
52 	bus_space_tag_t memt;		/* bus space tag (from chipset) */
53 	bus_space_handle_t memh;	/* mapped space handle */
54 	bus_addr_t      addr;		/* resulting address in bus space */
55 	bus_size_t      size;		/* size of mem space */
56 	bus_size_t      realsize;	/* how much we really allocated */
57 	bus_addr_t	cardaddr;	/* Absolute address on card */
58 	int		kind;
59 };
60 
61 /* Bits for kind */
62 #define	PCCARD_MEM_16BIT	1	/* 1 -> 16bit 0 -> 8bit */
63 #define PCCARD_MEM_ATTR		2	/* 1 -> attribute mem 0 -> common */
64 
65 #define	PCCARD_WIDTH_AUTO	0
66 #define	PCCARD_WIDTH_IO8	1
67 #define	PCCARD_WIDTH_IO16	2
68 
69 struct pccard_tuple {
70 	unsigned int	code;
71 	unsigned int	length;
72 	u_long		mult;		/* dist btn successive bytes */
73 	bus_addr_t	ptr;
74 	bus_space_tag_t	memt;
75 	bus_space_handle_t memh;
76 };
77 
78 typedef int (*pccard_scan_t)(const struct pccard_tuple *, void *);
79 
80 struct pccard_product {
81 	const char	*pp_name;
82 #define PCCARD_VENDOR_ANY (0xffffffff)
83 	uint32_t	pp_vendor;		/* 0 == end of table */
84 #define PCCARD_PRODUCT_ANY (0xffffffff)
85 	uint32_t	pp_product;
86 	const char	*pp_cis[4];
87 };
88 
89 /**
90  * Note: There's no cis3 or cis4 reported for NOMATCH / pnpinfo events for
91  * pccard.  It's unclear if we actually need that for automatic loading or
92  * not.  These strings are informative, according to the standard.  Some Linux
93  * drivers match on them, for example.  However, FreeBSD's hardware probing is a
94  * little different than Linux, so it turns out we don't need them.  Some cards
95  * use CIS3 or CIS4 for a textual representation of the MAC address.  In short,
96  * belief that all the entries in Linux don't actually need to be separate there
97  * either, but they persist since it's hard to eliminate them and retest on old,
98  * possibly rare, hardware.  Despite years of collecting ~300 different PC Cards
99  * off E-Bay, I've not been able to find any that need CIS3/CIS4 to select which
100  * device attaches.
101  */
102 #define PCCARD_PNP_DESCR "D:#;V32:manufacturer;V32:product;Z:cisvendor;Z:cisproduct;"
103 #define PCCARD_PNP_INFO(t) \
104 	MODULE_PNP_INFO(PCCARD_PNP_DESCR, pccard, t, t, nitems(t) - 1)
105 
106 typedef int (*pccard_product_match_fn) (device_t dev,
107     const struct pccard_product *ent, int vpfmatch);
108 
109 #include "card_if.h"
110 
111 /*
112  * Make this inline so that we don't have to worry about dangling references
113  * to it in the modules or the code.
114  */
115 static inline const struct pccard_product *
116 pccard_product_lookup(device_t dev, const struct pccard_product *tab,
117     size_t ent_size, pccard_product_match_fn matchfn)
118 {
119 	return CARD_DO_PRODUCT_LOOKUP(device_get_parent(dev), dev,
120 	    tab, ent_size, matchfn);
121 }
122 
123 #define	pccard_cis_read_1(tuple, idx0)					\
124 	(bus_space_read_1((tuple)->memt, (tuple)->memh, (tuple)->mult*(idx0)))
125 
126 #define	pccard_tuple_read_1(tuple, idx1)				\
127 	(pccard_cis_read_1((tuple), ((tuple)->ptr+(2+(idx1)))))
128 
129 #define	pccard_tuple_read_2(tuple, idx2)				\
130 	(pccard_tuple_read_1((tuple), (idx2)) |				\
131 	 (pccard_tuple_read_1((tuple), (idx2)+1)<<8))
132 
133 #define	pccard_tuple_read_3(tuple, idx3)				\
134 	(pccard_tuple_read_1((tuple), (idx3)) |				\
135 	 (pccard_tuple_read_1((tuple), (idx3)+1)<<8) |			\
136 	 (pccard_tuple_read_1((tuple), (idx3)+2)<<16))
137 
138 #define	pccard_tuple_read_4(tuple, idx4)				\
139 	(pccard_tuple_read_1((tuple), (idx4)) |				\
140 	 (pccard_tuple_read_1((tuple), (idx4)+1)<<8) |			\
141 	 (pccard_tuple_read_1((tuple), (idx4)+2)<<16) |			\
142 	 (pccard_tuple_read_1((tuple), (idx4)+3)<<24))
143 
144 #define	pccard_tuple_read_n(tuple, n, idxn)				\
145 	(((n)==1)?pccard_tuple_read_1((tuple), (idxn)) :		\
146 	 (((n)==2)?pccard_tuple_read_2((tuple), (idxn)) :		\
147 	  (((n)==3)?pccard_tuple_read_3((tuple), (idxn)) :		\
148 	   /* n == 4 */ pccard_tuple_read_4((tuple), (idxn)))))
149 
150 #define	PCCARD_SPACE_MEMORY	1
151 #define	PCCARD_SPACE_IO		2
152 
153 #define	pccard_mfc(sc)							\
154 		(STAILQ_FIRST(&(sc)->card.pf_head) &&			\
155 		 STAILQ_NEXT(STAILQ_FIRST(&(sc)->card.pf_head),pf_list))
156 
157 /* Convenience functions */
158 
159 static inline int
160 pccard_cis_scan(device_t dev, pccard_scan_t fct, void *arg)
161 {
162 	return (CARD_CIS_SCAN(device_get_parent(dev), dev, fct, arg));
163 }
164 
165 static inline int
166 pccard_attr_read_1(device_t dev, uint32_t offset, uint8_t *val)
167 {
168 	return (CARD_ATTR_READ(device_get_parent(dev), dev, offset, val));
169 }
170 
171 static inline int
172 pccard_attr_write_1(device_t dev, uint32_t offset, uint8_t val)
173 {
174 	return (CARD_ATTR_WRITE(device_get_parent(dev), dev, offset, val));
175 }
176 
177 static inline int
178 pccard_ccr_read_1(device_t dev, uint32_t offset, uint8_t *val)
179 {
180 	return (CARD_CCR_READ(device_get_parent(dev), dev, offset, val));
181 }
182 
183 static inline int
184 pccard_ccr_write_1(device_t dev, uint32_t offset, uint8_t val)
185 {
186 	return (CARD_CCR_WRITE(device_get_parent(dev), dev, offset, val));
187 }
188 
189 /* Hack */
190 int pccard_select_cfe(device_t dev, int entry);
191 
192 /* ivar interface */
193 enum {
194 	PCCARD_IVAR_ETHADDR,	/* read ethernet address from CIS tupple */
195 	PCCARD_IVAR_VENDOR,
196 	PCCARD_IVAR_PRODUCT,
197 	PCCARD_IVAR_PRODEXT,
198 	PCCARD_IVAR_FUNCTION_NUMBER,
199 	PCCARD_IVAR_VENDOR_STR,	/* CIS string for "Manufacturer" */
200 	PCCARD_IVAR_PRODUCT_STR,/* CIS string for "Product" */
201 	PCCARD_IVAR_CIS3_STR,
202 	PCCARD_IVAR_CIS4_STR,
203 	PCCARD_IVAR_FUNCTION,
204 	PCCARD_IVAR_FUNCE_DISK
205 };
206 
207 #define PCCARD_ACCESSOR(A, B, T)					\
208 static inline int							\
209 pccard_get_ ## A(device_t dev, T *t)					\
210 {									\
211 	return BUS_READ_IVAR(device_get_parent(dev), dev,		\
212 	    PCCARD_IVAR_ ## B, (uintptr_t *) t);			\
213 }
214 
215 PCCARD_ACCESSOR(ether,		ETHADDR,		uint8_t)
216 PCCARD_ACCESSOR(vendor,		VENDOR,			uint32_t)
217 PCCARD_ACCESSOR(product,	PRODUCT,		uint32_t)
218 PCCARD_ACCESSOR(prodext,	PRODEXT,		uint16_t)
219 PCCARD_ACCESSOR(function_number,FUNCTION_NUMBER,	uint32_t)
220 PCCARD_ACCESSOR(function,	FUNCTION,		uint32_t)
221 PCCARD_ACCESSOR(funce_disk,	FUNCE_DISK,		uint16_t)
222 PCCARD_ACCESSOR(vendor_str,	VENDOR_STR,		const char *)
223 PCCARD_ACCESSOR(product_str,	PRODUCT_STR,		const char *)
224 PCCARD_ACCESSOR(cis3_str,	CIS3_STR,		const char *)
225 PCCARD_ACCESSOR(cis4_str,	CIS4_STR,		const char *)
226 
227 /* shared memory flags */
228 enum {
229 	PCCARD_A_MEM_COM,       /* common */
230 	PCCARD_A_MEM_ATTR,      /* attribute */
231 	PCCARD_A_MEM_8BIT,      /* 8 bit */
232 	PCCARD_A_MEM_16BIT      /* 16 bit */
233 };
234 
235 #define PCCARD_S(a, b) PCMCIA_STR_ ## a ## _ ## b
236 #define PCCARD_P(a, b) PCMCIA_PRODUCT_ ## a ## _ ## b
237 #define PCCARD_C(a, b) PCMCIA_CIS_ ## a ## _ ## b
238 #define PCMCIA_CARD_D(v, p) { PCCARD_S(v, p), PCMCIA_VENDOR_ ## v, \
239 		PCCARD_P(v, p), PCCARD_C(v, p) }
240 #define PCMCIA_CARD(v, p) { PCCARD_S(v, p), PCMCIA_VENDOR_ ## v, \
241 		PCCARD_P(v, p), PCCARD_C(v, p) }
242 
243 /*
244  * Defines to decode the get_funce_disk return value.  See the PCMCIA standard
245  * for all the details of what these bits mean.
246  */
247 #define	PFD_I_V_MASK		0x3
248 #define PFD_I_V_NONE_REQUIRED	0x0
249 #define PFD_I_V_REQ_MOD_ACC	0x1
250 #define PFD_I_V_REQ_ACC		0x2
251 #define PFD_I_V_REQ_ALWYS	0x1
252 #define PFD_I_S			0x4	/* 0 rotating, 1 silicon */
253 #define PFD_I_U			0x8	/* SN Uniq? */
254 #define	PFD_I_D			0x10	/* 0 - 1 drive, 1 - 2 drives */
255 #define PFD_P_P0		0x100
256 #define PFD_P_P1		0x200
257 #define PFD_P_P2		0x400
258 #define PFD_P_P3		0x800
259 #define PFD_P_N			0x1000	/* 3f7/377 excluded? */
260 #define PFD_P_E			0x2000	/* Index bit supported? */
261 #define	PFD_P_I			0x4000	/* twincard */
262