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