xref: /freebsd/sys/dev/pccard/pccardvar.h (revision 71625ec9ad2a9bc8c09784fbd23b759830e0ee5f)
18456e16eSWarner Losh /*	$NetBSD: pcmciavar.h,v 1.12 2000/02/08 12:51:31 enami Exp $	*/
2c2380338SWarner Losh 
3098ca2bdSWarner Losh /*-
4718cf2ccSPedro F. Giffuni  * SPDX-License-Identifier: BSD-4-Clause
5718cf2ccSPedro F. Giffuni  *
6c2380338SWarner Losh  * Copyright (c) 1997 Marc Horowitz.  All rights reserved.
7c2380338SWarner Losh  *
8c2380338SWarner Losh  * Redistribution and use in source and binary forms, with or without
9c2380338SWarner Losh  * modification, are permitted provided that the following conditions
10c2380338SWarner Losh  * are met:
11c2380338SWarner Losh  * 1. Redistributions of source code must retain the above copyright
12c2380338SWarner Losh  *    notice, this list of conditions and the following disclaimer.
13c2380338SWarner Losh  * 2. Redistributions in binary form must reproduce the above copyright
14c2380338SWarner Losh  *    notice, this list of conditions and the following disclaimer in the
15c2380338SWarner Losh  *    documentation and/or other materials provided with the distribution.
16c2380338SWarner Losh  * 3. All advertising materials mentioning features or use of this software
17c2380338SWarner Losh  *    must display the following acknowledgement:
18c2380338SWarner Losh  *	This product includes software developed by Marc Horowitz.
19c2380338SWarner Losh  * 4. The name of the author may not be used to endorse or promote products
20c2380338SWarner Losh  *    derived from this software without specific prior written permission.
21c2380338SWarner Losh  *
22c2380338SWarner Losh  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23c2380338SWarner Losh  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24c2380338SWarner Losh  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25c2380338SWarner Losh  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26c2380338SWarner Losh  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27c2380338SWarner Losh  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28c2380338SWarner Losh  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29c2380338SWarner Losh  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30c2380338SWarner Losh  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31c2380338SWarner Losh  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32c2380338SWarner Losh  */
33c2380338SWarner Losh 
34c2380338SWarner Losh /*
35c2380338SWarner Losh  * Contains information about mapped/allocated i/o spaces.
36c2380338SWarner Losh  */
37c2380338SWarner Losh struct pccard_io_handle {
38c2380338SWarner Losh 	bus_space_tag_t iot;		/* bus space tag (from chipset) */
39c2380338SWarner Losh 	bus_space_handle_t ioh;		/* mapped space handle */
40c2380338SWarner Losh 	bus_addr_t      addr;		/* resulting address in bus space */
41c2380338SWarner Losh 	bus_size_t      size;		/* size of i/o space */
42c2380338SWarner Losh 	int             flags;		/* misc. information */
4381047394SWarner Losh 	int		width;
44c2380338SWarner Losh };
45c2380338SWarner Losh 
46c2380338SWarner Losh #define	PCCARD_IO_ALLOCATED	0x01	/* i/o space was allocated */
47c2380338SWarner Losh 
48c2380338SWarner Losh /*
49c2380338SWarner Losh  * Contains information about allocated memory space.
50c2380338SWarner Losh  */
51c2380338SWarner Losh struct pccard_mem_handle {
52c2380338SWarner Losh 	bus_space_tag_t memt;		/* bus space tag (from chipset) */
53c2380338SWarner Losh 	bus_space_handle_t memh;	/* mapped space handle */
54c2380338SWarner Losh 	bus_addr_t      addr;		/* resulting address in bus space */
55c2380338SWarner Losh 	bus_size_t      size;		/* size of mem space */
56c2380338SWarner Losh 	bus_size_t      realsize;	/* how much we really allocated */
57a91e0069SWarner Losh 	bus_addr_t	cardaddr;	/* Absolute address on card */
5881047394SWarner Losh 	int		kind;
59c2380338SWarner Losh };
60c2380338SWarner Losh 
61609729b7SWarner Losh /* Bits for kind */
62609729b7SWarner Losh #define	PCCARD_MEM_16BIT	1	/* 1 -> 16bit 0 -> 8bit */
63609729b7SWarner Losh #define PCCARD_MEM_ATTR		2	/* 1 -> attribute mem 0 -> common */
64609729b7SWarner Losh 
65d3d805e6SWarner Losh #define	PCCARD_WIDTH_AUTO	0
66d3d805e6SWarner Losh #define	PCCARD_WIDTH_IO8	1
67d3d805e6SWarner Losh #define	PCCARD_WIDTH_IO16	2
68d3d805e6SWarner Losh 
69c2380338SWarner Losh struct pccard_tuple {
70c2380338SWarner Losh 	unsigned int	code;
71c2380338SWarner Losh 	unsigned int	length;
7273cac338SWarner Losh 	u_long		mult;		/* dist btn successive bytes */
73c2380338SWarner Losh 	bus_addr_t	ptr;
74c2380338SWarner Losh 	bus_space_tag_t	memt;
75c2380338SWarner Losh 	bus_space_handle_t memh;
76c2380338SWarner Losh };
77c2380338SWarner Losh 
785af5f40cSWarner Losh typedef int (*pccard_scan_t)(const struct pccard_tuple *, void *);
7926db48b9SWarner Losh 
808456e16eSWarner Losh struct pccard_product {
8150acd0b8SWarner Losh 	const char	*pp_name;
820540e305SWarner Losh #define PCCARD_VENDOR_ANY (0xffffffff)
8350acd0b8SWarner Losh 	uint32_t	pp_vendor;		/* 0 == end of table */
840540e305SWarner Losh #define PCCARD_PRODUCT_ANY (0xffffffff)
850540e305SWarner Losh 	uint32_t	pp_product;
86da15fcf1SWarner Losh 	const char	*pp_cis[4];
878456e16eSWarner Losh };
888456e16eSWarner Losh 
89f6cea53fSWarner Losh /**
9075d03747SWarner Losh  * Note: There's no cis3 or cis4 reported for NOMATCH / pnpinfo events for
91a4f66e5fSJohn Baldwin  * pccard.  It's unclear if we actually need that for automatic loading or
92a4f66e5fSJohn Baldwin  * not.  These strings are informative, according to the standard.  Some Linux
9375d03747SWarner Losh  * drivers match on them, for example.  However, FreeBSD's hardware probing is a
94a4f66e5fSJohn Baldwin  * little different than Linux, so it turns out we don't need them.  Some cards
9575d03747SWarner Losh  * use CIS3 or CIS4 for a textual representation of the MAC address.  In short,
9675d03747SWarner Losh  * belief that all the entries in Linux don't actually need to be separate there
97a4f66e5fSJohn Baldwin  * either, but they persist since it's hard to eliminate them and retest on old,
98a4f66e5fSJohn Baldwin  * possibly rare, hardware.  Despite years of collecting ~300 different PC Cards
9975d03747SWarner Losh  * off E-Bay, I've not been able to find any that need CIS3/CIS4 to select which
10075d03747SWarner Losh  * device attaches.
101f6cea53fSWarner Losh  */
102922f5528SWarner Losh #define PCCARD_PNP_DESCR "D:#;V32:manufacturer;V32:product;Z:cisvendor;Z:cisproduct;"
103f6cea53fSWarner Losh #define PCCARD_PNP_INFO(t) \
104*329e817fSWarner Losh 	MODULE_PNP_INFO(PCCARD_PNP_DESCR, pccard, t, t, nitems(t) - 1)
105f6cea53fSWarner Losh 
1068456e16eSWarner Losh typedef int (*pccard_product_match_fn) (device_t dev,
1078456e16eSWarner Losh     const struct pccard_product *ent, int vpfmatch);
1088456e16eSWarner Losh 
109c1bb793bSWarner Losh #include "card_if.h"
110c1bb793bSWarner Losh 
111c1bb793bSWarner Losh /*
112a4f66e5fSJohn Baldwin  * Make this inline so that we don't have to worry about dangling references
113c1bb793bSWarner Losh  * to it in the modules or the code.
114c1bb793bSWarner Losh  */
11575da3c1aSEd Schouten static inline const struct pccard_product *
pccard_product_lookup(device_t dev,const struct pccard_product * tab,size_t ent_size,pccard_product_match_fn matchfn)116c1bb793bSWarner Losh pccard_product_lookup(device_t dev, const struct pccard_product *tab,
117c1bb793bSWarner Losh     size_t ent_size, pccard_product_match_fn matchfn)
118c1bb793bSWarner Losh {
119c1bb793bSWarner Losh 	return CARD_DO_PRODUCT_LOOKUP(device_get_parent(dev), dev,
120c1bb793bSWarner Losh 	    tab, ent_size, matchfn);
121c1bb793bSWarner Losh }
1228456e16eSWarner Losh 
123c2380338SWarner Losh #define	pccard_cis_read_1(tuple, idx0)					\
124c2380338SWarner Losh 	(bus_space_read_1((tuple)->memt, (tuple)->memh, (tuple)->mult*(idx0)))
125c2380338SWarner Losh 
126c2380338SWarner Losh #define	pccard_tuple_read_1(tuple, idx1)				\
127c2380338SWarner Losh 	(pccard_cis_read_1((tuple), ((tuple)->ptr+(2+(idx1)))))
128c2380338SWarner Losh 
129c2380338SWarner Losh #define	pccard_tuple_read_2(tuple, idx2)				\
130c2380338SWarner Losh 	(pccard_tuple_read_1((tuple), (idx2)) |				\
131c2380338SWarner Losh 	 (pccard_tuple_read_1((tuple), (idx2)+1)<<8))
132c2380338SWarner Losh 
133c2380338SWarner Losh #define	pccard_tuple_read_3(tuple, idx3)				\
134c2380338SWarner Losh 	(pccard_tuple_read_1((tuple), (idx3)) |				\
135c2380338SWarner Losh 	 (pccard_tuple_read_1((tuple), (idx3)+1)<<8) |			\
136c2380338SWarner Losh 	 (pccard_tuple_read_1((tuple), (idx3)+2)<<16))
137c2380338SWarner Losh 
138c2380338SWarner Losh #define	pccard_tuple_read_4(tuple, idx4)				\
139c2380338SWarner Losh 	(pccard_tuple_read_1((tuple), (idx4)) |				\
140c2380338SWarner Losh 	 (pccard_tuple_read_1((tuple), (idx4)+1)<<8) |			\
141c2380338SWarner Losh 	 (pccard_tuple_read_1((tuple), (idx4)+2)<<16) |			\
142c2380338SWarner Losh 	 (pccard_tuple_read_1((tuple), (idx4)+3)<<24))
143c2380338SWarner Losh 
144c2380338SWarner Losh #define	pccard_tuple_read_n(tuple, n, idxn)				\
145c2380338SWarner Losh 	(((n)==1)?pccard_tuple_read_1((tuple), (idxn)) :		\
146c2380338SWarner Losh 	 (((n)==2)?pccard_tuple_read_2((tuple), (idxn)) :		\
147c2380338SWarner Losh 	  (((n)==3)?pccard_tuple_read_3((tuple), (idxn)) :		\
148c2380338SWarner Losh 	   /* n == 4 */ pccard_tuple_read_4((tuple), (idxn)))))
149c2380338SWarner Losh 
150c2380338SWarner Losh #define	PCCARD_SPACE_MEMORY	1
151c2380338SWarner Losh #define	PCCARD_SPACE_IO		2
152c2380338SWarner Losh 
153d266c2dbSWarner Losh #define	pccard_mfc(sc)							\
154d266c2dbSWarner Losh 		(STAILQ_FIRST(&(sc)->card.pf_head) &&			\
155c2380338SWarner Losh 		 STAILQ_NEXT(STAILQ_FIRST(&(sc)->card.pf_head),pf_list))
156c2380338SWarner Losh 
157fe364ce9SWarner Losh /* Convenience functions */
158fe364ce9SWarner Losh 
15975da3c1aSEd Schouten static inline int
pccard_cis_scan(device_t dev,pccard_scan_t fct,void * arg)160fe364ce9SWarner Losh pccard_cis_scan(device_t dev, pccard_scan_t fct, void *arg)
161fe364ce9SWarner Losh {
162fe364ce9SWarner Losh 	return (CARD_CIS_SCAN(device_get_parent(dev), dev, fct, arg));
163fe364ce9SWarner Losh }
164fe364ce9SWarner Losh 
16575da3c1aSEd Schouten static inline int
pccard_attr_read_1(device_t dev,uint32_t offset,uint8_t * val)166fe364ce9SWarner Losh pccard_attr_read_1(device_t dev, uint32_t offset, uint8_t *val)
167fe364ce9SWarner Losh {
168fe364ce9SWarner Losh 	return (CARD_ATTR_READ(device_get_parent(dev), dev, offset, val));
169fe364ce9SWarner Losh }
170fe364ce9SWarner Losh 
17175da3c1aSEd Schouten static inline int
pccard_attr_write_1(device_t dev,uint32_t offset,uint8_t val)172fe364ce9SWarner Losh pccard_attr_write_1(device_t dev, uint32_t offset, uint8_t val)
173fe364ce9SWarner Losh {
174fe364ce9SWarner Losh 	return (CARD_ATTR_WRITE(device_get_parent(dev), dev, offset, val));
175fe364ce9SWarner Losh }
176fe364ce9SWarner Losh 
17775da3c1aSEd Schouten static inline int
pccard_ccr_read_1(device_t dev,uint32_t offset,uint8_t * val)178fe364ce9SWarner Losh pccard_ccr_read_1(device_t dev, uint32_t offset, uint8_t *val)
179fe364ce9SWarner Losh {
180fe364ce9SWarner Losh 	return (CARD_CCR_READ(device_get_parent(dev), dev, offset, val));
181fe364ce9SWarner Losh }
182fe364ce9SWarner Losh 
18375da3c1aSEd Schouten static inline int
pccard_ccr_write_1(device_t dev,uint32_t offset,uint8_t val)184fe364ce9SWarner Losh pccard_ccr_write_1(device_t dev, uint32_t offset, uint8_t val)
185fe364ce9SWarner Losh {
186fe364ce9SWarner Losh 	return (CARD_CCR_WRITE(device_get_parent(dev), dev, offset, val));
187fe364ce9SWarner Losh }
188fe364ce9SWarner Losh 
18969e401feSWarner Losh /* Hack */
19069e401feSWarner Losh int pccard_select_cfe(device_t dev, int entry);
19169e401feSWarner Losh 
19287ef0a0aSTatsumi Hosokawa /* ivar interface */
19387ef0a0aSTatsumi Hosokawa enum {
19487ef0a0aSTatsumi Hosokawa 	PCCARD_IVAR_ETHADDR,	/* read ethernet address from CIS tupple */
1958456e16eSWarner Losh 	PCCARD_IVAR_VENDOR,
1968456e16eSWarner Losh 	PCCARD_IVAR_PRODUCT,
19757ffbd6eSTakeshi Shibagaki 	PCCARD_IVAR_PRODEXT,
1988456e16eSWarner Losh 	PCCARD_IVAR_FUNCTION_NUMBER,
1998456e16eSWarner Losh 	PCCARD_IVAR_VENDOR_STR,	/* CIS string for "Manufacturer" */
200b1ce21c6SRebecca Cran 	PCCARD_IVAR_PRODUCT_STR,/* CIS string for "Product" */
201d62abc77SWarner Losh 	PCCARD_IVAR_CIS3_STR,
202dc8e185fSWarner Losh 	PCCARD_IVAR_CIS4_STR,
20396a31ac3SWarner Losh 	PCCARD_IVAR_FUNCTION,
20496a31ac3SWarner Losh 	PCCARD_IVAR_FUNCE_DISK
20587ef0a0aSTatsumi Hosokawa };
20687ef0a0aSTatsumi Hosokawa 
2078456e16eSWarner Losh #define PCCARD_ACCESSOR(A, B, T)					\
20875da3c1aSEd Schouten static inline int							\
2098456e16eSWarner Losh pccard_get_ ## A(device_t dev, T *t)					\
2108456e16eSWarner Losh {									\
2118456e16eSWarner Losh 	return BUS_READ_IVAR(device_get_parent(dev), dev,		\
2128456e16eSWarner Losh 	    PCCARD_IVAR_ ## B, (uintptr_t *) t);			\
213e14c13daSWarner Losh }
214e14c13daSWarner Losh 
2150540e305SWarner Losh PCCARD_ACCESSOR(ether,		ETHADDR,		uint8_t)
2160540e305SWarner Losh PCCARD_ACCESSOR(vendor,		VENDOR,			uint32_t)
2170540e305SWarner Losh PCCARD_ACCESSOR(product,	PRODUCT,		uint32_t)
2180540e305SWarner Losh PCCARD_ACCESSOR(prodext,	PRODEXT,		uint16_t)
2190540e305SWarner Losh PCCARD_ACCESSOR(function_number,FUNCTION_NUMBER,	uint32_t)
2200540e305SWarner Losh PCCARD_ACCESSOR(function,	FUNCTION,		uint32_t)
22196a31ac3SWarner Losh PCCARD_ACCESSOR(funce_disk,	FUNCE_DISK,		uint16_t)
222595670d9SWarner Losh PCCARD_ACCESSOR(vendor_str,	VENDOR_STR,		const char *)
223595670d9SWarner Losh PCCARD_ACCESSOR(product_str,	PRODUCT_STR,		const char *)
224595670d9SWarner Losh PCCARD_ACCESSOR(cis3_str,	CIS3_STR,		const char *)
225595670d9SWarner Losh PCCARD_ACCESSOR(cis4_str,	CIS4_STR,		const char *)
2268456e16eSWarner Losh 
2270a177c3dSDuncan Barclay /* shared memory flags */
228e14c13daSWarner Losh enum {
2290a177c3dSDuncan Barclay 	PCCARD_A_MEM_COM,       /* common */
2300a177c3dSDuncan Barclay 	PCCARD_A_MEM_ATTR,      /* attribute */
2310a177c3dSDuncan Barclay 	PCCARD_A_MEM_8BIT,      /* 8 bit */
2320a177c3dSDuncan Barclay 	PCCARD_A_MEM_16BIT      /* 16 bit */
233e14c13daSWarner Losh };
234e14c13daSWarner Losh 
23534e4437eSWarner Losh #define PCCARD_S(a, b) PCMCIA_STR_ ## a ## _ ## b
23634e4437eSWarner Losh #define PCCARD_P(a, b) PCMCIA_PRODUCT_ ## a ## _ ## b
23734e4437eSWarner Losh #define PCCARD_C(a, b) PCMCIA_CIS_ ## a ## _ ## b
238ab581af7SWarner Losh #define PCMCIA_CARD_D(v, p) { PCCARD_S(v, p), PCMCIA_VENDOR_ ## v, \
239ab581af7SWarner Losh 		PCCARD_P(v, p), PCCARD_C(v, p) }
24086fd8873SWarner Losh #define PCMCIA_CARD(v, p) { PCCARD_S(v, p), PCMCIA_VENDOR_ ## v, \
241ab581af7SWarner Losh 		PCCARD_P(v, p), PCCARD_C(v, p) }
24296a31ac3SWarner Losh 
24396a31ac3SWarner Losh /*
244b1ce21c6SRebecca Cran  * Defines to decode the get_funce_disk return value.  See the PCMCIA standard
24596a31ac3SWarner Losh  * for all the details of what these bits mean.
24696a31ac3SWarner Losh  */
24796a31ac3SWarner Losh #define	PFD_I_V_MASK		0x3
24896a31ac3SWarner Losh #define PFD_I_V_NONE_REQUIRED	0x0
24996a31ac3SWarner Losh #define PFD_I_V_REQ_MOD_ACC	0x1
25096a31ac3SWarner Losh #define PFD_I_V_REQ_ACC		0x2
25196a31ac3SWarner Losh #define PFD_I_V_REQ_ALWYS	0x1
25296a31ac3SWarner Losh #define PFD_I_S			0x4	/* 0 rotating, 1 silicon */
25396a31ac3SWarner Losh #define PFD_I_U			0x8	/* SN Uniq? */
25496a31ac3SWarner Losh #define	PFD_I_D			0x10	/* 0 - 1 drive, 1 - 2 drives */
25596a31ac3SWarner Losh #define PFD_P_P0		0x100
25696a31ac3SWarner Losh #define PFD_P_P1		0x200
25796a31ac3SWarner Losh #define PFD_P_P2		0x400
25896a31ac3SWarner Losh #define PFD_P_P3		0x800
25996a31ac3SWarner Losh #define PFD_P_N			0x1000	/* 3f7/377 excluded? */
26096a31ac3SWarner Losh #define PFD_P_E			0x2000	/* Index bit supported? */
26196a31ac3SWarner Losh #define	PFD_P_I			0x4000	/* twincard */
262