pci_machdep.h revision 1.6
1/* $NetBSD: pci_machdep.h,v 1.6 2006/04/09 19:28:01 bouyer Exp $ */
2
3/*
4 * Copyright (c) 2006 Manuel Bouyer.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 *    must display the following acknowledgement:
16 *      This product includes software developed by Manuel Bouyer.
17 * 4. The name of the author may not be used to endorse or promote products
18 *    derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 */
32
33/*
34 * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
35 * Copyright (c) 1994 Charles M. Hannum.  All rights reserved.
36 *
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
39 * are met:
40 * 1. Redistributions of source code must retain the above copyright
41 *    notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 *    notice, this list of conditions and the following disclaimer in the
44 *    documentation and/or other materials provided with the distribution.
45 * 3. All advertising materials mentioning features or use of this software
46 *    must display the following acknowledgement:
47 *      This product includes software developed by Charles M. Hannum.
48 * 4. The name of the author may not be used to endorse or promote products
49 *    derived from this software without specific prior written permission.
50 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
51 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
52 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
53 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
54 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
55 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
56 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
57 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
58 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
59 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60 */
61
62#ifndef _XEN_PCI_MACHDEP_H_
63#define _XEN_PCI_MACHDEP_H_
64
65#include "opt_xen.h"
66
67extern struct x86_bus_dma_tag pci_bus_dma_tag;
68#ifdef _LP64
69extern struct x86_bus_dma_tag pci_bus_dma64_tag;
70#endif
71
72/* Some values appropriate for x86, from x86/include/pci_machdep.h */
73#define __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
74#define PCI_PREFER_IOSPACE
75
76#ifdef XEN3
77union x86_pci_tag_u {
78	u_int32_t mode1;
79	struct {
80		u_int16_t port;
81		u_int8_t enable;
82		u_int8_t forward;
83	} mode2;
84};
85
86typedef union x86_pci_tag_u pcitag_t;
87
88#else /* XEN3 */
89
90extern u_int32_t pci_bus_attached[];
91
92#define PCI_MACHDEP_ENUMERATE_BUS xen_pci_enumerate_bus
93
94/* types provided to MI PCI */
95struct xen_pci_tag {
96	u_int8_t bus;
97	u_int8_t device;
98	u_int8_t function;
99	u_int8_t _pad; /* pad to 32bits */
100};
101
102typedef struct xen_pci_tag pcitag_t;
103#endif /* !XEN3 */
104
105typedef void *pci_chipset_tag_t;
106
107struct xen_intr_handle {
108	int pirq;
109	int evtch;
110};
111
112typedef struct xen_intr_handle pci_intr_handle_t;
113
114/* functions provided to MI PCI */
115struct pci_attach_args;
116
117void		pci_attach_hook(struct device *, struct device *,
118		    struct pcibus_attach_args *);
119int		pci_bus_maxdevs(pci_chipset_tag_t, int);
120pcitag_t	pci_make_tag(pci_chipset_tag_t, int, int, int);
121void		pci_decompose_tag(pci_chipset_tag_t, pcitag_t,
122		    int *, int *, int *);
123pcireg_t	pci_conf_read(pci_chipset_tag_t, pcitag_t, int);
124void		pci_conf_write(pci_chipset_tag_t, pcitag_t, int,
125		    pcireg_t);
126int		pci_intr_map(struct pci_attach_args *, pci_intr_handle_t *);
127const char	*pci_intr_string(pci_chipset_tag_t, pci_intr_handle_t);
128const struct evcnt *pci_intr_evcnt(pci_chipset_tag_t, pci_intr_handle_t);
129void		*pci_intr_establish(pci_chipset_tag_t, pci_intr_handle_t,
130		    int, int (*)(void *), void *);
131void		pci_intr_disestablish(pci_chipset_tag_t, void *);
132int		xen_pci_enumerate_bus(struct pci_softc *, const int *,
133		   int (*)(struct pci_attach_args *), struct pci_attach_args *);
134
135/*
136 * Section 6.2.4, `Miscellaneous Functions' of the PCI Specification,
137 * says that 255 means `unknown' or `no connection' to the interrupt
138 * controller on a PC.
139 */
140#define	X86_PCI_INTERRUPT_LINE_NO_CONNECTION	0xff
141
142extern int pci_mode;
143int pci_mode_detect(void);
144int pci_bus_flags(void);
145
146void pci_device_foreach(pci_chipset_tag_t, int,
147			void (*)(pci_chipset_tag_t, pcitag_t, void*),
148			void *);
149
150void pci_device_foreach_min(pci_chipset_tag_t, int, int,
151			    void (*)(pci_chipset_tag_t, pcitag_t, void*),
152			    void *);
153
154void pci_bridge_foreach(pci_chipset_tag_t, int, int,
155	void (*) (pci_chipset_tag_t, pcitag_t, void *), void *);
156
157#endif /* _XEN_PCI_MACHDEP_H_ */
158