pci_machdep.h revision 1.16
11.16Sdyoung/* $NetBSD: pci_machdep.h,v 1.16 2010/02/25 22:20:03 dyoung Exp $ */
21.2Sbouyer
31.2Sbouyer/*
41.6Sbouyer * Copyright (c) 2006 Manuel Bouyer.
51.2Sbouyer *
61.2Sbouyer * Redistribution and use in source and binary forms, with or without
71.2Sbouyer * modification, are permitted provided that the following conditions
81.2Sbouyer * are met:
91.2Sbouyer * 1. Redistributions of source code must retain the above copyright
101.2Sbouyer *    notice, this list of conditions and the following disclaimer.
111.2Sbouyer * 2. Redistributions in binary form must reproduce the above copyright
121.2Sbouyer *    notice, this list of conditions and the following disclaimer in the
131.2Sbouyer *    documentation and/or other materials provided with the distribution.
141.2Sbouyer *
151.2Sbouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
161.2Sbouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
171.2Sbouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
181.2Sbouyer * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
191.2Sbouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
201.2Sbouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
211.2Sbouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
221.2Sbouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
231.2Sbouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
241.2Sbouyer * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
251.2Sbouyer *
261.2Sbouyer */
271.2Sbouyer
281.6Sbouyer/*
291.6Sbouyer * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
301.6Sbouyer * Copyright (c) 1994 Charles M. Hannum.  All rights reserved.
311.6Sbouyer *
321.6Sbouyer * Redistribution and use in source and binary forms, with or without
331.6Sbouyer * modification, are permitted provided that the following conditions
341.6Sbouyer * are met:
351.6Sbouyer * 1. Redistributions of source code must retain the above copyright
361.6Sbouyer *    notice, this list of conditions and the following disclaimer.
371.6Sbouyer * 2. Redistributions in binary form must reproduce the above copyright
381.6Sbouyer *    notice, this list of conditions and the following disclaimer in the
391.6Sbouyer *    documentation and/or other materials provided with the distribution.
401.6Sbouyer * 3. All advertising materials mentioning features or use of this software
411.6Sbouyer *    must display the following acknowledgement:
421.6Sbouyer *      This product includes software developed by Charles M. Hannum.
431.6Sbouyer * 4. The name of the author may not be used to endorse or promote products
441.6Sbouyer *    derived from this software without specific prior written permission.
451.6Sbouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
461.6Sbouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
471.6Sbouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
481.6Sbouyer * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
491.6Sbouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
501.6Sbouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
511.6Sbouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
521.6Sbouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
531.6Sbouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
541.6Sbouyer * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
551.6Sbouyer */
561.6Sbouyer
571.2Sbouyer#ifndef _XEN_PCI_MACHDEP_H_
581.2Sbouyer#define _XEN_PCI_MACHDEP_H_
591.2Sbouyer
601.6Sbouyer#include "opt_xen.h"
611.6Sbouyer
621.11Sbouyerstruct pci_attach_args;
631.11Sbouyer
641.2Sbouyerextern struct x86_bus_dma_tag pci_bus_dma_tag;
651.6Sbouyer#ifdef _LP64
661.6Sbouyerextern struct x86_bus_dma_tag pci_bus_dma64_tag;
671.6Sbouyer#endif
681.2Sbouyer
691.2Sbouyer/* Some values appropriate for x86, from x86/include/pci_machdep.h */
701.2Sbouyer#define __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
711.2Sbouyer#define PCI_PREFER_IOSPACE
721.6Sbouyer
731.6Sbouyerunion x86_pci_tag_u {
741.8Scegger	uint32_t mode1;
751.6Sbouyer	struct {
761.8Scegger		uint16_t port;
771.8Scegger		uint8_t enable;
781.8Scegger		uint8_t forward;
791.6Sbouyer	} mode2;
801.6Sbouyer};
811.6Sbouyer
821.11Sbouyer#ifndef DOM0OPS
831.11Sbouyerint		xpci_enumerate_bus(struct pci_softc *, const int *,
841.11Sbouyer		   int (*)(struct pci_attach_args *), struct pci_attach_args *);
851.11Sbouyer#define PCI_MACHDEP_ENUMERATE_BUS xpci_enumerate_bus
861.11Sbouyer#endif
871.16Sdyoungstruct pci_chipset_tag;
881.16Sdyoungstruct pci_attach_args;
891.6Sbouyer
901.16Sdyoung/*
911.16Sdyoung * Types provided to machine-independent PCI code
921.16Sdyoung */
931.16Sdyoungtypedef struct pci_chipset_tag *pci_chipset_tag_t;
941.16Sdyoungtypedef union x86_pci_tag_u pcitag_t;
951.2Sbouyertypedef struct xen_intr_handle pci_intr_handle_t;
961.2Sbouyer
971.16Sdyoungstruct pci_chipset_tag {
981.16Sdyoung	pcireg_t (*pc_conf_read)(pci_chipset_tag_t, pcitag_t, int);
991.16Sdyoung
1001.16Sdyoung	void (*pc_conf_write)(pci_chipset_tag_t, pcitag_t, int, pcireg_t);
1011.16Sdyoung
1021.16Sdyoung#if 0
1031.16Sdyoung	int (*pc_find_rom)(struct pci_attach_args *, bus_space_tag_t,
1041.16Sdyoung	    bus_space_handle_t, int, bus_space_handle_t *, bus_space_size_t *);
1051.16Sdyoung#endif
1061.16Sdyoung
1071.16Sdyoung	int (*pc_intr_map)(struct pci_attach_args *, pci_intr_handle_t *);
1081.16Sdyoung
1091.16Sdyoung	const char *(*pc_intr_string)(pci_chipset_tag_t, pci_intr_handle_t);
1101.16Sdyoung
1111.16Sdyoung	const struct evcnt *(*pc_intr_evcnt)(pci_chipset_tag_t,
1121.16Sdyoung	    pci_intr_handle_t);
1131.16Sdyoung
1141.16Sdyoung	void *(*pc_intr_establish)(pci_chipset_tag_t, pci_intr_handle_t, int,
1151.16Sdyoung	    int (*)(void *), void *);
1161.16Sdyoung
1171.16Sdyoung	void (*pc_intr_disestablish)(pci_chipset_tag_t, void *);
1181.16Sdyoung
1191.16Sdyoung	pcitag_t (*pc_make_tag)(pci_chipset_tag_t, int, int, int);
1201.16Sdyoung
1211.16Sdyoung	void (*pc_decompose_tag)(pci_chipset_tag_t, pcitag_t,
1221.16Sdyoung	    int *, int *, int *);
1231.16Sdyoung};
1241.16Sdyoung
1251.2Sbouyer/* functions provided to MI PCI */
1261.2Sbouyer
1271.9Sceggervoid		pci_attach_hook(device_t, device_t,
1281.2Sbouyer		    struct pcibus_attach_args *);
1291.2Sbouyerint		pci_bus_maxdevs(pci_chipset_tag_t, int);
1301.2Sbouyerpcitag_t	pci_make_tag(pci_chipset_tag_t, int, int, int);
1311.2Sbouyervoid		pci_decompose_tag(pci_chipset_tag_t, pcitag_t,
1321.2Sbouyer		    int *, int *, int *);
1331.2Sbouyerpcireg_t	pci_conf_read(pci_chipset_tag_t, pcitag_t, int);
1341.2Sbouyervoid		pci_conf_write(pci_chipset_tag_t, pcitag_t, int,
1351.2Sbouyer		    pcireg_t);
1361.2Sbouyerint		pci_intr_map(struct pci_attach_args *, pci_intr_handle_t *);
1371.2Sbouyerconst char	*pci_intr_string(pci_chipset_tag_t, pci_intr_handle_t);
1381.2Sbouyerconst struct evcnt *pci_intr_evcnt(pci_chipset_tag_t, pci_intr_handle_t);
1391.2Sbouyervoid		*pci_intr_establish(pci_chipset_tag_t, pci_intr_handle_t,
1401.2Sbouyer		    int, int (*)(void *), void *);
1411.2Sbouyervoid		pci_intr_disestablish(pci_chipset_tag_t, void *);
1421.4Sbouyerint		xen_pci_enumerate_bus(struct pci_softc *, const int *,
1431.4Sbouyer		   int (*)(struct pci_attach_args *), struct pci_attach_args *);
1441.2Sbouyer
1451.10Scegger/* Extract Bus Number for a host bridge or -1 if unknown. */
1461.10Sceggerint             pchb_get_bus_number(pci_chipset_tag_t, pcitag_t);
1471.10Scegger
1481.2Sbouyer/*
1491.2Sbouyer * Section 6.2.4, `Miscellaneous Functions' of the PCI Specification,
1501.2Sbouyer * says that 255 means `unknown' or `no connection' to the interrupt
1511.2Sbouyer * controller on a PC.
1521.2Sbouyer */
1531.2Sbouyer#define	X86_PCI_INTERRUPT_LINE_NO_CONNECTION	0xff
1541.6Sbouyer
1551.15Sdyoungvoid pci_mode_set(int);
1561.6Sbouyerint pci_mode_detect(void);
1571.6Sbouyerint pci_bus_flags(void);
1581.6Sbouyer
1591.6Sbouyervoid pci_device_foreach(pci_chipset_tag_t, int,
1601.6Sbouyer			void (*)(pci_chipset_tag_t, pcitag_t, void*),
1611.6Sbouyer			void *);
1621.6Sbouyer
1631.6Sbouyervoid pci_device_foreach_min(pci_chipset_tag_t, int, int,
1641.6Sbouyer			    void (*)(pci_chipset_tag_t, pcitag_t, void*),
1651.6Sbouyer			    void *);
1661.6Sbouyer
1671.6Sbouyervoid pci_bridge_foreach(pci_chipset_tag_t, int, int,
1681.6Sbouyer	void (*) (pci_chipset_tag_t, pcitag_t, void *), void *);
1691.6Sbouyer
1701.2Sbouyer#endif /* _XEN_PCI_MACHDEP_H_ */
171