xref: /illumos-gate/usr/src/boot/common/isapnp.h (revision 55fea89dcaa64928bed4327112404dcb3e07b79f)
1*22028508SToomas Soome /*
2*22028508SToomas Soome  * Copyright (c) 1996, Sujal M. Patel
3*22028508SToomas Soome  * All rights reserved.
4*22028508SToomas Soome  *
5*22028508SToomas Soome  * Redistribution and use in source and binary forms, with or without
6*22028508SToomas Soome  * modification, are permitted provided that the following conditions
7*22028508SToomas Soome  * are met:
8*22028508SToomas Soome  * 1. Redistributions of source code must retain the above copyright
9*22028508SToomas Soome  *    notice, this list of conditions and the following disclaimer.
10*22028508SToomas Soome  * 2. Redistributions in binary form must reproduce the above copyright
11*22028508SToomas Soome  *    notice, this list of conditions and the following disclaimer in the
12*22028508SToomas Soome  *    documentation and/or other materials provided with the distribution.
13*22028508SToomas Soome  * 3. All advertising materials mentioning features or use of this software
14*22028508SToomas Soome  *    must display the following acknowledgement:
15*22028508SToomas Soome  *      This product includes software developed by Sujal M. Patel
16*22028508SToomas Soome  * 4. Neither the name of the author nor the names of any co-contributors
17*22028508SToomas Soome  *    may be used to endorse or promote products derived from this software
18*22028508SToomas Soome  *    without specific prior written permission.
19*22028508SToomas Soome  *
20*22028508SToomas Soome  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21*22028508SToomas Soome  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22*22028508SToomas Soome  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23*22028508SToomas Soome  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24*22028508SToomas Soome  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25*22028508SToomas Soome  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26*22028508SToomas Soome  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27*22028508SToomas Soome  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28*22028508SToomas Soome  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29*22028508SToomas Soome  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30*22028508SToomas Soome  * SUCH DAMAGE.
31*22028508SToomas Soome  */
32*22028508SToomas Soome 
33*22028508SToomas Soome #ifndef _I386_ISA_PNP_H_
34*22028508SToomas Soome #define _I386_ISA_PNP_H_
35*22028508SToomas Soome 
36*22028508SToomas Soome /* Maximum Number of PnP Devices.  8 should be plenty */
37*22028508SToomas Soome #define MAX_PNP_CARDS 8
38*22028508SToomas Soome /*
39*22028508SToomas Soome  * the following is the maximum number of PnP Logical devices that
40*22028508SToomas Soome  * userconfig can handle.
41*22028508SToomas Soome  */
42*22028508SToomas Soome #define MAX_PNP_LDN	20
43*22028508SToomas Soome 
44*22028508SToomas Soome /* Static ports to access PnP state machine */
45*22028508SToomas Soome #ifndef _KERNEL
46*22028508SToomas Soome /* pnp.h is included from pnpinfo.c. */
47*22028508SToomas Soome #define _PNP_ADDRESS		0x279
48*22028508SToomas Soome #define _PNP_WRITE_DATA		0xa79
49*22028508SToomas Soome #endif
50*22028508SToomas Soome 
51*22028508SToomas Soome /* PnP Registers.  Write to ADDRESS and then use WRITE/READ_DATA */
52*22028508SToomas Soome #define SET_RD_DATA		0x00
53*22028508SToomas Soome 	/***
54*22028508SToomas Soome 	Writing to this location modifies the address of the port used for
55*22028508SToomas Soome 	reading from the Plug and Play ISA cards.   Bits[7:0] become I/O
56*22028508SToomas Soome 	read port address bits[9:2].  Reads from this register are ignored.
57*22028508SToomas Soome 	***/
58*22028508SToomas Soome 
59*22028508SToomas Soome #define SERIAL_ISOLATION	0x01
60*22028508SToomas Soome 	/***
61*22028508SToomas Soome 	A read to this register causes a Plug and Play cards in the Isolation
62*22028508SToomas Soome 	state to compare one bit of the boards ID.
63*22028508SToomas Soome 	This register is read only.
64*22028508SToomas Soome 	***/
65*22028508SToomas Soome 
66*22028508SToomas Soome #define	CONFIG_CONTROL		0x02
67*22028508SToomas Soome 	/***
68*22028508SToomas Soome 	Bit[2]  Reset CSN to 0
69*22028508SToomas Soome 	Bit[1]  Return to the Wait for Key state
70*22028508SToomas Soome 	Bit[0]  Reset all logical devices and restore configuration
71*22028508SToomas Soome 		registers to their power-up values.
72*22028508SToomas Soome 
73*22028508SToomas Soome 	A write to bit[0] of this register performs a reset function on
74*22028508SToomas Soome 	all logical devices.  This resets the contents of configuration
75*22028508SToomas Soome 	registers to  their default state.  All card's logical devices
76*22028508SToomas Soome 	enter their default state and the CSN is preserved.
77*22028508SToomas Soome 
78*22028508SToomas Soome 	A write to bit[1] of this register causes all cards to enter the
79*22028508SToomas Soome 	Wait for Key state but all CSNs are preserved and logical devices
80*22028508SToomas Soome 	are not affected.
81*22028508SToomas Soome 
82*22028508SToomas Soome 	A write to bit[2] of this register causes all cards to reset their
83*22028508SToomas Soome 	CSN to zero .
84*22028508SToomas Soome 
85*22028508SToomas Soome 	This register is write-only.  The values are not sticky, that is,
86*22028508SToomas Soome 	hardware will automatically clear them and there is no need for
87*22028508SToomas Soome 	software to clear the bits.
88*22028508SToomas Soome 	***/
89*22028508SToomas Soome 
90*22028508SToomas Soome #define WAKE			0x03
91*22028508SToomas Soome 	/***
92*22028508SToomas Soome 	A write to this port will cause all cards that have a CSN that
93*22028508SToomas Soome 	matches the write data[7:0] to go from the Sleep state to the either
94*22028508SToomas Soome 	the Isolation state if the write data for this command is zero or
95*22028508SToomas Soome 	the Config state if the write data is not zero.  Additionally, the
96*22028508SToomas Soome 	pointer to the byte-serial device is reset.  This register is
97*22028508SToomas Soome 	writeonly.
98*22028508SToomas Soome 	***/
99*22028508SToomas Soome 
100*22028508SToomas Soome #define	RESOURCE_DATA		0x04
101*22028508SToomas Soome 	/***
102*22028508SToomas Soome 	A read from this address reads the next byte of resource information.
103*22028508SToomas Soome 	The Status register must be polled until bit[0] is set before this
104*22028508SToomas Soome 	register may be read.  This register is read only.
105*22028508SToomas Soome 	***/
106*22028508SToomas Soome 
107*22028508SToomas Soome #define STATUS			0x05
108*22028508SToomas Soome 	/***
109*22028508SToomas Soome 	Bit[0] when set indicates it is okay to read the next data byte
110*22028508SToomas Soome 	from the Resource Data register.  This register is readonly.
111*22028508SToomas Soome 	***/
112*22028508SToomas Soome 
113*22028508SToomas Soome #define SET_CSN			0x06
114*22028508SToomas Soome 	/***
115*22028508SToomas Soome 	A write to this port sets a card's CSN.  The CSN is a value uniquely
116*22028508SToomas Soome 	assigned to each ISA card after the serial identification process
117*22028508SToomas Soome 	so that each card may be individually selected during a Wake[CSN]
118*22028508SToomas Soome 	command. This register is read/write.
119*22028508SToomas Soome 	***/
120*22028508SToomas Soome 
121*22028508SToomas Soome #define SET_LDN			0x07
122*22028508SToomas Soome 	/***
123*22028508SToomas Soome 	Selects the current logical device.  All reads and writes of memory,
124*22028508SToomas Soome 	I/O, interrupt and DMA configuration information access the registers
125*22028508SToomas Soome 	of the logical device written here.  In addition, the I/O Range
126*22028508SToomas Soome 	Check and Activate  commands operate only on the selected logical
127*22028508SToomas Soome 	device.  This register is read/write. If a card has only 1 logical
128*22028508SToomas Soome 	device, this location should be a read-only value of 0x00.
129*22028508SToomas Soome 	***/
130*22028508SToomas Soome 
131*22028508SToomas Soome /*** addresses 0x08 - 0x1F Card Level Reserved for future use ***/
132*22028508SToomas Soome /*** addresses 0x20 - 0x2F Card Level, Vendor Defined ***/
133*22028508SToomas Soome 
134*22028508SToomas Soome #define ACTIVATE		0x30
135*22028508SToomas Soome 	/***
136*22028508SToomas Soome 	For each logical device there is one activate register that controls
137*22028508SToomas Soome 	whether or not the logical device is active on the ISA bus.  Bit[0],
138*22028508SToomas Soome 	if set, activates the logical device.  Bits[7:1] are reserved and
139*22028508SToomas Soome 	must return 0 on reads.  This is a read/write register. Before a
140*22028508SToomas Soome 	logical device is activated, I/O range check must be disabled.
141*22028508SToomas Soome 	***/
142*22028508SToomas Soome 
143*22028508SToomas Soome #define IO_RANGE_CHECK		0x31
144*22028508SToomas Soome 	/***
145*22028508SToomas Soome 	This register is used to perform a conflict check on the I/O port
146*22028508SToomas Soome 	range programmed for use by a logical device.
147*22028508SToomas Soome 
148*22028508SToomas Soome 	Bit[7:2]  Reserved and must return 0 on reads
149*22028508SToomas Soome 	Bit[1]    Enable I/O Range check, if set then I/O Range Check
150*22028508SToomas Soome 	is enabled. I/O range check is only valid when the logical
151*22028508SToomas Soome 	device is inactive.
152*22028508SToomas Soome 
153*22028508SToomas Soome 	Bit[0], if set, forces the logical device to respond to I/O reads
154*22028508SToomas Soome 	of the logical device's assigned I/O range with a 0x55 when I/O
155*22028508SToomas Soome 	range check is in operation.  If clear, the logical device drives
156*22028508SToomas Soome 	0xAA.  This register is read/write.
157*22028508SToomas Soome 	***/
158*22028508SToomas Soome 
159*22028508SToomas Soome /*** addr 0x32 - 0x37 Logical Device Control Reserved for future use ***/
160*22028508SToomas Soome /*** addr 0x38 - 0x3F Logical Device Control Vendor Define ***/
161*22028508SToomas Soome 
162*22028508SToomas Soome #define MEM_CONFIG		0x40
163*22028508SToomas Soome 	/***
164*22028508SToomas Soome 	Four memory resource registers per range, four ranges.
165*22028508SToomas Soome 	Fill with 0 if no ranges are enabled.
166*22028508SToomas Soome 
167*22028508SToomas Soome 	Offset 0:	RW Memory base address bits[23:16]
168*22028508SToomas Soome 	Offset 1:	RW Memory base address bits[15:8]
169*22028508SToomas Soome 	Offset 2:	Memory control
170*22028508SToomas Soome 	    Bit[1] specifies 8/16-bit control.  This bit is set to indicate
171*22028508SToomas Soome 	    16-bit memory, and cleared to indicate 8-bit memory.
172*22028508SToomas Soome 	    Bit[0], if cleared, indicates the next field can be used as a range
173*22028508SToomas Soome 	    length for decode (implies range length and base alignment of memory
174*22028508SToomas Soome 	    descriptor are equal).
175*22028508SToomas Soome 	    Bit[0], if set, indicates the next field is the upper limit for
176*22028508SToomas Soome 	    the address. -  - Bit[0] is read-only.
177*22028508SToomas Soome 	Offset 3:	RW upper limit or range len, bits[23:16]
178*22028508SToomas Soome 	Offset 4:	RW upper limit or range len, bits[15:8]
179*22028508SToomas Soome 	Offset 5-Offset 7: filler, unused.
180*22028508SToomas Soome 	***/
181*22028508SToomas Soome 
182*22028508SToomas Soome #define IO_CONFIG_BASE		0x60
183*22028508SToomas Soome 	/***
184*22028508SToomas Soome 	Eight ranges, two bytes per range.
185*22028508SToomas Soome 	Offset 0:		I/O port base address bits[15:8]
186*22028508SToomas Soome 	Offset 1:		I/O port base address bits[7:0]
187*22028508SToomas Soome 	***/
188*22028508SToomas Soome 
189*22028508SToomas Soome #define IRQ_CONFIG		0x70
190*22028508SToomas Soome 	/***
191*22028508SToomas Soome 	Two entries, two bytes per entry.
192*22028508SToomas Soome 	Offset 0:	RW interrupt level (1..15, 0=unused).
193*22028508SToomas Soome 	Offset 1:	Bit[1]: level(1:hi, 0:low),
194*22028508SToomas Soome 			Bit[0]: type (1:level, 0:edge)
195*22028508SToomas Soome 		byte 1 can be readonly if 1 type of int is used.
196*22028508SToomas Soome 	***/
197*22028508SToomas Soome 
198*22028508SToomas Soome #define DRQ_CONFIG		0x74
199*22028508SToomas Soome 	/***
200*22028508SToomas Soome 	Two entries, one byte per entry. Bits[2:0] select
201*22028508SToomas Soome 	which DMA channel is in use for DMA 0.  Zero selects DMA channel
202*22028508SToomas Soome 	0, seven selects DMA channel 7. DMA channel 4, the cascade channel
203*22028508SToomas Soome 	is used to indicate no DMA channel is active.
204*22028508SToomas Soome 	***/
205*22028508SToomas Soome 
206*22028508SToomas Soome /*** 32-bit memory accesses are at 0x76 ***/
207*22028508SToomas Soome 
208*22028508SToomas Soome /* Macros to parse Resource IDs */
209*22028508SToomas Soome #define PNP_RES_TYPE(a)		(a >> 7)
210*22028508SToomas Soome #define PNP_SRES_NUM(a)		(a >> 3)
211*22028508SToomas Soome #define PNP_SRES_LEN(a)		(a & 0x07)
212*22028508SToomas Soome #define PNP_LRES_NUM(a)		(a & 0x7f)
213*22028508SToomas Soome 
214*22028508SToomas Soome /* Small Resource Item names */
215*22028508SToomas Soome #define PNP_VERSION		0x1
216*22028508SToomas Soome #define LOG_DEVICE_ID		0x2
217*22028508SToomas Soome #define COMP_DEVICE_ID		0x3
218*22028508SToomas Soome #define IRQ_FORMAT		0x4
219*22028508SToomas Soome #define DMA_FORMAT		0x5
220*22028508SToomas Soome #define START_DEPEND_FUNC	0x6
221*22028508SToomas Soome #define END_DEPEND_FUNC		0x7
222*22028508SToomas Soome #define IO_PORT_DESC		0x8
223*22028508SToomas Soome #define FIXED_IO_PORT_DESC	0x9
224*22028508SToomas Soome #define SM_RES_RESERVED		0xa-0xd
225*22028508SToomas Soome #define SM_VENDOR_DEFINED	0xe
226*22028508SToomas Soome #define END_TAG			0xf
227*22028508SToomas Soome 
228*22028508SToomas Soome /* Large Resource Item names */
229*22028508SToomas Soome #define MEMORY_RANGE_DESC	0x1
230*22028508SToomas Soome #define ID_STRING_ANSI		0x2
231*22028508SToomas Soome #define ID_STRING_UNICODE	0x3
232*22028508SToomas Soome #define LG_VENDOR_DEFINED	0x4
233*22028508SToomas Soome #define _32BIT_MEM_RANGE_DESC	0x5
234*22028508SToomas Soome #define _32BIT_FIXED_LOC_DESC	0x6
235*22028508SToomas Soome #define LG_RES_RESERVED		0x7-0x7f
236*22028508SToomas Soome 
237*22028508SToomas Soome /*
238*22028508SToomas Soome  * pnp_cinfo contains Configuration Information. They are used
239*22028508SToomas Soome  * to communicate to the device driver the actual configuration
240*22028508SToomas Soome  * of the device, and also by the userconfig menu to let the
241*22028508SToomas Soome  * operating system override any configuration set by the bios.
242*22028508SToomas Soome  *
243*22028508SToomas Soome  */
244*22028508SToomas Soome struct pnp_cinfo {
245*22028508SToomas Soome 	u_int vendor_id;	/* board id */
246*22028508SToomas Soome 	u_int serial;		/* Board's Serial Number */
247*22028508SToomas Soome 	u_long flags;		/* OS-reserved flags */
248*22028508SToomas Soome 	u_char csn;		/* assigned Card Select Number */
249*22028508SToomas Soome 	u_char ldn;		/* Logical Device Number */
250*22028508SToomas Soome 	u_char enable;		/* pnp enable */
251*22028508SToomas Soome 	u_char override;	/* override bios parms (in userconfig) */
252*22028508SToomas Soome 	u_char irq[2];		/* IRQ Number */
253*22028508SToomas Soome 	u_char irq_type[2];	/* IRQ Type */
254*22028508SToomas Soome 	u_char drq[2];
255*22028508SToomas Soome 	u_short port[8];	/* The Base Address of the Port */
256*22028508SToomas Soome 	struct {
257*22028508SToomas Soome 		u_long base;	/* Memory Base Address */
258*22028508SToomas Soome 		int control;	/* Memory Control Register */
259*22028508SToomas Soome 		u_long range;	/* Memory Range *OR* Upper Limit */
260*22028508SToomas Soome 	} mem[4];
261*22028508SToomas Soome };
262*22028508SToomas Soome 
263*22028508SToomas Soome #ifdef _KERNEL
264*22028508SToomas Soome 
265*22028508SToomas Soome struct pnp_device {
266*22028508SToomas Soome     char *pd_name;
267*22028508SToomas Soome     char * (*pd_probe ) (u_long csn, u_long vendor_id);
268*22028508SToomas Soome     void (*pd_attach ) (u_long csn, u_long vend_id, char * name,
269*22028508SToomas Soome 	struct isa_device *dev);
270*22028508SToomas Soome     u_long	*pd_count;
271*22028508SToomas Soome     u_int *imask ;
272*22028508SToomas Soome };
273*22028508SToomas Soome 
274*22028508SToomas Soome struct _pnp_id {
275*22028508SToomas Soome     u_long vendor_id;
276*22028508SToomas Soome     u_long serial;
277*22028508SToomas Soome     u_char checksum;
278*22028508SToomas Soome } ;
279*22028508SToomas Soome 
280*22028508SToomas Soome struct pnp_dlist_node {
281*22028508SToomas Soome     struct pnp_device *pnp;
282*22028508SToomas Soome     struct isa_device dev;
283*22028508SToomas Soome     struct pnp_dlist_node *next;
284*22028508SToomas Soome };
285*22028508SToomas Soome 
286*22028508SToomas Soome typedef struct _pnp_id pnp_id;
287*22028508SToomas Soome extern struct pnp_dlist_node *pnp_device_list;
288*22028508SToomas Soome extern pnp_id pnp_devices[MAX_PNP_CARDS];
289*22028508SToomas Soome extern struct pnp_cinfo pnp_ldn_overrides[MAX_PNP_LDN];
290*22028508SToomas Soome extern int pnp_overrides_valid;
291*22028508SToomas Soome 
292*22028508SToomas Soome /*
293*22028508SToomas Soome  * these two functions are for use in drivers
294*22028508SToomas Soome  */
295*22028508SToomas Soome int read_pnp_parms(struct pnp_cinfo *d, int ldn);
296*22028508SToomas Soome int write_pnp_parms(struct pnp_cinfo *d, int ldn);
297*22028508SToomas Soome int enable_pnp_card(void);
298*22028508SToomas Soome 
299*22028508SToomas Soome /*
300*22028508SToomas Soome  * used by autoconfigure to actually probe and attach drivers
301*22028508SToomas Soome  */
302*22028508SToomas Soome void pnp_configure(void);
303*22028508SToomas Soome 
304*22028508SToomas Soome #endif /* _KERNEL */
305*22028508SToomas Soome 
306*22028508SToomas Soome #endif /* !_I386_ISA_PNP_H_ */
307