pcivar.h revision 12453
16100Sse/**************************************************************************
26100Sse**
312453Sbde**  $Id: pcivar.h,v 1.6 1995/05/30 08:13:12 rgrimes Exp $
46100Sse**
56100Sse**  Declarations for pci device drivers.
66100Sse**
77233Sse**  FreeBSD
86100Sse**
96100Sse**-------------------------------------------------------------------------
106100Sse**
116100Sse** Copyright (c) 1994 Wolfgang Stanglmeier.  All rights reserved.
126100Sse**
136100Sse** Redistribution and use in source and binary forms, with or without
146100Sse** modification, are permitted provided that the following conditions
156100Sse** are met:
166100Sse** 1. Redistributions of source code must retain the above copyright
176100Sse**    notice, this list of conditions and the following disclaimer.
186100Sse** 2. Redistributions in binary form must reproduce the above copyright
196100Sse**    notice, this list of conditions and the following disclaimer in the
206100Sse**    documentation and/or other materials provided with the distribution.
216100Sse** 3. The name of the author may not be used to endorse or promote products
226100Sse**    derived from this software without specific prior written permission.
236100Sse**
246100Sse** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
256100Sse** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
266100Sse** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
276100Sse** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
286100Sse** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
296100Sse** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
306100Sse** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
316100Sse** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
326100Sse** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
336100Sse** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
346100Sse**
356100Sse***************************************************************************
366100Sse*/
376100Sse
386100Sse#ifndef __PCI_VAR_H__
397233Sse#define __PCI_VAR_H__ "pl2 95/03/21"
406767Sse
416100Sse/*-----------------------------------------------------------------
426100Sse**
436100Sse**	main pci initialization function.
446100Sse**	called at boot time from autoconf.c
456100Sse**
466100Sse**-----------------------------------------------------------------
476100Sse*/
486100Sse
496100Ssevoid pci_configure (void);
506100Sse
516100Sse/*-----------------------------------------------------------------
526100Sse**
536100Sse**	The pci configuration id describes a pci device on the bus.
546100Sse**	It is constructed from: bus, device & function numbers.
556100Sse**
566100Sse**-----------------------------------------------------------------
576100Sse*/
586100Sse
596100Ssetypedef union {
606100Sse	u_long	 cfg1;
617233Sse	struct {
626100Sse		 u_char   enable;
636100Sse		 u_char   forward;
646100Sse		 u_short  port;
656100Sse	       } cfg2;
667233Sse	unsigned tag;
676100Sse	} pcici_t;
686100Sse
697233Sse#define sametag(x,y)  ((x).tag == (y).tag)
707233Sse
716100Sse/*-----------------------------------------------------------------
726100Sse**
736100Sse**	Each pci device has an unique device id.
746100Sse**	It is used to find a matching driver.
756100Sse**
766100Sse**-----------------------------------------------------------------
776100Sse*/
786100Sse
796100Ssetypedef u_long pcidi_t;
806100Sse
816100Sse/*-----------------------------------------------------------------
826100Sse**
836100Sse**	The following functions are provided for the device driver
846100Sse**	to read/write the configuration space.
856100Sse**
866100Sse**	pci_conf_read():
876100Sse**		Read a long word from the pci configuration space.
886100Sse**		Requires a tag (from pcitag) and the register
896100Sse**		number (should be a long word alligned one).
906100Sse**
916100Sse**	pci_conf_write():
926100Sse**		Writes a long word to the pci configuration space.
936100Sse**		Requires a tag (from pcitag), the register number
946100Sse**		(should be a long word alligned one), and a value.
956100Sse**
966100Sse**-----------------------------------------------------------------
976100Sse*/
986100Sse
996100Sseu_long pci_conf_read  (pcici_t tag, u_long reg		   );
1006100Sse
1016100Ssevoid   pci_conf_write (pcici_t tag, u_long reg, u_long data);
1027233Sse
1036100Sse/*-----------------------------------------------------------------
1046100Sse**
1056100Sse**	The pci driver structure.
1066100Sse**
1076100Sse**	name:	The short device name.
1086100Sse**
1096100Sse**	probe:	Checks if the driver can support a device
1106100Sse**		with this type. The tag may be used to get
1116100Sse**		more info with pci_read_conf(). See below.
1126100Sse**		It returns a string with the devices name,
1136100Sse**		or a NULL pointer, if the driver cannot
1146100Sse**		support this device.
1156100Sse**
1166100Sse**	attach:	Allocate a control structure and prepare
1176100Sse**		it. This function may use the pci mapping
1186100Sse**		functions. See below.
1196100Sse**		(configuration id) or type.
1206100Sse**
1216100Sse**	count:	A pointer to a unit counter.
1226100Sse**		It's used by the pci configurator to
1236100Sse**		allocate unit numbers.
1246100Sse**
1256100Sse**-----------------------------------------------------------------
1266100Sse*/
1276100Sse
1287373Sbdestruct kern_devconf;
1297373Sbde
1306100Ssestruct pci_device {
1316100Sse    char*    pd_name;
1326100Sse    char*  (*pd_probe ) (pcici_t tag, pcidi_t type);
1336100Sse    void   (*pd_attach) (pcici_t tag, int     unit);
1346100Sse    u_long  *pd_count;
1357104Sdg    int    (*pd_shutdown) (struct kern_devconf *, int);
1366100Sse};
1376100Sse
1386100Sse/*-----------------------------------------------------------------
1396100Sse**
1406100Sse**	This table includes pointers to all pci device drivers.
1416100Sse**	It should be generated by the linker.
1426100Sse**
1436100Sse**-----------------------------------------------------------------
1446100Sse*/
1456100Sse
1466100Sseextern struct linker_set pcidevice_set;
1477233Sse
1487233Sseextern unsigned pci_max_burst_len;  /* log2 of safe burst transfer length */
1497233Sseextern unsigned pci_mechanism;
1507233Sseextern unsigned pci_maxdevice;
1517233Sse
1526100Sse/*-----------------------------------------------------------------
1536100Sse**
1546100Sse**	The pci-devconf interface.
1556100Sse**
1566100Sse**-----------------------------------------------------------------
1576100Sse*/
1586100Sse
1596100Ssestruct pci_info {
1607233Sse	u_short pi_bus;
1617233Sse	u_short pi_device;
1628876Srgrimes};
1638876Srgrimes
1646100Sse#define PCI_EXT_CONF_LEN (16)
1656100Sse#define PCI_EXTERNAL_LEN (sizeof(struct pci_externalize_buffer))
1666100Sse
1676100Ssestruct pci_externalize_buffer {
1686100Sse	struct pci_info	peb_pci_info;
1696100Sse	u_long		peb_config[PCI_EXT_CONF_LEN];
1706100Sse};
1716100Sse
1726100Sse/*-----------------------------------------------------------------
1736100Sse**
1746100Sse**	Map a pci device to physical and virtual memory.
1756100Sse**
1767233Sse**      Entry selects the register in the pci configuration
1776100Sse**	space, which supplies the size of the region, and
1786100Sse**	receives the physical address.
1796100Sse**
1807233Sse**	In case of success the function sets the addresses
1817233Sse**	in *va and *pa, and returns 1.
1827233Sse**	In case of errors a message is written,
1837233Sse**	and the function returns 0.
1846100Sse**
1856100Sse**-----------------------------------------------------------------
1866100Sse*/
1876100Sse
1886100Sseint pci_map_mem (pcici_t tag, u_long entry, u_long  * va, u_long * pa);
1896100Sse
1906100Sse/*-----------------------------------------------------------------
1916100Sse**
1926100Sse**	Map a pci device to an io port area.
1936100Sse**
1946100Sse**	Entry selects the register in the pci configuration
1956100Sse**	space, which supplies the size of the region, and
1966100Sse**	receives the port number.
1976100Sse**
1987233Sse**	In case of success the function sets the port number in pa,
1997233Sse**	and returns 1.
2007233Sse**	In case of errors a message is written,
2017233Sse**	and the function returns 0.
2026100Sse**
2036100Sse**-----------------------------------------------------------------
2046100Sse*/
2056100Sse
2067233Sseint pci_map_port (pcici_t tag, u_long entry, u_short * pa);
2077233Sse
2086100Sse/*-----------------------------------------------------------------
2096100Sse**
2107233Sse**	Map a pci interrupt to an isa irq line, and enable the interrupt.
2116100Sse**
2127233Sse**      -----------------
2136100Sse**
2147233Sse**      func is the interrupt handler, arg is the argument
2157233Sse**      to the handler (usually a pointer to a softc).
2166100Sse**
2177233Sse**      The maskptr argument should be  &bio_imask,
2187233Sse**      &net_imask etc. or NULL.
2196100Sse**
2207233Sse**      If there is any error, a message is written, and
2217233Sse**      the function returns with zero.
2227233Sse**      Else it returns with a value different to zero.
2236100Sse**
2247233Sse**      -----------------
2256100Sse**
2267233Sse**	The irq number is read from the configuration space.
2277233Sse**	(Should have been set by the bios).
2286100Sse**
2297233Sse**	Supports multiple handlers per irq (shared interrupts).
2306100Sse**
2317233Sse**	-----------------
2326100Sse**
2337233Sse**	There is code to support shared edge triggered ints.
2347233Sse**	This relies on the cooperation of the interrupt handlers:
2357233Sse**	they have to return a value <>0 if and only if something
2367233Sse**	was done. Beware of the performance penalty.
2376100Sse**
2386100Sse**-----------------------------------------------------------------
2396100Sse*/
2406100Sse
24112453Sbdetypedef int pci_inthand_t(void *arg);
24212453Sbde
2437233Ssestruct pci_int_desc {
2447233Sse	struct pci_int_desc * pcid_next;
2457233Sse	pcici_t 	      pcid_tag;
24612453Sbde	pci_inthand_t	     *pcid_handler;
2477233Sse	void*		      pcid_argument;
2487233Sse	unsigned *	      pcid_maskptr;
2497233Sse	unsigned	      pcid_tally;
2507233Sse	unsigned	      pcid_mask;
2517233Sse};
2527233Sse
25312453Sbdeint pci_map_int (pcici_t tag, pci_inthand_t *func, void *arg,
25412453Sbde		 unsigned *maskptr);
2556100Sse
2567233Sseint pci_unmap_int (pcici_t tag);
2577233Sse
2586100Sse#endif
259