xref: /netbsd-src/sys/arch/xen/include/pci_machdep.h (revision 274254cdae52594c1aa480a736aef78313d15c9c)
1 /* $NetBSD: pci_machdep.h,v 1.11 2009/02/13 21:03:59 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 
67 struct pci_attach_args;
68 
69 extern struct x86_bus_dma_tag pci_bus_dma_tag;
70 #ifdef _LP64
71 extern struct x86_bus_dma_tag pci_bus_dma64_tag;
72 #endif
73 
74 /* Some values appropriate for x86, from x86/include/pci_machdep.h */
75 #define __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
76 #define PCI_PREFER_IOSPACE
77 
78 #ifdef XEN3
79 union x86_pci_tag_u {
80 	uint32_t mode1;
81 	struct {
82 		uint16_t port;
83 		uint8_t enable;
84 		uint8_t forward;
85 	} mode2;
86 };
87 
88 typedef union x86_pci_tag_u pcitag_t;
89 
90 #ifndef DOM0OPS
91 int		xpci_enumerate_bus(struct pci_softc *, const int *,
92 		   int (*)(struct pci_attach_args *), struct pci_attach_args *);
93 #define PCI_MACHDEP_ENUMERATE_BUS xpci_enumerate_bus
94 #endif
95 
96 #else /* XEN3 */
97 
98 extern uint32_t pci_bus_attached[];
99 
100 #define PCI_MACHDEP_ENUMERATE_BUS xen_pci_enumerate_bus
101 
102 /* types provided to MI PCI */
103 struct xen_pci_tag {
104 	uint8_t bus;
105 	uint8_t device;
106 	uint8_t function;
107 	uint8_t _pad; /* pad to 32bits */
108 };
109 
110 typedef struct xen_pci_tag pcitag_t;
111 #endif /* !XEN3 */
112 
113 typedef void *pci_chipset_tag_t;
114 
115 typedef struct xen_intr_handle pci_intr_handle_t;
116 
117 /* functions provided to MI PCI */
118 struct pci_attach_args;
119 
120 void		pci_attach_hook(device_t, device_t,
121 		    struct pcibus_attach_args *);
122 int		pci_bus_maxdevs(pci_chipset_tag_t, int);
123 pcitag_t	pci_make_tag(pci_chipset_tag_t, int, int, int);
124 void		pci_decompose_tag(pci_chipset_tag_t, pcitag_t,
125 		    int *, int *, int *);
126 pcireg_t	pci_conf_read(pci_chipset_tag_t, pcitag_t, int);
127 void		pci_conf_write(pci_chipset_tag_t, pcitag_t, int,
128 		    pcireg_t);
129 int		pci_intr_map(struct pci_attach_args *, pci_intr_handle_t *);
130 const char	*pci_intr_string(pci_chipset_tag_t, pci_intr_handle_t);
131 const struct evcnt *pci_intr_evcnt(pci_chipset_tag_t, pci_intr_handle_t);
132 void		*pci_intr_establish(pci_chipset_tag_t, pci_intr_handle_t,
133 		    int, int (*)(void *), void *);
134 void		pci_intr_disestablish(pci_chipset_tag_t, void *);
135 int		xen_pci_enumerate_bus(struct pci_softc *, const int *,
136 		   int (*)(struct pci_attach_args *), struct pci_attach_args *);
137 
138 /* Extract Bus Number for a host bridge or -1 if unknown. */
139 int             pchb_get_bus_number(pci_chipset_tag_t, pcitag_t);
140 
141 /*
142  * Section 6.2.4, `Miscellaneous Functions' of the PCI Specification,
143  * says that 255 means `unknown' or `no connection' to the interrupt
144  * controller on a PC.
145  */
146 #define	X86_PCI_INTERRUPT_LINE_NO_CONNECTION	0xff
147 
148 extern int pci_mode;
149 int pci_mode_detect(void);
150 int pci_bus_flags(void);
151 
152 void pci_device_foreach(pci_chipset_tag_t, int,
153 			void (*)(pci_chipset_tag_t, pcitag_t, void*),
154 			void *);
155 
156 void pci_device_foreach_min(pci_chipset_tag_t, int, int,
157 			    void (*)(pci_chipset_tag_t, pcitag_t, void*),
158 			    void *);
159 
160 void pci_bridge_foreach(pci_chipset_tag_t, int, int,
161 	void (*) (pci_chipset_tag_t, pcitag_t, void *), void *);
162 
163 #endif /* _XEN_PCI_MACHDEP_H_ */
164