xref: /freebsd/usr.sbin/dumpcis/cardinfo.h (revision 63a938566d524836885917d95bd491aa4400b181)
1 /*
2  *	Include file for PCMCIA user process interface
3  *
4  *-------------------------------------------------------------------------
5  */
6 /*-
7  * SPDX-License-Identifier: BSD-3-Clause
8  *
9  * Copyright (c) 1995 Andrew McRae.  All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 /* $FreeBSD$ */
35 
36 #ifndef	_PCCARD_CARDINFO_H_
37 #define	_PCCARD_CARDINFO_H_
38 
39 #ifndef _KERNEL
40 #include <sys/types.h>
41 #endif
42 #include <sys/ioccom.h>
43 
44 #define	PIOCGSTATE	_IOR('P', 1, struct slotstate)	/* Get slot state */
45 #define	PIOCGMEM	_IOWR('P', 2, struct mem_desc)	/* Get memory map */
46 #define	PIOCSMEM	_IOW('P', 3, struct mem_desc)	/* Set memory map */
47 #define	PIOCGIO		_IOWR('P', 4, struct io_desc)	/* Get I/O map */
48 #define	PIOCSIO		_IOW('P', 5, struct io_desc)	/* Set I/O map */
49 #define PIOCSDRV	_IOWR('P', 6, struct dev_desc)	/* Set driver */
50 #define PIOCRWFLAG	_IOW('P', 7, int)	/* Set flags for drv use */
51 #define PIOCRWMEM	_IOWR('P', 8, unsigned long) /* Set mem for drv use */
52 #define PIOCSPOW	_IOW('P', 9, struct power) /* Set power structure */
53 #define PIOCSVIR	_IOW('P', 10, int)	/* Virtual insert/remove */
54 #define PIOCSBEEP	_IOW('P', 11, int)		/* Select Beep */
55 #define PIOCSRESOURCE	_IOWR('P', 12, struct pccard_resource)	/* get resource info */
56 /*
57  *	Debug codes.
58  */
59 #define PIOCGREG	_IOWR('P',100, struct pcic_reg)	/* get reg */
60 #define PIOCSREG	_IOW('P', 101, struct pcic_reg)	/* Set reg */
61 
62 /*
63  *	Slot states for PIOCGSTATE
64  *
65  *	Here's a state diagram of all the possible states:
66  *
67  *                             power x 1
68  *                       -------------------
69  *                      /                   \
70  *                     /                     v
71  *    resume    +----------+   power x 0   +----------+
72  *      ------->| inactive |<--------------| filled   |
73  *     /        +----------+               +----------+
74  *    /           /     \                   ^   |
75  *  nil <---------       \        insert or |   | suspend or
76  *        suspend         \       power x 1 |   | eject
77  *                         \                |   v
78  *                          \            +----------+
79  *                           ----------->|  empty   |
80  *                             eject     +----------+
81  *
82  *	Note, the above diagram is for the state.  On suspend, the laststate
83  * gets set to suspend to tell pccardd what happened.  Also the nil state
84  * means that when the no state change has happened.  Note: if you eject
85  * while suspended in the inactive state, you will return to the
86  * empty state if you do not insert a new card and to the inactive state
87  * if you do insert a new card.
88  *
89  * Some might argue that inactive should be sticky forever and
90  * eject/insert shouldn't take it out of that state.  They might be
91  * right.  On the other hand, some would argue that eject resets all
92  * state.  They might be right.  They both can't be right.  The above
93  * represents a reasonable compromise between the two.
94  *
95  * Some bridges allow one to query to see if the card was changed while
96  * we were suspended.  Others do not.  We make no use of this functionality
97  * at this time.
98  */
99 enum cardstate { noslot, empty, suspend, filled, inactive };
100 
101 /*
102  *	Descriptor structure for memory map.
103  */
104 struct mem_desc {
105 	int	window;		/* Memory map window number (0-4) */
106 	int	flags;		/* Flags - see below */
107 	caddr_t	start;		/* System memory start */
108 	int	size;		/* Size of memory area */
109 	unsigned long card;	/* Card memory address */
110 };
111 
112 #define	MDF_16BITS	0x01	/* Memory is 16 bits wide */
113 #define	MDF_ZEROWS	0x02	/* Set no wait states for memory */
114 #define	MDF_WS0		0x04	/* Wait state flags */
115 #define	MDF_WS1		0x08
116 #define	MDF_ATTR	0x10	/* Memory is attribute memory */
117 #define	MDF_WP		0x20	/* Write protect memory */
118 #define	MDF_ACTIVE	0x40	/* Context active (read-only) */
119 
120 /*
121  *	Descriptor structure for I/O map
122  */
123 struct io_desc {
124 	int	window;		/* I/O map number (0-1) */
125 	int	flags;		/* Flags - see below */
126 	int	start;		/* I/O port start */
127 	int	size;		/* Number of port addresses */
128 };
129 
130 #define	IODF_WS		0x01	/* Set wait states for 16 bit I/O access */
131 #define	IODF_16BIT	0x02	/* I/O access are 16 bit */
132 #define	IODF_CS16	0x04	/* Allow card selection of 16 bit access */
133 #define	IODF_ZEROWS	0x08	/* No wait states for 8 bit I/O */
134 #define	IODF_ACTIVE	0x10	/* Context active (read-only) */
135 
136 /*
137  *	Device descriptor for allocation of driver.
138  */
139 #define DEV_MISC_LEN	36
140 #define DEV_MAX_CIS_LEN	40
141 struct dev_desc {
142 	char		name[16];	/* Driver name */
143 	int		unit;		/* Driver unit number */
144 	unsigned long	mem;		/* Memory address of driver */
145 	int		memsize;	/* Memory size (if used) */
146 	int		iobase;		/* base of I/O ports */
147 	int		iosize;		/* Length of I/O ports */
148 	int		irqmask;	/* Interrupt number(s) to allocate */
149 	int		flags;		/* Device flags */
150 	uint8_t		misc[DEV_MISC_LEN]; /* For any random info */
151 	uint8_t		manufstr[DEV_MAX_CIS_LEN];
152 	uint8_t		versstr[DEV_MAX_CIS_LEN];
153 	uint8_t		cis3str[DEV_MAX_CIS_LEN];
154 	uint8_t		cis4str[DEV_MAX_CIS_LEN];
155 	uint32_t	manufacturer;	/* Manufacturer ID */
156 	uint32_t	product;	/* Product ID */
157 	uint32_t	prodext;	/* Product ID (extended) */
158 };
159 #define DEV_DESC_HAS_SIZE 1
160 
161 struct pcic_reg {
162 	unsigned char reg;
163 	unsigned char value;
164 };
165 
166 /*
167  *	Slot information. Used to read current status of slot.
168  */
169 struct slotstate {
170 	enum cardstate	state;		/* Current state of slot */
171 	enum cardstate	laststate;	/* Previous state of slot */
172 	int		maxmem;		/* Max allowed memory windows */
173 	int		maxio;		/* Max allowed I/O windows */
174 	int		irqs;		/* Bitmap of IRQs allowed */
175 	int		flags;		/* Capability flags */
176 };
177 
178 /*
179  *	The power values are in volts * 10, e.g. 5V is 50, 3.3V is 33.
180  */
181 struct power {
182 	int		vcc;
183 	int		vpp;
184 };
185 
186 /*
187  *	The PC-Card resource IOC_GET_RESOURCE_RANGE
188  */
189 struct pccard_resource {
190 	int		type;
191 	u_long		size;
192 	u_long		min;
193 	u_long		max;
194 	u_long		resource_addr;
195 };
196 
197 
198 /*
199  *	Other system limits
200  */
201 #define MAXSLOT 16
202 #define	NUM_MEM_WINDOWS	10
203 #define	NUM_IO_WINDOWS	6
204 #define	CARD_DEVICE	"/dev/card%d"		/* String for snprintf */
205 #define	PCCARD_MEMSIZE	(4*1024)
206 
207 #endif /* !_PCCARD_CARDINFO_H_ */
208