pccardvar.h revision 66200
166200Simp/*	$NetBSD: pcmciavar.h,v 1.12 2000/02/08 12:51:31 enami Exp $	*/
252506Simp/* $FreeBSD: head/sys/dev/pccard/pccardvar.h 66200 2000-09-22 01:15:26Z 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
3852506Simpextern int	pccard_verbose;
3952506Simp
4052506Simp/*
4152506Simp * Contains information about mapped/allocated i/o spaces.
4252506Simp */
4352506Simpstruct pccard_io_handle {
4452506Simp	bus_space_tag_t iot;		/* bus space tag (from chipset) */
4552506Simp	bus_space_handle_t ioh;		/* mapped space handle */
4652506Simp	bus_addr_t      addr;		/* resulting address in bus space */
4752506Simp	bus_size_t      size;		/* size of i/o space */
4852506Simp	int             flags;		/* misc. information */
4954250Simp	int		width;
5052506Simp};
5152506Simp
5252506Simp#define	PCCARD_IO_ALLOCATED	0x01	/* i/o space was allocated */
5352506Simp
5452506Simp/*
5552506Simp * Contains information about allocated memory space.
5652506Simp */
5752506Simpstruct pccard_mem_handle {
5852506Simp	bus_space_tag_t memt;		/* bus space tag (from chipset) */
5952506Simp	bus_space_handle_t memh;	/* mapped space handle */
6052506Simp	bus_addr_t      addr;		/* resulting address in bus space */
6152506Simp	bus_size_t      size;		/* size of mem space */
6252506Simp	bus_size_t      realsize;	/* how much we really allocated */
6354250Simp	long		offset;
6454250Simp	int		kind;
6552506Simp};
6652506Simp
6752506Simp/* pccard itself */
6852506Simp
6952506Simp#define PCCARD_CFE_MWAIT_REQUIRED	0x0001
7052506Simp#define PCCARD_CFE_RDYBSY_ACTIVE	0x0002
7152506Simp#define PCCARD_CFE_WP_ACTIVE		0x0004
7252506Simp#define PCCARD_CFE_BVD_ACTIVE		0x0008
7352506Simp#define PCCARD_CFE_IO8			0x0010
7452506Simp#define PCCARD_CFE_IO16			0x0020
7552506Simp#define PCCARD_CFE_IRQSHARE		0x0040
7652506Simp#define PCCARD_CFE_IRQPULSE		0x0080
7752506Simp#define PCCARD_CFE_IRQLEVEL		0x0100
7852506Simp#define PCCARD_CFE_POWERDOWN		0x0200
7952506Simp#define PCCARD_CFE_READONLY		0x0400
8052506Simp#define PCCARD_CFE_AUDIO		0x0800
8152506Simp
8252506Simpstruct pccard_config_entry {
8352506Simp	int		number;
8452506Simp	u_int32_t	flags;
8552506Simp	int		iftype;
8652506Simp	int		num_iospace;
8752506Simp
8852506Simp	/*
8952506Simp	 * The card will only decode this mask in any case, so we can
9052506Simp	 * do dynamic allocation with this in mind, in case the suggestions
9152506Simp	 * below are no good.
9252506Simp	 */
9352506Simp	u_long		iomask;
9452506Simp	struct {
9552506Simp		u_long	length;
9652506Simp		u_long	start;
9752506Simp	} iospace[4];		/* XXX this could be as high as 16 */
9852506Simp	u_int16_t	irqmask;
9952506Simp	int		num_memspace;
10052506Simp	struct {
10152506Simp		u_long	length;
10252506Simp		u_long	cardaddr;
10352506Simp		u_long	hostaddr;
10452506Simp	} memspace[2];		/* XXX this could be as high as 8 */
10552506Simp	int		maxtwins;
10660938Sjake	STAILQ_ENTRY(pccard_config_entry) cfe_list;
10752506Simp};
10852506Simp
10952506Simpstruct pccard_function {
11052506Simp	/* read off the card */
11152506Simp	int		number;
11252506Simp	int		function;
11352506Simp	int		last_config_index;
11452506Simp	u_long		ccr_base;
11552506Simp	u_long		ccr_mask;
11655720Simp	struct resource *ccr_res;
11755720Simp	int		ccr_rid;
11860938Sjake	STAILQ_HEAD(, pccard_config_entry) cfe_head;
11960938Sjake	STAILQ_ENTRY(pccard_function) pf_list;
12052506Simp	/* run-time state */
12152506Simp	struct pccard_softc *sc;
12252506Simp	struct pccard_config_entry *cfe;
12352506Simp	struct pccard_mem_handle pf_pcmh;
12464927Simp	device_t	dev;
12552506Simp#define	pf_ccrt		pf_pcmh.memt
12652506Simp#define	pf_ccrh		pf_pcmh.memh
12752506Simp#define	pf_ccr_realsize	pf_pcmh.realsize
12852506Simp	bus_addr_t	pf_ccr_offset;
12952506Simp	int		pf_ccr_window;
13052506Simp	long		pf_mfc_iobase;
13152506Simp	long		pf_mfc_iomax;
13254250Simp	int		(*ih_fct)(void *);
13352506Simp	void		*ih_arg;
13452506Simp	int		ih_ipl;
13552506Simp	int		pf_flags;
13652506Simp};
13752506Simp
13852506Simp/* pf_flags */
13952506Simp#define	PFF_ENABLED	0x0001		/* function is enabled */
14052506Simp
14152506Simpstruct pccard_card {
14252506Simp	int		cis1_major;
14352506Simp	int		cis1_minor;
14452506Simp	/* XXX waste of space? */
14552506Simp	char		cis1_info_buf[256];
14652506Simp	char		*cis1_info[4];
14752506Simp	/*
14852506Simp	 * Use int32_t for manufacturer and product so that they can
14952506Simp	 * hold the id value found in card CIS and special value that
15052506Simp	 * indicates no id was found.
15152506Simp	 */
15252506Simp	int32_t		manufacturer;
15352506Simp#define	PCCARD_VENDOR_INVALID	-1
15452506Simp	int32_t		product;
15552506Simp#define	PCCARD_PRODUCT_INVALID		-1
15652506Simp	u_int16_t	error;
15752506Simp#define	PCCARD_CIS_INVALID		{ NULL, NULL, NULL, NULL }
15860938Sjake	STAILQ_HEAD(, pccard_function) pf_head;
15952506Simp};
16052506Simp
16159389Simp#define	PCCARD_MEM_ATTR		1
16259389Simp#define	PCCARD_MEM_COMMON	2
16359389Simp
16459389Simp#define	PCCARD_WIDTH_AUTO	0
16559389Simp#define	PCCARD_WIDTH_IO8	1
16659389Simp#define	PCCARD_WIDTH_IO16	2
16759389Simp
16853873Simp/* More later? */
16953873Simpstruct pccard_ivar {
17053873Simp	struct resource_list resources;
17165917Simp	struct pccard_function *fcn;
17252506Simp};
17352506Simp
17452506Simpstruct pccard_softc {
17555720Simp	device_t		dev;
17652506Simp	/* this stuff is for the socket */
17752506Simp
17852506Simp	/* this stuff is for the card */
17952506Simp	struct pccard_card card;
18055500Simp	int		sc_enabled_count;	/* num functions enabled */
18152506Simp};
18252506Simp
18352506Simpvoid
18454250Simppccardbus_if_setup(struct pccard_softc*);
18552506Simp
18652506Simpstruct pccard_cis_quirk {
18752506Simp	int32_t manufacturer;
18852506Simp	int32_t product;
18952506Simp	char *cis1_info[4];
19052506Simp	struct pccard_function *pf;
19152506Simp	struct pccard_config_entry *cfe;
19252506Simp};
19352506Simp
19452506Simpstruct pccard_tuple {
19552506Simp	unsigned int	code;
19652506Simp	unsigned int	length;
19752506Simp	u_long		mult;
19852506Simp	bus_addr_t	ptr;
19952506Simp	bus_space_tag_t	memt;
20052506Simp	bus_space_handle_t memh;
20152506Simp};
20252506Simp
20366200Simpstruct pccard_product {
20466200Simp	const char	*pp_name;		/* NULL if end of table */
20566200Simp#define PCCARD_VENDOR_ANY ((u_int32_t) -1)
20666200Simp	u_int32_t	pp_vendor;
20766200Simp#define PCCARD_PRODUCT_ANY ((u_int32_t) -1)
20866200Simp	u_int32_t	pp_product;
20966200Simp	int		pp_expfunc;
21066200Simp	const char	*pp_vendor_str;		/* NULL to not match */
21166200Simp	const char	*pp_product_str;	/* NULL to not match */
21266200Simp};
21366200Simp
21466200Simptypedef int (*pccard_product_match_fn) (device_t dev,
21566200Simp    const struct pccard_product *ent, int vpfmatch);
21666200Simp
21766200Simpconst struct pccard_product
21866200Simp	*pccard_product_lookup(device_t dev, const struct pccard_product *tab,
21966200Simp	    size_t ent_size, pccard_product_match_fn matchfn);
22066200Simp
22154250Simpvoid	pccard_read_cis(struct pccard_softc *);
22252506Simpvoid	pccard_check_cis_quirks(device_t);
22352506Simpvoid	pccard_print_cis(device_t);
22459193Simpint	pccard_scan_cis(device_t,
22559193Simp		int (*) (struct pccard_tuple *, void *), void *);
22652506Simp
22752506Simp#define	pccard_cis_read_1(tuple, idx0)					\
22852506Simp	(bus_space_read_1((tuple)->memt, (tuple)->memh, (tuple)->mult*(idx0)))
22952506Simp
23052506Simp#define	pccard_tuple_read_1(tuple, idx1)				\
23152506Simp	(pccard_cis_read_1((tuple), ((tuple)->ptr+(2+(idx1)))))
23252506Simp
23352506Simp#define	pccard_tuple_read_2(tuple, idx2)				\
23452506Simp	(pccard_tuple_read_1((tuple), (idx2)) | 			\
23552506Simp	 (pccard_tuple_read_1((tuple), (idx2)+1)<<8))
23652506Simp
23752506Simp#define	pccard_tuple_read_3(tuple, idx3)				\
23852506Simp	(pccard_tuple_read_1((tuple), (idx3)) |				\
23952506Simp	 (pccard_tuple_read_1((tuple), (idx3)+1)<<8) |			\
24052506Simp	 (pccard_tuple_read_1((tuple), (idx3)+2)<<16))
24152506Simp
24252506Simp#define	pccard_tuple_read_4(tuple, idx4)				\
24352506Simp	(pccard_tuple_read_1((tuple), (idx4)) |				\
24452506Simp	 (pccard_tuple_read_1((tuple), (idx4)+1)<<8) |			\
24552506Simp	 (pccard_tuple_read_1((tuple), (idx4)+2)<<16) |			\
24652506Simp	 (pccard_tuple_read_1((tuple), (idx4)+3)<<24))
24752506Simp
24852506Simp#define	pccard_tuple_read_n(tuple, n, idxn)				\
24952506Simp	(((n)==1)?pccard_tuple_read_1((tuple), (idxn)) :		\
25052506Simp	 (((n)==2)?pccard_tuple_read_2((tuple), (idxn)) :		\
25152506Simp	  (((n)==3)?pccard_tuple_read_3((tuple), (idxn)) :		\
25252506Simp	   /* n == 4 */ pccard_tuple_read_4((tuple), (idxn)))))
25352506Simp
25452506Simp#define	PCCARD_SPACE_MEMORY	1
25552506Simp#define	PCCARD_SPACE_IO		2
25652506Simp
25754250Simpint	pccard_ccr_read(struct pccard_function *, int);
25854250Simpvoid	pccard_ccr_write(struct pccard_function *, int, int);
25952506Simp
26052506Simp#define	pccard_mfc(sc)	(STAILQ_FIRST(&(sc)->card.pf_head) &&		\
26152506Simp		 STAILQ_NEXT(STAILQ_FIRST(&(sc)->card.pf_head),pf_list))
26252506Simp
26364850Simp/* The following is the vestages of the NetBSD driver api */
26464850Simp
26565917Simpvoid	pccard_function_init(struct pccard_function *);
26654250Simpint	pccard_function_enable(struct pccard_function *);
26754250Simpvoid	pccard_function_disable(struct pccard_function *);
26852506Simp
26952506Simp#define	pccard_io_alloc(pf, start, size, align, pciop)			\
27052506Simp	(pccard_chip_io_alloc((pf)->sc->pct, pf->sc->pch, (start),	\
27152506Simp	 (size), (align), (pciop)))
27252506Simp
27352506Simp#define	pccard_io_free(pf, pciohp)					\
27452506Simp	(pccard_chip_io_free((pf)->sc->pct, (pf)->sc->pch, (pciohp)))
27552506Simp
27654250Simpint	pccard_io_map(struct pccard_function *, int, bus_addr_t,
27754250Simp	    bus_size_t, struct pccard_io_handle *, int *);
27854250Simpvoid	pccard_io_unmap(struct pccard_function *, int);
27952506Simp
28052506Simp#define pccard_mem_alloc(pf, size, pcmhp)				\
28152506Simp	(pccard_chip_mem_alloc((pf)->sc->pct, (pf)->sc->pch, (size), (pcmhp)))
28252506Simp#define pccard_mem_free(pf, pcmhp)					\
28352506Simp	(pccard_chip_mem_free((pf)->sc->pct, (pf)->sc->pch, (pcmhp)))
28452506Simp#define pccard_mem_map(pf, kind, card_addr, size, pcmhp, offsetp, windowp) \
28552506Simp	(pccard_chip_mem_map((pf)->sc->pct, (pf)->sc->pch, (kind),	\
28652506Simp	 (card_addr), (size), (pcmhp), (offsetp), (windowp)))
28752506Simp#define	pccard_mem_unmap(pf, window)					\
28852506Simp	(pccard_chip_mem_unmap((pf)->sc->pct, (pf)->sc->pch, (window)))
28956361Shosokawa
29066058Simp/* compat layer */
29166058Simpint pccard_compat_probe(device_t dev);
29266058Simpint pccard_compat_attach(device_t dev);
29366058Simp
29456361Shosokawa/* ivar interface */
29556361Shosokawaenum {
29656361Shosokawa	PCCARD_IVAR_ETHADDR,	/* read ethernet address from CIS tupple */
29766200Simp	PCCARD_IVAR_VENDOR,
29866200Simp	PCCARD_IVAR_PRODUCT,
29966200Simp	PCCARD_IVAR_FUNCTION_NUMBER,
30066200Simp	PCCARD_IVAR_VENDOR_STR,	/* CIS string for "Manufacturer" */
30166200Simp	PCCARD_IVAR_PRODUCT_STR,/* CIS strnig for "Product" */
30266200Simp	PCCARD_IVAR_CIS3_STR	/* Some cards need this */
30356361Shosokawa};
30456361Shosokawa
30566200Simp#define PCCARD_ACCESSOR(A, B, T)					\
30666200Simp__inline static int							\
30766200Simppccard_get_ ## A(device_t dev, T *t)					\
30866200Simp{									\
30966200Simp	return BUS_READ_IVAR(device_get_parent(dev), dev, 		\
31066200Simp	    PCCARD_IVAR_ ## B, (uintptr_t *) t);			\
31156361Shosokawa}
31258581Simp
31366200SimpPCCARD_ACCESSOR(ether,		ETHADDR,		u_int8_t)
31466200SimpPCCARD_ACCESSOR(vendor,		VENDOR,			u_int32_t)
31566200SimpPCCARD_ACCESSOR(product,	PRODUCT,		u_int32_t)
31666200SimpPCCARD_ACCESSOR(function_number,FUNCTION_NUMBER,	u_int32_t)
31766200SimpPCCARD_ACCESSOR(vendor_str,	VENDOR_STR,		char *)
31866200SimpPCCARD_ACCESSOR(product_str,	PRODUCT_STR,		char *)
31966200SimpPCCARD_ACCESSOR(cis3_str,	CIS3_STR,		char *)
32066200Simp
32158581Simpenum {
32259193Simp	PCCARD_A_MEM_ATTR = 0x1
32358581Simp};
32458581Simp
32564850Simp#define PCCARD_SOFTC(d) (struct pccard_softc *) device_get_softc(d)
326