summaryrefslogtreecommitdiffstats
path: root/sys/dev/pci/pcivar.h
blob: af389ff91f9c4572a91adfc514e86204a13bdbd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/**************************************************************************
**
**  $FreeBSD$
**
**  Declarations for pci device drivers.
**
**  FreeBSD
**
**-------------------------------------------------------------------------
**
** Copyright (c) 1994 Wolfgang Stanglmeier.  All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
** 1. Redistributions of source code must retain the above copyright
**    notice, this list of conditions and the following disclaimer.
** 2. Redistributions in binary form must reproduce the above copyright
**    notice, this list of conditions and the following disclaimer in the
**    documentation and/or other materials provided with the distribution.
** 3. The name of the author may not be used to endorse or promote products
**    derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
***************************************************************************
*/

#ifndef __PCI_VAR_H__
#define __PCI_VAR_H__ "pl2 95/03/21"

/*-----------------------------------------------------------------
**
**	main pci initialization function.
**	called at boot time from autoconf.c
**
**-----------------------------------------------------------------
*/

void pci_configure (void);

/*-----------------------------------------------------------------
**
**	The pci configuration id describes a pci device on the bus.
**	It is constructed from: bus, device & function numbers.
**
**-----------------------------------------------------------------
*/

typedef union {
	u_long	 cfg1;
	struct {
		 u_char   enable;
		 u_char   forward;
		 u_short  port;
	       } cfg2;
	unsigned tag;
	} pcici_t;

#define sametag(x,y)  ((x).tag == (y).tag)

/*-----------------------------------------------------------------
**
**	Each pci device has an unique device id.
**	It is used to find a matching driver.
**
**-----------------------------------------------------------------
*/

typedef u_long pcidi_t;

/*-----------------------------------------------------------------
**
**	The following functions are provided for the device driver
**	to read/write the configuration space.
**
**	pci_conf_read():
**		Read a long word from the pci configuration space.
**		Requires a tag (from pcitag) and the register
**		number (should be a long word alligned one).
**
**	pci_conf_write():
**		Writes a long word to the pci configuration space.
**		Requires a tag (from pcitag), the register number
**		(should be a long word alligned one), and a value.
**
**-----------------------------------------------------------------
*/

u_long pci_conf_read  (pcici_t tag, u_long reg		   );

void   pci_conf_write (pcici_t tag, u_long reg, u_long data);

/*-----------------------------------------------------------------
**
**	The pci driver structure.
**
**	name:	The short device name.
**
**	probe:	Checks if the driver can support a device
**		with this type. The tag may be used to get
**		more info with pci_read_conf(). See below.
**		It returns a string with the devices name,
**		or a NULL pointer, if the driver cannot
**		support this device.
**
**	attach:	Allocate a control structure and prepare
**		it. This function may use the pci mapping
**		functions. See below.
**		(configuration id) or type.
**
**	count:	A pointer to a unit counter.
**		It's used by the pci configurator to
**		allocate unit numbers.
**
**-----------------------------------------------------------------
*/

struct pci_device {
    char*    pd_name;
    char*  (*pd_probe ) (pcici_t tag, pcidi_t type);
    void   (*pd_attach) (pcici_t tag, int     unit);
    u_long  *pd_count;
    int    (*pd_shutdown) (int, int);
};

/*-----------------------------------------------------------------
**
**	This table includes pointers to all pci device drivers.
**	It should be generated by the linker.
**
**-----------------------------------------------------------------
*/

extern struct linker_set pcidevice_set;

extern unsigned pci_max_burst_len;  /* log2 of safe burst transfer length */
extern unsigned pci_mechanism;
extern unsigned pci_maxdevice;

/*-----------------------------------------------------------------
**
**	Map a pci device to physical and virtual memory.
**
**      Entry selects the register in the pci configuration
**	space, which supplies the size of the region, and
**	receives the physical address.
**
**	In case of success the function sets the addresses
**	in *va and *pa, and returns 1.
**	In case of errors a message is written,
**	and the function returns 0.
**
**-----------------------------------------------------------------
*/

int pci_map_mem (pcici_t tag, u_long entry, vm_offset_t *va, vm_offset_t *pa);

/*-----------------------------------------------------------------
**
**	Map a pci device to an io port area.
**
**	Entry selects the register in the pci configuration
**	space, which supplies the size of the region, and
**	receives the port number.
**
**	In case of success the function sets the port number in pa,
**	and returns 1.
**	In case of errors a message is written,
**	and the function returns 0.
**
**-----------------------------------------------------------------
*/

int pci_map_port (pcici_t tag, u_long entry, u_short * pa);

/*-----------------------------------------------------------------
**
**	Map a pci interrupt to an isa irq line, and enable the interrupt.
**
**      -----------------
**
**      func is the interrupt handler, arg is the argument
**      to the handler (usually a pointer to a softc).
**
**      The maskptr argument should be  &bio_imask,
**      &net_imask etc. or NULL.
**
**      If there is any error, a message is written, and
**      the function returns with zero.
**      Else it returns with a value different to zero.
**
**      -----------------
**
**	The irq number is read from the configuration space.
**	(Should have been set by the bios).
**
**	Supports multiple handlers per irq (shared interrupts).
**
**-----------------------------------------------------------------
*/

typedef void pci_inthand_t(void *arg);

struct pci_int_desc {
	struct pci_int_desc * pcid_next;
	pcici_t 	      pcid_tag;
	pci_inthand_t	     *pcid_handler;
	void*		      pcid_argument;
	unsigned *	      pcid_maskptr;
	unsigned	      pcid_tally;
	unsigned	      pcid_mask;
};

int pci_map_int (pcici_t tag, pci_inthand_t *func, void *arg,
		 unsigned *maskptr);

int pci_unmap_int (pcici_t tag);

#endif
OpenPOWER on IntegriCloud