pccardvarp.h revision 189318
116125Swpaul/*-
216125Swpaul * Copyright (c) 2005, M. Warner Losh
316125Swpaul * All rights reserved.
416125Swpaul *
516125Swpaul * Redistribution and use in source and binary forms, with or without
616125Swpaul * modification, are permitted provided that the following conditions
716125Swpaul * are met:
816125Swpaul * 1. Redistributions of source code must retain the above copyright
916125Swpaul *    notice unmodified, this list of conditions, and the following
1016125Swpaul *    disclaimer.
1116125Swpaul * 2. Redistributions in binary form must reproduce the above copyright
1216125Swpaul *    notice, this list of conditions and the following disclaimer in the
1316125Swpaul *    documentation and/or other materials provided with the distribution.
1416125Swpaul *
1516125Swpaul * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1616125Swpaul * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1716125Swpaul * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1816125Swpaul * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1916125Swpaul * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2016125Swpaul * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2116125Swpaul * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2216125Swpaul * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2316125Swpaul * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2416125Swpaul * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2516125Swpaul * SUCH DAMAGE.
2616125Swpaul *
2716125Swpaul * $FreeBSD: head/sys/dev/pccard/pccardvarp.h 189318 2009-03-03 18:57:59Z imp $
2816125Swpaul */
2916125Swpaul
3016125Swpaul#ifndef _PCCARD_PCCARDVARP_H
3116125Swpaul#define _PCCARD_PCCARDVARP_H
3216125Swpaul
33114601Sobrien/* pccard itself */
34114601Sobrien
3530378Scharnier#define PCCARD_MEM_PAGE_SIZE		1024
3616125Swpaul
3730378Scharnier#define PCCARD_CFE_MWAIT_REQUIRED	0x0001
3830378Scharnier#define PCCARD_CFE_RDYBSY_ACTIVE	0x0002
3969793Sobrien#define PCCARD_CFE_WP_ACTIVE		0x0004
4016125Swpaul#define PCCARD_CFE_BVD_ACTIVE		0x0008
4116125Swpaul#define PCCARD_CFE_IO8			0x0010
4223716Speter#define PCCARD_CFE_IO16			0x0020
4316125Swpaul#define PCCARD_CFE_IRQSHARE		0x0040
44129654Sstefanf#define PCCARD_CFE_IRQPULSE		0x0080
4516125Swpaul#define PCCARD_CFE_IRQLEVEL		0x0100
4616125Swpaul#define PCCARD_CFE_POWERDOWN		0x0200
4716125Swpaul#define PCCARD_CFE_READONLY		0x0400
4816125Swpaul#define PCCARD_CFE_AUDIO		0x0800
4916125Swpaul
5016125Swpaulstruct pccard_config_entry {
5116125Swpaul	int		number;
5216125Swpaul	uint32_t	flags;
5316125Swpaul	int		iftype;
5416125Swpaul	int		num_iospace;
5516125Swpaul
5616125Swpaul	/*
5716125Swpaul	 * The card will only decode this mask in any case, so we can
5816125Swpaul	 * do dynamic allocation with this in mind, in case the suggestions
5916125Swpaul	 * below are no good.
6016125Swpaul	 */
6116125Swpaul	u_long		iomask;
6216125Swpaul	struct {
6316125Swpaul		u_long	length;
6416125Swpaul		u_long	start;
6516125Swpaul	} iospace[4];		/* XXX this could be as high as 16 */
6616125Swpaul	uint16_t	irqmask;
6716125Swpaul	int		num_memspace;
6816125Swpaul	struct {
6916125Swpaul		u_long	length;
7016125Swpaul		u_long	cardaddr;
7116125Swpaul		u_long	hostaddr;
7216125Swpaul	} memspace[2];		/* XXX this could be as high as 8 */
7316125Swpaul	int		maxtwins;
7416125Swpaul	STAILQ_ENTRY(pccard_config_entry) cfe_list;
7516125Swpaul};
7616125Swpaul
7716125Swpaulstruct pccard_funce_disk {
7816125Swpaul	uint8_t pfd_interface;
7916125Swpaul	uint8_t pfd_power;
8016125Swpaul};
8116125Swpaul
8290298Sdesstruct pccard_funce_lan {
8390298Sdes	int pfl_nidlen;
8416125Swpaul	uint8_t pfl_nid[8];
8516125Swpaul};
8616125Swpaul
8762989Skrisunion pccard_funce {
8816125Swpaul	struct pccard_funce_disk pfv_disk;
8930378Scharnier	struct pccard_funce_lan pfv_lan;
9016125Swpaul};
9162989Skris
9216125Swpaulstruct pccard_function {
9316125Swpaul	/* read off the card */
9416125Swpaul	int		number;
9516125Swpaul	int		function;
9616125Swpaul	int		last_config_index;
9716125Swpaul	uint32_t	ccr_base;	/* Offset with card's memory */
9816125Swpaul	uint32_t	ccr_mask;
9916125Swpaul	struct resource *ccr_res;
10016125Swpaul	int		ccr_rid;
10116125Swpaul	STAILQ_HEAD(, pccard_config_entry) cfe_head;
10216125Swpaul	STAILQ_ENTRY(pccard_function) pf_list;
10316125Swpaul	/* run-time state */
10416125Swpaul	struct pccard_softc *sc;
10516125Swpaul	struct pccard_config_entry *cfe;
10616125Swpaul	struct pccard_mem_handle pf_pcmh;
10716125Swpaul	device_t	dev;
10816125Swpaul#define	pf_ccrt		pf_pcmh.memt
10916125Swpaul#define	pf_ccrh		pf_pcmh.memh
11016125Swpaul#define	pf_ccr_realsize	pf_pcmh.realsize
11116125Swpaul	uint32_t	pf_ccr_offset;	/* Offset from ccr_base of CIS */
11216125Swpaul	int		pf_ccr_window;
11316125Swpaul	bus_addr_t	pf_mfc_iobase;
11416125Swpaul	bus_addr_t	pf_mfc_iomax;
11516125Swpaul	int		pf_flags;
11616125Swpaul	driver_filter_t	*intr_filter;
11716125Swpaul	driver_intr_t	*intr_handler;
11816125Swpaul	void		*intr_handler_arg;
11916125Swpaul	void		*intr_handler_cookie;
12016125Swpaul
12116125Swpaul	union pccard_funce pf_funce; /* CISTPL_FUNCE */
12216125Swpaul#define pf_funce_disk_interface pf_funce.pfv_disk.pfd_interface
12390298Sdes#define pf_funce_disk_power pf_funce.pfv_disk.pfd_power
12416125Swpaul#define pf_funce_lan_nid pf_funce.pfv_lan.pfl_nid
12516125Swpaul#define pf_funce_lan_nidlen pf_funce.pfv_lan.pfl_nidlen
12616125Swpaul};
12716125Swpaul
12816125Swpaul/* pf_flags */
12916125Swpaul#define	PFF_ENABLED	0x0001		/* function is enabled */
13016125Swpaul
13116125Swpaulstruct pccard_card {
13216125Swpaul	int		cis1_major;
13316125Swpaul	int		cis1_minor;
13416125Swpaul	/* XXX waste of space? */
13516125Swpaul	char		cis1_info_buf[256];
13616125Swpaul	char		*cis1_info[4];
13716125Swpaul	/*
13816125Swpaul	 * Use int32_t for manufacturer and product so that they can
13916125Swpaul	 * hold the id value found in card CIS and special value that
14016125Swpaul	 * indicates no id was found.
14116125Swpaul	 */
14216125Swpaul	int32_t		manufacturer;
14316125Swpaul#define	PCMCIA_VENDOR_INVALID	-1
14416125Swpaul	int32_t		product;
14516125Swpaul#define	PCMCIA_PRODUCT_INVALID		-1
14616125Swpaul	int16_t		prodext;
14716125Swpaul	uint16_t	error;
14816125Swpaul#define	PCMCIA_CIS_INVALID		{ NULL, NULL, NULL, NULL }
14930378Scharnier	STAILQ_HEAD(, pccard_function) pf_head;
15016125Swpaul};
15116125Swpaul
15216125Swpaul/* More later? */
15316125Swpaulstruct pccard_ivar {
15416125Swpaul	struct resource_list resources;
15516125Swpaul	struct pccard_function *pf;
15616125Swpaul};
15716125Swpaul
15816125Swpaulstruct cis_buffer
15916125Swpaul{
16016125Swpaul	size_t	len;			/* Actual length of the CIS */
16190298Sdes	uint8_t buffer[2040];		/* small enough to be 2k */
16216125Swpaul};
16336642Swpaul
16436642Swpaulstruct pccard_softc {
16516125Swpaul	device_t		dev;
16636642Swpaul	/* this stuff is for the socket */
16736642Swpaul
16816125Swpaul	/* this stuff is for the card */
16916125Swpaul	struct pccard_card card;
17036642Swpaul	int		sc_enabled_count;	/* num functions enabled */
17116125Swpaul	struct cdev *cisdev;
17216125Swpaul	int	cis_open;
17316125Swpaul	struct cis_buffer *cis;
17416125Swpaul};
17516125Swpaul
17616125Swpaulstruct pccard_cis_quirk {
17716125Swpaul	int32_t manufacturer;
17816125Swpaul	int32_t product;
17916125Swpaul	char *cis1_info[4];
18016125Swpaul	struct pccard_function *pf;
18136642Swpaul	struct pccard_config_entry *cfe;
18236642Swpaul};
18336642Swpaul
18416125Swpaulvoid	pccard_read_cis(struct pccard_softc *);
18516125Swpaulvoid	pccard_check_cis_quirks(device_t);
18690298Sdesvoid	pccard_print_cis(device_t);
18790298Sdesint	pccard_scan_cis(device_t, device_t, pccard_scan_t, void *);
18816125Swpaul
18930378Scharnierint	pccard_device_create(struct pccard_softc *);
19016125Swpaulint	pccard_device_destroy(struct pccard_softc *);
19116125Swpaul
19216125Swpaul#define PCCARD_SOFTC(d) (struct pccard_softc *) device_get_softc(d)
19330378Scharnier#define PCCARD_IVAR(d) (struct pccard_ivar *) device_get_ivars(d)
19490298Sdes
19516125Swpaul#endif /* _PCCARD_PCCARDVARP_H */
19630378Scharnier