xref: /openbsd/sys/arch/arm64/include/pci_machdep.h (revision 09467b48)
1 /*	$OpenBSD: pci_machdep.h,v 1.7 2020/07/14 15:42:19 patrick 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 arm64_pci_chipset *pci_chipset_tag_t;
30 typedef u_long pcitag_t;
31 
32 /* Supported interrupt types. */
33 #define PCI_NONE		0
34 #define PCI_INTX		1
35 #define PCI_MSI			2
36 #define PCI_MSIX		3
37 
38 typedef struct {
39 	pci_chipset_tag_t	ih_pc;
40 	pcitag_t		ih_tag;
41 	int			ih_intrpin;
42 	int			ih_type;
43 } pci_intr_handle_t;
44 
45 struct pci_attach_args;
46 
47 /*
48  * arm64-specific PCI structure and type definitions.
49  * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE.
50  */
51 struct arm64_pci_chipset {
52 	void		*pc_conf_v;
53 	void		(*pc_attach_hook)(struct device *,
54 			    struct device *, struct pcibus_attach_args *);
55 	int		(*pc_bus_maxdevs)(void *, int);
56 	pcitag_t	(*pc_make_tag)(void *, int, int, int);
57 	void		(*pc_decompose_tag)(void *, pcitag_t, int *,
58 			    int *, int *);
59 	int		(*pc_conf_size)(void *, pcitag_t);
60 	pcireg_t	(*pc_conf_read)(void *, pcitag_t, int);
61 	void		(*pc_conf_write)(void *, pcitag_t, int, pcireg_t);
62 
63 	void		*pc_intr_v;
64 	int		(*pc_intr_map)(struct pci_attach_args *,
65 			    pci_intr_handle_t *);
66 	int		(*pc_intr_map_msi)(struct pci_attach_args *,
67 			    pci_intr_handle_t *);
68 	int		(*pc_intr_map_msix)(struct pci_attach_args *,
69 			    int, pci_intr_handle_t *);
70 	const char	*(*pc_intr_string)(void *, pci_intr_handle_t);
71 	void		*(*pc_intr_establish)(void *, pci_intr_handle_t,
72 			    int, struct cpu_info *, int (*)(void *), void *,
73 			    char *);
74 	void		(*pc_intr_disestablish)(void *, void *);
75 };
76 
77 /*
78  * Functions provided to machine-independent PCI code.
79  */
80 #define	pci_attach_hook(p, s, pba)					\
81     (*(pba)->pba_pc->pc_attach_hook)((p), (s), (pba))
82 #define	pci_bus_maxdevs(c, b)						\
83     (*(c)->pc_bus_maxdevs)((c)->pc_conf_v, (b))
84 #define	pci_make_tag(c, b, d, f)					\
85     (*(c)->pc_make_tag)((c)->pc_conf_v, (b), (d), (f))
86 #define	pci_decompose_tag(c, t, bp, dp, fp)				\
87     (*(c)->pc_decompose_tag)((c)->pc_conf_v, (t), (bp), (dp), (fp))
88 #define	pci_conf_size(c, t)						\
89     (*(c)->pc_conf_size)((c)->pc_conf_v, (t))
90 #define	pci_conf_read(c, t, r)						\
91     (*(c)->pc_conf_read)((c)->pc_conf_v, (t), (r))
92 #define	pci_conf_write(c, t, r, v)					\
93     (*(c)->pc_conf_write)((c)->pc_conf_v, (t), (r), (v))
94 #define	pci_intr_map(c, ihp)						\
95     (*(c)->pa_pc->pc_intr_map)((c), (ihp))
96 #define	pci_intr_map_msi(c, ihp)					\
97     (*(c)->pa_pc->pc_intr_map_msi)((c), (ihp))
98 #define	pci_intr_map_msix(c, vec, ihp)					\
99     (*(c)->pa_pc->pc_intr_map_msix)((c), (vec), (ihp))
100 #define	pci_intr_string(c, ih)						\
101     (*(c)->pc_intr_string)((c)->pc_intr_v, (ih))
102 #define	pci_intr_establish(c, ih, l, h, a, nm)				\
103     (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), NULL, (h), (a),\
104 	(nm))
105 #define	pci_intr_establish_cpu(c, ih, l, ci, h, a, nm)			\
106     (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), (ci), (h), (a),\
107 	(nm))
108 #define	pci_intr_disestablish(c, iv)					\
109     (*(c)->pc_intr_disestablish)((c)->pc_intr_v, (iv))
110 #define	pci_probe_device_hook(c, a)	(0)
111 
112 #define	pci_min_powerstate(c, t)	(PCI_PMCSR_STATE_D3)
113 #define	pci_set_powerstate_md(c, t, s, p)
114 
115 #define	pci_dev_postattach(a, b)
116 
117 void	pci_mcfg_init(bus_space_tag_t, bus_addr_t, int, int, int);
118 pci_chipset_tag_t pci_lookup_segment(int);
119 
120 void	pci_msi_enable(pci_chipset_tag_t, pcitag_t, bus_addr_t, uint32_t);
121 void	pci_msix_enable(pci_chipset_tag_t, pcitag_t, bus_space_tag_t,
122 	    int, bus_addr_t, uint32_t);
123 int	_pci_intr_map_msi(struct pci_attach_args *, pci_intr_handle_t *);
124 int	_pci_intr_map_msix(struct pci_attach_args *, int, pci_intr_handle_t *);
125 
126 #define __HAVE_PCI_MSIX
127 
128 int	pci_msix_table_map(pci_chipset_tag_t, pcitag_t,
129 	    bus_space_tag_t, bus_space_handle_t *);
130 void	pci_msix_table_unmap(pci_chipset_tag_t, pcitag_t,
131 	    bus_space_tag_t, bus_space_handle_t);
132