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