pccardvar.h revision 55500
1/*	$NetBSD: pcmciavar.h,v 1.9 1998/12/29 09:00:28 marc Exp $	*/
2/* $FreeBSD: head/sys/dev/pccard/pccardvar.h 55500 2000-01-06 07:30:28Z imp $ */
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#include <sys/types.h>
34#include <sys/queue.h>
35
36#include <machine/bus.h>
37
38#include <dev/pccard/pccardchip.h>
39
40extern int	pccard_verbose;
41
42/*
43 * Contains information about mapped/allocated i/o spaces.
44 */
45struct pccard_io_handle {
46	bus_space_tag_t iot;		/* bus space tag (from chipset) */
47	bus_space_handle_t ioh;		/* mapped space handle */
48	bus_addr_t      addr;		/* resulting address in bus space */
49	bus_size_t      size;		/* size of i/o space */
50	int             flags;		/* misc. information */
51	int		width;
52};
53
54#define	PCCARD_IO_ALLOCATED	0x01	/* i/o space was allocated */
55
56/*
57 * Contains information about allocated memory space.
58 */
59struct pccard_mem_handle {
60	bus_space_tag_t memt;		/* bus space tag (from chipset) */
61	bus_space_handle_t memh;	/* mapped space handle */
62	bus_addr_t      addr;		/* resulting address in bus space */
63	bus_size_t      size;		/* size of mem space */
64	pccard_mem_handle_t mhandle;	/* opaque memory handle */
65	bus_size_t      realsize;	/* how much we really allocated */
66	long		offset;
67	int		kind;
68};
69
70/* pccard itself */
71
72#define PCCARD_CFE_MWAIT_REQUIRED	0x0001
73#define PCCARD_CFE_RDYBSY_ACTIVE	0x0002
74#define PCCARD_CFE_WP_ACTIVE		0x0004
75#define PCCARD_CFE_BVD_ACTIVE		0x0008
76#define PCCARD_CFE_IO8			0x0010
77#define PCCARD_CFE_IO16			0x0020
78#define PCCARD_CFE_IRQSHARE		0x0040
79#define PCCARD_CFE_IRQPULSE		0x0080
80#define PCCARD_CFE_IRQLEVEL		0x0100
81#define PCCARD_CFE_POWERDOWN		0x0200
82#define PCCARD_CFE_READONLY		0x0400
83#define PCCARD_CFE_AUDIO		0x0800
84
85struct pccard_config_entry {
86	int		number;
87	u_int32_t	flags;
88	int		iftype;
89	int		num_iospace;
90
91	/*
92	 * The card will only decode this mask in any case, so we can
93	 * do dynamic allocation with this in mind, in case the suggestions
94	 * below are no good.
95	 */
96	u_long		iomask;
97	struct {
98		u_long	length;
99		u_long	start;
100	} iospace[4];		/* XXX this could be as high as 16 */
101	u_int16_t	irqmask;
102	int		num_memspace;
103	struct {
104		u_long	length;
105		u_long	cardaddr;
106		u_long	hostaddr;
107	} memspace[2];		/* XXX this could be as high as 8 */
108	int		maxtwins;
109	STAILQ_ENTRY(pccard_config_entry) cfe_list;
110};
111
112struct pccard_function {
113	/* read off the card */
114	int		number;
115	int		function;
116	int		last_config_index;
117	u_long		ccr_base;
118	u_long		ccr_mask;
119	STAILQ_HEAD(, pccard_config_entry) cfe_head;
120	STAILQ_ENTRY(pccard_function) pf_list;
121	/* run-time state */
122	struct pccard_softc *sc;
123	struct device *child;
124	struct pccard_config_entry *cfe;
125	struct pccard_mem_handle pf_pcmh;
126#define	pf_ccrt		pf_pcmh.memt
127#define	pf_ccrh		pf_pcmh.memh
128#define	pf_ccr_mhandle	pf_pcmh.mhandle
129#define	pf_ccr_realsize	pf_pcmh.realsize
130	bus_addr_t	pf_ccr_offset;
131	int		pf_ccr_window;
132	long		pf_mfc_iobase;
133	long		pf_mfc_iomax;
134	int		(*ih_fct)(void *);
135	void		*ih_arg;
136	int		ih_ipl;
137	int		pf_flags;
138};
139
140/* pf_flags */
141#define	PFF_ENABLED	0x0001		/* function is enabled */
142
143struct pccard_card {
144	int		cis1_major;
145	int		cis1_minor;
146	/* XXX waste of space? */
147	char		cis1_info_buf[256];
148	char		*cis1_info[4];
149	/*
150	 * Use int32_t for manufacturer and product so that they can
151	 * hold the id value found in card CIS and special value that
152	 * indicates no id was found.
153	 */
154	int32_t		manufacturer;
155#define	PCCARD_VENDOR_INVALID	-1
156	int32_t		product;
157#define	PCCARD_PRODUCT_INVALID		-1
158	u_int16_t	error;
159#define	PCCARD_CIS_INVALID		{ NULL, NULL, NULL, NULL }
160	STAILQ_HEAD(, pccard_function) pf_head;
161};
162
163/* More later? */
164struct pccard_ivar {
165	struct resource_list resources;
166	int	slotnum;
167};
168
169struct pccard_softc {
170
171	/* this stuff is for the socket */
172	pccard_chipset_tag_t pct;
173	pccard_chipset_handle_t pch;
174
175	device_t		dev;
176
177	/* this stuff is for the card */
178	struct pccard_card card;
179	void		*ih;
180	int		sc_enabled_count;	/* num functions enabled */
181
182	/*
183	 * These are passed down from the PCCARD chip, and exist only
184	 * so that cards with Very Special address allocation needs
185	 * know what range they should be dealing with.
186	 */
187	bus_addr_t iobase;		/* start i/o space allocation here */
188	bus_size_t iosize;		/* size of the i/o space range */
189};
190
191void
192pccardbus_if_setup(struct pccard_softc*);
193
194struct pccard_cis_quirk {
195	int32_t manufacturer;
196	int32_t product;
197	char *cis1_info[4];
198	struct pccard_function *pf;
199	struct pccard_config_entry *cfe;
200};
201
202struct pccard_tuple {
203	unsigned int	code;
204	unsigned int	length;
205	u_long		mult;
206	bus_addr_t	ptr;
207	bus_space_tag_t	memt;
208	bus_space_handle_t memh;
209};
210
211void	pccard_read_cis(struct pccard_softc *);
212void	pccard_check_cis_quirks(device_t);
213void	pccard_print_cis(device_t);
214int	pccard_scan_cis(struct device * dev,
215	    int (*) (struct pccard_tuple *, void *), void *);
216
217#define	pccard_cis_read_1(tuple, idx0)					\
218	(bus_space_read_1((tuple)->memt, (tuple)->memh, (tuple)->mult*(idx0)))
219
220#define	pccard_tuple_read_1(tuple, idx1)				\
221	(pccard_cis_read_1((tuple), ((tuple)->ptr+(2+(idx1)))))
222
223#define	pccard_tuple_read_2(tuple, idx2)				\
224	(pccard_tuple_read_1((tuple), (idx2)) | 			\
225	 (pccard_tuple_read_1((tuple), (idx2)+1)<<8))
226
227#define	pccard_tuple_read_3(tuple, idx3)				\
228	(pccard_tuple_read_1((tuple), (idx3)) |				\
229	 (pccard_tuple_read_1((tuple), (idx3)+1)<<8) |			\
230	 (pccard_tuple_read_1((tuple), (idx3)+2)<<16))
231
232#define	pccard_tuple_read_4(tuple, idx4)				\
233	(pccard_tuple_read_1((tuple), (idx4)) |				\
234	 (pccard_tuple_read_1((tuple), (idx4)+1)<<8) |			\
235	 (pccard_tuple_read_1((tuple), (idx4)+2)<<16) |			\
236	 (pccard_tuple_read_1((tuple), (idx4)+3)<<24))
237
238#define	pccard_tuple_read_n(tuple, n, idxn)				\
239	(((n)==1)?pccard_tuple_read_1((tuple), (idxn)) :		\
240	 (((n)==2)?pccard_tuple_read_2((tuple), (idxn)) :		\
241	  (((n)==3)?pccard_tuple_read_3((tuple), (idxn)) :		\
242	   /* n == 4 */ pccard_tuple_read_4((tuple), (idxn)))))
243
244#define	PCCARD_SPACE_MEMORY	1
245#define	PCCARD_SPACE_IO		2
246
247int	pccard_ccr_read(struct pccard_function *, int);
248void	pccard_ccr_write(struct pccard_function *, int, int);
249
250#define	pccard_mfc(sc)	(STAILQ_FIRST(&(sc)->card.pf_head) &&		\
251		 STAILQ_NEXT(STAILQ_FIRST(&(sc)->card.pf_head),pf_list))
252
253void	pccard_function_init(struct pccard_function *,
254	    struct pccard_config_entry *);
255int	pccard_function_enable(struct pccard_function *);
256void	pccard_function_disable(struct pccard_function *);
257
258#define	pccard_io_alloc(pf, start, size, align, pciop)			\
259	(pccard_chip_io_alloc((pf)->sc->pct, pf->sc->pch, (start),	\
260	 (size), (align), (pciop)))
261
262#define	pccard_io_free(pf, pciohp)					\
263	(pccard_chip_io_free((pf)->sc->pct, (pf)->sc->pch, (pciohp)))
264
265int	pccard_io_map(struct pccard_function *, int, bus_addr_t,
266	    bus_size_t, struct pccard_io_handle *, int *);
267void	pccard_io_unmap(struct pccard_function *, int);
268
269#define pccard_mem_alloc(pf, size, pcmhp)				\
270	(pccard_chip_mem_alloc((pf)->sc->pct, (pf)->sc->pch, (size), (pcmhp)))
271
272#define pccard_mem_free(pf, pcmhp)					\
273	(pccard_chip_mem_free((pf)->sc->pct, (pf)->sc->pch, (pcmhp)))
274
275#define pccard_mem_map(pf, kind, card_addr, size, pcmhp, offsetp, windowp) \
276	(pccard_chip_mem_map((pf)->sc->pct, (pf)->sc->pch, (kind),	\
277	 (card_addr), (size), (pcmhp), (offsetp), (windowp)))
278
279#define	pccard_mem_unmap(pf, window)					\
280	(pccard_chip_mem_unmap((pf)->sc->pct, (pf)->sc->pch, (window)))
281
282void	*pccard_intr_establish(struct pccard_function *, int,
283	    int (*) (void *), void *);
284void 	pccard_intr_disestablish(struct pccard_function *, void *);
285