pcivar.h revision 6100
1150861Scognet/**************************************************************************
2150861Scognet**
3150861Scognet**  $Id: pcireg.h,v 1.2 1994/11/02 23:47:14 se Exp $
4150861Scognet**
5150861Scognet**  Declarations for pci device drivers.
6150861Scognet**
7150861Scognet**  386bsd / FreeBSD
8150861Scognet**
9150861Scognet**-------------------------------------------------------------------------
10150861Scognet**
11150861Scognet** Copyright (c) 1994 Wolfgang Stanglmeier.  All rights reserved.
12150861Scognet**
13150861Scognet** Redistribution and use in source and binary forms, with or without
14150861Scognet** modification, are permitted provided that the following conditions
15150861Scognet** are met:
16150861Scognet** 1. Redistributions of source code must retain the above copyright
17150861Scognet**    notice, this list of conditions and the following disclaimer.
18150861Scognet** 2. Redistributions in binary form must reproduce the above copyright
19150861Scognet**    notice, this list of conditions and the following disclaimer in the
20150861Scognet**    documentation and/or other materials provided with the distribution.
21150861Scognet** 3. The name of the author may not be used to endorse or promote products
22150861Scognet**    derived from this software without specific prior written permission.
23150861Scognet**
24150861Scognet** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25150861Scognet** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26150861Scognet** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27150861Scognet** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28163871Scognet** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29150861Scognet** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30153112Scognet** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31150861Scognet** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32154561Scognet** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33159084Scognet** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34159557Scognet**
35154561Scognet***************************************************************************
36161334Simp*/
37161334Simp
38161334Simp#ifndef __PCI_VAR_H__
39161334Simp#define __PCI_VAR_H__
40150861Scognet
41153112Scognet/*-----------------------------------------------------------------
42150861Scognet**
43150861Scognet**	main pci initialization function.
44150861Scognet**	called at boot time from autoconf.c
45150861Scognet**
46159557Scognet**-----------------------------------------------------------------
47159557Scognet*/
48177508Scognet
49152743Scognetvoid pci_configure (void);
50171619Scognet
51152743Scognet/*-----------------------------------------------------------------
52153112Scognet**
53152743Scognet**	The pci configuration id describes a pci device on the bus.
54159084Scognet**	It is constructed from: bus, device & function numbers.
55159084Scognet**
56159084Scognet**-----------------------------------------------------------------
57159084Scognet*/
58159084Scognet
59159557Scognettypedef union {
60177916Sraj	u_long	 cfg1;
61177916Sraj        struct {
62159084Scognet		 u_char   enable;
63159084Scognet		 u_char   forward;
64159084Scognet		 u_short  port;
65159084Scognet	       } cfg2;
66159084Scognet	} pcici_t;
67159084Scognet
68161592Scognet/*-----------------------------------------------------------------
69161592Scognet**
70159084Scognet**	Each pci device has an unique device id.
71171619Scognet**	It is used to find a matching driver.
72171619Scognet**
73159084Scognet**-----------------------------------------------------------------
74171619Scognet*/
75171619Scognet
76183840Srajtypedef u_long pcidi_t;
77186933Sraj
78171619Scognet/*-----------------------------------------------------------------
79171619Scognet**
80171619Scognet**	The following functions are provided for the device driver
81159557Scognet**	to read/write the configuration space.
82159758Scognet**
83159557Scognet**	pci_conf_read():
84159557Scognet**		Read a long word from the pci configuration space.
85159557Scognet**		Requires a tag (from pcitag) and the register
86159557Scognet**		number (should be a long word alligned one).
87159557Scognet**
88159557Scognet**	pci_conf_write():
89159557Scognet**		Writes a long word to the pci configuration space.
90159557Scognet**		Requires a tag (from pcitag), the register number
91159557Scognet**		(should be a long word alligned one), and a value.
92159557Scognet**
93159557Scognet**-----------------------------------------------------------------
94159557Scognet*/
95159557Scognet
96159557Scognetu_long pci_conf_read  (pcici_t tag, u_long reg		   );
97159557Scognet
98159557Scognetvoid   pci_conf_write (pcici_t tag, u_long reg, u_long data);
99159557Scognet
100159557Scognet/*-----------------------------------------------------------------
101159557Scognet**
102159557Scognet**	The pci driver structure.
103159557Scognet**
104159084Scognet**	name:	The short device name.
105159557Scognet**
106159557Scognet**	probe:	Checks if the driver can support a device
107159557Scognet**		with this type. The tag may be used to get
108159557Scognet**		more info with pci_read_conf(). See below.
109159084Scognet**		It returns a string with the devices name,
110150861Scognet**		or a NULL pointer, if the driver cannot
111150861Scognet**		support this device.
112150861Scognet**
113150861Scognet**	attach:	Allocate a control structure and prepare
114150861Scognet**		it. This function may use the pci mapping
115153549Scognet**		functions. See below.
116153112Scognet**		(configuration id) or type.
117166819Scognet**
118153549Scognet**	count:	A pointer to a unit counter.
119153112Scognet**		It's used by the pci configurator to
120153112Scognet**		allocate unit numbers.
121153112Scognet**
122153112Scognet**-----------------------------------------------------------------
123153112Scognet*/
124153112Scognet
125153112Scognetstruct pci_device {
126153112Scognet    char*    pd_name;
127150861Scognet    char*  (*pd_probe ) (pcici_t tag, pcidi_t type);
128150861Scognet    void   (*pd_attach) (pcici_t tag, int     unit);
129150861Scognet    u_long  *pd_count;
130150861Scognet};
131150861Scognet
132153112Scognet/*-----------------------------------------------------------------
133150861Scognet**
134153112Scognet**	This table includes pointers to all pci device drivers.
135153112Scognet**	It should be generated by the linker.
136150861Scognet**
137153112Scognet**-----------------------------------------------------------------
138153112Scognet*/
139153112Scognet
140153112Scognetextern struct linker_set pcidevice_set;
141153112Scognet
142153112Scognet/*-----------------------------------------------------------------
143153112Scognet**
144153112Scognet**	The pci-devconf interface.
145153112Scognet**
146150861Scognet**-----------------------------------------------------------------
147150861Scognet*/
148150861Scognet
149159900Scognetstruct pci_info {
150159900Scognet        u_short pi_bus;
151153112Scognet        u_short pi_device;
152171619Scognet};
153153112Scognet
154153549Scognet#define PCI_EXT_CONF_LEN (16)
155153549Scognet#define PCI_EXTERNAL_LEN (sizeof(struct pci_externalize_buffer))
156159758Scognet
157166819Scognetstruct pci_externalize_buffer {
158166819Scognet	struct pci_info	peb_pci_info;
159166819Scognet	u_long		peb_config[PCI_EXT_CONF_LEN];
160166819Scognet};
161166819Scognet
162166819Scognet
163166819Scognet/*-----------------------------------------------------------------
164166819Scognet**
165166819Scognet**	Map a pci device to physical and virtual memory.
166166819Scognet**
167166819Scognet**	The va and pa addresses are "in/out" parameters.
168166819Scognet**	If they are 0 on entry, the function assigns an address.
169166819Scognet**
170166819Scognet**	Entry selects the register in the pci configuration
171166819Scognet**	space, which supplies the size of the region, and
172166819Scognet**	receives the physical address.
173166819Scognet**
174166819Scognet**	If there is any error, a message is written, and
175166819Scognet**	the function returns with zero.
176166819Scognet**	Else it returns with a value different to zero.
177166819Scognet**
178166819Scognet**-----------------------------------------------------------------
179166819Scognet*/
180166819Scognet
181166819Scognetint pci_map_mem (pcici_t tag, u_long entry, u_long  * va, u_long * pa);
182166819Scognet
183166819Scognet/*-----------------------------------------------------------------
184166819Scognet**
185166819Scognet**	Map a pci device to an io port area.
186166819Scognet**
187166819Scognet**	*pa is an "in/out" parameter.
188159557Scognet**	If it's 0 on entry, the function assigns an port number..
189159557Scognet**
190159557Scognet**	Entry selects the register in the pci configuration
191159557Scognet**	space, which supplies the size of the region, and
192159557Scognet**	receives the port number.
193159557Scognet**
194153549Scognet**	If there is any error, a message is written, and
195153549Scognet**	the function returns with zero.
196153549Scognet**	Else it returns with a value different to zero.
197153549Scognet**
198153549Scognet**-----------------------------------------------------------------
199153549Scognet*/
200153549Scognet
201153549Scognetint pci_map_port(pcici_t tag, u_long entry, u_short * pa);
202153549Scognet
203153549Scognet/*-----------------------------------------------------------------
204153549Scognet**
205153549Scognet**	Map a pci interrupt to an isa irq line,
206153549Scognet**	and enable the interrupt.
207153549Scognet**
208153549Scognet**	func is the interrupt handler, arg is the argument
209153549Scognet**	to this function.
210153549Scognet**
211153549Scognet**	The maskptr argument should be  &bio_imask,
212159557Scognet**	&net_imask etc. or NULL.
213159557Scognet**
214159758Scognet**	If there is any error, a message is written, and
215159758Scognet**	the function returns with zero.
216159758Scognet**	Else it returns with a value different to zero.
217159758Scognet**
218159758Scognet**	A word of caution for FreeBSD 2.0:
219159758Scognet**
220159758Scognet**	We use the register_intr() function.
221171619Scognet**
222159758Scognet**	The interrupt line of the selected device is included
223153112Scognet**	into the supplied mask: after the corresponding splXXX
224153112Scognet**	this drivers interrupts are blocked.
225153112Scognet**
226159557Scognet**	But in the interrupt handlers startup code ONLY
227159557Scognet**	the interrupt of the driver is blocked, and NOT
228159557Scognet**	all interrupts of the spl group.
229159557Scognet**
230159557Scognet**	It may be required to additional block the group
231159557Scognet**	interrupts by splXXX() inside the interrupt handler.
232159557Scognet**
233159557Scognet**	In pre 2.0 kernels we emulate the register_intr
234159557Scognet**	function. The emulating function blocks all interrupts
235159557Scognet**	of the group in the interrupt handler prefix code.
236159557Scognet**
237159557Scognet**-----------------------------------------------------------------
238159557Scognet*/
239159557Scognet
240159557Scognetint pci_map_int (pcici_t tag, int (*func)(), void* arg, unsigned * maskptr);
241159557Scognet
242159557Scognet#endif
243159557Scognet