xref: /freebsd/sys/dev/pccard/pccardvar.h (revision 12bba6c259f1d26f0c245d3f26b89df26f280d0c)
1c2380338SWarner Losh /*	$NetBSD: pcmciavar.h,v 1.9 1998/12/29 09:00:28 marc Exp $	*/
2c2380338SWarner Losh /* $FreeBSD$ */
3c2380338SWarner Losh 
4c2380338SWarner Losh /*
5c2380338SWarner Losh  * Copyright (c) 1997 Marc Horowitz.  All rights reserved.
6c2380338SWarner Losh  *
7c2380338SWarner Losh  * Redistribution and use in source and binary forms, with or without
8c2380338SWarner Losh  * modification, are permitted provided that the following conditions
9c2380338SWarner Losh  * are met:
10c2380338SWarner Losh  * 1. Redistributions of source code must retain the above copyright
11c2380338SWarner Losh  *    notice, this list of conditions and the following disclaimer.
12c2380338SWarner Losh  * 2. Redistributions in binary form must reproduce the above copyright
13c2380338SWarner Losh  *    notice, this list of conditions and the following disclaimer in the
14c2380338SWarner Losh  *    documentation and/or other materials provided with the distribution.
15c2380338SWarner Losh  * 3. All advertising materials mentioning features or use of this software
16c2380338SWarner Losh  *    must display the following acknowledgement:
17c2380338SWarner Losh  *	This product includes software developed by Marc Horowitz.
18c2380338SWarner Losh  * 4. The name of the author may not be used to endorse or promote products
19c2380338SWarner Losh  *    derived from this software without specific prior written permission.
20c2380338SWarner Losh  *
21c2380338SWarner Losh  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22c2380338SWarner Losh  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23c2380338SWarner Losh  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24c2380338SWarner Losh  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25c2380338SWarner Losh  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26c2380338SWarner Losh  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27c2380338SWarner Losh  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28c2380338SWarner Losh  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29c2380338SWarner Losh  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30c2380338SWarner Losh  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31c2380338SWarner Losh  */
32c2380338SWarner Losh 
33c2380338SWarner Losh #include <sys/types.h>
34c2380338SWarner Losh #include <sys/queue.h>
35c2380338SWarner Losh 
36c2380338SWarner Losh #include <machine/bus.h>
37c2380338SWarner Losh 
38c2380338SWarner Losh #include <dev/pccard/pccardchip.h>
39c2380338SWarner Losh 
40c2380338SWarner Losh extern int	pccard_verbose;
41c2380338SWarner Losh 
42c2380338SWarner Losh /*
43c2380338SWarner Losh  * Contains information about mapped/allocated i/o spaces.
44c2380338SWarner Losh  */
45c2380338SWarner Losh struct pccard_io_handle {
46c2380338SWarner Losh 	bus_space_tag_t iot;		/* bus space tag (from chipset) */
47c2380338SWarner Losh 	bus_space_handle_t ioh;		/* mapped space handle */
48c2380338SWarner Losh 	bus_addr_t      addr;		/* resulting address in bus space */
49c2380338SWarner Losh 	bus_size_t      size;		/* size of i/o space */
50c2380338SWarner Losh 	int             flags;		/* misc. information */
51c2380338SWarner Losh };
52c2380338SWarner Losh 
53c2380338SWarner Losh #define	PCCARD_IO_ALLOCATED	0x01	/* i/o space was allocated */
54c2380338SWarner Losh 
55c2380338SWarner Losh /*
56c2380338SWarner Losh  * Contains information about allocated memory space.
57c2380338SWarner Losh  */
58c2380338SWarner Losh struct pccard_mem_handle {
59c2380338SWarner Losh 	bus_space_tag_t memt;		/* bus space tag (from chipset) */
60c2380338SWarner Losh 	bus_space_handle_t memh;	/* mapped space handle */
61c2380338SWarner Losh 	bus_addr_t      addr;		/* resulting address in bus space */
62c2380338SWarner Losh 	bus_size_t      size;		/* size of mem space */
63c2380338SWarner Losh 	pccard_mem_handle_t mhandle;	/* opaque memory handle */
64c2380338SWarner Losh 	bus_size_t      realsize;	/* how much we really allocated */
65c2380338SWarner Losh };
66c2380338SWarner Losh 
67c2380338SWarner Losh /* pccard itself */
68c2380338SWarner Losh 
69c2380338SWarner Losh #define PCCARD_CFE_MWAIT_REQUIRED	0x0001
70c2380338SWarner Losh #define PCCARD_CFE_RDYBSY_ACTIVE	0x0002
71c2380338SWarner Losh #define PCCARD_CFE_WP_ACTIVE		0x0004
72c2380338SWarner Losh #define PCCARD_CFE_BVD_ACTIVE		0x0008
73c2380338SWarner Losh #define PCCARD_CFE_IO8			0x0010
74c2380338SWarner Losh #define PCCARD_CFE_IO16			0x0020
75c2380338SWarner Losh #define PCCARD_CFE_IRQSHARE		0x0040
76c2380338SWarner Losh #define PCCARD_CFE_IRQPULSE		0x0080
77c2380338SWarner Losh #define PCCARD_CFE_IRQLEVEL		0x0100
78c2380338SWarner Losh #define PCCARD_CFE_POWERDOWN		0x0200
79c2380338SWarner Losh #define PCCARD_CFE_READONLY		0x0400
80c2380338SWarner Losh #define PCCARD_CFE_AUDIO		0x0800
81c2380338SWarner Losh 
82c2380338SWarner Losh struct pccard_config_entry {
83c2380338SWarner Losh 	int		number;
84c2380338SWarner Losh 	u_int32_t	flags;
85c2380338SWarner Losh 	int		iftype;
86c2380338SWarner Losh 	int		num_iospace;
87c2380338SWarner Losh 
88c2380338SWarner Losh 	/*
89c2380338SWarner Losh 	 * The card will only decode this mask in any case, so we can
90c2380338SWarner Losh 	 * do dynamic allocation with this in mind, in case the suggestions
91c2380338SWarner Losh 	 * below are no good.
92c2380338SWarner Losh 	 */
93c2380338SWarner Losh 	u_long		iomask;
94c2380338SWarner Losh 	struct {
95c2380338SWarner Losh 		u_long	length;
96c2380338SWarner Losh 		u_long	start;
97c2380338SWarner Losh 	} iospace[4];		/* XXX this could be as high as 16 */
98c2380338SWarner Losh 	u_int16_t	irqmask;
99c2380338SWarner Losh 	int		num_memspace;
100c2380338SWarner Losh 	struct {
101c2380338SWarner Losh 		u_long	length;
102c2380338SWarner Losh 		u_long	cardaddr;
103c2380338SWarner Losh 		u_long	hostaddr;
104c2380338SWarner Losh 	} memspace[2];		/* XXX this could be as high as 8 */
105c2380338SWarner Losh 	int		maxtwins;
106c2380338SWarner Losh 	STAILQ_ENTRY(pccard_config_entry) cfe_list;
107c2380338SWarner Losh };
108c2380338SWarner Losh 
109c2380338SWarner Losh struct pccard_function {
110c2380338SWarner Losh 	/* read off the card */
111c2380338SWarner Losh 	int		number;
112c2380338SWarner Losh 	int		function;
113c2380338SWarner Losh 	int		last_config_index;
114c2380338SWarner Losh 	u_long		ccr_base;
115c2380338SWarner Losh 	u_long		ccr_mask;
116c2380338SWarner Losh 	STAILQ_HEAD(, pccard_config_entry) cfe_head;
117c2380338SWarner Losh 	STAILQ_ENTRY(pccard_function) pf_list;
118c2380338SWarner Losh 	/* run-time state */
119c2380338SWarner Losh 	struct pccard_softc *sc;
120c2380338SWarner Losh 	struct device *child;
121c2380338SWarner Losh 	struct pccard_config_entry *cfe;
122c2380338SWarner Losh 	struct pccard_mem_handle pf_pcmh;
123c2380338SWarner Losh #define	pf_ccrt		pf_pcmh.memt
124c2380338SWarner Losh #define	pf_ccrh		pf_pcmh.memh
125c2380338SWarner Losh #define	pf_ccr_mhandle	pf_pcmh.mhandle
126c2380338SWarner Losh #define	pf_ccr_realsize	pf_pcmh.realsize
127c2380338SWarner Losh 	bus_addr_t	pf_ccr_offset;
128c2380338SWarner Losh 	int		pf_ccr_window;
129c2380338SWarner Losh 	long		pf_mfc_iobase;
130c2380338SWarner Losh 	long		pf_mfc_iomax;
131c2380338SWarner Losh 	int		(*ih_fct) __P((void *));
132c2380338SWarner Losh 	void		*ih_arg;
133c2380338SWarner Losh 	int		ih_ipl;
134c2380338SWarner Losh 	int		pf_flags;
135c2380338SWarner Losh };
136c2380338SWarner Losh 
137c2380338SWarner Losh /* pf_flags */
138c2380338SWarner Losh #define	PFF_ENABLED	0x0001		/* function is enabled */
139c2380338SWarner Losh 
140c2380338SWarner Losh struct pccard_card {
141c2380338SWarner Losh 	int		cis1_major;
142c2380338SWarner Losh 	int		cis1_minor;
143c2380338SWarner Losh 	/* XXX waste of space? */
144c2380338SWarner Losh 	char		cis1_info_buf[256];
145c2380338SWarner Losh 	char		*cis1_info[4];
146c2380338SWarner Losh 	/*
147c2380338SWarner Losh 	 * Use int32_t for manufacturer and product so that they can
148c2380338SWarner Losh 	 * hold the id value found in card CIS and special value that
149c2380338SWarner Losh 	 * indicates no id was found.
150c2380338SWarner Losh 	 */
151c2380338SWarner Losh 	int32_t		manufacturer;
152c2380338SWarner Losh #define	PCCARD_VENDOR_INVALID	-1
153c2380338SWarner Losh 	int32_t		product;
154c2380338SWarner Losh #define	PCCARD_PRODUCT_INVALID		-1
155c2380338SWarner Losh 	u_int16_t	error;
156c2380338SWarner Losh #define	PCCARD_CIS_INVALID		{ NULL, NULL, NULL, NULL }
157c2380338SWarner Losh 	STAILQ_HEAD(, pccard_function) pf_head;
158c2380338SWarner Losh };
159c2380338SWarner Losh 
16012bba6c2SWarner Losh /* More later? */
16112bba6c2SWarner Losh struct pccard_ivar {
16212bba6c2SWarner Losh 	struct resource_list resources;
16312bba6c2SWarner Losh 	int	slotnum;
164c2380338SWarner Losh };
165c2380338SWarner Losh 
166c2380338SWarner Losh struct pccard_softc {
167c2380338SWarner Losh 
168c2380338SWarner Losh 	/* this stuff is for the socket */
169c2380338SWarner Losh 	pccard_chipset_tag_t pct;
170c2380338SWarner Losh 	pccard_chipset_handle_t pch;
171c2380338SWarner Losh 
172c2380338SWarner Losh 	/* this stuff is for the card */
173c2380338SWarner Losh 	struct pccard_card card;
174c2380338SWarner Losh 	void		*ih;
175c2380338SWarner Losh 	int		sc_enabled_count;	/* how many functions are
176c2380338SWarner Losh 						   enabled */
177c2380338SWarner Losh 
178c2380338SWarner Losh 	/*
179c2380338SWarner Losh 	 * These are passed down from the PCCARD chip, and exist only
180c2380338SWarner Losh 	 * so that cards with Very Special address allocation needs
181c2380338SWarner Losh 	 * know what range they should be dealing with.
182c2380338SWarner Losh 	 */
183c2380338SWarner Losh 	bus_addr_t iobase;		/* start i/o space allocation here */
184c2380338SWarner Losh 	bus_size_t iosize;		/* size of the i/o space range */
185c2380338SWarner Losh };
186c2380338SWarner Losh 
187c2380338SWarner Losh void
188c2380338SWarner Losh pccardbus_if_setup __P((struct pccard_softc*));
189c2380338SWarner Losh 
190c2380338SWarner Losh struct pccard_cis_quirk {
191c2380338SWarner Losh 	int32_t manufacturer;
192c2380338SWarner Losh 	int32_t product;
193c2380338SWarner Losh 	char *cis1_info[4];
194c2380338SWarner Losh 	struct pccard_function *pf;
195c2380338SWarner Losh 	struct pccard_config_entry *cfe;
196c2380338SWarner Losh };
197c2380338SWarner Losh 
198c2380338SWarner Losh struct pccard_attach_args {
199c2380338SWarner Losh 	int32_t manufacturer;
200c2380338SWarner Losh 	int32_t product;
201c2380338SWarner Losh 	struct pccard_card *card;
202c2380338SWarner Losh 	struct pccard_function *pf;
203c2380338SWarner Losh };
204c2380338SWarner Losh 
205c2380338SWarner Losh struct pccard_tuple {
206c2380338SWarner Losh 	unsigned int	code;
207c2380338SWarner Losh 	unsigned int	length;
208c2380338SWarner Losh 	u_long		mult;
209c2380338SWarner Losh 	bus_addr_t	ptr;
210c2380338SWarner Losh 	bus_space_tag_t	memt;
211c2380338SWarner Losh 	bus_space_handle_t memh;
212c2380338SWarner Losh };
213c2380338SWarner Losh 
214c2380338SWarner Losh void	pccard_read_cis __P((struct pccard_softc *));
215c2380338SWarner Losh void	pccard_check_cis_quirks(device_t);
216c2380338SWarner Losh void	pccard_print_cis(device_t);
217c2380338SWarner Losh int	pccard_scan_cis __P((struct device * dev,
218c2380338SWarner Losh 	    int (*) (struct pccard_tuple *, void *), void *));
219c2380338SWarner Losh 
220c2380338SWarner Losh #define	pccard_cis_read_1(tuple, idx0)					\
221c2380338SWarner Losh 	(bus_space_read_1((tuple)->memt, (tuple)->memh, (tuple)->mult*(idx0)))
222c2380338SWarner Losh 
223c2380338SWarner Losh #define	pccard_tuple_read_1(tuple, idx1)				\
224c2380338SWarner Losh 	(pccard_cis_read_1((tuple), ((tuple)->ptr+(2+(idx1)))))
225c2380338SWarner Losh 
226c2380338SWarner Losh #define	pccard_tuple_read_2(tuple, idx2)				\
227c2380338SWarner Losh 	(pccard_tuple_read_1((tuple), (idx2)) | 			\
228c2380338SWarner Losh 	 (pccard_tuple_read_1((tuple), (idx2)+1)<<8))
229c2380338SWarner Losh 
230c2380338SWarner Losh #define	pccard_tuple_read_3(tuple, idx3)				\
231c2380338SWarner Losh 	(pccard_tuple_read_1((tuple), (idx3)) |				\
232c2380338SWarner Losh 	 (pccard_tuple_read_1((tuple), (idx3)+1)<<8) |			\
233c2380338SWarner Losh 	 (pccard_tuple_read_1((tuple), (idx3)+2)<<16))
234c2380338SWarner Losh 
235c2380338SWarner Losh #define	pccard_tuple_read_4(tuple, idx4)				\
236c2380338SWarner Losh 	(pccard_tuple_read_1((tuple), (idx4)) |				\
237c2380338SWarner Losh 	 (pccard_tuple_read_1((tuple), (idx4)+1)<<8) |			\
238c2380338SWarner Losh 	 (pccard_tuple_read_1((tuple), (idx4)+2)<<16) |			\
239c2380338SWarner Losh 	 (pccard_tuple_read_1((tuple), (idx4)+3)<<24))
240c2380338SWarner Losh 
241c2380338SWarner Losh #define	pccard_tuple_read_n(tuple, n, idxn)				\
242c2380338SWarner Losh 	(((n)==1)?pccard_tuple_read_1((tuple), (idxn)) :		\
243c2380338SWarner Losh 	 (((n)==2)?pccard_tuple_read_2((tuple), (idxn)) :		\
244c2380338SWarner Losh 	  (((n)==3)?pccard_tuple_read_3((tuple), (idxn)) :		\
245c2380338SWarner Losh 	   /* n == 4 */ pccard_tuple_read_4((tuple), (idxn)))))
246c2380338SWarner Losh 
247c2380338SWarner Losh #define	PCCARD_SPACE_MEMORY	1
248c2380338SWarner Losh #define	PCCARD_SPACE_IO		2
249c2380338SWarner Losh 
250c2380338SWarner Losh int	pccard_ccr_read __P((struct pccard_function *, int));
251c2380338SWarner Losh void	pccard_ccr_write __P((struct pccard_function *, int, int));
252c2380338SWarner Losh 
253c2380338SWarner Losh #define	pccard_mfc(sc)	(STAILQ_FIRST(&(sc)->card.pf_head) &&		\
254c2380338SWarner Losh 		 STAILQ_NEXT(STAILQ_FIRST(&(sc)->card.pf_head),pf_list))
255c2380338SWarner Losh 
256c2380338SWarner Losh void	pccard_function_init __P((struct pccard_function *,
257c2380338SWarner Losh 	    struct pccard_config_entry *));
258c2380338SWarner Losh int	pccard_function_enable __P((struct pccard_function *));
259c2380338SWarner Losh void	pccard_function_disable __P((struct pccard_function *));
260c2380338SWarner Losh 
261c2380338SWarner Losh #define	pccard_io_alloc(pf, start, size, align, pciop)			\
262c2380338SWarner Losh 	(pccard_chip_io_alloc((pf)->sc->pct, pf->sc->pch, (start),	\
263c2380338SWarner Losh 	 (size), (align), (pciop)))
264c2380338SWarner Losh 
265c2380338SWarner Losh #define	pccard_io_free(pf, pciohp)					\
266c2380338SWarner Losh 	(pccard_chip_io_free((pf)->sc->pct, (pf)->sc->pch, (pciohp)))
267c2380338SWarner Losh 
268c2380338SWarner Losh int	pccard_io_map __P((struct pccard_function *, int, bus_addr_t,
269c2380338SWarner Losh 	    bus_size_t, struct pccard_io_handle *, int *));
270c2380338SWarner Losh void	pccard_io_unmap __P((struct pccard_function *, int));
271c2380338SWarner Losh 
272c2380338SWarner Losh #define pccard_mem_alloc(pf, size, pcmhp)				\
273c2380338SWarner Losh 	(pccard_chip_mem_alloc((pf)->sc->pct, (pf)->sc->pch, (size), (pcmhp)))
274c2380338SWarner Losh 
275c2380338SWarner Losh #define pccard_mem_free(pf, pcmhp)					\
276c2380338SWarner Losh 	(pccard_chip_mem_free((pf)->sc->pct, (pf)->sc->pch, (pcmhp)))
277c2380338SWarner Losh 
278c2380338SWarner Losh #define pccard_mem_map(pf, kind, card_addr, size, pcmhp, offsetp, windowp) \
279c2380338SWarner Losh 	(pccard_chip_mem_map((pf)->sc->pct, (pf)->sc->pch, (kind),	\
280c2380338SWarner Losh 	 (card_addr), (size), (pcmhp), (offsetp), (windowp)))
281c2380338SWarner Losh 
282c2380338SWarner Losh #define	pccard_mem_unmap(pf, window)					\
283c2380338SWarner Losh 	(pccard_chip_mem_unmap((pf)->sc->pct, (pf)->sc->pch, (window)))
284c2380338SWarner Losh 
285c2380338SWarner Losh void	*pccard_intr_establish __P((struct pccard_function *, int,
286c2380338SWarner Losh 	    int (*) (void *), void *));
287c2380338SWarner Losh void 	pccard_intr_disestablish __P((struct pccard_function *, void *));
288