pccardvar.h revision 54250
152506Simp/*	$NetBSD: pcmciavar.h,v 1.9 1998/12/29 09:00:28 marc Exp $	*/
252506Simp/* $FreeBSD: head/sys/dev/pccard/pccardvar.h 54250 1999-12-07 06:44:38Z imp $ */
352506Simp
452506Simp/*
552506Simp * Copyright (c) 1997 Marc Horowitz.  All rights reserved.
652506Simp *
752506Simp * Redistribution and use in source and binary forms, with or without
852506Simp * modification, are permitted provided that the following conditions
952506Simp * are met:
1052506Simp * 1. Redistributions of source code must retain the above copyright
1152506Simp *    notice, this list of conditions and the following disclaimer.
1252506Simp * 2. Redistributions in binary form must reproduce the above copyright
1352506Simp *    notice, this list of conditions and the following disclaimer in the
1452506Simp *    documentation and/or other materials provided with the distribution.
1552506Simp * 3. All advertising materials mentioning features or use of this software
1652506Simp *    must display the following acknowledgement:
1752506Simp *	This product includes software developed by Marc Horowitz.
1852506Simp * 4. The name of the author may not be used to endorse or promote products
1952506Simp *    derived from this software without specific prior written permission.
2052506Simp *
2152506Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2252506Simp * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2352506Simp * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2452506Simp * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2552506Simp * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2652506Simp * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2752506Simp * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2852506Simp * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2952506Simp * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3052506Simp * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3152506Simp */
3252506Simp
3352506Simp#include <sys/types.h>
3452506Simp#include <sys/queue.h>
3552506Simp
3652506Simp#include <machine/bus.h>
3752506Simp
3852506Simp#include <dev/pccard/pccardchip.h>
3952506Simp
4052506Simpextern int	pccard_verbose;
4152506Simp
4252506Simp/*
4352506Simp * Contains information about mapped/allocated i/o spaces.
4452506Simp */
4552506Simpstruct pccard_io_handle {
4652506Simp	bus_space_tag_t iot;		/* bus space tag (from chipset) */
4752506Simp	bus_space_handle_t ioh;		/* mapped space handle */
4852506Simp	bus_addr_t      addr;		/* resulting address in bus space */
4952506Simp	bus_size_t      size;		/* size of i/o space */
5052506Simp	int             flags;		/* misc. information */
5154250Simp	int		width;
5252506Simp};
5352506Simp
5452506Simp#define	PCCARD_IO_ALLOCATED	0x01	/* i/o space was allocated */
5552506Simp
5652506Simp/*
5752506Simp * Contains information about allocated memory space.
5852506Simp */
5952506Simpstruct pccard_mem_handle {
6052506Simp	bus_space_tag_t memt;		/* bus space tag (from chipset) */
6152506Simp	bus_space_handle_t memh;	/* mapped space handle */
6252506Simp	bus_addr_t      addr;		/* resulting address in bus space */
6352506Simp	bus_size_t      size;		/* size of mem space */
6452506Simp	pccard_mem_handle_t mhandle;	/* opaque memory handle */
6552506Simp	bus_size_t      realsize;	/* how much we really allocated */
6654250Simp	long		offset;
6754250Simp	int		kind;
6852506Simp};
6952506Simp
7052506Simp/* pccard itself */
7152506Simp
7252506Simp#define PCCARD_CFE_MWAIT_REQUIRED	0x0001
7352506Simp#define PCCARD_CFE_RDYBSY_ACTIVE	0x0002
7452506Simp#define PCCARD_CFE_WP_ACTIVE		0x0004
7552506Simp#define PCCARD_CFE_BVD_ACTIVE		0x0008
7652506Simp#define PCCARD_CFE_IO8			0x0010
7752506Simp#define PCCARD_CFE_IO16			0x0020
7852506Simp#define PCCARD_CFE_IRQSHARE		0x0040
7952506Simp#define PCCARD_CFE_IRQPULSE		0x0080
8052506Simp#define PCCARD_CFE_IRQLEVEL		0x0100
8152506Simp#define PCCARD_CFE_POWERDOWN		0x0200
8252506Simp#define PCCARD_CFE_READONLY		0x0400
8352506Simp#define PCCARD_CFE_AUDIO		0x0800
8452506Simp
8552506Simpstruct pccard_config_entry {
8652506Simp	int		number;
8752506Simp	u_int32_t	flags;
8852506Simp	int		iftype;
8952506Simp	int		num_iospace;
9052506Simp
9152506Simp	/*
9252506Simp	 * The card will only decode this mask in any case, so we can
9352506Simp	 * do dynamic allocation with this in mind, in case the suggestions
9452506Simp	 * below are no good.
9552506Simp	 */
9652506Simp	u_long		iomask;
9752506Simp	struct {
9852506Simp		u_long	length;
9952506Simp		u_long	start;
10052506Simp	} iospace[4];		/* XXX this could be as high as 16 */
10152506Simp	u_int16_t	irqmask;
10252506Simp	int		num_memspace;
10352506Simp	struct {
10452506Simp		u_long	length;
10552506Simp		u_long	cardaddr;
10652506Simp		u_long	hostaddr;
10752506Simp	} memspace[2];		/* XXX this could be as high as 8 */
10852506Simp	int		maxtwins;
10952506Simp	STAILQ_ENTRY(pccard_config_entry) cfe_list;
11052506Simp};
11152506Simp
11252506Simpstruct pccard_function {
11352506Simp	/* read off the card */
11452506Simp	int		number;
11552506Simp	int		function;
11652506Simp	int		last_config_index;
11752506Simp	u_long		ccr_base;
11852506Simp	u_long		ccr_mask;
11952506Simp	STAILQ_HEAD(, pccard_config_entry) cfe_head;
12052506Simp	STAILQ_ENTRY(pccard_function) pf_list;
12152506Simp	/* run-time state */
12252506Simp	struct pccard_softc *sc;
12352506Simp	struct device *child;
12452506Simp	struct pccard_config_entry *cfe;
12552506Simp	struct pccard_mem_handle pf_pcmh;
12652506Simp#define	pf_ccrt		pf_pcmh.memt
12752506Simp#define	pf_ccrh		pf_pcmh.memh
12852506Simp#define	pf_ccr_mhandle	pf_pcmh.mhandle
12952506Simp#define	pf_ccr_realsize	pf_pcmh.realsize
13052506Simp	bus_addr_t	pf_ccr_offset;
13152506Simp	int		pf_ccr_window;
13252506Simp	long		pf_mfc_iobase;
13352506Simp	long		pf_mfc_iomax;
13454250Simp	int		(*ih_fct)(void *);
13552506Simp	void		*ih_arg;
13652506Simp	int		ih_ipl;
13752506Simp	int		pf_flags;
13852506Simp};
13952506Simp
14052506Simp/* pf_flags */
14152506Simp#define	PFF_ENABLED	0x0001		/* function is enabled */
14252506Simp
14352506Simpstruct pccard_card {
14452506Simp	int		cis1_major;
14552506Simp	int		cis1_minor;
14652506Simp	/* XXX waste of space? */
14752506Simp	char		cis1_info_buf[256];
14852506Simp	char		*cis1_info[4];
14952506Simp	/*
15052506Simp	 * Use int32_t for manufacturer and product so that they can
15152506Simp	 * hold the id value found in card CIS and special value that
15252506Simp	 * indicates no id was found.
15352506Simp	 */
15452506Simp	int32_t		manufacturer;
15552506Simp#define	PCCARD_VENDOR_INVALID	-1
15652506Simp	int32_t		product;
15752506Simp#define	PCCARD_PRODUCT_INVALID		-1
15852506Simp	u_int16_t	error;
15952506Simp#define	PCCARD_CIS_INVALID		{ NULL, NULL, NULL, NULL }
16052506Simp	STAILQ_HEAD(, pccard_function) pf_head;
16152506Simp};
16252506Simp
16353873Simp/* More later? */
16453873Simpstruct pccard_ivar {
16553873Simp	struct resource_list resources;
16653873Simp	int	slotnum;
16752506Simp};
16852506Simp
16952506Simpstruct pccard_softc {
17052506Simp
17152506Simp	/* this stuff is for the socket */
17252506Simp	pccard_chipset_tag_t pct;
17352506Simp	pccard_chipset_handle_t pch;
17452506Simp
17552506Simp	/* this stuff is for the card */
17652506Simp	struct pccard_card card;
17752506Simp	void		*ih;
17852506Simp	int		sc_enabled_count;	/* how many functions are
17952506Simp						   enabled */
18052506Simp
18152506Simp	/*
18252506Simp	 * These are passed down from the PCCARD chip, and exist only
18352506Simp	 * so that cards with Very Special address allocation needs
18452506Simp	 * know what range they should be dealing with.
18552506Simp	 */
18652506Simp	bus_addr_t iobase;		/* start i/o space allocation here */
18752506Simp	bus_size_t iosize;		/* size of the i/o space range */
18852506Simp};
18952506Simp
19052506Simpvoid
19154250Simppccardbus_if_setup(struct pccard_softc*);
19252506Simp
19352506Simpstruct pccard_cis_quirk {
19452506Simp	int32_t manufacturer;
19552506Simp	int32_t product;
19652506Simp	char *cis1_info[4];
19752506Simp	struct pccard_function *pf;
19852506Simp	struct pccard_config_entry *cfe;
19952506Simp};
20052506Simp
20152506Simpstruct pccard_attach_args {
20252506Simp	int32_t manufacturer;
20352506Simp	int32_t product;
20452506Simp	struct pccard_card *card;
20552506Simp	struct pccard_function *pf;
20652506Simp};
20752506Simp
20852506Simpstruct pccard_tuple {
20952506Simp	unsigned int	code;
21052506Simp	unsigned int	length;
21152506Simp	u_long		mult;
21252506Simp	bus_addr_t	ptr;
21352506Simp	bus_space_tag_t	memt;
21452506Simp	bus_space_handle_t memh;
21552506Simp};
21652506Simp
21754250Simpvoid	pccard_read_cis(struct pccard_softc *);
21852506Simpvoid	pccard_check_cis_quirks(device_t);
21952506Simpvoid	pccard_print_cis(device_t);
22054250Simpint	pccard_scan_cis(struct device * dev,
22154250Simp	    int (*) (struct pccard_tuple *, void *), void *);
22252506Simp
22352506Simp#define	pccard_cis_read_1(tuple, idx0)					\
22452506Simp	(bus_space_read_1((tuple)->memt, (tuple)->memh, (tuple)->mult*(idx0)))
22552506Simp
22652506Simp#define	pccard_tuple_read_1(tuple, idx1)				\
22752506Simp	(pccard_cis_read_1((tuple), ((tuple)->ptr+(2+(idx1)))))
22852506Simp
22952506Simp#define	pccard_tuple_read_2(tuple, idx2)				\
23052506Simp	(pccard_tuple_read_1((tuple), (idx2)) | 			\
23152506Simp	 (pccard_tuple_read_1((tuple), (idx2)+1)<<8))
23252506Simp
23352506Simp#define	pccard_tuple_read_3(tuple, idx3)				\
23452506Simp	(pccard_tuple_read_1((tuple), (idx3)) |				\
23552506Simp	 (pccard_tuple_read_1((tuple), (idx3)+1)<<8) |			\
23652506Simp	 (pccard_tuple_read_1((tuple), (idx3)+2)<<16))
23752506Simp
23852506Simp#define	pccard_tuple_read_4(tuple, idx4)				\
23952506Simp	(pccard_tuple_read_1((tuple), (idx4)) |				\
24052506Simp	 (pccard_tuple_read_1((tuple), (idx4)+1)<<8) |			\
24152506Simp	 (pccard_tuple_read_1((tuple), (idx4)+2)<<16) |			\
24252506Simp	 (pccard_tuple_read_1((tuple), (idx4)+3)<<24))
24352506Simp
24452506Simp#define	pccard_tuple_read_n(tuple, n, idxn)				\
24552506Simp	(((n)==1)?pccard_tuple_read_1((tuple), (idxn)) :		\
24652506Simp	 (((n)==2)?pccard_tuple_read_2((tuple), (idxn)) :		\
24752506Simp	  (((n)==3)?pccard_tuple_read_3((tuple), (idxn)) :		\
24852506Simp	   /* n == 4 */ pccard_tuple_read_4((tuple), (idxn)))))
24952506Simp
25052506Simp#define	PCCARD_SPACE_MEMORY	1
25152506Simp#define	PCCARD_SPACE_IO		2
25252506Simp
25354250Simpint	pccard_ccr_read(struct pccard_function *, int);
25454250Simpvoid	pccard_ccr_write(struct pccard_function *, int, int);
25552506Simp
25652506Simp#define	pccard_mfc(sc)	(STAILQ_FIRST(&(sc)->card.pf_head) &&		\
25752506Simp		 STAILQ_NEXT(STAILQ_FIRST(&(sc)->card.pf_head),pf_list))
25852506Simp
25954250Simpvoid	pccard_function_init(struct pccard_function *,
26054250Simp	    struct pccard_config_entry *);
26154250Simpint	pccard_function_enable(struct pccard_function *);
26254250Simpvoid	pccard_function_disable(struct pccard_function *);
26352506Simp
26452506Simp#define	pccard_io_alloc(pf, start, size, align, pciop)			\
26552506Simp	(pccard_chip_io_alloc((pf)->sc->pct, pf->sc->pch, (start),	\
26652506Simp	 (size), (align), (pciop)))
26752506Simp
26852506Simp#define	pccard_io_free(pf, pciohp)					\
26952506Simp	(pccard_chip_io_free((pf)->sc->pct, (pf)->sc->pch, (pciohp)))
27052506Simp
27154250Simpint	pccard_io_map(struct pccard_function *, int, bus_addr_t,
27254250Simp	    bus_size_t, struct pccard_io_handle *, int *);
27354250Simpvoid	pccard_io_unmap(struct pccard_function *, int);
27452506Simp
27552506Simp#define pccard_mem_alloc(pf, size, pcmhp)				\
27652506Simp	(pccard_chip_mem_alloc((pf)->sc->pct, (pf)->sc->pch, (size), (pcmhp)))
27752506Simp
27852506Simp#define pccard_mem_free(pf, pcmhp)					\
27952506Simp	(pccard_chip_mem_free((pf)->sc->pct, (pf)->sc->pch, (pcmhp)))
28052506Simp
28152506Simp#define pccard_mem_map(pf, kind, card_addr, size, pcmhp, offsetp, windowp) \
28252506Simp	(pccard_chip_mem_map((pf)->sc->pct, (pf)->sc->pch, (kind),	\
28352506Simp	 (card_addr), (size), (pcmhp), (offsetp), (windowp)))
28452506Simp
28552506Simp#define	pccard_mem_unmap(pf, window)					\
28652506Simp	(pccard_chip_mem_unmap((pf)->sc->pct, (pf)->sc->pch, (window)))
28752506Simp
28854250Simpvoid	*pccard_intr_establish(struct pccard_function *, int,
28954250Simp	    int (*) (void *), void *);
29054250Simpvoid 	pccard_intr_disestablish(struct pccard_function *, void *);
291