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