1 /*	$OpenBSD: pci_machdep.h,v 1.5 2021/06/09 19:46:33 kettenis Exp $ */
2 
3 /*
4  * Copyright (c) 2003-2004 Opsycon AB  (www.opsycon.se / www.opsycon.com)
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
16  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  */
28 
29 typedef struct ppc64_pci_chipset *pci_chipset_tag_t;
30 typedef uint64_t pcitag_t;
31 
32 #define PCITAG_NODE(x)		((x) >> 32)
33 #define PCITAG_OFFSET(x)	((x) & 0xffffffff)
34 
35 /* Supported interrupt types. */
36 #define PCI_NONE		0
37 #define PCI_INTX		1
38 #define PCI_MSI32		2
39 #define PCI_MSI64		3
40 #define PCI_MSIX		4
41 
42 typedef struct {
43 	pci_chipset_tag_t	ih_pc;
44 	pcitag_t		ih_tag;
45 	int			ih_intrpin;
46 	int			ih_type;
47 } pci_intr_handle_t;
48 
49 struct pci_attach_args;
50 
51 /*
52  * powerpc64-specific PCI structure and type definitions.
53  * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE.
54  */
55 struct ppc64_pci_chipset {
56 	void		*pc_conf_v;
57 	void		(*pc_attach_hook)(struct device *,
58 			    struct device *, struct pcibus_attach_args *);
59 	int		(*pc_bus_maxdevs)(void *, int);
60 	pcitag_t	(*pc_make_tag)(void *, int, int, int);
61 	void		(*pc_decompose_tag)(void *, pcitag_t, int *,
62 			    int *, int *);
63 	int		(*pc_conf_size)(void *, pcitag_t);
64 	pcireg_t	(*pc_conf_read)(void *, pcitag_t, int);
65 	void		(*pc_conf_write)(void *, pcitag_t, int, pcireg_t);
66 
67 	void		*pc_intr_v;
68 	int		(*pc_intr_map)(struct pci_attach_args *,
69 			    pci_intr_handle_t *);
70 	int		(*pc_intr_map_msi)(struct pci_attach_args *,
71 			    pci_intr_handle_t *);
72 	int		(*pc_intr_map_msix)(struct pci_attach_args *,
73 			    int, pci_intr_handle_t *);
74 	const char	*(*pc_intr_string)(void *, pci_intr_handle_t);
75 	void		*(*pc_intr_establish)(void *, pci_intr_handle_t,
76 			    int, struct cpu_info *, int (*)(void *), void *,
77 			    char *);
78 	void		(*pc_intr_disestablish)(void *, void *);
79 };
80 
81 /*
82  * Functions provided to machine-independent PCI code.
83  */
84 #define	pci_attach_hook(p, s, pba)					\
85     (*(pba)->pba_pc->pc_attach_hook)((p), (s), (pba))
86 #define	pci_bus_maxdevs(c, b)						\
87     (*(c)->pc_bus_maxdevs)((c)->pc_conf_v, (b))
88 #define	pci_make_tag(c, b, d, f)					\
89     (*(c)->pc_make_tag)((c)->pc_conf_v, (b), (d), (f))
90 #define	pci_decompose_tag(c, t, bp, dp, fp)				\
91     (*(c)->pc_decompose_tag)((c)->pc_conf_v, (t), (bp), (dp), (fp))
92 #define	pci_conf_size(c, t)						\
93     (*(c)->pc_conf_size)((c)->pc_conf_v, (t))
94 #define	pci_conf_read(c, t, r)						\
95     (*(c)->pc_conf_read)((c)->pc_conf_v, (t), (r))
96 #define	pci_conf_write(c, t, r, v)					\
97     (*(c)->pc_conf_write)((c)->pc_conf_v, (t), (r), (v))
98 #define	pci_intr_map(c, ihp)						\
99     (*(c)->pa_pc->pc_intr_map)((c), (ihp))
100 #define	pci_intr_map_msi(c, ihp)					\
101     (*(c)->pa_pc->pc_intr_map_msi)((c), (ihp))
102 #define	pci_intr_map_msix(c, vec, ihp)					\
103     (*(c)->pa_pc->pc_intr_map_msix)((c), (vec), (ihp))
104 #define	pci_intr_string(c, ih)						\
105     (*(c)->pc_intr_string)((c)->pc_intr_v, (ih))
106 #define	pci_intr_establish(c, ih, l, h, a, nm)				\
107     (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), NULL, (h), (a),\
108 	(nm))
109 #define	pci_intr_establish_cpu(c, ih, l, ci, h, a, nm)			\
110     (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), (ci), (h), (a),\
111 	(nm))
112 #define	pci_intr_disestablish(c, iv)					\
113     (*(c)->pc_intr_disestablish)((c)->pc_intr_v, (iv))
114 #define	pci_probe_device_hook(c, a)	(0)
115 
116 #define	pci_min_powerstate(c, t)	(PCI_PMCSR_STATE_D3)
117 #define	pci_set_powerstate_md(c, t, s, p)
118 
119 #define	pci_dev_postattach(a, b)
120 
121 void	pci_mcfg_init(bus_space_tag_t, bus_addr_t, int, int, int);
122 pci_chipset_tag_t pci_lookup_segment(int);
123 
124 void	pci_msi_enable(pci_chipset_tag_t, pcitag_t, bus_addr_t, uint32_t);
125 void	pci_msix_enable(pci_chipset_tag_t, pcitag_t, bus_space_tag_t,
126 	    int, bus_addr_t, uint32_t);
127 int	_pci_intr_map_msi(struct pci_attach_args *, pci_intr_handle_t *);
128 int	_pci_intr_map_msix(struct pci_attach_args *, int, pci_intr_handle_t *);
129 
130 #define __HAVE_PCI_MSIX
131 
132 int	pci_msix_table_map(pci_chipset_tag_t, pcitag_t,
133 	    bus_space_tag_t, bus_space_handle_t *);
134 void	pci_msix_table_unmap(pci_chipset_tag_t, pcitag_t,
135 	    bus_space_tag_t, bus_space_handle_t);
136